Skip to contentSkip to conversation

subvolumes: default and IDs

PATCH Superseded Florian Lindner 6 participants 11 messages Jul 30, 2012 – Jul 31, 2012 Btrfs file system

lore
Share & tools
lore
#0 lore raw

Hey!

I recently starting playing with btrfs and subvolume, but it has left me puzzled:
Distribution is Archlinux, Kernel is 3.4.6.

Quoted 1 line
Quoted 1 line
Quoted 1 line

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?

Quoted 1 line
Quoted 1 line
Quoted 1 line

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....?

Quoted 1 line
Quoted 1 line
Quoted 1 line

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.

Quoted 1 line
Quoted 1 line
Quoted 1 line

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)

Quoted 1 line
Quoted 1 line
Quoted 1 line

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:

Quoted 1 line
Quoted 1 line
Quoted 1 line

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:

Quoted 1 line
Quoted 1 line
Quoted 1 line

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?

Quoted 1 line
Quoted 1 line
Quoted 1 line

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

#1 lore raw
Quoted 11 lines · Florian Lindner

Hey!

I recently starting playing with btrfs and subvolume, but it has left me puzzled:

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?

It looks like there's currently a bug in btrfs-progs - the 'get-default' command is actually doing a 'list' instead of printing the default. With any luck it's just a little error in the command-line parsing and should be easy to fix...

Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

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)

The internal ID of the root subvolume is 5, yes. I don't know whether this is a current implementation detail and subject to change, or if it will permanently stay that way. I *think* it's part of the disk format, and it permanent.

In either case, the subvol id '0' is treated as an alias for 'the original root subvolume', and the two can be used interchangeably in the mount command. I always find '0' just a bit easier to remember :)

Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

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.

Looks like you've found another bug (or maybe just a missing feature); it would be nice if this command allows you to use '0' as an alias for the root subvolume.

Signature · 1 line
Calvin Walton <[email protected]>
#2 lore raw
Quoted 4 lines · Calvin Walton

It looks like there's currently a bug in btrfs-progs - the 'get-default' command is actually doing a 'list' instead of printing the default. With any luck it's just a little error in the command-line parsing and should be easy to fix...

I've fallen upon this one as well.

That's typically the kind of bug that makes one wonder to what extent the software has ever been tested, and doubt it's anything close to production quality... :-/

Signature · 1 line
Swâmi Petaramesh <[email protected]> http://petaramesh.org PGP 9076E32E
#3 lore raw
In reply to Florian Lindner
Quoted 94 lines · Florian Lindner

Hey!

I recently starting playing with btrfs and subvolume, but it has left me puzzled:
Distribution is Archlinux, Kernel is 3.4.6.

Quoted 1 line
Quoted 1 line
Quoted 1 line

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?

Quoted 1 line
Quoted 1 line
Quoted 1 line

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....?

Quoted 1 line
Quoted 1 line
Quoted 1 line

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.

Quoted 1 line
Quoted 1 line
Quoted 1 line

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)

Quoted 1 line
Quoted 1 line
Quoted 1 line

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:

Quoted 1 line
Quoted 1 line
Quoted 1 line

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:

Quoted 1 line
Quoted 1 line
Quoted 1 line

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?

Quoted 1 line
Quoted 1 line
Quoted 1 line

root@horus /mnt # umount test
root@horus /mnt # mount -o subvolid=5 /dev/sdb1 test root@horus /mnt # ls test
sv1/ sv2/
<<<

Quoted 5 lines

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.

Hi Florian,

Thanks for reporting these!

They are old bugs that had been fixed recently in latest btrfs progs, you can checkout the latest btrfs-progs from
git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git

subvolid=0 will be translated to subvolid=5 since 5 indicates btrfs' fs tree (the root subvolume as you mentioned)

thanks,
liubo

Quoted 8 lines

Thanks!

Florian
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Florian Lindner

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 <[email protected]>:

Quoted 106 lines

Hey!

I recently starting playing with btrfs and subvolume, but it has left me puzzled:
Distribution is Archlinux, Kernel is 3.4.6.

Quoted 1 line
Quoted 1 line
Quoted 1 line

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?

Quoted 1 line
Quoted 1 line
Quoted 1 line

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....?

Quoted 1 line
Quoted 1 line
Quoted 1 line

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.

Quoted 1 line
Quoted 1 line
Quoted 1 line

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)

Quoted 1 line
Quoted 1 line
Quoted 1 line

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:

Quoted 1 line
Quoted 1 line
Quoted 1 line

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:

