Commit 0ceaf6c7 authored by J. Bruce Fields's avatar J. Bruce Fields Committed by Linus Torvalds

locks: prevent ENOMEM on lease unlock

Removing a lock shouldn't require any allocations; a failure due to
ENOMEM leaves the caller with a choice between retrying or giving up and
leaking an unused lease.

Next we should split the other lease calls into add and delete cases.
I wanted to start with just the bugfix.
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0d07025e
...@@ -1441,6 +1441,7 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp) ...@@ -1441,6 +1441,7 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
return 0; return 0;
out: out:
if (arg != F_UNLCK)
locks_free_lock(lease); locks_free_lock(lease);
return error; return error;
} }
...@@ -1493,17 +1494,16 @@ int vfs_setlease(struct file *filp, long arg, struct file_lock **lease) ...@@ -1493,17 +1494,16 @@ int vfs_setlease(struct file *filp, long arg, struct file_lock **lease)
} }
EXPORT_SYMBOL_GPL(vfs_setlease); EXPORT_SYMBOL_GPL(vfs_setlease);
/** static int do_fcntl_delete_lease(struct file *filp)
* fcntl_setlease - sets a lease on an open file {
* @fd: open file descriptor struct file_lock fl, *flp = &fl;
* @filp: file pointer
* @arg: type of lease to obtain lease_init(filp, F_UNLCK, flp);
*
* Call this fcntl to establish a lease on the file. return vfs_setlease(filp, F_UNLCK, &flp);
* Note that you also need to call %F_SETSIG to }
* receive a signal when the lease is broken.
*/ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
{ {
struct file_lock *fl; struct file_lock *fl;
struct fasync_struct *new; struct fasync_struct *new;
...@@ -1521,7 +1521,7 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg) ...@@ -1521,7 +1521,7 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
} }
lock_flocks(); lock_flocks();
error = __vfs_setlease(filp, arg, &fl); error = __vfs_setlease(filp, arg, &fl);
if (error || arg == F_UNLCK) if (error)
goto out_unlock; goto out_unlock;
/* /*
...@@ -1549,6 +1549,23 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg) ...@@ -1549,6 +1549,23 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
return error; return error;
} }
/**
* fcntl_setlease - sets a lease on an open file
* @fd: open file descriptor
* @filp: file pointer
* @arg: type of lease to obtain
*
* Call this fcntl to establish a lease on the file.
* Note that you also need to call %F_SETSIG to
* receive a signal when the lease is broken.
*/
int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
{
if (arg == F_UNLCK)
return do_fcntl_delete_lease(filp);
return do_fcntl_add_lease(fd, filp, arg);
}
/** /**
* flock_lock_file_wait - Apply a FLOCK-style lock to a file * flock_lock_file_wait - Apply a FLOCK-style lock to a file
* @filp: The file to apply the lock to * @filp: The file to apply the lock to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment