From patchwork Wed Aug 8 13:21:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1295631 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 4B0F5DF223 for ; Wed, 8 Aug 2012 13:24:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758491Ab2HHNWH (ORCPT ); Wed, 8 Aug 2012 09:22:07 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:61865 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758468Ab2HHNWD (ORCPT ); Wed, 8 Aug 2012 09:22:03 -0400 Received: by yenl2 with SMTP id l2so730912yen.19 for ; Wed, 08 Aug 2012 06:22:03 -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=/qZaLD+H+QOqVrzFq6fJHXFBkI8gPS/Jt+Z4FI5F3rw=; b=ZpLFzuDRSo1awyf2JjhRPudb/hBYNkCEOQiLlsPCQbl7A5JK+V6r7A82Y/ZlBP9ER+ lytDMBxFSjFNEWhSplLV6czCcRnPYkkBD8t3lBQyHQ3uHf/QuevXmhy01SoNCV7KUZou MYW1U78BjB7WENE38fNn7y7A6W/MoMxXlUaeZTk9fxB/9xRXPM9rrzZW0ZvqntVZRd0L 7J9UwB3AcPFG2FrdrgFcffo5OG0XaBM+qpQzs9A12csDDzezcmuEfY/5gufFTt9Q8JYY CsBkP5PLRj5Qj5Ss4rgrjbd79NYKF50lOd9hadju62Pv6ZMPZzletaOEpMgFvFTt+Myt eq6g== Received: by 10.236.73.198 with SMTP id v46mr17055390yhd.80.1344432123035; Wed, 08 Aug 2012 06:22:03 -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.01 (version=SSLv3 cipher=OTHER); Wed, 08 Aug 2012 06:22:02 -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 11/19] vfs: fix linkat to retry on ESTALE errors Date: Wed, 8 Aug 2012 09:21:34 -0400 Message-Id: <1344432102-22312-12-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: ALoCoQm1AM2MqZypQ0KCrfvHJFiyE3F5LS6e2SizbP1cPPkfvNRKol3ncUz8zqa6ijtuYesxU6Mb 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/namei.c | 60 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 9986117..d6e9754 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3565,6 +3565,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname, struct path old_path, new_path; int how = 0; int error; + char *old, *new; + unsigned int try = 0; if ((flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0) return -EINVAL; @@ -3582,30 +3584,48 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname, if (flags & AT_SYMLINK_FOLLOW) how |= LOOKUP_FOLLOW; - error = user_path_at(olddfd, oldname, how, &old_path); - if (error) - return error; + old = getname_flags(oldname, how, NULL); + if (IS_ERR(old)) + return PTR_ERR(old); - new_dentry = user_path_create(newdfd, newname, &new_path, 0); - error = PTR_ERR(new_dentry); - if (IS_ERR(new_dentry)) - goto out; + new = getname(newname); + if (IS_ERR(new)) { + putname(old); + return PTR_ERR(new); + } - error = -EXDEV; - if (old_path.mnt != new_path.mnt) - goto out_dput; - error = may_linkat(&old_path); - if (unlikely(error)) - goto out_dput; - error = security_path_link(old_path.dentry, &new_path, new_dentry); - if (error) - goto out_dput; - error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry); + do { + error = kern_path_at(olddfd, old, how, &old_path); + if (error) + break; + + new_dentry = kern_path_create(newdfd, new, &new_path, 0, try); + error = PTR_ERR(new_dentry); + if (IS_ERR(new_dentry)) { + path_put(&old_path); + break; + } + + error = -EXDEV; + if (old_path.mnt != new_path.mnt) + goto out_dput; + error = may_linkat(&old_path); + if (unlikely(error)) + goto out_dput; + error = security_path_link(old_path.dentry, &new_path, + new_dentry); + if (error) + goto out_dput; + error = vfs_link(old_path.dentry, new_path.dentry->d_inode, + new_dentry); out_dput: - done_path_create(&new_path, new_dentry); + done_path_create(&new_path, new_dentry); out: - path_put(&old_path); - + path_put(&old_path); + how |= LOOKUP_REVAL; + } while (retry_estale(error, try++)); + putname(new); + putname(old); return error; }