mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-03-10 00:00:04 +03:00
bcacheadm unregister devices
uses unregister ioctl to unregister a cacheset that the device belongs to Change-Id: I01772de3471888c4951f050b3e92f41b58c5d103 Signed-off-by: Jacob Malevich <jam@daterainc.com>
This commit is contained in:
parent
6ad19a812b
commit
7a80b660c2
27
bcache.c
27
bcache.c
@ -1070,15 +1070,21 @@ int list_cachesets(char *cset_dir, bool list_devs)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int register_bcache(char *devs)
|
||||
static int get_bcache_fd()
|
||||
{
|
||||
int ret, bcachefd;
|
||||
|
||||
bcachefd = open("/dev/bcache", O_RDWR);
|
||||
int bcachefd = open("/dev/bcache", O_RDWR);
|
||||
if (bcachefd < 0) {
|
||||
perror("Can't open bcache device\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return bcachefd;
|
||||
}
|
||||
|
||||
int register_bcache(char *const *devs)
|
||||
{
|
||||
int ret, bcachefd;
|
||||
|
||||
bcachefd = get_bcache_fd();
|
||||
|
||||
ret = ioctl(bcachefd, BCH_IOCTL_REGISTER, devs);
|
||||
if (ret < 0) {
|
||||
@ -1086,7 +1092,20 @@ int register_bcache(char *devs)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unregister_bcache(char *const *devs)
|
||||
{
|
||||
int ret, bcachefd;
|
||||
|
||||
bcachefd = get_bcache_fd();
|
||||
|
||||
ret = ioctl(bcachefd, BCH_IOCTL_UNREGISTER, devs);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ioctl unregister error: %s\n", strerror(ret));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int probe(char *dev, int udev)
|
||||
|
5
bcache.h
5
bcache.h
@ -60,11 +60,14 @@ void show_super_cache(struct cache_sb *, bool);
|
||||
struct cache_sb *query_dev(char *, bool, bool, bool, char *dev_uuid);
|
||||
int list_cachesets(char *, bool);
|
||||
char *parse_array_to_list(char *const *);
|
||||
int register_bcache();
|
||||
int register_bcache(char *const *);
|
||||
int unregister_bcache(char *const *);
|
||||
int probe(char *, int);
|
||||
void sb_state(struct cache_sb *, char *);
|
||||
void read_stat_dir(DIR *, char *, char *, bool);
|
||||
void find_matching_uuid(char *, char *, const char*);
|
||||
//int add_device(char *);
|
||||
//int remove_device(char *);
|
||||
|
||||
#define csum_set(i, type) \
|
||||
({ \
|
||||
|
15
bcacheadm.c
15
bcacheadm.c
@ -199,6 +199,10 @@ static NihOption bcache_register_options[] = {
|
||||
NIH_OPTION_LAST
|
||||
};
|
||||
|
||||
static NihOption bcache_unregister_options[] = {
|
||||
NIH_OPTION_LAST
|
||||
};
|
||||
|
||||
static NihOption query_devs_options[] = {
|
||||
{'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},
|
||||
@ -356,6 +360,13 @@ int bcache_register (NihCommand *command, char *const *args)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bcache_unregister (NihCommand *command, char *const *args)
|
||||
{
|
||||
int ret = unregister_bcache(args);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bcache_list_cachesets (NihCommand *command, char *const *args)
|
||||
{
|
||||
return list_cachesets(cset_dir, list_devs);
|
||||
@ -470,6 +481,10 @@ static NihCommand commands[] = {
|
||||
"Registers a list of devices",
|
||||
N_("Registers a list of devices"),
|
||||
NULL, bcache_register_options, bcache_register},
|
||||
{"unregister", N_("unregister <list of devices>"),
|
||||
"Unregisters a list of devices",
|
||||
N_("Unregisters a list of devices"),
|
||||
NULL, bcache_unregister_options, bcache_unregister},
|
||||
{"list-cachesets", N_("list-cachesets"),
|
||||
"Lists cachesets in /sys/fs/bcache",
|
||||
N_("Lists cachesets in /sys/fs/bcache"),
|
||||
|
Loading…
Reference in New Issue
Block a user