summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlava Pestov <sp@daterainc.com>2015-01-20 22:18:35 -0800
committerSlava Pestov <sp@daterainc.com>2015-01-20 22:18:52 -0800
commit34c87b0e983038be4939ec775d68fa5dc688040c (patch)
treed57a0165b654568c378d7642fa0e44d24dc32bb2
parent15c8235aa4ccb918cee1c80d6fbcfba5ca20bb99 (diff)
bcacheadm: add --writearound flag for testing, probably not useful
Change-Id: Ia4a2125a50d7b102791b8fc64b48bd102d8cdc89
-rw-r--r--bcache.c6
-rw-r--r--bcache.h4
-rw-r--r--bcacheadm.c14
-rw-r--r--make-bcache.c5
4 files changed, 20 insertions, 9 deletions
diff --git a/bcache.c b/bcache.c
index 4bdbc6e..a032761 100644
--- a/bcache.c
+++ b/bcache.c
@@ -452,7 +452,7 @@ static void do_write_sb(int fd, struct cache_sb *sb)
}
void write_backingdev_sb(int fd, unsigned block_size, unsigned *bucket_sizes,
- bool writeback, uint64_t data_offset,
+ unsigned mode, uint64_t data_offset,
const char *label,
uuid_le set_uuid)
{
@@ -474,9 +474,7 @@ void write_backingdev_sb(int fd, unsigned block_size, unsigned *bucket_sizes,
if (label)
memcpy(sb.label, label, SB_LABEL_SIZE);
- SET_BDEV_CACHE_MODE(&sb, writeback
- ? CACHE_MODE_WRITEBACK
- : CACHE_MODE_WRITETHROUGH);
+ SET_BDEV_CACHE_MODE(&sb, mode);
if (data_offset != BDEV_DATA_START_DEFAULT) {
sb.version = BCACHE_SB_VERSION_BDEV_WITH_OFFSET;
diff --git a/bcache.h b/bcache.h
index d409ee2..d77d0a2 100644
--- a/bcache.h
+++ b/bcache.h
@@ -46,8 +46,8 @@ uint64_t bch_checksum(unsigned, const void *, size_t);
uint64_t getblocks(int);
uint64_t hatoi(const char *);
unsigned hatoi_validate(const char *, const char *);
-void write_backingdev_sb(int, unsigned, unsigned *, bool, uint64_t,
- const char *, uuid_le);
+void write_backingdev_sb(int, unsigned, unsigned *, unsigned, uint64_t,
+ const char *, uuid_le);
int dev_open(const char *, bool);
void write_cache_sbs(int *, struct cache_sb *, unsigned, unsigned *, int);
void next_cache_device(struct cache_sb *, unsigned, int, unsigned, bool);
diff --git a/bcacheadm.c b/bcacheadm.c
index 05e48d9..d400ed2 100644
--- a/bcacheadm.c
+++ b/bcacheadm.c
@@ -48,7 +48,7 @@ size_t i, nr_backing_devices = 0, nr_cache_devices = 0;
unsigned block_size = 0;
unsigned bucket_sizes[MAX_DEVS];
int num_bucket_sizes = 0;
-int writeback = 0, discard = 0, wipe_bcache = 0;
+int writeback = 0, writearound = 0, discard = 0, wipe_bcache = 0;
unsigned replication_set = 0;
char *replacement_policy = 0;
uint64_t data_offset = BDEV_DATA_START_DEFAULT;
@@ -204,6 +204,7 @@ static NihOption make_bcache_options[] = {
{0, "wipe-bcache", N_("destroy existing bcache data if present"), NULL, NULL, &wipe_bcache, NULL},
{0, "discard", N_("enable discards"), NULL, NULL, &discard, NULL},
{0, "writeback", N_("enable writeback"), NULL, NULL, &writeback, NULL},
+ {0, "writearound", N_("enable writearound"), NULL, NULL, &writearound, NULL},
NIH_OPTION_LAST
};
@@ -291,6 +292,8 @@ int make_bcache(NihCommand *command, char *const *args)
int backing_dev_fd[devs];
+ unsigned cache_mode;
+
cache_set_sb = calloc(1, sizeof(*cache_set_sb) +
sizeof(struct cache_member) * devs);
@@ -380,10 +383,17 @@ int make_bcache(NihCommand *command, char *const *args)
write_cache_sbs(cache_dev_fd, cache_set_sb, block_size,
bucket_sizes, num_bucket_sizes);
+ if (writeback)
+ cache_mode = CACHE_MODE_WRITEBACK;
+ else if (writearound)
+ cache_mode = CACHE_MODE_WRITEAROUND;
+ else
+ cache_mode = CACHE_MODE_WRITETHROUGH;
+
for (i = 0; i < nr_backing_devices; i++)
write_backingdev_sb(backing_dev_fd[i],
block_size, bucket_sizes,
- writeback, data_offset,
+ cache_mode, data_offset,
backing_dev_labels[i],
cache_set_sb->set_uuid);
diff --git a/make-bcache.c b/make-bcache.c
index 35bfc8c..96b8d58 100644
--- a/make-bcache.c
+++ b/make-bcache.c
@@ -247,7 +247,10 @@ int main(int argc, char **argv)
for (i = 0; i < nr_backing_devices; i++)
write_backingdev_sb(backing_dev_fd[i],
block_size, bucket_sizes,
- writeback, data_offset,
+ writeback
+ ? CACHE_MODE_WRITEBACK
+ : CACHE_MODE_WRITETHROUGH,
+ data_offset,
backing_dev_labels[i],
cache_set_sb->set_uuid);