mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-03-10 00:00:04 +03:00
bcacheadm: ioctl refactor
add-devs, rm-devs, and set-failed no longer need the cacheset uuid. The cacheset already comes with the bcache_extent0 chardev. Change-Id: I32572e865361d3c6ce759cf53f19d3f0e4cf04ce Signed-off-by: Jacob Malevich <jam@daterainc.com>
This commit is contained in:
parent
aa3e2d589d
commit
b765c10d0c
15
bcache.c
15
bcache.c
@ -1180,12 +1180,12 @@ err:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *add_devices(char *const *devs, char *uuid)
|
char *add_devices(char *const *devs)
|
||||||
{
|
{
|
||||||
int ret, bcachefd;
|
int ret, bcachefd;
|
||||||
char *err = NULL;
|
char *err = NULL;
|
||||||
|
|
||||||
bcachefd = open("/dev/bcache", O_RDWR);
|
bcachefd = open("/dev/bcache_extent0", O_RDWR);
|
||||||
if (bcachefd < 0) {
|
if (bcachefd < 0) {
|
||||||
err = "Can't open bcache device";
|
err = "Can't open bcache device";
|
||||||
goto err;
|
goto err;
|
||||||
@ -1193,7 +1193,6 @@ char *add_devices(char *const *devs, char *uuid)
|
|||||||
|
|
||||||
struct bch_ioctl_add_disks ia;
|
struct bch_ioctl_add_disks ia;
|
||||||
ia.devs = devs;
|
ia.devs = devs;
|
||||||
ia.uuid = uuid;
|
|
||||||
|
|
||||||
ret = ioctl(bcachefd, BCH_IOCTL_ADD_DISKS, &ia);
|
ret = ioctl(bcachefd, BCH_IOCTL_ADD_DISKS, &ia);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -1213,7 +1212,7 @@ char *remove_device(const char *dev, bool force)
|
|||||||
int ret, bcachefd;
|
int ret, bcachefd;
|
||||||
char *err = NULL;
|
char *err = NULL;
|
||||||
|
|
||||||
bcachefd = open("/dev/bcache", O_RDWR);
|
bcachefd = open("/dev/bcache_extent0", O_RDWR);
|
||||||
if (bcachefd < 0) {
|
if (bcachefd < 0) {
|
||||||
err = "Can't open bcache device";
|
err = "Can't open bcache device";
|
||||||
goto err;
|
goto err;
|
||||||
@ -1236,22 +1235,20 @@ err:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *device_set_failed(const char *dev_uuid, const char *set_uuid) {
|
char *device_set_failed(const char *dev_uuid) {
|
||||||
int ret, bcachefd;
|
int ret, bcachefd;
|
||||||
char *err = NULL;
|
char *err = NULL;
|
||||||
uuid_le dev, set;
|
uuid_le dev;
|
||||||
struct bch_ioctl_disk_failed df;
|
struct bch_ioctl_disk_failed df;
|
||||||
|
|
||||||
bcachefd = open("/dev/bcache", O_RDWR);
|
bcachefd = open("/dev/bcache_extent0", O_RDWR);
|
||||||
if (bcachefd < 0) {
|
if (bcachefd < 0) {
|
||||||
err = "Can't open bcache device";
|
err = "Can't open bcache device";
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid_parse(dev_uuid, dev.b);
|
uuid_parse(dev_uuid, dev.b);
|
||||||
uuid_parse(set_uuid, set.b);
|
|
||||||
df.dev_uuid = dev;
|
df.dev_uuid = dev;
|
||||||
df.set_uuid = set;
|
|
||||||
|
|
||||||
ret = ioctl(bcachefd, BCH_IOCTL_SET_DISK_FAILED, &df);
|
ret = ioctl(bcachefd, BCH_IOCTL_SET_DISK_FAILED, &df);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
4
bcache.h
4
bcache.h
@ -106,11 +106,11 @@ char *unregister_bcache(char *const *);
|
|||||||
char *probe(char *, int);
|
char *probe(char *, int);
|
||||||
char *read_stat_dir(DIR *, char *, char *, char *);
|
char *read_stat_dir(DIR *, char *, char *, char *);
|
||||||
char *find_matching_uuid(char *, char *, const char*);
|
char *find_matching_uuid(char *, char *, const char*);
|
||||||
char *add_devices(char *const *, char *);
|
char *add_devices(char *const *);
|
||||||
char *remove_device(const char *, bool);
|
char *remove_device(const char *, bool);
|
||||||
char *bcache_get_capacity(const char *, const char *, bool);
|
char *bcache_get_capacity(const char *, const char *, bool);
|
||||||
char *dev_name(const char *);
|
char *dev_name(const char *);
|
||||||
char *device_set_failed(const char *dev_uuid, const char *set_uuid);
|
char *device_set_failed(const char *dev_uuid);
|
||||||
|
|
||||||
#define csum_set(i, type) \
|
#define csum_set(i, type) \
|
||||||
({ \
|
({ \
|
||||||
|
24
bcacheadm.c
24
bcacheadm.c
@ -58,9 +58,6 @@ char *metadata_replicas = 0;
|
|||||||
char *data_replicas = 0;
|
char *data_replicas = 0;
|
||||||
char *tier = 0;
|
char *tier = 0;
|
||||||
|
|
||||||
/* add-dev globals */
|
|
||||||
char *add_dev_uuid = NULL;
|
|
||||||
|
|
||||||
/* rm-dev globals */
|
/* rm-dev globals */
|
||||||
bool force_remove = false;
|
bool force_remove = false;
|
||||||
|
|
||||||
@ -100,7 +97,6 @@ bool stats_day = false;
|
|||||||
bool stats_total = false;
|
bool stats_total = false;
|
||||||
|
|
||||||
/* set_failed globals */
|
/* set_failed globals */
|
||||||
static const char *failed_uuid = NULL;
|
|
||||||
static const char *dev_failed_uuid = NULL;
|
static const char *dev_failed_uuid = NULL;
|
||||||
|
|
||||||
/* make-bcache option setters */
|
/* make-bcache option setters */
|
||||||
@ -205,7 +201,6 @@ static NihOption bcache_unregister_options[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static NihOption bcache_add_device_options[] = {
|
static NihOption bcache_add_device_options[] = {
|
||||||
{'u', "set", N_("cacheset uuid"), NULL, "UUID", &add_dev_uuid, NULL},
|
|
||||||
NIH_OPTION_LAST
|
NIH_OPTION_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -259,7 +254,6 @@ static NihOption stats_options[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static NihOption set_failed_options[] = {
|
static NihOption set_failed_options[] = {
|
||||||
{'u', "set", N_("cache_set UUID"), NULL, "UUID", &failed_uuid, NULL},
|
|
||||||
{'d', "dev", N_("dev UUID"), NULL, "UUID", &dev_failed_uuid, NULL},
|
{'d', "dev", N_("dev UUID"), NULL, "UUID", &dev_failed_uuid, NULL},
|
||||||
NIH_OPTION_LAST
|
NIH_OPTION_LAST
|
||||||
};
|
};
|
||||||
@ -422,12 +416,7 @@ int bcache_add_devices(NihCommand *command, char *const *args)
|
|||||||
{
|
{
|
||||||
char *err;
|
char *err;
|
||||||
|
|
||||||
if (!add_dev_uuid) {
|
err = add_devices(args);
|
||||||
printf("Must specify a cacheset uuid to add the disk to\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = add_devices(args, add_dev_uuid);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
printf("bcache_add_devices error: %s\n", err);
|
printf("bcache_add_devices error: %s\n", err);
|
||||||
return -1;
|
return -1;
|
||||||
@ -804,17 +793,12 @@ int bcache_set_failed(NihCommand *command, char *const *args)
|
|||||||
int i;
|
int i;
|
||||||
char *err = NULL;
|
char *err = NULL;
|
||||||
|
|
||||||
if (!failed_uuid) {
|
|
||||||
printf("Pass in a cacheset uuid\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dev_failed_uuid) {
|
if (!dev_failed_uuid) {
|
||||||
printf("Pass in a dev uuid\n");
|
printf("Pass in a dev uuid\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = device_set_failed(dev_failed_uuid, failed_uuid);
|
err = device_set_failed(dev_failed_uuid);
|
||||||
if (err) {
|
if (err) {
|
||||||
printf("bcache_set_failed_ioctl error: %s\n", err);
|
printf("bcache_set_failed_ioctl error: %s\n", err);
|
||||||
return -1;
|
return -1;
|
||||||
@ -841,7 +825,7 @@ static NihCommand commands[] = {
|
|||||||
"Unregisters a list of devices",
|
"Unregisters a list of devices",
|
||||||
N_("Unregisters a list of devices"),
|
N_("Unregisters a list of devices"),
|
||||||
NULL, bcache_unregister_options, bcache_unregister},
|
NULL, bcache_unregister_options, bcache_unregister},
|
||||||
{"add-devs", N_("add-devs --set=UUID --tier=# <list of devices>"),
|
{"add-devs", N_("add-devs --tier=# <list of devices>"),
|
||||||
"Adds a list of devices to a cacheset",
|
"Adds a list of devices to a cacheset",
|
||||||
N_("Adds a list of devices to a cacheset"),
|
N_("Adds a list of devices to a cacheset"),
|
||||||
NULL, bcache_add_device_options, bcache_add_devices},
|
NULL, bcache_add_device_options, bcache_add_devices},
|
||||||
@ -873,7 +857,7 @@ static NihCommand commands[] = {
|
|||||||
"List various bcache statistics",
|
"List various bcache statistics",
|
||||||
N_("List various bcache statistics"),
|
N_("List various bcache statistics"),
|
||||||
NULL, stats_options, bcache_stats},
|
NULL, stats_options, bcache_stats},
|
||||||
{"set-failed", N_("set-failed --set=UUID --dev=UUID"),
|
{"set-failed", N_("set-failed --dev=UUID"),
|
||||||
"Sets a device to the FAILED state",
|
"Sets a device to the FAILED state",
|
||||||
N_("Sets a device to the FAILED state"),
|
N_("Sets a device to the FAILED state"),
|
||||||
NULL, set_failed_options, bcache_set_failed},
|
NULL, set_failed_options, bcache_set_failed},
|
||||||
|
Loading…
Reference in New Issue
Block a user