Anand Jain
2013-Jan-28 04:10 UTC
[PATCH 00/10 v3] add show sub-command for btrfs subvol cli
Here is the v3 of this patch-set, kindly review and accept.
v2->v3:
. Accepts review comments from Eric.
Anand Jain (10):
Btrfs-progs: move open_file_or_dir() to utils.c
Btrfs-progs: move printing subvol list outside of btrfs_list_subvols
Btrfs-progs: add parent uuid for snapshots
Btrfs-progs: move struct root_info to btrfs-list.h
Btrfs-progs: add function btrfs_get_subvol to get root_info of a
subvol
Btrfs-progs: add method to filter snapshots by parent uuid
Btrfs-progs: put find_mount_root() in commands.h
Btrfs-progs: make printing subvol extensible to newer layouts
Btrfs-progs: make get_subvol_name non cmds-send specific
Btrfs-progs: add show subcommand to subvol cli
Makefile | 4 +-
btrfs-list.c | 192 +++++++++++++++++++++++++++++++++++--------------------
btrfs-list.h | 58 ++++++++++++++++-
btrfsctl.c | 7 +-
cmds-balance.c | 1 +
cmds-inspect.c | 1 +
cmds-qgroup.c | 1 +
cmds-quota.c | 1 +
cmds-send.c | 12 ++--
cmds-subvolume.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++--
commands.h | 7 +-
common.c | 46 -------------
man/btrfs.8.in | 6 ++
utils.c | 30 ++++++++-
utils.h | 5 +-
15 files changed, 408 insertions(+), 142 deletions(-)
delete mode 100644 common.c
--
1.8.1.227.g44fe835
--
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
Anand Jain
2013-Jan-28 04:10 UTC
[PATCH 01/10] Btrfs-progs: move open_file_or_dir() to utils.c
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 | 5 +++--
11 files changed, 42 insertions(+), 58 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 25b83d2..f10bf55 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -23,6 +23,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 938f9a5..78530e1 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__
@@ -1268,3 +1269,28 @@ u64 parse_size(char *s)
return strtoull(s, NULL, 10) * mult;
}
+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 714fd7a..ed43e84 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,
@@ -44,8 +46,7 @@ int btrfs_device_already_in_root(struct btrfs_root *root, int
fd,
char *pretty_sizes(u64 size);
int check_label(char *input);
int get_mountpt(char *dev, char *mntpt, size_t size);
-
int btrfs_scan_block_devices(int run_ioctl);
-
u64 parse_size(char *s);
+int open_file_or_dir(const char *fname);
#endif
--
1.8.1.227.g44fe835
--
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
Anand Jain
2013-Jan-28 04:10 UTC
[PATCH 02/10] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols
To improve the code reuse its better to have btrfs_list_subvols
just return list of subvols witout printing
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 cb42fbc..b404e1d 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1439,15 +1439,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));
@@ -1458,16 +1454,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.8.1.227.g44fe835
--
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
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
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;
--
1.8.1.227.g44fe835
--
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
Anand Jain
2013-Jan-28 04:10 UTC
[PATCH 04/10] Btrfs-progs: move struct root_info to btrfs-list.h
As we would add more ways to list and manage the subvols
and snapshots, its better if we have struct root_info
defined in the header file.
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 13a365d..909d814 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.8.1.227.g44fe835
--
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
Anand Jain
2013-Jan-28 04:10 UTC
[PATCH 05/10] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol
We need a function which can get the root_info of a given
subvol. This is in preparation to add support for the show
sub-cli.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
btrfs-list.c | 38 ++++++++++++++++++++++++++++++++++++++
btrfs-list.h | 1 +
2 files changed, 39 insertions(+)
diff --git a/btrfs-list.c b/btrfs-list.c
index 909d814..0ee13b6 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1453,6 +1453,44 @@ 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 root_id = btrfs_list_get_path_rootid(fd);
+
+ if (btrfs_list_subvols(fd, &rl))
+ return 1;
+
+ rbn = rb_first(&rl.root);
+ while(rbn) {
+ ri = rb_entry(rbn, struct root_info, rb_node);
+ resolve_root(&rl, ri, root_id);
+ if (!comp_entry_with_rootid(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;
+ break;
+ }
+ 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.8.1.227.g44fe835
--
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
Anand Jain
2013-Jan-28 04:10 UTC
[PATCH 06/10] Btrfs-progs: add method to filter snapshots by parent uuid
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
btrfs-list.c | 6 ++++++
btrfs-list.h | 1 +
2 files changed, 7 insertions(+)
diff --git a/btrfs-list.c b/btrfs-list.c
index 0ee13b6..9c84ecb 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1142,6 +1142,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,
@@ -1153,6 +1158,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 580d4d1..cde7a3f 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.8.1.227.g44fe835
--
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
Anand Jain
2013-Jan-28 04:10 UTC
[PATCH 07/10] Btrfs-progs: put find_mount_root() in commands.h
A useful function need to define it in a header file. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- commands.h | 3 +++ 1 file changed, 3 insertions(+) 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.8.1.227.g44fe835 -- 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
Anand Jain
2013-Jan-28 04:10 UTC
[PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts
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 <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 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;
--
1.8.1.227.g44fe835
--
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
Anand Jain
2013-Jan-28 04:10 UTC
[PATCH 09/10] Btrfs-progs: make get_subvol_name non cmds-send specific
get_subvol_name can be used other than the just with in cmds-send.c
so this patch will make it possible with out changing the original
intentions.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
cmds-send.c | 12 ++++++------
commands.h | 1 +
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/cmds-send.c b/cmds-send.c
index ac1d3cf..0416b79 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -333,12 +333,12 @@ out:
return ret;
}
-static const char *get_subvol_name(struct btrfs_send *s, const char *full_path)
+char *get_subvol_name(char *mnt, char *full_path)
{
- int len = strlen(s->root_path);
+ int len = strlen(mnt);
if (!len)
return full_path;
- if (s->root_path[len - 1] != ''/'')
+ if (mnt[len - 1] != ''/'')
len += 1;
return full_path + len;
@@ -452,7 +452,7 @@ int cmd_send_start(int argc, char **argv)
if (ret < 0)
goto out;
- ret = get_root_id(&send, get_subvol_name(&send, subvol),
+ ret = get_root_id(&send, get_subvol_name(send.root_path, subvol),
&root_id);
if (ret < 0) {
fprintf(stderr, "ERROR: could not resolve "
@@ -513,7 +513,7 @@ int cmd_send_start(int argc, char **argv)
if (snapshot_parent != NULL) {
ret = get_root_id(&send,
- get_subvol_name(&send, snapshot_parent),
+ get_subvol_name(send.root_path, snapshot_parent),
&parent_root_id);
if (ret < 0) {
fprintf(stderr, "ERROR: could not resolve root_id "
@@ -572,7 +572,7 @@ int cmd_send_start(int argc, char **argv)
goto out;
}
- ret = get_root_id(&send, get_subvol_name(&send, subvol),
+ ret = get_root_id(&send, get_subvol_name(send.root_path, subvol),
&root_id);
if (ret < 0) {
fprintf(stderr, "ERROR: could not resolve root_id "
diff --git a/commands.h b/commands.h
index 9b77f3e..631fb6b 100644
--- a/commands.h
+++ b/commands.h
@@ -106,3 +106,4 @@ int test_issubvolume(char *path);
/* send.c */
int find_mount_root(const char *path, char **mount_root);
+char *get_subvol_name(char *mnt, char *full_path);
--
1.8.1.227.g44fe835
--
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
Anand Jain
2013-Jan-28 04:10 UTC
[PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli
This adds show sub-command to the btrfs subvol cli
to display detailed inforamtion of the given subvol
or snapshot.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
btrfs-list.c | 25 +++++++--
btrfs-list.h | 3 +-
cmds-subvolume.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
man/btrfs.8.in | 6 +++
4 files changed, 182 insertions(+), 7 deletions(-)
diff --git a/btrfs-list.c b/btrfs-list.c
index 656de10..1915ece 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1335,6 +1335,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;
@@ -1401,7 +1417,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;
@@ -1419,6 +1435,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);
}
@@ -1445,7 +1464,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;
@@ -1457,7 +1476,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 5b60068..09d35f7 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 bb9629f..6a14c4c 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,153 @@ 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)
+{
+ struct root_info get_ri;
+ struct btrfs_list_filter_set *filter_set;
+ char tstr[256];
+ char uuidparse[37];
+ char *fullpath = NULL, *svpath = NULL, *mnt = NULL;
+ char raw_prefix[] = "\t\t\t\t";
+ u64 sv_id, mntid;
+ int fd = -1, mntfd = -1;
+ int ret = -1;
+
+ if (check_argc_exact(argc, 2))
+ usage(cmd_subvol_show_usage);
+
+ fullpath = realpath(argv[1], 0);
+ if (!fullpath) {
+ fprintf(stderr, "ERROR: finding real path for ''%s'',
%s\n",
+ argv[1], strerror(errno));
+ goto out;
+ }
+
+ ret = test_issubvolume(fullpath);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: error accessing ''%s''\n",
fullpath);
+ goto out;
+ }
+ if (!ret) {
+ fprintf(stderr, "ERROR: ''%s'' is not a
subvolume\n", fullpath);
+ ret = -1;
+ goto out;
+ }
+
+ ret = find_mount_root(fullpath, &mnt);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: find_mount_root failed on %s: "
+ "%s\n", fullpath, strerror(-ret));
+ goto out;
+ }
+ ret = -1;
+ svpath = get_subvol_name(mnt, fullpath);
+
+ fd = open_file_or_dir(fullpath);
+ if (fd < 0) {
+ fprintf(stderr, "ERROR: can''t access
''%s''\n", fullpath);
+ goto out;
+ }
+
+ sv_id = btrfs_list_get_path_rootid(fd);
+ if (sv_id < 0) {
+ fprintf(stderr, "ERROR: can''t get rootid for
''%s''\n",
+ fullpath);
+ goto out;
+ }
+
+ mntfd = open_file_or_dir(mnt);
+ if (mntfd < 0) {
+ fprintf(stderr, "ERROR: can''t access
''%s''\n", mnt);
+ goto out;
+ }
+
+ mntid = btrfs_list_get_path_rootid(mntfd);
+ if (mntid < 0) {
+ fprintf(stderr, "ERROR: can''t get rootid for
''%s''\n", mnt);
+ goto out;
+ }
+
+ if (sv_id == BTRFS_FS_TREE_OBJECTID) {
+ printf("%s is btrfs root\n", fullpath);
+ goto out;
+ }
+
+ memset(&get_ri, 0, sizeof(get_ri));
+ get_ri.root_id = sv_id;
+
+ if (btrfs_get_subvol(mntfd, &get_ri)) {
+ fprintf(stderr, "ERROR: can''t find
''%s''\n",
+ svpath);
+ goto out;
+ }
+
+ ret = 0;
+ /* print the info */
+ printf("%s\n", fullpath);
+ printf("\tName: \t\t\t%s\n", get_ri.name);
+
+ if (uuid_is_null(get_ri.uuid))
+ strcpy(uuidparse, "-");
+ else
+ uuid_unparse(get_ri.uuid, uuidparse);
+ printf("\tuuid: \t\t\t%s\n", uuidparse);
+
+ if (uuid_is_null(get_ri.puuid))
+ strcpy(uuidparse, "-");
+ else
+ uuid_unparse(get_ri.puuid, uuidparse);
+ printf("\tParent uuid: \t\t%s\n", uuidparse);
+
+ if (get_ri.otime)
+ strftime(tstr, 256, "%Y-%m-%d %X",
+ localtime(&get_ri.otime));
+ else
+ strcpy(tstr, "-");
+ printf("\tCreation time: \t\t%s\n", tstr);
+
+ printf("\tObject ID: \t\t%llu\n", get_ri.root_id);
+ printf("\tGeneration (Gen): \t%llu\n", get_ri.gen);
+ printf("\tGen at creation: \t%llu\n", get_ri.ogen);
+ printf("\tParent: \t\t%llu\n", get_ri.ref_tree);
+ printf("\tTop Level: \t\t%llu\n", get_ri.top_id);
+
+ /* print the snapshots of the given subvol if any*/
+ printf("\tSnapshot(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);
+
+out:
+ if (mntfd >= 0)
+ close(mntfd);
+ if (fd >= 0)
+ close(fd);
+ if (mnt)
+ free(mnt);
+ if (fullpath)
+ free(fullpath);
+
+ return ret;
+}
+
const struct cmd_group subvolume_cmd_group = {
subvolume_cmd_group_usage, NULL, {
{ "create", cmd_subvol_create, cmd_subvol_create_usage, NULL, 0 },
@@ -732,6 +880,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 d20e332..0008a06 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>...]
@@ -158,6 +160,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.8.1.227.g44fe835
--
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
Anand Jain
2013-Jan-28 05:29 UTC
Re: [PATCH 00/10 v3] add show sub-command for btrfs subvol cli
sorry missed some git cli option and late noticed error in the change-log, Pls. ignore this thread and ref to the email thread with the subject: [RESEND] [PATCH 00/10 v3] add show sub-command for btrfs subvol cli -Anand On 01/28/2013 12:10 PM, Anand Jain wrote:> Here is the v3 of this patch-set, kindly review and accept. > > v2->v3: > . Accepts review comments from Eric. > > Anand Jain (10): > Btrfs-progs: move open_file_or_dir() to utils.c > Btrfs-progs: move printing subvol list outside of btrfs_list_subvols > Btrfs-progs: add parent uuid for snapshots > Btrfs-progs: move struct root_info to btrfs-list.h > Btrfs-progs: add function btrfs_get_subvol to get root_info of a > subvol > Btrfs-progs: add method to filter snapshots by parent uuid > Btrfs-progs: put find_mount_root() in commands.h > Btrfs-progs: make printing subvol extensible to newer layouts > Btrfs-progs: make get_subvol_name non cmds-send specific > Btrfs-progs: add show subcommand to subvol cli > > Makefile | 4 +- > btrfs-list.c | 192 +++++++++++++++++++++++++++++++++++-------------------- > btrfs-list.h | 58 ++++++++++++++++- > btrfsctl.c | 7 +- > cmds-balance.c | 1 + > cmds-inspect.c | 1 + > cmds-qgroup.c | 1 + > cmds-quota.c | 1 + > cmds-send.c | 12 ++-- > cmds-subvolume.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++-- > commands.h | 7 +- > common.c | 46 ------------- > man/btrfs.8.in | 6 ++ > utils.c | 30 ++++++++- > utils.h | 5 +- > 15 files changed, 408 insertions(+), 142 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