Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bcache-export-cached helper to export CACHED_UUID and CACHED_LABEL #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions 69-bcache.rules
Expand Up @@ -23,10 +23,9 @@ RUN+="bcache-register $tempnode"
LABEL="bcache_backing_end"

# Cached devices: symlink
DRIVER=="bcache", ENV{CACHED_UUID}=="?*", \
SYMLINK+="bcache/by-uuid/$env{CACHED_UUID}"
DRIVER=="bcache", ENV{CACHED_LABEL}=="?*", \
SYMLINK+="bcache/by-label/$env{CACHED_LABEL}"
IMPORT{program}="bcache-export-cached $tempnode"
ENV{CACHED_UUID}=="?*", SYMLINK+="bcache/by-uuid/$env{CACHED_UUID}"
ENV{CACHED_LABEL}=="?*", SYMLINK+="bcache/by-label/$env{CACHED_LABEL}"

LABEL="bcache_end"

2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -9,7 +9,7 @@ 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/
$(INSTALL) -m0755 probe-bcache bcache-register $(DESTDIR)$(UDEVLIBDIR)/
$(INSTALL) -m0755 probe-bcache bcache-register bcache-export-cached $(DESTDIR)$(UDEVLIBDIR)/
$(INSTALL) -m0644 69-bcache.rules $(DESTDIR)$(UDEVLIBDIR)/rules.d/
$(INSTALL) -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/
$(INSTALL) -D -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache
Expand Down
31 changes: 31 additions & 0 deletions bcache-export-cached
@@ -0,0 +1,31 @@
#!/bin/sh
#
# This program reads the bcache superblock on bcacheX slaves to extract the
# dev.uuid and dev.label which refer to a specific backing device.
#
# It integrates with udev 'import' by writing CACHED_UUID=X and optionally
# CACHED_LABEL=X for the backing device of the provided bcache device.
# Ignore caching devices by skipping unless sb.version=1
#
# There is 1 and only 1 backing device (slaves/*) for a bcache device.

TEMPNODE=${1} # /dev/bcacheN
DEVNAME=${TEMPNODE##*/} # /dev/bcacheN -> bcacheN

for slave in "/sys/class/block/$DEVNAME/slaves"/*; do
[ -d "$slave" ] || continue
bcache-super-show "/dev/${slave##*/}" |
awk '$1 == "sb.version" { sbver=$2; }
$1 == "dev.uuid" { uuid=$2; }
$1 == "dev.label" && $2 != "(empty)" { label=$2; }
END {
if (sbver == 1 && uuid) {
print("CACHED_UUID=" uuid)
if (label) print("CACHED_LABEL=" label)
exit(0)
}
exit(1);
}'
# awk exits 0 if it found a backing device.
[ $? -eq 0 ] && exit 0
done
1 change: 1 addition & 0 deletions initcpio/install
@@ -1,6 +1,7 @@
#!/bin/bash
build() {
add_module bcache
add_binary /usr/lib/udev/bcache-export-cached
add_binary /usr/lib/udev/bcache-register
add_binary /usr/lib/udev/probe-bcache
add_file /usr/lib/udev/rules.d/69-bcache.rules
Expand Down
1 change: 1 addition & 0 deletions initramfs/hook
Expand Up @@ -22,6 +22,7 @@ elif [ -e /lib/udev/rules.d/69-bcache.rules ]; then
cp -pt "${DESTDIR}/lib/udev/rules.d" /lib/udev/rules.d/69-bcache.rules
fi

copy_exec /lib/udev/bcache-export-cached
copy_exec /lib/udev/bcache-register
copy_exec /lib/udev/probe-bcache
manual_add_modules bcache