From 3c49295e8a050f8d209ed4c4f55129c705ee7361 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 14 Jan 2021 22:37:06 +0100 Subject: [PATCH] btrfs-progs: subvol set-default: change id to 5 if specified as 0 The id 0 of the default subvolume is an internal alias for the toplevel fs tree, kernel does that conversion. Until 2116398b1dbe ("btrfs-progs: use libbtrfsutil for set-default") there was no manual conversion and the value was passed to kernel as-is. With the switch to the libbtrfsutil API this got broken (4.19). $ btrfs subvol set-default 0 /path In this case the default subvolume would be containing subvolume of /path instead of the toplevel one. Fix it by manually switching the 0 to 5 in case user specifies that to avoid the difference in the API, that we can't change. Issue: #327 Reported-by: Chris Murphy Signed-off-by: David Sterba --- cmds/subvolume.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmds/subvolume.c b/cmds/subvolume.c index 12313b17..6f5e688c 100644 --- a/cmds/subvolume.c +++ b/cmds/subvolume.c @@ -947,6 +947,13 @@ static int cmd_subvol_set_default(const struct cmd_struct *cmd, } else { /* subvol id and path to the filesystem are specified */ objectid = arg_strtou64(argv[optind]); + /* + * To avoid confusion with the case above inside libbtrfsutil, + * we must set the toplevel as default manually, same what + * would kernel do. + */ + if (objectid == 0) + objectid = BTRFS_FS_TREE_OBJECTID; path = argv[optind + 1]; }