diff options
author | Simon Gomizelj <simongmzlj@gmail.com> | 2014-06-28 21:31:51 -0400 |
---|---|---|
committer | Gabriel <g2p.code@gmail.com> | 2014-12-04 23:35:29 +0100 |
commit | 399021549984ad27bf4a13ae85e458833fe003d7 (patch) | |
tree | 262627a53dadb84378f20d7844c7d87a364906f6 | |
parent | 25016feee1aab63c4cdc1188bae40e481d6b17c1 (diff) |
Replace bcache-register with c, use builtin kmod
In a pure systemd pre-boot environment, register-bcache can't be shell
code as there is no shell available. Switch to loading the module with
udev's builtin kmod support and introduce a small binary for registering
devices.
Gabriel: Changed errors to be verbose
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | 69-bcache.rules | 1 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rwxr-xr-x | bcache-register | 4 | ||||
-rw-r--r-- | bcache-register.c | 37 |
5 files changed, 41 insertions, 5 deletions
@@ -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" @@ -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; +} + |