From mboxrd@z Thu Jan 1 00:00:00 1970 From: "J. Bruce Fields" Subject: Re: [PATCH 2/6] leases: fix write-open/read-lease race Date: Mon, 10 Oct 2011 17:59:11 -0400 Message-ID: <20111010215911.GC17936@fieldses.org> References: <1316617097-21384-1-git-send-email-bfields@redhat.com> <1316617097-21384-3-git-send-email-bfields@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, samba-technical-w/Ol4Ecudpl8XjKLYN78aQ@public.gmane.org, Christoph Hellwig , Al Viro , Mimi Zohar To: "J. Bruce Fields" Return-path: Content-Disposition: inline In-Reply-To: <1316617097-21384-3-git-send-email-bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> Sender: linux-nfs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: linux-fsdevel.vger.kernel.org On Wed, Sep 21, 2011 at 10:58:13AM -0400, J. Bruce Fields wrote: > In setlease, we use i_writecount to decide whether we can give out a > read lease. > > In open, we break leases before incrementing i_writecount. > > There is therefore a window between the break lease and the i_writecount > increment when setlease could add a new read lease. > > This would leave us with a simultaneous write open and read lease, which > shouldn't happen. Al, could you apply this for 3.2, if you don't see any problem? (Patch 1 of this series only touches locks.c, and I'm queueing up such patches through the nfsd tree. Patches 3-6 I intend to rewrite, probably not in time for 3.2 unless I'm very lucky.) --b. > > Signed-off-by: J. Bruce Fields > --- > fs/namei.c | 5 +---- > fs/open.c | 4 ++++ > 2 files changed, 5 insertions(+), 4 deletions(-) > > diff --git a/fs/namei.c b/fs/namei.c > index 2826db3..6ff59e5 100644 > --- a/fs/namei.c > +++ b/fs/namei.c > @@ -2044,10 +2044,7 @@ static int may_open(struct path *path, int acc_mode, int flag) > if (flag & O_NOATIME && !inode_owner_or_capable(inode)) > return -EPERM; > > - /* > - * Ensure there are no outstanding leases on the file. > - */ > - return break_lease(inode, flag); > + return 0; > } > > static int handle_truncate(struct file *filp) > diff --git a/fs/open.c b/fs/open.c > index f711921..22c41b5 100644 > --- a/fs/open.c > +++ b/fs/open.c > @@ -685,6 +685,10 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, > if (error) > goto cleanup_all; > > + error = break_lease(inode, f->f_flags); > + if (error) > + goto cleanup_all; > + > if (!open && f->f_op) > open = f->f_op->open; > if (open) { > -- > 1.7.4.1 > -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html