From 34980cc0df9892909f893f029cefee4c7df55ffd Mon Sep 17 00:00:00 2001 From: Jacob Malevich Date: Fri, 14 Nov 2014 14:29:05 -0800 Subject: [PATCH] bcacheadm: dev path parsing Parse out the dev name for list-cachesets --list-devs This gives the dev path that will be needed for query-dev to get the superblock Change-Id: I333cd8a0e593e02d7635111309b8aff14050cc41 Signed-off-by: Jacob Malevich --- bcache.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/bcache.c b/bcache.c index 4b9c66c4..72adccad 100644 --- a/bcache.c +++ b/bcache.c @@ -912,7 +912,24 @@ struct cache_sb *query_dev(char *dev, bool force_csum, return sb; } -static void list_cacheset_devs(char *cset_dir, char *cset_name) { +static void dev_name(char *ugly_path) { + char buf[32]; + int i, end = strlen(ugly_path); + + //Chop off "/bcache", then look for the next '/' from the end + for (i = end - 8; ; i--) + if(ugly_path[i] == '/') + break; + + strcpy(buf, ugly_path + i); + buf[end - i - 7] = 0; + + // Is the dev guaranteed to be in /dev? + // This is needed for finding the superblock with a query-dev + printf("/dev%s\n", buf); +} + +static void list_cacheset_devs(char *cset_dir, char *cset_name, bool parse_dev_name) { int i = 0; DIR *cachedir; struct stat cache_stat; @@ -937,7 +954,10 @@ static void list_cacheset_devs(char *cset_dir, char *cset_name) { if((len = readlink(entry, buf, sizeof(buf) - 1)) != -1) { buf[len] = '\0'; - printf("\t%s\n", buf); + if(parse_dev_name) + dev_name(buf); + else + printf("\t%s\n", buf); } /* remove i from end and append i++ */ @@ -978,7 +998,7 @@ int list_cachesets(char *cset_dir, bool list_devs) printf("%s\n", ent->d_name); if(list_devs) { - list_cacheset_devs(cset_dir, ent->d_name); + list_cacheset_devs(cset_dir, ent->d_name, true); } } }