strange behavior btrfs copy
Hi,
I have a btrfs file system /b1 on /dev/sdb with 2 subvolumes and 2 snapshots of them.
I have written a code which takes 2 disks as input source: /dev/sdb and destination as /dev/sdc and copies entire disk in 512 byte chunks to desination /dev/sdc.
my source btrfs /dev/sdb is mounted /b1 currently and mount command show the same.
I ran above program and it is successful. and now everything in /dev/sdb is copied to /dev/sdc
but after this when I run mount command at CLI, i am seeing strange behaviour and output show /dev/sdc is mounted on /b1.
Some how it changes device from /dev/sdb to /dev/sdc on the fliy.
I also tried to cd to /b1 (which make /b1 is in use) and ran same program, still after copy from /dev/sdb to /dev/sdc, mount shows /dev/sdc is mounted on /b1
what could be the reason for this?
does btrfs do any polling or something?
since /dev/sdb and /dev/sdc contains same data, i can mount /dev/sdc independently.
Quoted 8 lines · sri
Hi,
I have a btrfs file system /b1 on
/dev/sdbwith 2 subvolumes and 2 snapshots of them.I have written a code which takes 2 disks as input source:
/dev/sdband destination as/dev/sdcand copies entire disk in 512 byte chunks to desination/dev/sdc.
Don't do that. Really.
What you end up with is two devices containing the same filesystem,
*with the same UUID*. What then happens is that udev is likely to read the newly-modified device, and identify it as a btrfs filesystem. That then triggers a run of btrfs dev scan, which tells the kernel that /dev/sdb and /dev/sdc are part of the same filesystem (because they have the same UUID). When one (or, worse, both) of these are mounted, you get undefined behaviour, because it's treating both devices as part of the same FS.
Quoted 10 lines
my source btrfs
/dev/sdbis mounted /b1 currently and mount command show the same.I ran above program and it is successful. and now everything in
/dev/sdbis copied to/dev/sdcbut after this when I run mount command at CLI, i am seeing strange behaviour and output show
/dev/sdcis mounted on /b1.Some how it changes device from
/dev/sdbto/dev/sdcon the fliy.
Yes, because it's the same filesystem according to the kernel.
Quoted 8 lines
I also tried to cd to /b1 (which make /b1 is in use) and ran same program, still after copy from
/dev/sdbto/dev/sdc, mount shows/dev/sdcis mounted on /b1what could be the reason for this?
does btrfs do any polling or something?
It's udev that does the "polling" that triggers the rescan that
gives the kernel correct but inconsistent (and inconvenient for you) information.
Quoted 2 lines
since
/dev/sdband/dev/sdccontains same data, i can mount/dev/sdcindependently.
Well, you can't, because they're the same filesystem according to
the kernel...
Qu Wenruo posted a patch set recently (Tuesday) that gives the
capability of changing the UUID of a btrfs filesystem. If you really must do this copying, that's probably what you need. You will probably also have to turn off udev while the copy and UUID-changing is going on.
Hugo.
Signature · 4 lines
Hugo Mills | vi: The core of evil. hugo@... carfax.org.uk | http://carfax.org.uk/ | PGP: E2AB1DE4 |