mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-01-23 00:07:07 +03:00
bcacheadm status <list of devs>
provides status for the newest sb version for each tier for all the devs passed in Change-Id: Ib6e5b08e65b5c36e7b1af0e9806efc39d069f94c Signed-off-by: Jacob Malevich <jam@daterainc.com>
This commit is contained in:
parent
bc69c8fe04
commit
637b614630
20
bcache.c
20
bcache.c
@ -851,7 +851,7 @@ void show_super_cache(struct cache_sb *sb, bool force_csum)
|
||||
show_cache_member(sb, sb->nr_this_dev);
|
||||
}
|
||||
|
||||
void query_dev(char *dev, bool force_csum)
|
||||
struct cache_sb *query_dev(char *dev, bool force_csum)
|
||||
{
|
||||
struct cache_sb sb_stack, *sb = &sb_stack;
|
||||
size_t bytes = sizeof(*sb);
|
||||
@ -877,6 +877,11 @@ void query_dev(char *dev, bool force_csum)
|
||||
}
|
||||
}
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
void print_dev_info(struct cache_sb *sb, bool force_csum)
|
||||
{
|
||||
if (!SB_IS_BDEV(sb))
|
||||
show_super_cache(sb, force_csum);
|
||||
else
|
||||
@ -891,6 +896,7 @@ int list_cachesets(char *cset_dir)
|
||||
fprintf(stderr, "Failed to open dir %s\n", cset_dir);
|
||||
return 1;
|
||||
}
|
||||
printf("cachesets:\n");
|
||||
|
||||
while ((ent = readdir(dir)) != NULL) {
|
||||
struct stat statbuf;
|
||||
@ -907,7 +913,7 @@ int list_cachesets(char *cset_dir)
|
||||
return 1;
|
||||
}
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
printf("%s\n", ent->d_name);
|
||||
printf("\t%s\n", ent->d_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -997,4 +1003,14 @@ int probe(char *dev, int udev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sb_state(struct cache_sb *sb, char *dev)
|
||||
{
|
||||
struct cache_member *m = ((struct cache_member *) sb->d) +
|
||||
sb->nr_this_dev;
|
||||
|
||||
printf("device %s\n", dev);
|
||||
printf("\tcache state\t%s\n", cache_state[CACHE_STATE(m)]);
|
||||
printf("\tcache_tier\t%llu\n", CACHE_TIER(m));
|
||||
printf("\tseq#: \t%llu\n", sb->seq);
|
||||
|
||||
}
|
||||
|
11
bcache.h
11
bcache.h
@ -56,12 +56,13 @@ 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);
|
||||
|
||||
void query_dev(char *dev, bool force_csum);
|
||||
int list_cachesets(char *cset_dir);
|
||||
char *parse_array_to_list(char *const *args);
|
||||
struct cache_sb *query_dev(char *, bool);
|
||||
int list_cachesets(char *);
|
||||
char *parse_array_to_list(char *const *);
|
||||
int register_bcache();
|
||||
int probe(char *dev, int udev);
|
||||
|
||||
int probe(char *, int);
|
||||
void print_dev_info(struct cache_sb *, bool);
|
||||
void sb_state(struct cache_sb *, char *);
|
||||
|
||||
|
||||
#define csum_set(i, type) \
|
||||
|
70
bcacheadm.c
70
bcacheadm.c
@ -33,9 +33,7 @@
|
||||
#define PACKAGE_VERSION "1.0"
|
||||
#define PACKAGE_BUGREPORT "bugreport"
|
||||
|
||||
//What is the actual max?
|
||||
#define MAX_DEVS 64
|
||||
|
||||
#define MAX_DEVS MAX_CACHES_PER_SET
|
||||
|
||||
|
||||
/* bcacheadm globals */
|
||||
@ -206,6 +204,10 @@ static NihOption list_cachesets_options[] = {
|
||||
NIH_OPTION_LAST
|
||||
};
|
||||
|
||||
static NihOption status_options[] = {
|
||||
NIH_OPTION_LAST
|
||||
};
|
||||
|
||||
static NihOption options[] = {
|
||||
NIH_OPTION_LAST
|
||||
};
|
||||
@ -310,17 +312,65 @@ int bcache_query_devs (NihCommand *command, char *const *args)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; args[i]!=NULL; i++) {
|
||||
query_dev(args[i], false);
|
||||
for (i = 0; args[i] != NULL; i++) {
|
||||
struct cache_sb *sb = query_dev(args[i], false);
|
||||
print_dev_info(sb, force_csum);
|
||||
}
|
||||
}
|
||||
|
||||
int bcache_status (NihCommand *command, char *const *args)
|
||||
{
|
||||
int i;
|
||||
struct cache_sb *sb_tier0 = NULL, *sb_tier1 = NULL;
|
||||
char *dev0 = NULL, *dev1 = NULL;
|
||||
|
||||
for (i = 0; args[i] != NULL; i++) {
|
||||
struct cache_sb *sb = query_dev(args[i], false);
|
||||
struct cache_member *m = ((struct cache_member *) sb->d) +
|
||||
sb->nr_this_dev;
|
||||
long long unsigned cache_tier = CACHE_TIER(m);
|
||||
|
||||
if (!cache_tier)
|
||||
if (!sb_tier0 || sb->seq > sb_tier0->seq) {
|
||||
sb_tier0 = sb;
|
||||
dev0 = args[i];
|
||||
}
|
||||
else if (cache_tier == 1)
|
||||
if (!sb_tier1 || sb->seq > sb_tier1->seq) {
|
||||
sb_tier1 = sb;
|
||||
dev1 = args[i];
|
||||
}
|
||||
}
|
||||
if (sb_tier0) sb_state(sb_tier0, dev0);
|
||||
if (sb_tier1) sb_state(sb_tier1, dev1);
|
||||
}
|
||||
|
||||
static NihCommand commands[] = {
|
||||
{"format", N_("format <list of drives>"), "Format one or a list of devices with bcache datastructures. You need to do this before you create a volume", N_("format drive[s] with bcache"), NULL, make_bcache_options, make_bcache},
|
||||
{"probe", N_("probe <list of devices>"), "Does a blkid_probe on a device", N_("Does a blkid_probe on a device"), NULL, probe_bcache_options, probe_bcache},
|
||||
{"register", N_("register <list of devices>"), "Registers a list of devices", N_("Registers a list of devices"), NULL, bcache_register_options, bcache_register},
|
||||
{"list-cachesets", N_("list-cachesets"), "Lists cachesets in /sys/fs/bcache", N_("Lists cachesets in /sys/fs/bcache"), NULL, list_cachesets_options, bcache_list_cachesets},
|
||||
{"query-devs", N_("query <list of devices>"), "Gives info about the superblock of a list of devices", N_("show superblock on each of the listed drive"), NULL, query_devs_options, bcache_query_devs},
|
||||
{"format", N_("format <list of drives>"),
|
||||
"Format one or a list of devices with bcache datastructures."
|
||||
" You need to do this before you create a volume",
|
||||
N_("format drive[s] with bcache"),
|
||||
NULL, make_bcache_options, make_bcache},
|
||||
{"probe", N_("probe <list of devices>"),
|
||||
"Does a blkid_probe on a device",
|
||||
N_("Does a blkid_probe on a device"),
|
||||
NULL, probe_bcache_options, probe_bcache},
|
||||
{"register", N_("register <list of devices>"),
|
||||
"Registers a list of devices",
|
||||
N_("Registers a list of devices"),
|
||||
NULL, bcache_register_options, bcache_register},
|
||||
{"list-cachesets", N_("list-cachesets"),
|
||||
"Lists cachesets in /sys/fs/bcache",
|
||||
N_("Lists cachesets in /sys/fs/bcache"),
|
||||
NULL, list_cachesets_options, bcache_list_cachesets},
|
||||
{"query-devs", N_("query <list of devices>"),
|
||||
"Gives info about the superblock of a list of devices",
|
||||
N_("show superblock on each of the listed drive"),
|
||||
NULL, query_devs_options, bcache_query_devs},
|
||||
{"status", N_("status <list of devices>"),
|
||||
"Finds the status of the most up to date superblock",
|
||||
N_("Finds the status of the most up to date superblock"),
|
||||
NULL, status_options, bcache_status},
|
||||
NIH_COMMAND_LAST
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user