On Thu, May 07, 2015 at 08:44:35AM +0000, sri wrote: > 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. 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. > 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. Yes, because it's the same filesystem according to the kernel. > 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? It's udev that does the "polling" that triggers the rescan that gives the kernel correct but inconsistent (and inconvenient for you) information. > since /dev/sdb and /dev/sdc contains same data, i can mount /dev/sdc > independently. 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. -- Hugo Mills | vi: The core of evil. hugo@... carfax.org.uk | http://carfax.org.uk/ | PGP: E2AB1DE4 |
Attachment:
signature.asc
Description: Digital signature
