i have read just recently and in the past that btrfs supports COW for _any_ file/directory (this is reflinks, yes?), and today i accidentally noticed that i can mount a directory as well (if it''s in the top level volume at least). eg. if i have a "regular" directory (not a subvolume) in the top-level: /__boot i can mount it with: mount -o subvol=__boot /dev/sda /mnt is this supposed to be supported via the "subvol" mount option? though it sounds like i''ve answered my own question, i ask because playing around with this caused my kernel to oops for the first time in a long, long time (on .35 but just about to upgrade to .36 in about 10 min). i am working on an update to my initramfs hook that will utilize extlinux, and this property to provide seamless kernel level system rollbacks, and i want to make sure it''s safe to do this. also, is there a way to target an arbitrary directory? does "subvol" support paths yet, or maybe via "subvolid" somehow? essentially i just want to mount a directory inside a snapshot at /boot, so when users upgrade there kernels, the images are visible to extlinux (which cannot yet peek inside or use subvolumes, so it has to be a regular directory in the top-level volume) any insight is much appreciated. C Anthony -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sat, 2010-11-27 at 21:19 -0600, C Anthony Risinger wrote:> i have read just recently and in the past that btrfs supports COW for > _any_ file/directory (this is reflinks, yes?), and today i > accidentally noticed that i can mount a directory as well (if it''s in > the top level volume at least). > > eg. if i have a "regular" directory (not a subvolume) in the top-level: > > /__boot > > i can mount it with: > > mount -o subvol=__boot /dev/sda /mntThe ''subvol'' option actually works using the same mechanism as a bind mount. The fact that it works using a directory is purely a coincidence - I would not expect it to be officially supported, and you shouldn''t rely on it.> i am working on an update to my initramfs hook that will utilize > extlinux, and this property to provide seamless kernel level system > rollbacks, and i want to make sure it''s safe to do this.To handle system rollbacks, you really should be using subvolumes and snapshots, not regular directories.> also, is there a way to target an arbitrary directory? does "subvol" > support paths yet, or maybe via "subvolid" somehow? essentially iI don''t think that it would be very hard to make subvol= support a path instead of only one level deep. Actually, I think I could make a patch for that myself... I''ve included it here. Mildly tested, but I''m not really a kernel programmer and might have missed something - particularly with regards to the locking.> just want to mount a directory inside a snapshot at /boot, so when > users upgrade there kernels, the images are visible to extlinux (which > cannot yet peek inside or use subvolumes, so it has to be a regular > directory in the top-level volume)Ah, this is the first I''ve heard that extlinux doesn''t support reading files in subvolumes. That''s an unfortunate limitation :/ ------------------------8<----------8<--------------------- From: Calvin Walton <calvin.walton@gmail.com> Date: Sat, 27 Nov 2010 23:17:55 -0500 Subject: [PATCH] Btrfs: Allow mounting sub-sub(-sub...)-volumes using subvol=a/b/c Currently you can only mount subvolumes which are direct children of the ''default'' root. I.e. with ID 258 top level 5 path a ID 259 top level 5 path a/b you could mount with "-o subvol=a" but not "-o subvol=a/b" This patch fixes that by recursively following the path to the subvolume. Signed-off-by: Calvin Walton <calvin.walton@gmail.com> --- fs/btrfs/super.c | 41 +++++++++++++++++++++++------------------ 1 files changed, 23 insertions(+), 18 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 8299a25..5e78c86 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -646,26 +646,31 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, /* if they gave us a subvolume name bind mount into that */ if (strcmp(subvol_name, ".")) { struct dentry *new_root; - mutex_lock(&root->d_inode->i_mutex); - new_root = lookup_one_len(subvol_name, root, - strlen(subvol_name)); - mutex_unlock(&root->d_inode->i_mutex); - - if (IS_ERR(new_root)) { - deactivate_locked_super(s); - error = PTR_ERR(new_root); - dput(root); - goto error_free_subvol_name; - } - if (!new_root->d_inode) { + char *subvol_name_next = subvol_name; + char *subvol_name_part; + + while ((subvol_name_part = strsep(&subvol_name_next, "/"))) { + mutex_lock(&root->d_inode->i_mutex); + new_root = lookup_one_len(subvol_name, root, + strlen(subvol_name)); + mutex_unlock(&root->d_inode->i_mutex); + + if (IS_ERR(new_root)) { + deactivate_locked_super(s); + error = PTR_ERR(new_root); + dput(root); + goto error_free_subvol_name; + } + if (!new_root->d_inode) { + dput(root); + dput(new_root); + deactivate_locked_super(s); + error = -ENXIO; + goto error_free_subvol_name; + } dput(root); - dput(new_root); - deactivate_locked_super(s); - error = -ENXIO; - goto error_free_subvol_name; + root = new_root; } - dput(root); - root = new_root; } kfree(subvol_name); -- 1.7.3.2 -- Calvin Walton <calvin.walton@gmail.com> -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
C Anthony Risinger
2010-Nov-28 09:41 UTC
Re: [RFC-PATCH] Re: mounting arbitrary directories
On Sat, Nov 27, 2010 at 10:22 PM, Calvin Walton <calvin.walton@gmail.com> wrote:> On Sat, 2010-11-27 at 21:19 -0600, C Anthony Risinger wrote: >> i have read just recently and in the past that btrfs supports COW for >> _any_ file/directory (this is reflinks, yes?), and today i >> accidentally noticed that i can mount a directory as well (if it''s in >> the top level volume at least). >> >> eg. if i have a "regular" directory (not a subvolume) in the top-level: >> >> /__boot >> >> i can mount it with: >> >> mount -o subvol=__boot /dev/sda /mnt > > The ''subvol'' option actually works using the same mechanism as a bind > mount. The fact that it works using a directory is purely a coincidence > - I would not expect it to be officially supported, and you shouldn''t > rely on it.ok, good to know.>> i am working on an update to my initramfs hook that will utilize >> extlinux, and this property to provide seamless kernel level system >> rollbacks, and i want to make sure it''s safe to do this. > > To handle system rollbacks, you really should be using subvolumes and > snapshots, not regular directories.i do use snapshots, but the kernels cannot be read from them by extlinux. i must manually sync to either the top level btrfs root or separate boot partition(s); this is required to handle kernel upgrades... else you end up running a kernel against modules/etc. built against an older/newer version. the only other way i could think of was to use a permanent intermediary kernel with the sole purpose of mounting the btrfs device, and kexec''ing the correct kernel within a snapshot.>> also, is there a way to target an arbitrary directory? does "subvol" >> support paths yet, or maybe via "subvolid" somehow? essentially i > > I don''t think that it would be very hard to make subvol= support a path > instead of only one level deep. Actually, I think I could make a patch > for that myself... I''ve included it here. Mildly tested, but I''m not > really a kernel programmer and might have missed something - > particularly with regards to the locking.nice, something like this is a good addition! if it''s really that simple it should definitely be included.>> just want to mount a directory inside a snapshot at /boot, so when >> users upgrade there kernels, the images are visible to extlinux (which >> cannot yet peek inside or use subvolumes, so it has to be a regular >> directory in the top-level volume) > > Ah, this is the first I''ve heard that extlinux doesn''t support reading > files in subvolumes. That''s an unfortunate limitation :/well i actually thought it was working... but i ended up wasting several hours only to learn that extlinux could "kind of" see them. basically, usually the first snapshot appeared correct, but it was really a recursive link back on itself. sometimes snapshots would be missing pieces -- seems to be related to COW; i think extlinux could only see the chunks in snapshots that were still shared with the top-level volume... but that''s a observational guess. needless to say, it really tripped me up for awhile until i remembered the "rosh.c32" module and manually peeked around a bit :-) C Anthony -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
C Anthony Risinger
2010-Nov-28 10:07 UTC
Re: [RFC-PATCH] Re: mounting arbitrary directories
On Nov 27, 2010, at 10:22 PM, Calvin Walton <calvin.walton@gmail.com> wrote:> On Sat, 2010-11-27 at 21:19 -0600, C Anthony Risinger wrote: >> i have read just recently and in the past that btrfs supports COW for >> _any_ file/directory (this is reflinks, yes?), and today i >> accidentally noticed that i can mount a directory as well (if it''s in >> the top level volume at least). >> >> eg. if i have a "regular" directory (not a subvolume) in the top- >> level: >> >> /__boot >> >> i can mount it with: >> >> mount -o subvol=__boot /dev/sda /mnt > > The ''subvol'' option actually works using the same mechanism as a bind > mount. The fact that it works using a directory is purely a > coincidence > - I would not expect it to be officially supported, and you shouldn''t > rely on it. > >> i am working on an update to my initramfs hook that will utilize >> extlinux, and this property to provide seamless kernel level system >> rollbacks, and i want to make sure it''s safe to do this. > > To handle system rollbacks, you really should be using subvolumes and > snapshots, not regular directories. > >> also, is there a way to target an arbitrary directory? does "subvol" >> support paths yet, or maybe via "subvolid" somehow? essentially i > > I don''t think that it would be very hard to make subvol= support a > path > instead of only one level deep. Actually, I think I could make a patch > for that myself... I''ve included it here. Mildly tested, but I''m not > really a kernel programmer and might have missed something - > particularly with regards to the locking. > >> just want to mount a directory inside a snapshot at /boot, so when >> users upgrade there kernels, the images are visible to extlinux >> (which >> cannot yet peek inside or use subvolumes, so it has to be a regular >> directory in the top-level volume) > > Ah, this is the first I''ve heard that extlinux doesn''t support reading > files in subvolumes. That''s an unfortunate limitation :/Hrrrm... Well I thought I''d be clever and use this little trick one time to update my kernel... Anyways I oops out like 3 times in a row (last func was <something>.clone in each IIRC) and now I''m stuck with only my mobile since my server isn''t set up yet and my SSD just failed on my netbook yesterday :-( Sooooo, if anyone can help me recover this partition long enough to grab a few things... I would be most grateful :-) I think I have everything critical, but I''d rather take another look :-) Right now I can''t mount; mount is failing w/bad superblock. /me promises to never recklessly sabotage himself after being warned < 6 hrs earlier C Anthony [mobile] -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
C Anthony Risinger
2010-Nov-29 17:42 UTC
Re: [RFC-PATCH] Re: mounting arbitrary directories
On Sun, Nov 28, 2010 at 4:07 AM, C Anthony Risinger <anthony@extof.me> wrote:> On Nov 27, 2010, at 10:22 PM, Calvin Walton <calvin.walton@gmail.com> > wrote: >> On Sat, 2010-11-27 at 21:19 -0600, C Anthony Risinger wrote: >> >>> eg. if i have a "regular" directory (not a subvolume) in the top- >>> level: >>> >>> /__boot >>> >>> i can mount it with: >>> >>> mount -o subvol=__boot /dev/sda /mnt >> >> The ''subvol'' option actually works using the same mechanism as a bind >> mount. The fact that it works using a directory is purely a >> coincidence >> - I would not expect it to be officially supported, and you shouldn''t >> rely on it. > > Hrrrm... Well I thought I''d be clever and use this little trick one > time to update my kernel... Anyways I oops out like 3 times in a row > (last func was <something>.clone in each IIRC) and now I''m stuck with > only my mobile since my server isn''t set up yet and my SSD just > failed on my netbook yesterday :-( > > Sooooo, if anyone can help me recover this partition long enough to > grab a few things... I would be most grateful :-) I think I have > everything critical, but I''d rather take another look :-) Right now I > can''t mount; mount is failing w/bad superblock. > > /me promises to never recklessly sabotage himself after being warned < > 6 hrs earlierany suggestions for me? i dd''ed the corrupt partition to an external disk because i need the machine back up and running, but if possible i''d like to get the image running again. i mounted it via loopback and as expected got the same errors: (will post the dmesg output next message -- left at home) open_ctree_fd failed.... wanted XXXX found YYYY instead the mount command itself fails with "bad superblock or ..." i have seen others withe similar crash reports and IIRC correctly were able to recover it (seems like something just didn''t get updated right before it locked...) any ideas? C Anthony -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
C Anthony Risinger
2010-Dec-03 09:41 UTC
Re: [RFC-PATCH] Re: mounting arbitrary directories
On Mon, Nov 29, 2010 at 11:42 AM, C Anthony Risinger <anthony@extof.me> wrote:> On Sun, Nov 28, 2010 at 4:07 AM, C Anthony Risinger <anthony@extof.me> wrote: >> On Nov 27, 2010, at 10:22 PM, Calvin Walton <calvin.walton@gmail.com> >> wrote: >>> On Sat, 2010-11-27 at 21:19 -0600, C Anthony Risinger wrote: >>> >>>> eg. if i have a "regular" directory (not a subvolume) in the top- >>>> level: >>>> >>>> /__boot >>>> >>>> i can mount it with: >>>> >>>> mount -o subvol=__boot /dev/sda /mnt >>> >>> The ''subvol'' option actually works using the same mechanism as a bind >>> mount. The fact that it works using a directory is purely a >>> coincidence >>> - I would not expect it to be officially supported, and you shouldn''t >>> rely on it. >> >> Hrrrm... Well I thought I''d be clever and use this little trick one >> time to update my kernel... Anyways I oops out like 3 times in a row >> (last func was <something>.clone in each IIRC) and now I''m stuck with >> only my mobile since my server isn''t set up yet and my SSD just >> failed on my netbook yesterday :-( >> >> Sooooo, if anyone can help me recover this partition long enough to >> grab a few things... I would be most grateful :-) I think I have >> everything critical, but I''d rather take another look :-) Right now I >> can''t mount; mount is failing w/bad superblock. >> >> /me promises to never recklessly sabotage himself after being warned < >> 6 hrs earlier > > any suggestions for me? i dd''ed the corrupt partition to an external > disk because i need the machine back up and running, but if possible > i''d like to get the image running again. i mounted it via loopback > and as expected got the same errors: > > (will post the dmesg output next message -- left at home) > open_ctree_fd failed.... > wanted XXXX found YYYY instead > > the mount command itself fails with "bad superblock or ..." > > i have seen others withe similar crash reports and IIRC correctly were > able to recover it (seems like something just didn''t get updated right > before it locked...) > > any ideas?dmesg output was: ------------------------------------------------------ device label root devid 1 transid 61235 /dev/loop0 parent transid verify failed on 11335634944 wanted 61235 found 61237 parent transid verify failed on 11335634944 wanted 61235 found 61237 parent transid verify failed on 11335634944 wanted 61235 found 61237 btrfs: open_ctree failed ------------------------------------------------------ i tried btrfsck as suggested in the recent thread: ------------------------------------------------------ # sudo losetup /dev/loop0 /mnt/btrfs.img # sudo btrfsck -s 1 /dev/loop0 using SB copy 1, bytenr 67108864 parent transid verify failed on 11335634944 wanted 61235 found 61237 parent transid verify failed on 11335634944 wanted 61235 found 61237 parent transid verify failed on 11335634944 wanted 61235 found 61237 btrfsck: disk-io.c:739: open_ctree_fd: Assertion `!(!tree_root->node)'' failed. # sudo btrfsck -s 2 /dev/loop0 using SB copy 2, bytenr 274877906944 No valid Btrfs found on /dev/loop0 ------------------------------------------------------ soooo... does this mean i''m totally boned for ever mounting this image again? or should i keep it around for later? or anything else i can try/do? C Anthony -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html