public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: viro@ZenIV.linux.org.uk, torvalds@linux-foundation.org,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	hch@infradead.org, akpm@linux-foundation.org,
	dhowells@redhat.com, zab@redhat.com, jack@suse.cz,
	luto@amacapital.net, mszeredi@suse.cz
Subject: Re: [PATCH 05/11] vfs: add RENAME_NOREPLACE flag
Date: Wed, 15 Jan 2014 13:19:55 -0500	[thread overview]
Message-ID: <20140115181955.GA5715@fieldses.org> (raw)
In-Reply-To: <1389219015-10980-6-git-send-email-miklos@szeredi.hu>

On Wed, Jan 08, 2014 at 11:10:09PM +0100, Miklos Szeredi wrote:
> From: Miklos Szeredi <mszeredi@suse.cz>
> 
> If this flag is specified and the target of the rename exists then the
> rename syscall fails with EEXIST.

Why is this useful?

(I'm sure it is, it'd just be useful to have the reasons recorded
someplace.)

> The VFS does the existence checking, so it is trivial to enable for most
> local filesystems.  This patch only enables it in ext4.
> 
> For network filesystems the VFS check is not enough as there may be a race
> between a remote create and the rename, so these filesystems need to handle
> this flag in their ->rename() implementations to ensure atomicity.

Till that's done this should probably result in -EOPNOTSUPP on those
filesystems?

I think this would need new protocol in the NFS case.

--b.

