summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Malevich <jam@daterainc.com>2015-02-02 17:37:27 -0800
committerJacob Malevich <jam@daterainc.com>2015-02-02 17:37:27 -0800
commit3fa318e8b7103487ae0fe9b74e9629f6391b166b (patch)
treefdb8d53bf5848292140f7c8fb2d22230a89a9c81
parent8c9ab0614193c3c98a961e4e850bef9556affeb3 (diff)
bcacheadm: add "list-cachesets --internal_uuid UUID" option
This shows the superblock set_uuid, given the user_uuid. Signed-off-by: Jacob Malevich <jam@daterainc.com> Issue DAT-1913 Change-Id: If5f81427ac02bceeb609ae119f044de3fb5a0d77
-rw-r--r--bcacheadm.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/bcacheadm.c b/bcacheadm.c
index 0a7585f..d9dba68 100644
--- a/bcacheadm.c
+++ b/bcacheadm.c
@@ -79,6 +79,7 @@ bool udev = false;
/* list globals */
char *cset_dir = "/sys/fs/bcache";
bool list_devs = false;
+static const char *internal_uuid = NULL;
/* status globals */
bool status_all = false;
@@ -248,6 +249,7 @@ static NihOption query_devs_options[] = {
static NihOption list_cachesets_options[] = {
{'d', "dir", N_("directory"), NULL, NULL, &cset_dir, NULL},
{0, "list-devs", N_("list all devices in the cache sets as well"), NULL, NULL, &list_devs, NULL},
+ {0, "internal_uuid", N_("Show the internal UUID for the given cacheset UUID"), NULL, "UUID", &internal_uuid, NULL},
NIH_OPTION_LAST
};
@@ -550,13 +552,34 @@ err:
int bcache_list_cachesets(NihCommand *command, char *const *args)
{
char *err = NULL;
- err = list_cachesets(cset_dir, list_devs);
- if (err) {
- printf("bcache_list_cachesets error :%s\n", err);
- return -1;
+
+ if (internal_uuid) {
+ char uuid_path[MAX_PATH];
+ DIR *uuid_dir;
+ char buf[MAX_PATH];
+
+ snprintf(uuid_path, MAX_PATH, "%s/%s", cset_dir, internal_uuid);
+
+ err = "uuid does not exist";
+ if((uuid_dir = opendir(uuid_path)) == NULL)
+ goto err;
+
+ err = read_stat_dir(uuid_dir, uuid_path, "/internal/internal_uuid", buf);
+ if (err)
+ goto err;
+ printf("%s", buf);
+ return 0;
}
+ err = list_cachesets(cset_dir, list_devs);
+ if (err)
+ goto err;
+
return 0;
+
+err:
+ printf("bcache_list_cachesets error :%s\n", err);
+ return -1;
}
int bcache_query_devs(NihCommand *command, char *const *args)