char *backing_dev_labels[MAX_DEVS];
size_t i, nr_backing_devices = 0, nr_cache_devices = 0;
unsigned block_size = 0;
+unsigned btree_node_size = 0;
unsigned bucket_sizes[MAX_DEVS];
int num_bucket_sizes = 0;
int writeback = 0, writearound = 0, discard = 0, wipe_bcache = 0;
/* list globals */
char *cset_dir = "/sys/fs/bcache";
bool list_devs = false;
+static const char *internal_uuid = NULL;
/* status globals */
bool status_all = false;
return 0;
}
+static int set_btree_node_size(NihOption *option, const char *arg)
+{
+ btree_node_size = hatoi_validate(arg, "btree node size");
+ return 0;
+}
+
static int set_cache(NihOption *option, const char *arg)
{
bdev = 0;
//Only one bucket_size supported until a list of bucket sizes is parsed correctly
{'b', "bucket", N_("bucket size"), NULL, "size", NULL, set_bucket_sizes},
//Does the default setter automatically convert strings to an int?
- {'w', "block", N_("block size (hard sector size of SSD, often 2k"), NULL,"size", NULL, set_block_size},
+ {'w', "block", N_("block size (hard sector size of SSD, often 2k"), NULL, "size", NULL, set_block_size},
+
+ {'n', "btree-node", N_("Btree node size, default 256k"), NULL, "size", NULL, set_btree_node_size},
+
{'t', "tier", N_("tier of subsequent devices"), NULL,"#", &tier, NULL},
{'p', "cache_replacement_policy", N_("one of (lru|fifo|random)"), NULL,"policy", &replacement_policy, NULL},
{'o', "data_offset", N_("data offset in sectors"), NULL,"offset", &data_offset, NULL},
static NihOption list_cachesets_options[] = {
{'d', "dir", N_("directory"), NULL, NULL, &cset_dir, NULL},
{0, "list-devs", N_("list all devices in the cache sets as well"), NULL, NULL, &list_devs, NULL},
+ {0, "internal_uuid", N_("Show the internal UUID for the given cacheset UUID"), NULL, "UUID", &internal_uuid, NULL},
NIH_OPTION_LAST
};
static NihOption capacity_options[] = {
{'u', "set", N_("cache_set UUID"), NULL, "UUID", &capacity_uuid, NULL},
- {'d', "devs", N_("dev UUID"), NULL, NULL, &capacity_devs, NULL},
+ {'d', "devs", N_("Individual device capacities"), NULL, NULL, &capacity_devs, NULL},
NIH_OPTION_LAST
};
int make_bcache(NihCommand *command, char *const *args)
{
int cache_dev_fd[devs];
+ int data_replicas_num, metadata_replicas_num;
int backing_dev_fd[devs];
cache_set_sb = calloc(1, sizeof(*cache_set_sb) +
sizeof(struct cache_member) * devs);
- /*
- * Currently make the cache-set uuid and user_id same,
- * until proper support/usage is added.
- */
- if (cache_set_uuid) {
- if (uuid_parse(cache_set_uuid, cache_set_sb->set_uuid.b)) {
- fprintf(stderr, "Bad uuid\n");
- return -1;
- }
- } else {
- uuid_generate(cache_set_sb->set_uuid.b);
- }
+ uuid_generate(cache_set_sb->set_uuid.b);
if (cache_set_uuid) {
if(uuid_parse(cache_set_uuid, cache_set_sb->user_uuid.b)) {
}
if (metadata_replicas) {
- SET_CACHE_SET_META_REPLICAS_WANT(cache_set_sb,
- strtoul_or_die(metadata_replicas,
- CACHE_SET_META_REPLICAS_WANT_MAX,
- "meta replicas"));
+ metadata_replicas_num =
+ strtoul_or_die(metadata_replicas,
+ CACHE_SET_META_REPLICAS_WANT_MAX,
+ "meta replicas");
} else {
- SET_CACHE_SET_META_REPLICAS_WANT(cache_set_sb, 1);
+ metadata_replicas_num = 1;
}
+ SET_CACHE_SET_META_REPLICAS_WANT(cache_set_sb,
+ metadata_replicas_num);
+ SET_CACHE_SET_META_REPLICAS_HAVE(cache_set_sb,
+ metadata_replicas_num);
+
if (data_replicas) {
- SET_CACHE_SET_DATA_REPLICAS_WANT(cache_set_sb,
+ data_replicas_num =
strtoul_or_die(data_replicas,
CACHE_SET_DATA_REPLICAS_WANT_MAX,
- "data replicas"));
+ "data replicas");
} else {
- SET_CACHE_SET_DATA_REPLICAS_WANT(cache_set_sb, 1);
+ data_replicas_num = 1;
}
+ SET_CACHE_SET_DATA_REPLICAS_WANT(cache_set_sb,
+ data_replicas_num);
+ SET_CACHE_SET_DATA_REPLICAS_HAVE(cache_set_sb,
+ data_replicas_num);
+
if (bdev == -1) {
fprintf(stderr, "Please specify -C or -B\n");
exit(EXIT_FAILURE);
backing_dev_fd[i] = dev_open(backing_devices[i], wipe_bcache);
write_cache_sbs(cache_dev_fd, cache_set_sb, block_size,
- bucket_sizes, num_bucket_sizes);
+ bucket_sizes, num_bucket_sizes, btree_node_size);
if (writeback)
cache_mode = CACHE_MODE_WRITEBACK;
{
char *err;
+ if (!args[0]) {
+ printf("Must provide a device name\n");
+ return -1;
+ }
+
err = remove_device(args[0], force_remove);
if (err) {
printf("bcache_rm_devices error: %s\n", err);
int bcache_list_cachesets(NihCommand *command, char *const *args)
{
char *err = NULL;
- err = list_cachesets(cset_dir, list_devs);
- if (err) {
- printf("bcache_list_cachesets error :%s\n", err);
- return -1;
+
+ if (internal_uuid) {
+ char uuid_path[MAX_PATH];
+ DIR *uuid_dir;
+ char buf[MAX_PATH];
+
+ snprintf(uuid_path, MAX_PATH, "%s/%s", cset_dir, internal_uuid);
+
+ err = "uuid does not exist";
+ if((uuid_dir = opendir(uuid_path)) == NULL)
+ goto err;
+
+ err = read_stat_dir(uuid_dir, uuid_path, "/internal/internal_uuid", buf);
+ if (err)
+ goto err;
+ printf("%s", buf);
+ return 0;
}
+ err = list_cachesets(cset_dir, list_devs);
+ if (err)
+ goto err;
+
return 0;
+
+err:
+ printf("bcache_list_cachesets error :%s\n", err);
+ return -1;
}
int bcache_query_devs(NihCommand *command, char *const *args)
char set_uuid_str[40], dev_uuid_str[40];
char *clus_uuid = (char *)sb->label;
- uuid_unparse(sb->set_uuid.b, set_uuid_str);
+ uuid_unparse(sb->user_uuid.b, set_uuid_str);
uuid_unparse(sb->disk_uuid.b, dev_uuid_str);
if (!strcmp(clus_uuid, ""))
clus_uuid = "None";
printf("Unable to find a superblock\n");
return -1;
} else {
- uuid_unparse(seq_sb->set_uuid.b, set_uuid);
+ uuid_unparse(seq_sb->user_uuid.b, set_uuid);
printf("%-50s%-15s%-4s\n", "uuid", "state", "tier");
}