All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org, dsterba@suse.cz, gene@czarc.net
Subject: [PATCH 10/13] Btrfs-progs: filter the deleted subvolumes when listing snapshots
Date: Fri,  1 Feb 2013 15:56:29 +0800	[thread overview]
Message-ID: <1359705392-7485-11-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1359705392-7485-1-git-send-email-anand.jain@oracle.com>

From: Wang Shilong <wangsl-fnst@cn.fujistu.com>

btrfs snapshot list command will stop by the deleted subvolumes.

The problem may happen by two ways:
1. a subvolume deletion is not commited, that is ROOT_BACKREF has been deleted,
   but ROOT_ITEM still exists. The command will fail to fill the path of
   the deleted subvolumes because we can not get the parent fs/file tree.
2. a subvolume is possibly deleted when we fill the path, For example,
   Fs tree
     |->subv0
	  |->subv1

   We may fill the path of subv1 firstly, after that, some user deletes subv1
   and subv0, and then we fill the path of subv0. The command will fail to
   fill the path of subv0 because we can not get path of subv0. And the command
   also will fail to make the full path of subv1 because we don't have the path
   of subv0.

Since these subvolumes have been deleted, we should filter them. This patch
fixed the above problem by this way.

For the 1st case, ->ref_tree of the deleted subvolumes are 0.
For the 2nd case, if we found the error number that ioctl() returns is ENOENT,
we will set ->ref_tree to 0.
And when we make the full path of the subvolumes, we will check ->ref_tree of
them and their parent. If someone's ->ref_tree or its parent's ->ref_tree is 0,
we will filter it.

Reported-by: Stefan Priebe <s.priebe@profihost.ag>
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c | 42 ++++++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index 545aa15..69ee3e7 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -564,6 +564,12 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
 	while (1) {
 		char *tmp;
 		u64 next;
+		/*
+		* ref_tree = 0 indicates the subvolumes
+		* has been deleted.
+		*/
+		if (!found->ref_tree)
+			return -ENOENT;
 		int add_len = strlen(found->path);
 
 		/* room for / and for null */
@@ -592,6 +598,10 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
 			break;
 		}
 
+		/*
+		* if the ref_tree = BTRFS_FS_TREE_OBJECTID,
+		* we are at the top
+		*/
 		if (next == BTRFS_FS_TREE_OBJECTID) {
 			char p[] = "<FS_TREE>";
 			add_len = strlen(p);
@@ -608,14 +618,12 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
 		}
 
 		/*
-		 * if the ref_tree wasn't in our tree of roots, we're
-		 * at the top
-		 */
+		* if the ref_tree wasn't in our tree of roots, the
+		* subvolume was deleted.
+		*/
 		found = root_tree_search(rl, next);
-		if (!found) {
-			ri->top_id = next;
-			break;
-		}
+		if (!found)
+			return -ENOENT;
 	}
 
 	ri->full_path = full_path;
@@ -638,6 +646,9 @@ static int lookup_ino_path(int fd, struct root_info *ri)
 	if (ri->path)
 		return 0;
 
+	if (!ri->ref_tree)
+		return -ENOENT;
+
 	memset(&args, 0, sizeof(args));
 	args.treeid = ri->ref_tree;
 	args.objectid = ri->dir_id;
@@ -645,6 +656,10 @@ static int lookup_ino_path(int fd, struct root_info *ri)
 	ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
 	e = errno;
 	if (ret) {
+		if (e == ENOENT) {
+			ri->ref_tree = 0;
+			return -ENOENT;
+		}
 		fprintf(stderr, "ERROR: Failed to lookup path for root %llu - %s\n",
 			(unsigned long long)ri->ref_tree,
 			strerror(e));
@@ -1255,10 +1270,13 @@ static void __filter_and_sort_subvol(struct root_lookup *all_subvols,
 	while (n) {
 		entry = rb_entry(n, struct root_info, rb_node);
 
-		resolve_root(all_subvols, entry, top_id);
+		ret = resolve_root(all_subvols, entry, top_id);
+		if (ret == -ENOENT)
+			goto skip;
 		ret = filter_root(entry, filter_set);
 		if (ret)
 			sort_tree_insert(sort_tree, entry, comp_set);
+skip:
 		n = rb_prev(n);
 	}
 }
@@ -1273,7 +1291,7 @@ static int __list_subvol_fill_paths(int fd, struct root_lookup *root_lookup)
 		int ret;
 		entry = rb_entry(n, struct root_info, rb_node);
 		ret = lookup_ino_path(fd, entry);
-		if(ret < 0)
+		if (ret && ret != -ENOENT)
 			return ret;
 		n = rb_next(n);
 	}
