Commit a94accab authored by Ben Walker's avatar Ben Walker Committed by Jim Harris
Browse files

bdev: Begin encapsulating spdk_bdev_io



This begins the process of hiding data members in
spdk_bdev_io that don't need to be accessed from
within bdev modules.

One strategy would be to implement accessors for
every data member in the structure. However, that
may have negative performance effects. Instead,
create a new internal structure within the old
structure. This new structure will still be visible
for now, but at least makes clear which members
are accessible and which are not.

This patch shifts one data member to the new structure
as an example.

Change-Id: I68525db995325732fe9f5fc3f45b06920948309b
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/412298


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent c6ae008d
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -407,15 +407,17 @@ struct spdk_bdev_io {
	/** Callback for when buf is allocated */
	spdk_bdev_io_get_buf_cb get_buf_cb;

	/** Entry to the list need_buf of struct spdk_bdev. */
	STAILQ_ENTRY(spdk_bdev_io) buf_link;

	/** Member used for linking child I/Os together. */
	TAILQ_ENTRY(spdk_bdev_io) link;

	/** It may be used by modules to put the bdev_io into its own list. */
	TAILQ_ENTRY(spdk_bdev_io) module_link;

	struct {
		/** Entry to the list need_buf of struct spdk_bdev. */
		STAILQ_ENTRY(spdk_bdev_io) buf_link;
	} internal;

	/**
	 * Per I/O context for use by the bdev module.
	 */
+8 −8
Original line number Diff line number Diff line
@@ -359,7 +359,7 @@ spdk_bdev_io_put_buf(struct spdk_bdev_io *bdev_io)
		spdk_mempool_put(pool, buf);
	} else {
		tmp = STAILQ_FIRST(stailq);
		STAILQ_REMOVE_HEAD(stailq, buf_link);
		STAILQ_REMOVE_HEAD(stailq, internal.buf_link);
		spdk_bdev_io_set_buf(tmp, buf);
	}
}
@@ -397,7 +397,7 @@ spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb, u
	buf = spdk_mempool_get(pool);

	if (!buf) {
		STAILQ_INSERT_TAIL(stailq, bdev_io, buf_link);
		STAILQ_INSERT_TAIL(stailq, bdev_io, internal.buf_link);
	} else {
		spdk_bdev_io_set_buf(bdev_io, buf);
	}
@@ -485,7 +485,7 @@ spdk_bdev_mgmt_channel_destroy(void *io_device, void *ctx_buf)

	while (!STAILQ_EMPTY(&ch->per_thread_cache)) {
		bdev_io = STAILQ_FIRST(&ch->per_thread_cache);
		STAILQ_REMOVE_HEAD(&ch->per_thread_cache, buf_link);
		STAILQ_REMOVE_HEAD(&ch->per_thread_cache, internal.buf_link);
		ch->per_thread_cache_count--;
		spdk_mempool_put(g_bdev_mgr.bdev_io_pool, (void *)bdev_io);
	}
@@ -820,7 +820,7 @@ spdk_bdev_get_io(struct spdk_bdev_channel *channel)

	if (ch->per_thread_cache_count > 0) {
		bdev_io = STAILQ_FIRST(&ch->per_thread_cache);
		STAILQ_REMOVE_HEAD(&ch->per_thread_cache, buf_link);
		STAILQ_REMOVE_HEAD(&ch->per_thread_cache, internal.buf_link);
		ch->per_thread_cache_count--;
	} else {
		bdev_io = spdk_mempool_get(g_bdev_mgr.bdev_io_pool);
@@ -844,7 +844,7 @@ spdk_bdev_put_io(struct spdk_bdev_io *bdev_io)

	if (ch->per_thread_cache_count < SPDK_BDEV_IO_CACHE_SIZE) {
		ch->per_thread_cache_count++;
		STAILQ_INSERT_TAIL(&ch->per_thread_cache, bdev_io, buf_link);
		STAILQ_INSERT_TAIL(&ch->per_thread_cache, bdev_io, internal.buf_link);
	} else {
		spdk_mempool_put(g_bdev_mgr.bdev_io_pool, (void *)bdev_io);
	}
@@ -1161,7 +1161,7 @@ spdk_bdev_channel_create(void *io_device, void *ctx_buf)

/*
 * Abort I/O that are waiting on a data buffer.  These types of I/O are
 *  linked using the spdk_bdev_io buf_link TAILQ_ENTRY.
 *  linked using the spdk_bdev_io internal.buf_link TAILQ_ENTRY.
 */
static void
_spdk_bdev_abort_buf_io(bdev_io_stailq_t *queue, struct spdk_bdev_channel *ch)
@@ -1173,11 +1173,11 @@ _spdk_bdev_abort_buf_io(bdev_io_stailq_t *queue, struct spdk_bdev_channel *ch)

	while (!STAILQ_EMPTY(queue)) {
		bdev_io = STAILQ_FIRST(queue);
		STAILQ_REMOVE_HEAD(queue, buf_link);
		STAILQ_REMOVE_HEAD(queue, internal.buf_link);
		if (bdev_io->ch == ch) {
			spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
		} else {
			STAILQ_INSERT_TAIL(&tmp, bdev_io, buf_link);
			STAILQ_INSERT_TAIL(&tmp, bdev_io, internal.buf_link);
		}
	}