From 158b898ebe11ea16a83a17c282f24ab363d18317 Mon Sep 17 00:00:00 2001 From: Sidong Yang Date: Sun, 19 Jan 2025 10:38:26 +0000 Subject: [PATCH] btrfs-progs: subvol delete: show nested subvolumes during recursive delete When a subvolume is deleted with the recursive option, any nested subvolumes also get removed without reporting it. Update the subvolume delete command to print the list of nested subvolumes. Issue: #923 Signed-off-by: Sidong Yang Signed-off-by: David Sterba --- cmds/subvolume.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cmds/subvolume.c b/cmds/subvolume.c index f34d94009..ba5cb9fac 100644 --- a/cmds/subvolume.c +++ b/cmds/subvolume.c @@ -507,6 +507,35 @@ static int cmd_subvolume_delete(const struct cmd_struct *cmd, int argc, char **a goto out; } + if (flags & BTRFS_UTIL_DELETE_SUBVOLUME_RECURSIVE) { + struct btrfs_util_subvolume_iterator *iter; + + err = btrfs_util_subvolume_iter_create_fd(fd, target_subvol_id, + BTRFS_UTIL_SUBVOLUME_ITERATOR_POST_ORDER, + &iter); + if (!err) { + char *nested_path; + struct btrfs_util_subvolume_info subvol_info; + + while (!(err = btrfs_util_subvolume_iter_next_info(iter, &nested_path, &subvol_info))) { + pr_verbose(LOG_DEFAULT, "Delete subvolume %" PRIu64 " (%s): ", + subvol_info.id, + commit_mode == COMMIT_EACH || + (commit_mode == COMMIT_AFTER && cnt + 1 == argc) ? + "commit" : "no-commit"); + pr_verbose(LOG_DEFAULT, "'%s/%s/%s'\n", dname, vname, nested_path); + + free(nested_path); + } + if (err != BTRFS_UTIL_ERROR_STOP_ITERATION) + warning("failed to iterate subvolumes, nested subvolumes will not be printed: %s", btrfs_util_strerror(err)); + + btrfs_util_destroy_subvolume_iterator(iter); + } else { + warning("failed to create subvolume iterator, nested subvolumes will not be printed: %s", btrfs_util_strerror(err)); + } + } + pr_verbose(LOG_DEFAULT, "Delete subvolume %" PRIu64 " (%s): ", target_subvol_id, commit_mode == COMMIT_EACH ||