Skip to contentSkip to conversation

Btrfs-progs: move path modification to filters

PATCH In review Lukas Czerner 3 participants 9 messages Dec 11, 2012 – Jan 31, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Btrfs-progs: move path modification to filters

Commit 8e8e019e910f20947fea7eff5da40753639d8870 introduces -a option which will list all subvolumes with distinguishing between relative and absolute by prepending absolute patch with "<FS_TREE>".

This commit moves the path modification to a filter code rather than doing so in path construction in resolve_root(). This gives us more flexibility in formatting path output.

---
 btrfs-list.c     |   32 +++++++++++++++++++++++---------
 btrfs-list.h     |    1 +
 cmds-subvolume.c |   11 +++++++++--
 man/btrfs.8.in   |    3 ++-
 4 files changed, 35 insertions(+), 12 deletions(-)
btrfs-list.c +23 -9
index e5f0f96..77d99f8 100644
@@ -628,15 +628,6 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
 		}
 
 		if (next == BTRFS_FS_TREE_OBJECTID) {
-			char p[] = "<FS_TREE>";
-			add_len = strlen(p);
-			len = strlen(full_path);
-			tmp = malloc(len + add_len + 2);
-			memcpy(tmp + add_len + 1, full_path, len);
-			tmp[add_len] = '/';
-			memcpy(tmp, p, add_len);
-			free(full_path);
-			full_path = tmp;
 			ri->top_id = next;
 			break;
 		}
@@ -1176,6 +1167,28 @@ static int filter_topid_equal(struct root_info *ri, u64 data)
 	return ri->top_id == data;
 }
 
+static int filter_full_path(struct root_info *ri, u64 data)
+{
+	if (ri->full_path && ri->top_id != data) {
+		char *tmp;
+		char p[] = "<FS_TREE>";
+		int add_len = strlen(p);
+		int len = strlen(ri->full_path);
+
+		tmp = malloc(len + add_len + 2);
+		if (!tmp) {
+			fprintf(stderr, "memory allocation failed\n");
+			exit(1);
+		}
+		memcpy(tmp + add_len + 1, ri->full_path, len);
+		tmp[add_len] = '/';
+		memcpy(tmp, p, add_len);
+		free(ri->full_path);
+		ri->full_path = tmp;
+	}
+	return 1;
+}
+
 static btrfs_list_filter_func all_filter_funcs[] = {
 	[BTRFS_LIST_FILTER_ROOTID]		= filter_by_rootid,
 	[BTRFS_LIST_FILTER_SNAPSHOT_ONLY]	= filter_snapshot,
@@ -1187,6 +1200,7 @@ static btrfs_list_filter_func all_filter_funcs[] = {
 	[BTRFS_LIST_FILTER_CGEN_LESS]		= filter_cgen_less,
 	[BTRFS_LIST_FILTER_CGEN_EQUAL]          = filter_cgen_equal,
 	[BTRFS_LIST_FILTER_TOPID_EQUAL]		= filter_topid_equal,
+	[BTRFS_LIST_FILTER_FULL_PATH]		= filter_full_path,
 };
 
 struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void)
btrfs-list.h +1 -0
index cde4b3c..f7fbea6 100644
@@ -71,6 +71,7 @@ enum btrfs_list_filter_enum {
 	BTRFS_LIST_FILTER_CGEN_LESS,
 	BTRFS_LIST_FILTER_CGEN_MORE,
 	BTRFS_LIST_FILTER_TOPID_EQUAL,
+	BTRFS_LIST_FILTER_FULL_PATH,
 	BTRFS_LIST_FILTER_MAX,
 };
 
cmds-subvolume.c +9 -2
index ac39f7b..37cb8cc 100644
@@ -277,7 +277,9 @@ static const char * const cmd_subvol_list_usage[] = {
 	"List subvolumes (and snapshots)",
 	"",
 	"-p           print parent ID",
-	"-a           print all the subvolumes in the filesystem.",
+	"-a           print all the subvolumes in the filesystem and",
+	"             distinguish absolute and relative path with respect",
+	"             to the given <path>",
 	"-u           print the uuid of subvolumes (and snapshots)",
 	"-t           print the result as a table",
 	"-s           list snapshots only in the filesystem",
@@ -400,7 +402,12 @@ static int cmd_subvol_list(int argc, char **argv)
 	}
 
 	top_id = btrfs_list_get_path_rootid(fd);
-	if (!is_list_all)
+
+	if (is_list_all)
+		btrfs_list_setup_filter(&filter_set,
+					BTRFS_LIST_FILTER_FULL_PATH,
+					top_id);
+	else
 		btrfs_list_setup_filter(&filter_set,
 					BTRFS_LIST_FILTER_TOPID_EQUAL,
 					top_id);
man/btrfs.8.in +2 -1
index 9222580..d6d8e94 100644
@@ -124,7 +124,8 @@ and top level. The parent's ID may be used at mount time via the
 
 \fB-t\fP print the result as a table.
 
-\fB-a\fP print all the subvolumes in the filesystem.
+\fB-a\fP print all the subvolumes in the filesystem and distinguish between
+absolute and relative path with respect to the given <path>.
 
 \fB-r\fP only readonly subvolumes in the filesystem wille be listed.
 
Signature · 1 line
1.7.7.6
#1 lore raw

PATCH 2/3 Btrfs-progs: add '-o' option into subvolume list command

This commit introduces new option '-o' to list only subvolumes under the specified path. This does not change subvolume list behaviour. It has been default in the past and it is even with this commit.

---
 cmds-subvolume.c |   11 ++++++++---
 man/btrfs.8.in   |    6 ++++--
 2 files changed, 12 insertions(+), 5 deletions(-)
