From patchwork Tue Jan 29 06:48:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 2059481 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 8D4D23FDD1 for ; Tue, 29 Jan 2013 06:42:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753843Ab3A2Gms (ORCPT ); Tue, 29 Jan 2013 01:42:48 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:22414 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753157Ab3A2Gmp (ORCPT ); Tue, 29 Jan 2013 01:42:45 -0500 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r0T6fvXf008562 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 29 Jan 2013 06:41:57 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r0T6fueL027832 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 29 Jan 2013 06:41:56 GMT Received: from abhmt115.oracle.com (abhmt115.oracle.com [141.146.116.67]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r0T6fufF016886; Tue, 29 Jan 2013 00:41:56 -0600 Received: from wish.sg.oracle.com (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 28 Jan 2013 22:41:55 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org, dsterba@suse.cz, gene@czarc.net Subject: [PATCH 03/12] Btrfs-progs: add parent uuid for snapshots Date: Tue, 29 Jan 2013 14:48:52 +0800 Message-Id: <1359442141-25498-4-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.1.164.g2d0029e In-Reply-To: <1359442141-25498-1-git-send-email-anand.jain@oracle.com> References: <1358928771-31960-1-git-send-email-anand.jain@oracle.com> <1359442141-25498-1-git-send-email-anand.jain@oracle.com> X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Signed-off-by: Anand Jain --- btrfs-list.c | 34 ++++++++++++++++++++++++++++------ btrfs-list.h | 1 + cmds-subvolume.c | 6 +++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/btrfs-list.c b/btrfs-list.c index b404e1d..13a365d 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; @@ -537,9 +546,12 @@ static int add_root(struct root_lookup *root_lookup, if (ot) ri->otime = ot; - if (uuid) + 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); @@ -1021,6 +1033,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)); @@ -1073,7 +1086,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); @@ -1083,15 +1096,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; @@ -1345,6 +1360,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..a1e6893 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 the 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;