Commit 0e46c8f6 authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Jim Harris
Browse files

vhost: allow allocating per-session context data



Sessions are allocated internally by the core vhost
library whenever DPDK accepts a new connection, so
the only reasonable way to store additional per-sesion
data is to tell the core vhost library how much extra
memory it needs to allocate. Hence, we add a new field
to the vhost device backend struct.

Change-Id: Id6c8285505b2e610e28e5d985aceb271ed232555
Signed-off-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/437778


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
parent aab24255
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1282,7 +1282,8 @@ new_connection(int vid)
		return -1;
	}

	vsession = spdk_dma_zmalloc(sizeof(struct spdk_vhost_session),
	vsession = spdk_dma_zmalloc(sizeof(struct spdk_vhost_session) +
				    vdev->backend->session_ctx_size,
				    SPDK_CACHE_LINE_SIZE, NULL);
	if (vsession == NULL) {
		SPDK_ERRLOG("spdk_dma_zmalloc failed\n");
+1 −0
Original line number Diff line number Diff line
@@ -832,6 +832,7 @@ static const struct spdk_vhost_dev_backend vhost_blk_device_backend = {
	(1ULL << VIRTIO_BLK_F_RO) | (1ULL << VIRTIO_BLK_F_FLUSH) | (1ULL << VIRTIO_BLK_F_CONFIG_WCE) |
	(1ULL << VIRTIO_BLK_F_BARRIER) | (1ULL << VIRTIO_BLK_F_SCSI) | (1ULL << VIRTIO_BLK_F_DISCARD) |
	(1ULL << VIRTIO_BLK_F_WRITE_ZEROES),
	.session_ctx_size = 0,
	.start_device =  spdk_vhost_blk_start,
	.stop_device = spdk_vhost_blk_stop,
	.vhost_get_config = spdk_vhost_blk_get_config,
+6 −0
Original line number Diff line number Diff line
@@ -115,6 +115,12 @@ struct spdk_vhost_dev_backend {
	uint64_t virtio_features;
	uint64_t disabled_features;

	/**
	 * Size of additional per-session context data
	 * allocated whenever a new client connects.
	 */
	size_t session_ctx_size;

	/**
	 * Callbacks for starting and pausing the device.
	 * The first param is struct spdk_vhost_dev *.
+1 −0
Original line number Diff line number Diff line
@@ -1249,6 +1249,7 @@ spdk_vhost_nvme_write_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_
}

static const struct spdk_vhost_dev_backend spdk_vhost_nvme_device_backend = {
	.session_ctx_size = 0,
	.start_device = spdk_vhost_nvme_start_device,
	.stop_device = spdk_vhost_nvme_stop_device,
	.dump_info_json = spdk_vhost_nvme_dump_info_json,
+1 −0
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ static int spdk_vhost_scsi_dev_remove(struct spdk_vhost_dev *vdev);
const struct spdk_vhost_dev_backend spdk_vhost_scsi_device_backend = {
	.virtio_features = SPDK_VHOST_SCSI_FEATURES,
	.disabled_features = SPDK_VHOST_SCSI_DISABLED_FEATURES,
	.session_ctx_size = 0,
	.start_device =  spdk_vhost_scsi_start,
	.stop_device = spdk_vhost_scsi_stop,
	.dump_info_json = spdk_vhost_scsi_dump_info_json,