summaryrefslogtreecommitdiff
path: root/make-bcache.c
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 /make-bcache.c
parent552595bc6eef40e464a82a2eeddc3711078abafc (diff)
Add a --writeback switch to make-bcache
Diffstat (limited to 'make-bcache.c')
-rw-r--r--make-bcache.c19
1 files changed, 17 insertions, 2 deletions
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;