Skip to content

Commit

Permalink
locks: fix setlease methods to free passed-in lock
Browse files Browse the repository at this point in the history
We modified setlease to require the caller to allocate the new lease in
the case of creating a new lease, but forgot to fix up the filesystem
methods.

Cc: Steven Whitehouse <[email protected]>
Cc: Steve French <[email protected]>
Cc: Trond Myklebust <[email protected]>
Signed-off-by: J. Bruce Fields <[email protected]>
Acked-by: Arnd Bergmann <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
J. Bruce Fields authored and torvalds committed Oct 31, 2010
1 parent 096657b commit 05fa313
Showing 5 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion fs/cifs/cifsfs.c
Original file line number Diff line number Diff line change
@@ -625,8 +625,11 @@ static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
knows that the file won't be changed on the server
by anyone else */
return generic_setlease(file, arg, lease);
else
else {
if (arg != F_UNLCK)
locks_free_lock(*lease);
return -EAGAIN;
}
}

struct file_system_type cifs_fs_type = {
2 changes: 2 additions & 0 deletions fs/gfs2/file.c
Original file line number Diff line number Diff line change
@@ -629,6 +629,8 @@ static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov,

static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl)
{
if (arg != F_UNLCK)
locks_free_lock(*fl);
return -EINVAL;
}

3 changes: 2 additions & 1 deletion fs/locks.c
Original file line number Diff line number Diff line change
@@ -186,7 +186,7 @@ void locks_release_private(struct file_lock *fl)
EXPORT_SYMBOL_GPL(locks_release_private);

/* Free a lock which is not in use. */
static void locks_free_lock(struct file_lock *fl)
void locks_free_lock(struct file_lock *fl)
{
BUG_ON(waitqueue_active(&fl->fl_wait));
BUG_ON(!list_empty(&fl->fl_block));
@@ -195,6 +195,7 @@ static void locks_free_lock(struct file_lock *fl)
locks_release_private(fl);
kmem_cache_free(filelock_cache, fl);
}
EXPORT_SYMBOL(locks_free_lock);

void locks_init_lock(struct file_lock *fl)
{
3 changes: 2 additions & 1 deletion fs/nfs/file.c
Original file line number Diff line number Diff line change
@@ -884,6 +884,7 @@ static int nfs_setlease(struct file *file, long arg, struct file_lock **fl)
dprintk("NFS: setlease(%s/%s, arg=%ld)\n",
file->f_path.dentry->d_parent->d_name.name,
file->f_path.dentry->d_name.name, arg);

if (arg != F_UNLCK)
locks_free_lock(*fl);
return -EINVAL;
}
1 change: 1 addition & 0 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
@@ -1129,6 +1129,7 @@ extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
extern int fcntl_getlease(struct file *filp);

/* fs/locks.c */
void locks_free_lock(struct file_lock *fl);
extern void locks_init_lock(struct file_lock *);
extern struct file_lock * locks_alloc_lock(void);
extern void locks_copy_lock(struct file_lock *, struct file_lock *);

0 comments on commit 05fa313

Please sign in to comment.