bdev/virtio/rpc: add RPC to attach virtio-pci device

`rpc.py construct_virtio_pci_scsi_bdev <bdf> <name>`

The RPC internals reuse the struct definition and callback
functions from virtio-user equivalents

Change-Id: I0c6c49d8481565a49ec9460a633696d27d55367a
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/394447
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2018-01-11 20:55:03 +01:00 committed by Jim Harris
parent 2bbc59fa79
commit 0d6a37c7d9
2 changed files with 67 additions and 0 deletions

View File

@ -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;

View File

@ -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: <name>t<target_id>""")
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)