On Tue, Apr 24, 2018 at 08:26:10AM -0700, Omar Sandoval wrote: > On Tue, Apr 24, 2018 at 06:21:07AM -0700, Christoph Hellwig wrote: > > > Patch 1 implements the VFS support for this flag. The implementation > > > resembles sys_renameat2(), and I took care to preserve all of the > > > original error cases and make the new error cases consistent with > > > rename. > > > > Shouldn't we try to reuse the rename code and the ->rename method > > instead of largely duplicating it? > > As I mentioned in my cover letter, I did try, and it was uglier to reuse > rename. > > For O_TMPFILE, we can't pass a meaningful old_dir to ->rename(), so now > every ->rename() supporting AT_EMPTY_PATH has to grow a bunch of special > cases for ignoring old_dir (I looked at Btrfs, ext4, and XFS, and it'd > be messy for all three). Conversely, ->link() just needs the extra > unlink before link logic (I added ->link2() for this RFC, but for the > actual patch I'll just add the flag to ->link()). > > On the VFS side, in my opinion, there isn't that much duplication -- we > have the may_delete()/is_local_mountpoint() a la unlink, delegation > handling, and some specific error cases we need to handle similarly to > rename, but that's not too suprising for a new primitive. > > > In fact I wonder if a better interface would just use renameat(2) > > and accept the AT_EMPTY_PATH (for the source name only). > > renameat() makes sense for the O_TMPFILE case, but linkat() + AT_REPLACE > also supports a normal, named source file, and renameat() + > AT_EMPTY_PATH for that doesn't make sense at all (rename this file by > file descriptor, but don't really rename it?). Oh, another argument in favor of linkat() is that existing programs which are naming an O_TMPFILE will already be using linkat(), and it's just a matter of adding the AT_REPLACE flag and skipping the temporary name/rename dance.