> 
> Suggested-by: Andy Lutomirski <luto@amacapital.net>
> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
> ---
>  fs/ext4/namei.c         |  2 +-
>  fs/namei.c              | 21 +++++++++++++--------
>  include/uapi/linux/fs.h |  2 ++
>  3 files changed, 16 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 08c40f4e7eed..e0129b6e74cf 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -3021,7 +3021,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
>  	int inlined = 0, new_inlined = 0;
>  	struct ext4_dir_entry_2 *parent_de;
>  
> -	if (flags)
> +	if (flags & ~RENAME_NOREPLACE)
>  		return -EOPNOTSUPP;
>  
>  	dquot_initialize(old_dir);
> diff --git a/fs/namei.c b/fs/namei.c
> index 593673fcbfef..f9cf3020394c 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -4123,7 +4123,7 @@ SYSCALL_DEFINE5(renameat2, int, olddfd, const char __user *, oldname,
>  	bool should_retry = false;
>  	int error;
>  
> -	if (flags)
> +	if (flags & ~RENAME_NOREPLACE)
>  		return -EOPNOTSUPP;
>  
>  retry:
> @@ -4149,6 +4149,8 @@ retry:
>  		goto exit2;
>  
>  	new_dir = newnd.path.dentry;
> +	if (flags & RENAME_NOREPLACE)
> +		error = -EEXIST;
>  	if (newnd.last_type != LAST_NORM)
>  		goto exit2;
>  
> @@ -4171,22 +4173,25 @@ retry_deleg:
>  	error = -ENOENT;
>  	if (d_is_negative(old_dentry))
>  		goto exit4;
> +	new_dentry = lookup_hash(&newnd);
> +	error = PTR_ERR(new_dentry);
> +	if (IS_ERR(new_dentry))
> +		goto exit4;
> +	error = -EEXIST;
> +	if ((flags & RENAME_NOREPLACE) && d_is_positive(new_dentry))
> +		goto exit5;
>  	/* unless the source is a directory trailing slashes give -ENOTDIR */
>  	if (!d_is_dir(old_dentry)) {
>  		error = -ENOTDIR;
>  		if (oldnd.last.name[oldnd.last.len])
> -			goto exit4;
> +			goto exit5;
>  		if (newnd.last.name[newnd.last.len])
> -			goto exit4;
> +			goto exit5;
>  	}
>  	/* source should not be ancestor of target */
>  	error = -EINVAL;
>  	if (old_dentry == trap)
> -		goto exit4;
> -	new_dentry = lookup_hash(&newnd);
> -	error = PTR_ERR(new_dentry);
> -	if (IS_ERR(new_dentry))
> -		goto exit4;
> +		goto exit5;
>  	/* target should not be an ancestor of source */
>  	error = -ENOTEMPTY;
>  	if (new_dentry == trap)
> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
> index 6c28b61bb690..9250f4dd7d96 100644
> --- a/include/uapi/linux/fs.h
> +++ b/include/uapi/linux/fs.h
> @@ -35,6 +35,8 @@
>  #define SEEK_HOLE	4	/* seek to the next hole */
>  #define SEEK_MAX	SEEK_HOLE
>  
> +#define RENAME_NOREPLACE	(1 << 0)	/* Don't overwrite target */
> +
>  struct fstrim_range {
>  	__u64 start;
>  	__u64 len;
> -- 
> 1.8.1.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2014-01-15 18:20 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-08 22:10 [PATCH 00/11] cross rename v3 Miklos Szeredi
2014-01-08 22:10 ` [PATCH 01/11] vfs: add d_is_dir() Miklos Szeredi
2014-01-08 22:10 ` [PATCH 02/11] vfs: rename: move d_move() up Miklos Szeredi
2014-01-08 22:10 ` [PATCH 03/11] vfs: rename: use common code for dir and non-dir Miklos Szeredi
2014-01-08 22:10 ` [PATCH 04/11] vfs: add renameat2 syscall Miklos Szeredi
2014-01-14 22:11   ` Tetsuo Handa
2014-01-15 10:30     ` Miklos Szeredi
2014-01-15 13:50       ` Miklos Szeredi
2014-01-18 10:40         ` Tetsuo Handa
2014-01-08 22:10 ` [PATCH 05/11] vfs: add RENAME_NOREPLACE flag Miklos Szeredi
2014-01-15 18:19   ` J. Bruce Fields [this message]
2014-01-15 18:26     ` Andy Lutomirski
2014-01-15 23:33       ` J. Bruce Fields
2014-01-16 10:45         ` Miklos Szeredi
2014-01-15 18:35     ` Miklos Szeredi
2014-01-15 23:31       ` J. Bruce Fields
2014-01-08 22:10 ` [PATCH 06/11] security: add flags to rename hooks Miklos Szeredi
2014-01-08 22:10 ` [PATCH 07/11] vfs: add cross-rename Miklos Szeredi
2014-01-13  7:52   ` Jan Kara
2014-01-14 10:31     ` Miklos Szeredi
2014-01-14 12:47       ` Jan Kara
2014-01-08 22:10 ` [PATCH 08/11] ext4: rename: create ext4_renament structure for local vars Miklos Szeredi
2014-01-08 22:10 ` [PATCH 09/11] ext4: rename: move EMLINK check up Miklos Szeredi
2014-01-08 22:10 ` [PATCH 10/11] ext4: rename: split out helper functions Miklos Szeredi
2014-01-08 22:10 ` [PATCH 11/11] ext4: add cross rename support Miklos Szeredi
2014-01-13 12:25   ` Jan Kara
2014-01-14 10:35     ` Miklos Szeredi
2014-01-15 18:23     ` J. Bruce Fields
2014-01-15 18:31       ` Miklos Szeredi
2014-01-16 10:54         ` Miklos Szeredi
2014-01-16 14:48           ` J. Bruce Fields
2014-01-17 10:53           ` Michael Kerrisk (man-pages)
2014-01-17 14:41             ` Miklos Szeredi
2014-04-19  9:08               ` Michael Kerrisk (man-pages)
2014-04-19 12:08                 ` Tetsuo Handa
2014-04-23 14:24                   ` Miklos Szeredi
2014-04-24 11:20                     ` [PATCH (for 3.15) 0/5] Fix cross rename race window for LSM Tetsuo Handa
2014-04-24 11:22                       ` [PATCH (for 3.15) 1/5] LSM: Pass the rename flags to each LSM module Tetsuo Handa
2014-04-25 20:49                         ` Casey Schaufler
2014-04-24 11:23                       ` [PATCH (for 3.15) 2/5] SELinux: Handle the rename flags Tetsuo Handa
2014-04-24 11:24                       ` [PATCH (for 3.15) 3/5] AppArmor: " Tetsuo Handa
2014-04-24 11:25                       ` [PATCH (for 3.15) 4/5] TOMOYO: " Tetsuo Handa
2014-04-24 11:26                       ` [PATCH (for 3.15) 5/5] LSM: Remove duplicated rename handling Tetsuo Handa
2014-05-01 11:58                       ` [PATCH (for 3.15) 0/5] Fix cross rename race window for LSM Tetsuo Handa
2014-05-05  5:49                         ` Tetsuo Handa
2014-05-11 15:53                           ` Tetsuo Handa
2014-05-12 13:21                             ` [PATCH (for 3.15) 0/5] Fix cross rename regressions " Tetsuo Handa
2014-05-12 13:22                               ` [PATCH (for 3.15) 1/5] LSM: Pass the rename flags to each LSM module Tetsuo Handa
2014-05-19 12:19                                 ` John Johansen
2014-05-12 13:23                               ` [PATCH (for 3.15) 2/5] SELinux: Handle the rename flags Tetsuo Handa
2014-05-12 13:24                               ` [PATCH (for 3.15) 3/5] AppArmor: " Tetsuo Handa
2014-05-19 12:28                                 ` John Johansen
2014-05-12 13:25                               ` [PATCH (for 3.15) 4/5] TOMOYO: " Tetsuo Handa
2014-05-12 13:25                               ` [PATCH (for 3.15) 5/5] LSM: Remove duplicated rename handling Tetsuo Handa
2014-05-19 12:34                                 ` John Johansen
2014-04-23 14:21                 ` [PATCH 11/11] ext4: add cross rename support Miklos Szeredi
2014-04-23 19:01                   ` Michael Kerrisk (man-pages)
2014-01-17 22:08             ` J. Bruce Fields
2014-01-18  6:49               ` Miklos Szeredi
2014-01-18 16:27                 ` J. Bruce Fields
2014-01-20 11:39                   ` Miklos Szeredi
2014-01-20 11:50                     ` Michael Kerrisk (man-pages)
2014-01-13 12:46 ` [PATCH 00/11] cross rename v3 Tetsuo Handa
2014-01-13 17:08   ` Miklos Szeredi
2014-01-13 22:03     ` Tetsuo Handa
2014-01-14  9:58       ` Miklos Szeredi
2014-01-14 13:03         ` Tetsuo Handa
2014-01-14 20:10           ` John Johansen
2014-01-14 20:53             ` Tetsuo Handa
2014-01-15 10:10               ` Miklos Szeredi
  -- strict thread matches above, loose matches on Subject: below --
2013-11-20 13:01 [PATCH 00/11] cross rename v2 Miklos Szeredi
2013-11-20 13:01 ` [PATCH 05/11] vfs: add RENAME_NOREPLACE flag 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=20140115181955.GA5715@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=hch@infradead.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=miklos@szeredi.hu \
    --cc=mszeredi@suse.cz \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@ZenIV.linux.org.uk \
    --cc=zab@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox