lkml.org 
[lkml]   [2023]   [Apr]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 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...

\
 
 \ /
  Last update: 2023-04-14 04:55    [W:0.022 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site