blobfs: make the cluster size of blobfs configurable.

Change-Id: I26738d71316b8509cf8e98fee549a0745bb09bfa
Signed-off-by: Cunyin Chang <cunyin.chang@intel.com>
Reviewed-on: https://review.gerrithub.io/393715
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Cunyin Chang 2018-01-05 09:46:54 +08:00 committed by Ben Walker
parent b9252b1272
commit 6951b97964
5 changed files with 64 additions and 13 deletions

View File

@ -53,6 +53,10 @@ struct spdk_filesystem;
typedef struct spdk_file *spdk_fs_iter;
struct spdk_blobfs_opts {
uint32_t cluster_sz;
};
struct spdk_file_stat {
spdk_blob_id blobid;
uint64_t size;
@ -69,7 +73,10 @@ typedef void (*spdk_file_stat_op_complete)(void *ctx, struct spdk_file_stat *sta
typedef void (*fs_request_fn)(void *);
typedef void (*fs_send_request_fn)(fs_request_fn, void *);
void spdk_fs_init(struct spdk_bs_dev *dev, fs_send_request_fn send_request_fn,
/* Initialize an spdk_blobfs_opts structure to the default blobfs option values. */
void spdk_fs_opts_init(struct spdk_blobfs_opts *opts);
void spdk_fs_init(struct spdk_bs_dev *dev, struct spdk_blobfs_opts *opt,
fs_send_request_fn send_request_fn,
spdk_fs_op_with_handle_complete cb_fn, void *cb_arg);
void spdk_fs_load(struct spdk_bs_dev *dev, fs_send_request_fn send_request_fn,
spdk_fs_op_with_handle_complete cb_fn, void *cb_arg);

View File

@ -51,6 +51,7 @@
SPDK_DEBUGLOG(SPDK_LOG_BLOBFS_RW, "file=%s " str, file->name, ##args)
#define BLOBFS_CACHE_SIZE (4ULL * 1024 * 1024 * 1024)
#define SPDK_BLOBFS_OPTS_CLUSTER_SZ (1024 * 1024)
static uint64_t g_fs_cache_size = BLOBFS_CACHE_SIZE;
static struct spdk_mempool *g_cache_pool;
@ -200,6 +201,12 @@ struct spdk_fs_cb_args {
static void cache_free_buffers(struct spdk_file *file);
void
spdk_fs_opts_init(struct spdk_blobfs_opts *opts)
{
opts->cluster_sz = SPDK_BLOBFS_OPTS_CLUSTER_SZ;
}
static void
__initialize_cache(void)
{
@ -453,7 +460,8 @@ fs_alloc(struct spdk_bs_dev *dev, fs_send_request_fn send_request_fn)
}
void
spdk_fs_init(struct spdk_bs_dev *dev, fs_send_request_fn send_request_fn,
spdk_fs_init(struct spdk_bs_dev *dev, struct spdk_blobfs_opts *opt,
fs_send_request_fn send_request_fn,
spdk_fs_op_with_handle_complete cb_fn, void *cb_arg)
{
struct spdk_filesystem *fs;
@ -488,7 +496,9 @@ spdk_fs_init(struct spdk_bs_dev *dev, fs_send_request_fn send_request_fn,
spdk_bs_opts_init(&opts);
strncpy(opts.bstype.bstype, "BLOBFS", SPDK_BLOBSTORE_TYPE_LENGTH);
if (opt) {
opts.cluster_sz = opt->cluster_sz;
}
spdk_bs_init(dev, &opts, init_cb, req);
}

View File

@ -89,7 +89,7 @@ fs_init(void)
dev = init_dev();
spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0");
spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL);
spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL);
CU_ASSERT(g_fs != NULL);
CU_ASSERT(g_fserrno == 0);
fs = g_fs;
@ -133,7 +133,7 @@ fs_open(void)
memset(name, 'a', sizeof(name) - 1);
spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0");
spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL);
spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL);
CU_ASSERT(g_fs != NULL);
CU_ASSERT(g_fserrno == 0);
fs = g_fs;
@ -192,7 +192,7 @@ fs_create(void)
memset(name, 'a', sizeof(name) - 1);
spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0");
spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL);
spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL);
SPDK_CU_ASSERT_FATAL(g_fs != NULL);
CU_ASSERT(g_fserrno == 0);
fs = g_fs;
@ -231,7 +231,7 @@ fs_truncate(void)
dev = init_dev();
spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0");
spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL);
spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL);
SPDK_CU_ASSERT_FATAL(g_fs != NULL);
CU_ASSERT(g_fserrno == 0);
fs = g_fs;
@ -284,7 +284,7 @@ fs_rename(void)
dev = init_dev();
spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0");
spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL);
spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL);
SPDK_CU_ASSERT_FATAL(g_fs != NULL);
CU_ASSERT(g_fserrno == 0);
fs = g_fs;
@ -437,7 +437,7 @@ channel_ops(void)
dev = init_dev();
spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0");
spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL);
spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL);
SPDK_CU_ASSERT_FATAL(g_fs != NULL);
CU_ASSERT(g_fserrno == 0);
fs = g_fs;
@ -465,7 +465,7 @@ channel_ops_sync(void)
dev = init_dev();
spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0");
spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL);
spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL);
SPDK_CU_ASSERT_FATAL(g_fs != NULL);
CU_ASSERT(g_fserrno == 0);
fs = g_fs;

