From 3732429c007467b3c246969721984669383909fe Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Thu, 11 Apr 2019 20:37:13 -0400 Subject: [PATCH] blobfs: allocate flush request before appending to cache buffer After the write data has been appended to cache buffer, the allocation of flush request can return error, so we move this allocation before appending to the cache buffer. Change-Id: Ia8baae8f3d88596561633bd8a5c4f83e554c72d7 Signed-off-by: Changpeng Liu Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/450981 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/blobfs/blobfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/blobfs/blobfs.c b/lib/blobfs/blobfs.c index 9b8ac4d72..133e4bacd 100644 --- a/lib/blobfs/blobfs.c +++ b/lib/blobfs/blobfs.c @@ -2195,6 +2195,12 @@ spdk_file_write(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx, } } + args = calloc(1, sizeof(*args)); + if (args == NULL) { + pthread_spin_unlock(&file->lock); + return -ENOMEM; + } + last = file->last; rem_length = length; cur_payload = payload; @@ -2217,6 +2223,7 @@ spdk_file_write(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx, last = cache_append_buffer(file); if (last == NULL) { BLOBFS_TRACE(file, "nomem\n"); + __free_args(args); pthread_spin_unlock(&file->lock); return -ENOMEM; } @@ -2226,14 +2233,10 @@ spdk_file_write(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx, pthread_spin_unlock(&file->lock); if (cache_buffers_filled == 0) { + __free_args(args); return 0; } - args = calloc(1, sizeof(*args)); - if (args == NULL) { - return -ENOMEM; - } - args->file = file; file->fs->send_request(__file_flush, args); return 0;