mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-10 00:00:04 +03:00
bcacheadm: add query-devs --brief command
bcacheadm query-devs --brief /dev/sdb /dev/sdc /dev/sdd will output table showing only the dev name, dev uuid, server uuid, and cluster uuid for each device Change-Id: I47a375c9a8f9284942befa0151fae32b0b856a53 Signed-off-by: Jacob Malevich <jam@daterainc.com>
This commit is contained in:
parent
1c113a126b
commit
d8e72eb615
15
bcache.c
15
bcache.c
@ -911,12 +911,12 @@ struct cache_sb *query_dev(char *dev, bool force_csum,
|
|||||||
int fd = open(dev, O_RDONLY);
|
int fd = open(dev, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
printf("Can't open dev %s: %s\n", dev, strerror(errno));
|
printf("Can't open dev %s: %s\n", dev, strerror(errno));
|
||||||
exit(2);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pread(fd, sb, bytes, SB_START) != bytes) {
|
if (pread(fd, sb, bytes, SB_START) != bytes) {
|
||||||
fprintf(stderr, "Couldn't read\n");
|
fprintf(stderr, "Couldn't read\n");
|
||||||
exit(2);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sb->keys) {
|
if (sb->keys) {
|
||||||
@ -925,7 +925,7 @@ struct cache_sb *query_dev(char *dev, bool force_csum,
|
|||||||
|
|
||||||
if (pread(fd, sb, bytes, SB_START) != bytes) {
|
if (pread(fd, sb, bytes, SB_START) != bytes) {
|
||||||
fprintf(stderr, "Couldn't read\n");
|
fprintf(stderr, "Couldn't read\n");
|
||||||
exit(2);
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1029,6 +1029,7 @@ char *find_matching_uuid(char *stats_dir, char *subdir, const char *stats_dev_uu
|
|||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
int i, end = strlen(buf);
|
int i, end = strlen(buf);
|
||||||
char tmp[32], devname[32];
|
char tmp[32], devname[32];
|
||||||
|
struct cache_sb *sb;
|
||||||
|
|
||||||
/* Chop off "/bcache", then look for the
|
/* Chop off "/bcache", then look for the
|
||||||
* next '/' from the end
|
* next '/' from the end
|
||||||
@ -1042,10 +1043,14 @@ char *find_matching_uuid(char *stats_dir, char *subdir, const char *stats_dev_uu
|
|||||||
strcpy(devname, "/dev");
|
strcpy(devname, "/dev");
|
||||||
strcat(devname, tmp);
|
strcat(devname, tmp);
|
||||||
|
|
||||||
query_dev(devname, false, false, true, dev_uuid);
|
err = "Unable to open superblock";
|
||||||
|
sb = query_dev(devname, false, false, true, dev_uuid);
|
||||||
|
if(!sb)
|
||||||
|
return err;
|
||||||
|
|
||||||
if(!strcmp(stats_dev_uuid, dev_uuid)) {
|
if(!strcmp(stats_dev_uuid, dev_uuid)) {
|
||||||
strcat(subdir, intbuf);
|
strcat(subdir, intbuf);
|
||||||
return err;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
bcacheadm.c
32
bcacheadm.c
@ -73,6 +73,7 @@ static const char *modify_dev_uuid = NULL;
|
|||||||
/* query-dev globals */
|
/* query-dev globals */
|
||||||
bool force_csum = false;
|
bool force_csum = false;
|
||||||
bool uuid_only = false;
|
bool uuid_only = false;
|
||||||
|
bool query_brief = false;
|
||||||
|
|
||||||
/* probe globals */
|
/* probe globals */
|
||||||
bool udev = false;
|
bool udev = false;
|
||||||
@ -216,6 +217,7 @@ static NihOption bcache_modify_options[] = {
|
|||||||
static NihOption query_devs_options[] = {
|
static NihOption query_devs_options[] = {
|
||||||
{'f', "force_csum", N_("force_csum"), NULL, NULL, &force_csum, NULL},
|
{'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},
|
{'u', "uuid-only", N_("only print out the uuid for the devices, not the whole superblock"), NULL, NULL, &uuid_only, NULL},
|
||||||
|
{'b', "brief", N_("only print out the cluster,server,and disk uuids"), NULL, NULL, &query_brief, NULL},
|
||||||
NIH_OPTION_LAST
|
NIH_OPTION_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -520,11 +522,37 @@ int bcache_query_devs(NihCommand *command, char *const *args)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (query_brief)
|
||||||
|
printf("%-10s%-40s%-40s%-40s\n", "dev name", "disk uuid",
|
||||||
|
"server uuid", "cluster uuid");
|
||||||
|
|
||||||
for (i = 0; args[i] != NULL; i++) {
|
for (i = 0; args[i] != NULL; i++) {
|
||||||
char dev_uuid[40];
|
char dev_uuid[40];
|
||||||
query_dev(args[i], force_csum, true, uuid_only, dev_uuid);
|
struct cache_sb *sb = query_dev(args[i], force_csum,
|
||||||
if(uuid_only)
|
!query_brief, uuid_only, dev_uuid);
|
||||||
|
|
||||||
|
if (!sb) {
|
||||||
|
printf("error opening the superblock for %s\n",
|
||||||
|
args[i]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uuid_only) {
|
||||||
printf("%s\n", dev_uuid);
|
printf("%s\n", dev_uuid);
|
||||||
|
} else if (query_brief) {
|
||||||
|
char set_uuid_str[40], dev_uuid_str[40];
|
||||||
|
char *clus_uuid = (char *)sb->label;
|
||||||
|
|
||||||
|
uuid_unparse(sb->set_uuid.b, set_uuid_str);
|
||||||
|
uuid_unparse(sb->uuid.b, dev_uuid_str);
|
||||||
|
if (!strcmp(clus_uuid, ""))
|
||||||
|
clus_uuid = "None";
|
||||||
|
|
||||||
|
printf("%-10s%-40s%-40s%-40s\n", args[i],
|
||||||
|
dev_uuid_str,
|
||||||
|
set_uuid_str,
|
||||||
|
clus_uuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user