Commit 2505b938 authored by Changpeng Liu's avatar Changpeng Liu Committed by Tomasz Zawadzki
Browse files

blobfs: remove _file_read() function



_file_read() is only be called in spdk_file_read() API, and we only
need to count the children IOs sent to the backend, and skip the IOs
which hit the cache buffer.

Change-Id: I36e4a464e5810beaf30f1b580dc15ea3d3a68582
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/667


Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 19d5c3ed
Loading
Loading
Loading
Loading
+29 −36
Original line number Diff line number Diff line
@@ -2569,39 +2569,6 @@ check_readahead(struct spdk_file *file, uint64_t offset,
	file->fs->send_request(__readahead, req);
}

static int
__file_read(struct spdk_file *file, void *payload, uint64_t offset, uint64_t length,
	    struct spdk_fs_channel *channel)
{
	struct cache_buffer *buf;
	int rc;

	buf = spdk_tree_find_filled_buffer(file->tree, offset);
	if (buf == NULL) {
		pthread_spin_unlock(&file->lock);
		rc = __send_rw_from_file(file, payload, offset, length, true, channel);
		pthread_spin_lock(&file->lock);
		return rc;
	}

	if ((offset + length) > (buf->offset + buf->bytes_filled)) {
		length = buf->offset + buf->bytes_filled - offset;
	}
	BLOBFS_TRACE(file, "read %p offset=%ju length=%ju\n", payload, offset, length);
	memcpy(payload, &buf->buf[offset - buf->offset], length);
	if ((offset + length) % CACHE_BUFFER_SIZE == 0) {
		pthread_spin_lock(&g_caches_lock);
		spdk_tree_remove_buffer(file->tree, buf);
		if (file->tree->present_mask == 0) {
			TAILQ_REMOVE(&g_caches, file, cache_tailq);
		}
		pthread_spin_unlock(&g_caches_lock);
	}

	sem_post(&channel->sem);
	return 0;
}

int64_t
spdk_file_read(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx,
	       void *payload, uint64_t offset, uint64_t length)
@@ -2609,6 +2576,8 @@ spdk_file_read(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx,
	struct spdk_fs_channel *channel = (struct spdk_fs_channel *)ctx;
	uint64_t final_offset, final_length;
	uint32_t sub_reads = 0;
	struct cache_buffer *buf;
	uint64_t read_len;
	int rc = 0;

	pthread_spin_lock(&file->lock);
@@ -2644,8 +2613,31 @@ spdk_file_read(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx,
			length = final_offset - offset;
		}

		buf = spdk_tree_find_filled_buffer(file->tree, offset);
		if (buf == NULL) {
			pthread_spin_unlock(&file->lock);
			rc = __send_rw_from_file(file, payload, offset, length, true, channel);
			pthread_spin_lock(&file->lock);
			if (rc == 0) {
				sub_reads++;
		rc = __file_read(file, payload, offset, length, channel);
			}
		} else {
			read_len = length;
			if ((offset + length) > (buf->offset + buf->bytes_filled)) {
				read_len = buf->offset + buf->bytes_filled - offset;
			}
			BLOBFS_TRACE(file, "read %p offset=%ju length=%ju\n", payload, offset, read_len);
			memcpy(payload, &buf->buf[offset - buf->offset], read_len);
			if ((offset + read_len) % CACHE_BUFFER_SIZE == 0) {
				pthread_spin_lock(&g_caches_lock);
				spdk_tree_remove_buffer(file->tree, buf);
				if (file->tree->present_mask == 0) {
					TAILQ_REMOVE(&g_caches, file, cache_tailq);
				}
				pthread_spin_unlock(&g_caches_lock);
			}
		}

		if (rc == 0) {
			final_length += length;
		} else {
@@ -2655,8 +2647,9 @@ spdk_file_read(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx,
		offset += length;
	}
	pthread_spin_unlock(&file->lock);
	while (sub_reads-- > 0) {
	while (sub_reads > 0) {
		sem_wait(&channel->sem);
		sub_reads--;
	}
	if (rc == 0) {
		return final_length;