2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2017 Intel Corporation. All rights reserved.
|
2017-03-02 14:12:20 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
#include "spdk/env.h"
|
2017-05-24 12:52:07 +00:00
|
|
|
#include "spdk/likely.h"
|
2017-08-11 23:27:04 +00:00
|
|
|
#include "spdk/string.h"
|
2017-05-26 12:00:56 +00:00
|
|
|
#include "spdk/util.h"
|
2020-02-27 13:38:02 +00:00
|
|
|
#include "spdk/memory.h"
|
2017-08-09 17:05:06 +00:00
|
|
|
#include "spdk/barrier.h"
|
2017-03-02 14:12:20 +00:00
|
|
|
#include "spdk/vhost.h"
|
2017-05-22 12:53:27 +00:00
|
|
|
#include "vhost_internal.h"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2020-03-24 10:42:40 +00:00
|
|
|
static struct spdk_cpuset g_vhost_core_mask;
|
|
|
|
|
2019-07-20 21:06:19 +00:00
|
|
|
static TAILQ_HEAD(, spdk_vhost_dev) g_vhost_devices = TAILQ_HEAD_INITIALIZER(
|
|
|
|
g_vhost_devices);
|
|
|
|
static pthread_mutex_t g_vhost_mutex = PTHREAD_MUTEX_INITIALIZER;
|
2017-05-18 13:57:09 +00:00
|
|
|
|
2021-09-17 08:23:35 +00:00
|
|
|
static TAILQ_HEAD(, spdk_virtio_blk_transport) g_virtio_blk_transports = TAILQ_HEAD_INITIALIZER(
|
|
|
|
g_virtio_blk_transports);
|
|
|
|
|
2022-11-17 05:43:41 +00:00
|
|
|
static spdk_vhost_fini_cb g_fini_cb;
|
|
|
|
|
2019-01-13 14:13:46 +00:00
|
|
|
struct spdk_vhost_dev *
|
|
|
|
spdk_vhost_dev_next(struct spdk_vhost_dev *vdev)
|
|
|
|
{
|
|
|
|
if (vdev == NULL) {
|
2019-07-20 21:06:19 +00:00
|
|
|
return TAILQ_FIRST(&g_vhost_devices);
|
2019-01-13 14:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TAILQ_NEXT(vdev, tailq);
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:08:07 +00:00
|
|
|
struct spdk_vhost_dev *
|
|
|
|
spdk_vhost_dev_find(const char *ctrlr_name)
|
2017-03-02 14:12:20 +00:00
|
|
|
{
|
2018-02-12 20:02:15 +00:00
|
|
|
struct spdk_vhost_dev *vdev;
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2019-07-20 21:06:19 +00:00
|
|
|
TAILQ_FOREACH(vdev, &g_vhost_devices, tailq) {
|
2018-02-12 20:02:15 +00:00
|
|
|
if (strcmp(vdev->name, ctrlr_name) == 0) {
|
|
|
|
return vdev;
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:08:07 +00:00
|
|
|
return NULL;
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 18:11:14 +00:00
|
|
|
static int
|
2019-07-20 21:06:19 +00:00
|
|
|
vhost_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask)
|
2017-08-10 18:11:14 +00:00
|
|
|
{
|
2017-12-21 04:29:21 +00:00
|
|
|
int rc;
|
2021-02-01 12:32:46 +00:00
|
|
|
struct spdk_cpuset negative_vhost_mask;
|
2017-12-21 04:29:21 +00:00
|
|
|
|
|
|
|
if (cpumask == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
2017-08-10 18:11:14 +00:00
|
|
|
|
2017-08-31 20:01:14 +00:00
|
|
|
if (mask == NULL) {
|
2020-03-24 10:42:40 +00:00
|
|
|
spdk_cpuset_copy(cpumask, &g_vhost_core_mask);
|
2017-08-10 18:11:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-24 10:42:40 +00:00
|
|
|
rc = spdk_cpuset_parse(cpumask, mask);
|
2017-12-21 16:48:31 +00:00
|
|
|
if (rc < 0) {
|
2017-12-21 04:29:21 +00:00
|
|
|
SPDK_ERRLOG("invalid cpumask %s\n", mask);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-08-10 18:11:14 +00:00
|
|
|
|
2021-02-01 12:32:46 +00:00
|
|
|
spdk_cpuset_copy(&negative_vhost_mask, &g_vhost_core_mask);
|
|
|
|
spdk_cpuset_negate(&negative_vhost_mask);
|
|
|
|
spdk_cpuset_and(&negative_vhost_mask, cpumask);
|
|
|
|
|
|
|
|
if (spdk_cpuset_count(&negative_vhost_mask) != 0) {
|
|
|
|
SPDK_ERRLOG("one of selected cpu is outside of core mask(=%s)\n",
|
|
|
|
spdk_cpuset_fmt(&g_vhost_core_mask));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-03-24 10:42:40 +00:00
|
|
|
spdk_cpuset_and(cpumask, &g_vhost_core_mask);
|
|
|
|
|
2017-12-21 16:48:31 +00:00
|
|
|
if (spdk_cpuset_count(cpumask) == 0) {
|
2020-03-24 10:42:40 +00:00
|
|
|
SPDK_ERRLOG("no cpu is selected among core mask(=%s)\n",
|
|
|
|
spdk_cpuset_fmt(&g_vhost_core_mask));
|
2017-08-10 18:11:14 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:23:35 +00:00
|
|
|
TAILQ_HEAD(, virtio_blk_transport_ops_list_element)
|
|
|
|
g_spdk_virtio_blk_transport_ops = TAILQ_HEAD_INITIALIZER(g_spdk_virtio_blk_transport_ops);
|
|
|
|
|
|
|
|
const struct spdk_virtio_blk_transport_ops *
|
|
|
|
virtio_blk_get_transport_ops(const char *transport_name)
|
|
|
|
{
|
|
|
|
struct virtio_blk_transport_ops_list_element *ops;
|
|
|
|
TAILQ_FOREACH(ops, &g_spdk_virtio_blk_transport_ops, link) {
|
|
|
|
if (strcasecmp(transport_name, ops->ops.name) == 0) {
|
|
|
|
return &ops->ops;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-05-22 12:53:27 +00:00
|
|
|
int
|
2019-07-20 21:06:19 +00:00
|
|
|
vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str,
|
2021-09-17 08:23:35 +00:00
|
|
|
const struct spdk_json_val *params,
|
2022-03-03 10:24:34 +00:00
|
|
|
const struct spdk_vhost_dev_backend *backend,
|
|
|
|
const struct spdk_vhost_user_dev_backend *user_backend)
|
2017-03-02 14:12:20 +00:00
|
|
|
{
|
2019-12-20 07:56:57 +00:00
|
|
|
struct spdk_cpuset cpumask = {};
|
2017-12-21 16:48:31 +00:00
|
|
|
int rc;
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2017-06-02 17:51:19 +00:00
|
|
|
assert(vdev);
|
|
|
|
if (name == NULL) {
|
2017-05-18 15:39:28 +00:00
|
|
|
SPDK_ERRLOG("Can't register controller with no name\n");
|
2017-03-02 14:12:20 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-12-20 07:56:57 +00:00
|
|
|
if (vhost_parse_core_mask(mask_str, &cpumask) != 0) {
|
2020-03-24 10:42:40 +00:00
|
|
|
SPDK_ERRLOG("cpumask %s is invalid (core mask is 0x%s)\n",
|
|
|
|
mask_str, spdk_cpuset_fmt(&g_vhost_core_mask));
|
2020-03-05 03:32:16 +00:00
|
|
|
return -EINVAL;
|
2017-06-02 17:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_vhost_dev_find(name)) {
|
|
|
|
SPDK_ERRLOG("vhost controller %s already exists.\n", name);
|
2020-03-05 03:32:16 +00:00
|
|
|
return -EEXIST;
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 22:44:43 +00:00
|
|
|
vdev->name = strdup(name);
|
2022-01-12 14:25:38 +00:00
|
|
|
if (vdev->name == NULL) {
|
|
|
|
return -EIO;
|
2020-03-05 21:36:13 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 10:24:34 +00:00
|
|
|
vdev->backend = backend;
|
2021-09-17 08:23:35 +00:00
|
|
|
if (vdev->backend->type == VHOST_BACKEND_SCSI) {
|
|
|
|
rc = vhost_user_dev_register(vdev, name, &cpumask, user_backend);
|
|
|
|
} else {
|
|
|
|
rc = virtio_blk_construct_ctrlr(vdev, name, &cpumask, params, user_backend);
|
|
|
|
}
|
2022-01-12 14:25:38 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
free(vdev->name);
|
|
|
|
return rc;
|
2018-04-09 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 03:32:16 +00:00
|
|
|
TAILQ_INSERT_TAIL(&g_vhost_devices, vdev, tailq);
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vhost, "Controller %s: new controller added\n", vdev->name);
|
2017-05-18 15:39:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-07-20 21:06:19 +00:00
|
|
|
vhost_dev_unregister(struct spdk_vhost_dev *vdev)
|
2017-03-15 16:00:55 +00:00
|
|
|
{
|
2022-01-12 14:25:38 +00:00
|
|
|
int rc;
|
2017-03-15 16:00:55 +00:00
|
|
|
|
2021-09-17 08:23:35 +00:00
|
|
|
if (vdev->backend->type == VHOST_BACKEND_SCSI) {
|
|
|
|
rc = vhost_user_dev_unregister(vdev);
|
|
|
|
} else {
|
|
|
|
rc = virtio_blk_destroy_ctrlr(vdev);
|
|
|
|
}
|
2022-01-12 14:25:38 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
return rc;
|
2017-05-22 13:34:45 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vhost, "Controller %s: removed\n", vdev->name);
|
2017-05-22 13:34:45 +00:00
|
|
|
|
2017-06-02 17:51:19 +00:00
|
|
|
free(vdev->name);
|
2019-07-20 21:06:19 +00:00
|
|
|
TAILQ_REMOVE(&g_vhost_devices, vdev, tailq);
|
2022-11-17 05:43:41 +00:00
|
|
|
|
|
|
|
if (TAILQ_EMPTY(&g_vhost_devices) && g_fini_cb != NULL) {
|
|
|
|
g_fini_cb();
|
|
|
|
}
|
|
|
|
|
2017-05-22 13:34:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
const char *
|
2017-05-17 12:42:20 +00:00
|
|
|
spdk_vhost_dev_get_name(struct spdk_vhost_dev *vdev)
|
2017-03-02 14:12:20 +00:00
|
|
|
{
|
2017-05-17 12:42:20 +00:00
|
|
|
assert(vdev != NULL);
|
|
|
|
return vdev->name;
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 20:58:50 +00:00
|
|
|
const struct spdk_cpuset *
|
|
|
|
spdk_vhost_dev_get_cpumask(struct spdk_vhost_dev *vdev)
|
2017-03-02 14:12:20 +00:00
|
|
|
{
|
2017-05-17 12:42:20 +00:00
|
|
|
assert(vdev != NULL);
|
2020-03-05 21:36:13 +00:00
|
|
|
return spdk_thread_get_cpumask(vdev->thread);
|
2019-07-30 11:13:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 14:37:50 +00:00
|
|
|
void
|
2019-07-20 21:06:19 +00:00
|
|
|
vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
|
2017-07-13 14:37:50 +00:00
|
|
|
{
|
2018-03-19 18:01:57 +00:00
|
|
|
assert(vdev->backend->dump_info_json != NULL);
|
|
|
|
vdev->backend->dump_info_json(vdev, w);
|
2017-07-13 14:37:50 +00:00
|
|
|
}
|
|
|
|
|
2017-09-05 18:23:43 +00:00
|
|
|
int
|
2018-01-26 13:09:39 +00:00
|
|
|
spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev)
|
2017-09-05 18:23:43 +00:00
|
|
|
{
|
2018-01-26 13:09:39 +00:00
|
|
|
return vdev->backend->remove_device(vdev);
|
2017-09-05 18:23:43 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 11:06:41 +00:00
|
|
|
void
|
|
|
|
spdk_vhost_lock(void)
|
|
|
|
{
|
2019-07-20 21:06:19 +00:00
|
|
|
pthread_mutex_lock(&g_vhost_mutex);
|
2017-09-08 11:06:41 +00:00
|
|
|
}
|
|
|
|
|
2019-03-17 00:57:42 +00:00
|
|
|
int
|
|
|
|
spdk_vhost_trylock(void)
|
|
|
|
{
|
2019-07-20 21:06:19 +00:00
|
|
|
return -pthread_mutex_trylock(&g_vhost_mutex);
|
2019-03-17 00:57:42 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 11:06:41 +00:00
|
|
|
void
|
|
|
|
spdk_vhost_unlock(void)
|
|
|
|
{
|
2019-07-20 21:06:19 +00:00
|
|
|
pthread_mutex_unlock(&g_vhost_mutex);
|
2017-09-08 11:06:41 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 16:11:24 +00:00
|
|
|
void
|
2021-08-31 09:28:29 +00:00
|
|
|
spdk_vhost_scsi_init(spdk_vhost_init_cb init_cb)
|
2017-11-29 06:47:59 +00:00
|
|
|
{
|
2021-01-29 19:04:48 +00:00
|
|
|
uint32_t i;
|
|
|
|
int ret = 0;
|
2017-12-24 23:43:41 +00:00
|
|
|
|
2022-01-12 14:25:38 +00:00
|
|
|
ret = vhost_user_init();
|
|
|
|
if (ret != 0) {
|
|
|
|
init_cb(ret);
|
|
|
|
return;
|
2018-07-12 13:29:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 10:42:40 +00:00
|
|
|
spdk_cpuset_zero(&g_vhost_core_mask);
|
2021-01-29 19:04:48 +00:00
|
|
|
SPDK_ENV_FOREACH_CORE(i) {
|
|
|
|
spdk_cpuset_set_cpu(&g_vhost_core_mask, i, true);
|
|
|
|
}
|
2019-04-25 16:11:24 +00:00
|
|
|
init_cb(ret);
|
2017-11-29 06:47:59 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 17:24:52 +00:00
|
|
|
static void
|
2021-08-31 09:28:29 +00:00
|
|
|
vhost_fini(void)
|
2018-01-26 13:46:26 +00:00
|
|
|
{
|
2019-01-13 17:24:52 +00:00
|
|
|
struct spdk_vhost_dev *vdev, *tmp;
|
2018-01-26 13:46:26 +00:00
|
|
|
|
2019-01-13 17:24:52 +00:00
|
|
|
spdk_vhost_lock();
|
2022-11-17 05:43:41 +00:00
|
|
|
if (spdk_vhost_dev_next(NULL) == NULL) {
|
|
|
|
spdk_vhost_unlock();
|
|
|
|
g_fini_cb();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-13 17:24:52 +00:00
|
|
|
vdev = spdk_vhost_dev_next(NULL);
|
|
|
|
while (vdev != NULL) {
|
|
|
|
tmp = spdk_vhost_dev_next(vdev);
|
2018-01-26 13:46:26 +00:00
|
|
|
spdk_vhost_dev_remove(vdev);
|
2019-01-07 23:30:57 +00:00
|
|
|
/* don't care if it fails, there's nothing we can do for now */
|
2019-01-13 17:24:52 +00:00
|
|
|
vdev = tmp;
|
2018-01-26 13:46:26 +00:00
|
|
|
}
|
2019-01-13 17:24:52 +00:00
|
|
|
spdk_vhost_unlock();
|
2018-01-26 13:46:26 +00:00
|
|
|
|
2022-11-17 05:43:41 +00:00
|
|
|
/* g_fini_cb will get called when last device is unregistered. */
|
2019-04-29 09:44:40 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 10:55:05 +00:00
|
|
|
void
|
2021-08-31 09:28:29 +00:00
|
|
|
spdk_vhost_blk_init(spdk_vhost_init_cb init_cb)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
int ret = 0;
|
|
|
|
|
2021-09-17 08:23:35 +00:00
|
|
|
ret = virtio_blk_transport_create("vhost_user_blk", NULL);
|
2021-08-31 09:28:29 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_cpuset_zero(&g_vhost_core_mask);
|
|
|
|
SPDK_ENV_FOREACH_CORE(i) {
|
|
|
|
spdk_cpuset_set_cpu(&g_vhost_core_mask, i, true);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
init_cb(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_vhost_scsi_fini(spdk_vhost_fini_cb fini_cb)
|
|
|
|
{
|
|
|
|
g_fini_cb = fini_cb;
|
|
|
|
|
|
|
|
vhost_user_fini(vhost_fini);
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:23:35 +00:00
|
|
|
static void
|
|
|
|
virtio_blk_transports_destroy(void)
|
|
|
|
{
|
|
|
|
struct spdk_virtio_blk_transport *transport = TAILQ_FIRST(&g_virtio_blk_transports);
|
|
|
|
|
|
|
|
if (transport == NULL) {
|
|
|
|
g_fini_cb();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TAILQ_REMOVE(&g_virtio_blk_transports, transport, tailq);
|
|
|
|
virtio_blk_transport_destroy(transport, virtio_blk_transports_destroy);
|
|
|
|
}
|
|
|
|
|
2021-08-31 09:28:29 +00:00
|
|
|
void
|
|
|
|
spdk_vhost_blk_fini(spdk_vhost_fini_cb fini_cb)
|
2018-01-26 10:55:05 +00:00
|
|
|
{
|
2022-01-12 14:25:38 +00:00
|
|
|
g_fini_cb = fini_cb;
|
|
|
|
|
2021-09-17 08:23:35 +00:00
|
|
|
virtio_blk_transports_destroy();
|
2017-11-29 06:47:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 11:07:35 +00:00
|
|
|
static void
|
|
|
|
vhost_user_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
|
|
|
|
{
|
|
|
|
uint32_t delay_base_us;
|
|
|
|
uint32_t iops_threshold;
|
|
|
|
|
|
|
|
vdev->backend->write_config_json(vdev, w);
|
|
|
|
|
|
|
|
spdk_vhost_get_coalescing(vdev, &delay_base_us, &iops_threshold);
|
|
|
|
if (delay_base_us) {
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
spdk_json_write_named_string(w, "method", "vhost_controller_set_coalescing");
|
|
|
|
|
|
|
|
spdk_json_write_named_object_begin(w, "params");
|
|
|
|
spdk_json_write_named_string(w, "ctrlr", vdev->name);
|
|
|
|
spdk_json_write_named_uint32(w, "delay_base_us", delay_base_us);
|
|
|
|
spdk_json_write_named_uint32(w, "iops_threshold", iops_threshold);
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 17:24:52 +00:00
|
|
|
void
|
2021-08-31 09:28:29 +00:00
|
|
|
spdk_vhost_scsi_config_json(struct spdk_json_write_ctx *w)
|
|
|
|
{
|
|
|
|
struct spdk_vhost_dev *vdev;
|
|
|
|
|
|
|
|
spdk_json_write_array_begin(w);
|
|
|
|
|
|
|
|
spdk_vhost_lock();
|
|
|
|
for (vdev = spdk_vhost_dev_next(NULL); vdev != NULL;
|
|
|
|
vdev = spdk_vhost_dev_next(vdev)) {
|
|
|
|
if (vdev->backend->type == VHOST_BACKEND_SCSI) {
|
|
|
|
vhost_user_config_json(vdev, w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spdk_vhost_unlock();
|
|
|
|
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_vhost_blk_config_json(struct spdk_json_write_ctx *w)
|
2018-03-19 18:01:57 +00:00
|
|
|
{
|
2019-01-13 17:24:52 +00:00
|
|
|
struct spdk_vhost_dev *vdev;
|
2018-03-19 18:01:57 +00:00
|
|
|
|
2019-01-13 17:24:52 +00:00
|
|
|
spdk_json_write_array_begin(w);
|
2018-06-15 15:10:58 +00:00
|
|
|
|
2019-01-13 17:24:52 +00:00
|
|
|
spdk_vhost_lock();
|
2022-01-11 10:48:33 +00:00
|
|
|
for (vdev = spdk_vhost_dev_next(NULL); vdev != NULL;
|
|
|
|
vdev = spdk_vhost_dev_next(vdev)) {
|
2021-08-31 09:28:29 +00:00
|
|
|
if (vdev->backend->type == VHOST_BACKEND_BLK) {
|
|
|
|
vhost_user_config_json(vdev, w);
|
|
|
|
}
|
2018-04-18 20:36:40 +00:00
|
|
|
}
|
2019-01-13 17:24:52 +00:00
|
|
|
spdk_vhost_unlock();
|
2018-03-19 18:01:57 +00:00
|
|
|
|
2019-01-13 17:24:52 +00:00
|
|
|
spdk_json_write_array_end(w);
|
2018-03-19 18:01:57 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 08:23:35 +00:00
|
|
|
void
|
|
|
|
virtio_blk_transport_register(const struct spdk_virtio_blk_transport_ops *ops)
|
|
|
|
{
|
|
|
|
struct virtio_blk_transport_ops_list_element *new_ops;
|
|
|
|
|
|
|
|
if (virtio_blk_get_transport_ops(ops->name) != NULL) {
|
|
|
|
SPDK_ERRLOG("Double registering virtio blk transport type %s.\n", ops->name);
|
|
|
|
assert(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_ops = calloc(1, sizeof(*new_ops));
|
|
|
|
if (new_ops == NULL) {
|
|
|
|
SPDK_ERRLOG("Unable to allocate memory to register new transport type %s.\n", ops->name);
|
|
|
|
assert(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_ops->ops = *ops;
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&g_spdk_virtio_blk_transport_ops, new_ops, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
virtio_blk_transport_create(const char *transport_name,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
const struct spdk_virtio_blk_transport_ops *ops = NULL;
|
|
|
|
struct spdk_virtio_blk_transport *transport;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(transport, &g_virtio_blk_transports, tailq) {
|
|
|
|
if (strcasecmp(transport->ops->name, transport_name) == 0) {
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ops = virtio_blk_get_transport_ops(transport_name);
|
|
|
|
if (!ops) {
|
|
|
|
SPDK_ERRLOG("Transport type '%s' unavailable.\n", transport_name);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
transport = ops->create(params);
|
|
|
|
if (!transport) {
|
|
|
|
SPDK_ERRLOG("Unable to create new transport of type %s\n", transport_name);
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
transport->ops = ops;
|
|
|
|
TAILQ_INSERT_TAIL(&g_virtio_blk_transports, transport, tailq);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
virtio_blk_transport_destroy(struct spdk_virtio_blk_transport *transport,
|
|
|
|
spdk_vhost_fini_cb cb_fn)
|
|
|
|
{
|
|
|
|
return transport->ops->destroy(transport, cb_fn);
|
|
|
|
}
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT(vhost)
|
|
|
|
SPDK_LOG_REGISTER_COMPONENT(vhost_ring)
|