Commit 3732429c authored by Changpeng Liu's avatar Changpeng Liu Committed by Jim Harris
Browse files

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: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/450981


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent dd90ff7a
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -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;