From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io0-f178.google.com ([209.85.223.178]:35203 "EHLO mail-io0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752749AbeDZHtg (ORCPT ); Thu, 26 Apr 2018 03:49:36 -0400 Received: by mail-io0-f178.google.com with SMTP id d26-v6so29964031ioc.2 for ; Thu, 26 Apr 2018 00:49:36 -0700 (PDT) Date: Thu, 26 Apr 2018 00:49:33 -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: <20180426074933.GA16273@vader> References: <20180424132107.GA14919@infradead.org> <20180424152610.GA6989@vader> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180424152610.GA6989@vader> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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.