bcachefs-tools/bcachectl.c
Surbhi Palande 73ef76c1c0 Add bcachectl: to start bcache, add and remove devices.
Useful for lifecycle management of bcache devices.

Change-Id: Icdcb559786ab0557dbe7f2a30b5dbeacf7dad665
Signed-off-by: Surbhi Palande <sap@daterainc.com>
2014-08-05 11:28:47 -07:00

52 lines
886 B
C

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#define __KERNEL__
#include <linux/bcache-ioctl.h>
#undef __KERNEL__
int bcachefd;
static int register_devices(int argc, char *argv[])
{
int ret;
ret = ioctl(bcachefd, BCH_IOCTL_REGISTER, argv);
if (ret < 0) {
fprintf(stderr, "ioctl error %d", ret);
exit(EXIT_FAILURE);
}
return 0;
}
int main(int argc, char *argv[])
{
char *ioctl = argv[2];
if (argc < 3) {
fprintf(stderr, "Enter bcache device and an ioctl to issue\n");
exit(EXIT_FAILURE);
}
bcachefd = open(argv[1], O_RDWR);
if (bcachefd < 0) {
perror("Can't open bcache device");
exit(EXIT_FAILURE);
}
argc -= 3;
argv += 3;
if (!strcmp(ioctl, "register_devices"))
return register_devices(argc, argv);
else {
fprintf(stderr, "Unknown ioctl\n");
exit(EXIT_FAILURE);
}
}