Re: subvolumes: default and IDs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Florian,

in case you would like to have some code references, to better
understand how it works:
1. Why is the default subvolid=5?
The trees in Btrfs all are referenced in the root tree by their
OBJECTIDs. You can find the definitions("magic numbers") for the
"main" trees in ctree.h:
For example, the main FS tree (you have one FS tree per subvolume) is
defined like this:
#define BTRFS_FS_TREE_OBJECTID 5ULL
==> subvolid=5

2. Why can I mount with -o subvolid=0 succesfully, albeit the default
FS tree has subvolid=5?
Have a look at: linux/fs/btrfs/super.c
In early mount options parser: btrfs_parse_early_options
Snippet:
         case Opt_subvolid:
                        intarg = 0;
                        error = match_int(&args[0], &intarg);
                        if (!error) {
                                /* we want the original fs_tree */
/*Here is the trick ==> */              if (!intarg)
                                        *subvol_objectid =
                                           BTRFS_FS_TREE_OBJECTID;
                                else
                                        *subvol_objectid = intarg;
                        }
                        break;
==> So, if intarg is still 0 after the match_int line, it will use
BTRFS_FS_TREE_OBJECTID (which we know from 1. being 5ULL) when
mounting.

Best Regards,
Alex

2012/7/30 Florian Lindner <mailinglists@xxxxxx>:
> Hey!
>
> I recently starting playing with btrfs and subvolume, but it has left
> me puzzled:
> Distribution is Archlinux, Kernel is 3.4.6.
>
>>>>
> root@horus /mnt # mkfs.btrfs -L test /dev/sdb1
>
> WARNING! - Btrfs Btrfs v0.19 IS EXPERIMENTAL
> WARNING! - see http://btrfs.wiki.kernel.org before using
>
> fs created label test on /dev/sdb1
>         nodesize 4096 leafsize 4096 sectorsize 4096 size 2.73TB
> Btrfs Btrfs v0.19
> root@horus /mnt # mount /dev/sdb1 test
> root@horus /mnt # cd test
> root@horus /mnt/test # btrfs subvolume create sv1
> Create subvolume './sv1'
> root@horus /mnt/test # btrfs subvolume create sv2
> Create subvolume './sv2'
> root@horus /mnt/test # touch sv1/sv1.file
> root@horus /mnt/test # touch sv2/sv2.file
> root@horus /mnt/test # btrfs subvolume get-default .
> ID 256 top level 5 path sv1
> ID 259 top level 5 path sv2
> <<<
>
> What is the default subvolume now? How can I tell?
>
>>>>
> root@horus /mnt/test # btrfs subvolume set-default 259 .
> root@horus /mnt/test # btrfs subvolume get-default .
> ID 256 top level 5 path sv1
> ID 259 top level 5 path sv2
> <<<
>
> Seems to have changed nothing....?
>
>>>>
> root@horus /mnt/test # cd ..
> root@horus /mnt # umount test && mount /dev/sdb1 test
> root@horus /mnt # ls test
> sv2.file
> <<<
>
> Ah, sv2 seems to be default, like I had set it.
>
>>>>
> root@horus /mnt # btrfs subvolume set-default 5 test
> root@horus /mnt # umount test && /mnt # mount /dev/sdb1 test
> root@horus /mnt # ls test
> sv1/  sv2/
> <<<
>
> Ok, 5 seems to be the root subvolume id. Is it always like that? I
> remembered to have read somewhere it was 0 ? (which makes a kind of
> more sense for me)
>
>>>>
> root@horus /mnt # btrfs subvolume set-default 256 test
> root@horus /mnt # umount test && mount /dev/sdb1 test
> root@horus /mnt # ls test
> sv1.file
> <<<
>
> Fine! But:
>
>>>>
> root@horus /mnt # btrfs subvolume set-default 0 test
> root@horus /mnt # umount test && mount /dev/sdb1 test
> root@horus /mnt # ls test
> sv1.file
> <<<
>
> set-default 0 seems to do nothing but does not produce an error
> either. What about subvolume 0? Still I can do:
>
>>>>
> root@horus /mnt # umount test
> root@horus /mnt # mount -o subvolid=0 /dev/sdb1 test
> root@horus /mnt # ls test
> sv1/  sv2/
> <<<
>
> Ok, here 0 as subvolid works. What about subvolid=5?
>
>>>>
> root@horus /mnt # umount test
> root@horus /mnt # mount -o subvolid=5 /dev/sdb1 test
> root@horus /mnt # ls test
> sv1/  sv2/
> <<<
>
> Works too.
>
> Sorry for the lengthy posting, but writing this posting has puzzled me
> even more I was yesterday. I hope someone could shed some light on it.
>
> Thanks!
>
> Florian
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux