From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f51.google.com ([74.125.83.51]:32905 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751155AbeDXP0M (ORCPT ); Tue, 24 Apr 2018 11:26:12 -0400 Received: by mail-pg0-f51.google.com with SMTP id i194so11131175pgd.0 for ; Tue, 24 Apr 2018 08:26:12 -0700 (PDT) Date: Tue, 24 Apr 2018 08:26:10 -0700 From: Omar Sandoval To: Christoph Hellwig Cc: Al Viro , linux-fsdevel@vger.kernel.org, Linus Torvalds , linux-api@vger.kernel.org, kernel-team@fb.com, Xi Wang Subject: Re: [RFC PATCH v3 0/2] fs: add AT_REPLACE flag for linkat() Message-ID: <20180424152610.GA6989@vader> References: <20180424132107.GA14919@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180424132107.GA14919@infradead.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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?).