From: Mimi Zohar <zohar@linux.vnet.ibm.com>
To: "J. Bruce Fields" <bfields@redhat.com>
Cc: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org,
samba-technical@lists.samba.org,
Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH 1/6] leases: split up generic_setlease into lock/unlock cases
Date: Thu, 22 Sep 2011 13:16:14 -0400 [thread overview]
Message-ID: <1316711774.3159.52.camel@localhost.localdomain> (raw)
In-Reply-To: <1316617097-21384-2-git-send-email-bfields@redhat.com>
On Wed, 2011-09-21 at 10:58 -0400, J. Bruce Fields wrote:
> Eventually we should probably do the same thing to the file operations
> as well.
>
> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
> ---
> fs/locks.c | 98 ++++++++++++++++++++++++++++++++++++++----------------------
> 1 files changed, 62 insertions(+), 36 deletions(-)
>
> diff --git a/fs/locks.c b/fs/locks.c
> index 9b8408e..b342902 100644
> --- a/fs/locks.c
> +++ b/fs/locks.c
> @@ -1352,18 +1352,7 @@ int fcntl_getlease(struct file *filp)
> return type;
> }
>
> -/**
> - * generic_setlease - sets a lease on an open file
> - * @filp: file pointer
> - * @arg: type of lease to obtain
> - * @flp: input - file_lock to use, output - file_lock inserted
> - *
> - * The (input) flp->fl_lmops->lm_break function is required
> - * by break_lease().
> - *
> - * Called with file_lock_lock held.
> - */
> -int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
> +int generic_add_lease(struct file *filp, long arg, struct file_lock **flp)
> {
> struct file_lock *fl, **before, **my_before = NULL, *lease;
> struct dentry *dentry = filp->f_path.dentry;
> @@ -1372,30 +1361,14 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
>
> lease = *flp;
>
> - error = -EACCES;
> - if ((current_fsuid() != inode->i_uid) && !capable(CAP_LEASE))
> - goto out;
> - error = -EINVAL;
> - if (!S_ISREG(inode->i_mode))
> + error = -EAGAIN;
> + if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0))
> goto out;
> - error = security_file_lock(filp, arg);
> - if (error)
> + if ((arg == F_WRLCK)
> + && ((dentry->d_count > 1)
> + || (atomic_read(&inode->i_count) > 1)))
> goto out;
>
> - time_out_leases(inode);
> -
> - BUG_ON(!(*flp)->fl_lmops->lm_break);
> -
> - if (arg != F_UNLCK) {
> - error = -EAGAIN;
> - if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0))
> - goto out;
> - if ((arg == F_WRLCK)
> - && ((dentry->d_count > 1)
> - || (atomic_read(&inode->i_count) > 1)))
> - goto out;
> - }
> -
> /*
> * At this point, we know that if there is an exclusive
> * lease on this file, then we hold it on this filp
> @@ -1433,9 +1406,6 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
> goto out;
> }
>
> - if (arg == F_UNLCK)
> - goto out;
> -
> error = -EINVAL;
> if (!leases_enable)
> goto out;
> @@ -1446,6 +1416,62 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
> out:
> return error;
> }
> +
> +int generic_delete_lease(struct file *filp, struct file_lock **flp)
> +{
> + struct file_lock *fl, **before;
> + struct dentry *dentry = filp->f_path.dentry;
> + struct inode *inode = dentry->d_inode;
> +
> + for (before = &inode->i_flock;
> + ((fl = *before) != NULL) && IS_LEASE(fl);
> + before = &fl->fl_next) {
> + if (fl->fl_file != filp)
> + continue;
> + return (*flp)->fl_lmops->lm_change(before, F_UNLCK);
> + }
> + return -EAGAIN;
> +}
> +
> +/**
> + * generic_setlease - sets a lease on an open file
> + * @filp: file pointer
> + * @arg: type of lease to obtain
> + * @flp: input - file_lock to use, output - file_lock inserted
> + *
> + * The (input) flp->fl_lmops->lm_break function is required
> + * by break_lease().
> + *
> + * Called with file_lock_lock held.
> + */
> +int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
> +{
> + struct dentry *dentry = filp->f_path.dentry;
> + struct inode *inode = dentry->d_inode;
> + int error;
> +
> + if ((current_fsuid() != inode->i_uid) && !capable(CAP_LEASE))
> + return -EACCES;
> + if (!S_ISREG(inode->i_mode))
> + return -EINVAL;
> + error = security_file_lock(filp, arg);
> + if (error)
> + return error;
> +
> + time_out_leases(inode);
> +
> + BUG_ON(!(*flp)->fl_lmops->lm_break);
> +
> + switch (arg) {
> + case F_UNLCK:
> + return generic_delete_lease(filp, flp);
> + case F_RDLCK:
> + case F_WRLCK:
> + return generic_add_lease(filp, arg, flp);
> + default:
> + BUG();
> + }
> +}
> EXPORT_SYMBOL(generic_setlease);
>
> static int __vfs_setlease(struct file *filp, long arg, struct file_lock **lease)
Nice, the code refactoring makes it a lot more readable.
thanks,
Mimi
next prev parent reply other threads:[~2011-09-22 17:16 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-21 14:58 breaking leases on metadata changes J. Bruce Fields
[not found] ` <1316617097-21384-1-git-send-email-bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-09-21 14:58 ` [PATCH 1/6] leases: split up generic_setlease into lock/unlock cases J. Bruce Fields
2011-09-22 17:16 ` Mimi Zohar [this message]
[not found] ` <1316711774.3159.52.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2011-09-23 18:57 ` J. Bruce Fields
2011-09-21 14:58 ` [PATCH 5/6] leases: break leases on any attribute modification J. Bruce Fields
2011-09-21 15:35 ` J. Bruce Fields
2011-09-21 14:58 ` [PATCH 2/6] leases: fix write-open/read-lease race J. Bruce Fields
2011-09-21 15:01 ` J. Bruce Fields
2011-09-22 17:17 ` Mimi Zohar
[not found] ` <1316617097-21384-3-git-send-email-bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-10-10 21:59 ` J. Bruce Fields
2011-10-11 6:19 ` Need information about the net ads user command Pankaj Baranwal
[not found] ` <20111010215911.GC17936-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2011-10-28 8:46 ` [PATCH 2/6] leases: fix write-open/read-lease race J. Bruce Fields
2011-09-21 14:58 ` [PATCH 3/6] leases: break read leases on unlink J. Bruce Fields
[not found] ` <1316617097-21384-4-git-send-email-bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-09-21 15:02 ` Christoph Hellwig
[not found] ` <20110921150241.GA11452-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2011-09-21 17:41 ` J. Bruce Fields
2011-09-21 14:58 ` [PATCH 4/6] leases: break read leases on rename J. Bruce Fields
[not found] ` <1316617097-21384-5-git-send-email-bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2011-09-22 17:17 ` Mimi Zohar
2011-09-23 16:55 ` J. Bruce Fields
[not found] ` <20110923165510.GA807-spRCxval1Z7TsXDwO4sDpg@public.gmane.org>
2011-09-23 18:55 ` J. Bruce Fields
2011-09-23 19:58 ` Mimi Zohar
2011-09-23 20:13 ` J. Bruce Fields
2011-09-21 14:58 ` [PATCH 6/6] leases: break read leases on link J. Bruce Fields
2011-09-24 18:36 ` breaking leases on metadata changes Stefan (metze) Metzmacher
2011-09-26 14:10 ` J. Bruce Fields
2011-09-26 16:16 ` J. Bruce Fields
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1316711774.3159.52.camel@localhost.localdomain \
--to=zohar@linux.vnet.ibm.com \
--cc=bfields@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=samba-technical@lists.samba.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).