cmds-subvolume.c +8 -3
index 37cb8cc..0aa7467 100644
@@ -272,7 +272,7 @@ out:
 }
 
 static const char * const cmd_subvol_list_usage[] = {
-	"btrfs subvolume list [-apurts] [-g [+|-]value] [-c [+|-]value] "
+	"btrfs subvolume list [-aopurts] [-g [+|-]value] [-c [+|-]value] "
 	"[--sort=gen,ogen,rootid,path] <path>",
 	"List subvolumes (and snapshots)",
 	"",
@@ -280,6 +280,7 @@ static const char * const cmd_subvol_list_usage[] = {
 	"-a           print all the subvolumes in the filesystem and",
 	"             distinguish absolute and relative path with respect",
 	"             to the given <path>",
+	"-o           print only subvolumes bellow specified path",
 	"-u           print the uuid of subvolumes (and snapshots)",
 	"-t           print the result as a table",
 	"-s           list snapshots only in the filesystem",
@@ -309,6 +310,7 @@ static int cmd_subvol_list(int argc, char **argv)
 	char *subvol;
 	int is_tab_result = 0;
 	int is_list_all = 0;
+	int is_only_in_path = 1;
 	struct option long_options[] = {
 		{"sort", 1, NULL, 'S'},
 		{0, 0, 0, 0}
@@ -320,7 +322,7 @@ static int cmd_subvol_list(int argc, char **argv)
 	optind = 1;
 	while(1) {
 		c = getopt_long(argc, argv,
-				    "apsurg:c:t", long_options, NULL);
+				    "aopsurg:c:t", long_options, NULL);
 		if (c < 0)
 			break;
 
@@ -331,6 +333,9 @@ static int cmd_subvol_list(int argc, char **argv)
 		case 'a':
 			is_list_all = 1;
 			break;
+		case 'o':
+			is_only_in_path = 1;
+			break;
 		case 't':
 			is_tab_result = 1;
 			break;
@@ -407,7 +412,7 @@ static int cmd_subvol_list(int argc, char **argv)
 		btrfs_list_setup_filter(&filter_set,
 					BTRFS_LIST_FILTER_FULL_PATH,
 					top_id);
-	else
+	else if (is_only_in_path)
 		btrfs_list_setup_filter(&filter_set,
 					BTRFS_LIST_FILTER_TOPID_EQUAL,
 					top_id);
man/btrfs.8.in +4 -2
index d6d8e94..1e314eb 100644
@@ -11,7 +11,7 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBsubvolume create\fP\fI [<dest>/]<name>\fP
 .PP
-\fBbtrfs\fP \fBsubvolume list\fP\fI [-aprts] [-g [+|-]value] [-c [+|-]value] [--rootid=rootid,gen,ogen,path] <path>\fP
+\fBbtrfs\fP \fBsubvolume list\fP\fI [-aoprts] [-g [+|-]value] [-c [+|-]value] [--rootid=rootid,gen,ogen,path] <path>\fP
 .PP
 \fBbtrfs\fP \fBsubvolume set-default\fP\fI <id> <path>\fP
 .PP
@@ -108,7 +108,7 @@ Create a subvolume in \fI<dest>\fR (or in the current directory if
 \fI<dest>\fR is omitted).
 .TP
 
-\fBsubvolume list\fR\fI [-aprts][-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] <path>\fR
+\fBsubvolume list\fR\fI [-aoprts][-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] <path>\fR
 .RS
 List the subvolumes present in the filesystem \fI<path>\fR. For every
 subvolume the following information is shown by default.
@@ -127,6 +127,8 @@ and top level. The parent's ID may be used at mount time via the
 \fB-a\fP print all the subvolumes in the filesystem and distinguish between
 absolute and relative path with respect to the given <path>.
 
+\fB-o\fP print only subvolumes bellow specified <path>.
+
 \fB-r\fP only readonly subvolumes in the filesystem wille be listed.
 
 \fB-s\fP only snapshot subvolumes in the filesystem will  be listed.
Signature · 1 line
1.7.7.6
#2 lore raw

PATCH 3/3 Btrfs-progs: List all subvolumes by default

In reply to Lukas Czerner

Commit a1e89891eb6af5381539d9875b85c196150171b6 changed subvolume list command so that we list only subvolumes under the specified directory. However this is confusing and unnecessary obstacle, because one usually want to see all subvolumes in the file system. It was introduced with the notion the full_path may be invalid which is not exactly true as the full_path is always relative to the root subvolume which makes perfect sense.

Simply making option '-a' default is not enough since it introduces the relative/absolute path distinction effectively obfuscating the subvolume nesting.

This commit returns the subvolume list command behaviour before commit a1e89891eb6af5381539d9875b85c196150171b6 where we list all subvolumes in the filesystem with path naming from root subovolume. IMO this is the best default as it is well understood and gives all the important information about file system subvolumes including subvolume nesting without the need to parse additional information.

---
 btrfs-list.c     |    8 ++++----
 btrfs-list.h     |    2 +-
 cmds-subvolume.c |    7 ++++---
 3 files changed, 9 insertions(+), 8 deletions(-)
btrfs-list.c +4 -4
index 77d99f8..ac6e1f0 100644
@@ -1283,12 +1283,11 @@ static void __filter_and_sort_subvol(struct root_lookup *all_subvols,
 				    struct root_lookup *sort_tree,
 				    struct btrfs_list_filter_set *filter_set,
 				    struct btrfs_list_comparer_set *comp_set,
-				    int fd)
+				    u64 top_id)
 {
 	struct rb_node *n;
 	struct root_info *entry;
 	int ret;
-	u64 top_id = btrfs_list_get_path_rootid(fd);
 
 	root_lookup_init(sort_tree);
 
@@ -1457,11 +1456,12 @@ static void print_all_volume_info(struct root_lookup *sorted_tree,
 
 int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
 		       struct btrfs_list_comparer_set *comp_set,
-		       int is_tab_result)
+		       int is_tab_result, int full_path)
 {
 	struct root_lookup root_lookup;
 	struct root_lookup root_sort;
 	int ret;
+	u64 top_id = (full_path ? 0 : btrfs_list_get_path_rootid(fd));
 
 	ret = __list_subvol_search(fd, &root_lookup);
 	if (ret) {
@@ -1479,7 +1479,7 @@ int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
 		return ret;
 
 	__filter_and_sort_subvol(&root_lookup, &root_sort, filter_set,
-				 comp_set, fd);
+				 comp_set, top_id);
 
 	print_all_volume_info(&root_sort, is_tab_result);
 	__free_all_subvolumn(&root_lookup);
btrfs-list.h +1 -1
index f7fbea6..658e1ad 100644
@@ -101,7 +101,7 @@ int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
 
 int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
 		       struct btrfs_list_comparer_set *comp_set,
-			int is_tab_result);
+		       int is_tab_result, int full_path);
 int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
 int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
 char *btrfs_list_path_for_root(int fd, u64 root);
cmds-subvolume.c +4 -3
index 0aa7467..88158f0 100644
@@ -310,7 +310,7 @@ static int cmd_subvol_list(int argc, char **argv)
 	char *subvol;
 	int is_tab_result = 0;
 	int is_list_all = 0;
-	int is_only_in_path = 1;
+	int is_only_in_path = 0;
 	struct option long_options[] = {
 		{"sort", 1, NULL, 'S'},
 		{0, 0, 0, 0}
@@ -418,7 +418,8 @@ static int cmd_subvol_list(int argc, char **argv)
 					top_id);
 
 	ret = btrfs_list_subvols(fd, filter_set, comparer_set,
-				is_tab_result);
+				is_tab_result,
+				!is_list_all && !is_only_in_path);
 	if (ret)
 		return 19;
 	return 0;
