Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5445690ybl; Tue, 14 Jan 2020 09:04:04 -0800 (PST) X-Google-Smtp-Source: APXvYqx4iYbAxzblWG52tDuHOigTJeEzDuxr9F9hN82YknHOteWQ0klL5sKIjFBSnfbZx0MAa1bv X-Received: by 2002:a05:6830:1689:: with SMTP id k9mr18302191otr.311.1579021444923; Tue, 14 Jan 2020 09:04:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579021444; cv=none; d=google.com; s=arc-20160816; b=M3zMioRDHfD37dY4UTIkwmk9emiG77AnQ/NgyFw1odf+jMVQ1hMe+F2J9udjgZTAQn 688Jsmbe7vIC+OTTcvCDa5JnHLt4fg8mOxRWazUhS6zCp7AadGEfroH2WLh3oBVwQ45/ pvdLw9fZYdVNqocFUfIcaGdpqJBSZ5UxMFQVrRPcQDSBT7rUN6NuV3VFPqcLghzpJopm dAljuLQanmJUEGIjyAgwaqtffSKdWhtV1O1SrZUwFawRQVbgJyIhQM7UtnP0iVv8EioU LBm+OOL/TRZ96AO4aDaWb9qYXQw4HSG4VYLSYTK2NsFnBT7HHit5RyzQIlkvwYL+ydiu EY2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Nu0hNco2xL9lZsLRyBGnUidngAhucaueTcaKpG0fp8o=; b=z0RnR1hAMza1/HdnQMv8p/AVSJNb8CGudSZvnEFzqHWO3JkfPj1c+l3VvHyo1mcj1p wVO0vRjrpHsyh9oEgtyklr2FVwg/1BeiZ7pJcGLX52WmBQRDImWyFot5XHhld20oJpPL WeQ3HTqQIh9OKMbL/JLHGF4JJNLJn7z3eGI+f8fH/hwMxavJq+/i9Cu7zx3Dzqi7wugG TPwWqiBH+EUUN8588+eq/uTeBi/WFxhVMTl+xiQWrCQHe5HgsIjChuDuhrwUJJsMx7Gi 3PuewTz7L1OTfsa3kZ73IBFOrfiI3QUshWhu2QTleOlI80/hcUU7MHvkeb36WaJFD5JQ uarQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p62si7552254oig.101.2020.01.14.09.03.39; Tue, 14 Jan 2020 09:04:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728650AbgANRCz (ORCPT + 99 others); Tue, 14 Jan 2020 12:02:55 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:42680 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbgANRCy (ORCPT ); Tue, 14 Jan 2020 12:02:54 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1irPac-0087wB-8a; Tue, 14 Jan 2020 17:02:50 +0000 Date: Tue, 14 Jan 2020 17:02:50 +0000 From: Al Viro To: David Howells Cc: linux-fsdevel@vger.kernel.org, hch@lst.de, tytso@mit.edu, adilger.kernel@dilger.ca, darrick.wong@oracle.com, clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Making linkat() able to overwrite the target Message-ID: <20200114170250.GA8904@ZenIV.linux.org.uk> References: <3326.1579019665@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3326.1579019665@warthog.procyon.org.uk> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Tue, Jan 14, 2020 at 04:34:25PM +0000, David Howells wrote: > With my rewrite of fscache and cachefiles: > > https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=fscache-iter > > when a file gets invalidated by the server - and, under some circumstances, > modified locally - I have the cache create a temporary file with vfs_tmpfile() > that I'd like to just link into place over the old one - but I can't because > vfs_link() doesn't allow you to do that. Instead I have to either unlink the > old one and then link the new one in or create it elsewhere and rename across. > > Would it be possible to make linkat() take a flag, say AT_LINK_REPLACE, that > causes the target to be replaced and not give EEXIST? Or make it so that > rename() can take a tmpfile as the source and replace the target with that. I > presume that, either way, this would require journal changes on ext4, xfs and > btrfs. Umm... I don't like the idea of linkat() doing that - you suddenly get new fun cases to think about (what should happen when the target is a mountpoint, for starters?) _and_ you would have to add a magical flag to vfs_link() so that it would know which tests to do. As for rename... How would that work? AT_EMPTY_PATH for source? What happens if two threads do that at the same time? Should that case be always "create a new link, even if you've got it by plain lookup somewhere"? Worse, suppose you do that to given tmpfile; what should happen to /proc/self/fd/* link to it? Should it point to new location, or...?