From patchwork Sat Oct 27 12:33: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: 1655421 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 D88AD3FD4E for ; Sat, 27 Oct 2012 12:41:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755312Ab2J0Mkt (ORCPT ); Sat, 27 Oct 2012 08:40:49 -0400 Received: from mail-gh0-f174.google.com ([209.85.160.174]:35347 "EHLO mail-gh0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755277Ab2J0MeP (ORCPT ); Sat, 27 Oct 2012 08:34:15 -0400 Received: by mail-gh0-f174.google.com with SMTP id g15so699691ghb.19 for ; Sat, 27 Oct 2012 05:34:15 -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=b+AEbhsaJ5vuQfvDFyR5yLKaKKhg/wzWBrjH0pGzh28=; b=map7X2MKOGci8MJYGvWhc6CcYqjQB33H6AcaSXl0JuIOnui45ppLTRIt+k1/W18NoG AZn2lkyNoOXjdR6IYJG3cXI25qcSnHnep6qnfAuhdYhgXE5fIakOYeGiPbSyTbRhJcTV RccMgU6V4PeJJ2NlhPeAp/CYVOjZ6HcrGj89PM5Bb16YNke9uciFX/7JHztSPQPWg41u vqk4ouwy0fxKopN5rUQzZTcQ7mnBHjQEbiyDmXMyfQ/3w4W5yKpinUteuaiNgaWpeZpo 11jX7xMkbc8BOXcEepMIeIenA72wWqV8DXyAtKsD7z/6cQ8oUPJ/584Yhck3Ae8SOu3G GB1w== Received: by 10.236.92.15 with SMTP id i15mr24701733yhf.85.1351341255011; Sat, 27 Oct 2012 05:34:15 -0700 (PDT) Received: from salusa.poochiereds.net (cpe-107-015-110-129.nc.res.rr.com. [107.15.110.129]) by mx.google.com with ESMTPS id f15sm4124613yhi.11.2012.10.27.05.34.13 (version=SSLv3 cipher=OTHER); Sat, 27 Oct 2012 05:34:14 -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 v8 13/32] vfs: have do_sys_truncate retry once on an ESTALE error Date: Sat, 27 Oct 2012 08:33:20 -0400 Message-Id: <1351341219-17837-14-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1351341219-17837-1-git-send-email-jlayton@redhat.com> References: <1351341219-17837-1-git-send-email-jlayton@redhat.com> X-Gm-Message-State: ALoCoQnaKHkFUTCdFDehcIhtR8kPK6U6wGtIdEzHjS6yviB8YHfIbDlkAm/Ejm3tlH3L8GRrQqkx 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 94d5649..2a32d5c 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; }