@@ -624,7 +625,7 @@ static int cmd_subvol_get_default(int argc, char **argv)
 	btrfs_list_setup_filter(&filter_set, BTRFS_LIST_FILTER_ROOTID,
 				default_id);
 
-	ret = btrfs_list_subvols(fd, filter_set, NULL, 0);
+	ret = btrfs_list_subvols(fd, filter_set, NULL, 0, 1);
 	if (ret)
 		return 19;
 	return 0;
Signature · 1 line
1.7.7.6
#3 lore raw
In reply to Lukas Czerner
Quoted 7 lines · Lukas Czerner

Date: Tue, 11 Dec 2012 15:24:58 +0100
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
Lukas Czerner <[email protected]>
Subject: [PATCH 1/3] Btrfs-progs: move path modification to filters

Quoted 7 lines

Commit 8e8e019e910f20947fea7eff5da40753639d8870 introduces -a option which will list all subvolumes with distinguishing between relative and absolute by prepending absolute patch with "<FS_TREE>".

This commit moves the path modification to a filter code rather than doing so in path construction in resolve_root(). This gives us more flexibility in formatting path output.

ping

any comments on this ?

-Lukas

Quoted 122 lines
---
 btrfs-list.c     |   32 +++++++++++++++++++++++---------
 btrfs-list.h     |    1 +
 cmds-subvolume.c |   11 +++++++++--
 man/btrfs.8.in   |    3 ++-
 4 files changed, 35 insertions(+), 12 deletions(-)
btrfs-list.c +23 -9
index e5f0f96..77d99f8 100644
@@ -628,15 +628,6 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
 		}
 
 		if (next == BTRFS_FS_TREE_OBJECTID) {
-			char p[] = "<FS_TREE>";
-			add_len = strlen(p);
-			len = strlen(full_path);
-			tmp = malloc(len + add_len + 2);
-			memcpy(tmp + add_len + 1, full_path, len);
-			tmp[add_len] = '/';
-			memcpy(tmp, p, add_len);
-			free(full_path);
-			full_path = tmp;
 			ri->top_id = next;
 			break;
 		}
@@ -1176,6 +1167,28 @@ static int filter_topid_equal(struct root_info *ri, u64 data)
 	return ri->top_id == data;
 }
 
+static int filter_full_path(struct root_info *ri, u64 data)
+{
+	if (ri->full_path && ri->top_id != data) {
+		char *tmp;
+		char p[] = "<FS_TREE>";
+		int add_len = strlen(p);
+		int len = strlen(ri->full_path);
+
+		tmp = malloc(len + add_len + 2);
+		if (!tmp) {
+			fprintf(stderr, "memory allocation failed\n");
+			exit(1);
+		}
+		memcpy(tmp + add_len + 1, ri->full_path, len);
+		tmp[add_len] = '/';
+		memcpy(tmp, p, add_len);
+		free(ri->full_path);
+		ri->full_path = tmp;
+	}
+	return 1;
+}
+
 static btrfs_list_filter_func all_filter_funcs[] = {
 	[BTRFS_LIST_FILTER_ROOTID]		= filter_by_rootid,
 	[BTRFS_LIST_FILTER_SNAPSHOT_ONLY]	= filter_snapshot,
@@ -1187,6 +1200,7 @@ static btrfs_list_filter_func all_filter_funcs[] = {
 	[BTRFS_LIST_FILTER_CGEN_LESS]		= filter_cgen_less,
 	[BTRFS_LIST_FILTER_CGEN_EQUAL]          = filter_cgen_equal,
 	[BTRFS_LIST_FILTER_TOPID_EQUAL]		= filter_topid_equal,
+	[BTRFS_LIST_FILTER_FULL_PATH]		= filter_full_path,
 };
 
 struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void)
