mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-12-09 00:00:17 +03:00
reset-counters --counters=
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
40ffcbc496
commit
2bb681dbd1
@ -3,6 +3,7 @@
|
|||||||
#include "cmds.h"
|
#include "cmds.h"
|
||||||
#include "libbcachefs.h"
|
#include "libbcachefs.h"
|
||||||
#include "init/fs.h"
|
#include "init/fs.h"
|
||||||
|
#include "sb/counters.h"
|
||||||
#include "sb/io.h"
|
#include "sb/io.h"
|
||||||
|
|
||||||
static void reset_counters_usage(void)
|
static void reset_counters_usage(void)
|
||||||
@ -11,6 +12,7 @@ static void reset_counters_usage(void)
|
|||||||
"Usage: bcachefs reset-counters device\n"
|
"Usage: bcachefs reset-counters device\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
|
" -c, --counters=<counters> reset specific counters, not all\n"
|
||||||
" -h, --help display this help and exit\n"
|
" -h, --help display this help and exit\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Report bugs to <linux-bcachefs@vger.kernel.org>");
|
"Report bugs to <linux-bcachefs@vger.kernel.org>");
|
||||||
@ -20,13 +22,26 @@ static void reset_counters_usage(void)
|
|||||||
int cmd_reset_counters(int argc, char *argv[])
|
int cmd_reset_counters(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "counters", required_argument, NULL, 'c' },
|
||||||
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
|
DARRAY(enum bch_persistent_counters) to_reset = {};
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, "h", longopts, NULL)) != -1)
|
while ((opt = getopt_long(argc, argv, "h", longopts, NULL)) != -1)
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
case 'c': {
|
||||||
|
char *p;
|
||||||
|
while ((p = strsep(&optarg, ","))) {
|
||||||
|
ssize_t v = match_string(bch2_counter_names, BCH_COUNTER_NR, p);
|
||||||
|
if (v < 0)
|
||||||
|
die("invalid counter %s", p);
|
||||||
|
darray_push(&to_reset, v);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'h':
|
case 'h':
|
||||||
reset_counters_usage();
|
reset_counters_usage();
|
||||||
break;
|
break;
|
||||||
@ -54,10 +69,16 @@ int cmd_reset_counters(int argc, char *argv[])
|
|||||||
if (ret)
|
if (ret)
|
||||||
die("Error opening filesystem: %s", bch2_err_str(ret));
|
die("Error opening filesystem: %s", bch2_err_str(ret));
|
||||||
|
|
||||||
scoped_guard(mutex, &c->sb_lock) {
|
if (!to_reset.nr) {
|
||||||
bch2_sb_field_resize(&c->disk_sb, counters, 0);
|
for (unsigned i = 0; i < BCH_COUNTER_NR; i++)
|
||||||
bch2_write_super(c);
|
percpu_u64_set(&c->counters[i], 0);
|
||||||
|
} else {
|
||||||
|
darray_for_each(to_reset, i)
|
||||||
|
percpu_u64_set(&c->counters[*i], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scoped_guard(mutex, &c->sb_lock)
|
||||||
|
bch2_write_super(c);
|
||||||
bch2_fs_stop(c);
|
bch2_fs_stop(c);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user