| •1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# This program reads the bcache superblock on bcacheX slaves to extract the |
| 4 |
# dev.uuid and dev.label which refer to a specific backing device. |
| 5 |
# |
| 6 |
# It integrates with udev 'import' by writing CACHED_UUID=X and optionally |
| 7 |
# CACHED_LABEL=X for the backing device of the provided bcache device. |
| 8 |
# Ignore caching devices by skipping unless sb.version=1 |
| 9 |
# |
| 10 |
# There is 1 and only 1 backing device (slaves/*) for a bcache device. |
| 11 |
|
| 12 |
TEMPNODE=${1} # /dev/bcacheN |
| 13 |
DEVNAME=${TEMPNODE##*/} # /dev/bcacheN -> bcacheN |
| 14 |
|
| 15 |
for slave in "/sys/class/block/$DEVNAME/slaves"/*; do |
| 16 |
[ -d "$slave" ] || continue |
| 17 |
/usr/sbin/bcache-super-show "/dev/${slave##*/}" | |
| 18 |
awk '$1 == "sb.version" { sbver=$2; } |
| 19 |
$1 == "dev.uuid" { uuid=$2; } |
| 20 |
$1 == "dev.label" && $2 != "(empty)" { label=$2; } |
| 21 |
END { |
| 22 |
if (sbver == 1 && uuid) { |
| 23 |
print("CACHED_UUID=" uuid) |
| 24 |
if (label) print("CACHED_LABEL=" label) |
| 25 |
exit(0) |
| 26 |
} |
| 27 |
exit(1); |
| 28 |
}' |
| 29 |
# awk exits 0 if it found a backing device. |
| 30 |
[ $? -eq 0 ] && exit 0 |
| 31 |
done |