btrfs-list.h +1 -0
index cde4b3c..f7fbea6 100644
@@ -71,6 +71,7 @@ enum btrfs_list_filter_enum {
 	BTRFS_LIST_FILTER_CGEN_LESS,
 	BTRFS_LIST_FILTER_CGEN_MORE,
 	BTRFS_LIST_FILTER_TOPID_EQUAL,
+	BTRFS_LIST_FILTER_FULL_PATH,
 	BTRFS_LIST_FILTER_MAX,
 };
 
cmds-subvolume.c +9 -2
index ac39f7b..37cb8cc 100644
@@ -277,7 +277,9 @@ static const char * const cmd_subvol_list_usage[] = {
 	"List subvolumes (and snapshots)",
 	"",
 	"-p           print parent ID",
-	"-a           print all the subvolumes in the filesystem.",
+	"-a           print all the subvolumes in the filesystem and",
+	"             distinguish absolute and relative path with respect",
+	"             to the given <path>",
 	"-u           print the uuid of subvolumes (and snapshots)",
 	"-t           print the result as a table",
 	"-s           list snapshots only in the filesystem",
@@ -400,7 +402,12 @@ static int cmd_subvol_list(int argc, char **argv)
 	}
 
 	top_id = btrfs_list_get_path_rootid(fd);
-	if (!is_list_all)
+
+	if (is_list_all)
+		btrfs_list_setup_filter(&filter_set,
+					BTRFS_LIST_FILTER_FULL_PATH,
+					top_id);
+	else
 		btrfs_list_setup_filter(&filter_set,
 					BTRFS_LIST_FILTER_TOPID_EQUAL,
 					top_id);
man/btrfs.8.in +2 -1
index 9222580..d6d8e94 100644
@@ -124,7 +124,8 @@ and top level. The parent's ID may be used at mount time via the
 
 \fB-t\fP print the result as a table.
 
-\fB-a\fP print all the subvolumes in the filesystem.
+\fB-a\fP print all the subvolumes in the filesystem and distinguish between
+absolute and relative path with respect to the given <path>.
 
 \fB-r\fP only readonly subvolumes in the filesystem wille be listed.
 
#4 lore raw
Quoted 23 lines · Lukáš Czerner

Date: Thu, 10 Jan 2013 13:02:42 +0100 (CET)
From: Lukáš Czerner <[email protected]>
To: Lukas Czerner <[email protected]>
Cc: [email protected], [email protected], [email protected]
Subject: Re: [PATCH 1/3] Btrfs-progs: move path modification to filters

Quoted 7 lines · Lukas Czerner

Date: Tue, 11 Dec 2012 15:24:58 +0100
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
Lukas Czerner <[email protected]>
Subject: [PATCH 1/3] Btrfs-progs: move path modification to filters

Quoted 7 lines

Commit 8e8e019e910f20947fea7eff5da40753639d8870 introduces -a option which will list all subvolumes with distinguishing between relative and absolute by prepending absolute patch with "<FS_TREE>".

This commit moves the path modification to a filter code rather than doing so in path construction in resolve_root(). This gives us more flexibility in formatting path output.

Quoted 5 lines

ping

any comments on this ?

-Lukas

ping

Quoted 124 lines
Quoted 123 lines
---
 btrfs-list.c     |   32 +++++++++++++++++++++++---------
 btrfs-list.h     |    1 +
 cmds-subvolume.c |   11 +++++++++--
 man/btrfs.8.in   |    3 ++-
 4 files changed, 35 insertions(+), 12 deletions(-)
btrfs-list.c +23 -9
index e5f0f96..77d99f8 100644
@@ -628,15 +628,6 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
 		}
 
 		if (next == BTRFS_FS_TREE_OBJECTID) {
-			char p[] = "<FS_TREE>";
-			add_len = strlen(p);
-			len = strlen(full_path);
-			tmp = malloc(len + add_len + 2);
-			memcpy(tmp + add_len + 1, full_path, len);
-			tmp[add_len] = '/';
-			memcpy(tmp, p, add_len);
-			free(full_path);
-			full_path = tmp;
 			ri->top_id = next;
 			break;
 		}
@@ -1176,6 +1167,28 @@ static int filter_topid_equal(struct root_info *ri, u64 data)
 	return ri->top_id == data;
 }
 
+static int filter_full_path(struct root_info *ri, u64 data)
+{
+	if (ri->full_path && ri->top_id != data) {
+		char *tmp;
+		char p[] = "<FS_TREE>";
+		int add_len = strlen(p);
+		int len = strlen(ri->full_path);
+
+		tmp = malloc(len + add_len + 2);
+		if (!tmp) {
+			fprintf(stderr, "memory allocation failed\n");
+			exit(1);
+		}
+		memcpy(tmp + add_len + 1, ri->full_path, len);
+		tmp[add_len] = '/';
+		memcpy(tmp, p, add_len);
+		free(ri->full_path);
+		ri->full_path = tmp;
+	}
+	return 1;
+}
+
 static btrfs_list_filter_func all_filter_funcs[] = {
 	[BTRFS_LIST_FILTER_ROOTID]		= filter_by_rootid,
 	[BTRFS_LIST_FILTER_SNAPSHOT_ONLY]	= filter_snapshot,
@@ -1187,6 +1200,7 @@ static btrfs_list_filter_func all_filter_funcs[] = {
 	[BTRFS_LIST_FILTER_CGEN_LESS]		= filter_cgen_less,
 	[BTRFS_LIST_FILTER_CGEN_EQUAL]          = filter_cgen_equal,
 	[BTRFS_LIST_FILTER_TOPID_EQUAL]		= filter_topid_equal,
+	[BTRFS_LIST_FILTER_FULL_PATH]		= filter_full_path,
 };
 
 struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void)
