diff --git a/include/spdk/vhost.h b/include/spdk/vhost.h index 02296e2d7..bc7cfc152 100644 --- a/include/spdk/vhost.h +++ b/include/spdk/vhost.h @@ -313,11 +313,12 @@ int spdk_vhost_scsi_dev_remove_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tg * \param dev_name bdev name to associate with this vhost device * \param readonly if set, all writes to the device will fail with * \c VIRTIO_BLK_S_IOERR error code. + * \param packed_ring this controller supports packed ring if set. * * \return 0 on success, negative errno on error. */ int spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_name, - bool readonly); + bool readonly, bool packed_ring); /** * Remove a vhost device. The device must not have any open connections on it's socket. diff --git a/lib/vhost/Makefile b/lib/vhost/Makefile index 1ad7e2e2c..e79ac31e7 100644 --- a/lib/vhost/Makefile +++ b/lib/vhost/Makefile @@ -34,7 +34,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -SO_VER := 2 +SO_VER := 3 SO_MINOR := 0 SO_SUFFIX := $(SO_VER).$(SO_MINOR) diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 8b145eb05..b4f7d473b 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -1158,6 +1158,7 @@ vhost_blk_controller_construct(void) char *cpumask; char *name; bool readonly; + bool packed_ring; for (sp = spdk_conf_first_section(NULL); sp != NULL; sp = spdk_conf_next_section(sp)) { if (!spdk_conf_section_match_prefix(sp, "VhostBlk")) { @@ -1178,13 +1179,15 @@ vhost_blk_controller_construct(void) cpumask = spdk_conf_section_get_val(sp, "Cpumask"); readonly = spdk_conf_section_get_boolval(sp, "ReadOnly", false); + packed_ring = spdk_conf_section_get_boolval(sp, "PackedRing", false); bdev_name = spdk_conf_section_get_val(sp, "Dev"); if (bdev_name == NULL) { continue; } - if (spdk_vhost_blk_construct(name, cpumask, bdev_name, readonly) < 0) { + if (spdk_vhost_blk_construct(name, cpumask, bdev_name, + readonly, packed_ring) < 0) { return -1; } } @@ -1193,7 +1196,8 @@ vhost_blk_controller_construct(void) } int -spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_name, bool readonly) +spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_name, + bool readonly, bool packed_ring) { struct spdk_vhost_blk_dev *bvdev = NULL; struct spdk_vhost_dev *vdev; @@ -1220,6 +1224,8 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_ vdev->disabled_features = SPDK_VHOST_BLK_DISABLED_FEATURES; vdev->protocol_features = SPDK_VHOST_BLK_PROTOCOL_FEATURES; + vdev->virtio_features |= (uint64_t)packed_ring << VIRTIO_F_RING_PACKED; + if (spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_UNMAP)) { vdev->virtio_features |= (1ULL << VIRTIO_BLK_F_DISCARD); } diff --git a/lib/vhost/vhost_rpc.c b/lib/vhost/vhost_rpc.c index da2f28d21..79d5ce089 100644 --- a/lib/vhost/vhost_rpc.c +++ b/lib/vhost/vhost_rpc.c @@ -242,6 +242,7 @@ struct rpc_vhost_blk_ctrlr { char *dev_name; char *cpumask; bool readonly; + bool packed_ring; }; static const struct spdk_json_object_decoder rpc_construct_vhost_blk_ctrlr[] = { @@ -249,6 +250,7 @@ static const struct spdk_json_object_decoder rpc_construct_vhost_blk_ctrlr[] = { {"dev_name", offsetof(struct rpc_vhost_blk_ctrlr, dev_name), spdk_json_decode_string }, {"cpumask", offsetof(struct rpc_vhost_blk_ctrlr, cpumask), spdk_json_decode_string, true}, {"readonly", offsetof(struct rpc_vhost_blk_ctrlr, readonly), spdk_json_decode_bool, true}, + {"packed_ring", offsetof(struct rpc_vhost_blk_ctrlr, packed_ring), spdk_json_decode_bool, true}, }; static void @@ -275,7 +277,8 @@ spdk_rpc_vhost_create_blk_controller(struct spdk_jsonrpc_request *request, goto invalid; } - rc = spdk_vhost_blk_construct(req.ctrlr, req.cpumask, req.dev_name, req.readonly); + rc = spdk_vhost_blk_construct(req.ctrlr, req.cpumask, req.dev_name, + req.readonly, req.packed_ring); if (rc < 0) { goto invalid; } diff --git a/scripts/rpc.py b/scripts/rpc.py index 74f6c59aa..255d3906a 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -1993,7 +1993,8 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse ctrlr=args.ctrlr, dev_name=args.dev_name, cpumask=args.cpumask, - readonly=args.readonly) + readonly=args.readonly, + packed_ring=args.packed_ring) p = subparsers.add_parser('vhost_create_blk_controller', aliases=['construct_vhost_blk_controller'], @@ -2002,6 +2003,7 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse p.add_argument('dev_name', help='device name') p.add_argument('--cpumask', help='cpu mask for this controller') p.add_argument("-r", "--readonly", action='store_true', help='Set controller as read-only') + p.add_argument("-p", "--packed_ring", action='store_true', help='Set controller as packed ring supported') p.set_defaults(func=vhost_create_blk_controller) def vhost_create_nvme_controller(args): diff --git a/scripts/rpc/vhost.py b/scripts/rpc/vhost.py index dbf5f939c..b2e0a846c 100644 --- a/scripts/rpc/vhost.py +++ b/scripts/rpc/vhost.py @@ -97,13 +97,14 @@ def vhost_nvme_controller_add_ns(client, ctrlr, bdev_name): @deprecated_alias('construct_vhost_blk_controller') -def vhost_create_blk_controller(client, ctrlr, dev_name, cpumask=None, readonly=None): +def vhost_create_blk_controller(client, ctrlr, dev_name, cpumask=None, readonly=None, packed_ring=None): """Create vhost BLK controller. Args: ctrlr: controller name dev_name: device name to add to controller cpumask: cpu mask for this controller readonly: set controller as read-only + packed_ring: support controller packed_ring """ params = { 'ctrlr': ctrlr, @@ -113,6 +114,8 @@ def vhost_create_blk_controller(client, ctrlr, dev_name, cpumask=None, readonly= params['cpumask'] = cpumask if readonly: params['readonly'] = readonly + if packed_ring: + params['packed_ring'] = packed_ring return client.call('vhost_create_blk_controller', params)