btrfs-progs: subvolume: fix return value when the target exists
This commit is contained in:
parent
0a6fd286dd
commit
4c55bc27e5
102
0002-subvolume-fix-return-value-when-the-target-exists.patch
Normal file
102
0002-subvolume-fix-return-value-when-the-target-exists.patch
Normal file
@ -0,0 +1,102 @@
|
||||
From 3f988c91763682afc1242de844a901837ab4863a Mon Sep 17 00:00:00 2001
|
||||
From: Qu Wenruo <wqu@suse.com>
|
||||
Date: Wed, 10 Jan 2024 13:23:31 +1030
|
||||
Subject: [PATCH] btrfs-progs: subvolume: fix return value when the target
|
||||
exists
|
||||
|
||||
[BUG]
|
||||
When try to create a subvolume where the target path already exists, the
|
||||
"btrfs" command doesn't return error code correctly.
|
||||
|
||||
# mkfs.btrfs -f $dev
|
||||
# mount $dev $mnt
|
||||
# touch $mnt/subv1
|
||||
# btrfs subvolume create $mnt/subv1
|
||||
ERROR: target path already exists: $mnt/subv1
|
||||
# echo $?
|
||||
0
|
||||
|
||||
[CAUSE]
|
||||
The check on whether target exists is done by path_is_dir(), if it
|
||||
returns 0 or 1, it means there is something in that path already.
|
||||
|
||||
But unfortunately commit 5aa959fb3440 ("btrfs-progs: subvolume create:
|
||||
accept multiple arguments") only changed the out label, which would
|
||||
directly return @ret, not updating the return value correctly.
|
||||
|
||||
[FIX]
|
||||
Make sure all error out branch has their @ret manually updated.
|
||||
|
||||
Fixes: 5aa959fb3440 ("btrfs-progs: subvolume create: accept multiple arguments")
|
||||
Issue: #730
|
||||
Signed-off-by: Qu Wenruo <wqu@suse.com>
|
||||
Signed-off-by: David Sterba <dsterba@suse.com>
|
||||
---
|
||||
cmds/subvolume.c | 11 ++++++++++-
|
||||
1 file changed, 10 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/cmds/subvolume.c b/cmds/subvolume.c
|
||||
index 57be9ea..b01d5c8 100644
|
||||
--- a/cmds/subvolume.c
|
||||
+++ b/cmds/subvolume.c
|
||||
@@ -160,12 +160,14 @@ static int create_one_subvolume(const char *dst, struct btrfs_qgroup_inherit *in
|
||||
}
|
||||
if (ret >= 0) {
|
||||
error("target path already exists: %s", dst);
|
||||
+ ret = -EEXIST;
|
||||
goto out;
|
||||
}
|
||||
|
||||
dupname = strdup(dst);
|
||||
if (!dupname) {
|
||||
error_msg(ERROR_MSG_MEMORY, "duplicating %s", dst);
|
||||
+ ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
newname = basename(dupname);
|
||||
@@ -173,18 +175,21 @@ static int create_one_subvolume(const char *dst, struct btrfs_qgroup_inherit *in
|
||||
dupdir = strdup(dst);
|
||||
if (!dupdir) {
|
||||
error_msg(ERROR_MSG_MEMORY, "duplicating %s", dst);
|
||||
+ ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
dstdir = dirname(dupdir);
|
||||
|
||||
if (!test_issubvolname(newname)) {
|
||||
error("invalid subvolume name: %s", newname);
|
||||
+ ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
len = strlen(newname);
|
||||
if (len > BTRFS_VOL_NAME_MAX) {
|
||||
error("subvolume name too long: %s", newname);
|
||||
+ ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -208,6 +213,8 @@ static int create_one_subvolume(const char *dst, struct btrfs_qgroup_inherit *in
|
||||
goto out;
|
||||
}
|
||||
} else if (ret <= 0) {
|
||||
+ if (ret == 0)
|
||||
+ ret = -EEXIST;
|
||||
errno = ret ;
|
||||
error("failed to check directory %s before creation: %m", p);
|
||||
goto out;
|
||||
@@ -218,8 +225,10 @@ static int create_one_subvolume(const char *dst, struct btrfs_qgroup_inherit *in
|
||||
}
|
||||
|
||||
fddst = btrfs_open_dir(dstdir, &dirstream, 1);
|
||||
- if (fddst < 0)
|
||||
+ if (fddst < 0) {
|
||||
+ ret = fddst;
|
||||
goto out;
|
||||
+ }
|
||||
|
||||
pr_verbose(LOG_DEFAULT, "Create subvolume '%s/%s'\n", dstdir, newname);
|
||||
if (inherit) {
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
Name: btrfs-progs
|
||||
Version: 6.6.3
|
||||
Release: 2
|
||||
Release: 3
|
||||
Summary: btrfs userspace programs
|
||||
License: GPLv2 and GPL+ and LGPL-2.1+ and GPL-3.0+ and LGPL-2.1 and MIT
|
||||
URL: https://btrfs.wiki.kernel.org/index.php/Main_Page
|
||||
Source0: https://www.kernel.org/pub/linux/kernel/people/kdave/%{name}/%{name}-v%{version}.tar.xz
|
||||
|
||||
Patch0001: 0001-fix-exclusive-op-enqueue-timeout.patch
|
||||
Patch0002: 0002-subvolume-fix-return-value-when-the-target-exists.patch
|
||||
|
||||
BuildRequires: python3-devel >= 3.4
|
||||
BuildRequires: libacl-devel, e2fsprogs-devel, libblkid-devel, libuuid-devel, zlib-devel, libzstd-devel, lzo-devel, systemd-devel
|
||||
@ -72,6 +73,9 @@ make mandir=%{_mandir} bindir=%{_sbindir} libdir=%{_libdir} incdir=%{_includedir
|
||||
%{_mandir}/man8/*.gz
|
||||
|
||||
%changelog
|
||||
* Wed May 8 2024 Deyuan Fan <fandeyuan@kylinos.cn> - 6.6.3-3
|
||||
- btrfs-progs: subvolume: fix return value when the target exists
|
||||
|
||||
* Fri Apr 19 2024 cenhuilin <cenhuilin@kylinos.cn> - 6.6.3-2
|
||||
- fix exclusive op enqueue timeout
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user