mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-02 00:00:03 +03:00
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>
This commit is contained in:
parent
039b45dfe9
commit
73ef76c1c0
7
Makefile
7
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
|
||||
|
@ -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`
|
||||
|
51
bcachectl.c
Normal file
51
bcachectl.c
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user