Add a --writeback switch to make-bcache

This commit is contained in:
Kent Overstreet 2011-07-31 19:29:22 -07:00
parent 552595bc6e
commit e8c85bb806
2 changed files with 29 additions and 2 deletions

View File

@ -1,6 +1,16 @@
#ifndef _BCACHE_H #ifndef _BCACHE_H
#define _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[] = { static const char bcache_magic[] = {
0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca, 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca,
0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 }; 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 };
@ -41,6 +51,8 @@ struct cache_sb {
uint64_t d[]; /* journal buckets */ uint64_t d[]; /* journal buckets */
}; };
BITMASK(BDEV_WRITEBACK, struct cache_sb, flags, 0, 1);
inline uint64_t crc64(const void *_data, size_t len); inline uint64_t crc64(const void *_data, size_t len);
#define node(i, j) ((void *) ((i)->d + (j))) #define node(i, j) ((void *) ((i)->d + (j)))

View File

@ -5,6 +5,7 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <getopt.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@ -67,10 +68,16 @@ void usage()
" -b bucket size\n" " -b bucket size\n"
" -w block size (hard sector size of SSD, often 2k)\n" " -w block size (hard sector size of SSD, often 2k)\n"
" -U UUID\n" " -U UUID\n"
" -S Set UUID\n"); " --writeback Enable writeback\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int writeback;
struct option opts[2] = {
{ "writeback", 0, &writeback, 1 }
};
void write_sb(char *dev, struct cache_sb *sb) void write_sb(char *dev, struct cache_sb *sb)
{ {
int fd; int fd;
@ -97,6 +104,12 @@ void write_sb(char *dev, struct cache_sb *sb)
exit(EXIT_FAILURE); 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; sb->offset = SB_SECTOR;
memcpy(sb->magic, bcache_magic, 16); memcpy(sb->magic, bcache_magic, 16);
sb->nbuckets = getblocks(fd) / sb->bucket_size; sb->nbuckets = getblocks(fd) / sb->bucket_size;
@ -153,7 +166,9 @@ int main(int argc, char **argv)
uuid_generate(sb.uuid); uuid_generate(sb.uuid);
uuid_generate(sb.set_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) { switch (c) {
case 'C': case 'C':
sb.version = 0; sb.version = 0;