linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand jain <Anand.Jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 3/8] Btrfs-progs: add parent uuid for snapshots
Date: Fri, 28 Dec 2012 11:12:57 +0800	[thread overview]
Message-ID: <1356664382-24423-4-git-send-email-Anand.Jain@oracle.com> (raw)
In-Reply-To: <1356664382-24423-1-git-send-email-Anand.Jain@oracle.com>

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


  parent reply	other threads:[~2012-12-28  3:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=1356664382-24423-4-git-send-email-Anand.Jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

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

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