btrfs-list.h +1 -0
index cde4b3c..f7fbea6 100644
@@ -71,6 +71,7 @@ enum btrfs_list_filter_enum {
 	BTRFS_LIST_FILTER_CGEN_LESS,
 	BTRFS_LIST_FILTER_CGEN_MORE,
 	BTRFS_LIST_FILTER_TOPID_EQUAL,
+	BTRFS_LIST_FILTER_FULL_PATH,
 	BTRFS_LIST_FILTER_MAX,
 };
 
cmds-subvolume.c +9 -2
index ac39f7b..37cb8cc 100644
@@ -277,7 +277,9 @@ static const char * const cmd_subvol_list_usage[] = {
 	"List subvolumes (and snapshots)",
 	"",
 	"-p           print parent ID",
-	"-a           print all the subvolumes in the filesystem.",
+	"-a           print all the subvolumes in the filesystem and",
+	"             distinguish absolute and relative path with respect",
+	"             to the given <path>",
 	"-u           print the uuid of subvolumes (and snapshots)",
 	"-t           print the result as a table",
 	"-s           list snapshots only in the filesystem",
@@ -400,7 +402,12 @@ static int cmd_subvol_list(int argc, char **argv)
 	}
 
 	top_id = btrfs_list_get_path_rootid(fd);
-	if (!is_list_all)
+
+	if (is_list_all)
+		btrfs_list_setup_filter(&filter_set,
+					BTRFS_LIST_FILTER_FULL_PATH,
+					top_id);
+	else
 		btrfs_list_setup_filter(&filter_set,
 					BTRFS_LIST_FILTER_TOPID_EQUAL,
 					top_id);
man/btrfs.8.in +2 -1
index 9222580..d6d8e94 100644
@@ -124,7 +124,8 @@ and top level. The parent's ID may be used at mount time via the
 
 \fB-t\fP print the result as a table.
 
-\fB-a\fP print all the subvolumes in the filesystem.
+\fB-a\fP print all the subvolumes in the filesystem and distinguish between
+absolute and relative path with respect to the given <path>.
 
 \fB-r\fP only readonly subvolumes in the filesystem wille be listed.
 
#5 lore raw

Ignoring for the moment whether these patches are a good idea or not, what is the base upon which these patches were built. You might want to consider rebasing them to David Sterba's integration-20130130

Gene

Quoted 152 lines · Lukáš Czerner
Quoted 19 lines · Lukáš Czerner

Date: Thu, 10 Jan 2013 13:02:42 +0100 (CET)
From: Lukáš Czerner <[email protected]>
To: Lukas Czerner <[email protected]>
Cc: [email protected], [email protected], [email protected]
Subject: Re: [PATCH 1/3] Btrfs-progs: move path modification to filters

Quoted 11 lines · Lukas Czerner

Date: Tue, 11 Dec 2012 15:24:58 +0100
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
Lukas Czerner <[email protected]>
Subject: [PATCH 1/3] Btrfs-progs: move path modification to filters

Commit 8e8e019e910f20947fea7eff5da40753639d8870 introduces -a option which will list all subvolumes with distinguishing between relative and absolute by prepending absolute patch with "<FS_TREE>".

Quoted 8 lines
Quoted 3 lines

This commit moves the path modification to a filter code rather than doing so in path construction in resolve_root(). This gives us more flexibility in formatting path output.

ping

any comments on this ?

-Lukas

ping

Quoted 121 lines
Quoted 121 lines
---
  btrfs-list.c     |   32 +++++++++++++++++++++++---------
  btrfs-list.h     |    1 +
  cmds-subvolume.c |   11 +++++++++--
  man/btrfs.8.in   |    3 ++-
  4 files changed, 35 insertions(+), 12 deletions(-)
btrfs-list.c +23 -9
index e5f0f96..77d99f8 100644
@@ -628,15 +628,6 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
  		}
 
  		if (next == BTRFS_FS_TREE_OBJECTID) {
-			char p[] = "<FS_TREE>";
-			add_len = strlen(p);
-			len = strlen(full_path);
-			tmp = malloc(len + add_len + 2);
-			memcpy(tmp + add_len + 1, full_path, len);
-			tmp[add_len] = '/';
-			memcpy(tmp, p, add_len);
-			free(full_path);
-			full_path = tmp;
  			ri->top_id = next;
  			break;
  		}
@@ -1176,6 +1167,28 @@ static int filter_topid_equal(struct root_info *ri, u64 data)
  	return ri->top_id == data;
  }
 
+static int filter_full_path(struct root_info *ri, u64 data)
+{
+	if (ri->full_path && ri->top_id != data) {
+		char *tmp;
+		char p[] = "<FS_TREE>";
+		int add_len = strlen(p);
+		int len = strlen(ri->full_path);
+
+		tmp = malloc(len + add_len + 2);
+		if (!tmp) {
+			fprintf(stderr, "memory allocation failed\n");
+			exit(1);
+		}
+		memcpy(tmp + add_len + 1, ri->full_path, len);
+		tmp[add_len] = '/';
+		memcpy(tmp, p, add_len);
+		free(ri->full_path);
+		ri->full_path = tmp;
+	}
+	return 1;
+}
+
  static btrfs_list_filter_func all_filter_funcs[] = {
  	[BTRFS_LIST_FILTER_ROOTID]		= filter_by_rootid,
  	[BTRFS_LIST_FILTER_SNAPSHOT_ONLY]	= filter_snapshot,
@@ -1187,6 +1200,7 @@ static btrfs_list_filter_func all_filter_funcs[] = {
  	[BTRFS_LIST_FILTER_CGEN_LESS]		= filter_cgen_less,
  	[BTRFS_LIST_FILTER_CGEN_EQUAL]          = filter_cgen_equal,
  	[BTRFS_LIST_FILTER_TOPID_EQUAL]		= filter_topid_equal,
+	[BTRFS_LIST_FILTER_FULL_PATH]		= filter_full_path,
  };
 
  struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void)
