2017-03-02 14:12:20 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright(c) Intel Corporation. All rights reserved.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2017-05-24 14:48:22 +00:00
|
|
|
|
2020-10-06 16:16:26 +00:00
|
|
|
#include "spdk/log.h"
|
2017-03-02 14:12:20 +00:00
|
|
|
#include "spdk/rpc.h"
|
2017-03-03 20:44:04 +00:00
|
|
|
#include "spdk/util.h"
|
2017-08-11 23:27:04 +00:00
|
|
|
#include "spdk/string.h"
|
2017-07-26 10:09:34 +00:00
|
|
|
#include "spdk/env.h"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2017-06-23 10:02:34 +00:00
|
|
|
#include "spdk/scsi.h"
|
2017-03-02 14:12:20 +00:00
|
|
|
#include "spdk/vhost.h"
|
2017-06-02 16:00:22 +00:00
|
|
|
#include "vhost_internal.h"
|
2017-06-05 13:09:56 +00:00
|
|
|
#include "spdk/bdev.h"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
struct rpc_vhost_scsi_ctrlr {
|
|
|
|
char *ctrlr;
|
|
|
|
char *cpumask;
|
|
|
|
};
|
|
|
|
|
2017-03-08 18:58:37 +00:00
|
|
|
static void
|
|
|
|
free_rpc_vhost_scsi_ctrlr(struct rpc_vhost_scsi_ctrlr *req)
|
|
|
|
{
|
|
|
|
free(req->ctrlr);
|
|
|
|
free(req->cpumask);
|
|
|
|
}
|
|
|
|
|
2019-09-24 14:29:10 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_vhost_create_scsi_ctrlr[] = {
|
2017-03-02 14:12:20 +00:00
|
|
|
{"ctrlr", offsetof(struct rpc_vhost_scsi_ctrlr, ctrlr), spdk_json_decode_string },
|
|
|
|
{"cpumask", offsetof(struct rpc_vhost_scsi_ctrlr, cpumask), spdk_json_decode_string, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-05-10 01:24:05 +00:00
|
|
|
rpc_vhost_create_scsi_controller(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-03-02 14:12:20 +00:00
|
|
|
{
|
|
|
|
struct rpc_vhost_scsi_ctrlr req = {0};
|
|
|
|
int rc;
|
|
|
|
|
2019-09-24 14:29:10 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_vhost_create_scsi_ctrlr,
|
|
|
|
SPDK_COUNTOF(rpc_vhost_create_scsi_ctrlr),
|
2017-03-02 14:12:20 +00:00
|
|
|
&req)) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
|
2017-03-02 14:12:20 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2017-08-10 18:11:14 +00:00
|
|
|
rc = spdk_vhost_scsi_dev_construct(req.ctrlr, req.cpumask);
|
2017-03-02 14:12:20 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2017-03-08 18:58:37 +00:00
|
|
|
free_rpc_vhost_scsi_ctrlr(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2017-03-02 14:12:20 +00:00
|
|
|
return;
|
2017-06-29 20:37:39 +00:00
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
invalid:
|
2017-03-08 18:58:37 +00:00
|
|
|
free_rpc_vhost_scsi_ctrlr(&req);
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-rc));
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
2020-05-10 01:24:05 +00:00
|
|
|
SPDK_RPC_REGISTER("vhost_create_scsi_controller", rpc_vhost_create_scsi_controller,
|
2018-05-02 04:28:57 +00:00
|
|
|
SPDK_RPC_RUNTIME)
|
2019-09-24 14:29:10 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(vhost_create_scsi_controller, construct_vhost_scsi_controller)
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2019-09-27 20:53:41 +00:00
|
|
|
struct rpc_vhost_scsi_ctrlr_add_target {
|
2017-03-02 14:12:20 +00:00
|
|
|
char *ctrlr;
|
2019-01-28 21:30:36 +00:00
|
|
|
int32_t scsi_target_num;
|
2018-01-10 05:55:53 +00:00
|
|
|
char *bdev_name;
|
2017-03-02 14:12:20 +00:00
|
|
|
};
|
|
|
|
|
2017-03-08 18:58:37 +00:00
|
|
|
static void
|
2019-09-27 20:53:41 +00:00
|
|
|
free_rpc_vhost_scsi_ctrlr_add_target(struct rpc_vhost_scsi_ctrlr_add_target *req)
|
2017-03-08 18:58:37 +00:00
|
|
|
{
|
|
|
|
free(req->ctrlr);
|
2018-01-10 05:55:53 +00:00
|
|
|
free(req->bdev_name);
|
2017-03-08 18:58:37 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 20:53:41 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_vhost_scsi_ctrlr_add_target[] = {
|
|
|
|
{"ctrlr", offsetof(struct rpc_vhost_scsi_ctrlr_add_target, ctrlr), spdk_json_decode_string },
|
|
|
|
{"scsi_target_num", offsetof(struct rpc_vhost_scsi_ctrlr_add_target, scsi_target_num), spdk_json_decode_int32},
|
|
|
|
{"bdev_name", offsetof(struct rpc_vhost_scsi_ctrlr_add_target, bdev_name), spdk_json_decode_string },
|
2017-03-02 14:12:20 +00:00
|
|
|
};
|
|
|
|
|
2017-07-26 10:09:34 +00:00
|
|
|
static void
|
2020-05-10 01:24:05 +00:00
|
|
|
rpc_vhost_scsi_controller_add_target(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-07-26 10:09:34 +00:00
|
|
|
{
|
2019-09-27 20:53:41 +00:00
|
|
|
struct rpc_vhost_scsi_ctrlr_add_target req = {0};
|
2019-01-13 17:28:46 +00:00
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
struct spdk_vhost_dev *vdev;
|
2017-07-26 10:09:34 +00:00
|
|
|
int rc;
|
|
|
|
|
2019-09-27 20:53:41 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_vhost_scsi_ctrlr_add_target,
|
|
|
|
SPDK_COUNTOF(rpc_vhost_scsi_ctrlr_add_target),
|
2019-01-13 17:47:16 +00:00
|
|
|
&req)) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
|
2017-07-26 10:09:34 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2019-01-13 17:28:46 +00:00
|
|
|
spdk_vhost_lock();
|
2019-01-13 17:47:16 +00:00
|
|
|
vdev = spdk_vhost_dev_find(req.ctrlr);
|
2019-01-13 17:28:46 +00:00
|
|
|
if (vdev == NULL) {
|
|
|
|
spdk_vhost_unlock();
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto invalid;
|
|
|
|
}
|
2017-07-26 10:09:34 +00:00
|
|
|
|
2019-01-13 17:47:16 +00:00
|
|
|
rc = spdk_vhost_scsi_dev_add_tgt(vdev, req.scsi_target_num, req.bdev_name);
|
2019-01-13 17:28:46 +00:00
|
|
|
spdk_vhost_unlock();
|
|
|
|
if (rc < 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2019-09-27 20:53:41 +00:00
|
|
|
free_rpc_vhost_scsi_ctrlr_add_target(&req);
|
2019-01-13 17:28:46 +00:00
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
spdk_json_write_int32(w, rc);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
2017-03-02 14:12:20 +00:00
|
|
|
return;
|
2017-06-29 20:37:39 +00:00
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
invalid:
|
2019-09-27 20:53:41 +00:00
|
|
|
free_rpc_vhost_scsi_ctrlr_add_target(&req);
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-rc));
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
2020-05-10 01:24:05 +00:00
|
|
|
SPDK_RPC_REGISTER("vhost_scsi_controller_add_target", rpc_vhost_scsi_controller_add_target,
|
2019-09-27 20:53:41 +00:00
|
|
|
SPDK_RPC_RUNTIME)
|
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(vhost_scsi_controller_add_target, add_vhost_scsi_lun)
|
2017-03-15 16:00:55 +00:00
|
|
|
|
2017-11-22 11:20:03 +00:00
|
|
|
struct rpc_remove_vhost_scsi_ctrlr_target {
|
2017-03-15 16:00:55 +00:00
|
|
|
char *ctrlr;
|
2017-11-22 11:20:03 +00:00
|
|
|
uint32_t scsi_target_num;
|
2017-03-15 16:00:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2017-11-22 11:20:03 +00:00
|
|
|
free_rpc_remove_vhost_scsi_ctrlr_target(struct rpc_remove_vhost_scsi_ctrlr_target *req)
|
2017-03-15 16:00:55 +00:00
|
|
|
{
|
|
|
|
free(req->ctrlr);
|
|
|
|
}
|
|
|
|
|
2017-11-22 11:20:03 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_vhost_remove_target[] = {
|
|
|
|
{"ctrlr", offsetof(struct rpc_remove_vhost_scsi_ctrlr_target, ctrlr), spdk_json_decode_string },
|
|
|
|
{"scsi_target_num", offsetof(struct rpc_remove_vhost_scsi_ctrlr_target, scsi_target_num), spdk_json_decode_uint32},
|
2017-03-15 16:00:55 +00:00
|
|
|
};
|
|
|
|
|
2017-07-26 10:09:34 +00:00
|
|
|
static int
|
2020-05-10 01:24:05 +00:00
|
|
|
rpc_vhost_scsi_controller_remove_target_finish_cb(struct spdk_vhost_dev *vdev, void *arg)
|
2017-03-15 16:00:55 +00:00
|
|
|
{
|
2019-01-13 17:47:16 +00:00
|
|
|
struct spdk_jsonrpc_request *request = arg;
|
2017-07-25 13:42:27 +00:00
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2017-07-25 13:42:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-26 10:09:34 +00:00
|
|
|
static void
|
2020-05-10 01:24:05 +00:00
|
|
|
rpc_vhost_scsi_controller_remove_target(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-07-26 10:09:34 +00:00
|
|
|
{
|
2019-01-13 17:47:16 +00:00
|
|
|
struct rpc_remove_vhost_scsi_ctrlr_target req = {0};
|
2019-01-13 17:28:46 +00:00
|
|
|
struct spdk_vhost_dev *vdev;
|
2017-07-26 10:09:34 +00:00
|
|
|
int rc;
|
|
|
|
|
2017-11-22 11:20:03 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_vhost_remove_target,
|
|
|
|
SPDK_COUNTOF(rpc_vhost_remove_target),
|
2019-01-13 17:47:16 +00:00
|
|
|
&req)) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
|
2017-07-26 10:09:34 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2019-01-13 17:28:46 +00:00
|
|
|
spdk_vhost_lock();
|
2019-01-13 17:47:16 +00:00
|
|
|
vdev = spdk_vhost_dev_find(req.ctrlr);
|
2019-01-13 17:28:46 +00:00
|
|
|
if (vdev == NULL) {
|
|
|
|
spdk_vhost_unlock();
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto invalid;
|
|
|
|
}
|
2017-07-26 10:09:34 +00:00
|
|
|
|
2019-01-13 17:47:16 +00:00
|
|
|
rc = spdk_vhost_scsi_dev_remove_tgt(vdev, req.scsi_target_num,
|
2020-05-10 01:24:05 +00:00
|
|
|
rpc_vhost_scsi_controller_remove_target_finish_cb,
|
2019-01-13 17:47:16 +00:00
|
|
|
request);
|
2019-01-13 17:28:46 +00:00
|
|
|
spdk_vhost_unlock();
|
|
|
|
if (rc < 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
2019-01-13 17:47:16 +00:00
|
|
|
|
|
|
|
free_rpc_remove_vhost_scsi_ctrlr_target(&req);
|
2017-03-15 16:00:55 +00:00
|
|
|
return;
|
2017-06-29 20:37:39 +00:00
|
|
|
|
2017-03-15 16:00:55 +00:00
|
|
|
invalid:
|
2019-01-13 17:47:16 +00:00
|
|
|
free_rpc_remove_vhost_scsi_ctrlr_target(&req);
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-rc));
|
2017-03-15 16:00:55 +00:00
|
|
|
}
|
2017-07-26 10:09:34 +00:00
|
|
|
|
2019-09-27 21:06:04 +00:00
|
|
|
SPDK_RPC_REGISTER("vhost_scsi_controller_remove_target",
|
2020-05-10 01:24:05 +00:00
|
|
|
rpc_vhost_scsi_controller_remove_target, SPDK_RPC_RUNTIME)
|
2019-09-27 21:06:04 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(vhost_scsi_controller_remove_target, remove_vhost_scsi_target)
|
2017-06-05 13:09:56 +00:00
|
|
|
|
|
|
|
struct rpc_vhost_blk_ctrlr {
|
|
|
|
char *ctrlr;
|
|
|
|
char *dev_name;
|
|
|
|
char *cpumask;
|
2017-06-19 14:37:51 +00:00
|
|
|
bool readonly;
|
2020-03-30 11:16:24 +00:00
|
|
|
bool packed_ring;
|
2020-08-19 10:02:07 +00:00
|
|
|
bool packed_ring_recovery;
|
2017-06-05 13:09:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_construct_vhost_blk_ctrlr[] = {
|
|
|
|
{"ctrlr", offsetof(struct rpc_vhost_blk_ctrlr, ctrlr), spdk_json_decode_string },
|
|
|
|
{"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},
|
2017-06-19 14:37:51 +00:00
|
|
|
{"readonly", offsetof(struct rpc_vhost_blk_ctrlr, readonly), spdk_json_decode_bool, true},
|
2020-03-30 11:16:24 +00:00
|
|
|
{"packed_ring", offsetof(struct rpc_vhost_blk_ctrlr, packed_ring), spdk_json_decode_bool, true},
|
2020-08-19 10:02:07 +00:00
|
|
|
{"packed_ring_recovery", offsetof(struct rpc_vhost_blk_ctrlr, packed_ring_recovery), spdk_json_decode_bool, true},
|
2017-06-05 13:09:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_vhost_blk_ctrlr(struct rpc_vhost_blk_ctrlr *req)
|
|
|
|
{
|
|
|
|
free(req->ctrlr);
|
|
|
|
free(req->dev_name);
|
|
|
|
free(req->cpumask);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-10 01:24:05 +00:00
|
|
|
rpc_vhost_create_blk_controller(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-06-05 13:09:56 +00:00
|
|
|
{
|
|
|
|
struct rpc_vhost_blk_ctrlr req = {0};
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_construct_vhost_blk_ctrlr,
|
|
|
|
SPDK_COUNTOF(rpc_construct_vhost_blk_ctrlr),
|
|
|
|
&req)) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
|
2017-06-05 13:09:56 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2020-08-19 10:02:07 +00:00
|
|
|
g_packed_ring_recovery = req.packed_ring_recovery;
|
|
|
|
|
2020-03-30 11:16:24 +00:00
|
|
|
rc = spdk_vhost_blk_construct(req.ctrlr, req.cpumask, req.dev_name,
|
|
|
|
req.readonly, req.packed_ring);
|
2017-06-05 13:09:56 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_rpc_vhost_blk_ctrlr(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2017-06-05 13:09:56 +00:00
|
|
|
return;
|
2017-06-29 20:37:39 +00:00
|
|
|
|
2017-06-05 13:09:56 +00:00
|
|
|
invalid:
|
|
|
|
free_rpc_vhost_blk_ctrlr(&req);
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-rc));
|
2017-06-05 13:09:56 +00:00
|
|
|
|
|
|
|
}
|
2020-05-10 01:24:05 +00:00
|
|
|
SPDK_RPC_REGISTER("vhost_create_blk_controller", rpc_vhost_create_blk_controller,
|
2018-05-02 04:28:57 +00:00
|
|
|
SPDK_RPC_RUNTIME)
|
2019-09-30 10:51:55 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(vhost_create_blk_controller, construct_vhost_blk_controller)
|
2017-06-05 13:09:56 +00:00
|
|
|
|
2019-09-30 11:01:44 +00:00
|
|
|
struct rpc_delete_vhost_ctrlr {
|
2017-06-05 13:09:56 +00:00
|
|
|
char *ctrlr;
|
|
|
|
};
|
|
|
|
|
2019-09-30 11:01:44 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_delete_vhost_ctrlr_decoder[] = {
|
|
|
|
{"ctrlr", offsetof(struct rpc_delete_vhost_ctrlr, ctrlr), spdk_json_decode_string },
|
2017-06-05 13:09:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2019-09-30 11:01:44 +00:00
|
|
|
free_rpc_delete_vhost_ctrlr(struct rpc_delete_vhost_ctrlr *req)
|
2017-06-05 13:09:56 +00:00
|
|
|
{
|
|
|
|
free(req->ctrlr);
|
|
|
|
}
|
|
|
|
|
2019-01-13 17:28:46 +00:00
|
|
|
static void
|
2020-05-10 01:24:05 +00:00
|
|
|
rpc_vhost_delete_controller(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-06-05 13:09:56 +00:00
|
|
|
{
|
2019-09-30 11:01:44 +00:00
|
|
|
struct rpc_delete_vhost_ctrlr req = {0};
|
2019-01-13 17:28:46 +00:00
|
|
|
struct spdk_vhost_dev *vdev;
|
2017-06-05 13:09:56 +00:00
|
|
|
int rc;
|
|
|
|
|
2019-09-30 11:01:44 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_delete_vhost_ctrlr_decoder,
|
|
|
|
SPDK_COUNTOF(rpc_delete_vhost_ctrlr_decoder), &req)) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
|
2019-01-13 17:28:46 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_vhost_lock();
|
2019-01-13 17:47:16 +00:00
|
|
|
vdev = spdk_vhost_dev_find(req.ctrlr);
|
2017-09-05 18:23:43 +00:00
|
|
|
if (vdev == NULL) {
|
2019-01-13 17:28:46 +00:00
|
|
|
spdk_vhost_unlock();
|
2017-09-05 18:23:43 +00:00
|
|
|
rc = -ENODEV;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2018-01-26 13:09:39 +00:00
|
|
|
rc = spdk_vhost_dev_remove(vdev);
|
2019-01-13 17:28:46 +00:00
|
|
|
spdk_vhost_unlock();
|
2017-06-05 13:09:56 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2019-09-30 11:01:44 +00:00
|
|
|
free_rpc_delete_vhost_ctrlr(&req);
|
2017-06-05 13:09:56 +00:00
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2017-06-05 13:09:56 +00:00
|
|
|
return;
|
2017-06-29 20:37:39 +00:00
|
|
|
|
2017-06-05 13:09:56 +00:00
|
|
|
invalid:
|
2019-09-30 11:01:44 +00:00
|
|
|
free_rpc_delete_vhost_ctrlr(&req);
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-rc));
|
2017-06-05 13:09:56 +00:00
|
|
|
|
|
|
|
}
|
2020-05-10 01:24:05 +00:00
|
|
|
SPDK_RPC_REGISTER("vhost_delete_controller", rpc_vhost_delete_controller, SPDK_RPC_RUNTIME)
|
2019-09-30 11:01:44 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(vhost_delete_controller, remove_vhost_controller)
|
2017-06-05 13:09:56 +00:00
|
|
|
|
2017-08-08 16:52:53 +00:00
|
|
|
struct rpc_get_vhost_ctrlrs {
|
2018-09-13 03:58:55 +00:00
|
|
|
char *name;
|
2017-08-08 16:52:53 +00:00
|
|
|
};
|
|
|
|
|
2018-09-13 03:58:55 +00:00
|
|
|
static void
|
2020-05-10 01:24:05 +00:00
|
|
|
_rpc_get_vhost_controller(struct spdk_json_write_ctx *w, struct spdk_vhost_dev *vdev)
|
2018-09-13 03:58:55 +00:00
|
|
|
{
|
|
|
|
uint32_t delay_base_us, iops_threshold;
|
|
|
|
|
|
|
|
spdk_vhost_get_coalescing(vdev, &delay_base_us, &iops_threshold);
|
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
|
|
|
|
spdk_json_write_named_string(w, "ctrlr", spdk_vhost_dev_get_name(vdev));
|
2020-03-05 21:36:13 +00:00
|
|
|
spdk_json_write_named_string_fmt(w, "cpumask", "0x%s",
|
|
|
|
spdk_cpuset_fmt(spdk_thread_get_cpumask(vdev->thread)));
|
2018-09-13 03:58:55 +00:00
|
|
|
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_named_string(w, "socket", vdev->path);
|
|
|
|
|
|
|
|
spdk_json_write_named_object_begin(w, "backend_specific");
|
2019-07-20 21:06:19 +00:00
|
|
|
vhost_dump_info_json(vdev, w);
|
2018-09-13 03:58:55 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_get_vhost_ctrlrs_decoders[] = {
|
|
|
|
{"name", offsetof(struct rpc_get_vhost_ctrlrs, name), spdk_json_decode_string, true},
|
|
|
|
};
|
2017-08-08 16:52:53 +00:00
|
|
|
|
2019-01-13 17:28:46 +00:00
|
|
|
static void
|
|
|
|
free_rpc_get_vhost_ctrlrs(struct rpc_get_vhost_ctrlrs *req)
|
|
|
|
{
|
|
|
|
free(req->name);
|
|
|
|
}
|
|
|
|
|
2017-06-05 13:09:56 +00:00
|
|
|
static void
|
2020-05-10 01:24:05 +00:00
|
|
|
rpc_vhost_get_controllers(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-06-05 13:09:56 +00:00
|
|
|
{
|
2019-01-13 17:47:16 +00:00
|
|
|
struct rpc_get_vhost_ctrlrs req = {0};
|
2017-06-05 13:09:56 +00:00
|
|
|
struct spdk_json_write_ctx *w;
|
2019-01-13 17:28:46 +00:00
|
|
|
struct spdk_vhost_dev *vdev;
|
|
|
|
int rc;
|
2017-06-05 13:09:56 +00:00
|
|
|
|
2018-09-13 03:58:55 +00:00
|
|
|
if (params && spdk_json_decode_object(params, rpc_get_vhost_ctrlrs_decoders,
|
2019-01-13 17:47:16 +00:00
|
|
|
SPDK_COUNTOF(rpc_get_vhost_ctrlrs_decoders), &req)) {
|
2018-09-13 03:58:55 +00:00
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
2019-01-13 17:28:46 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
2018-09-13 03:58:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 17:28:46 +00:00
|
|
|
spdk_vhost_lock();
|
2019-01-13 17:47:16 +00:00
|
|
|
if (req.name != NULL) {
|
|
|
|
vdev = spdk_vhost_dev_find(req.name);
|
2019-01-13 17:28:46 +00:00
|
|
|
if (vdev == NULL) {
|
|
|
|
spdk_vhost_unlock();
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2019-01-13 17:47:16 +00:00
|
|
|
free_rpc_get_vhost_ctrlrs(&req);
|
2019-01-13 17:28:46 +00:00
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
spdk_json_write_array_begin(w);
|
|
|
|
|
2020-05-10 01:24:05 +00:00
|
|
|
_rpc_get_vhost_controller(w, vdev);
|
2019-01-13 17:28:46 +00:00
|
|
|
spdk_vhost_unlock();
|
|
|
|
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
2018-09-13 03:58:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-13 17:47:16 +00:00
|
|
|
free_rpc_get_vhost_ctrlrs(&req);
|
2019-01-13 17:28:46 +00:00
|
|
|
|
2018-09-12 07:52:30 +00:00
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
spdk_json_write_array_begin(w);
|
|
|
|
|
2019-01-13 17:28:46 +00:00
|
|
|
vdev = spdk_vhost_dev_next(NULL);
|
|
|
|
while (vdev != NULL) {
|
2020-05-10 01:24:05 +00:00
|
|
|
_rpc_get_vhost_controller(w, vdev);
|
2019-01-13 17:28:46 +00:00
|
|
|
vdev = spdk_vhost_dev_next(vdev);
|
|
|
|
}
|
|
|
|
spdk_vhost_unlock();
|
|
|
|
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2019-01-13 17:47:16 +00:00
|
|
|
free_rpc_get_vhost_ctrlrs(&req);
|
2019-01-13 17:28:46 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
spdk_strerror(-rc));
|
2017-06-05 13:09:56 +00:00
|
|
|
}
|
2020-05-10 01:24:05 +00:00
|
|
|
SPDK_RPC_REGISTER("vhost_get_controllers", rpc_vhost_get_controllers, SPDK_RPC_RUNTIME)
|
2019-09-30 12:00:12 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(vhost_get_controllers, get_vhost_controllers)
|
2017-08-25 21:22:46 +00:00
|
|
|
|
2017-09-11 17:45:56 +00:00
|
|
|
|
|
|
|
struct rpc_vhost_ctrlr_coalescing {
|
|
|
|
char *ctrlr;
|
|
|
|
uint32_t delay_base_us;
|
|
|
|
uint32_t iops_threshold;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_set_vhost_ctrlr_coalescing[] = {
|
|
|
|
{"ctrlr", offsetof(struct rpc_vhost_ctrlr_coalescing, ctrlr), spdk_json_decode_string },
|
|
|
|
{"delay_base_us", offsetof(struct rpc_vhost_ctrlr_coalescing, delay_base_us), spdk_json_decode_uint32},
|
|
|
|
{"iops_threshold", offsetof(struct rpc_vhost_ctrlr_coalescing, iops_threshold), spdk_json_decode_uint32},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_set_vhost_controllers_event_coalescing(struct rpc_vhost_ctrlr_coalescing *req)
|
|
|
|
{
|
|
|
|
free(req->ctrlr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-10 01:24:05 +00:00
|
|
|
rpc_vhost_controller_set_coalescing(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-09-11 17:45:56 +00:00
|
|
|
{
|
2019-01-13 17:47:16 +00:00
|
|
|
struct rpc_vhost_ctrlr_coalescing req = {0};
|
2019-01-13 17:28:46 +00:00
|
|
|
struct spdk_vhost_dev *vdev;
|
2017-09-11 17:45:56 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_set_vhost_ctrlr_coalescing,
|
2019-01-13 17:47:16 +00:00
|
|
|
SPDK_COUNTOF(rpc_set_vhost_ctrlr_coalescing), &req)) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
|
2017-09-11 17:45:56 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2019-01-13 17:28:46 +00:00
|
|
|
spdk_vhost_lock();
|
2019-01-13 17:47:16 +00:00
|
|
|
vdev = spdk_vhost_dev_find(req.ctrlr);
|
2019-01-13 17:28:46 +00:00
|
|
|
if (vdev == NULL) {
|
|
|
|
spdk_vhost_unlock();
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2019-01-13 17:47:16 +00:00
|
|
|
rc = spdk_vhost_set_coalescing(vdev, req.delay_base_us, req.iops_threshold);
|
2019-01-13 17:28:46 +00:00
|
|
|
spdk_vhost_unlock();
|
|
|
|
if (rc) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2019-01-13 17:47:16 +00:00
|
|
|
free_rpc_set_vhost_controllers_event_coalescing(&req);
|
2019-01-13 17:28:46 +00:00
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2017-09-11 17:45:56 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2019-01-13 17:47:16 +00:00
|
|
|
free_rpc_set_vhost_controllers_event_coalescing(&req);
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-rc));
|
2017-09-11 17:45:56 +00:00
|
|
|
}
|
2020-05-10 01:24:05 +00:00
|
|
|
SPDK_RPC_REGISTER("vhost_controller_set_coalescing", rpc_vhost_controller_set_coalescing,
|
2018-05-02 04:28:57 +00:00
|
|
|
SPDK_RPC_RUNTIME)
|
2019-09-30 12:16:22 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(vhost_controller_set_coalescing, set_vhost_controller_coalescing)
|
2017-09-11 17:45:56 +00:00
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT(vhost_rpc)
|