From e9d400d5b9231c403f78a7b8373d67c883ac20ea Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Thu, 28 Mar 2019 11:25:48 -0700 Subject: [PATCH] blobfs: Change channel type for synchronous operations In the next step, this won't be a channel at all. Change-Id: Ia8fe4da5b0b283e8dfc5c6477b84cfdd346d89a0 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/449464 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- include/spdk/blobfs.h | 65 ++++++++++-------- lib/blobfs/blobfs.c | 66 +++++++++++-------- lib/rocksdb/env_spdk.cc | 4 +- test/blobfs/fuse/fuse.c | 6 +- .../blobfs/blobfs_async_ut/blobfs_async_ut.c | 6 +- .../blobfs/blobfs_sync_ut/blobfs_sync_ut.c | 30 ++++----- 6 files changed, 99 insertions(+), 78 deletions(-) diff --git a/include/spdk/blobfs.h b/include/spdk/blobfs.h index 05d5d9990..7a166c8d7 100644 --- a/include/spdk/blobfs.h +++ b/include/spdk/blobfs.h @@ -176,15 +176,6 @@ void spdk_fs_unload(struct spdk_filesystem *fs, spdk_fs_op_complete cb_fn, void */ struct spdk_io_channel *spdk_fs_alloc_io_channel(struct spdk_filesystem *fs); -/** - * Allocate an I/O channel for synchronous operations. - * - * \param fs Blobstore filesystem to allocate I/O channel. - * - * \return a pointer to the I/O channel on success or NULL otherwise. - */ -struct spdk_io_channel *spdk_fs_alloc_io_channel_sync(struct spdk_filesystem *fs); - /** * Free I/O channel. * @@ -195,18 +186,34 @@ struct spdk_io_channel *spdk_fs_alloc_io_channel_sync(struct spdk_filesystem *fs */ void spdk_fs_free_io_channel(struct spdk_io_channel *channel); +/** + * Allocate a context for synchronous operations. + * + * \param fs Blobstore filesystem for this context. + * + * \return a pointer to the context on success or NULL otherwise. + */ +struct spdk_fs_thread_ctx *spdk_fs_alloc_thread_ctx(struct spdk_filesystem *fs); + +/** + * Free thread context. + * + * \param ctx Thread context to free. + */ +void spdk_fs_free_thread_ctx(struct spdk_fs_thread_ctx *ctx); + /** * Get statistics about the file including the underlying blob id and the file size. * * \param fs Blobstore filesystem. - * \param channel The I/O channel used to allocate file request. + * \param ctx The thread context for this operation * \param name The file name used to look up the matched file in the blobstore filesystem. * \param stat Caller allocated structure to store the obtained information about * this file. * * \return 0 on success, negative errno on failure. */ -int spdk_fs_file_stat(struct spdk_filesystem *fs, struct spdk_io_channel *channel, +int spdk_fs_file_stat(struct spdk_filesystem *fs, struct spdk_fs_thread_ctx *ctx, const char *name, struct spdk_file_stat *stat); #define SPDK_BLOBFS_OPEN_CREATE (1ULL << 0) @@ -215,37 +222,37 @@ int spdk_fs_file_stat(struct spdk_filesystem *fs, struct spdk_io_channel *channe * Create a new file on the given blobstore filesystem. * * \param fs Blobstore filesystem. - * \param channel The I/O channel used to allocate file request. + * \param ctx The thread context for this operation * \param name The file name for this new file. * * \return 0 on success, negative errno on failure. */ -int spdk_fs_create_file(struct spdk_filesystem *fs, struct spdk_io_channel *channel, +int spdk_fs_create_file(struct spdk_filesystem *fs, struct spdk_fs_thread_ctx *ctx, const char *name); /** * Open the file. * * \param fs Blobstore filesystem. - * \param channel The I/O channel used to allocate file request. + * \param ctx The thread context for this operation * \param name The file name used to look up the matched file in the blobstore filesystem. * \param flags This flags will be used to control the open mode. * \param file It will point to the open file if sccessful or NULL otherwirse. * * \return 0 on success, negative errno on failure. */ -int spdk_fs_open_file(struct spdk_filesystem *fs, struct spdk_io_channel *channel, +int spdk_fs_open_file(struct spdk_filesystem *fs, struct spdk_fs_thread_ctx *ctx, const char *name, uint32_t flags, struct spdk_file **file); /** * Close the file. * * \param file File to close. - * \param channel The I/O channel used to allocate file request. + * \param ctx The thread context for this operation * * \return 0 on success, negative errno on failure. */ -int spdk_file_close(struct spdk_file *file, struct spdk_io_channel *channel); +int spdk_file_close(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx); /** * Change the file name. @@ -254,25 +261,25 @@ int spdk_file_close(struct spdk_file *file, struct spdk_io_channel *channel); * same name. * * \param fs Blobstore filesystem. - * \param channel The I/O channel used to allocate file request. + * \param ctx The thread context for this operation * \param old_name Old name of the file. * \param new_name New name of the file. * * \return 0 on success, negative errno on failure. */ -int spdk_fs_rename_file(struct spdk_filesystem *fs, struct spdk_io_channel *channel, +int spdk_fs_rename_file(struct spdk_filesystem *fs, struct spdk_fs_thread_ctx *ctx, const char *old_name, const char *new_name); /** * Delete the file. * * \param fs Blobstore filesystem. - * \param channel The I/O channel used to allocate file request. + * \param ctx The thread context for this operation * \param name The name of the file to be deleted. * * \return 0 on success, negative errno on failure. */ -int spdk_fs_delete_file(struct spdk_filesystem *fs, struct spdk_io_channel *channel, +int spdk_fs_delete_file(struct spdk_filesystem *fs, struct spdk_fs_thread_ctx *ctx, const char *name); /** @@ -299,12 +306,12 @@ spdk_fs_iter spdk_fs_iter_next(spdk_fs_iter iter); * Truncate the file. * * \param file File to truncate. - * \param channel The I/O channel used to allocate file request. + * \param ctx The thread context for this operation * \param length New size in bytes of the file. * * \return 0 on success, negative errno on failure. */ -int spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *channel, +int spdk_file_truncate(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx, uint64_t length); /** @@ -329,28 +336,28 @@ uint64_t spdk_file_get_length(struct spdk_file *file); * Write data to the given file. * * \param file File to write. - * \param channel The I/O channel used to allocate file request. + * \param ctx The thread context for this operation * \param payload The specified buffer which should contain the data to be transmitted. * \param offset The beginning position to write data. * \param length The size in bytes of data to write. * * \return 0 on success, negative errno on failure. */ -int spdk_file_write(struct spdk_file *file, struct spdk_io_channel *channel, +int spdk_file_write(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx, void *payload, uint64_t offset, uint64_t length); /** * Read data to user buffer from the given file. * * \param file File to read. - * \param channel The I/O channel used to allocate file request. + * \param ctx The thread context for this operation * \param payload The specified buffer which will store the obtained data. * \param offset The beginning position to read. * \param length The size in bytes of data to read. * * \return the end position of this read operation on success, negated errno on failure. */ -int64_t spdk_file_read(struct spdk_file *file, struct spdk_io_channel *channel, +int64_t spdk_file_read(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx, void *payload, uint64_t offset, uint64_t length); /** @@ -382,11 +389,11 @@ void spdk_file_set_priority(struct spdk_file *file, uint32_t priority); * Synchronize the data from the cache to the disk. * * \param file File to sync. - * \param channel The I/O channel used to allocate file request. + * \param ctx The thread context for this operation * * \return 0 on success. */ -int spdk_file_sync(struct spdk_file *file, struct spdk_io_channel *channel); +int spdk_file_sync(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx); /** * Get the unique ID for the file. diff --git a/lib/blobfs/blobfs.c b/lib/blobfs/blobfs.c index 58fffbe19..50703fd66 100644 --- a/lib/blobfs/blobfs.c +++ b/lib/blobfs/blobfs.c @@ -254,6 +254,12 @@ struct spdk_fs_channel { pthread_spinlock_t lock; }; +/* For now, this is effectively an alias. But eventually we'll shift + * some data members over. */ +struct spdk_fs_thread_ctx { + struct spdk_fs_channel ch; +}; + static struct spdk_fs_request * alloc_fs_request(struct spdk_fs_channel *channel) { @@ -849,10 +855,10 @@ __file_stat(void *arg) } int -spdk_fs_file_stat(struct spdk_filesystem *fs, struct spdk_io_channel *_channel, +spdk_fs_file_stat(struct spdk_filesystem *fs, struct spdk_fs_thread_ctx *ctx, const char *name, struct spdk_file_stat *stat) { - struct spdk_fs_channel *channel = spdk_io_channel_get_ctx(_channel); + struct spdk_fs_channel *channel = (struct spdk_fs_channel *)ctx; struct spdk_fs_request *req; int rc; @@ -1003,9 +1009,9 @@ __fs_create_file(void *arg) } int -spdk_fs_create_file(struct spdk_filesystem *fs, struct spdk_io_channel *_channel, const char *name) +spdk_fs_create_file(struct spdk_filesystem *fs, struct spdk_fs_thread_ctx *ctx, const char *name) { - struct spdk_fs_channel *channel = spdk_io_channel_get_ctx(_channel); + struct spdk_fs_channel *channel = (struct spdk_fs_channel *)ctx; struct spdk_fs_request *req; struct spdk_fs_cb_args *args; int rc; @@ -1148,10 +1154,10 @@ __fs_open_file(void *arg) } int -spdk_fs_open_file(struct spdk_filesystem *fs, struct spdk_io_channel *_channel, +spdk_fs_open_file(struct spdk_filesystem *fs, struct spdk_fs_thread_ctx *ctx, const char *name, uint32_t flags, struct spdk_file **file) { - struct spdk_fs_channel *channel = spdk_io_channel_get_ctx(_channel); + struct spdk_fs_channel *channel = (struct spdk_fs_channel *)ctx; struct spdk_fs_request *req; struct spdk_fs_cb_args *args; int rc; @@ -1288,10 +1294,10 @@ __fs_rename_file(void *arg) } int -spdk_fs_rename_file(struct spdk_filesystem *fs, struct spdk_io_channel *_channel, +spdk_fs_rename_file(struct spdk_filesystem *fs, struct spdk_fs_thread_ctx *ctx, const char *old_name, const char *new_name) { - struct spdk_fs_channel *channel = spdk_io_channel_get_ctx(_channel); + struct spdk_fs_channel *channel = (struct spdk_fs_channel *)ctx; struct spdk_fs_request *req; struct spdk_fs_cb_args *args; int rc; @@ -1396,10 +1402,10 @@ __fs_delete_file(void *arg) } int -spdk_fs_delete_file(struct spdk_filesystem *fs, struct spdk_io_channel *_channel, +spdk_fs_delete_file(struct spdk_filesystem *fs, struct spdk_fs_thread_ctx *ctx, const char *name) { - struct spdk_fs_channel *channel = spdk_io_channel_get_ctx(_channel); + struct spdk_fs_channel *channel = (struct spdk_fs_channel *)ctx; struct spdk_fs_request *req; struct spdk_fs_cb_args *args; int rc; @@ -1545,10 +1551,10 @@ __truncate(void *arg) } int -spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *_channel, +spdk_file_truncate(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx, uint64_t length) { - struct spdk_fs_channel *channel = spdk_io_channel_get_ctx(_channel); + struct spdk_fs_channel *channel = (struct spdk_fs_channel *)ctx; struct spdk_fs_request *req; struct spdk_fs_cb_args *args; int rc; @@ -1723,8 +1729,14 @@ spdk_fs_alloc_io_channel(struct spdk_filesystem *fs) return io_channel; } -struct spdk_io_channel * -spdk_fs_alloc_io_channel_sync(struct spdk_filesystem *fs) +void +spdk_fs_free_io_channel(struct spdk_io_channel *channel) +{ + spdk_put_io_channel(channel); +} + +struct spdk_fs_thread_ctx * +spdk_fs_alloc_thread_ctx(struct spdk_filesystem *fs) { struct spdk_io_channel *io_channel; struct spdk_fs_channel *fs_channel; @@ -1735,13 +1747,15 @@ spdk_fs_alloc_io_channel_sync(struct spdk_filesystem *fs) fs_channel->sync = 1; pthread_spin_init(&fs_channel->lock, 0); - return io_channel; + /* These two types are currently equivalent */ + return (struct spdk_fs_thread_ctx *)fs_channel; } + void -spdk_fs_free_io_channel(struct spdk_io_channel *channel) +spdk_fs_free_thread_ctx(struct spdk_fs_thread_ctx *ctx) { - spdk_put_io_channel(channel); + spdk_put_io_channel(spdk_io_channel_from_ctx(ctx)); } void @@ -2120,10 +2134,10 @@ __send_rw_from_file(struct spdk_file *file, sem_t *sem, void *payload, } int -spdk_file_write(struct spdk_file *file, struct spdk_io_channel *_channel, +spdk_file_write(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx, void *payload, uint64_t offset, uint64_t length) { - struct spdk_fs_channel *channel = spdk_io_channel_get_ctx(_channel); + struct spdk_fs_channel *channel = (struct spdk_fs_channel *)ctx; struct spdk_fs_cb_args *args; uint64_t rem_length, copy, blob_size, cluster_sz; uint32_t cache_buffers_filled = 0; @@ -2334,10 +2348,10 @@ __file_read(struct spdk_file *file, void *payload, uint64_t offset, uint64_t len } int64_t -spdk_file_read(struct spdk_file *file, struct spdk_io_channel *_channel, +spdk_file_read(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx, void *payload, uint64_t offset, uint64_t length) { - struct spdk_fs_channel *channel = spdk_io_channel_get_ctx(_channel); + struct spdk_fs_channel *channel = (struct spdk_fs_channel *)ctx; uint64_t final_offset, final_length; uint32_t sub_reads = 0; int rc = 0; @@ -2443,9 +2457,9 @@ _file_sync(struct spdk_file *file, struct spdk_fs_channel *channel, } int -spdk_file_sync(struct spdk_file *file, struct spdk_io_channel *_channel) +spdk_file_sync(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx) { - struct spdk_fs_channel *channel = spdk_io_channel_get_ctx(_channel); + struct spdk_fs_channel *channel = (struct spdk_fs_channel *)ctx; struct spdk_fs_cb_args args = {}; args.sem = &channel->sem; @@ -2559,9 +2573,9 @@ __file_close(void *arg) } int -spdk_file_close(struct spdk_file *file, struct spdk_io_channel *_channel) +spdk_file_close(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx) { - struct spdk_fs_channel *channel = spdk_io_channel_get_ctx(_channel); + struct spdk_fs_channel *channel = (struct spdk_fs_channel *)ctx; struct spdk_fs_request *req; struct spdk_fs_cb_args *args; @@ -2572,7 +2586,7 @@ spdk_file_close(struct spdk_file *file, struct spdk_io_channel *_channel) args = &req->args; - spdk_file_sync(file, _channel); + spdk_file_sync(file, ctx); BLOBFS_TRACE(file, "name=%s\n", file->name); args->file = file; args->sem = &channel->sem; diff --git a/lib/rocksdb/env_spdk.cc b/lib/rocksdb/env_spdk.cc index 8c0af7d58..0950c1dc8 100644 --- a/lib/rocksdb/env_spdk.cc +++ b/lib/rocksdb/env_spdk.cc @@ -59,7 +59,7 @@ std::string g_bdev_name; volatile bool g_spdk_ready = false; volatile bool g_spdk_start_failure = false; struct sync_args { - struct spdk_io_channel *channel; + struct spdk_fs_thread_ctx *channel; }; __thread struct sync_args g_sync_args; @@ -586,7 +586,7 @@ void SpdkInitializeThread(void) if (g_fs != NULL) { thread = spdk_thread_create("spdk_rocksdb"); spdk_set_thread(thread); - g_sync_args.channel = spdk_fs_alloc_io_channel_sync(g_fs); + g_sync_args.channel = spdk_fs_alloc_thread_ctx(g_fs); } } diff --git a/test/blobfs/fuse/fuse.c b/test/blobfs/fuse/fuse.c index 7e1ff6d24..3401aabb2 100644 --- a/test/blobfs/fuse/fuse.c +++ b/test/blobfs/fuse/fuse.c @@ -51,7 +51,7 @@ pthread_t g_fuse_thread; struct spdk_bs_dev *g_bs_dev; struct spdk_filesystem *g_fs; -struct spdk_io_channel *g_channel; +struct spdk_fs_thread_ctx *g_channel; struct spdk_file *g_file; int g_fserrno; int g_fuse_argc = 0; @@ -292,7 +292,7 @@ init_cb(void *ctx, struct spdk_filesystem *fs, int fserrno) struct spdk_event *event; g_fs = fs; - g_channel = spdk_fs_alloc_io_channel_sync(g_fs); + g_channel = spdk_fs_alloc_thread_ctx(g_fs); event = spdk_event_allocate(1, start_fuse_fn, NULL, NULL); spdk_event_call(event); } @@ -309,7 +309,7 @@ shutdown_cb(void *ctx, int fserrno) { fuse_session_exit(fuse_get_session(g_fuse)); pthread_kill(g_fuse_thread, SIGINT); - spdk_fs_free_io_channel(g_channel); + spdk_fs_free_thread_ctx(g_channel); spdk_app_stop(0); } diff --git a/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c b/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c index 8c5ae9363..947f75fbc 100644 --- a/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c +++ b/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c @@ -485,7 +485,7 @@ channel_ops_sync(void) { struct spdk_filesystem *fs; struct spdk_bs_dev *dev; - struct spdk_io_channel *channel; + struct spdk_fs_thread_ctx *channel; dev = init_dev(); @@ -496,10 +496,10 @@ channel_ops_sync(void) fs = g_fs; SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); - channel = spdk_fs_alloc_io_channel_sync(fs); + channel = spdk_fs_alloc_thread_ctx(fs); CU_ASSERT(channel != NULL); - spdk_fs_free_io_channel(channel); + spdk_fs_free_thread_ctx(channel); g_fserrno = 1; spdk_fs_unload(fs, fs_op_complete, NULL); diff --git a/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c b/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c index 14e1d6e18..dafc365dd 100644 --- a/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c +++ b/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c @@ -151,11 +151,11 @@ cache_write(void) uint64_t length; int rc; char buf[100]; - struct spdk_io_channel *channel; + struct spdk_fs_thread_ctx *channel; ut_send_request(_fs_init, NULL); - channel = spdk_fs_alloc_io_channel_sync(g_fs); + channel = spdk_fs_alloc_thread_ctx(g_fs); rc = spdk_fs_open_file(g_fs, channel, "testfile", SPDK_BLOBFS_OPEN_CREATE, &g_file); CU_ASSERT(rc == 0); @@ -179,7 +179,7 @@ cache_write(void) rc = spdk_fs_delete_file(g_fs, channel, "testfile"); CU_ASSERT(rc == -ENOENT); - spdk_fs_free_io_channel(channel); + spdk_fs_free_thread_ctx(channel); ut_send_request(_fs_unload, NULL); } @@ -189,12 +189,12 @@ cache_write_null_buffer(void) { uint64_t length; int rc; - struct spdk_io_channel *channel; + struct spdk_fs_thread_ctx *channel; struct spdk_thread *thread; ut_send_request(_fs_init, NULL); - channel = spdk_fs_alloc_io_channel_sync(g_fs); + channel = spdk_fs_alloc_thread_ctx(g_fs); rc = spdk_fs_open_file(g_fs, channel, "testfile", SPDK_BLOBFS_OPEN_CREATE, &g_file); CU_ASSERT(rc == 0); @@ -211,7 +211,7 @@ cache_write_null_buffer(void) rc = spdk_fs_delete_file(g_fs, channel, "testfile"); CU_ASSERT(rc == 0); - spdk_fs_free_io_channel(channel); + spdk_fs_free_thread_ctx(channel); thread = spdk_get_thread(); while (spdk_thread_poll(thread, 0, 0) > 0) {} @@ -223,12 +223,12 @@ static void fs_create_sync(void) { int rc; - struct spdk_io_channel *channel; + struct spdk_fs_thread_ctx *channel; struct spdk_thread *thread; ut_send_request(_fs_init, NULL); - channel = spdk_fs_alloc_io_channel_sync(g_fs); + channel = spdk_fs_alloc_thread_ctx(g_fs); CU_ASSERT(channel != NULL); rc = spdk_fs_create_file(g_fs, channel, "testfile"); @@ -241,7 +241,7 @@ fs_create_sync(void) rc = spdk_fs_delete_file(g_fs, channel, "testfile"); CU_ASSERT(rc == 0); - spdk_fs_free_io_channel(channel); + spdk_fs_free_thread_ctx(channel); thread = spdk_get_thread(); while (spdk_thread_poll(thread, 0, 0) > 0) {} @@ -254,12 +254,12 @@ cache_append_no_cache(void) { int rc; char buf[100]; - struct spdk_io_channel *channel; + struct spdk_fs_thread_ctx *channel; struct spdk_thread *thread; ut_send_request(_fs_init, NULL); - channel = spdk_fs_alloc_io_channel_sync(g_fs); + channel = spdk_fs_alloc_thread_ctx(g_fs); rc = spdk_fs_open_file(g_fs, channel, "testfile", SPDK_BLOBFS_OPEN_CREATE, &g_file); CU_ASSERT(rc == 0); @@ -282,7 +282,7 @@ cache_append_no_cache(void) rc = spdk_fs_delete_file(g_fs, channel, "testfile"); CU_ASSERT(rc == 0); - spdk_fs_free_io_channel(channel); + spdk_fs_free_thread_ctx(channel); thread = spdk_get_thread(); while (spdk_thread_poll(thread, 0, 0) > 0) {} @@ -294,12 +294,12 @@ static void fs_delete_file_without_close(void) { int rc; - struct spdk_io_channel *channel; + struct spdk_fs_thread_ctx *channel; struct spdk_file *file; struct spdk_thread *thread; ut_send_request(_fs_init, NULL); - channel = spdk_fs_alloc_io_channel_sync(g_fs); + channel = spdk_fs_alloc_thread_ctx(g_fs); CU_ASSERT(channel != NULL); rc = spdk_fs_open_file(g_fs, channel, "testfile", SPDK_BLOBFS_OPEN_CREATE, &g_file); @@ -319,7 +319,7 @@ fs_delete_file_without_close(void) rc = spdk_fs_open_file(g_fs, channel, "testfile", 0, &file); CU_ASSERT(rc != 0); - spdk_fs_free_io_channel(channel); + spdk_fs_free_thread_ctx(channel); thread = spdk_get_thread(); while (spdk_thread_poll(thread, 0, 0) > 0) {}