btrfs-list.h +1 -0
index cde4b3c..f7fbea6 100644
@@ -71,6 +71,7 @@ enum btrfs_list_filter_enum {
  	BTRFS_LIST_FILTER_CGEN_LESS,
  	BTRFS_LIST_FILTER_CGEN_MORE,
  	BTRFS_LIST_FILTER_TOPID_EQUAL,
+	BTRFS_LIST_FILTER_FULL_PATH,
  	BTRFS_LIST_FILTER_MAX,
  };
 
cmds-subvolume.c +9 -2
index ac39f7b..37cb8cc 100644
@@ -277,7 +277,9 @@ static const char * const cmd_subvol_list_usage[] = {
  	"List subvolumes (and snapshots)",
  	"",
  	"-p           print parent ID",
-	"-a           print all the subvolumes in the filesystem.",
+	"-a           print all the subvolumes in the filesystem and",
+	"             distinguish absolute and relative path with respect",
+	"             to the given <path>",
  	"-u           print the uuid of subvolumes (and snapshots)",
  	"-t           print the result as a table",
  	"-s           list snapshots only in the filesystem",
@@ -400,7 +402,12 @@ static int cmd_subvol_list(int argc, char **argv)
  	}
 
  	top_id = btrfs_list_get_path_rootid(fd);
-	if (!is_list_all)
+
+	if (is_list_all)
+		btrfs_list_setup_filter(&filter_set,
+					BTRFS_LIST_FILTER_FULL_PATH,
+					top_id);
+	else
  		btrfs_list_setup_filter(&filter_set,
  					BTRFS_LIST_FILTER_TOPID_EQUAL,
  					top_id);
man/btrfs.8.in +2 -1
index 9222580..d6d8e94 100644
@@ -124,7 +124,8 @@ and top level. The parent's ID may be used at mount time via the
 
  \fB-t\fP print the result as a table.
 
-\fB-a\fP print all the subvolumes in the filesystem.
+\fB-a\fP print all the subvolumes in the filesystem and distinguish between
+absolute and relative path with respect to the given <path>.
 
  \fB-r\fP only readonly subvolumes in the filesystem wille be listed.
 
#6 lore raw
Quoted 11 lines · Gene Czarcinski

Date: Wed, 30 Jan 2013 13:03:30 -0500
From: Gene Czarcinski <[email protected]>
To: Lukáš Czerner <[email protected]>
Cc: linux-btrfs <[email protected]>
Subject: Re: [PATCH 1/3] Btrfs-progs: move path modification to filters

Ignoring for the moment whether these patches are a good idea or not, what is the base upon which these patches were built. You might want to consider rebasing them to David Sterba's integration-20130130

Gene

Hi,

yet it has been a while since I've posted it so I guess I have to rebase.

Thanks!
-Lukas

Quoted 154 lines · Lukáš Czerner
Quoted 150 lines · Lukáš Czerner
Quoted 21 lines

Date: Thu, 10 Jan 2013 13:02:42 +0100 (CET)
From: Lukáš Czerner <[email protected]>
To: Lukas Czerner <[email protected]>
Cc: [email protected], [email protected], [email protected]
Subject: Re: [PATCH 1/3] Btrfs-progs: move path modification to filters

Quoted 11 lines · Lukas Czerner

Date: Tue, 11 Dec 2012 15:24:58 +0100
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
Lukas Czerner <[email protected]>
Subject: [PATCH 1/3] Btrfs-progs: move path modification to filters

Commit 8e8e019e910f20947fea7eff5da40753639d8870 introduces -a option which will list all subvolumes with distinguishing between relative and absolute by prepending absolute patch with "<FS_TREE>".

Quoted 8 lines
Quoted 3 lines

This commit moves the path modification to a filter code rather than doing so in path construction in resolve_root(). This gives us more flexibility in formatting path output.

ping

any comments on this ?

-Lukas

ping

Quoted 118 lines
Quoted 118 lines
---
  btrfs-list.c     |   32 +++++++++++++++++++++++---------
  btrfs-list.h     |    1 +
  cmds-subvolume.c |   11 +++++++++--
  man/btrfs.8.in   |    3 ++-
  4 files changed, 35 insertions(+), 12 deletions(-)
btrfs-list.c +22 -9
index e5f0f96..77d99f8 100644
@@ -628,15 +628,6 @@ static int resolve_root(struct root_lookup *rl,
 struct root_info *ri,
  		}
    		if (next == BTRFS_FS_TREE_OBJECTID) {
-			char p[] = "<FS_TREE>";
-			add_len = strlen(p);
-			len = strlen(full_path);
-			tmp = malloc(len + add_len + 2);
-			memcpy(tmp + add_len + 1, full_path, len);
-			tmp[add_len] = '/';
-			memcpy(tmp, p, add_len);
-			free(full_path);
-			full_path = tmp;
  			ri->top_id = next;
  			break;
  		}
@@ -1176,6 +1167,28 @@ static int filter_topid_equal(struct root_info
 *ri, u64 data)
  	return ri->top_id == data;
  }
  +static int filter_full_path(struct root_info *ri, u64 data)
