From 039b45dfe9a1e58726cdc35f1e077b547edf4d35 Mon Sep 17 00:00:00 2001 From: rk Date: Tue, 3 Jun 2014 10:24:10 -0700 Subject: [PATCH] make-bcache.c: Added support for storing "label" information for the the devices in the super-block. bcache.h: Bring version information to the latest kernel version. bcache-super-show.c: Add setsize for caching devices. This indicates the number of devices in caching set. Testing done: 1.0 make-bcache with --label option and checking back to see if bcache-super-show shows the devices. 2.0 bcache-super-show does not bail if version is 5. 3.0 bcache-super-show shows the correct setsize. Change-Id: If0f1ec6204b233b34ff4c8a57a8809d2c8dbe3e3 --- bcache-super-show.c | 2 ++ bcache.h | 5 +++-- make-bcache.c | 18 ++++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/bcache-super-show.c b/bcache-super-show.c index 26cc40ed..c65c672c 100644 --- a/bcache-super-show.c +++ b/bcache-super-show.c @@ -173,6 +173,7 @@ int main(int argc, char **argv) "dev.cache.ordered\t%s\n" "dev.cache.discard\t%s\n" "dev.cache.pos\t\t%u\n" + "dev.cache.setsize\t\t%u\n" "dev.cache.replacement\t%ju", sb.bucket_size * sb.first_bucket, sb.bucket_size * (sb.nbuckets - sb.first_bucket), @@ -180,6 +181,7 @@ int main(int argc, char **argv) CACHE_SYNC(&sb) ? "yes" : "no", CACHE_DISCARD(&sb) ? "yes" : "no", sb.nr_this_dev, + sb.nr_in_set, CACHE_REPLACEMENT(&sb)); switch (CACHE_REPLACEMENT(&sb)) { case CACHE_REPLACEMENT_LRU: diff --git a/bcache.h b/bcache.h index b9e148ba..bd61d76e 100644 --- a/bcache.h +++ b/bcache.h @@ -28,11 +28,12 @@ static const char bcache_magic[] = { * Version 3: Cache device with new UUID format * Version 4: Backing device with data offset */ -#define BCACHE_SB_VERSION_CDEV 0 +#define BCACHE_SB_VERSION_CDEV_V0 0 #define BCACHE_SB_VERSION_BDEV 1 #define BCACHE_SB_VERSION_CDEV_WITH_UUID 3 #define BCACHE_SB_VERSION_BDEV_WITH_OFFSET 4 -#define BCACHE_SB_MAX_VERSION 4 +#define BCACHE_SB_VERSION_CDEV 5 +#define BCACHE_SB_MAX_VERSION 5 #define SB_SECTOR 8 #define SB_LABEL_SIZE 32 diff --git a/make-bcache.c b/make-bcache.c index 430d24a1..75df4d3e 100644 --- a/make-bcache.c +++ b/make-bcache.c @@ -158,6 +158,7 @@ void usage() " --wipe-bcache destroy existing bcache data if present\n" " --tier set tier of subsequent cache devices\n" " --cache_replacement_policy=(lru|fifo|random)\n" + " -l, --label label\n" " -h, --help display this help and exit\n"); exit(EXIT_FAILURE); } @@ -173,7 +174,8 @@ static void write_sb(char *dev, unsigned block_size, unsigned bucket_size, bool writeback, bool discard, bool wipe_bcache, unsigned cache_replacement_policy, uint64_t data_offset, uuid_t set_uuid, unsigned tier, bool bdev, - uint16_t nr_in_set, uint16_t nr_this_dev) + uint16_t nr_in_set, uint16_t nr_this_dev, + char *label) { int fd; char uuid_str[40], set_uuid_str[40], zeroes[SB_START] = {0}; @@ -224,6 +226,9 @@ static void write_sb(char *dev, unsigned block_size, unsigned bucket_size, uuid_unparse(sb.uuid, uuid_str); uuid_unparse(sb.set_uuid, set_uuid_str); + if (label) { + memcpy(sb.label, label, SB_LABEL_SIZE); + } if (SB_IS_BDEV(&sb)) { SET_BDEV_CACHE_MODE( @@ -353,6 +358,7 @@ int main(int argc, char **argv) unsigned cache_replacement_policy = 0; uint64_t data_offset = BDEV_DATA_START_DEFAULT; uuid_t set_uuid; + char *label = NULL; uuid_generate(set_uuid); @@ -368,12 +374,13 @@ int main(int argc, char **argv) { "data_offset", 1, NULL, 'o' }, { "cset-uuid", 1, NULL, 'u' }, { "tier", 1, NULL, 't' }, + { "label", 1, NULL, 'l' }, { "help", 0, NULL, 'h' }, { NULL, 0, NULL, 0 }, }; while ((c = getopt_long(argc, argv, - "-hCBU:w:b:", + "-hCBU:w:b:l:", opts, NULL)) != -1) switch (c) { case 'C': @@ -414,6 +421,9 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } break; + case 'l': + label = optarg; + break; case 't': tier = strtoul(optarg, NULL, 10); if (tier >= CACHE_TIERS) { @@ -465,13 +475,13 @@ int main(int argc, char **argv) writeback, discard, wipe_bcache, cache_replacement_policy, data_offset, set_uuid, cache_device_tier[i], false, - ncache_devices, i); + ncache_devices, i, label); for (i = 0; i < nbacking_devices; i++) write_sb(backing_devices[i], block_size, bucket_size, writeback, discard, wipe_bcache, cache_replacement_policy, data_offset, - set_uuid, 0, true, nbacking_devices, i); + set_uuid, 0, true, nbacking_devices, i, label); return 0; }