From: Jeff Layton <jlayton@redhat.com>
To: Benjamin Coddington <bcodding@redhat.com>,
Trond Myklebust <trond.myklebust@primarydata.com>,
Anna Schumaker <anna.schumaker@netapp.com>
Cc: mszeredi@redhat.com, bfields@redhat.com, linux-nfs@vger.kernel.org
Subject: Re: [PATCH v2 1/2] Revert "NFS: nfs_rename() handle -ERESTARTSYS dentry left behind"
Date: Thu, 15 Jun 2017 17:11:25 -0400 [thread overview]
Message-ID: <1497561085.4607.19.camel@redhat.com> (raw)
In-Reply-To: <019c971f05beedfcf9d8039da508548e4819217d.1497559453.git.bcodding@redhat.com>
On Thu, 2017-06-15 at 16:59 -0400, Benjamin Coddington wrote:
> This reverts commit 920b4530fb80430ff30ef83efe21ba1fa5623731 which could
> call d_move() without holding the directory's i_mutex, and reverts commit
> d4ea7e3c5c0e341c15b073016dbf3ab6c65f12f3 "NFS: Fix old dentry rehash after
> move", which was a follow-up fix.
>
> Fixes: 920b4530fb80 ("NFS: nfs_rename() handle -ERESTARTSYS dentry left behind")
> Cc: stable@vger.kernel.org # v4.10+
> ---
> fs/nfs/dir.c | 45 ++++++++++++++++++---------------------------
> 1 file changed, 18 insertions(+), 27 deletions(-)
>
> diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
> index 32ccd7754f8a..1faf337b316f 100644
> --- a/fs/nfs/dir.c
> +++ b/fs/nfs/dir.c
> @@ -1946,29 +1946,6 @@ nfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
> }
> EXPORT_SYMBOL_GPL(nfs_link);
>
> -static void
> -nfs_complete_rename(struct rpc_task *task, struct nfs_renamedata *data)
> -{
> - struct dentry *old_dentry = data->old_dentry;
> - struct dentry *new_dentry = data->new_dentry;
> - struct inode *old_inode = d_inode(old_dentry);
> - struct inode *new_inode = d_inode(new_dentry);
> -
> - nfs_mark_for_revalidate(old_inode);
> -
> - switch (task->tk_status) {
> - case 0:
> - if (new_inode != NULL)
> - nfs_drop_nlink(new_inode);
> - d_move(old_dentry, new_dentry);
> - nfs_set_verifier(new_dentry,
> - nfs_save_change_attribute(data->new_dir));
> - break;
> - case -ENOENT:
> - nfs_dentry_handle_enoent(old_dentry);
> - }
> -}
> -
> /*
> * RENAME
> * FIXME: Some nfsds, like the Linux user space nfsd, may generate a
> @@ -1999,7 +1976,7 @@ int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
> {
> struct inode *old_inode = d_inode(old_dentry);
> struct inode *new_inode = d_inode(new_dentry);
> - struct dentry *dentry = NULL;
> + struct dentry *dentry = NULL, *rehash = NULL;
> struct rpc_task *task;
> int error = -EBUSY;
>
> @@ -2022,8 +1999,10 @@ int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
> * To prevent any new references to the target during the
> * rename, we unhash the dentry in advance.
> */
> - if (!d_unhashed(new_dentry))
> + if (!d_unhashed(new_dentry)) {
> d_drop(new_dentry);
> + rehash = new_dentry;
> + }
>
> if (d_count(new_dentry) > 2) {
> int err;
> @@ -2040,6 +2019,7 @@ int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
> goto out;
>
> new_dentry = dentry;
> + rehash = NULL;
> new_inode = NULL;
> }
> }
> @@ -2048,8 +2028,7 @@ int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
> if (new_inode != NULL)
> NFS_PROTO(new_inode)->return_delegation(new_inode);
>
> - task = nfs_async_rename(old_dir, new_dir, old_dentry, new_dentry,
> - nfs_complete_rename);
> + task = nfs_async_rename(old_dir, new_dir, old_dentry, new_dentry, NULL);
> if (IS_ERR(task)) {
> error = PTR_ERR(task);
> goto out;
> @@ -2059,9 +2038,21 @@ int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
> if (error == 0)
> error = task->tk_status;
> rpc_put_task(task);
> + nfs_mark_for_revalidate(old_inode);
> out:
> + if (rehash)
> + d_rehash(rehash);
> trace_nfs_rename_exit(old_dir, old_dentry,
> new_dir, new_dentry, error);
> + if (!error) {
> + if (new_inode != NULL)
> + nfs_drop_nlink(new_inode);
> + d_move(old_dentry, new_dentry);
> + nfs_set_verifier(new_dentry,
> + nfs_save_change_attribute(new_dir));
> + } else if (error == -ENOENT)
> + nfs_dentry_handle_enoent(old_dentry);
> +
Could you add a comment about why we need to do the d_move here instead
of in the completion handler? I worry that someone else may make the
same mistake later if we don't leave some breadcrumbs.
> /* new dentry created? */
> if (dentry)
> dput(dentry);
You can add this to both. Thanks for turning this around quickly:
Reviewed-by: Jeff Layton <jlayton@redhat.com>
next prev parent reply other threads:[~2017-06-15 21:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-15 20:59 [PATCH v2 0/2] nfs_complete_rename() calls d_move() without i_mutex Benjamin Coddington
2017-06-15 20:59 ` [PATCH v2 1/2] Revert "NFS: nfs_rename() handle -ERESTARTSYS dentry left behind" Benjamin Coddington
2017-06-15 21:11 ` Jeff Layton [this message]
2017-06-15 20:59 ` [PATCH v2 2/2] NFS: nfs_rename() - revalidate directories on -ERESTARTSYS Benjamin Coddington
2017-06-15 21:09 ` Jeff Layton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1497561085.4607.19.camel@redhat.com \
--to=jlayton@redhat.com \
--cc=anna.schumaker@netapp.com \
--cc=bcodding@redhat.com \
--cc=bfields@redhat.com \
--cc=linux-nfs@vger.kernel.org \
--cc=mszeredi@redhat.com \
--cc=trond.myklebust@primarydata.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.