+{
+	if (ri->full_path && ri->top_id != data) {
+		char *tmp;
+		char p[] = "<FS_TREE>";
+		int add_len = strlen(p);
+		int len = strlen(ri->full_path);
+
+		tmp = malloc(len + add_len + 2);
+		if (!tmp) {
+			fprintf(stderr, "memory allocation failed\n");
+			exit(1);
+		}
+		memcpy(tmp + add_len + 1, ri->full_path, len);
+		tmp[add_len] = '/';
+		memcpy(tmp, p, add_len);
+		free(ri->full_path);
+		ri->full_path = tmp;
+	}
+	return 1;
+}
+
  static btrfs_list_filter_func all_filter_funcs[] = {
  	[BTRFS_LIST_FILTER_ROOTID]		= filter_by_rootid,
  	[BTRFS_LIST_FILTER_SNAPSHOT_ONLY]	= filter_snapshot,
@@ -1187,6 +1200,7 @@ static btrfs_list_filter_func all_filter_funcs[] =
 {
  	[BTRFS_LIST_FILTER_CGEN_LESS]		= filter_cgen_less,
  	[BTRFS_LIST_FILTER_CGEN_EQUAL]          = filter_cgen_equal,
  	[BTRFS_LIST_FILTER_TOPID_EQUAL]		= filter_topid_equal,
+	[BTRFS_LIST_FILTER_FULL_PATH]		= filter_full_path,
  };
    struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void)
btrfs-list.h +1 -0
index cde4b3c..f7fbea6 100644
@@ -71,6 +71,7 @@ enum btrfs_list_filter_enum {
  	BTRFS_LIST_FILTER_CGEN_LESS,
  	BTRFS_LIST_FILTER_CGEN_MORE,
  	BTRFS_LIST_FILTER_TOPID_EQUAL,
+	BTRFS_LIST_FILTER_FULL_PATH,
  	BTRFS_LIST_FILTER_MAX,
  };
  diff --git a/cmds-subvolume.c b/cmds-subvolume.c

index ac39f7b..37cb8cc 100644

cmds-subvolume.c +3 -1
@@ -277,7 +277,9 @@ static const char * const cmd_subvol_list_usage[] =
 {
  	"List subvolumes (and snapshots)",
  	"",
  	"-p           print parent ID",
-	"-a           print all the subvolumes in the filesystem.",
+	"-a           print all the subvolumes in the filesystem and",
+	"             distinguish absolute and relative path with respect",
+	"             to the given <path>",
  	"-u           print the uuid of subvolumes (and snapshots)",
  	"-t           print the result as a table",

"-s list snapshots only in the filesystem",

cmds-subvolume.c +6 -1
@@ -400,7 +402,12 @@ static int cmd_subvol_list(int argc, char **argv)
  	}
    	top_id = btrfs_list_get_path_rootid(fd);
-	if (!is_list_all)
+
+	if (is_list_all)
+		btrfs_list_setup_filter(&filter_set,
+					BTRFS_LIST_FILTER_FULL_PATH,
+					top_id);
+	else
  		btrfs_list_setup_filter(&filter_set,
  					BTRFS_LIST_FILTER_TOPID_EQUAL,
  					top_id);
man/btrfs.8.in +0 -0
index 9222580..d6d8e94 100644
@@ -124,7 +124,8 @@ and top level. The parent's ID may be used at mount

time via the
\fB-t\fP print the result as a table.
-\fB-a\fP print all the subvolumes in the filesystem.
+\fB-a\fP print all the subvolumes in the filesystem and distinguish between
+absolute and relative path with respect to the given <path>.
\fB-r\fP only readonly subvolumes in the filesystem wille be listed.

#7 lore raw
Quoted 19 lines · Lukáš Czerner

Date: Thu, 31 Jan 2013 07:40:37 +0100 (CET)
From: Lukáš Czerner <[email protected]>
To: Gene Czarcinski <[email protected]>
Cc: Lukáš Czerner <[email protected]>,
linux-btrfs <[email protected]>
Subject: Re: [PATCH 1/3] Btrfs-progs: move path modification to filters

Quoted 10 lines · Gene Czarcinski

Date: Wed, 30 Jan 2013 13:03:30 -0500
From: Gene Czarcinski <[email protected]>
To: Lukáš Czerner <[email protected]>
Cc: linux-btrfs <[email protected]>
Subject: Re: [PATCH 1/3] Btrfs-progs: move path modification to filters

Ignoring for the moment whether these patches are a good idea or not, what is the base upon which these patches were built. You might want to consider rebasing them to David Sterba's integration-20130130

Quoted 6 lines
Quoted 1 line

Gene

Hi,

yet it has been a while since I've posted it so I guess I have to rebase.

Just to be sure sure I have to ask. Which is the btrfs-progs repository/branch I should base my work on ? Currently I am using repostitory

git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git

and master branch. Is that ok ?

Thanks!
-Lukas

Quoted 158 lines

Thanks!
-Lukas

Quoted 154 lines · Lukáš Czerner
Quoted 150 lines · Lukáš Czerner
Quoted 21 lines

Date: Thu, 10 Jan 2013 13:02:42 +0100 (CET)
From: Lukáš Czerner <[email protected]>
To: Lukas Czerner <[email protected]>
Cc: [email protected], [email protected], [email protected]
Subject: Re: [PATCH 1/3] Btrfs-progs: move path modification to filters

Quoted 11 lines · Lukas Czerner

Date: Tue, 11 Dec 2012 15:24:58 +0100
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
Lukas Czerner <[email protected]>
Subject: [PATCH 1/3] Btrfs-progs: move path modification to filters