Quoted 1 line
Quoted 1 line
Quoted 1 line

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?

Quoted 1 line
Quoted 1 line
Quoted 1 line

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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
In reply to Florian Lindner

Hi everybody,

I believe Florian came across some odd behaviour of btrfs subvolume set-default which might still not be perfect in the current btrfs-progs: It does not seem to change the default subvolume to the original root fs tree if he does "btrfs subvolume set-default 0 /path/to/fs".

I am referring to this mail of Chris Mason where he said "btrfs subvolume set-default 0 /path" should set the default subvolume to the original root tree:
http://www.mail-archive.com/[email protected]/msg04567.html
either this was not implemented, yet, or I just didn't find it.

So to answer Florians third question, and to provide a patch for discussion:
3. Why does btrfs subvolume set-default 0 /path/to/fs seemingly not change the default subvol?
It goes like this:
3.1 Btrfs-progs:
btrfs subvolume set-default 0 /path/to/fs lands in:
do_set_default_subvol
and
ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid);
then sends the subvolid=0 to the kernel ioctl.

3.2 Kernel fs/btrfs:
ioctl.c reveals the function to look at:
long btrfs_ioctl(struct file *file, unsigned int
cmd, unsigned long arg)
...

        case BTRFS_IOC_DEFAULT_SUBVOL:
                return btrfs_ioctl_default_subvol(file, argp);

...
=> static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
Here we got this:

        u64 objectid = 0;

...

       /* argp is the the pointer to the "0" supplied from btrfs subvolume
set-default 0 ... */
       if (copy_from_user(&objectid, argp, sizeof(objectid)))
                return -EFAULT;

    /* as objectid now is 0, we use the current mounted subvolumes (FS
tree) objectid */
        if (!objectid)
                objectid = root->root_key.objectid;

==> So, btrfs subvolume set-default 0 /path/to/fs does in fact change the default subvolume, if the currently mounted subvolume is not the current default-subvolume. In Florian's example the subvolume seemingly did't change because he alway had the current default-subvolume mounted.

IMHO, when following the principle of least surprise calling "btrfs subvolume set-default 0 /path/to/fs" should always change the default subvolume to be the "root" subvolume. This would actually establish the same behaviour as the automatic translation from 0ULL to 5ULL in mount -o subvolid=0.

This can be done either in the kernel code(fs/btrfs/ioctl.c), by just exchanging:
if (!objectid)
- objectid = root->root_key.objectid;
+ objectid = BTRFS_FS_TREE_OBJECTID;

Or in btrfs-tools, which I would prefer. I am gonna send a patch against the integration branch of btrfs-progs for discussion shortly.

Best Regards,
Alex

2012/7/30 Florian Lindner <[email protected]>

Quoted 107 lines

Hey!

I recently starting playing with btrfs and subvolume, but it has left me puzzled:
Distribution is Archlinux, Kernel is 3.4.6.

Quoted 1 line
Quoted 1 line
Quoted 1 line

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?

Quoted 1 line
Quoted 1 line
Quoted 1 line

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....?

Quoted 1 line
Quoted 1 line
Quoted 1 line

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.

Quoted 1 line
Quoted 1 line
Quoted 1 line

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)

Quoted 1 line
Quoted 1 line
Quoted 1 line

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:

Quoted 1 line
Quoted 1 line
Quoted 1 line

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:

Quoted 1 line
Quoted 1 line
Quoted 1 line

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?

Quoted 1 line
Quoted 1 line
Quoted 1 line

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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

PATCH 1/1 Btrfs-progs: Enabled setting root subvolume with subvolid=0

The command btrfs subvolume set-default 0 /path/to/fs changed the default subvolume to whatever subvolume was currently mounted on /path/to/fs. This patch changes this behaviour to set the default subvolume to BTRFS_FS_TREE_OBJECTID in case the user asks for subvolid=0

---
 btrfs_cmds.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
btrfs_cmds.c +5 -0
index f2b6355..699d9b0 100644
@@ -964,6 +964,11 @@ int do_set_default_subvol(int nargs, char **argv)
 		fprintf(stderr, "ERROR: invalid tree id (%s)\n",subvolid);
 		return 30;
 	}
+	
+	/* Using the original root fs tree */
+	if (objectid == 0ULL) {
+		objectid = BTRFS_FS_TREE_OBJECTID;
+	}
 	ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid);
 	e = errno;
 	close(fd);
Signature · 1 line
1.7.2.5
#7 lore raw

