]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Add bcachectl: to start bcache, add and remove devices.
authorSurbhi Palande <sap@daterainc.com>
Tue, 5 Aug 2014 18:25:20 +0000 (11:25 -0700)
committerSurbhi Palande <sap@rts26.daterainc.com>
Tue, 5 Aug 2014 18:28:47 +0000 (11:28 -0700)
Useful for lifecycle management of bcache devices.

Change-Id: Icdcb559786ab0557dbe7f2a30b5dbeacf7dad665
Signed-off-by: Surbhi Palande <sap@daterainc.com>
Makefile
Makefile.am
bcachectl.c [new file with mode: 0644]

index 4f9f7c542059c484b8514f4db3932377a1109982..e7d94e6edfe3fedf95e6b0dfc6b955d54289153e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,10 +5,10 @@ DRACUTLIBDIR=/lib/dracut
 INSTALL=install
 CFLAGS+=-O2 -Wall -g
 
-all: make-bcache probe-bcache bcache-super-show
+all: make-bcache probe-bcache bcache-super-show bcachectl
 
 install: make-bcache probe-bcache bcache-super-show
-       $(INSTALL) -m0755 make-bcache bcache-super-show $(DESTDIR)${PREFIX}/sbin/
+       $(INSTALL) -m0755 make-bcache bcache-super-show bcachectl $(DESTDIR)${PREFIX}/sbin/
        $(INSTALL) -m0755 probe-bcache bcache-register          $(DESTDIR)$(UDEVLIBDIR)/
        $(INSTALL) -m0644 69-bcache.rules       $(DESTDIR)$(UDEVLIBDIR)/rules.d/
        -$(INSTALL) -T -m0755 initramfs/hook    $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache
@@ -19,7 +19,7 @@ install: make-bcache probe-bcache bcache-super-show
 #      $(INSTALL) -m0755 bcache-test $(DESTDIR)${PREFIX}/sbin/
 
 clean:
-       $(RM) -f make-bcache probe-bcache bcache-super-show bcache-test *.o
+       $(RM) -f make-bcache probe-bcache bcache-super-show bcache-test bcachectl *.o
 
 bcache-test: LDLIBS += `pkg-config --libs openssl`
 make-bcache: LDLIBS += `pkg-config --libs uuid blkid`
@@ -30,3 +30,4 @@ probe-bcache: CFLAGS += `pkg-config --cflags uuid blkid`
 bcache-super-show: LDLIBS += `pkg-config --libs uuid`
 bcache-super-show: CFLAGS += -std=gnu99
 bcache-super-show: bcache.o
+bcachectl: bcachectl.o
index c36267392d2eeba2372d79a320bd08ed4fa0c6a8..fdfe1a530516497d712a415ab83fc0eaac0210c2 100644 (file)
@@ -7,7 +7,8 @@ AM_CFLAGS=-O2 -Wall -g -std=gnu99
 
 bin_PROGRAMS=make-bcache \
             probe-bcache \
-            bcache-super-show
+            bcache-super-show \
+            bcachectl
 
 noinst_PROGRAMS=bcache-test
 
@@ -23,6 +24,8 @@ bcache_super_show_SOURCES=bcache-super-show.c bcache.c
 bcache_super_show_LDFLAGS=`pkg-config --libs uuid`
 bcache_super_show_CFLAGS=$(AM_CFLAGS) `pkg-config --cflags uuid`
 
+bcachectl_SOURCES=bcachectl.c
+
 bcache_test_SOURCE=bcache-test.c
 bcache_test_LDFLAGS=-lm `pkg-config --libs openssl`
 bcache_test_CFLAGS=$(AM_CFLAGS) `pkg-config --cflags openssl`
diff --git a/bcachectl.c b/bcachectl.c
new file mode 100644 (file)
index 0000000..2325cb5
--- /dev/null
@@ -0,0 +1,51 @@
+#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);
+       }
+}
+