linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8 v2] add show command to the subvol sub command
@ 2012-12-28  3:12 Anand jain
  2012-12-28  3:12 ` [PATCH 1/8] Btrfs-progs: move open_file_or_dir() to utils.c Anand jain
                   ` (8 more replies)
  0 siblings, 9 replies; 28+ messages in thread
From: Anand jain @ 2012-12-28  3:12 UTC (permalink / raw)
  To: linux-btrfs

From: Anand Jain <anand.jain@oracle.com>

v1->v2: Rebased and merged with the newer patch (which are not yet in
the git), and will now print few more parameters of the subvol.

Anand Jain (8):
  Btrfs-progs: move open_file_or_dir() to utils.c
  Btrfs-progs: Move printing outside of btrfs_list_subvols
  Btrfs-progs: add parent uuid for snapshots
  Btrfs-progs: move struct root_info to btrfs-list.h
  Btrfs-progs: function to get root_info of a subvol
  Btrfs-progs: provide method to check if filter is set
  Btrfs-progs: add method to filter snapshots by parent uuid
  Btrfs-progs: add show command to display detailed information about
    the subvol

 Makefile         |    4 +-
 btrfs-list.c     |  157 +++++++++++++++++++++++++++++++++---------------------
 btrfs-list.h     |   54 ++++++++++++++++++-
 btrfsctl.c       |    7 ++-
 cmds-balance.c   |    1 +
 cmds-inspect.c   |    1 +
 cmds-qgroup.c    |    1 +
 cmds-quota.c     |    1 +
 cmds-subvolume.c |  133 ++++++++++++++++++++++++++++++++++++++++++++-
 commands.h       |    3 -
 common.c         |   46 ----------------
 man/btrfs.8.in   |    6 ++
 utils.c          |   30 ++++++++++-
 utils.h          |    3 +
 14 files changed, 326 insertions(+), 121 deletions(-)
 delete mode 100644 common.c


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

* [PATCH 1/8] Btrfs-progs: move open_file_or_dir() to utils.c
  2012-12-28  3:12 [PATCH 0/8 v2] add show command to the subvol sub command Anand jain
@ 2012-12-28  3:12 ` Anand jain
  2012-12-28  3:12 ` [PATCH 2/8] Btrfs-progs: Move printing outside of btrfs_list_subvols Anand jain
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Anand jain @ 2012-12-28  3:12 UTC (permalink / raw)
  To: linux-btrfs

From: Anand Jain <anand.jain@oracle.com>

The definition of the function open_file_or_dir() is moved from common.c
to utils.c in order to be able to share some common code between scrub
and the device stats in the following step. That common code uses
open_file_or_dir(). Since open_file_or_dir() makes use of the function
dirfd(3), the required XOPEN version was raised from 6 to 7.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Original-Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
---
 Makefile         |    4 ++--
 btrfsctl.c       |    7 ++++---
 cmds-balance.c   |    1 +
 cmds-inspect.c   |    1 +
 cmds-qgroup.c    |    1 +
 cmds-quota.c     |    1 +
 cmds-subvolume.c |    1 +
 commands.h       |    3 ---
 common.c         |   46 ----------------------------------------------
 utils.c          |   30 ++++++++++++++++++++++++++++--
 utils.h          |    3 +++
 11 files changed, 42 insertions(+), 56 deletions(-)
 delete mode 100644 common.c

diff --git a/Makefile b/Makefile
index 4894903..8576d90 100644
--- a/Makefile
+++ b/Makefile
@@ -41,8 +41,8 @@ all: version $(progs) manpages
 version:
 	bash version.sh
 
-btrfs: $(objects) btrfs.o help.o common.o $(cmds_objects)
-	$(CC) $(CFLAGS) -o btrfs btrfs.o help.o common.o $(cmds_objects) \
+btrfs: $(objects) btrfs.o help.o $(cmds_objects)
+	$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
 		$(objects) $(LDFLAGS) $(LIBS) -lpthread
 
 calc-size: $(objects) calc-size.o
diff --git a/btrfsctl.c b/btrfsctl.c
index 518684c..049a5f3 100644
--- a/btrfsctl.c
+++ b/btrfsctl.c
@@ -63,7 +63,7 @@ static void print_usage(void)
 	exit(1);
 }
 
-static int open_file_or_dir(const char *fname)
+static int btrfsctl_open_file_or_dir(const char *fname)
 {
 	int ret;
 	struct stat st;
@@ -91,6 +91,7 @@ static int open_file_or_dir(const char *fname)
 	}
 	return fd;
 }