Re: [PATCH] Btrfs-progs: Enabled setting root subvolume with subvolid=0

Quoted 18 lines · Alexander Karbstein

The command btrfs subvolume set-default 0 /path/to/fs changed the default subvolume to whatever subvolume was currently mounted on /path/to/fs. This patch changes this behaviour to set the default subvolume to BTRFS_FS_TREE_OBJECTID in case the user asks for subvolid=0

---
 btrfs_cmds.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
btrfs_cmds.c +0 -0
index f2b6355..699d9b0 100644
@@ -964,6 +964,11 @@ int do_set_default_subvol(int nargs, char **argv)
 		fprintf(stderr, "ERROR: invalid tree id (%s)\n",subvolid);

btrfs_cmds.c int do_set_default_subvol(int nargs, char **argv) · line 974

Quoted 10 lines
btrfs_cmds.c +5 -0
 		return 30;
 	}
+	
+	/* Using the original root fs tree */
+	if (objectid == 0ULL) {
+		objectid = BTRFS_FS_TREE_OBJECTID;
+	}
 	ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid);
 	e = errno;
 	close(fd);

Seems that you're using an old btrfs-prog source code, now the file is cmds-subvolume.c

And also checkpatch.pl complains about style errors while checking this.

thanks,
liubo

#8 lore raw

Re: [PATCH] Btrfs-progs: Enabled setting root subvolume with subvolid=0

Hello Liu,

thanks, you are so right. I just got it exactly the wrong way (I read btrfs-progs-unstable and thought this must be the bleeding edge one ;-). I should have read your e-Mail before.
I will revise it asap. But I have to let it wait for tomorrow... Gotta sleep now.

Best Regards,
Alex

2012/7/31 Liu Bo <[email protected]>:

Quoted 38 lines · Alexander Karbstein
Quoted 19 lines

The command btrfs subvolume set-default 0 /path/to/fs changed the default subvolume to whatever subvolume was currently mounted on /path/to/fs. This patch changes this behaviour to set the default subvolume to BTRFS_FS_TREE_OBJECTID in case the user asks for subvolid=0

---
 btrfs_cmds.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
btrfs_cmds.c +0 -0
index f2b6355..699d9b0 100644
@@ -964,6 +964,11 @@ int do_set_default_subvol(int nargs, char **argv)
              fprintf(stderr, "ERROR: invalid tree id (%s)\n",subvolid);

btrfs_cmds.c int do_set_default_subvol(int nargs, char **argv) · line 974

Quoted 10 lines
btrfs_cmds.c +5 -0
              return 30;
      }
+
+     /* Using the original root fs tree */
+     if (objectid == 0ULL) {
+             objectid = BTRFS_FS_TREE_OBJECTID;
+     }
      ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid);
      e = errno;
      close(fd);

Seems that you're using an old btrfs-prog source code, now the file is cmds-subvolume.c

And also checkpatch.pl complains about style errors while checking this.

thanks,
liubo

#9 lore raw

PATCH v2 1/1 Btrfs-progs: Enabled setting root subvolume with subvolid=0

In reply to Liu Bo

Hello everybody,

here is my revised patch free from checkpatch warnings and based on the right git tree.

Alexander Karbstein (1):
Btrfs-progs: Enabled setting root subvolume with subvolid=0

 cmds-subvolume.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.2.5
#10 lore raw

PATCH v2 1/1 Btrfs-progs: Enabled setting root subvolume with subvolid=0

In reply to Liu Bo

The command btrfs subvolume set-default 0 /path/to/fs changed the default subvolume to whatever subvolume was currently mounted on /path/to/fs. This patch changes this behaviour to set the default subvolume to BTRFS_FS_TREE_OBJECTID in case the user asks for subvolid=0

---
 cmds-subvolume.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
cmds-subvolume.c +4 -0
index 3508ce6..8f8c918 100644
@@ -25,6 +25,7 @@
 #include <limits.h>
 
 #include "kerncompat.h"
+#include "ctree.h"
 #include "ioctl.h"
 
 #include "commands.h"
@@ -464,6 +465,9 @@ static int cmd_subvol_set_default(int argc, char **argv)
 		fprintf(stderr, "ERROR: invalid tree id (%s)\n",subvolid);
 		return 30;
 	}
+	/* Using the original root fs tree */
+	if (objectid == 0ULL)
+		objectid = BTRFS_FS_TREE_OBJECTID;
 	ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid);
 	e = errno;
 	close(fd);
Signature · 1 line
1.7.2.5