From patchwork Fri Jan 25 09:19:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 2042111 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 22820DF23E for ; Fri, 25 Jan 2013 09:14:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755686Ab3AYJOf (ORCPT ); Fri, 25 Jan 2013 04:14:35 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:27592 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755459Ab3AYJOZ (ORCPT ); Fri, 25 Jan 2013 04:14:25 -0500 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id r0P9DejM026052 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 25 Jan 2013 09:13:41 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 r0P9DeWH020704 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 25 Jan 2013 09:13:40 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 r0P9De4l008122; Fri, 25 Jan 2013 03:13:40 -0600 Received: from wish.sg.oracle.com (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 25 Jan 2013 01:13:39 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org, dsterba@suse.cz, gene@czarc.net Cc: Anand Jain Subject: [PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts Date: Fri, 25 Jan 2013 17:19:31 +0800 Message-Id: <1359105573-20726-9-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.1.164.g2d0029e In-Reply-To: <1359105573-20726-1-git-send-email-anand.jain@oracle.com> References: <1359105573-20726-1-git-send-email-anand.jain@oracle.com> In-Reply-To: <1358928771-31960-1-git-send-email-anand.jain@oracle.com> References: <1358928771-31960-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 Currently you can print subvol in a list or table format. This patch will provide a way to extend this to other formats like the upcoming raw format. Signed-off-by: Anand Jain --- 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 9c84ecb..656de10 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, @@ -1401,21 +1401,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); } } @@ -1441,7 +1445,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; @@ -1453,7 +1457,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 cde7a3f..5b60068 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 a1e6893..bb9629f 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;