aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2024-02-27 14:41:16 +1030
committerDavid Sterba <dsterba@suse.com>2024-03-04 22:55:07 +0100
commit5f87b467a9e74de90382237187107844fe2c7f77 (patch)
tree1a8825449af9db8223fe589e34e22b9995fdb0eb
parent4da5f22b23ba5de2190e762635763d1a8fd225f3 (diff)
downloadbtrfs-progs-5f87b467a9e74de90382237187107844fe2c7f77.tar.gz
btrfs-progs: subvolume: output the prompt line only when the ioctl succeeded
[BUG] With the latest kernel patch to reject invalid qgroupids in btrfs_qgroup_inherit structure, "btrfs subvolume create" or "btrfs subvolume snapshot" can lead to the following output: # mkfs.btrfs -O quota -f $dev # mount $dev $mnt # btrfs subvolume create -i 2/0 $mnt/subv1 Create subvolume '/mnt/btrfs/subv1' ERROR: cannot create subvolume: No such file or directory The "btrfs subvolume" command output the first line, seemingly to indicate a successful subvolume creation, then followed by an error message. This can be a little confusing on whether if the subvolume is created or not. [FIX] Fix the output by only outputting the regular line if the ioctl succeeded. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--cmds/subvolume.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/cmds/subvolume.c b/cmds/subvolume.c
index 00c5eacf..16eda56a 100644
--- a/cmds/subvolume.c
+++ b/cmds/subvolume.c
@@ -229,7 +229,6 @@ static int create_one_subvolume(const char *dst, struct btrfs_qgroup_inherit *in
goto out;
}
- pr_verbose(LOG_DEFAULT, "Create subvolume '%s/%s'\n", dstdir, newname);
if (inherit) {
struct btrfs_ioctl_vol_args_v2 args;
@@ -253,6 +252,7 @@ static int create_one_subvolume(const char *dst, struct btrfs_qgroup_inherit *in
error("cannot create subvolume: %m");
goto out;
}
+ pr_verbose(LOG_DEFAULT, "Create subvolume '%s/%s'\n", dstdir, newname);
out:
close(fddst);
@@ -754,16 +754,8 @@ static int cmd_subvolume_snapshot(const struct cmd_struct *cmd, int argc, char *
if (fd < 0)
goto out;
- if (readonly) {
+ if (readonly)
args.flags |= BTRFS_SUBVOL_RDONLY;
- pr_verbose(LOG_DEFAULT,
- "Create a readonly snapshot of '%s' in '%s/%s'\n",
- subvol, dstdir, newname);
- } else {
- pr_verbose(LOG_DEFAULT,
- "Create a snapshot of '%s' in '%s/%s'\n",
- subvol, dstdir, newname);
- }
args.fd = fd;
if (inherit) {
@@ -784,6 +776,15 @@ static int cmd_subvolume_snapshot(const struct cmd_struct *cmd, int argc, char *
retval = 0; /* success */
+ if (readonly)
+ pr_verbose(LOG_DEFAULT,
+ "Create readonly snapshot of '%s' in '%s/%s'\n",
+ subvol, dstdir, newname);
+ else
+ pr_verbose(LOG_DEFAULT,
+ "Create snapshot of '%s' in '%s/%s'\n",
+ subvol, dstdir, newname);
+
out:
close(fddst);
close(fd);