summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--69-bcache.rules1
-rw-r--r--Makefile3
-rwxr-xr-xbcache-register4
-rw-r--r--bcache-register.c37
5 files changed, 41 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index eb69a7c..7a8fe1a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
/bcache-super-show
/bcache-test
+/bcache-register
/make-bcache
/probe-bcache
.*
diff --git a/69-bcache.rules b/69-bcache.rules
index 5d28e70..9cc7f0d 100644
--- a/69-bcache.rules
+++ b/69-bcache.rules
@@ -18,6 +18,7 @@ ENV{ID_FS_TYPE}!="bcache", GOTO="bcache_backing_end"
ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
LABEL="bcache_backing_found"
+RUN{builtin}+="kmod load bcache"
RUN+="bcache-register $tempnode"
LABEL="bcache_backing_end"
diff --git a/Makefile b/Makefile
index 3f8d87b..c824ae3 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ 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 bcache-register
install: make-bcache probe-bcache bcache-super-show
$(INSTALL) -m0755 make-bcache bcache-super-show $(DESTDIR)${PREFIX}/sbin/
@@ -29,3 +29,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
+bcache-register: bcache-register.o
diff --git a/bcache-register b/bcache-register
deleted file mode 100755
index 9b592bc..0000000
--- a/bcache-register
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-/sbin/modprobe -qba bcache
-test -f /sys/fs/bcache/register_quiet && echo "$1" > /sys/fs/bcache/register_quiet
-
diff --git a/bcache-register.c b/bcache-register.c
new file mode 100644
index 0000000..e22d80b
--- /dev/null
+++ b/bcache-register.c
@@ -0,0 +1,37 @@
+/*
+ * Author: Simon Gomizelj <simongmzlj@gmail.com>
+ *
+ * GPLv2
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int main(int argc, char *argv[])
+{
+ int fd;
+
+ if (argc != 2)
+ {
+ fprintf(stderr, "bcache-register takes exactly one argument\n");
+ return 1;
+ }
+
+ fd = open("/sys/fs/bcache/register_quiet", O_WRONLY);
+ if (fd < 0)
+ {
+ perror("Error opening /sys/fs/bcache/register_quiet");
+ fprintf(stderr, "The bcache kernel module must be loaded\n");
+ return 1;
+ }
+
+ if (dprintf(fd, "%s\n", argv[1]) < 0)
+ {
+ fprintf(stderr, "Error registering %s with bcache: %m\n", argv[1]);
+ return 1;
+ }
+
+ return 0;
+}
+