From 0d6a37c7d92b05d13b22420eea1a649127ca8a63 Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Thu, 11 Jan 2018 20:55:03 +0100 Subject: [PATCH] bdev/virtio/rpc: add RPC to attach virtio-pci device `rpc.py construct_virtio_pci_scsi_bdev ` The RPC internals reuse the struct definition and callback functions from virtio-user equivalents Change-Id: I0c6c49d8481565a49ec9460a633696d27d55367a Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/394447 Reviewed-by: Pawel Wodkowski Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris --- lib/bdev/virtio/bdev_virtio_rpc.c | 53 +++++++++++++++++++++++++++++++ scripts/rpc.py | 14 ++++++++ 2 files changed, 67 insertions(+) diff --git a/lib/bdev/virtio/bdev_virtio_rpc.c b/lib/bdev/virtio/bdev_virtio_rpc.c index 0911eab381..c7ce92bd73 100644 --- a/lib/bdev/virtio/bdev_virtio_rpc.c +++ b/lib/bdev/virtio/bdev_virtio_rpc.c @@ -42,6 +42,7 @@ struct rpc_construct_virtio_scsi_dev { char *path; + char *pci_address; char *name; uint32_t vq_count; uint32_t vq_size; @@ -64,6 +65,7 @@ free_rpc_construct_virtio_scsi_dev(struct rpc_construct_virtio_scsi_dev *req) } free(req->path); + free(req->pci_address); free(req->name); free(req); } @@ -110,6 +112,7 @@ spdk_rpc_create_virtio_user_scsi_bdev(struct spdk_jsonrpc_request *request, goto invalid; } + req->pci_address = NULL; req->vq_count = 1; req->vq_size = 512; @@ -136,6 +139,56 @@ invalid: } SPDK_RPC_REGISTER("construct_virtio_user_scsi_bdev", spdk_rpc_create_virtio_user_scsi_bdev); +static const struct spdk_json_object_decoder rpc_construct_virtio_pci_scsi_dev[] = { + {"pci_address", offsetof(struct rpc_construct_virtio_scsi_dev, pci_address), spdk_json_decode_string }, + {"name", offsetof(struct rpc_construct_virtio_scsi_dev, name), spdk_json_decode_string }, +}; + +static void +spdk_rpc_construct_virtio_pci_scsi_dev(struct spdk_jsonrpc_request *request, + const struct spdk_json_val *params) +{ + struct rpc_construct_virtio_scsi_dev *req; + struct spdk_pci_addr pci_addr; + int rc; + + req = calloc(1, sizeof(*req)); + if (!req) { + rc = -ENOMEM; + goto invalid; + } + + req->path = NULL; + + if (spdk_json_decode_object(params, rpc_construct_virtio_pci_scsi_dev, + SPDK_COUNTOF(rpc_construct_virtio_pci_scsi_dev), + req)) { + rc = -EINVAL; + goto invalid; + } + + if (spdk_pci_addr_parse(&pci_addr, req->pci_address) != 0) { + SPDK_ERRLOG("Invalid PCI address '%s'\n", req->pci_address); + rc = -EINVAL; + goto invalid; + } + + req->request = request; + rc = bdev_virtio_pci_scsi_dev_create(req->name, &pci_addr, + rpc_construct_virtio_scsi_dev_cb, req); + if (rc < 0) { + goto invalid; + } + + return; + +invalid: + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); + free_rpc_construct_virtio_scsi_dev(req); +} +SPDK_RPC_REGISTER("construct_virtio_pci_scsi_bdev", spdk_rpc_construct_virtio_pci_scsi_dev); + struct rpc_remove_virtio_scsi_dev { char *name; struct spdk_jsonrpc_request *request; diff --git a/scripts/rpc.py b/scripts/rpc.py index 711450edf5..0a01bd1213 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -868,6 +868,20 @@ p.add_argument('--vq-count', help='Number of virtual queues to be used.', type=i p.add_argument('--vq-size', help='Size of each queue', type=int) p.set_defaults(func=construct_virtio_user_scsi_bdev) +def construct_virtio_pci_scsi_bdev(args): + params = { + 'pci_address': args.pci_address, + 'name': args.name, + } + print_dict(jsonrpc_call('construct_virtio_pci_scsi_bdev', params)) + +p = subparsers.add_parser('construct_virtio_pci_scsi_bdev', help="""Create a Virtio SCSI device from a virtio-pci device.""") +p.add_argument('pci_address', help="""PCI address in domain:bus:device.function format or +domain.bus.device.function format""") +p.add_argument('name', help="""Name for the virtio device. +It will be inherited by all created bdevs, which are named in the following format: t""") +p.set_defaults(func=construct_virtio_pci_scsi_bdev) + def remove_virtio_scsi_bdev(args): params = {'name': args.name} jsonrpc_call('remove_virtio_scsi_bdev', params)