Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp25282rwl; Thu, 13 Apr 2023 20:07:15 -0700 (PDT) X-Google-Smtp-Source: AKy350ZMZk6lnTGDVeEPslSCpXfcPXSoGAhFpWQQPk/+gPtUp3gsn2bQ9rnnbelVaWin3U+YpwnW X-Received: by 2002:a5d:8710:0:b0:74c:c6ed:6de with SMTP id u16-20020a5d8710000000b0074cc6ed06demr2843166iom.12.1681441634941; Thu, 13 Apr 2023 20:07:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681441634; cv=none; d=google.com; s=arc-20160816; b=kupTIKIPklMvqhTsso/NIqbiVwSay3SNO6Bho5LP78xRiND1+2hGb+a6moToB17KXZ S3nhpfKo6aZ3usdew4oE8Fu5Y65K0XwMj18lMu0i9/mj7AXrGmPpasATlPuVRrfndUa9 u/I41tWrcgzOf2fOBsUDKZUmTiX35G+P6eXERx2VZpiXt5SiC1gxbT6WIgnaSsbIkiK4 kXdmLbmgX+FQ5OYqdZrstzCbDYUU8stFOOJtjLabEwoX38mx5qmo8xGdWYM74HP2WaOU ht7zxEF9gnj8/JsHx/xV58ZiDv4qoYbBBcuiYJpb3DzBFS9hQ/UqDoCME2dPOecTFOaR +meQ== 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 :dkim-signature; bh=arnTy/k2SDXcsFTbM5uG7lhSXpUi+P+pNKJGwnp46Os=; b=pN3bK5iKK7cmyvJaWAm2uReTIPLI393q1Ept0maIJQzbnU6J63OHrHHsx+/3xLseVa Ii1BLzsba3kv5e/9L5urCv640+jlIACD4056tlCAxe+Kk/GCp0cvICcOEFeXsvry19aO TDO3S+DIGZDe8lTRvm2BqQ9JC3COVWBo3nEukSL84yQfYry5wUi8I+OvB/PTWhe9gInv kVrwIcY9eWbLAo4Gej21e/9yrn09zW24lJWAlHHJQXzkUfngTdg9o39blf8XFZmnaLM0 f3n0pcMKI2etYcTC2QD1OfONqKL5IbktTI8w4moq6mA8htO61+mKxxR8ivMsHf9G0LUV Mc/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=gDsGw3PK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l42-20020a02666a000000b0040bd4f2fceasi2731062jaf.158.2023.04.13.20.07.00; Thu, 13 Apr 2023 20:07:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=gDsGw3PK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229540AbjDNCzT (ORCPT + 99 others); Thu, 13 Apr 2023 22:55:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbjDNCzS (ORCPT ); Thu, 13 Apr 2023 22:55:18 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B7942722 for ; Thu, 13 Apr 2023 19:55:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=arnTy/k2SDXcsFTbM5uG7lhSXpUi+P+pNKJGwnp46Os=; b=gDsGw3PKon86S5e5ztCdSyuKHR bQpcFt9JrAMlPnGiC+gQB6h97/MuUfdXbtPnuEA0stj/Z8fa6b3Be9EMNzWv7KvbRntbFQjoRBCvG KtqxJPp3TbJfedpipSmo8BeRLICvNurjags46myra516KT3Vy4wR+zcZm5+JMJDKMiM0w93j9m6CI ogvbo7AlFbFyV3X1DUnrPDFgHAWZEbz/KkBqEp6hD5nuLSvMO29K4wYpWVqGVH2GNW/aidNa9a5gx KQUhYxuPXkH/Bmx996UxCgcIHIasXR8BfOZXmVYfXXujFC6+QxTTd02R79bog4xBKQTf+uZ8rVxz2 8FjrWLXQ==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1pn9al-008pIY-2I; Fri, 14 Apr 2023 02:55:15 +0000 Date: Fri, 14 Apr 2023 03:55:15 +0100 From: Al Viro To: Richard Cochran Cc: linux-kernel@vger.kernel.org Subject: Re: Weirdness with bind mounts and moving files from tmpfs Message-ID: <20230414025515.GG3390869@ZenIV> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 13, 2023 at 05:23:13PM -0700, Richard Cochran wrote: > So far, so good. Now do the same, but with 'mv' instead of 'cp'... > > # echo three > /run/file > # mv /run/file /home/file > # cat /opt/file > two > > At this point, the contents of /opt/file are stuck forever with "two"... > > # echo three > /run/file > # cp /run/file /home/file > # cat /opt/file > two > # echo three > /home/file > # cat /opt/file > two > > What is going on here? Is this a bug or a feature? strace and compare the traces... cp(1) opens the existing target, truncates and writes to it; mv(1) tries rename(), falling back to unlink()+creat()+write() in case rename() failed with -EXDEV. The same behaviour can be seen without any mount(2) use: ; echo x > a ; ln a b ; echo y > c ; cat a x ; cat b x ; cat c y ; cp c a ; cat b y ; echo x > a ; cat a x ; cat b x ; mv c a ; cat a y ; cat b x ; Exact same underlying cause - writing down what happens step-by-step might be enlightening...