aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2010-10-08 07:04:49 -0700
committerKent Overstreet <kent.overstreet@gmail.com>2010-10-08 07:04:49 -0700
commit7e9790107563dfa88ccd89aa0d0fa33266848400 (patch)
treea1418f8289ca916ba329756fec003c66ac024d09
parent1d895a5a451e041fcefeefbe1fd07eed034394cd (diff)
downloadbcache-tools-7e9790107563dfa88ccd89aa0d0fa33266848400.tar.gz
UUIDs
-rw-r--r--61-bcache.rules3
-rw-r--r--Makefile13
-rw-r--r--bcache-test.c4
-rw-r--r--bcache.h29
-rw-r--r--initramfs11
-rw-r--r--make-bcache.c40
-rw-r--r--probe-bcache.c67
7 files changed, 138 insertions, 29 deletions
diff --git a/61-bcache.rules b/61-bcache.rules
new file mode 100644
index 00000000..acedefe0
--- /dev/null
+++ b/61-bcache.rules
@@ -0,0 +1,3 @@
+KERNEL=="sd*", ENV{DEVTYPE}=="disk", IMPORT{program}="/sbin/probe-bcache -o udev $tempnode"
+
+ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
diff --git a/Makefile b/Makefile
index a47719d7..62e0fb9d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,20 @@
-PREFIX=/usr/local
+#PREFIX=/usr/local
CFLAGS=-O2 -Wall -g
-all: make-bcache
+all: make-bcache probe-bcache
clean:
rm -f make-bcache bcache-test *.o
-install: make-bcache
+install: make-bcache probe-bcache
install -m0755 make-bcache ${PREFIX}/sbin/
- install -m0755 bcache-test ${PREFIX}/sbin/
+ install -m0755 probe-bcache ${PREFIX}/sbin/
+ install -m0644 61-bcache.rules /lib/udev/rules.d/
+ install -m0755 initramfs /usr/share/initramfs-tools/hooks/bcache
+# install -m0755 bcache-test ${PREFIX}/sbin/
bcache-test: LDFLAGS += -lm -lssl -lcrypto
+make-bcache: LDFLAGS += -luuid
+probe-bcache: LDFLAGS += -luuid
diff --git a/bcache-test.c b/bcache-test.c
index 5858cab1..0f8ad376 100644
--- a/bcache-test.c
+++ b/bcache-test.c
@@ -62,7 +62,7 @@ double normal()
n = 0 / (double) 0;
return x;
}
-
+
do {
x = random() / (double) (RAND_MAX / 2) - 1;
y = random() / (double) (RAND_MAX / 2) - 1;
@@ -233,7 +233,7 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
//setvbuf(stdout, NULL, _IONBF, 0);
-
+
for (i = 0; !benchmark || i < benchmark; i++) {
bool writing = (wtest && (i & 1)) || !rtest;
nbytes = randsize ? drand48() * 16 + 1 : 1;
diff --git a/bcache.h b/bcache.h
new file mode 100644
index 00000000..448b6a50
--- /dev/null
+++ b/bcache.h
@@ -0,0 +1,29 @@
+#ifndef _BCACHE_H
+#define _BCACHE_H
+
+static const char bcache_magic[] = {
+ 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca,
+ 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 };
+
+struct cache_sb {
+ uint8_t magic[16];
+#define CACHE_CLEAN 1
+#define CACHE_SYNC 2
+ uint32_t version;
+ uint16_t block_size; /* sectors */
+ uint16_t bucket_size; /* sectors */
+ uint32_t journal_start; /* buckets */
+ uint32_t first_bucket; /* start of data */
+ uint64_t nbuckets; /* device size */
+ uint64_t btree_root;
+ uint16_t btree_level;
+ uint16_t _pad[3];
+ uint8_t uuid[16];
+};
+
+struct bucket_disk {
+ uint16_t priority;
+ uint8_t generation;
+} __attribute((packed));
+
+#endif
diff --git a/initramfs b/initramfs
new file mode 100644
index 00000000..3815dc95
--- /dev/null
+++ b/initramfs
@@ -0,0 +1,11 @@
+#!/bin/sh -e
+
+case "$1" in
+prereqs)
+ echo "udev"
+ exit 0
+ ;;
+esac
+
+cp -p /lib/udev/rules.d/61-bcache.rules $DESTDIR/lib/udev/rules.d/
+cp -p /sbin/probe-bcache $DESTDIR/sbin
diff --git a/make-bcache.c b/make-bcache.c
index 04861f91..a7381d0a 100644
--- a/make-bcache.c
+++ b/make-bcache.c
@@ -12,27 +12,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <uuid/uuid.h>
-static const char bcache_magic[] = {
- 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca,
- 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 };
-
-struct cache_sb {
- uint8_t magic[16];
- uint32_t version;
- uint16_t block_size; /* sectors */
- uint16_t bucket_size; /* sectors */
- uint32_t journal_start; /* buckets */
- uint32_t first_bucket; /* start of data */
- uint64_t nbuckets; /* device size */
- uint64_t btree_root;
- uint16_t btree_level;
-};
-
-struct bucket_disk {
- uint16_t priority;
- uint8_t generation;
-} __attribute((packed));
+#include "bcache.h"
char zero[4096];
@@ -85,12 +67,21 @@ int main(int argc, char **argv)
int64_t nblocks, bucketsize = 32, blocksize = 8;
int fd, i, c;
struct cache_sb sb;
+ char uuid[40];
- while ((c = getopt(argc, argv, "b:")) != -1)
+ uuid_generate(sb.uuid);
+
+ while ((c = getopt(argc, argv, "U:b:")) != -1)
switch (c) {
case 'b':
bucketsize = hatoi(optarg) / 512;
break;
+ case 'U':
+ if (uuid_parse(optarg, sb.uuid)) {
+ printf("Bad uuid\n");
+ exit(EXIT_FAILURE);
+ }
+ break;
}
if (argc <= optind) {
@@ -117,6 +108,7 @@ int main(int argc, char **argv)
sb.block_size = blocksize;
sb.bucket_size = bucketsize;
sb.nbuckets = nblocks / sb.bucket_size;
+ uuid_unparse(sb.uuid, uuid);
do
sb.first_bucket = ((--sb.nbuckets * sizeof(struct bucket_disk)) + (24 << 9)) / (sb.bucket_size << 9) + 1;
@@ -131,12 +123,14 @@ int main(int argc, char **argv)
"bucket_size: %u\n"
"journal_start: %u\n"
"first_bucket: %u\n"
- "nbuckets: %ju\n",
+ "nbuckets: %ju\n"
+ "UUID: %s\n",
sb.block_size,
sb.bucket_size,
sb.journal_start,
sb.first_bucket,
- sb.nbuckets);
+ sb.nbuckets,
+ uuid);
/* Zero out priorities */
lseek(fd, 4096, SEEK_SET);
diff --git a/probe-bcache.c b/probe-bcache.c
new file mode 100644
index 00000000..ec81ea71
--- /dev/null
+++ b/probe-bcache.c
@@ -0,0 +1,67 @@
+#define _FILE_OFFSET_BITS 64
+#define __USE_FILE_OFFSET64
+#define _XOPEN_SOURCE 500
+
+#include <fcntl.h>
+#include <linux/fs.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <uuid/uuid.h>
+
+#include "bcache.h"
+
+int main(int argc, char **argv)
+{
+ bool udev = false;
+ int i, o;
+ extern char *optarg;
+ struct cache_sb sb;
+ char uuid[40];
+
+ while ((o = getopt(argc, argv, "o:")) != EOF)
+ switch (o) {
+ case 'o':
+ if (strcmp("udev", optarg)) {
+ printf("Invalid output format %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ udev = true;
+ break;
+ }
+
+
+ argv += optind;
+ argc -= optind;
+
+ for (i = 0; i < argc; i++) {
+ int fd = open(argv[i], O_RDONLY);
+ if (fd == -1)
+ continue;
+
+
+ if (pread(fd, &sb, sizeof(sb), 4096) != sizeof(sb))
+ continue;
+
+ if (memcmp(sb.magic, bcache_magic, 16))
+ continue;
+
+ uuid_unparse(sb.uuid, uuid);
+
+ if (udev)
+ printf("ID_FS_UUID=%s\n"
+ "ID_FS_UUID_ENC=%s\n"
+ "ID_FS_TYPE=bcache\n",
+ uuid, uuid);
+ else
+ printf("%s: UUID=\"\" TYPE=\"bcache\"\n", uuid);
+ }
+
+ return 0;
+}