From 4603dcf36b07230277474c6db76d76a128edaa5a Mon Sep 17 00:00:00 2001 From: Jacob Malevich Date: Fri, 14 Nov 2014 11:24:02 -0800 Subject: [PATCH] Option for returning only the uuid of the dev when doing a query-dev Change-Id: Ia055da0516bc7baac836642fa1405b77adfc5139 Signed-off-by: Jacob Malevich --- bcache.c | 14 +++++++++++++- bcache.h | 2 +- bcacheadm.c | 8 +++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bcache.c b/bcache.c index 6ba5fad7..4b9c66c4 100644 --- a/bcache.c +++ b/bcache.c @@ -718,6 +718,12 @@ static void print_encode(char *in) printf("%%%x", *pos); } +static void show_uuid_only(struct cache_sb *sb) { + char uuid[40]; + uuid_unparse(sb->uuid.b, uuid); + printf("%s\n", uuid); +} + static void show_super_common(struct cache_sb *sb, bool force_csum) { char uuid[40]; @@ -864,7 +870,8 @@ void show_super_cache(struct cache_sb *sb, bool force_csum) show_cache_member(sb, sb->nr_this_dev); } -struct cache_sb *query_dev(char *dev, bool force_csum, bool print_sb) +struct cache_sb *query_dev(char *dev, bool force_csum, + bool print_sb, bool uuid_only) { struct cache_sb sb_stack, *sb = &sb_stack; size_t bytes = sizeof(*sb); @@ -890,6 +897,11 @@ struct cache_sb *query_dev(char *dev, bool force_csum, bool print_sb) } } + if(uuid_only) { + show_uuid_only(sb); + return sb; + } + if(print_sb) { if (!SB_IS_BDEV(sb)) show_super_cache(sb, force_csum); diff --git a/bcache.h b/bcache.h index 3a551d1e..e10c73c7 100644 --- a/bcache.h +++ b/bcache.h @@ -57,7 +57,7 @@ long strtoul_or_die(const char *, size_t, const char *); void show_super_backingdev(struct cache_sb *, bool); void show_super_cache(struct cache_sb *, bool); -struct cache_sb *query_dev(char *, bool, bool); +struct cache_sb *query_dev(char *, bool, bool, bool); int list_cachesets(char *, bool); char *parse_array_to_list(char *const *); int register_bcache(); diff --git a/bcacheadm.c b/bcacheadm.c index 76e53941..76ad0c6b 100644 --- a/bcacheadm.c +++ b/bcacheadm.c @@ -77,8 +77,9 @@ char *data_replicas = 0; char *tier = 0; -/* super-show globals */ +/* query-dev globals */ bool force_csum = false; +bool uuid_only = false; /* probe globals */ bool udev = false; @@ -199,6 +200,7 @@ static NihOption bcache_register_options[] = { static NihOption query_devs_options[] = { {'f', "force_csum", N_("force_csum"), NULL, NULL, &force_csum, NULL}, + {'u', "uuid-only", N_("only print out the uuid for the devices, not the whole superblock"), NULL, NULL, &uuid_only, NULL}, NIH_OPTION_LAST }; @@ -363,7 +365,7 @@ int bcache_query_devs (NihCommand *command, char *const *args) for (i = 0; args[i] != NULL; i++) - query_dev(args[i], force_csum, true); + query_dev(args[i], force_csum, true, uuid_only); } int bcache_status (NihCommand *command, char *const *args) @@ -373,7 +375,7 @@ int bcache_status (NihCommand *command, char *const *args) char *dev0 = NULL, *dev1 = NULL; for (i = 0; args[i] != NULL; i++) { - struct cache_sb *sb = query_dev(args[i], false, false); + struct cache_sb *sb = query_dev(args[i], false, false, false); struct cache_member *m = ((struct cache_member *) sb->d) + sb->nr_this_dev; long long unsigned cache_tier = CACHE_TIER(m);