From 8327108eeaf3e0491b17d803da164c0827aae622 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 26 Aug 2013 14:46:19 -0700 Subject: [PATCH 01/12] Use register_quiet for udev hook --- bcache-register | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bcache-register b/bcache-register index bf93c7f9..3a9cd995 100755 --- a/bcache-register +++ b/bcache-register @@ -1,4 +1,4 @@ #!/bin/sh modprobe -qba bcache -test -f /sys/fs/bcache/register && echo "$1" > /sys/fs/bcache/register +test -f /sys/fs/bcache/register_quiet && echo "$1" > /sys/fs/bcache/register_quiet From b15fb776c99fcab56fbbe295629749d307e2018d Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sat, 17 Aug 2013 18:56:50 +0200 Subject: [PATCH 02/12] make-bcache: Prevent stray superblocks Fail if the device has any leftover superblock or partition table label. Add a --wipe-bcache flag to overwrite bcache superblocks and recommend wipefs for non-bcache superblocks. Once the device is safe to write, always zero immediately before the bcache superblock. Make sure errors go to stderr. Use pkg-config. --- Makefile | 9 ++++--- make-bcache.c | 71 +++++++++++++++++++++++++++++++++++++------------- probe-bcache.c | 2 +- 3 files changed, 59 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 10ec79c6..edb4133a 100644 --- a/Makefile +++ b/Makefile @@ -16,9 +16,10 @@ install: make-bcache probe-bcache bcache-super-show clean: $(RM) -f make-bcache probe-bcache bcache-super-show bcache-test *.o -bcache-test: LDLIBS += -lm -lssl -lcrypto -make-bcache: LDLIBS += -luuid +bcache-test: LDLIBS += `pkg-config --libs openssl` +make-bcache: LDLIBS += `pkg-config --libs uuid blkid` +make-bcache: CFLAGS += `pkg-config --cflags uuid blkid` make-bcache: bcache.o -probe-bcache: LDLIBS += -luuid -bcache-super-show: LDLIBS += -luuid +probe-bcache: LDLIBS += `pkg-config --libs uuid` +bcache-super-show: LDLIBS += `pkg-config --libs uuid` bcache-super-show: bcache.o diff --git a/make-bcache.c b/make-bcache.c index 9c038a89..27d49eb9 100644 --- a/make-bcache.c +++ b/make-bcache.c @@ -8,6 +8,7 @@ #define __USE_FILE_OFFSET64 #define _XOPEN_SOURCE 600 +#include #include #include #include @@ -76,19 +77,19 @@ unsigned hatoi_validate(const char *s, const char *msg) uint64_t v = hatoi(s); if (v & (v - 1)) { - printf("%s must be a power of two\n", msg); + fprintf(stderr, "%s must be a power of two\n", msg); exit(EXIT_FAILURE); } v /= 512; if (v > USHRT_MAX) { - printf("%s too large\n", msg); + fprintf(stderr, "%s too large\n", msg); exit(EXIT_FAILURE); } if (!v) { - printf("%s too small\n", msg); + fprintf(stderr, "%s too small\n", msg); exit(EXIT_FAILURE); } @@ -143,7 +144,8 @@ ssize_t read_string_list(const char *buf, const char * const list[]) void usage() { - printf("Usage: make-bcache [options] device\n" + fprintf(stderr, + "Usage: make-bcache [options] device\n" " -C, --cache Format a cache device\n" " -B, --bdev Format a backing device\n" " -b, --bucket bucket size\n" @@ -166,17 +168,41 @@ const char * const cache_replacement_policies[] = { }; static void write_sb(char *dev, unsigned block_size, unsigned bucket_size, - bool writeback, bool discard, + bool writeback, bool discard, bool wipe_bcache, unsigned cache_replacement_policy, uint64_t data_offset, uuid_t set_uuid, bool bdev) { int fd; - char uuid_str[40], set_uuid_str[40]; + char uuid_str[40], set_uuid_str[40], zeroes[SB_START] = {0}; struct cache_sb sb; + blkid_probe pr; if ((fd = open(dev, O_RDWR|O_EXCL)) == -1) { - printf("Can't open dev %s: %s\n", dev, strerror(errno)); + fprintf(stderr, "Can't open dev %s: %s\n", dev, strerror(errno)); + exit(EXIT_FAILURE); + } + + if (pread(fd, &sb, sizeof(sb), SB_START) != sizeof(sb)) + exit(EXIT_FAILURE); + + if (!memcmp(sb.magic, bcache_magic, 16) && !wipe_bcache) { + fprintf(stderr, "Already a bcache device on %s, " + "overwrite with --wipe-bcache\n", dev); + exit(EXIT_FAILURE); + } + + if (!(pr = blkid_new_probe())) + exit(EXIT_FAILURE); + if (blkid_probe_set_device(pr, fd, 0, 0)) + exit(EXIT_FAILURE); + /* enable ptable probing; superblock probing is enabled by default */ + if (blkid_probe_enable_partitions(pr, true)) + exit(EXIT_FAILURE); + if (!blkid_do_probe(pr)) { + /* XXX wipefs doesn't know how to remove partition tables */ + fprintf(stderr, "Device %s already has a non-bcache superblock, " + "remove it using wipefs and wipefs -a\n", dev); exit(EXIT_FAILURE); } @@ -221,7 +247,7 @@ static void write_sb(char *dev, unsigned block_size, unsigned bucket_size, sb.first_bucket = (23 / sb.bucket_size) + 1; if (sb.nbuckets < 1 << 7) { - printf("Not enough buckets: %ju, need %u\n", + fprintf(stderr, "Not enough buckets: %ju, need %u\n", sb.nbuckets, 1 << 7); exit(EXIT_FAILURE); } @@ -250,7 +276,13 @@ static void write_sb(char *dev, unsigned block_size, unsigned bucket_size, sb.csum = csum_set(&sb); - if (pwrite(fd, &sb, sizeof(sb), SB_SECTOR << 9) != sizeof(sb)) { + /* Zero start of disk */ + if (pwrite(fd, zeroes, SB_START, 0) != SB_START) { + perror("write error\n"); + exit(EXIT_FAILURE); + } + /* Write superblock */ + if (pwrite(fd, &sb, sizeof(sb), SB_START) != sizeof(sb)) { perror("write error\n"); exit(EXIT_FAILURE); } @@ -311,7 +343,7 @@ int main(int argc, char **argv) char *backing_devices[argc]; unsigned block_size = 0, bucket_size = 1024; - int writeback = 0, discard = 0; + int writeback = 0, discard = 0, wipe_bcache = 0; unsigned cache_replacement_policy = 0; uint64_t data_offset = BDEV_DATA_START_DEFAULT; uuid_t set_uuid; @@ -324,6 +356,7 @@ int main(int argc, char **argv) { "bucket", 1, NULL, 'b' }, { "block", 1, NULL, 'w' }, { "writeback", 0, &writeback, 1 }, + { "wipe-bcache", 0, &wipe_bcache, 1 }, { "discard", 0, &discard, 1 }, { "cache_replacement_policy", 1, NULL, 'p' }, { "data_offset", 1, NULL, 'o' }, @@ -351,7 +384,7 @@ int main(int argc, char **argv) #if 0 case 'U': if (uuid_parse(optarg, sb.uuid)) { - printf("Bad uuid\n"); + fprintf(stderr, "Bad uuid\n"); exit(EXIT_FAILURE); } break; @@ -363,14 +396,14 @@ int main(int argc, char **argv) case 'o': data_offset = atoll(optarg); if (data_offset < BDEV_DATA_START_DEFAULT) { - printf("Bad data offset; minimum %d sectors\n", + fprintf(stderr, "Bad data offset; minimum %d sectors\n", BDEV_DATA_START_DEFAULT); exit(EXIT_FAILURE); } break; case 'u': if (uuid_parse(optarg, set_uuid)) { - printf("Bad uuid\n"); + fprintf(stderr, "Bad uuid\n"); exit(EXIT_FAILURE); } break; @@ -379,7 +412,7 @@ int main(int argc, char **argv) break; case 1: if (bdev == -1) { - printf("Please specify -C or -B\n"); + fprintf(stderr, "Please specify -C or -B\n"); exit(EXIT_FAILURE); } @@ -391,12 +424,12 @@ int main(int argc, char **argv) } if (!ncache_devices && !nbacking_devices) { - printf("Please supply a device\n"); + fprintf(stderr, "Please supply a device\n"); usage(); } if (bucket_size < block_size) { - printf("Bucket size cannot be smaller than block size\n"); + fprintf(stderr, "Bucket size cannot be smaller than block size\n"); exit(EXIT_FAILURE); } @@ -412,12 +445,14 @@ int main(int argc, char **argv) for (i = 0; i < ncache_devices; i++) write_sb(cache_devices[i], block_size, bucket_size, - writeback, discard, cache_replacement_policy, + writeback, discard, wipe_bcache, + cache_replacement_policy, data_offset, set_uuid, false); for (i = 0; i < nbacking_devices; i++) write_sb(backing_devices[i], block_size, bucket_size, - writeback, discard, cache_replacement_policy, + writeback, discard, wipe_bcache, + cache_replacement_policy, data_offset, set_uuid, true); return 0; diff --git a/probe-bcache.c b/probe-bcache.c index caff7b65..e1ad6146 100644 --- a/probe-bcache.c +++ b/probe-bcache.c @@ -52,7 +52,7 @@ int main(int argc, char **argv) continue; - if (pread(fd, &sb, sizeof(sb), 4096) != sizeof(sb)) + if (pread(fd, &sb, sizeof(sb), SB_START) != sizeof(sb)) continue; if (memcmp(sb.magic, bcache_magic, 16)) From 0d54a238b11b1b3b7c482dc20bf302f97bb81cd7 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sun, 22 Sep 2013 01:12:52 +0200 Subject: [PATCH 03/12] Use the absolute path to modprobe This is necessary on Fedora, according to Rolf Fokkens. --- bcache-register | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bcache-register b/bcache-register index 3a9cd995..9b592bcd 100755 --- a/bcache-register +++ b/bcache-register @@ -1,4 +1,4 @@ #!/bin/sh -modprobe -qba bcache +/sbin/modprobe -qba bcache test -f /sys/fs/bcache/register_quiet && echo "$1" > /sys/fs/bcache/register_quiet From 8b3e39e0525df37dfbc840e49f2f5a4069b34a1f Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sun, 22 Sep 2013 01:13:36 +0200 Subject: [PATCH 04/12] Install the initramfs hook in /usr/share not /etc --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index edb4133a..efeac036 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,8 @@ install: make-bcache probe-bcache bcache-super-show install -m0755 probe-bcache $(DESTDIR)/sbin/ install -m0644 61-bcache.rules $(DESTDIR)/lib/udev/rules.d/ install -m0755 bcache-register $(DESTDIR)/lib/udev/ - -install -m0755 initramfs/hook $(DESTDIR)/etc/initramfs-tools/hooks/bcache - install -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8 + -install -T -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache + install -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/ # install -m0755 bcache-test $(DESTDIR)${PREFIX}/sbin/ clean: From decab738147cf0eb7d6508454d43048b6ff2ab24 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 27 Sep 2013 12:05:46 +0200 Subject: [PATCH 05/12] super-show: Show sync mode and cache replacement policy --- bcache-super-show.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bcache-super-show.c b/bcache-super-show.c index fab5e810..c00d22e1 100644 --- a/bcache-super-show.c +++ b/bcache-super-show.c @@ -136,13 +136,31 @@ int main(int argc, char **argv) printf("dev.cache.first_sector\t%u\n" "dev.cache.cache_sectors\t%ju\n" "dev.cache.total_sectors\t%ju\n" + "dev.cache.ordered\t%s\n" "dev.cache.discard\t%s\n" - "dev.cache.pos\t\t%u\n", + "dev.cache.pos\t\t%u\n" + "dev.cache.replacement\t%ju", sb.bucket_size * sb.first_bucket, sb.bucket_size * (sb.nbuckets - sb.first_bucket), sb.bucket_size * sb.nbuckets, + CACHE_SYNC(&sb) ? "yes" : "no", CACHE_DISCARD(&sb) ? "yes" : "no", - sb.nr_this_dev); + sb.nr_this_dev, + CACHE_REPLACEMENT(&sb)); + switch (CACHE_REPLACEMENT(&sb)) { + case CACHE_REPLACEMENT_LRU: + printf(" [lru]\n"); + break; + case CACHE_REPLACEMENT_FIFO: + printf(" [fifo]\n"); + break; + case CACHE_REPLACEMENT_RANDOM: + printf(" [random]\n"); + break; + default: + putchar('\n'); + } + } else { uint64_t first_sector; if (sb.version == BCACHE_SB_VERSION_BDEV) { From 866e21a35d40e8c5df75cdc7146da88c17cc18d1 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 5 Jul 2013 23:59:21 +0200 Subject: [PATCH 06/12] super-show: Print label --- Makefile | 1 + bcache-super-show.c | 34 ++++++++++++++++++++++++++++++++++ bcache.h | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index efeac036..1f3caa48 100644 --- a/Makefile +++ b/Makefile @@ -22,4 +22,5 @@ make-bcache: CFLAGS += `pkg-config --cflags uuid blkid` make-bcache: bcache.o probe-bcache: LDLIBS += `pkg-config --libs uuid` bcache-super-show: LDLIBS += `pkg-config --libs uuid` +bcache-super-show: CFLAGS += -std=gnu99 bcache-super-show: bcache.o diff --git a/bcache-super-show.c b/bcache-super-show.c index c00d22e1..26cc40ed 100644 --- a/bcache-super-show.c +++ b/bcache-super-show.c @@ -4,6 +4,7 @@ * GPLv2 */ + #define _FILE_OFFSET_BITS 64 #define __USE_FILE_OFFSET64 #define _XOPEN_SOURCE 500 @@ -32,6 +33,29 @@ static void usage() } +static bool accepted_char(char c) +{ + if ('0' <= c && c <= '9') + return true; + if ('A' <= c && c <= 'Z') + return true; + if ('a' <= c && c <= 'z') + return true; + if (strchr(".-_", c)) + return true; + return false; +} + +static void print_encode(char* in) +{ + for (char* pos = in; *pos; pos++) + if (accepted_char(*pos)) + putchar(*pos); + else + printf("%%%x", *pos); +} + + int main(int argc, char **argv) { bool force_csum = false; @@ -123,6 +147,16 @@ int main(int argc, char **argv) putchar('\n'); + char label[SB_LABEL_SIZE + 1]; + strncpy(label, (char*)sb.label, SB_LABEL_SIZE); + label[SB_LABEL_SIZE] = '\0'; + printf("dev.label\t\t"); + if (*label) + print_encode(label); + else + printf("(empty)"); + putchar('\n'); + uuid_unparse(sb.uuid, uuid); printf("dev.uuid\t\t%s\n", uuid); diff --git a/bcache.h b/bcache.h index 1d78da3b..61e42524 100644 --- a/bcache.h +++ b/bcache.h @@ -115,7 +115,7 @@ BITMASK(BDEV_STATE, struct cache_sb, flags, 61, 2); #define BDEV_STATE_DIRTY 2U #define BDEV_STATE_STALE 3U -inline uint64_t crc64(const void *_data, size_t len); +uint64_t crc64(const void *_data, size_t len); #define node(i, j) ((void *) ((i)->d + (j))) #define end(i) node(i, (i)->keys) From 0c7a484a5b09d710814451c06ad30e894deb7ff5 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sat, 5 Oct 2013 21:16:21 +0200 Subject: [PATCH 07/12] 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. --- 61-bcache.rules => 69-bcache.rules | 13 +++++++++---- Makefile | 5 +++-- initramfs/hook | 2 +- probe-bcache.c | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 7 deletions(-) rename 61-bcache.rules => 69-bcache.rules (69%) diff --git a/61-bcache.rules b/69-bcache.rules similarity index 69% rename from 61-bcache.rules rename to 69-bcache.rules index dd85e69a..3f89b125 100644 --- a/61-bcache.rules +++ b/69-bcache.rules @@ -4,13 +4,18 @@ SUBSYSTEM!="block", GOTO="bcache_end" ACTION=="remove", GOTO="bcache_end" -# Backing devices: scan, symlink, register -IMPORT{program}="/sbin/blkid -o udev $tempnode" -# blkid and probe-bcache can disagree, in which case don't register -ENV{ID_FS_TYPE}=="?*", ENV{ID_FS_TYPE}!="bcache", GOTO="bcache_backing_end" +# blkid was run by the standard udev rules +# It recognised bcache (util-linux 2.24+) +ENV{ID_FS_TYPE}=="bcache", GOTO="bcache_backing_found" +# 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" +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" SUBSYSTEM=="block", ACTION=="add|change", ENV{ID_FS_TYPE}=="bcache", \ RUN+="bcache-register $tempnode" LABEL="bcache_backing_end" diff --git a/Makefile b/Makefile index 1f3caa48..b31e080e 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ all: 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 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 -T -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache 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: CFLAGS += `pkg-config --cflags uuid blkid` 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: CFLAGS += -std=gnu99 bcache-super-show: bcache.o diff --git a/initramfs/hook b/initramfs/hook index ce328f3a..5890fe2a 100755 --- a/initramfs/hook +++ b/initramfs/hook @@ -16,7 +16,7 @@ esac . /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 /sbin/probe-bcache manual_add_modules bcache diff --git a/probe-bcache.c b/probe-bcache.c index e1ad6146..c94c9722 100644 --- a/probe-bcache.c +++ b/probe-bcache.c @@ -8,6 +8,7 @@ #define __USE_FILE_OFFSET64 #define _XOPEN_SOURCE 500 +#include #include #include #include @@ -30,6 +31,7 @@ int main(int argc, char **argv) extern char *optarg; struct cache_sb sb; char uuid[40]; + blkid_probe pr; while ((o = getopt(argc, argv, "o:")) != EOF) switch (o) { @@ -51,6 +53,18 @@ int main(int argc, char **argv) if (fd == -1) 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)) continue; From 86ba62c6a19a7ebb1e672a668ce991fb940c415d Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sun, 6 Oct 2013 11:07:20 +0200 Subject: [PATCH 08/12] Move probe-bcache to UDEVLIBDIR --- 69-bcache.rules | 2 +- Makefile | 6 +++--- initramfs/hook | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/69-bcache.rules b/69-bcache.rules index 3f89b125..9445f730 100644 --- a/69-bcache.rules +++ b/69-bcache.rules @@ -11,7 +11,7 @@ ENV{ID_FS_TYPE}=="bcache", GOTO="bcache_backing_found" ENV{ID_FS_TYPE}=="?*", GOTO="bcache_backing_end" # Backing devices: scan, symlink, register -IMPORT{program}="/sbin/probe-bcache -o udev $tempnode" +IMPORT{program}="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}" diff --git a/Makefile b/Makefile index b31e080e..a3179304 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,14 @@ PREFIX=/usr +UDEVLIBDIR=/lib/udev CFLAGS+=-O2 -Wall -g all: 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 probe-bcache $(DESTDIR)/sbin/ - install -m0644 69-bcache.rules $(DESTDIR)/lib/udev/rules.d/ - install -m0755 bcache-register $(DESTDIR)/lib/udev/ + install -m0755 probe-bcache bcache-register $(DESTDIR)$(UDEVLIBDIR)/ + install -m0644 69-bcache.rules $(DESTDIR)$(UDEVLIBDIR)/rules.d/ -install -T -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache install -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/ # install -m0755 bcache-test $(DESTDIR)${PREFIX}/sbin/ diff --git a/initramfs/hook b/initramfs/hook index 5890fe2a..e618e1a5 100755 --- a/initramfs/hook +++ b/initramfs/hook @@ -18,5 +18,5 @@ esac cp -pt "${DESTDIR}/lib/udev/rules.d" /lib/udev/rules.d/69-bcache.rules copy_exec /lib/udev/bcache-register -copy_exec /sbin/probe-bcache +copy_exec /lib/udev/probe-bcache manual_add_modules bcache From 7703224daa1c5b75c5a104b7db2d7fdcd3816cdf Mon Sep 17 00:00:00 2001 From: Rolf Fokkens Date: Sun, 6 Oct 2013 20:30:07 +0200 Subject: [PATCH 09/12] Add a dracut module for bcache --- Makefile | 3 +++ dracut/module-setup.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 dracut/module-setup.sh diff --git a/Makefile b/Makefile index a3179304..825e86f7 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,9 @@ install: make-bcache probe-bcache bcache-super-show install -m0755 probe-bcache bcache-register $(DESTDIR)$(UDEVLIBDIR)/ install -m0644 69-bcache.rules $(DESTDIR)$(UDEVLIBDIR)/rules.d/ -install -T -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache + if [ -d $(DESTDIR)/lib/dracut/modules.d ]; \ + then install -D -m0755 dracut/module-setup.sh $(DESTDIR)/lib/dracut/modules.d/90bcache/module-setup.sh; \ + fi install -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/ # install -m0755 bcache-test $(DESTDIR)${PREFIX}/sbin/ diff --git a/dracut/module-setup.sh b/dracut/module-setup.sh new file mode 100644 index 00000000..5a067cb0 --- /dev/null +++ b/dracut/module-setup.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh + +# +# At some point (util-linux v2.24) blkid will be able to identify bcache +# but until every system has this version of util-linux, probe-bcache is +# provided as an alternative. +# + +check() { + if [[ $hostonly ]] || [[ $mount_needs ]] + then + for fs in "${host_fs_types[@]}"; do + [[ $fs = "bcache" ]] && return 0 + done + return 255 + fi + + return 0 +} + +depends() { + return 0 +} + +installkernel() { + instmods bcache +} + +install() { + inst_multiple ${udevdir}/probe-bcache ${udevdir}/bcache-register + inst_rules 69-bcache.rules +} From 649425369845c51df117420e3c55457b9e4660b2 Mon Sep 17 00:00:00 2001 From: Rolf Fokkens Date: Sun, 6 Oct 2013 22:45:41 +0200 Subject: [PATCH 10/12] Add DRACUTLIBDIR to Makefile --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 825e86f7..f7bc5a83 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ PREFIX=/usr UDEVLIBDIR=/lib/udev +DRACUTLIBDIR=/lib/dracut CFLAGS+=-O2 -Wall -g all: make-bcache probe-bcache bcache-super-show @@ -10,8 +11,8 @@ install: make-bcache probe-bcache bcache-super-show install -m0755 probe-bcache bcache-register $(DESTDIR)$(UDEVLIBDIR)/ install -m0644 69-bcache.rules $(DESTDIR)$(UDEVLIBDIR)/rules.d/ -install -T -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache - if [ -d $(DESTDIR)/lib/dracut/modules.d ]; \ - then install -D -m0755 dracut/module-setup.sh $(DESTDIR)/lib/dracut/modules.d/90bcache/module-setup.sh; \ + if [ -d $(DESTDIR)$(DRACUTLIBDIR)/modules.d ]; \ + then install -D -m0755 dracut/module-setup.sh $(DESTDIR)$(DRACUTLIBDIR)/modules.d/90bcache/module-setup.sh; \ fi install -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/ # install -m0755 bcache-test $(DESTDIR)${PREFIX}/sbin/ From 4ff504e17b032b75f6d5546ec190c834ac69af8c Mon Sep 17 00:00:00 2001 From: Rolf Fokkens Date: Sun, 6 Oct 2013 23:13:05 +0200 Subject: [PATCH 11/12] Add an INSTALL macro to the Makefile --- Makefile | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index f7bc5a83..4f9f7c54 100644 --- a/Makefile +++ b/Makefile @@ -2,20 +2,21 @@ PREFIX=/usr UDEVLIBDIR=/lib/udev DRACUTLIBDIR=/lib/dracut +INSTALL=install CFLAGS+=-O2 -Wall -g all: 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 probe-bcache bcache-register $(DESTDIR)$(UDEVLIBDIR)/ - install -m0644 69-bcache.rules $(DESTDIR)$(UDEVLIBDIR)/rules.d/ - -install -T -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache + $(INSTALL) -m0755 make-bcache bcache-super-show $(DESTDIR)${PREFIX}/sbin/ + $(INSTALL) -m0755 probe-bcache bcache-register $(DESTDIR)$(UDEVLIBDIR)/ + $(INSTALL) -m0644 69-bcache.rules $(DESTDIR)$(UDEVLIBDIR)/rules.d/ + -$(INSTALL) -T -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache if [ -d $(DESTDIR)$(DRACUTLIBDIR)/modules.d ]; \ - then install -D -m0755 dracut/module-setup.sh $(DESTDIR)$(DRACUTLIBDIR)/modules.d/90bcache/module-setup.sh; \ + then $(INSTALL) -D -m0755 dracut/module-setup.sh $(DESTDIR)$(DRACUTLIBDIR)/modules.d/90bcache/module-setup.sh; \ fi - install -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/ -# install -m0755 bcache-test $(DESTDIR)${PREFIX}/sbin/ + $(INSTALL) -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/ +# $(INSTALL) -m0755 bcache-test $(DESTDIR)${PREFIX}/sbin/ clean: $(RM) -f make-bcache probe-bcache bcache-super-show bcache-test *.o From 89f11b135d1d57a5dbdc3548bfb9bfa0113075c4 Mon Sep 17 00:00:00 2001 From: Rolf Fokkens Date: Thu, 10 Oct 2013 22:53:02 +0200 Subject: [PATCH 12/12] Simplify 69-bcache.rules Gabriel: simplified a bit further --- 69-bcache.rules | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/69-bcache.rules b/69-bcache.rules index 9445f730..b83f6bc4 100644 --- a/69-bcache.rules +++ b/69-bcache.rules @@ -16,8 +16,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" -SUBSYSTEM=="block", ACTION=="add|change", ENV{ID_FS_TYPE}=="bcache", \ - RUN+="bcache-register $tempnode" +RUN+="bcache-register $tempnode" LABEL="bcache_backing_end" # Cached devices: symlink