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 <jam@daterainc.com>
This commit is contained in:
Jacob Malevich 2014-11-14 14:29:05 -08:00
parent 4603dcf36b
commit 34980cc0df

View File

@ -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,6 +954,9 @@ static void list_cacheset_devs(char *cset_dir, char *cset_name) {
if((len = readlink(entry, buf, sizeof(buf) - 1)) != -1) {
buf[len] = '\0';
if(parse_dev_name)
dev_name(buf);
else
printf("\t%s\n", buf);
}
@ -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);
}
}
}