@@ -1721,7 +1739,11 @@ char *btrfs_list_path_for_root(int fd, u64 root)
 		struct root_info *entry;
 
 		entry = rb_entry(n, struct root_info, rb_node);
-		resolve_root(&root_lookup, entry, top_id);
+		ret = resolve_root(&root_lookup, entry, top_id);
+		if (ret == -ENOENT && entry->root_id == root) {
+			ret_path = NULL;
+			break;
+		}
 		if (entry->root_id == root) {
 			ret_path = entry->full_path;
 			entry->full_path = NULL;
-- 
1.8.1.227.g44fe835


  parent reply	other threads:[~2013-02-01  7:58 UTC|newest]

Thread overview: 131+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-25  9:19 [PATCH 00/10 V2] add show sub-command for btrfs subvol cli Anand Jain
2013-01-23  8:12 ` [PATCH 00/10] " Anand Jain
2013-01-23  8:12   ` [PATCH 01/10] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-24  4:39     ` Eric Sandeen
2013-01-24  9:23       ` Stefan Behrens
2013-01-24 17:57         ` Goffredo Baroncelli
2013-01-24 19:42           ` Eric Sandeen
2013-01-24 22:09             ` Goffredo Baroncelli
2013-01-24 22:36               ` Chris Mason
2013-01-24 22:49                 ` David Sterba
2013-01-24 22:52                 ` Avi Miller
2013-01-25 16:14               ` Eric Sandeen
2013-01-25 16:48                 ` Hugo Mills
2013-01-25 18:47                   ` Gene Czarcinski
2013-01-28  3:12                     ` Anand Jain
2013-01-25 15:19             ` Eric Sandeen
2013-01-25  9:21       ` Anand Jain
2013-01-23  8:12   ` [PATCH 02/10] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-23  8:12   ` [PATCH 03/10] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-23  8:12   ` [PATCH 04/10] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-23  8:12   ` [PATCH 05/10] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-24  4:49     ` Eric Sandeen
2013-01-25  9:20       ` Anand Jain
2013-01-23  8:12   ` [PATCH 06/10] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-23  8:12   ` [PATCH 07/10] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-23  8:12   ` [PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-23  8:12   ` [PATCH 09/10] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-23  8:12   ` [PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-24  5:06     ` Eric Sandeen
2013-01-24 19:42       ` Zach Brown
2013-01-24 23:14         ` Chris Mason
2013-01-24 23:24           ` Zach Brown
2013-01-25  9:24       ` Anand Jain
2013-01-23 21:57   ` [PATCH 00/10] add show sub-command for btrfs " Gene Czarcinski
2013-01-24  4:11     ` Anand Jain
2013-01-24 20:52   ` Gene Czarcinski
2013-01-25  9:23     ` Anand Jain
2013-01-25  9:19   ` [PATCH 01/10] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-25  9:19   ` [PATCH 02/10] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-25  9:19   ` [PATCH 03/10] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-25  9:19   ` [PATCH 04/10] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-25  9:19   ` [PATCH 05/10] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-25  9:19   ` [PATCH 06/10] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-25  9:19   ` [PATCH 07/10] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-25  9:19   ` [PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-25  9:19   ` [PATCH 09/10] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-25  9:19   ` [PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-25  9:30   ` [RESEND] [PATCH 00/10 V2] add show sub-command for btrfs " Anand Jain
2013-01-25  9:30     ` [PATCH 01/10] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-25  9:30     ` [PATCH 02/10] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-25  9:30     ` [PATCH 03/10] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-25  9:30     ` [PATCH 04/10] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-25  9:30     ` [PATCH 05/10] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-25  9:30     ` [PATCH 06/10] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-25  9:30     ` [PATCH 07/10] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-25  9:30     ` [PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-25  9:30     ` [PATCH 09/10] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-25  9:30     ` [PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-25 10:07       ` Stefan Behrens
2013-01-28  5:26         ` Anand Jain
2013-01-28  4:10   ` [PATCH 00/10 v3] add show sub-command for btrfs " Anand Jain
2013-01-28  4:10     ` [PATCH 01/10] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-28  4:10     ` [PATCH 02/10] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-28  4:10     ` [PATCH 03/10] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-28  4:10     ` [PATCH 04/10] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-28  4:10     ` [PATCH 05/10] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-28  4:10     ` [PATCH 06/10] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-28  4:10     ` [PATCH 07/10] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-28  4:10     ` [PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-28  4:10     ` [PATCH 09/10] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-28  4:10     ` [PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-28  5:29     ` [PATCH 00/10 v3] add show sub-command for btrfs " Anand Jain
2013-01-28  5:22   ` [RESEND] " Anand Jain
2013-01-28  5:22     ` [PATCH 01/10] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-28 18:08       ` David Sterba
2013-01-28  5:22     ` [PATCH 02/10] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-28  5:22     ` [PATCH 03/10] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-28  5:22     ` [PATCH 04/10] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-28  5:22     ` [PATCH 05/10] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-29  4:42       ` Wang Shilong
2013-01-28 18:04         ` David Sterba
2013-01-29  6:59           ` Anand Jain
2013-01-28  5:22     ` [PATCH 06/10] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-28  5:22     ` [PATCH 07/10] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-28  5:22     ` [PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-28  5:22     ` [PATCH 09/10] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-28  5:22     ` [PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-29  6:48   ` [PATCH 00/12 v4] add show sub-command for btrfs " Anand Jain
2013-01-29  6:48     ` [PATCH 01/12] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-29  6:48     ` [PATCH 02/12] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-30  3:27       ` Wang Shilong
2013-01-30  9:57         ` Anand Jain
2013-01-29  6:48     ` [PATCH 03/12] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-29  6:48     ` [PATCH 04/12] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-29  6:48     ` [PATCH 05/12] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-29  6:48     ` [PATCH 06/12] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-29  6:48     ` [PATCH 07/12] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-29  6:48     ` [PATCH 08/12] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-29  6:48     ` [PATCH 09/12] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-29  6:48     ` [PATCH 10/12] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-30 10:32       ` Wang Shilong
2013-01-31  3:13         ` Anand Jain
2013-01-29  6:49     ` [PATCH 11/12] Btrfs-progs: filter the deleted subvolumes when listing snapshots Anand Jain
2013-01-29  6:49     ` [PATCH 12/12] Btrfs-progs: update btrfs_get_subvol to be inline with resolve_root ret changes Anand Jain
2013-01-30  9:56   ` [PATCH 00/12 v5] Btrfs-progs: add show sub-command for btrfs subvol cli Anand Jain
2013-01-30  9:56     ` [PATCH 01/12] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-30  9:56     ` [PATCH 02/12] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-30  9:56     ` [PATCH 03/12] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-30  9:56     ` [PATCH 04/12] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-30  9:56     ` [PATCH 05/12] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-30  9:56     ` [PATCH 06/12] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-30  9:56     ` [PATCH 07/12] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-30  9:56     ` [PATCH 08/12] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-30  9:56     ` [PATCH 09/12] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-30  9:56     ` [PATCH 10/12] Btrfs-progs: filter the deleted subvolumes when listing snapshots Anand Jain
2013-01-30  9:56     ` [PATCH 11/12] Btrfs-progs: update btrfs_get_subvol to be inline with resolve_root ret changes Anand Jain
2013-01-30  9:56     ` [PATCH 12/12] Btrfs-progs: Fix a small memory leak in managing the btrfs list filter Anand Jain
2013-02-01  7:56   ` [PATCH 00/13 v6] Btrfs-progs: add show sub-command for btrfs subvol cli Anand Jain
2013-02-01  7:56     ` [PATCH 01/13] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-02-01  7:56     ` [PATCH 02/13] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-02-01  7:56     ` [PATCH 03/13] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-02-01  7:56     ` [PATCH 04/13] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-02-01  7:56     ` [PATCH 05/13] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-02-01  7:56     ` [PATCH 06/13] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-02-01  7:56     ` [PATCH 07/13] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-02-01  7:56     ` [PATCH 08/13] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-02-01  7:56     ` [PATCH 09/13] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-02-01  7:56     ` Anand Jain [this message]
2013-02-01  7:56     ` [PATCH 11/13] Btrfs-progs: update btrfs_get_subvol to be inline with resolve_root ret changes Anand Jain
2013-02-01  7:56     ` [PATCH 12/13] Btrfs-progs: Fix a small memory leak in managing the btrfs list filter Anand Jain
2013-02-01  7:56     ` [PATCH 13/13] Btrfs-progs: add subvol flags to print Anand Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1359705392-7485-11-git-send-email-anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.cz \
    --cc=gene@czarc.net \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.