All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Richard Cochran <richardcochran@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Weirdness with bind mounts and moving files from tmpfs
Date: Fri, 14 Apr 2023 03:55:15 +0100	[thread overview]
Message-ID: <20230414025515.GG3390869@ZenIV> (raw)
In-Reply-To: <ZDic8fx1NQirB2+d@hoboy.vegasvil.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...

      reply	other threads:[~2023-04-14  2:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14  0:23 Weirdness with bind mounts and moving files from tmpfs Richard Cochran
2023-04-14  2:55 ` Al Viro [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230414025515.GG3390869@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.