Commit b3518196 authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Daniel Verkamp
Browse files

bdev/virtio/rpc: allow listing created devices



Listing them through get_bdevs is not enough. Some
devices might not have any LUNs presented while expecting
some to be hotplugged in the future.

```
$ rpc.py get_virtio_scsi_devs
[
  {
    "virtio": {
      "vq_count": 18,
      "type": "user",
      "socket": "/tmp/vhost.0",
      "vq_size": 512
    },
    "name": "VirtioScsi0"
  }
]
```

Change-Id: I56857d7a0637300beba39a8d83a98447f1f74ce7
Signed-off-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/405182


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 36506448
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -116,6 +116,13 @@ int bdev_virtio_pci_scsi_dev_create(const char *name, struct spdk_pci_addr *pci_
void bdev_virtio_scsi_dev_remove(const char *name,
				 bdev_virtio_remove_cb cb_fn, void *cb_arg);

/**
 * List all created Virtio-SCSI devices.
 *
 * \param write_ctx JSON context to write into
 */
void bdev_virtio_scsi_dev_list(struct spdk_json_write_ctx *write_ctx);

/**
 * Connect to a vhost-user Unix domain socket and create a Virtio BLK bdev.
 *
+22 −0
Original line number Diff line number Diff line
@@ -265,6 +265,28 @@ invalid:
}
SPDK_RPC_REGISTER("remove_virtio_scsi_bdev", spdk_rpc_remove_virtio_scsi_bdev);

static void
spdk_rpc_get_virtio_scsi_devs(struct spdk_jsonrpc_request *request,
			      const struct spdk_json_val *params)
{
	struct spdk_json_write_ctx *w;

	if (params != NULL) {
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
						 "get_virtio_scsi_devs requires no parameters");
		return;
	}

	w = spdk_jsonrpc_begin_result(request);
	if (w == NULL) {
		return;
	}

	bdev_virtio_scsi_dev_list(w);
	spdk_jsonrpc_end_result(request, w);
}
SPDK_RPC_REGISTER("get_virtio_scsi_devs", spdk_rpc_get_virtio_scsi_devs)

struct rpc_construct_virtio_blk_dev {
	char *path;
	char *pci_address;
+23 −0
Original line number Diff line number Diff line
@@ -1933,4 +1933,27 @@ bdev_virtio_scsi_dev_remove(const char *name, bdev_virtio_remove_cb cb_fn, void
	pthread_mutex_unlock(&g_virtio_scsi_mutex);
}

void
bdev_virtio_scsi_dev_list(struct spdk_json_write_ctx *w)
{
	struct virtio_scsi_dev *svdev;

	spdk_json_write_array_begin(w);

	pthread_mutex_lock(&g_virtio_scsi_mutex);
	TAILQ_FOREACH(svdev, &g_virtio_scsi_devs, tailq) {
		spdk_json_write_object_begin(w);

		spdk_json_write_name(w, "name");
		spdk_json_write_string(w, svdev->vdev.name);

		virtio_dev_dump_json_config(&svdev->vdev, w);

		spdk_json_write_object_end(w);
	}
	pthread_mutex_unlock(&g_virtio_scsi_mutex);

	spdk_json_write_array_end(w);
}

SPDK_LOG_REGISTER_COMPONENT("virtio", SPDK_LOG_VIRTIO)
+6 −0
Original line number Diff line number Diff line
@@ -762,6 +762,12 @@ if __name__ == "__main__":
    It will be inhereted by all created bdevs, which are named n the following format: <name>t<target_id>""")
    p.set_defaults(func=construct_virtio_pci_scsi_bdev)

    def get_virtio_scsi_devs(args):
        print_dict(rpc.vhost.get_virtio_scsi_devs(args))

    p = subparsers.add_parser('get_virtio_scsi_devs', help='List all Virtio-SCSI devices.')
    p.set_defaults(func=get_virtio_scsi_devs)

    def remove_virtio_scsi_bdev(args):
        rpc.vhost.remove_virtio_scsi_bdev(args)

+4 −0
Original line number Diff line number Diff line
@@ -79,6 +79,10 @@ def remove_virtio_scsi_bdev(args):
    return args.client.call('remove_virtio_scsi_bdev', params)


def get_virtio_scsi_devs(args):
    return args.client.call('get_virtio_scsi_devs')


def construct_virtio_user_blk_bdev(args):
    params = {
        'path': args.path,