From patchwork Fri Sep 7 14:18:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1422931 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 56E3FDF283 for ; Fri, 7 Sep 2012 14:24:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760725Ab2IGOYw (ORCPT ); Fri, 7 Sep 2012 10:24:52 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:49735 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760581Ab2IGOS4 (ORCPT ); Fri, 7 Sep 2012 10:18:56 -0400 Received: by yenl14 with SMTP id l14so546098yen.19 for ; Fri, 07 Sep 2012 07:18:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=I+qOLIEZCce5dFc8LH7u1Id7xJ7OKQMadt7XPAs+sg0=; b=lR5clrLVmBFvci9tk3js+/zQvqP3NbdKO2p9p9HAwHghIePcyfKIi5aGZ0Y+zINCS9 Qo9VBfSamWWakuj3G7ADPPqUVXWomO0bFv5/v8UzB6cOikEn5XR1GnwDwB8ksFboaufW 8uxQ4vsUmaYPp186iS1Upd+QGHFpXrqxYW4Og+Hh3AEXDwS1G9izMqHGCCAX7z9X8oaH m/agFe2HypcBtfXg4srF0eiufuIpwnGng9j5QkLBh7NCaOtLhKAdhYCXnAZML5pzdnzy hZng+KvvEclts+WLDCl1JDPMHIWmBH87rWMLJr03/XKshsin7OxZqcjSXGvTiduGJbAl VnQg== Received: by 10.58.89.200 with SMTP id bq8mr1820188veb.17.1347027535976; Fri, 07 Sep 2012 07:18:55 -0700 (PDT) Received: from salusa.poochiereds.net (cpe-069-134-145-027.nc.res.rr.com. [69.134.145.27]) by mx.google.com with ESMTPS id v9sm3207113ves.8.2012.09.07.07.18.54 (version=SSLv3 cipher=OTHER); Fri, 07 Sep 2012 07:18:55 -0700 (PDT) From: Jeff Layton To: viro@ZenIV.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, michael.brantley@deshaw.com, hch@infradead.org, miklos@szeredi.hu, pstaubach@exagrid.com Subject: [PATCH v6 13/20] vfs: have do_sys_truncate retry once on an ESTALE error Date: Fri, 7 Sep 2012 10:18:20 -0400 Message-Id: <1347027507-20956-14-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1347027507-20956-1-git-send-email-jlayton@redhat.com> References: <1347027507-20956-1-git-send-email-jlayton@redhat.com> X-Gm-Message-State: ALoCoQlc8u3zpEN68VaQyf/uTa2+4tyI6EaGMPOAiivSTrw4oFNurifBkcrjzAO4YzbAao0e7UYo Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Signed-off-by: Jeff Layton --- fs/open.c | 86 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/fs/open.c b/fs/open.c index d0f225e..5dcee00 100644 --- a/fs/open.c +++ b/fs/open.c @@ -66,62 +66,66 @@ static long do_sys_truncate(const char __user *pathname, loff_t length) struct path path; struct inode *inode; int error; + unsigned int lookup_flags = LOOKUP_FOLLOW; + unsigned int try = 0; - error = -EINVAL; if (length < 0) /* sorry, but loff_t says... */ - goto out; + return -EINVAL; - error = user_path(pathname, &path); - if (error) - goto out; - inode = path.dentry->d_inode; + do { + error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); + if (error) + break; + inode = path.dentry->d_inode; - /* For directories it's -EISDIR, for other non-regulars - -EINVAL */ - error = -EISDIR; - if (S_ISDIR(inode->i_mode)) - goto dput_and_out; + /* For dirs, -EISDIR. For other non-regulars, -EINVAL */ + error = -EISDIR; + if (S_ISDIR(inode->i_mode)) + goto dput_and_out; - error = -EINVAL; - if (!S_ISREG(inode->i_mode)) - goto dput_and_out; + error = -EINVAL; + if (!S_ISREG(inode->i_mode)) + goto dput_and_out; - error = mnt_want_write(path.mnt); - if (error) - goto dput_and_out; + error = mnt_want_write(path.mnt); + if (error) + goto dput_and_out; - error = inode_permission(inode, MAY_WRITE); - if (error) - goto mnt_drop_write_and_out; + error = inode_permission(inode, MAY_WRITE); + if (error) + goto mnt_drop_write_and_out; - error = -EPERM; - if (IS_APPEND(inode)) - goto mnt_drop_write_and_out; + error = -EPERM; + if (IS_APPEND(inode)) + goto mnt_drop_write_and_out; - error = get_write_access(inode); - if (error) - goto mnt_drop_write_and_out; + error = get_write_access(inode); + if (error) + goto mnt_drop_write_and_out; - /* - * Make sure that there are no leases. get_write_access() protects - * against the truncate racing with a lease-granting setlease(). - */ - error = break_lease(inode, O_WRONLY); - if (error) - goto put_write_and_out; + /* + * Make sure that there are no leases. get_write_access() + * protects against the truncate racing with a lease-granting + * setlease(). + */ + error = break_lease(inode, O_WRONLY); + if (error) + goto put_write_and_out; - error = locks_verify_truncate(inode, NULL, length); - if (!error) - error = security_path_truncate(&path); - if (!error) - error = do_truncate(path.dentry, length, 0, NULL); + error = locks_verify_truncate(inode, NULL, length); + if (!error) + error = security_path_truncate(&path); + if (!error) + error = do_truncate(path.dentry, length, 0, NULL); put_write_and_out: - put_write_access(inode); + put_write_access(inode); mnt_drop_write_and_out: - mnt_drop_write(path.mnt); + mnt_drop_write(path.mnt); dput_and_out: - path_put(&path); -out: + path_put(&path); + lookup_flags |= LOOKUP_REVAL; + } while (retry_estale(error, try++)); return error; }