View File

@ -148,7 +148,7 @@ _fs_init(void *arg)
g_fs = NULL;
g_fserrno = -1;
dev = init_dev();
spdk_fs_init(dev, send_request, fs_op_with_handle_complete, NULL);
spdk_fs_init(dev, NULL, send_request, fs_op_with_handle_complete, NULL);
SPDK_CU_ASSERT_FATAL(g_fs != NULL);
CU_ASSERT(g_fserrno == 0);
}

View File

@ -38,9 +38,11 @@
#include "spdk/event.h"
#include "spdk/blob_bdev.h"
#include "spdk/log.h"
#include "spdk/string.h"
struct spdk_bs_dev *g_bs_dev;
const char *g_bdev_name;
static uint64_t g_cluster_size;
static void
stop_cb(void *ctx, int fserrno)
@ -70,6 +72,7 @@ static void
spdk_mkfs_run(void *arg1, void *arg2)
{
struct spdk_bdev *bdev;
struct spdk_blobfs_opts blobfs_opt;
bdev = spdk_bdev_get_by_name(g_bdev_name);
@ -81,8 +84,38 @@ spdk_mkfs_run(void *arg1, void *arg2)
printf("Initializing filesystem on bdev %s...", g_bdev_name);
fflush(stdout);
spdk_fs_opts_init(&blobfs_opt);
if (g_cluster_size) {
blobfs_opt.cluster_sz = g_cluster_size;
}
g_bs_dev = spdk_bdev_create_bs_dev(bdev, NULL, NULL);
spdk_fs_init(g_bs_dev, NULL, init_cb, NULL);
if (blobfs_opt.cluster_sz) {
spdk_fs_init(g_bs_dev, &blobfs_opt, NULL, init_cb, NULL);
} else {
spdk_fs_init(g_bs_dev, NULL, NULL, init_cb, NULL);
}
}
static void
mkfs_usage(void)
{
printf(" -C cluster size\n");
}
static void
mkfs_parse_arg(int ch, char *arg)
{
bool has_prefix;
switch (ch) {
case 'C':
spdk_parse_capacity(arg, &g_cluster_size, &has_prefix);
break;
default:
break;
}
}
int main(int argc, char **argv)
@ -102,8 +135,9 @@ int main(int argc, char **argv)
opts.shutdown_cb = NULL;
spdk_fs_set_cache_size(512);
g_bdev_name = argv[2];
spdk_app_parse_args(argc, argv, &opts, "C:", mkfs_parse_arg, mkfs_usage);
spdk_app_start(&opts, spdk_mkfs_run, NULL, NULL);
spdk_app_fini();