linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: Al Viro <viro@zeniv.linux.org.uk>, linux-fsdevel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	linux-api@vger.kernel.org, kernel-team@fb.com,
	Xi Wang <xi@cs.washington.edu>
Subject: Re: [RFC PATCH v3 1/2] fs: add AT_REPLACE flag for linkat() which replaces the target
Date: Tue, 24 Apr 2018 15:14:43 -0700	[thread overview]
Message-ID: <20180424221443.GA9228@vader> (raw)
In-Reply-To: <eac9480f80c689504148b5d658ee4218cc1e421e.1524549513.git.osandov@fb.com>

On Mon, Apr 23, 2018 at 11:19:41PM -0700, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
> 
> One of the most common uses of temporary files is the classic atomic
> replacement pattern, i.e.,
> 
> - write temporary file
> - fsync temporary file
> - rename temporary file over real file
> - fsync parent directory
> 
> Now, we have O_TMPFILE, which gives us a much better way to create
> temporary files, but it's not possible to use it for this pattern.
> 
> This patch introduces an AT_REPLACE flag which allows linkat() to
> replace the target file. Now, the temporary file in the pattern above
> can be a proper O_TMPFILE. Even without O_TMPFILE, this is a new
> primitive which might be useful in other contexts.
> 
> The implementation on the VFS side mimics sys_renameat2().
> 
> Cc: Xi Wang <xi@cs.washington.edu>
> Signed-off-by: Omar Sandoval <osandov@fb.com>
> ---
>  fs/ecryptfs/inode.c        |   2 +-
>  fs/namei.c                 | 181 +++++++++++++++++++++++++++++--------
>  fs/nfsd/vfs.c              |   2 +-
>  fs/overlayfs/overlayfs.h   |   2 +-
>  include/linux/fs.h         |   3 +-
>  include/uapi/linux/fcntl.h |   1 +
>  6 files changed, 150 insertions(+), 41 deletions(-)
> 
> diff --git a/fs/namei.c b/fs/namei.c
> index 186bd2464fd5..2cc2b1deaa12 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -4149,6 +4149,7 @@ SYSCALL_DEFINE2(symlink, const char __user *, oldname, const char __user *, newn
>   * @dir:	new parent
>   * @new_dentry:	where to create the new link
>   * @delegated_inode: returns inode needing a delegation break
> + * @flags:      link flags
>   *
>   * The caller must hold dir->i_mutex
>   *
> @@ -4162,16 +4163,26 @@ SYSCALL_DEFINE2(symlink, const char __user *, oldname, const char __user *, newn
>   * be appropriate for callers that expect the underlying filesystem not
>   * to be NFS exported.
>   */
> -int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry, struct inode **delegated_inode)
> +int vfs_link(struct dentry *old_dentry, struct inode *dir,
> +	     struct dentry *new_dentry, struct inode **delegated_inode,
> +	     unsigned int flags)
>  {
>  	struct inode *inode = old_dentry->d_inode;
> +	struct inode *target = new_dentry->d_inode;
>  	unsigned max_links = dir->i_sb->s_max_links;
>  	int error;
>  
>  	if (!inode)
>  		return -ENOENT;
>  
> -	error = may_create(dir, new_dentry);
> +	if (target) {
> +		if (flags & AT_REPLACE)

This needs an

	if (inode == target)
		return 0;
		
I'll fix this in v4.

> +			error = may_delete(dir, new_dentry, d_is_dir(old_dentry));
> +		else
> +			error = -EEXIST;
> +	} else {
> +		error = may_create(dir, new_dentry);
> +	}
>  	if (error)
>  		return error;
>  

  reply	other threads:[~2018-04-24 22:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-24  6:19 [RFC PATCH v3 0/2] fs: add AT_REPLACE flag for linkat() Omar Sandoval
2018-04-24  6:19 ` [RFC PATCH v3 1/2] fs: add AT_REPLACE flag for linkat() which replaces the target Omar Sandoval
2018-04-24 22:14   ` Omar Sandoval [this message]
2018-04-24  6:19 ` [RFC PATCH v3 2/2] Btrfs: add support for linkat() AT_REPLACE Omar Sandoval
2018-04-24 13:21 ` [RFC PATCH v3 0/2] fs: add AT_REPLACE flag for linkat() Christoph Hellwig
2018-04-24 15:26   ` Omar Sandoval
2018-04-26  7:49     ` Omar Sandoval
2018-04-27 12:00 ` Michael Kerrisk (man-pages)
2018-05-04 18:29   ` Omar Sandoval
2018-05-04 18:30 ` Omar Sandoval

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=20180424221443.GA9228@vader \
    --to=osandov@osandov.com \
    --cc=kernel-team@fb.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xi@cs.washington.edu \
    /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).