From patchwork Wed Aug 8 13:21:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1295581 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 8AFDC3FCFC for ; Wed, 8 Aug 2012 13:23:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758560Ab2HHNXV (ORCPT ); Wed, 8 Aug 2012 09:23:21 -0400 Received: from mail-yw0-f46.google.com ([209.85.213.46]:49060 "EHLO mail-yw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758506Ab2HHNWK (ORCPT ); Wed, 8 Aug 2012 09:22:10 -0400 Received: by mail-yw0-f46.google.com with SMTP id m54so724917yhm.19 for ; Wed, 08 Aug 2012 06:22:09 -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=Davuijoc1nx0+QOiKlipfuzZ2gOyKeDrukOMQ3kVDT8=; b=aKC82yqd5CiscREbFaQlCRIANn1+g+23GEZXWHbWXMiQAFtAVQuwMOScQ5pLUGLSCj CQHTOvLQDDrRWW+D/ucPdn3r6IAfziS5KcqIhV/VM8Zqf/AsAe6kYvVe4GQoJrvW2H1h ywoaQba4T88RWLQ3bGFMYNPO9D8rLBsKjITNfIuP7bySIpfTExr5R2OrQdQ8f3EU1QaU eH/wQF6Kar8hUw2T1E5E/4HvKJdrtjJRIAfjVVRBuk55IoHzZ982G2bkFMP6gkCxol4P Gt1KVjqDaJ6N2XU86r/vHcaUOGATL7DVLMfpMvuQ8SWc3BXKyER737KRr9Ch73nCmKRv kYFw== Received: by 10.236.140.67 with SMTP id d43mr16598566yhj.19.1344432129850; Wed, 08 Aug 2012 06:22:09 -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 l1sm24418002yhm.19.2012.08.08.06.22.08 (version=SSLv3 cipher=OTHER); Wed, 08 Aug 2012 06:22:09 -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 v5 16/19] vfs: have do_sys_truncate retry once on an ESTALE error Date: Wed, 8 Aug 2012 09:21:39 -0400 Message-Id: <1344432102-22312-17-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1344432102-22312-1-git-send-email-jlayton@redhat.com> References: <1344432102-22312-1-git-send-email-jlayton@redhat.com> X-Gm-Message-State: ALoCoQnGijVTXmadYYQu0BX/fIBFZSyMDvamyJZmzVYikfmlHW/4i98r2Ci4Dv+WXQkUh/V0tivM 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 | 92 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/fs/open.c b/fs/open.c index 7babeed..0df0c5d 100644 --- a/fs/open.c +++ b/fs/open.c @@ -66,62 +66,72 @@ 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; + char *name; - 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; + name = getname_flags(pathname, lookup_flags, NULL); + if (IS_ERR(name)) + return PTR_ERR(name); - /* For directories it's -EISDIR, for other non-regulars - -EINVAL */ - error = -EISDIR; - if (S_ISDIR(inode->i_mode)) - goto dput_and_out; + do { + error = kern_path_at(AT_FDCWD, name, lookup_flags, &path); + if (error) + break; + inode = path.dentry->d_inode; - error = -EINVAL; - if (!S_ISREG(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 = mnt_want_write(path.mnt); - if (error) - goto dput_and_out; + error = -EINVAL; + if (!S_ISREG(inode->i_mode)) + goto dput_and_out; - error = inode_permission(inode, MAY_WRITE); - if (error) - goto mnt_drop_write_and_out; + error = mnt_want_write(path.mnt); + if (error) + goto dput_and_out; - error = -EPERM; - if (IS_APPEND(inode)) - goto mnt_drop_write_and_out; + error = inode_permission(inode, MAY_WRITE); + if (error) + goto mnt_drop_write_and_out; - error = get_write_access(inode); - if (error) - goto mnt_drop_write_and_out; + error = -EPERM; + if (IS_APPEND(inode)) + 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; + error = get_write_access(inode); + if (error) + goto mnt_drop_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); + /* + * 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); 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++)); + putname(name); return error; }