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
This commit is contained in:
rk 2014-06-03 10:24:10 -07:00
parent 9115b9a7ba
commit 039b45dfe9
3 changed files with 19 additions and 6 deletions

View File

@ -173,6 +173,7 @@ int main(int argc, char **argv)
"dev.cache.ordered\t%s\n" "dev.cache.ordered\t%s\n"
"dev.cache.discard\t%s\n" "dev.cache.discard\t%s\n"
"dev.cache.pos\t\t%u\n" "dev.cache.pos\t\t%u\n"
"dev.cache.setsize\t\t%u\n"
"dev.cache.replacement\t%ju", "dev.cache.replacement\t%ju",
sb.bucket_size * sb.first_bucket, sb.bucket_size * sb.first_bucket,
sb.bucket_size * (sb.nbuckets - 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_SYNC(&sb) ? "yes" : "no",
CACHE_DISCARD(&sb) ? "yes" : "no", CACHE_DISCARD(&sb) ? "yes" : "no",
sb.nr_this_dev, sb.nr_this_dev,
sb.nr_in_set,
CACHE_REPLACEMENT(&sb)); CACHE_REPLACEMENT(&sb));
switch (CACHE_REPLACEMENT(&sb)) { switch (CACHE_REPLACEMENT(&sb)) {
case CACHE_REPLACEMENT_LRU: case CACHE_REPLACEMENT_LRU:

View File

@ -28,11 +28,12 @@ static const char bcache_magic[] = {
* Version 3: Cache device with new UUID format * Version 3: Cache device with new UUID format
* Version 4: Backing device with data offset * 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_BDEV 1
#define BCACHE_SB_VERSION_CDEV_WITH_UUID 3 #define BCACHE_SB_VERSION_CDEV_WITH_UUID 3
#define BCACHE_SB_VERSION_BDEV_WITH_OFFSET 4 #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_SECTOR 8
#define SB_LABEL_SIZE 32 #define SB_LABEL_SIZE 32

View File

@ -158,6 +158,7 @@ void usage()
" --wipe-bcache destroy existing bcache data if present\n" " --wipe-bcache destroy existing bcache data if present\n"
" --tier set tier of subsequent cache devices\n" " --tier set tier of subsequent cache devices\n"
" --cache_replacement_policy=(lru|fifo|random)\n" " --cache_replacement_policy=(lru|fifo|random)\n"
" -l, --label label\n"
" -h, --help display this help and exit\n"); " -h, --help display this help and exit\n");
exit(EXIT_FAILURE); 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, bool writeback, bool discard, bool wipe_bcache,
unsigned cache_replacement_policy, uint64_t data_offset, unsigned cache_replacement_policy, uint64_t data_offset,
uuid_t set_uuid, unsigned tier, bool bdev, 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; int fd;
char uuid_str[40], set_uuid_str[40], zeroes[SB_START] = {0}; 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.uuid, uuid_str);
uuid_unparse(sb.set_uuid, set_uuid_str); uuid_unparse(sb.set_uuid, set_uuid_str);
if (label) {
memcpy(sb.label, label, SB_LABEL_SIZE);
}
if (SB_IS_BDEV(&sb)) { if (SB_IS_BDEV(&sb)) {
SET_BDEV_CACHE_MODE( SET_BDEV_CACHE_MODE(
@ -353,6 +358,7 @@ int main(int argc, char **argv)
unsigned cache_replacement_policy = 0; unsigned cache_replacement_policy = 0;
uint64_t data_offset = BDEV_DATA_START_DEFAULT; uint64_t data_offset = BDEV_DATA_START_DEFAULT;
uuid_t set_uuid; uuid_t set_uuid;
char *label = NULL;
uuid_generate(set_uuid); uuid_generate(set_uuid);
@ -368,12 +374,13 @@ int main(int argc, char **argv)
{ "data_offset", 1, NULL, 'o' }, { "data_offset", 1, NULL, 'o' },
{ "cset-uuid", 1, NULL, 'u' }, { "cset-uuid", 1, NULL, 'u' },
{ "tier", 1, NULL, 't' }, { "tier", 1, NULL, 't' },
{ "label", 1, NULL, 'l' },
{ "help", 0, NULL, 'h' }, { "help", 0, NULL, 'h' },
{ NULL, 0, NULL, 0 }, { NULL, 0, NULL, 0 },
}; };
while ((c = getopt_long(argc, argv, while ((c = getopt_long(argc, argv,
"-hCBU:w:b:", "-hCBU:w:b:l:",
opts, NULL)) != -1) opts, NULL)) != -1)
switch (c) { switch (c) {
case 'C': case 'C':
@ -414,6 +421,9 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
break; break;
case 'l':
label = optarg;
break;
case 't': case 't':
tier = strtoul(optarg, NULL, 10); tier = strtoul(optarg, NULL, 10);
if (tier >= CACHE_TIERS) { if (tier >= CACHE_TIERS) {
@ -465,13 +475,13 @@ int main(int argc, char **argv)
writeback, discard, wipe_bcache, writeback, discard, wipe_bcache,
cache_replacement_policy, data_offset, cache_replacement_policy, data_offset,
set_uuid, cache_device_tier[i], false, set_uuid, cache_device_tier[i], false,
ncache_devices, i); ncache_devices, i, label);
for (i = 0; i < nbacking_devices; i++) for (i = 0; i < nbacking_devices; i++)
write_sb(backing_devices[i], block_size, bucket_size, write_sb(backing_devices[i], block_size, bucket_size,
writeback, discard, wipe_bcache, writeback, discard, wipe_bcache,
cache_replacement_policy, data_offset, cache_replacement_policy, data_offset,
set_uuid, 0, true, nbacking_devices, i); set_uuid, 0, true, nbacking_devices, i, label);
return 0; return 0;
} }