From patchwork Fri Jun 29 18:57:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1133281 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 DFFDADFF34 for ; Fri, 29 Jun 2012 19:01:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932735Ab2F2TA5 (ORCPT ); Fri, 29 Jun 2012 15:00:57 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:41418 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932727Ab2F2S6X (ORCPT ); Fri, 29 Jun 2012 14:58:23 -0400 Received: by mail-yx0-f174.google.com with SMTP id l2so3038059yen.19 for ; Fri, 29 Jun 2012 11:58:23 -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=rjztUDyFJauSgyI/kTSyybHNfWnJLdKhcEBR3yI1g2M=; b=H6eHgGKxxMbS/z5fZD469VBAIfYOf57k81H7tkR5mQ1GrzEjGzDW0kfA1iM4b+zq0y KmnK7LPZokIFXteq4MDkUsWfv4Gp2qgSqcK1c/QlVp09lf/E+aKAITJska3M/y/cc9uL tLd7wq5nrSQDYOBVqXluBmx3zMC4QYQZRIdVKtTGYGY4XRy+tYGGl7cmoGKmNuAbYSGW 2v/b5gPYZpY7MRRWVdpLZPh06oUKBKIXRZP0IVaEHjaONOFXBU5b5KHaczMt++tCk0x5 MXBy9/+CKGMA18sFu6dbzU0zmm1Lvo0NDgwP1pkqIRtIet0GYmAZa0eMiM7tQa7345da ZB2w== Received: by 10.101.74.11 with SMTP id b11mr1213663anl.56.1340996303138; Fri, 29 Jun 2012 11:58:23 -0700 (PDT) Received: from salusa.poochiereds.net (cpe-076-182-054-194.nc.res.rr.com. [76.182.54.194]) by mx.google.com with ESMTPS id l13sm3936309ann.2.2012.06.29.11.58.21 (version=SSLv3 cipher=OTHER); Fri, 29 Jun 2012 11:58:22 -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 v3 11/17] vfs: fix linkat to retry on ESTALE errors Date: Fri, 29 Jun 2012 14:57:54 -0400 Message-Id: <1340996280-27123-12-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1340996280-27123-1-git-send-email-jlayton@redhat.com> References: <1340996280-27123-1-git-send-email-jlayton@redhat.com> X-Gm-Message-State: ALoCoQnBCzuxO9jErsBIyDKhblWIIFPla+H40cvwzhl/5vcZqlLdDykWxoG3P7CEu2zk+P3M4emk 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 | 67 ++++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 43 insertions(+), 24 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index a2d691a..e902770 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3138,6 +3138,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; @@ -3155,34 +3157,51 @@ 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 = mnt_want_write(new_path.mnt); - if (error) - goto out_dput; - error = security_path_link(old_path.dentry, &new_path, new_dentry); - if (error) - goto out_drop_write; - 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 = mnt_want_write(new_path.mnt); + if (error) + goto out_dput; + error = security_path_link(old_path.dentry, &new_path, + new_dentry); + if (error) + goto out_drop_write; + error = vfs_link(old_path.dentry, new_path.dentry->d_inode, + new_dentry); out_drop_write: - mnt_drop_write(new_path.mnt); + mnt_drop_write(new_path.mnt); out_dput: - dput(new_dentry); - mutex_unlock(&new_path.dentry->d_inode->i_mutex); - path_put(&new_path); -out: - path_put(&old_path); - + dput(new_dentry); + mutex_unlock(&new_path.dentry->d_inode->i_mutex); + path_put(&new_path); + path_put(&old_path); + how |= LOOKUP_REVAL; + } while (retry_estale(error, try++)); + putname(new); + putname(old); return error; }