udev: Fit into the standard rule sequence

Move the rule to run a bit later, after
the standard udev rules have called blkid.

Don't run blkid manually, and run probe-bcache
as a fallback which can be patched out in a
package that depends on util-linux 2.24+.

probe-bcache: bail if libblkid finds anything
Preserve our last-resort safety check here
in case earlier rules fail to call blkid.
This commit is contained in:
Gabriel 2013-10-05 21:16:21 +02:00
parent 866e21a35d
commit 0c7a484a5b
4 changed files with 27 additions and 7 deletions

View File

@ -4,13 +4,18 @@
SUBSYSTEM!="block", GOTO="bcache_end" SUBSYSTEM!="block", GOTO="bcache_end"
ACTION=="remove", GOTO="bcache_end" ACTION=="remove", GOTO="bcache_end"
# Backing devices: scan, symlink, register # blkid was run by the standard udev rules
IMPORT{program}="/sbin/blkid -o udev $tempnode" # It recognised bcache (util-linux 2.24+)
# blkid and probe-bcache can disagree, in which case don't register ENV{ID_FS_TYPE}=="bcache", GOTO="bcache_backing_found"
ENV{ID_FS_TYPE}=="?*", ENV{ID_FS_TYPE}!="bcache", GOTO="bcache_backing_end" # It recognised something else; bail
ENV{ID_FS_TYPE}=="?*", GOTO="bcache_backing_end"
# Backing devices: scan, symlink, register
IMPORT{program}="/sbin/probe-bcache -o udev $tempnode" IMPORT{program}="/sbin/probe-bcache -o udev $tempnode"
ENV{ID_FS_TYPE}!="bcache", GOTO="bcache_backing_end"
ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}" ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
LABEL="bcache_backing_found"
SUBSYSTEM=="block", ACTION=="add|change", ENV{ID_FS_TYPE}=="bcache", \ SUBSYSTEM=="block", ACTION=="add|change", ENV{ID_FS_TYPE}=="bcache", \
RUN+="bcache-register $tempnode" RUN+="bcache-register $tempnode"
LABEL="bcache_backing_end" LABEL="bcache_backing_end"

View File

@ -7,7 +7,7 @@ all: make-bcache probe-bcache bcache-super-show
install: make-bcache probe-bcache bcache-super-show 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 $(DESTDIR)${PREFIX}/sbin/
install -m0755 probe-bcache $(DESTDIR)/sbin/ install -m0755 probe-bcache $(DESTDIR)/sbin/
install -m0644 61-bcache.rules $(DESTDIR)/lib/udev/rules.d/ install -m0644 69-bcache.rules $(DESTDIR)/lib/udev/rules.d/
install -m0755 bcache-register $(DESTDIR)/lib/udev/ install -m0755 bcache-register $(DESTDIR)/lib/udev/
-install -T -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache -install -T -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache
install -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/ install -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/
@ -20,7 +20,8 @@ bcache-test: LDLIBS += `pkg-config --libs openssl`
make-bcache: LDLIBS += `pkg-config --libs uuid blkid` make-bcache: LDLIBS += `pkg-config --libs uuid blkid`
make-bcache: CFLAGS += `pkg-config --cflags uuid blkid` make-bcache: CFLAGS += `pkg-config --cflags uuid blkid`
make-bcache: bcache.o make-bcache: bcache.o
probe-bcache: LDLIBS += `pkg-config --libs uuid` probe-bcache: LDLIBS += `pkg-config --libs uuid blkid`
probe-bcache: CFLAGS += `pkg-config --cflags uuid blkid`
bcache-super-show: LDLIBS += `pkg-config --libs uuid` bcache-super-show: LDLIBS += `pkg-config --libs uuid`
bcache-super-show: CFLAGS += -std=gnu99 bcache-super-show: CFLAGS += -std=gnu99
bcache-super-show: bcache.o bcache-super-show: bcache.o

View File

@ -16,7 +16,7 @@ esac
. /usr/share/initramfs-tools/hook-functions . /usr/share/initramfs-tools/hook-functions
cp -pt "${DESTDIR}/lib/udev/rules.d" /lib/udev/rules.d/61-bcache.rules cp -pt "${DESTDIR}/lib/udev/rules.d" /lib/udev/rules.d/69-bcache.rules
copy_exec /lib/udev/bcache-register copy_exec /lib/udev/bcache-register
copy_exec /sbin/probe-bcache copy_exec /sbin/probe-bcache
manual_add_modules bcache manual_add_modules bcache

View File

@ -8,6 +8,7 @@
#define __USE_FILE_OFFSET64 #define __USE_FILE_OFFSET64
#define _XOPEN_SOURCE 500 #define _XOPEN_SOURCE 500
#include <blkid.h>
#include <fcntl.h> #include <fcntl.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <stdbool.h> #include <stdbool.h>
@ -30,6 +31,7 @@ int main(int argc, char **argv)
extern char *optarg; extern char *optarg;
struct cache_sb sb; struct cache_sb sb;
char uuid[40]; char uuid[40];
blkid_probe pr;
while ((o = getopt(argc, argv, "o:")) != EOF) while ((o = getopt(argc, argv, "o:")) != EOF)
switch (o) { switch (o) {
@ -51,6 +53,18 @@ int main(int argc, char **argv)
if (fd == -1) if (fd == -1)
continue; continue;
if (!(pr = blkid_new_probe()))
continue;
if (blkid_probe_set_device(pr, fd, 0, 0))
continue;
/* probe partitions too */
if (blkid_probe_enable_partitions(pr, true))
continue;
/* bail if anything was found
* probe-bcache isn't needed once blkid recognizes bcache */
if (!blkid_do_probe(pr)) {
continue;
}
if (pread(fd, &sb, sizeof(sb), SB_START) != sizeof(sb)) if (pread(fd, &sb, sizeof(sb), SB_START) != sizeof(sb))
continue; continue;