Commit 8e8e019e910f20947fea7eff5da40753639d8870 introduces -a option which will list all subvolumes with distinguishing between relative and absolute by prepending absolute patch with "<FS_TREE>".

Quoted 8 lines
Quoted 3 lines

This commit moves the path modification to a filter code rather than doing so in path construction in resolve_root(). This gives us more flexibility in formatting path output.

ping

any comments on this ?

-Lukas

ping

Quoted 118 lines
Quoted 118 lines
---
  btrfs-list.c     |   32 +++++++++++++++++++++++---------
  btrfs-list.h     |    1 +
  cmds-subvolume.c |   11 +++++++++--
  man/btrfs.8.in   |    3 ++-
  4 files changed, 35 insertions(+), 12 deletions(-)
btrfs-list.c +22 -9
index e5f0f96..77d99f8 100644
@@ -628,15 +628,6 @@ static int resolve_root(struct root_lookup *rl,
 struct root_info *ri,
  		}
    		if (next == BTRFS_FS_TREE_OBJECTID) {
-			char p[] = "<FS_TREE>";
-			add_len = strlen(p);
-			len = strlen(full_path);
-			tmp = malloc(len + add_len + 2);
-			memcpy(tmp + add_len + 1, full_path, len);
-			tmp[add_len] = '/';
-			memcpy(tmp, p, add_len);
-			free(full_path);
-			full_path = tmp;
  			ri->top_id = next;
  			break;
  		}
@@ -1176,6 +1167,28 @@ static int filter_topid_equal(struct root_info
 *ri, u64 data)
  	return ri->top_id == data;
  }
  +static int filter_full_path(struct root_info *ri, u64 data)
+{
+	if (ri->full_path && ri->top_id != data) {
+		char *tmp;
+		char p[] = "<FS_TREE>";
+		int add_len = strlen(p);
+		int len = strlen(ri->full_path);
+
+		tmp = malloc(len + add_len + 2);
+		if (!tmp) {
+			fprintf(stderr, "memory allocation failed\n");
+			exit(1);
+		}
+		memcpy(tmp + add_len + 1, ri->full_path, len);
+		tmp[add_len] = '/';
+		memcpy(tmp, p, add_len);
+		free(ri->full_path);
+		ri->full_path = tmp;
+	}
+	return 1;
+}
+
  static btrfs_list_filter_func all_filter_funcs[] = {
  	[BTRFS_LIST_FILTER_ROOTID]		= filter_by_rootid,
  	[BTRFS_LIST_FILTER_SNAPSHOT_ONLY]	= filter_snapshot,
@@ -1187,6 +1200,7 @@ static btrfs_list_filter_func all_filter_funcs[] =
 {
  	[BTRFS_LIST_FILTER_CGEN_LESS]		= filter_cgen_less,
  	[BTRFS_LIST_FILTER_CGEN_EQUAL]          = filter_cgen_equal,
  	[BTRFS_LIST_FILTER_TOPID_EQUAL]		= filter_topid_equal,
+	[BTRFS_LIST_FILTER_FULL_PATH]		= filter_full_path,
  };
    struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void)
btrfs-list.h +1 -0
index cde4b3c..f7fbea6 100644
@@ -71,6 +71,7 @@ enum btrfs_list_filter_enum {
  	BTRFS_LIST_FILTER_CGEN_LESS,
  	BTRFS_LIST_FILTER_CGEN_MORE,
  	BTRFS_LIST_FILTER_TOPID_EQUAL,
+	BTRFS_LIST_FILTER_FULL_PATH,
  	BTRFS_LIST_FILTER_MAX,
  };
  diff --git a/cmds-subvolume.c b/cmds-subvolume.c

index ac39f7b..37cb8cc 100644

cmds-subvolume.c +3 -1
@@ -277,7 +277,9 @@ static const char * const cmd_subvol_list_usage[] =
 {
  	"List subvolumes (and snapshots)",
  	"",
  	"-p           print parent ID",
-	"-a           print all the subvolumes in the filesystem.",
+	"-a           print all the subvolumes in the filesystem and",
+	"             distinguish absolute and relative path with respect",
+	"             to the given <path>",
  	"-u           print the uuid of subvolumes (and snapshots)",
  	"-t           print the result as a table",

"-s list snapshots only in the filesystem",

cmds-subvolume.c +6 -1
@@ -400,7 +402,12 @@ static int cmd_subvol_list(int argc, char **argv)
  	}
    	top_id = btrfs_list_get_path_rootid(fd);
-	if (!is_list_all)
+
+	if (is_list_all)
+		btrfs_list_setup_filter(&filter_set,
+					BTRFS_LIST_FILTER_FULL_PATH,
+					top_id);
+	else
  		btrfs_list_setup_filter(&filter_set,
  					BTRFS_LIST_FILTER_TOPID_EQUAL,
  					top_id);
man/btrfs.8.in +0 -0
index 9222580..d6d8e94 100644
@@ -124,7 +124,8 @@ and top level. The parent's ID may be used at mount

time via the
\fB-t\fP print the result as a table.
-\fB-a\fP print all the subvolumes in the filesystem.
+\fB-a\fP print all the subvolumes in the filesystem and distinguish between
+absolute and relative path with respect to the given <path>.
\fB-r\fP only readonly subvolumes in the filesystem wille be listed.

#8 lore raw
Quoted 6 lines · Lukáš Czerner

Just to be sure sure I have to ask. Which is the btrfs-progs repository/branch I should base my work on ? Currently I am using repostitory

git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git

and master branch. Is that ok ?

No need to rebase now, there's only one easy merge conflict in 1/3.

thanks,
david