+
 int main(int ac, char **av)
 {
 	char *fname = NULL;
@@ -128,7 +129,7 @@ int main(int ac, char **av)
 			snap_location = strdup(fullpath);
 			snap_location = dirname(snap_location);
 
-			snap_fd = open_file_or_dir(snap_location);
+			snap_fd = btrfsctl_open_file_or_dir(snap_location);
 
 			name = strdup(fullpath);
 			name = basename(name);
@@ -238,7 +239,7 @@ int main(int ac, char **av)
 		}
 		name = fname;
 	 } else {
-		fd = open_file_or_dir(fname);
+		fd = btrfsctl_open_file_or_dir(fname);
 	 }
 
 	if (name) {
diff --git a/cmds-balance.c b/cmds-balance.c
index 38a7426..6268b61 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -28,6 +28,7 @@
 #include "volumes.h"
 
 #include "commands.h"
+#include "utils.h"
 
 static const char * const balance_cmd_group_usage[] = {
 	"btrfs [filesystem] balance <command> [options] <path>",
diff --git a/cmds-inspect.c b/cmds-inspect.c
index edabff5..79e069b 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -22,6 +22,7 @@
 
 #include "kerncompat.h"
 #include "ioctl.h"
+#include "utils.h"
 
 #include "commands.h"
 #include "btrfs-list.h"
diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 1525c11..cafc284 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -24,6 +24,7 @@
 #include "ioctl.h"
 
 #include "commands.h"
+#include "utils.h"
 
 static const char * const qgroup_cmd_group_usage[] = {
 	"btrfs qgroup <command> [options] <path>",
diff --git a/cmds-quota.c b/cmds-quota.c
index cf9ad97..8481514 100644
--- a/cmds-quota.c
+++ b/cmds-quota.c
@@ -23,6 +23,7 @@
 #include "ioctl.h"
 
 #include "commands.h"
+#include "utils.h"
 
 static const char * const quota_cmd_group_usage[] = {
 	"btrfs quota <command> [options] <path>",
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index ac39f7b..e3cdb1e 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -32,6 +32,7 @@
 #include "ctree.h"
 #include "commands.h"
 #include "btrfs-list.h"
+#include "utils.h"
 
 static const char * const subvolume_cmd_group_usage[] = {
 	"btrfs subvolume <command> <args>",
diff --git a/commands.h b/commands.h
index bb6d2dd..8114a73 100644
--- a/commands.h
+++ b/commands.h
@@ -79,9 +79,6 @@ void help_ambiguous_token(const char *arg, const struct cmd_group *grp);
 
 void help_command_group(const struct cmd_group *grp, int argc, char **argv);
 
-/* common.c */
-int open_file_or_dir(const char *fname);
-
 extern const struct cmd_group subvolume_cmd_group;
 extern const struct cmd_group filesystem_cmd_group;
 extern const struct cmd_group balance_cmd_group;
diff --git a/common.c b/common.c
deleted file mode 100644
index 03f6570..0000000
--- a/common.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License v2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <fcntl.h>
-
-int open_file_or_dir(const char *fname)
-{
-	int ret;
-	struct stat st;
-	DIR *dirstream;
-	int fd;
-
-	ret = stat(fname, &st);
-	if (ret < 0) {
-		return -1;
-	}
-	if (S_ISDIR(st.st_mode)) {
-		dirstream = opendir(fname);
-		if (!dirstream) {
-			return -2;
-		}
-		fd = dirfd(dirstream);
-	} else {
-		fd = open(fname, O_RDWR);
-	}
-	if (fd < 0) {
-		return -3;
-	}
-	return fd;
-}
diff --git a/utils.c b/utils.c
index 205e667..774f81d 100644
--- a/utils.c
+++ b/utils.c
@@ -16,8 +16,9 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 600
-#define __USE_XOPEN2K
+#define _XOPEN_SOURCE 700
+#define __USE_XOPEN2K8
+#define __XOPEN2K8 /* due to an error in dirent.h, to get dirfd() */
 #include <stdio.h>
 #include <stdlib.h>
 #ifndef __CHECKER__
@@ -1220,3 +1221,28 @@ scan_again:
 	return 0;
 }
 
+int open_file_or_dir(const char *fname)
+{
+	int ret;
+	struct stat st;
+	DIR *dirstream;
+	int fd;
+
+	ret = stat(fname, &st);
+	if (ret < 0) {
+		return -1;
+	}
+	if (S_ISDIR(st.st_mode)) {
+		dirstream = opendir(fname);
+		if (!dirstream) {
+			return -2;
+		}
+		fd = dirfd(dirstream);
+	} else {
+		fd = open(fname, O_RDWR);
+	}
+	if (fd < 0) {
+		return -3;
+	}
+	return fd;
+}
diff --git a/utils.h b/utils.h
index 3a0368b..6975f10 100644
--- a/utils.h
+++ b/utils.h
@@ -19,6 +19,8 @@
 #ifndef __UTILS__
 #define __UTILS__
 
+#include "ctree.h"
+
 #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
 
 int make_btrfs(int fd, const char *device, const char *label,
@@ -46,4 +48,5 @@ int check_label(char *input);
 int get_mountpt(char *dev, char *mntpt, size_t size);
 
 int btrfs_scan_block_devices(int run_ioctl);
+int open_file_or_dir(const char *fname);
 #endif
-- 
1.7.1


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

* [PATCH 2/8] Btrfs-progs: Move printing outside of btrfs_list_subvols
  2012-12-28  3:12 [PATCH 0/8 v2] add show command to the subvol sub command Anand jain
  2012-12-28  3:12 ` [PATCH 1/8] Btrfs-progs: move open_file_or_dir() to utils.c Anand jain
@ 2012-12-28  3:12 ` Anand jain
  2012-12-28  3:12 ` [PATCH 3/8] Btrfs-progs: add parent uuid for snapshots Anand jain
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Anand jain @ 2012-12-28  3:12 UTC (permalink / raw)
  To: linux-btrfs

From: Anand Jain <anand.jain@oracle.com>

its better to have btrfs_list_subvols just return witout printing
so that btrfs_list_subvols can be reused.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c     |   28 ++++++++++++++++++----------
 btrfs-list.h     |    2 +-
 cmds-subvolume.c |    4 ++--
 3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index e5f0f96..b656286 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1441,15 +1441,11 @@ 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 btrfs_list_subvols(int fd, struct root_lookup *root_lookup)
 {
-	struct root_lookup root_lookup;
-	struct root_lookup root_sort;
 	int ret;
 
-	ret = __list_subvol_search(fd, &root_lookup);
+	ret = __list_subvol_search(fd, root_lookup);
 	if (ret) {
 		fprintf(stderr, "ERROR: can't perform the search - %s\n",
 				strerror(errno));
@@ -1460,16 +1456,28 @@ int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
 	 * now we have an rbtree full of root_info objects, but we need to fill
 	 * in their path names within the subvol that is referencing each one.
 	 */
-	ret = __list_subvol_fill_paths(fd, &root_lookup);
-	if (ret < 0)
-		return ret;
+	ret = __list_subvol_fill_paths(fd, root_lookup);
+	return ret;
+}
 
+int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
+		       struct btrfs_list_comparer_set *comp_set,
+		       int is_tab_result)
+{
+	struct root_lookup root_lookup;
+	struct root_lookup root_sort;
+	int ret;
+
+	ret = btrfs_list_subvols(fd, &root_lookup);
+	if (ret)
+		return ret;
 	__filter_and_sort_subvol(&root_lookup, &root_sort, filter_set,
 				 comp_set, fd);
 
 	print_all_volume_info(&root_sort, is_tab_result);
 	__free_all_subvolumn(&root_lookup);
-	return ret;
+
+	return 0;
 }
 
 static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh,
diff --git a/btrfs-list.h b/btrfs-list.h
index cde4b3c..71fe0f3 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -98,7 +98,7 @@ int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
 			      enum btrfs_list_comp_enum comparer,
 			      int is_descending);
 
-int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
+int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
 		       struct btrfs_list_comparer_set *comp_set,
 			int is_tab_result);
 int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index e3cdb1e..c35dff7 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -406,7 +406,7 @@ static int cmd_subvol_list(int argc, char **argv)
 					BTRFS_LIST_FILTER_TOPID_EQUAL,
 					top_id);
 
-	ret = btrfs_list_subvols(fd, filter_set, comparer_set,
+	ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
 				is_tab_result);
 	if (ret)
 		return 19;
@@ -613,7 +613,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_print(fd, filter_set, NULL, 0);
 	if (ret)
 		return 19;
 	return 0;
-- 
1.7.1


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

* [PATCH 3/8] Btrfs-progs: add parent uuid for snapshots
  2012-12-28  3:12 [PATCH 0/8 v2] add show command to the subvol sub command Anand jain
  2012-12-28  3:12 ` [PATCH 1/8] Btrfs-progs: move open_file_or_dir() to utils.c Anand jain
  2012-12-28  3:12 ` [PATCH 2/8] Btrfs-progs: Move printing outside of btrfs_list_subvols Anand jain
@ 2012-12-28  3:12 ` Anand jain
  2012-12-28  3:12 ` [PATCH 4/8] Btrfs-progs: move struct root_info to btrfs-list.h Anand jain
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Anand jain @ 2012-12-28  3:12 UTC (permalink / raw)
  To: linux-btrfs

From: Anand Jain <anand.jain@oracle.com>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c     |   32 +++++++++++++++++++++++++++-----
 btrfs-list.h     |    1 +
 cmds-subvolume.c |    6 +++++-
 3 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index b656286..cc065e9 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -80,6 +80,7 @@ struct root_info {
 	time_t otime;
 
 	u8 uuid[BTRFS_UUID_SIZE];
+	u8 puuid[BTRFS_UUID_SIZE];
 
 	/* path from the subvol we live in to this root, including the
 	 * root's name.  This is null until we do the extra lookup ioctl.
@@ -128,6 +129,11 @@ struct {
 		.need_print	= 0,
 	},
 	{
+		.name		= "parent UUID",
+		.column_name	= "Parent UUID",
+		.need_print	= 0,
+	},
+	{
 		.name		= "uuid",
 		.column_name	= "UUID",
 		.need_print	= 0,
@@ -435,7 +441,7 @@ static struct root_info *root_tree_search(struct root_lookup *root_tree,
 static int update_root(struct root_lookup *root_lookup,
 		       u64 root_id, u64 ref_tree, u64 root_offset, u64 flags,
 		       u64 dir_id, char *name, int name_len, u64 ogen, u64 gen,
-		       time_t ot, void *uuid)
+		       time_t ot, void *uuid, void *puuid)
 {
 	struct root_info *ri;
 
@@ -472,6 +478,8 @@ static int update_root(struct root_lookup *root_lookup,
 		ri->otime = ot;
 	if (uuid)
 		memcpy(&ri->uuid, uuid, BTRFS_UUID_SIZE);
+	if (puuid)
+		memcpy(&ri->puuid, puuid, BTRFS_UUID_SIZE);
 
 	return 0;
 }
@@ -489,17 +497,18 @@ static int update_root(struct root_lookup *root_lookup,
  * gen: the current generation of the root
  * ot: the original time(create time) of the root
  * uuid: uuid of the root
+ * puuid: uuid of the root parent if any
  */
 static int add_root(struct root_lookup *root_lookup,
 		    u64 root_id, u64 ref_tree, u64 root_offset, u64 flags,
 		    u64 dir_id, char *name, int name_len, u64 ogen, u64 gen,
-		    time_t ot, void *uuid)
+		    time_t ot, void *uuid, void *puuid)
 {
 	struct root_info *ri;
 	int ret;
 
 	ret = update_root(root_lookup, root_id, ref_tree, root_offset, flags,
-			  dir_id, name, name_len, ogen, gen, ot, uuid);
+			  dir_id, name, name_len, ogen, gen, ot, uuid, puuid);
 	if (!ret)
 		return 0;
 
@@ -540,6 +549,9 @@ static int add_root(struct root_lookup *root_lookup,
 	if (uuid) 
 		memcpy(&ri->uuid, uuid, BTRFS_UUID_SIZE);
 
+	if (puuid)
+		memcpy(&ri->puuid, puuid, BTRFS_UUID_SIZE);
+
 	ret = root_tree_insert(root_lookup, ri);
 	if (ret) {
 		printf("failed to insert tree %llu\n", (unsigned long long)root_id);
@@ -1022,6 +1034,7 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup)
 	int i;
 	time_t t;
 	u8 uuid[BTRFS_UUID_SIZE];
+	u8 puuid[BTRFS_UUID_SIZE];
 
 	root_lookup_init(root_lookup);
 	memset(&args, 0, sizeof(args));
@@ -1075,7 +1088,7 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup)
 
 				add_root(root_lookup, sh->objectid, sh->offset,
 					 0, 0, dir_id, name, name_len, 0, 0, 0,
-					 NULL);
+					 NULL, NULL);
 			} else if (sh->type == BTRFS_ROOT_ITEM_KEY) {
 				ri = (struct btrfs_root_item *)(args.buf + off);
 				gen = btrfs_root_generation(ri);
@@ -1085,15 +1098,17 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup)
 					t = ri->otime.sec;
 					ogen = btrfs_root_otransid(ri);
 					memcpy(uuid, ri->uuid, BTRFS_UUID_SIZE);
+					memcpy(puuid, ri->parent_uuid, BTRFS_UUID_SIZE);
 				} else {
 					t = 0;
 					ogen = 0;
 					memset(uuid, 0, BTRFS_UUID_SIZE);
+					memset(puuid, 0, BTRFS_UUID_SIZE);
 				}
 
 				add_root(root_lookup, sh->objectid, 0,
 					 sh->offset, flags, 0, NULL, 0, ogen,
-					 gen, t, uuid);
+					 gen, t, uuid, puuid);
 			}
 
 			off += sh->len;
@@ -1347,6 +1362,13 @@ static void print_subvolume_column(struct root_info *subv,
 			uuid_unparse(subv->uuid, uuidparse);
 		printf("%s", uuidparse);
 		break;
+	case BTRFS_LIST_PUUID:
+		if (uuid_is_null(subv->puuid))
+			strcpy(uuidparse, "-");
+		else
+			uuid_unparse(subv->puuid, uuidparse);
+		printf("%s", uuidparse);
+		break;
 	case BTRFS_LIST_PATH:
 		BUG_ON(!subv->full_path);
 		printf("%s", subv->full_path);
diff --git a/btrfs-list.h b/btrfs-list.h
index 71fe0f3..855e73d 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -53,6 +53,7 @@ enum btrfs_list_column_enum {
 	BTRFS_LIST_PARENT,
 	BTRFS_LIST_TOP_LEVEL,
 	BTRFS_LIST_OTIME,
+	BTRFS_LIST_PUUID,
 	BTRFS_LIST_UUID,
 	BTRFS_LIST_PATH,
 	BTRFS_LIST_ALL,
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index c35dff7..ee36463 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -280,6 +280,7 @@ static const char * const cmd_subvol_list_usage[] = {
 	"-p           print parent ID",
 	"-a           print all the subvolumes in the filesystem.",
 	"-u           print the uuid of subvolumes (and snapshots)",
+	"-q           print the parent uuid of snapshots",
 	"-t           print the result as a table",
 	"-s           list snapshots only in the filesystem",
 	"-r           list readonly subvolumes (including snapshots)",
@@ -319,7 +320,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);
+				    "apsuqrg:c:t", long_options, NULL);
 		if (c < 0)
 			break;
 
@@ -343,6 +344,9 @@ static int cmd_subvol_list(int argc, char **argv)
 		case 'u':
 			btrfs_list_setup_print_column(BTRFS_LIST_UUID);
 			break;
+		case 'q':
+			btrfs_list_setup_print_column(BTRFS_LIST_PUUID);
+			break;
 		case 'r':
 			flags |= BTRFS_ROOT_SUBVOL_RDONLY;
 			break;
-- 
1.7.1


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

* [PATCH 4/8] Btrfs-progs: move struct root_info to btrfs-list.h
  2012-12-28  3:12 [PATCH 0/8 v2] add show command to the subvol sub command Anand jain
                   ` (2 preceding siblings ...)
  2012-12-28  3:12 ` [PATCH 3/8] Btrfs-progs: add parent uuid for snapshots Anand jain
@ 2012-12-28  3:12 ` Anand jain
  2012-12-28  3:12 ` [PATCH 5/8] Btrfs-progs: function to get root_info of a subvol Anand jain
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Anand jain @ 2012-12-28  3:12 UTC (permalink / raw)
  To: linux-btrfs

From: Anand Jain <anand.jain@oracle.com>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c |   47 -----------------------------------------------
 btrfs-list.h |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index cc065e9..1851f3e 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -46,53 +46,6 @@ struct root_lookup {
 	struct rb_root root;
 };
 
-/*
- * one of these for each root we find.
- */
-struct root_info {
-	struct rb_node rb_node;
-	struct rb_node sort_node;
-
-	/* this root's id */
-	u64 root_id;
-
-	/* equal the offset of the root's key */
-	u64 root_offset;
-
-	/* flags of the root */
-	u64 flags;
-
-	/* the id of the root that references this one */
-	u64 ref_tree;
-
-	/* the dir id we're in from ref_tree */
-	u64 dir_id;
-
-	u64 top_id;
-
-	/* generation when the root is created or last updated */
-	u64 gen;
-
-	/* creation generation of this root in sec*/
-	u64 ogen;
-
-	/* creation time of this root in sec*/
-	time_t otime;
-
-	u8 uuid[BTRFS_UUID_SIZE];
-	u8 puuid[BTRFS_UUID_SIZE];
-
-	/* path from the subvol we live in to this root, including the
-	 * root's name.  This is null until we do the extra lookup ioctl.
-	 */
-	char *path;
-
-	/* the name of this root in the directory it lives in */
-	char *name;
-
-	char *full_path;
-};
-
 struct {
 	char	*name;
 	char	*column_name;
diff --git a/btrfs-list.h b/btrfs-list.h
index 855e73d..3b7b680 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -18,7 +18,52 @@
 
 #include "kerncompat.h"
 
-struct root_info;
+/*
+ * one of these for each root we find.
+ */
+struct root_info {
+	struct rb_node rb_node;
+	struct rb_node sort_node;
+
+	/* this root's id */
+	u64 root_id;
+
+	/* equal the offset of the root's key */
+	u64 root_offset;
+
+	/* flags of the root */
+	u64 flags;
+
+	/* the id of the root that references this one */
+	u64 ref_tree;
+
+	/* the dir id we're in from ref_tree */
+	u64 dir_id;
+
+	u64 top_id;
+
+	/* generation when the root is created or last updated */
+	u64 gen;
+
+	/* creation generation of this root in sec*/
+	u64 ogen;
+
+	/* creation time of this root in sec*/
+	time_t otime;
+
+	u8 uuid[BTRFS_UUID_SIZE];
+	u8 puuid[BTRFS_UUID_SIZE];
+
+	/* path from the subvol we live in to this root, including the
+	 * root's name.  This is null until we do the extra lookup ioctl.
+	 */
+	char *path;
+
+	/* the name of this root in the directory it lives in */
+	char *name;
+
+	char *full_path;
+};
 
 typedef int (*btrfs_list_filter_func)(struct root_info *, u64);
 typedef int (*btrfs_list_comp_func)(struct root_info *, struct root_info *,
-- 
1.7.1


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

* [PATCH 5/8] Btrfs-progs: function to get root_info of a subvol
  2012-12-28  3:12 [PATCH 0/8 v2] add show command to the subvol sub command Anand jain
                   ` (3 preceding siblings ...)
  2012-12-28  3:12 ` [PATCH 4/8] Btrfs-progs: move struct root_info to btrfs-list.h Anand jain
@ 2012-12-28  3:12 ` Anand jain
  2012-12-28  3:13 ` [PATCH 6/8] Btrfs-progs: provide method to check if filter is set Anand jain
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Anand jain @ 2012-12-28  3:12 UTC (permalink / raw)
  To: linux-btrfs

From: Anand Jain <anand.jain@oracle.com>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c |   37 +++++++++++++++++++++++++++++++++++++
 btrfs-list.h |    1 +
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index 1851f3e..cb458f1 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1455,6 +1455,43 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
 	return 0;
 }
 
+int btrfs_get_subvol(int fd, struct root_info *the_ri)
+{
+	int ret = -1;
+	struct root_lookup rl;
+	struct rb_node *rbn;
+	struct root_info *ri;
+	u64 top_id = btrfs_list_get_path_rootid(fd);
+
+	if (btrfs_list_subvols(fd, &rl))
+		return 13;
+
+	rbn = rb_first(&rl.root);
+	while(rbn) {
+		ri = rb_entry(rbn, struct root_info, rb_node);
+		resolve_root(&rl, ri, top_id);
+		if (!comp_entry_with_path(the_ri, ri, 0)) {
+			memcpy(the_ri, ri, offsetof(struct root_info, path));
+			if (ri->path)
+				the_ri->path = strdup(ri->path);
+			else
+				the_ri->path = NULL;
+			if (ri->name)
+				the_ri->name = strdup(ri->name);
+			else
+				the_ri->name = NULL;
+			if (ri->full_path)
+				the_ri->full_path = strdup(ri->full_path);
+			else
+				the_ri->name = NULL;
+			ret = 0;
+		}
+		rbn = rb_next(rbn);
+	}
+	__free_all_subvolumn(&rl);
+	return ret;
+}
+
 static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh,
 			    struct btrfs_file_extent_item *item,
 			    u64 found_gen, u64 *cache_dirid,
diff --git a/btrfs-list.h b/btrfs-list.h
index 3b7b680..580d4d1 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -151,3 +151,4 @@ 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);
 u64 btrfs_list_get_path_rootid(int fd);
+int btrfs_get_subvol(int fd, struct root_info *the_ri);
-- 
1.7.1


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

* [PATCH 6/8] Btrfs-progs: provide method to check if filter is set
  2012-12-28  3:12 [PATCH 0/8 v2] add show command to the subvol sub command Anand jain
                   ` (4 preceding siblings ...)
  2012-12-28  3:12 ` [PATCH 5/8] Btrfs-progs: function to get root_info of a subvol Anand jain
@ 2012-12-28  3:13 ` Anand jain
  2012-12-28  3:13 ` [PATCH 7/8] Btrfs-progs: add method to filter snapshots by parent uuid Anand jain
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Anand jain @ 2012-12-28  3:13 UTC (permalink / raw)
  To: linux-btrfs

From: Anand Jain <anand.jain@oracle.com>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c |   11 +++++++++++
 btrfs-list.h |    2 ++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index cb458f1..308b54c 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1181,6 +1181,17 @@ void btrfs_list_free_filter_set(struct btrfs_list_filter_set *filter_set)
 	free(filter_set);
 }
 
+int btrfs_list_check_filter_set(struct btrfs_list_filter_set *fset,
+			enum btrfs_list_filter_enum filter)
+{
+	int i;
+	for (i=0; i < fset->nfilters; i++) {
+		if (fset->filters[i].filter_func == all_filter_funcs[filter])
+			return i;
+	}
+	return -1;
+}
+
 int btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
 			    enum btrfs_list_filter_enum filter, u64 data)
 {
diff --git a/btrfs-list.h b/btrfs-list.h
index 580d4d1..f5dbd47 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -152,3 +152,5 @@ int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
 char *btrfs_list_path_for_root(int fd, u64 root);
 u64 btrfs_list_get_path_rootid(int fd);
 int btrfs_get_subvol(int fd, struct root_info *the_ri);
+int btrfs_list_check_filter_set(struct btrfs_list_filter_set *fset,
+			enum btrfs_list_filter_enum filter);
-- 
1.7.1


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

* [PATCH 7/8] Btrfs-progs: add method to filter snapshots by parent uuid
  2012-12-28  3:12 [PATCH 0/8 v2] add show command to the subvol sub command Anand jain
                   ` (5 preceding siblings ...)
  2012-12-28  3:13 ` [PATCH 6/8] Btrfs-progs: provide method to check if filter is set Anand jain
@ 2012-12-28  3:13 ` Anand jain
  2012-12-28  3:13 ` [PATCH 8/8] Btrfs-progs: add show command to display detailed information about the subvol Anand jain
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
  8 siblings, 0 replies; 28+ messages in thread
From: Anand jain @ 2012-12-28  3:13 UTC (permalink / raw)
  To: linux-btrfs

From: Anand Jain <anand.jain@oracle.com>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c |    6 ++++++
 btrfs-list.h |    1 +
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index 308b54c..efce966 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1144,6 +1144,11 @@ static int filter_topid_equal(struct root_info *ri, u64 data)
 	return ri->top_id == data;
 }
 
+static int filter_by_parent(struct root_info *ri, u64 data)
+{
+	return !uuid_compare(ri->puuid, (u8 *)data);
+}
+
 static btrfs_list_filter_func all_filter_funcs[] = {
 	[BTRFS_LIST_FILTER_ROOTID]		= filter_by_rootid,
 	[BTRFS_LIST_FILTER_SNAPSHOT_ONLY]	= filter_snapshot,
@@ -1155,6 +1160,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_BY_PARENT]		= filter_by_parent,
 };
 
 struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void)
diff --git a/btrfs-list.h b/btrfs-list.h
index f5dbd47..d71d2b0 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -117,6 +117,7 @@ enum btrfs_list_filter_enum {
 	BTRFS_LIST_FILTER_CGEN_LESS,
 	BTRFS_LIST_FILTER_CGEN_MORE,
 	BTRFS_LIST_FILTER_TOPID_EQUAL,
+	BTRFS_LIST_FILTER_BY_PARENT,
 	BTRFS_LIST_FILTER_MAX,
 };
 
-- 
1.7.1


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

* [PATCH 8/8] Btrfs-progs: add show command to display detailed information about the subvol
  2012-12-28  3:12 [PATCH 0/8 v2] add show command to the subvol sub command Anand jain
                   ` (6 preceding siblings ...)
  2012-12-28  3:13 ` [PATCH 7/8] Btrfs-progs: add method to filter snapshots by parent uuid Anand jain
@ 2012-12-28  3:13 ` Anand jain
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
  8 siblings, 0 replies; 28+ messages in thread
From: Anand jain @ 2012-12-28  3:13 UTC (permalink / raw)
  To: linux-btrfs

From: Anand Jain <anand.jain@oracle.com>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds-subvolume.c |  122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 man/btrfs.8.in   |    6 +++
 2 files changed, 128 insertions(+), 0 deletions(-)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index ee36463..d5c45db 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -24,6 +24,7 @@
 #include <libgen.h>
 #include <limits.h>
 #include <getopt.h>
+#include <uuid/uuid.h>
 
 #include "kerncompat.h"
 #include "ioctl.h"
@@ -704,6 +705,126 @@ static int cmd_find_new(int argc, char **argv)
 	return 0;
 }
 
+static const char * const cmd_subvol_show_usage[] = {
+	"btrfs subvolume show <subvol-path>",
+	"Show more information of the subvolume",
+	NULL
+};
+
+static int cmd_subvol_show(int argc, char **argv)
+{
+	int ret, fd;
+	char *subvol, *mnt = NULL;
+	struct root_info get_ri;
+	char tstr[256];
+	char uuidparse[37];
+
+	if (check_argc_exact(argc, 2))
+		usage(cmd_subvol_show_usage);
+
+	subvol = realpath(argv[1],0);
+	if(!subvol) {
+		fprintf(stderr, "ERROR: finding real path for '%s', %s\n",
+			argv[1], strerror(errno));
+		return 12;
+	}
+
+	ret = test_issubvolume(subvol);
+	if (ret < 0) {
+		fprintf(stderr, "ERROR: error accessing '%s'\n", subvol);
+		free(subvol);
+		return 12;
+	}
+	if (!ret) {
+		fprintf(stderr, "ERROR: '%s' is not a subvolume\n", subvol);
+		free(subvol);
+		return 13;
+	}
+
+	ret = find_mount_root(subvol, &mnt);
+	if (ret < 0) {
+		fprintf(stderr, "ERROR: find_mount_root failed on %s: "
+				"%s\n", subvol, strerror(-ret));
+		free(subvol);
+		return 12;
+	}
+	if (!strcmp(subvol, mnt))
+		return 0;
+
+	/* this will point to after the mnt/" */
+	get_ri.full_path = subvol+strlen(mnt)+1;
+
+	if (!strcmp(get_ri.full_path, ""))
+		return 0;
+
+	fd = open_file_or_dir(mnt);
+	if (fd < 0) {
+		fprintf(stderr, "ERROR: can't access '%s'\n", subvol);
+		return 12;
+	}
+
+	if (btrfs_get_subvol(fd, &get_ri)) {
+		fprintf(stderr, "ERROR: can't find '%s'\n",
+			get_ri.full_path);
+		close(fd);
+		return 13;
+	}
+
+	/* print the info */
+	printf("%s/%s", mnt, get_ri.full_path);
+	printf("\n");
+
+	if (uuid_is_null(get_ri.uuid))
+		strcpy(uuidparse, "-");
+	else
+		uuid_unparse(get_ri.uuid, uuidparse);
+	printf("\t");
+	printf("uuid: \t\t\t%s", uuidparse);
+	printf("\n");
+
+	if (get_ri.otime)
+		strftime(tstr, 256, "%Y-%m-%d %X",
+			 localtime(&get_ri.otime));
+	else
+		strcpy(tstr, "-");
+	printf("\t");
+	printf("Creation time: \t\t%s", tstr);
+	printf("\n");
+
+	printf("\t");
+	printf("Object ID: \t\t%llu", get_ri.root_id);
+	printf("\n");
+
+	printf("\t");
+	printf("Generation (Gen): \t%llu", get_ri.gen);
+	printf("\n");
+
+	printf("\t");
+	printf("Gen at creation: \t%llu", get_ri.ogen);
+	printf("\n");
+
+	printf("\t");
+	printf("Parent: \t\t%llu", get_ri.ref_tree);
+	printf("\n");
+
+	printf("\t");
+	printf("Top Level: \t\t%llu", get_ri.top_id);
+	printf("\n");
+
+	/* clean up */
+	if (get_ri.path)
+		free(get_ri.path);
+	if (get_ri.name)
+		free(get_ri.name);
+	if (get_ri.full_path)
+		free(get_ri.full_path);
+
+	close(fd);
+	free(mnt);
+	free(subvol);
+	return 0;
+}
+
 const struct cmd_group subvolume_cmd_group = {
 	subvolume_cmd_group_usage, NULL, {
 		{ "create", cmd_subvol_create, cmd_subvol_create_usage, NULL, 0 },
@@ -715,6 +836,7 @@ const struct cmd_group subvolume_cmd_group = {
 		{ "set-default", cmd_subvol_set_default,
 			cmd_subvol_set_default_usage, NULL, 0 },
 		{ "find-new", cmd_find_new, cmd_find_new_usage, NULL, 0 },
+		{ "show", cmd_subvol_show, cmd_subvol_show_usage, NULL, 0 },
 		{ 0, 0, 0, 0, 0 }
 	}
 };
diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 9222580..57c25b0 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -17,6 +17,8 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBsubvolume get-default\fP\fI <path>\fP
 .PP
+\fBbtrfs\fP \fBsubvolume show\fP\fI <path>\fP
+.PP
 \fBbtrfs\fP \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] \
 [-s \fIstart\fR] [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> \
 [<\fIfile\fR>|<\fIdir\fR>...]
@@ -160,6 +162,10 @@ Get the default subvolume of the filesystem \fI<path>\fR. The output format
 is similar to \fBsubvolume list\fR command.
 .TP
 
+\fBsubvolume show\fR\fI <path>\fR
+Show information of a given subvolume in the \fI<path>\fR.
+.TP
+
 \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] [-s \fIstart\fR] \
 [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> [<\fIfile\fR>|<\fIdir\fR>...]
 
-- 
1.7.1


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

* [PATCH 00/11 V3] add show command to the subvol sub command
@ 2013-01-10 11:41 ` Anand Jain
  2013-01-10 11:41   ` [PATCH 01/11] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
                     ` (13 more replies)
  0 siblings, 14 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

This is an attempt to make btrfs cli more end user friendly.
And adds show subcommand to display all known (as of now)
information of the given subvol including its snapshot(s).

The below patch:
 "Btrfs-progs: accommodate different layout for printing subvol list"
obsoletes the previosuly submitted patch
 "Btrfs-progs: make provision to print subvol list tree format"

Please provide your review comments. Thanks.

An example output:

First list out all the subvols/snapshots using the list subcommand.

btrfs su list /btrfs
ID 256 gen 10 top level 5 path sv1
ID 259 gen 6 top level 5 path sv1/snap
ID 260 gen 7 top level 5 path snap
ID 261 gen 8 top level 5 path sv2
ID 262 gen 9 top level 5 path sv1/snap2
ID 263 gen 10 top level 5 path sv1/snap3

Then use show subcommand to know all known information about the
given subvol.

btrfs su show /btrfs/sv1
/btrfs/sv1
	uuid: 			508b12a5-ed2a-3942-af63-830967201070
	Parent uuid: 		-
	Creation time: 		2013-01-07 13:53:30
	Object ID: 		256
	Generation (Gen): 	10
	Gen at creation: 	5
	Parent: 		5
	Top Level: 		5
	Snapshot(s):
				sv1/snap
				sv1/snap2
				sv1/snap3


v2->v3: List snapshots of the given subvol if any.
        Uses a more simple approach to obtain the snapshots.

Anand Jain (11):
  Btrfs-progs: move open_file_or_dir() to utils.c
  Btrfs-progs: Move printing outside of btrfs_list_subvols
  Btrfs-progs: add parent uuid for snapshots
  Btrfs-progs: move struct root_info to btrfs-list.h
  Btrfs-progs: function to get root_info of a subvol
  Btrfs-progs: provide method to check if filter is set
  Btrfs-progs: add method to filter snapshots by parent uuid
  Btrfs-progs: put find_mount_root() in commands.h
  Btrfs-progs: maintain similar case in heading prefix
  Btrfs-progs: accommodate different layout for printing subvol list
  Btrfs-progs: add show to display all known parameters of the given
    subvol

 Makefile         |    4 +-
 btrfs-list.c     |  200 +++++++++++++++++++++++++++++++++++-------------------
 btrfs-list.h     |   60 +++++++++++++++-
 btrfsctl.c       |    7 +-
 cmds-balance.c   |    1 +
 cmds-inspect.c   |    1 +
 cmds-qgroup.c    |    1 +
 cmds-quota.c     |    1 +
 cmds-subvolume.c |  172 +++++++++++++++++++++++++++++++++++++++++++++-
 commands.h       |    6 +-
 common.c         |   46 ------------
 man/btrfs.8.in   |    6 ++
 utils.c          |   30 ++++++++-
 utils.h          |    3 +
 14 files changed, 405 insertions(+), 133 deletions(-)
 delete mode 100644 common.c


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

* [PATCH 01/11] Btrfs-progs: move open_file_or_dir() to utils.c
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
@ 2013-01-10 11:41   ` Anand Jain
  2013-01-10 11:41   ` [PATCH 02/11] Btrfs-progs: Move printing outside of btrfs_list_subvols Anand Jain
                     ` (12 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

The definition of the function open_file_or_dir() is moved from common.c
to utils.c in order to be able to share some common code between scrub
and the device stats in the following step. That common code uses
open_file_or_dir(). Since open_file_or_dir() makes use of the function
dirfd(3), the required XOPEN version was raised from 6 to 7.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Original-Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
---
 Makefile         |    4 ++--
 btrfsctl.c       |    7 ++++---
 cmds-balance.c   |    1 +
 cmds-inspect.c   |    1 +
 cmds-qgroup.c    |    1 +
 cmds-quota.c     |    1 +
 cmds-subvolume.c |    1 +
 commands.h       |    3 ---
 common.c         |   46 ----------------------------------------------
 utils.c          |   30 ++++++++++++++++++++++++++++--
 utils.h          |    3 +++
 11 files changed, 42 insertions(+), 56 deletions(-)
 delete mode 100644 common.c

diff --git a/Makefile b/Makefile
index 4894903..8576d90 100644
--- a/Makefile
+++ b/Makefile
@@ -41,8 +41,8 @@ all: version $(progs) manpages
 version:
 	bash version.sh
 
-btrfs: $(objects) btrfs.o help.o common.o $(cmds_objects)
-	$(CC) $(CFLAGS) -o btrfs btrfs.o help.o common.o $(cmds_objects) \
+btrfs: $(objects) btrfs.o help.o $(cmds_objects)
+	$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
 		$(objects) $(LDFLAGS) $(LIBS) -lpthread
 
 calc-size: $(objects) calc-size.o
diff --git a/btrfsctl.c b/btrfsctl.c
index 518684c..049a5f3 100644
--- a/btrfsctl.c
+++ b/btrfsctl.c
@@ -63,7 +63,7 @@ static void print_usage(void)
 	exit(1);
 }
 
-static int open_file_or_dir(const char *fname)
+static int btrfsctl_open_file_or_dir(const char *fname)
 {
 	int ret;
 	struct stat st;
@@ -91,6 +91,7 @@ static int open_file_or_dir(const char *fname)
 	}
 	return fd;
 }
+
 int main(int ac, char **av)
 {
 	char *fname = NULL;
@@ -128,7 +129,7 @@ int main(int ac, char **av)
 			snap_location = strdup(fullpath);
 			snap_location = dirname(snap_location);
 
-			snap_fd = open_file_or_dir(snap_location);
+			snap_fd = btrfsctl_open_file_or_dir(snap_location);
 
 			name = strdup(fullpath);
 			name = basename(name);
@@ -238,7 +239,7 @@ int main(int ac, char **av)
 		}
 		name = fname;
 	 } else {
-		fd = open_file_or_dir(fname);
+		fd = btrfsctl_open_file_or_dir(fname);
 	 }
 
 	if (name) {
diff --git a/cmds-balance.c b/cmds-balance.c
index 38a7426..6268b61 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -28,6 +28,7 @@
 #include "volumes.h"
 
 #include "commands.h"
+#include "utils.h"
 
 static const char * const balance_cmd_group_usage[] = {
 	"btrfs [filesystem] balance <command> [options] <path>",
diff --git a/cmds-inspect.c b/cmds-inspect.c
index edabff5..79e069b 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -22,6 +22,7 @@
 
 #include "kerncompat.h"
 #include "ioctl.h"
+#include "utils.h"
 
 #include "commands.h"
 #include "btrfs-list.h"
diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 1525c11..cafc284 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -24,6 +24,7 @@
 #include "ioctl.h"
 
 #include "commands.h"
+#include "utils.h"
 
 static const char * const qgroup_cmd_group_usage[] = {
 	"btrfs qgroup <command> [options] <path>",
diff --git a/cmds-quota.c b/cmds-quota.c
index cf9ad97..8481514 100644
--- a/cmds-quota.c
+++ b/cmds-quota.c
@@ -23,6 +23,7 @@
 #include "ioctl.h"
 
 #include "commands.h"
+#include "utils.h"
 
 static const char * const quota_cmd_group_usage[] = {
 	"btrfs quota <command> [options] <path>",
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index ac39f7b..e3cdb1e 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -32,6 +32,7 @@
 #include "ctree.h"
 #include "commands.h"
 #include "btrfs-list.h"
+#include "utils.h"
 
 static const char * const subvolume_cmd_group_usage[] = {
 	"btrfs subvolume <command> <args>",
diff --git a/commands.h b/commands.h
index bb6d2dd..8114a73 100644
--- a/commands.h
+++ b/commands.h
@@ -79,9 +79,6 @@ void help_ambiguous_token(const char *arg, const struct cmd_group *grp);
 
 void help_command_group(const struct cmd_group *grp, int argc, char **argv);
 
-/* common.c */
-int open_file_or_dir(const char *fname);
-
 extern const struct cmd_group subvolume_cmd_group;
 extern const struct cmd_group filesystem_cmd_group;
 extern const struct cmd_group balance_cmd_group;
diff --git a/common.c b/common.c
deleted file mode 100644
index 03f6570..0000000
--- a/common.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License v2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <fcntl.h>
-
-int open_file_or_dir(const char *fname)
-{
-	int ret;
-	struct stat st;
-	DIR *dirstream;
-	int fd;
-
-	ret = stat(fname, &st);
-	if (ret < 0) {
-		return -1;
-	}
-	if (S_ISDIR(st.st_mode)) {
-		dirstream = opendir(fname);
-		if (!dirstream) {
-			return -2;
-		}
-		fd = dirfd(dirstream);
-	} else {
-		fd = open(fname, O_RDWR);
-	}
-	if (fd < 0) {
-		return -3;
-	}
-	return fd;
-}
diff --git a/utils.c b/utils.c
index 205e667..774f81d 100644
--- a/utils.c
+++ b/utils.c
@@ -16,8 +16,9 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 600
-#define __USE_XOPEN2K
+#define _XOPEN_SOURCE 700
+#define __USE_XOPEN2K8
+#define __XOPEN2K8 /* due to an error in dirent.h, to get dirfd() */
 #include <stdio.h>
 #include <stdlib.h>
 #ifndef __CHECKER__
@@ -1220,3 +1221,28 @@ scan_again:
 	return 0;
 }
 
+int open_file_or_dir(const char *fname)
+{
+	int ret;
+	struct stat st;
+	DIR *dirstream;
+	int fd;
+
+	ret = stat(fname, &st);
+	if (ret < 0) {
+		return -1;
+	}
+	if (S_ISDIR(st.st_mode)) {
+		dirstream = opendir(fname);
+		if (!dirstream) {
+			return -2;
+		}
+		fd = dirfd(dirstream);
+	} else {
+		fd = open(fname, O_RDWR);
+	}
+	if (fd < 0) {
+		return -3;
+	}
+	return fd;
+}
diff --git a/utils.h b/utils.h
index 3a0368b..6975f10 100644
--- a/utils.h
+++ b/utils.h
@@ -19,6 +19,8 @@
 #ifndef __UTILS__
 #define __UTILS__
 
+#include "ctree.h"
+
 #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
 
 int make_btrfs(int fd, const char *device, const char *label,
@@ -46,4 +48,5 @@ int check_label(char *input);
 int get_mountpt(char *dev, char *mntpt, size_t size);
 
 int btrfs_scan_block_devices(int run_ioctl);
+int open_file_or_dir(const char *fname);
 #endif
-- 
1.7.1


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

* [PATCH 02/11] Btrfs-progs: Move printing outside of btrfs_list_subvols
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
  2013-01-10 11:41   ` [PATCH 01/11] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
@ 2013-01-10 11:41   ` Anand Jain
  2013-01-10 11:41   ` [PATCH 03/11] Btrfs-progs: add parent uuid for snapshots Anand Jain
                     ` (11 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

its better to have btrfs_list_subvols just return witout printing
so that btrfs_list_subvols can be reused.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c     |   28 ++++++++++++++++++----------
 btrfs-list.h     |    2 +-
 cmds-subvolume.c |    4 ++--
 3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index e5f0f96..b656286 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1441,15 +1441,11 @@ 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 btrfs_list_subvols(int fd, struct root_lookup *root_lookup)
 {
-	struct root_lookup root_lookup;
-	struct root_lookup root_sort;
 	int ret;
 
-	ret = __list_subvol_search(fd, &root_lookup);
+	ret = __list_subvol_search(fd, root_lookup);
 	if (ret) {
 		fprintf(stderr, "ERROR: can't perform the search - %s\n",
 				strerror(errno));
@@ -1460,16 +1456,28 @@ int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
 	 * now we have an rbtree full of root_info objects, but we need to fill
 	 * in their path names within the subvol that is referencing each one.
 	 */
-	ret = __list_subvol_fill_paths(fd, &root_lookup);
-	if (ret < 0)
-		return ret;
+	ret = __list_subvol_fill_paths(fd, root_lookup);
+	return ret;
+}
 
+int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
+		       struct btrfs_list_comparer_set *comp_set,
+		       int is_tab_result)
+{
+	struct root_lookup root_lookup;
+	struct root_lookup root_sort;
+	int ret;
+
+	ret = btrfs_list_subvols(fd, &root_lookup);
+	if (ret)
+		return ret;
 	__filter_and_sort_subvol(&root_lookup, &root_sort, filter_set,
 				 comp_set, fd);
 
 	print_all_volume_info(&root_sort, is_tab_result);
 	__free_all_subvolumn(&root_lookup);
-	return ret;
+
+	return 0;
 }
 
 static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh,
diff --git a/btrfs-list.h b/btrfs-list.h
index cde4b3c..71fe0f3 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -98,7 +98,7 @@ int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
 			      enum btrfs_list_comp_enum comparer,
 			      int is_descending);
 
-int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
+int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
 		       struct btrfs_list_comparer_set *comp_set,
 			int is_tab_result);
 int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index e3cdb1e..c35dff7 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -406,7 +406,7 @@ static int cmd_subvol_list(int argc, char **argv)
 					BTRFS_LIST_FILTER_TOPID_EQUAL,
 					top_id);
 
-	ret = btrfs_list_subvols(fd, filter_set, comparer_set,
+	ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
 				is_tab_result);
 	if (ret)
 		return 19;
@@ -613,7 +613,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_print(fd, filter_set, NULL, 0);
 	if (ret)
 		return 19;
 	return 0;
-- 
1.7.1


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

* [PATCH 03/11] Btrfs-progs: add parent uuid for snapshots
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
  2013-01-10 11:41   ` [PATCH 01/11] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
  2013-01-10 11:41   ` [PATCH 02/11] Btrfs-progs: Move printing outside of btrfs_list_subvols Anand Jain
@ 2013-01-10 11:41   ` Anand Jain
  2013-01-10 11:41   ` [PATCH 04/11] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
                     ` (10 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c     |   32 +++++++++++++++++++++++++++-----
 btrfs-list.h     |    1 +
 cmds-subvolume.c |    6 +++++-
 3 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index b656286..cc065e9 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -80,6 +80,7 @@ struct root_info {
 	time_t otime;
 
 	u8 uuid[BTRFS_UUID_SIZE];
+	u8 puuid[BTRFS_UUID_SIZE];
 
 	/* path from the subvol we live in to this root, including the
 	 * root's name.  This is null until we do the extra lookup ioctl.
@@ -128,6 +129,11 @@ struct {
 		.need_print	= 0,
 	},
 	{
+		.name		= "parent UUID",
+		.column_name	= "Parent UUID",
+		.need_print	= 0,
+	},
+	{
 		.name		= "uuid",
 		.column_name	= "UUID",
 		.need_print	= 0,
@@ -435,7 +441,7 @@ static struct root_info *root_tree_search(struct root_lookup *root_tree,
 static int update_root(struct root_lookup *root_lookup,
 		       u64 root_id, u64 ref_tree, u64 root_offset, u64 flags,
 		       u64 dir_id, char *name, int name_len, u64 ogen, u64 gen,
-		       time_t ot, void *uuid)
+		       time_t ot, void *uuid, void *puuid)
 {
 	struct root_info *ri;
 
@@ -472,6 +478,8 @@ static int update_root(struct root_lookup *root_lookup,
 		ri->otime = ot;
 	if (uuid)
 		memcpy(&ri->uuid, uuid, BTRFS_UUID_SIZE);
+	if (puuid)
+		memcpy(&ri->puuid, puuid, BTRFS_UUID_SIZE);
 
 	return 0;
 }
@@ -489,17 +497,18 @@ static int update_root(struct root_lookup *root_lookup,
  * gen: the current generation of the root
  * ot: the original time(create time) of the root
  * uuid: uuid of the root
+ * puuid: uuid of the root parent if any
  */
 static int add_root(struct root_lookup *root_lookup,
 		    u64 root_id, u64 ref_tree, u64 root_offset, u64 flags,
 		    u64 dir_id, char *name, int name_len, u64 ogen, u64 gen,
-		    time_t ot, void *uuid)
+		    time_t ot, void *uuid, void *puuid)
 {
 	struct root_info *ri;
 	int ret;
 
 	ret = update_root(root_lookup, root_id, ref_tree, root_offset, flags,
-			  dir_id, name, name_len, ogen, gen, ot, uuid);
+			  dir_id, name, name_len, ogen, gen, ot, uuid, puuid);
 	if (!ret)
 		return 0;
 
@@ -540,6 +549,9 @@ static int add_root(struct root_lookup *root_lookup,
 	if (uuid) 
 		memcpy(&ri->uuid, uuid, BTRFS_UUID_SIZE);
 
+	if (puuid)
+		memcpy(&ri->puuid, puuid, BTRFS_UUID_SIZE);
+
 	ret = root_tree_insert(root_lookup, ri);
 	if (ret) {
 		printf("failed to insert tree %llu\n", (unsigned long long)root_id);
@@ -1022,6 +1034,7 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup)
 	int i;
 	time_t t;
 	u8 uuid[BTRFS_UUID_SIZE];
+	u8 puuid[BTRFS_UUID_SIZE];
 
 	root_lookup_init(root_lookup);
 	memset(&args, 0, sizeof(args));
@@ -1075,7 +1088,7 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup)
 
 				add_root(root_lookup, sh->objectid, sh->offset,
 					 0, 0, dir_id, name, name_len, 0, 0, 0,
-					 NULL);
+					 NULL, NULL);
 			} else if (sh->type == BTRFS_ROOT_ITEM_KEY) {
 				ri = (struct btrfs_root_item *)(args.buf + off);
 				gen = btrfs_root_generation(ri);
@@ -1085,15 +1098,17 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup)
 					t = ri->otime.sec;
 					ogen = btrfs_root_otransid(ri);
 					memcpy(uuid, ri->uuid, BTRFS_UUID_SIZE);
+					memcpy(puuid, ri->parent_uuid, BTRFS_UUID_SIZE);
 				} else {
 					t = 0;
 					ogen = 0;
 					memset(uuid, 0, BTRFS_UUID_SIZE);
+					memset(puuid, 0, BTRFS_UUID_SIZE);
 				}
 
 				add_root(root_lookup, sh->objectid, 0,
 					 sh->offset, flags, 0, NULL, 0, ogen,
-					 gen, t, uuid);
+					 gen, t, uuid, puuid);
 			}
 
 			off += sh->len;
@@ -1347,6 +1362,13 @@ static void print_subvolume_column(struct root_info *subv,
 			uuid_unparse(subv->uuid, uuidparse);
 		printf("%s", uuidparse);
 		break;
+	case BTRFS_LIST_PUUID:
+		if (uuid_is_null(subv->puuid))
+			strcpy(uuidparse, "-");
+		else
+			uuid_unparse(subv->puuid, uuidparse);
+		printf("%s", uuidparse);
+		break;
 	case BTRFS_LIST_PATH:
 		BUG_ON(!subv->full_path);
 		printf("%s", subv->full_path);
diff --git a/btrfs-list.h b/btrfs-list.h
index 71fe0f3..855e73d 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -53,6 +53,7 @@ enum btrfs_list_column_enum {
 	BTRFS_LIST_PARENT,
 	BTRFS_LIST_TOP_LEVEL,
 	BTRFS_LIST_OTIME,
+	BTRFS_LIST_PUUID,
 	BTRFS_LIST_UUID,
 	BTRFS_LIST_PATH,
 	BTRFS_LIST_ALL,
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index c35dff7..ee36463 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -280,6 +280,7 @@ static const char * const cmd_subvol_list_usage[] = {
 	"-p           print parent ID",
 	"-a           print all the subvolumes in the filesystem.",
 	"-u           print the uuid of subvolumes (and snapshots)",
+	"-q           print the parent uuid of snapshots",
 	"-t           print the result as a table",
 	"-s           list snapshots only in the filesystem",
 	"-r           list readonly subvolumes (including snapshots)",
@@ -319,7 +320,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);
+				    "apsuqrg:c:t", long_options, NULL);
 		if (c < 0)
 			break;
 
@@ -343,6 +344,9 @@ static int cmd_subvol_list(int argc, char **argv)
 		case 'u':
 			btrfs_list_setup_print_column(BTRFS_LIST_UUID);
 			break;
+		case 'q':
+			btrfs_list_setup_print_column(BTRFS_LIST_PUUID);
+			break;
 		case 'r':
 			flags |= BTRFS_ROOT_SUBVOL_RDONLY;
 			break;
-- 
1.7.1


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

* [PATCH 04/11] Btrfs-progs: move struct root_info to btrfs-list.h
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (2 preceding siblings ...)
  2013-01-10 11:41   ` [PATCH 03/11] Btrfs-progs: add parent uuid for snapshots Anand Jain
@ 2013-01-10 11:41   ` Anand Jain
  2013-01-10 11:41   ` [PATCH 05/11] Btrfs-progs: function to get root_info of a subvol Anand Jain
                     ` (9 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c |   47 -----------------------------------------------
 btrfs-list.h |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index cc065e9..1851f3e 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -46,53 +46,6 @@ struct root_lookup {
 	struct rb_root root;
 };
 
-/*
- * one of these for each root we find.
- */
-struct root_info {
-	struct rb_node rb_node;
-	struct rb_node sort_node;
-
-	/* this root's id */
-	u64 root_id;
-
-	/* equal the offset of the root's key */
-	u64 root_offset;
-
-	/* flags of the root */
-	u64 flags;
-
-	/* the id of the root that references this one */
-	u64 ref_tree;
-
-	/* the dir id we're in from ref_tree */
-	u64 dir_id;
-
-	u64 top_id;
-
-	/* generation when the root is created or last updated */
-	u64 gen;
-
-	/* creation generation of this root in sec*/
-	u64 ogen;
-
-	/* creation time of this root in sec*/
-	time_t otime;
-
-	u8 uuid[BTRFS_UUID_SIZE];
-	u8 puuid[BTRFS_UUID_SIZE];
-
-	/* path from the subvol we live in to this root, including the
-	 * root's name.  This is null until we do the extra lookup ioctl.
-	 */
-	char *path;
-
-	/* the name of this root in the directory it lives in */
-	char *name;
-
-	char *full_path;
-};
-
 struct {
 	char	*name;
 	char	*column_name;
diff --git a/btrfs-list.h b/btrfs-list.h
index 855e73d..3b7b680 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -18,7 +18,52 @@
 
 #include "kerncompat.h"
 
-struct root_info;
+/*
+ * one of these for each root we find.
+ */
+struct root_info {
+	struct rb_node rb_node;
+	struct rb_node sort_node;
+
+	/* this root's id */
+	u64 root_id;
+
+	/* equal the offset of the root's key */
+	u64 root_offset;
+
+	/* flags of the root */
+	u64 flags;
+
+	/* the id of the root that references this one */
+	u64 ref_tree;
+
+	/* the dir id we're in from ref_tree */
+	u64 dir_id;
+
+	u64 top_id;
+
+	/* generation when the root is created or last updated */
+	u64 gen;
+
+	/* creation generation of this root in sec*/
+	u64 ogen;
+
+	/* creation time of this root in sec*/
+	time_t otime;
+
+	u8 uuid[BTRFS_UUID_SIZE];
+	u8 puuid[BTRFS_UUID_SIZE];
+
+	/* path from the subvol we live in to this root, including the
+	 * root's name.  This is null until we do the extra lookup ioctl.
+	 */
+	char *path;
+
+	/* the name of this root in the directory it lives in */
+	char *name;
+
+	char *full_path;
+};
 
 typedef int (*btrfs_list_filter_func)(struct root_info *, u64);
 typedef int (*btrfs_list_comp_func)(struct root_info *, struct root_info *,
-- 
1.7.1


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

* [PATCH 05/11] Btrfs-progs: function to get root_info of a subvol
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (3 preceding siblings ...)
  2013-01-10 11:41   ` [PATCH 04/11] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
@ 2013-01-10 11:41   ` Anand Jain
  2013-01-10 11:41   ` [PATCH 06/11] Btrfs-progs: provide method to check if filter is set Anand Jain
                     ` (8 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c |   37 +++++++++++++++++++++++++++++++++++++
 btrfs-list.h |    1 +
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index 1851f3e..cb458f1 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1455,6 +1455,43 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
 	return 0;
 }
 
+int btrfs_get_subvol(int fd, struct root_info *the_ri)
+{
+	int ret = -1;
+	struct root_lookup rl;
+	struct rb_node *rbn;
+	struct root_info *ri;
+	u64 top_id = btrfs_list_get_path_rootid(fd);
+
+	if (btrfs_list_subvols(fd, &rl))
+		return 13;
+
+	rbn = rb_first(&rl.root);
+	while(rbn) {
+		ri = rb_entry(rbn, struct root_info, rb_node);
+		resolve_root(&rl, ri, top_id);
+		if (!comp_entry_with_path(the_ri, ri, 0)) {
+			memcpy(the_ri, ri, offsetof(struct root_info, path));
+			if (ri->path)
+				the_ri->path = strdup(ri->path);
+			else
+				the_ri->path = NULL;
+			if (ri->name)
+				the_ri->name = strdup(ri->name);
+			else
+				the_ri->name = NULL;
+			if (ri->full_path)
+				the_ri->full_path = strdup(ri->full_path);
+			else
+				the_ri->name = NULL;
+			ret = 0;
+		}
+		rbn = rb_next(rbn);
+	}
+	__free_all_subvolumn(&rl);
+	return ret;
+}
+
 static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh,
 			    struct btrfs_file_extent_item *item,
 			    u64 found_gen, u64 *cache_dirid,
diff --git a/btrfs-list.h b/btrfs-list.h
index 3b7b680..580d4d1 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -151,3 +151,4 @@ 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);
 u64 btrfs_list_get_path_rootid(int fd);
+int btrfs_get_subvol(int fd, struct root_info *the_ri);
-- 
1.7.1


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

* [PATCH 06/11] Btrfs-progs: provide method to check if filter is set
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (4 preceding siblings ...)
  2013-01-10 11:41   ` [PATCH 05/11] Btrfs-progs: function to get root_info of a subvol Anand Jain
@ 2013-01-10 11:41   ` Anand Jain
  2013-01-10 11:41   ` [PATCH 07/11] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
                     ` (7 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c |   11 +++++++++++
 btrfs-list.h |    2 ++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index cb458f1..308b54c 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1181,6 +1181,17 @@ void btrfs_list_free_filter_set(struct btrfs_list_filter_set *filter_set)
 	free(filter_set);
 }
 
+int btrfs_list_check_filter_set(struct btrfs_list_filter_set *fset,
+			enum btrfs_list_filter_enum filter)
+{
+	int i;
+	for (i=0; i < fset->nfilters; i++) {
+		if (fset->filters[i].filter_func == all_filter_funcs[filter])
+			return i;
+	}
+	return -1;
+}
+
 int btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
 			    enum btrfs_list_filter_enum filter, u64 data)
 {
diff --git a/btrfs-list.h b/btrfs-list.h
index 580d4d1..f5dbd47 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -152,3 +152,5 @@ int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
 char *btrfs_list_path_for_root(int fd, u64 root);
 u64 btrfs_list_get_path_rootid(int fd);
 int btrfs_get_subvol(int fd, struct root_info *the_ri);
+int btrfs_list_check_filter_set(struct btrfs_list_filter_set *fset,
+			enum btrfs_list_filter_enum filter);
-- 
1.7.1


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

* [PATCH 07/11] Btrfs-progs: add method to filter snapshots by parent uuid
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (5 preceding siblings ...)
  2013-01-10 11:41   ` [PATCH 06/11] Btrfs-progs: provide method to check if filter is set Anand Jain
@ 2013-01-10 11:41   ` Anand Jain
  2013-01-10 11:41   ` [PATCH 08/11] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
                     ` (6 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c |    6 ++++++
 btrfs-list.h |    1 +
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index 308b54c..efce966 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1144,6 +1144,11 @@ static int filter_topid_equal(struct root_info *ri, u64 data)
 	return ri->top_id == data;
 }
 
+static int filter_by_parent(struct root_info *ri, u64 data)
+{
+	return !uuid_compare(ri->puuid, (u8 *)data);
+}
+
 static btrfs_list_filter_func all_filter_funcs[] = {
 	[BTRFS_LIST_FILTER_ROOTID]		= filter_by_rootid,
 	[BTRFS_LIST_FILTER_SNAPSHOT_ONLY]	= filter_snapshot,
@@ -1155,6 +1160,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_BY_PARENT]		= filter_by_parent,
 };
 
 struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void)
diff --git a/btrfs-list.h b/btrfs-list.h
index f5dbd47..d71d2b0 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -117,6 +117,7 @@ enum btrfs_list_filter_enum {
 	BTRFS_LIST_FILTER_CGEN_LESS,
 	BTRFS_LIST_FILTER_CGEN_MORE,
 	BTRFS_LIST_FILTER_TOPID_EQUAL,
+	BTRFS_LIST_FILTER_BY_PARENT,
 	BTRFS_LIST_FILTER_MAX,
 };
 
-- 
1.7.1


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

* [PATCH 08/11] Btrfs-progs: put find_mount_root() in commands.h
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (6 preceding siblings ...)
  2013-01-10 11:41   ` [PATCH 07/11] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
@ 2013-01-10 11:41   ` Anand Jain
  2013-01-10 11:41   ` [PATCH 09/11] Btrfs-progs: maintain similar case in heading prefix Anand Jain
                     ` (5 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 commands.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/commands.h b/commands.h
index 8114a73..9b77f3e 100644
--- a/commands.h
+++ b/commands.h
@@ -103,3 +103,6 @@ int cmd_qgroup(int argc, char **argv);
 
 /* subvolume exported functions */
 int test_issubvolume(char *path);
+
+/* send.c */
+int find_mount_root(const char *path, char **mount_root);
-- 
1.7.1


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

* [PATCH 09/11] Btrfs-progs: maintain similar case in heading prefix
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (7 preceding siblings ...)
  2013-01-10 11:41   ` [PATCH 08/11] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
@ 2013-01-10 11:41   ` Anand Jain
  2013-01-10 11:41   ` [PATCH 10/11] Btrfs-progs: accommodate different layout for printing subvol list Anand Jain
                     ` (4 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

A trivial fix
before this patch
  btrfs su list -qu /btrfs
  ID 256 gen 35 top level 5 parent UUID - uuid 60e54c4a-8136-3c43-a107-ea42052c6240 path sv1
  ID 257 gen 35 top level 5 parent UUID 60e54c4a-8136-3c43-a107-ea42052c6240 uuid fdefa4a9-5b67-4f4c-8a11-c43acec51d43 path ss1

after this path
  btrfs su list -qu /btrfs
  ID 256 gen 35 top level 5 parent_uuid - uuid 60e54c4a-8136-3c43-a107-ea42052c6240 path sv1
  ID 257 gen 35 top level 5 parent_uuid 60e54c4a-8136-3c43-a107-ea42052c6240 uuid fdefa4a9-5b67-4f4c-8a11-c43acec51d43 path ss1

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index efce966..8581762 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -82,7 +82,7 @@ struct {
 		.need_print	= 0,
 	},
 	{
-		.name		= "parent UUID",
+		.name		= "parent_uuid",
 		.column_name	= "Parent UUID",
 		.need_print	= 0,
 	},
-- 
1.7.1


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

* [PATCH 10/11] Btrfs-progs: accommodate different layout for printing subvol list
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (8 preceding siblings ...)
  2013-01-10 11:41   ` [PATCH 09/11] Btrfs-progs: maintain similar case in heading prefix Anand Jain
@ 2013-01-10 11:41   ` Anand Jain
  2013-01-10 11:41   ` [PATCH 11/11] Btrfs-progs: add show to display all known parameters of the given subvol Anand Jain
                     ` (3 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

Currently we have name prefix (default) and table format to print
the output of subvol list. Just these two formats does not cater
to all the needs, for eg. the up coming show sub-command need a
way to display all the known information of the given subvol.
This patch will provide a way to extend the printing to other
formats.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c     |   26 +++++++++++++++-----------
 btrfs-list.h     |    3 +++
 cmds-subvolume.c |   23 ++++++++++++++++++++---
 3 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index 8581762..844788b 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -54,12 +54,12 @@ struct {
 	{
 		.name		= "ID",
 		.column_name	= "ID",
-		.need_print	= 1,
+		.need_print	= 0,
 	},
 	{
 		.name		= "gen",
 		.column_name	= "Gen",
-		.need_print	= 1,
+		.need_print	= 0,
 	},
 	{
 		.name		= "cgen",
@@ -74,7 +74,7 @@ struct {
 	{
 		.name		= "top level",
 		.column_name	= "Top Level",
-		.need_print	= 1,
+		.need_print	= 0,
 	},
 	{
 		.name		= "otime",
@@ -94,7 +94,7 @@ struct {
 	{
 		.name		= "path",
 		.column_name	= "Path",
-		.need_print	= 1,
+		.need_print	= 0,
 	},
 	{
 		.name		= NULL,
@@ -1414,21 +1414,25 @@ static void print_all_volume_info_tab_head()
 }
 
 static void print_all_volume_info(struct root_lookup *sorted_tree,
-				  int is_tab_result)
+				  int layout)
 {
 	struct rb_node *n;
 	struct root_info *entry;
 
-	if (is_tab_result)
+	if (layout == BTRFS_LIST_LAYOUT_TABLE)
 		print_all_volume_info_tab_head();
 
 	n = rb_first(&sorted_tree->root);
 	while (n) {
 		entry = rb_entry(n, struct root_info, sort_node);
-		if (is_tab_result)
-			print_single_volume_info_table(entry);
-		else
+		switch (layout) {
+		case BTRFS_LIST_LAYOUT_DEFAULT:
 			print_single_volume_info_default(entry);
+			break;
+		case BTRFS_LIST_LAYOUT_TABLE:
+			print_single_volume_info_table(entry);
+			break;
+		}
 		n = rb_next(n);
 	}
 }
@@ -1454,7 +1458,7 @@ int btrfs_list_subvols(int fd, struct root_lookup *root_lookup)
 
 int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
 		       struct btrfs_list_comparer_set *comp_set,
-		       int is_tab_result)
+		       int layout)
 {
 	struct root_lookup root_lookup;
 	struct root_lookup root_sort;
@@ -1466,7 +1470,7 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
 	__filter_and_sort_subvol(&root_lookup, &root_sort, filter_set,
 				 comp_set, fd);
 
-	print_all_volume_info(&root_sort, is_tab_result);
+	print_all_volume_info(&root_sort, layout);
 	__free_all_subvolumn(&root_lookup);
 
 	return 0;
diff --git a/btrfs-list.h b/btrfs-list.h
index d71d2b0..5f3febd 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -18,6 +18,9 @@
 
 #include "kerncompat.h"
 
+#define BTRFS_LIST_LAYOUT_DEFAULT	0
+#define BTRFS_LIST_LAYOUT_TABLE		1
+
 /*
  * one of these for each root we find.
  */
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index ee36463..dd677f7 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -410,8 +410,18 @@ static int cmd_subvol_list(int argc, char **argv)
 					BTRFS_LIST_FILTER_TOPID_EQUAL,
 					top_id);
 
-	ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
-				is_tab_result);
+	/* by default we shall print the following columns*/
+	btrfs_list_setup_print_column(BTRFS_LIST_OBJECTID);
+	btrfs_list_setup_print_column(BTRFS_LIST_GENERATION);
+	btrfs_list_setup_print_column(BTRFS_LIST_TOP_LEVEL);
+	btrfs_list_setup_print_column(BTRFS_LIST_PATH);
+
+	if (is_tab_result)
+		ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
+				BTRFS_LIST_LAYOUT_TABLE);
+	else
+		ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
+				BTRFS_LIST_LAYOUT_DEFAULT);
 	if (ret)
 		return 19;
 	return 0;
@@ -617,7 +627,14 @@ 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_print(fd, filter_set, NULL, 0);
+	/* by default we shall print the following columns*/
+	btrfs_list_setup_print_column(BTRFS_LIST_OBJECTID);
+	btrfs_list_setup_print_column(BTRFS_LIST_GENERATION);
+	btrfs_list_setup_print_column(BTRFS_LIST_TOP_LEVEL);
+	btrfs_list_setup_print_column(BTRFS_LIST_PATH);
+
+	ret = btrfs_list_subvols_print(fd, filter_set, NULL,
+		BTRFS_LIST_LAYOUT_DEFAULT);
 	if (ret)
 		return 19;
 	return 0;
-- 
1.7.1


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

* [PATCH 11/11] Btrfs-progs: add show to display all known parameters of the given subvol
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (9 preceding siblings ...)
  2013-01-10 11:41   ` [PATCH 10/11] Btrfs-progs: accommodate different layout for printing subvol list Anand Jain
@ 2013-01-10 11:41   ` Anand Jain
  2013-01-14  4:04   ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (2 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-10 11:41 UTC (permalink / raw)
  To: linux-btrfs

This adds show sub-command to the btrfs subvol, which is to display
all known parameters of the given subvol or snapshot. This command
will also list out snapshots of the given subvol if there is any.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 btrfs-list.c     |   25 ++++++++-
 btrfs-list.h     |    3 +-
 cmds-subvolume.c |  148 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 man/btrfs.8.in   |    6 ++
 4 files changed, 175 insertions(+), 7 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index 844788b..309f99a 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1348,6 +1348,22 @@ static void print_subvolume_column(struct root_info *subv,
 	}
 }
 
+static void print_single_volume_info_raw(struct root_info *subv, char *raw_prefix)
+{
+	int i;
+
+	for (i = 0; i < BTRFS_LIST_ALL; i++) {
+		if (!btrfs_list_columns[i].need_print)
+			continue;
+
+		if(raw_prefix);
+			printf("%s",raw_prefix);
+
+		print_subvolume_column(subv, i);
+	}
+	printf("\n");
+}
+
 static void print_single_volume_info_table(struct root_info *subv)
 {
 	int i;
@@ -1414,7 +1430,7 @@ static void print_all_volume_info_tab_head()
 }
 
 static void print_all_volume_info(struct root_lookup *sorted_tree,
-				  int layout)
+				  int layout, char *raw_prefix)
 {
 	struct rb_node *n;
 	struct root_info *entry;
@@ -1432,6 +1448,9 @@ static void print_all_volume_info(struct root_lookup *sorted_tree,
 		case BTRFS_LIST_LAYOUT_TABLE:
 			print_single_volume_info_table(entry);
 			break;
+		case BTRFS_LIST_LAYOUT_RAW:
+			print_single_volume_info_raw(entry, raw_prefix);
+			break;
 		}
 		n = rb_next(n);
 	}
@@ -1458,7 +1477,7 @@ int btrfs_list_subvols(int fd, struct root_lookup *root_lookup)
 
 int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
 		       struct btrfs_list_comparer_set *comp_set,
-		       int layout)
+		       int layout, char *raw_prefix)
 {
 	struct root_lookup root_lookup;
 	struct root_lookup root_sort;
@@ -1470,7 +1489,7 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
 	__filter_and_sort_subvol(&root_lookup, &root_sort, filter_set,
 				 comp_set, fd);
 
-	print_all_volume_info(&root_sort, layout);
+	print_all_volume_info(&root_sort, layout, raw_prefix);
 	__free_all_subvolumn(&root_lookup);
 
 	return 0;
diff --git a/btrfs-list.h b/btrfs-list.h
index 5f3febd..fee7c5b 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -20,6 +20,7 @@
 
 #define BTRFS_LIST_LAYOUT_DEFAULT	0
 #define BTRFS_LIST_LAYOUT_TABLE		1
+#define BTRFS_LIST_LAYOUT_RAW		2
 
 /*
  * one of these for each root we find.
@@ -150,7 +151,7 @@ int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
 
 int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
 		       struct btrfs_list_comparer_set *comp_set,
-			int is_tab_result);
+			int layout, char *raw_prefix);
 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);
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index dd677f7..808a7da 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -24,6 +24,7 @@
 #include <libgen.h>
 #include <limits.h>
 #include <getopt.h>
+#include <uuid/uuid.h>
 
 #include "kerncompat.h"
 #include "ioctl.h"
@@ -418,10 +419,10 @@ static int cmd_subvol_list(int argc, char **argv)
 
 	if (is_tab_result)
 		ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
-				BTRFS_LIST_LAYOUT_TABLE);
+				BTRFS_LIST_LAYOUT_TABLE, NULL);
 	else
 		ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
-				BTRFS_LIST_LAYOUT_DEFAULT);
+				BTRFS_LIST_LAYOUT_DEFAULT, NULL);
 	if (ret)
 		return 19;
 	return 0;
@@ -634,7 +635,7 @@ static int cmd_subvol_get_default(int argc, char **argv)
 	btrfs_list_setup_print_column(BTRFS_LIST_PATH);
 
 	ret = btrfs_list_subvols_print(fd, filter_set, NULL,
-		BTRFS_LIST_LAYOUT_DEFAULT);
+		BTRFS_LIST_LAYOUT_DEFAULT, NULL);
 	if (ret)
 		return 19;
 	return 0;
@@ -721,6 +722,146 @@ static int cmd_find_new(int argc, char **argv)
 	return 0;
 }
 
+static const char * const cmd_subvol_show_usage[] = {
+	"btrfs subvolume show <subvol-path>",
+	"Show more information of the subvolume",
+	NULL
+};
+
+static int cmd_subvol_show(int argc, char **argv)
+{
+	int ret, fd;
+	char *subvol, *mnt = NULL;
+	struct root_info get_ri;
+	char tstr[256];
+	char uuidparse[37];
+	struct btrfs_list_filter_set *filter_set;
+	char raw_prefix[] = "\t\t\t\t";
+
+	if (check_argc_exact(argc, 2))
+		usage(cmd_subvol_show_usage);
+
+	subvol = realpath(argv[1],0);
+	if(!subvol) {
+		fprintf(stderr, "ERROR: finding real path for '%s', %s\n",
+			argv[1], strerror(errno));
+		return 12;
+	}
+
+	ret = test_issubvolume(subvol);
+	if (ret < 0) {
+		fprintf(stderr, "ERROR: error accessing '%s'\n", subvol);
+		free(subvol);
+		return 12;
+	}
+	if (!ret) {
+		fprintf(stderr, "ERROR: '%s' is not a subvolume\n", subvol);
+		free(subvol);
+		return 13;
+	}
+
+	ret = find_mount_root(subvol, &mnt);
+	if (ret < 0) {
+		fprintf(stderr, "ERROR: find_mount_root failed on %s: "
+				"%s\n", subvol, strerror(-ret));
+		free(subvol);
+		return 12;
+	}
+	if (!strcmp(subvol, mnt))
+		return 0;
+
+	/* this will point to after the mnt/" */
+	get_ri.full_path = subvol+strlen(mnt)+1;
+
+	if (!strcmp(get_ri.full_path, ""))
+		return 0;
+
+	fd = open_file_or_dir(mnt);
+	if (fd < 0) {
+		fprintf(stderr, "ERROR: can't access '%s'\n", subvol);
+		return 12;
+	}
+
+	if (btrfs_get_subvol(fd, &get_ri)) {
+		fprintf(stderr, "ERROR: can't find '%s'\n",
+			get_ri.full_path);
+		close(fd);
+		return 13;
+	}
+
+	/* print the info */
+	printf("%s/%s", mnt, get_ri.full_path);
+	printf("\n");
+
+	if (uuid_is_null(get_ri.uuid))
+		strcpy(uuidparse, "-");
+	else
+		uuid_unparse(get_ri.uuid, uuidparse);
+	printf("\t");
+	printf("uuid: \t\t\t%s", uuidparse);
+	printf("\n");
+
+        if (uuid_is_null(get_ri.puuid))
+                strcpy(uuidparse, "-");
+        else
+                uuid_unparse(get_ri.puuid, uuidparse);
+	printf("\t");
+	printf("Parent uuid: \t\t%s", uuidparse);
+	printf("\n");
+
+	if (get_ri.otime)
+		strftime(tstr, 256, "%Y-%m-%d %X",
+			 localtime(&get_ri.otime));
+	else
+		strcpy(tstr, "-");
+	printf("\t");
+	printf("Creation time: \t\t%s", tstr);
+	printf("\n");
+
+	printf("\t");
+	printf("Object ID: \t\t%llu", get_ri.root_id);
+	printf("\n");
+
+	printf("\t");
+	printf("Generation (Gen): \t%llu", get_ri.gen);
+	printf("\n");
+
+	printf("\t");
+	printf("Gen at creation: \t%llu", get_ri.ogen);
+	printf("\n");
+
+	printf("\t");
+	printf("Parent: \t\t%llu", get_ri.ref_tree);
+	printf("\n");
+
+	printf("\t");
+	printf("Top Level: \t\t%llu", get_ri.top_id);
+	printf("\n");
+
+	/* print the snapshots of the given subvol if any*/
+	printf("\t");
+	printf("Snapshot(s):\n");
+	filter_set = btrfs_list_alloc_filter_set();
+	btrfs_list_setup_filter(&filter_set, BTRFS_LIST_FILTER_BY_PARENT,
+				get_ri.uuid);
+	btrfs_list_setup_print_column(BTRFS_LIST_PATH);
+	btrfs_list_subvols_print(fd, filter_set, NULL, BTRFS_LIST_LAYOUT_RAW,
+			raw_prefix);
+
+	/* clean up */
+	if (get_ri.path)
+		free(get_ri.path);
+	if (get_ri.name)
+		free(get_ri.name);
+	if (get_ri.full_path)
+		free(get_ri.full_path);
+
+	close(fd);
+	free(mnt);
+	free(subvol);
+	return 0;
+}
+
 const struct cmd_group subvolume_cmd_group = {
 	subvolume_cmd_group_usage, NULL, {
 		{ "create", cmd_subvol_create, cmd_subvol_create_usage, NULL, 0 },
@@ -732,6 +873,7 @@ const struct cmd_group subvolume_cmd_group = {
 		{ "set-default", cmd_subvol_set_default,
 			cmd_subvol_set_default_usage, NULL, 0 },
 		{ "find-new", cmd_find_new, cmd_find_new_usage, NULL, 0 },
+		{ "show", cmd_subvol_show, cmd_subvol_show_usage, NULL, 0 },
 		{ 0, 0, 0, 0, 0 }
 	}
 };
diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 9222580..57c25b0 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -17,6 +17,8 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBsubvolume get-default\fP\fI <path>\fP
 .PP
+\fBbtrfs\fP \fBsubvolume show\fP\fI <path>\fP
+.PP
 \fBbtrfs\fP \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] \
 [-s \fIstart\fR] [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> \
 [<\fIfile\fR>|<\fIdir\fR>...]
@@ -160,6 +162,10 @@ Get the default subvolume of the filesystem \fI<path>\fR. The output format
 is similar to \fBsubvolume list\fR command.
 .TP
 
+\fBsubvolume show\fR\fI <path>\fR
+Show information of a given subvolume in the \fI<path>\fR.
+.TP
+
 \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] [-s \fIstart\fR] \
 [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> [<\fIfile\fR>|<\fIdir\fR>...]
 
-- 
1.7.1


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

* Re: [PATCH 00/11 V3] add show command to the subvol sub command
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (10 preceding siblings ...)
  2013-01-10 11:41   ` [PATCH 11/11] Btrfs-progs: add show to display all known parameters of the given subvol Anand Jain
@ 2013-01-14  4:04   ` Anand Jain
  2013-01-14 18:25     ` Goffredo Baroncelli
  2013-01-21  0:19   ` Gene Czarcinski
  2013-01-23  8:30   ` Anand Jain
  13 siblings, 1 reply; 28+ messages in thread
From: Anand Jain @ 2013-01-14  4:04 UTC (permalink / raw)
  To: linux-btrfs



  Any comments on this new sub-command, please. ?

Thanks, Anand


On 01/10/2013 07:41 PM, Anand Jain wrote:
> This is an attempt to make btrfs cli more end user friendly.
> And adds show subcommand to display all known (as of now)
> information of the given subvol including its snapshot(s).
>
> The below patch:
>   "Btrfs-progs: accommodate different layout for printing subvol list"
> obsoletes the previosuly submitted patch
>   "Btrfs-progs: make provision to print subvol list tree format"
>
> Please provide your review comments. Thanks.
>
> An example output:
>
> First list out all the subvols/snapshots using the list subcommand.
>
> btrfs su list /btrfs
> ID 256 gen 10 top level 5 path sv1
> ID 259 gen 6 top level 5 path sv1/snap
> ID 260 gen 7 top level 5 path snap
> ID 261 gen 8 top level 5 path sv2
> ID 262 gen 9 top level 5 path sv1/snap2
> ID 263 gen 10 top level 5 path sv1/snap3
>
> Then use show subcommand to know all known information about the
> given subvol.
>
> btrfs su show /btrfs/sv1
> /btrfs/sv1
> 	uuid: 			508b12a5-ed2a-3942-af63-830967201070
> 	Parent uuid: 		-
> 	Creation time: 		2013-01-07 13:53:30
> 	Object ID: 		256
> 	Generation (Gen): 	10
> 	Gen at creation: 	5
> 	Parent: 		5
> 	Top Level: 		5
> 	Snapshot(s):
> 				sv1/snap
> 				sv1/snap2
> 				sv1/snap3
>
>
> v2->v3: List snapshots of the given subvol if any.
>          Uses a more simple approach to obtain the snapshots.
>
> Anand Jain (11):
>    Btrfs-progs: move open_file_or_dir() to utils.c
>    Btrfs-progs: Move printing outside of btrfs_list_subvols
>    Btrfs-progs: add parent uuid for snapshots
>    Btrfs-progs: move struct root_info to btrfs-list.h
>    Btrfs-progs: function to get root_info of a subvol
>    Btrfs-progs: provide method to check if filter is set
>    Btrfs-progs: add method to filter snapshots by parent uuid
>    Btrfs-progs: put find_mount_root() in commands.h
>    Btrfs-progs: maintain similar case in heading prefix
>    Btrfs-progs: accommodate different layout for printing subvol list
>    Btrfs-progs: add show to display all known parameters of the given
>      subvol
>
>   Makefile         |    4 +-
>   btrfs-list.c     |  200 +++++++++++++++++++++++++++++++++++-------------------
>   btrfs-list.h     |   60 +++++++++++++++-
>   btrfsctl.c       |    7 +-
>   cmds-balance.c   |    1 +
>   cmds-inspect.c   |    1 +
>   cmds-qgroup.c    |    1 +
>   cmds-quota.c     |    1 +
>   cmds-subvolume.c |  172 +++++++++++++++++++++++++++++++++++++++++++++-
>   commands.h       |    6 +-
>   common.c         |   46 ------------
>   man/btrfs.8.in   |    6 ++
>   utils.c          |   30 ++++++++-
>   utils.h          |    3 +
>   14 files changed, 405 insertions(+), 133 deletions(-)
>   delete mode 100644 common.c
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

* Re: [PATCH 00/11 V3] add show command to the subvol sub command
  2013-01-14  4:04   ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
@ 2013-01-14 18:25     ` Goffredo Baroncelli
  2013-01-15  8:05       ` Anand Jain
  0 siblings, 1 reply; 28+ messages in thread
From: Goffredo Baroncelli @ 2013-01-14 18:25 UTC (permalink / raw)
  To: Anand Jain, linux-btrfs

On 01/14/2013 05:04 AM, Anand Jain wrote:
> 
> 
> Any comments on this new sub-command, please. ?
> 
> Thanks, Anand
> 
I am trying to use this new command. Very nice. However I tried to use
it against the root of filesystem, without success:

The root of filesystem is under /var/btrfs; I used a subvolume as root:

$ cat /proc/self/mountinfo  | grep sdc3
19 1 0:15 /__active / rw,noatime,nodiratime - btrfs /dev/sdc3 rw,space_cache
25 19 0:15 / /var/btrfs rw,noatime,nodiratime - btrfs /dev/sdc3
rw,space_cache


If I do:

$ #test 1
$ sudo ./btrfs su show /

I got nothing

If I do

$ #test 2
$ sudo ./btrfs su show /var/btrfs/

still, I got nothing

$ #test 3
$  sudo ./btrfs su show /var/btrfs/__active

I, finally, got:

/var/btrfs/__active
	uuid: 			835c96b8-c066-554b-9230-1c531e831ff6
	Parent uuid: 		-
	Creation time: 		-
	Object ID: 		256
	Generation (Gen): 	75774
	Gen at creation: 	0
	Parent: 		5
	Top Level: 		5
	Snapshot(s):


I expected also from test1 and test2 something.

BR
G.Baroncelli





-- 
gpg @keyserver.linux.it: Goffredo Baroncelli (kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5

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

* Re: [PATCH 00/11 V3] add show command to the subvol sub command
  2013-01-14 18:25     ` Goffredo Baroncelli
@ 2013-01-15  8:05       ` Anand Jain
  2013-01-15 18:37         ` Goffredo Baroncelli
  0 siblings, 1 reply; 28+ messages in thread
From: Anand Jain @ 2013-01-15  8:05 UTC (permalink / raw)
  To: kreijack; +Cc: Goffredo Baroncelli, linux-btrfs


Goffredo,

  Thanks for the review.

 > I expected also from test1 and test2 something.

  actually it is working as intended. which is
  to show more info of any item under btrfs su list output,
  and root itself won't be in the btrfs su list (unless
  -a option is used), otherwise any suggestion what
  is good to have for btrfs su show / ?

Anand

On 01/15/2013 02:25 AM, Goffredo Baroncelli wrote:
> On 01/14/2013 05:04 AM, Anand Jain wrote:
>>
>>
>> Any comments on this new sub-command, please. ?
>>
>> Thanks, Anand
>>
> I am trying to use this new command. Very nice. However I tried to use
> it against the root of filesystem, without success:
>
> The root of filesystem is under /var/btrfs; I used a subvolume as root:
>
> $ cat /proc/self/mountinfo  | grep sdc3
> 19 1 0:15 /__active / rw,noatime,nodiratime - btrfs /dev/sdc3 rw,space_cache
> 25 19 0:15 / /var/btrfs rw,noatime,nodiratime - btrfs /dev/sdc3
> rw,space_cache
>
>
> If I do:
>
> $ #test 1
> $ sudo ./btrfs su show /
>
> I got nothing
>
> If I do
>
> $ #test 2
> $ sudo ./btrfs su show /var/btrfs/
>
> still, I got nothing
>
> $ #test 3
> $  sudo ./btrfs su show /var/btrfs/__active
>
> I, finally, got:
>
> /var/btrfs/__active
> 	uuid: 			835c96b8-c066-554b-9230-1c531e831ff6
> 	Parent uuid: 		-
> 	Creation time: 		-
> 	Object ID: 		256
> 	Generation (Gen): 	75774
> 	Gen at creation: 	0
> 	Parent: 		5
> 	Top Level: 		5
> 	Snapshot(s):
>
>
> I expected also from test1 and test2 something.
>
> BR
> G.Baroncelli
>
>
>
>
>

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

* Re: [PATCH 00/11 V3] add show command to the subvol sub command
  2013-01-15  8:05       ` Anand Jain
@ 2013-01-15 18:37         ` Goffredo Baroncelli
  0 siblings, 0 replies; 28+ messages in thread
From: Goffredo Baroncelli @ 2013-01-15 18:37 UTC (permalink / raw)
  To: Anand Jain; +Cc: kreijack, Goffredo Baroncelli, linux-btrfs

Hi Anand
On 01/15/2013 09:05 AM, Anand Jain wrote:
> 
> Goffredo,
> 
>  Thanks for the review.
> 
>> I expected also from test1 and test2 something.
> 
>  actually it is working as intended. which is
>  to show more info of any item under btrfs su list output,
>  and root itself won't be in the btrfs su list (unless
>  -a option is used), otherwise any suggestion what
>  is good to have for btrfs su show / ?

If I understood correctly, btrfs su show is capable to lists the
subvolume snapshots. It could be useful to list the snapshot of the root
subvolume.



> 
> Anand
> 
> On 01/15/2013 02:25 AM, Goffredo Baroncelli wrote:
>> On 01/14/2013 05:04 AM, Anand Jain wrote:
>>>
>>>
>>> Any comments on this new sub-command, please. ?
>>>
>>> Thanks, Anand
>>>
>> I am trying to use this new command. Very nice. However I tried to use
>> it against the root of filesystem, without success:
>>
>> The root of filesystem is under /var/btrfs; I used a subvolume as root:
>>
>> $ cat /proc/self/mountinfo  | grep sdc3
>> 19 1 0:15 /__active / rw,noatime,nodiratime - btrfs /dev/sdc3
>> rw,space_cache
>> 25 19 0:15 / /var/btrfs rw,noatime,nodiratime - btrfs /dev/sdc3
>> rw,space_cache
>>
>>
>> If I do:
>>
>> $ #test 1
>> $ sudo ./btrfs su show /
>>
>> I got nothing
>>
>> If I do
>>
>> $ #test 2
>> $ sudo ./btrfs su show /var/btrfs/
>>
>> still, I got nothing
>>
>> $ #test 3
>> $  sudo ./btrfs su show /var/btrfs/__active
>>
>> I, finally, got:
>>
>> /var/btrfs/__active
>>     uuid:             835c96b8-c066-554b-9230-1c531e831ff6
>>     Parent uuid:         -
>>     Creation time:         -
>>     Object ID:         256
>>     Generation (Gen):     75774
>>     Gen at creation:     0
>>     Parent:         5
>>     Top Level:         5
>>     Snapshot(s):
>>
>>
>> I expected also from test1 and test2 something.
>>
>> BR
>> G.Baroncelli
>>
>>
>>
>>
>>
> 


-- 
gpg @keyserver.linux.it: Goffredo Baroncelli (kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5

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

* Re: [PATCH 00/11 V3] add show command to the subvol sub command
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (11 preceding siblings ...)
  2013-01-14  4:04   ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
@ 2013-01-21  0:19   ` Gene Czarcinski
  2013-01-21 10:35     ` Anand Jain
  2013-01-23  8:30   ` Anand Jain
  13 siblings, 1 reply; 28+ messages in thread
From: Gene Czarcinski @ 2013-01-21  0:19 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Anand Jain

On 01/10/2013 06:41 AM, Anand Jain wrote:
> This is an attempt to make btrfs cli more end user friendly.
> And adds show subcommand to display all known (as of now)
> information of the given subvol including its snapshot(s).
>
> The below patch:
>   "Btrfs-progs: accommodate different layout for printing subvol list"
> obsoletes the previosuly submitted patch
>   "Btrfs-progs: make provision to print subvol list tree format"
>
> Please provide your review comments. Thanks.
>
> An example output:
>
> First list out all the subvols/snapshots using the list subcommand.
>
> btrfs su list /btrfs
> ID 256 gen 10 top level 5 path sv1
> ID 259 gen 6 top level 5 path sv1/snap
> ID 260 gen 7 top level 5 path snap
> ID 261 gen 8 top level 5 path sv2
> ID 262 gen 9 top level 5 path sv1/snap2
> ID 263 gen 10 top level 5 path sv1/snap3
>
> Then use show subcommand to know all known information about the
> given subvol.
>
> btrfs su show /btrfs/sv1
> /btrfs/sv1
> 	uuid: 			508b12a5-ed2a-3942-af63-830967201070
> 	Parent uuid: 		-
> 	Creation time: 		2013-01-07 13:53:30
> 	Object ID: 		256
> 	Generation (Gen): 	10
> 	Gen at creation: 	5
> 	Parent: 		5
> 	Top Level: 		5
> 	Snapshot(s):
> 				sv1/snap
> 				sv1/snap2
> 				sv1/snap3
>
>
> v2->v3: List snapshots of the given subvol if any.
>          Uses a more simple approach to obtain the snapshots.
>
>
You have certainly been busy.  However, your patches need to be rebased 
considering some of the patch-sets currently sent to the mailing list.  
If nothing else, I would appreciate it if you could rebase to David 
Sterba's set.  And then there are the two patch-sets I submitted.

BTW, I do not claim anything except for the effort to scrapes these off 
the list to attempt getting btrfs-progs a bit more current with respect 
to bugfixes.  I was going to include "su show" but your latest 
submission is a bit too much for now.

Gene

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

* Re: [PATCH 00/11 V3] add show command to the subvol sub command
  2013-01-21  0:19   ` Gene Czarcinski
@ 2013-01-21 10:35     ` Anand Jain
  0 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-21 10:35 UTC (permalink / raw)
  To: Gene Czarcinski; +Cc: linux-btrfs


Gene,

  I should do that in couple of days. Thanks.

Anand


On 01/21/2013 08:19 AM, Gene Czarcinski wrote:
> On 01/10/2013 06:41 AM, Anand Jain wrote:
>> This is an attempt to make btrfs cli more end user friendly.
>> And adds show subcommand to display all known (as of now)
>> information of the given subvol including its snapshot(s).
>>
>> The below patch:
>>   "Btrfs-progs: accommodate different layout for printing subvol list"
>> obsoletes the previosuly submitted patch
>>   "Btrfs-progs: make provision to print subvol list tree format"
>>
>> Please provide your review comments. Thanks.
>>
>> An example output:
>>
>> First list out all the subvols/snapshots using the list subcommand.
>>
>> btrfs su list /btrfs
>> ID 256 gen 10 top level 5 path sv1
>> ID 259 gen 6 top level 5 path sv1/snap
>> ID 260 gen 7 top level 5 path snap
>> ID 261 gen 8 top level 5 path sv2
>> ID 262 gen 9 top level 5 path sv1/snap2
>> ID 263 gen 10 top level 5 path sv1/snap3
>>
>> Then use show subcommand to know all known information about the
>> given subvol.
>>
>> btrfs su show /btrfs/sv1
>> /btrfs/sv1
>>     uuid:             508b12a5-ed2a-3942-af63-830967201070
>>     Parent uuid:         -
>>     Creation time:         2013-01-07 13:53:30
>>     Object ID:         256
>>     Generation (Gen):     10
>>     Gen at creation:     5
>>     Parent:         5
>>     Top Level:         5
>>     Snapshot(s):
>>                 sv1/snap
>>                 sv1/snap2
>>                 sv1/snap3
>>
>>
>> v2->v3: List snapshots of the given subvol if any.
>>          Uses a more simple approach to obtain the snapshots.
>>
>>
> You have certainly been busy.  However, your patches need to be rebased
> considering some of the patch-sets currently sent to the mailing list.
> If nothing else, I would appreciate it if you could rebase to David
> Sterba's set.  And then there are the two patch-sets I submitted.
>
> BTW, I do not claim anything except for the effort to scrapes these off
> the list to attempt getting btrfs-progs a bit more current with respect
> to bugfixes.  I was going to include "su show" but your latest
> submission is a bit too much for now.
>
> Gene
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 00/11 V3] add show command to the subvol sub command
  2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
                     ` (12 preceding siblings ...)
  2013-01-21  0:19   ` Gene Czarcinski
@ 2013-01-23  8:30   ` Anand Jain
  13 siblings, 0 replies; 28+ messages in thread
From: Anand Jain @ 2013-01-23  8:30 UTC (permalink / raw)
  To: linux-btrfs



  kindly note
  The patch-set in this email-thread is now obsolete,
  since a newer patch-set[1] based on the git repo at
   git://repo.or.cz/btrfs-progs-unstable/devel.git for-chris
  has been submitted which IMO is easy and good for integration.

  [1]
  Subject: [PATCH 00/10] add show sub-command for btrfs subvol cli
  Date: Wed, 23 Jan 2013 16:12:41 +0800

Thanks, Anand


On 01/10/2013 07:41 PM, Anand Jain wrote:
> This is an attempt to make btrfs cli more end user friendly.
> And adds show subcommand to display all known (as of now)
> information of the given subvol including its snapshot(s).
>
> The below patch:
>   "Btrfs-progs: accommodate different layout for printing subvol list"
> obsoletes the previosuly submitted patch
>   "Btrfs-progs: make provision to print subvol list tree format"
>
> Please provide your review comments. Thanks.
>
> An example output:
>
> First list out all the subvols/snapshots using the list subcommand.
>
> btrfs su list /btrfs
> ID 256 gen 10 top level 5 path sv1
> ID 259 gen 6 top level 5 path sv1/snap
> ID 260 gen 7 top level 5 path snap
> ID 261 gen 8 top level 5 path sv2
> ID 262 gen 9 top level 5 path sv1/snap2
> ID 263 gen 10 top level 5 path sv1/snap3
>
> Then use show subcommand to know all known information about the
> given subvol.
>
> btrfs su show /btrfs/sv1
> /btrfs/sv1
> 	uuid: 			508b12a5-ed2a-3942-af63-830967201070
> 	Parent uuid: 		-
> 	Creation time: 		2013-01-07 13:53:30
> 	Object ID: 		256
> 	Generation (Gen): 	10
> 	Gen at creation: 	5
> 	Parent: 		5
> 	Top Level: 		5
> 	Snapshot(s):
> 				sv1/snap
> 				sv1/snap2
> 				sv1/snap3
>
>
> v2->v3: List snapshots of the given subvol if any.
>          Uses a more simple approach to obtain the snapshots.
>
> Anand Jain (11):
>    Btrfs-progs: move open_file_or_dir() to utils.c
>    Btrfs-progs: Move printing outside of btrfs_list_subvols
>    Btrfs-progs: add parent uuid for snapshots
>    Btrfs-progs: move struct root_info to btrfs-list.h
>    Btrfs-progs: function to get root_info of a subvol
>    Btrfs-progs: provide method to check if filter is set
>    Btrfs-progs: add method to filter snapshots by parent uuid
>    Btrfs-progs: put find_mount_root() in commands.h
>    Btrfs-progs: maintain similar case in heading prefix
>    Btrfs-progs: accommodate different layout for printing subvol list
>    Btrfs-progs: add show to display all known parameters of the given
>      subvol
>
>   Makefile         |    4 +-
>   btrfs-list.c     |  200 +++++++++++++++++++++++++++++++++++-------------------
>   btrfs-list.h     |   60 +++++++++++++++-
>   btrfsctl.c       |    7 +-
>   cmds-balance.c   |    1 +
>   cmds-inspect.c   |    1 +
>   cmds-qgroup.c    |    1 +
>   cmds-quota.c     |    1 +
>   cmds-subvolume.c |  172 +++++++++++++++++++++++++++++++++++++++++++++-
>   commands.h       |    6 +-
>   common.c         |   46 ------------
>   man/btrfs.8.in   |    6 ++
>   utils.c          |   30 ++++++++-
>   utils.h          |    3 +
>   14 files changed, 405 insertions(+), 133 deletions(-)
>   delete mode 100644 common.c
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

end of thread, other threads:[~2013-01-23  8:23 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-28  3:12 [PATCH 0/8 v2] add show command to the subvol sub command Anand jain
2012-12-28  3:12 ` [PATCH 1/8] Btrfs-progs: move open_file_or_dir() to utils.c Anand jain
2012-12-28  3:12 ` [PATCH 2/8] Btrfs-progs: Move printing outside of btrfs_list_subvols Anand jain
2012-12-28  3:12 ` [PATCH 3/8] Btrfs-progs: add parent uuid for snapshots Anand jain
2012-12-28  3:12 ` [PATCH 4/8] Btrfs-progs: move struct root_info to btrfs-list.h Anand jain
2012-12-28  3:12 ` [PATCH 5/8] Btrfs-progs: function to get root_info of a subvol Anand jain
2012-12-28  3:13 ` [PATCH 6/8] Btrfs-progs: provide method to check if filter is set Anand jain
2012-12-28  3:13 ` [PATCH 7/8] Btrfs-progs: add method to filter snapshots by parent uuid Anand jain
2012-12-28  3:13 ` [PATCH 8/8] Btrfs-progs: add show command to display detailed information about the subvol Anand jain
2013-01-10 11:41 ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
2013-01-10 11:41   ` [PATCH 01/11] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-10 11:41   ` [PATCH 02/11] Btrfs-progs: Move printing outside of btrfs_list_subvols Anand Jain
2013-01-10 11:41   ` [PATCH 03/11] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-10 11:41   ` [PATCH 04/11] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-10 11:41   ` [PATCH 05/11] Btrfs-progs: function to get root_info of a subvol Anand Jain
2013-01-10 11:41   ` [PATCH 06/11] Btrfs-progs: provide method to check if filter is set Anand Jain
2013-01-10 11:41   ` [PATCH 07/11] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-10 11:41   ` [PATCH 08/11] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-10 11:41   ` [PATCH 09/11] Btrfs-progs: maintain similar case in heading prefix Anand Jain
2013-01-10 11:41   ` [PATCH 10/11] Btrfs-progs: accommodate different layout for printing subvol list Anand Jain
2013-01-10 11:41   ` [PATCH 11/11] Btrfs-progs: add show to display all known parameters of the given subvol Anand Jain
2013-01-14  4:04   ` [PATCH 00/11 V3] add show command to the subvol sub command Anand Jain
2013-01-14 18:25     ` Goffredo Baroncelli
2013-01-15  8:05       ` Anand Jain
2013-01-15 18:37         ` Goffredo Baroncelli
2013-01-21  0:19   ` Gene Czarcinski
2013-01-21 10:35     ` Anand Jain
2013-01-23  8:30   ` Anand Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).