summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <koverstreet@google.com>2011-07-31 19:29:22 -0700
committerKent Overstreet <koverstreet@google.com>2011-07-31 19:29:22 -0700
commite8c85bb806084037a48bedb0613be9c1bb43d853 (patch)
treede65e6d89504f6ad6d1d4ea95a39a2d840e85679
parent552595bc6eef40e464a82a2eeddc3711078abafc (diff)
Add a --writeback switch to make-bcache
-rw-r--r--bcache.h12
-rw-r--r--make-bcache.c19
2 files changed, 29 insertions, 2 deletions
diff --git a/bcache.h b/bcache.h
index d91b3e1..e667cc0 100644
--- a/bcache.h
+++ b/bcache.h
@@ -1,6 +1,16 @@
#ifndef _BCACHE_H
#define _BCACHE_H
+#define BITMASK(name, type, field, offset, size) \
+static inline uint64_t name(const type *k) \
+{ return (k->field >> offset) & ~(((uint64_t) ~0) << size); } \
+ \
+static inline void SET_##name(type *k, uint64_t v) \
+{ \
+ k->field &= ~(~((uint64_t) ~0 << size) << offset); \
+ k->field |= v << offset; \
+}
+
static const char bcache_magic[] = {
0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca,
0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 };
@@ -41,6 +51,8 @@ struct cache_sb {
uint64_t d[]; /* journal buckets */
};
+BITMASK(BDEV_WRITEBACK, struct cache_sb, flags, 0, 1);
+
inline uint64_t crc64(const void *_data, size_t len);
#define node(i, j) ((void *) ((i)->d + (j)))
diff --git a/make-bcache.c b/make-bcache.c
index 58fe674..d442853 100644
--- a/make-bcache.c
+++ b/make-bcache.c
@@ -5,6 +5,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
+#include <getopt.h>
#include <linux/fs.h>
#include <stdbool.h>
#include <stdint.h>
@@ -67,10 +68,16 @@ void usage()
" -b bucket size\n"
" -w block size (hard sector size of SSD, often 2k)\n"
" -U UUID\n"
- " -S Set UUID\n");
+ " --writeback Enable writeback\n");
exit(EXIT_FAILURE);
}
+int writeback;
+
+struct option opts[2] = {
+ { "writeback", 0, &writeback, 1 }
+};
+
void write_sb(char *dev, struct cache_sb *sb)
{
int fd;
@@ -97,6 +104,12 @@ void write_sb(char *dev, struct cache_sb *sb)
exit(EXIT_FAILURE);
}
+ if (sb->version == CACHE_BACKING_DEV &&
+ writeback)
+ SET_BDEV_WRITEBACK(sb, 1);
+ else
+ SET_BDEV_WRITEBACK(sb, 0);
+
sb->offset = SB_SECTOR;
memcpy(sb->magic, bcache_magic, 16);
sb->nbuckets = getblocks(fd) / sb->bucket_size;
@@ -153,7 +166,9 @@ int main(int argc, char **argv)
uuid_generate(sb.uuid);
uuid_generate(sb.set_uuid);
- while ((c = getopt(argc, argv, "-CBU:w:b:")) != -1)
+ while ((c = getopt_long(argc, argv,
+ "-CBU:w:b:",
+ opts, NULL)) != -1)
switch (c) {
case 'C':
sb.version = 0;