提交 5c1c669a 编写于 作者: J Jeff Layton

locks: don't allocate a lock context for an F_UNLCK request

In the event that we get an F_UNLCK request on an inode that has no lock
context, there is no reason to allocate one. Change
locks_get_lock_context to take a "type" pointer and avoid allocating a
new context if it's F_UNLCK.

Then, fix the callers to return appropriately if that function returns
NULL.
Signed-off-by: NJeff Layton <jlayton@primarydata.com>
上级 663d5af7
...@@ -203,11 +203,11 @@ static struct kmem_cache *flctx_cache __read_mostly; ...@@ -203,11 +203,11 @@ static struct kmem_cache *flctx_cache __read_mostly;
static struct kmem_cache *filelock_cache __read_mostly; static struct kmem_cache *filelock_cache __read_mostly;
static struct file_lock_context * static struct file_lock_context *
locks_get_lock_context(struct inode *inode) locks_get_lock_context(struct inode *inode, int type)
{ {
struct file_lock_context *new; struct file_lock_context *new;
if (likely(inode->i_flctx)) if (likely(inode->i_flctx) || type == F_UNLCK)
goto out; goto out;
new = kmem_cache_alloc(flctx_cache, GFP_KERNEL); new = kmem_cache_alloc(flctx_cache, GFP_KERNEL);
...@@ -877,9 +877,12 @@ static int flock_lock_file(struct file *filp, struct file_lock *request) ...@@ -877,9 +877,12 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
bool found = false; bool found = false;
LIST_HEAD(dispose); LIST_HEAD(dispose);
ctx = locks_get_lock_context(inode); ctx = locks_get_lock_context(inode, request->fl_type);
if (!ctx) if (!ctx) {
return -ENOMEM; if (request->fl_type != F_UNLCK)
return -ENOMEM;
return (request->fl_flags & FL_EXISTS) ? -ENOENT : 0;
}
if (!(request->fl_flags & FL_ACCESS) && (request->fl_type != F_UNLCK)) { if (!(request->fl_flags & FL_ACCESS) && (request->fl_type != F_UNLCK)) {
new_fl = locks_alloc_lock(); new_fl = locks_alloc_lock();
...@@ -945,9 +948,9 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str ...@@ -945,9 +948,9 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
bool added = false; bool added = false;
LIST_HEAD(dispose); LIST_HEAD(dispose);
ctx = locks_get_lock_context(inode); ctx = locks_get_lock_context(inode, request->fl_type);
if (!ctx) if (!ctx)
return -ENOMEM; return (request->fl_type == F_UNLCK) ? 0 : -ENOMEM;
/* /*
* We may need two file_lock structures for this operation, * We may need two file_lock structures for this operation,
...@@ -1609,7 +1612,8 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr ...@@ -1609,7 +1612,8 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
lease = *flp; lease = *flp;
trace_generic_add_lease(inode, lease); trace_generic_add_lease(inode, lease);
ctx = locks_get_lock_context(inode); /* Note that arg is never F_UNLCK here */
ctx = locks_get_lock_context(inode, arg);
if (!ctx) if (!ctx)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册