All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: cmds/subvolume: try to delete subvolume by id when its path can't be reoslved
@ 2021-06-28 10:26 Qu Wenruo
  2021-08-17 13:32 ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Qu Wenruo @ 2021-06-28 10:26 UTC (permalink / raw)
  To: linux-btrfs

There is a recent report of ghost subvolumes where such subvolumes has
no ROOT_REF/BACKREF, and 0 root ref.
But without an orphan item, thus kernel won't queue them for cleanup.

Such ghost subvolumes are just here to take up space, and no way to
delete them except by btrfs check, which will try to fix the problem by
adding orphan item.

There is a kernel patch submitted to allow btrfs to detect such ghost
subvolumes and queue them for cleanup.

But btrfs-progs will not continue to call the ioctl if it can't find the
full subvolume path.

Thus this patch will loose the restriction by allowing btrfs-progs to
continue to call the ioctl even if it can't grab the subvolume path.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 cmds/subvolume.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/cmds/subvolume.c b/cmds/subvolume.c
index 9bd178082495..4881ba5be4b1 100644
--- a/cmds/subvolume.c
+++ b/cmds/subvolume.c
@@ -258,6 +258,7 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
 	char	*path = NULL;
 	DIR	*dirstream = NULL;
 	int commit_mode = 0;
+	bool subvol_path_not_found = false;
 	u8 fsid[BTRFS_FSID_SIZE];
 	u64 subvolid = 0;
 	char uuidbuf[BTRFS_UUID_UNPARSED_SIZE];
@@ -319,6 +320,18 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
 
 		path = argv[cnt];
 		err = btrfs_util_subvolume_path(path, subvolid, &subvol);
+		/*
+		 * If the subvolume is really not referred by anyone, and
+		 * refs is 0, newer kernel can handle it by just adding an
+		 * orphan item and queue it for cleanup.
+		 *
+		 * In this case, just let kernel to handle it, we do no
+		 * extra handling.
+		 */
+		if (err == BTRFS_UTIL_ERROR_SUBVOLUME_NOT_FOUND) {
+			subvol_path_not_found = true;
+			goto again;
+		}
 		if (err) {
 			error_btrfs_util(err);
 			ret = 1;
@@ -395,8 +408,10 @@ again:
 
 	if (subvolid == 0)
 		pr_verbose(MUST_LOG, "'%s/%s'\n", dname, vname);
-	else
+	else if (!subvol_path_not_found)
 		pr_verbose(MUST_LOG, "'%s'\n", full_subvolpath);
+	else
+		pr_verbose(MUST_LOG, "subvolid=%llu\n", subvolid);
 
 	if (subvolid == 0)
 		err = btrfs_util_delete_subvolume_fd(fd, vname, 0);
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs-progs: cmds/subvolume: try to delete subvolume by id when its path can't be reoslved
  2021-06-28 10:26 [PATCH] btrfs-progs: cmds/subvolume: try to delete subvolume by id when its path can't be reoslved Qu Wenruo
@ 2021-08-17 13:32 ` David Sterba
  2021-08-17 22:21   ` Qu Wenruo
  0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2021-08-17 13:32 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Mon, Jun 28, 2021 at 06:26:28PM +0800, Qu Wenruo wrote:
> There is a recent report of ghost subvolumes where such subvolumes has
> no ROOT_REF/BACKREF, and 0 root ref.
> But without an orphan item, thus kernel won't queue them for cleanup.
> 
> Such ghost subvolumes are just here to take up space, and no way to
> delete them except by btrfs check, which will try to fix the problem by
> adding orphan item.
> 
> There is a kernel patch submitted to allow btrfs to detect such ghost
> subvolumes and queue them for cleanup.
> 
> But btrfs-progs will not continue to call the ioctl if it can't find the
> full subvolume path.
> 
> Thus this patch will loose the restriction by allowing btrfs-progs to
> continue to call the ioctl even if it can't grab the subvolume path.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Added to devel, thanks. Please send a test case.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs-progs: cmds/subvolume: try to delete subvolume by id when its path can't be reoslved
  2021-08-17 13:32 ` David Sterba
@ 2021-08-17 22:21   ` Qu Wenruo
  0 siblings, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2021-08-17 22:21 UTC (permalink / raw)
  To: dsterba, Qu Wenruo, linux-btrfs



On 2021/8/17 下午9:32, David Sterba wrote:
> On Mon, Jun 28, 2021 at 06:26:28PM +0800, Qu Wenruo wrote:
>> There is a recent report of ghost subvolumes where such subvolumes has
>> no ROOT_REF/BACKREF, and 0 root ref.
>> But without an orphan item, thus kernel won't queue them for cleanup.
>>
>> Such ghost subvolumes are just here to take up space, and no way to
>> delete them except by btrfs check, which will try to fix the problem by
>> adding orphan item.
>>
>> There is a kernel patch submitted to allow btrfs to detect such ghost
>> subvolumes and queue them for cleanup.
>>
>> But btrfs-progs will not continue to call the ioctl if it can't find the
>> full subvolume path.
>>
>> Thus this patch will loose the restriction by allowing btrfs-progs to
>> continue to call the ioctl even if it can't grab the subvolume path.
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>
> Added to devel, thanks. Please send a test case.
>
That needs kernel support, and I didn't see kernel patch get merged yet.

Thanks,
Qu

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-17 22:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-28 10:26 [PATCH] btrfs-progs: cmds/subvolume: try to delete subvolume by id when its path can't be reoslved Qu Wenruo
2021-08-17 13:32 ` David Sterba
2021-08-17 22:21   ` Qu Wenruo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.