From: Hugh Dickins <hughd@google.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-kernel@vger.kernel.org, hch@infradead.org,
viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
Miklos Szeredi <mszeredi@suse.cz>,
Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH 5/7] shmem: support RENAME_EXCHANGE
Date: Thu, 24 Jul 2014 04:09:19 -0700 (PDT) [thread overview]
Message-ID: <alpine.LSU.2.11.1407240408500.1136@eggly.anvils> (raw)
In-Reply-To: <1406121336-1379-6-git-send-email-miklos@szeredi.hu>
On Wed, 23 Jul 2014, Miklos Szeredi wrote:
> From: Miklos Szeredi <mszeredi@suse.cz>
>
> This is really simple in tmpfs since the VFS already takes care of
> shuffling the dentries. Just adjust nlink on parent directories and touch
> c & mtimes.
>
> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
> Cc: Hugh Dickins <hughd@google.com>
Acked-by: Hugh Dickins <hughd@google.com>
> ---
> mm/shmem.c | 27 ++++++++++++++++++++++++++-
> 1 file changed, 26 insertions(+), 1 deletion(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 791b05514f9a..75d5ac806f1e 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -2016,6 +2016,28 @@ static int shmem_rmdir(struct inode *dir, struct dentry *dentry)
> return shmem_unlink(dir, dentry);
> }
>
> +static int shmem_exchange(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry)
> +{
> + bool old_is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
> + bool new_is_dir = S_ISDIR(new_dentry->d_inode->i_mode);
> +
> + if (old_dir != new_dir && old_is_dir != new_is_dir) {
> + if (old_is_dir) {
> + drop_nlink(old_dir);
> + inc_nlink(new_dir);
> + } else {
> + drop_nlink(new_dir);
> + inc_nlink(old_dir);
> + }
> + }
> + old_dir->i_ctime = old_dir->i_mtime =
> + new_dir->i_ctime = new_dir->i_mtime =
> + old_dentry->d_inode->i_ctime =
> + new_dentry->d_inode->i_ctime = CURRENT_TIME;
> +
> + return 0;
> +}
> +
> /*
> * The VFS layer already does all the dentry stuff for rename,
> * we just have to decrement the usage count for the target if
> @@ -2027,9 +2049,12 @@ static int shmem_rename2(struct inode *old_dir, struct dentry *old_dentry, struc
> struct inode *inode = old_dentry->d_inode;
> int they_are_dirs = S_ISDIR(inode->i_mode);
>
> - if (flags & ~(RENAME_NOREPLACE))
> + if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE))
> return -EINVAL;
>
> + if (flags & RENAME_EXCHANGE)
> + return shmem_exchange(old_dir, old_dentry, new_dir, new_dentry);
> +
> if (!simple_empty(new_dentry))
> return -ENOTEMPTY;
>
> --
> 1.8.1.4
next prev parent reply other threads:[~2014-07-24 11:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-23 13:15 [PATCH 0/7] first iteration of rename2 support Miklos Szeredi
2014-07-23 13:15 ` [PATCH 1/7] vfs: call rename2 if exists Miklos Szeredi
2014-07-23 13:15 ` [PATCH 2/7] bad_inode: add ->rename2() Miklos Szeredi
2014-07-23 13:15 ` [PATCH 3/7] btrfs: add RENAME_NOREPLACE Miklos Szeredi
2014-07-23 13:15 ` [PATCH 4/7] shmem: support RENAME_NOREPLACE Miklos Szeredi
2014-07-24 11:08 ` Hugh Dickins
2014-07-24 11:21 ` Miklos Szeredi
2014-07-23 13:15 ` [PATCH 5/7] shmem: support RENAME_EXCHANGE Miklos Szeredi
2014-07-24 11:09 ` Hugh Dickins [this message]
2014-07-23 13:15 ` [PATCH 6/7] hostfs: support rename flags Miklos Szeredi
2014-07-23 13:15 ` [PATCH 7/7] cifs: support RENAME_NOREPLACE Miklos Szeredi
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=alpine.LSU.2.11.1407240408500.1136@eggly.anvils \
--to=hughd@google.com \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=mszeredi@suse.cz \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).