Option for returning only the uuid of the dev when doing a

query-dev

Change-Id: Ia055da0516bc7baac836642fa1405b77adfc5139
Signed-off-by: Jacob Malevich <jam@daterainc.com>
This commit is contained in:
Jacob Malevich 2014-11-14 11:24:02 -08:00
parent 28271115d7
commit 4603dcf36b
3 changed files with 19 additions and 5 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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);