[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230414025515.GG3390869@ZenIV>
Date: Fri, 14 Apr 2023 03:55:15 +0100
From: Al Viro <viro@...iv.linux.org.uk>
To: Richard Cochran <richardcochran@...il.com>
Cc: linux-kernel@...r.kernel.org
Subject: Re: Weirdness with bind mounts and moving files from tmpfs
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...
Powered by blists - more mailing lists