Skip to content

Commit 193cd24

Browse files
committed
btrfs-progs: subvol delete: more fine grained check when looking for default subvol
The search for default subvolume could fail for two reasons, the lack of CAP_SYS_ADMIN for TREE_SEARCH ioctl is one but the default subvolume could be unset as well, thus no restrictions for deletion. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 0e66228 commit 193cd24

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

cmds/subvolume.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
265265
struct seen_fsid *seen_fsid_hash[SEEN_FSID_HASH_SIZE] = { NULL, };
266266
enum { COMMIT_AFTER = 1, COMMIT_EACH = 2 };
267267
enum btrfs_util_error err;
268-
uint64_t default_subvol_id = 0, target_subvol_id = 0;
268+
uint64_t default_subvol_id, target_subvol_id = 0;
269269

270270
optind = 0;
271271
while (1) {
@@ -374,11 +374,11 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
374374
goto out;
375375
}
376376

377+
default_subvol_id = 0;
377378
err = btrfs_util_get_default_subvolume_fd(fd, &default_subvol_id);
378-
if (err) {
379+
if (err == BTRFS_UTIL_ERROR_SEARCH_FAILED) {
379380
if (geteuid() != 0)
380381
warning("cannot read default subvolume id: %m");
381-
default_subvol_id = 0;
382382
}
383383

384384
if (subvolid > 0) {

0 commit comments

Comments
 (0)