vhost: RPC: unify RPC "get_vhost_controllers" for all backends

replaced "get_vhost_scsi_controllers" and "get_vhost_blk_controllers"
with "get_vhost_controllers"

Change-Id: I4988313e311e5b66632d8e216bde209c8ea5e318
Signed-off-by: Pawel Niedzwiecki<pawelx.niedzwiecki@intel.com>
Reviewed-on: https://review.gerrithub.io/369399
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Pawel 2017-07-13 16:37:50 +02:00 committed by Daniel Verkamp
parent fcfa6f3432
commit 83c2b65a4f
7 changed files with 111 additions and 138 deletions

View File

@ -346,6 +346,7 @@ spdk_vhost_dev_construct(struct spdk_vhost_dev *vdev, const char *name, uint64_t
vdev->lcore = -1;
vdev->cpumask = cpumask;
vdev->type = type;
vdev->vhost_backend = backend;
g_spdk_vhost_devices[ctrlr_num] = vdev;
@ -703,4 +704,11 @@ spdk_vhost_timed_event_wait(struct spdk_vhost_timed_event *ev, const char *errms
sem_destroy(&ev->sem);
}
void
spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
{
assert(vdev->vhost_backend->dump_config_json != NULL);
vdev->vhost_backend->dump_config_json(vdev, w);
}
SPDK_LOG_REGISTER_TRACE_FLAG("vhost_ring", SPDK_TRACE_VHOST_RING)

View File

@ -428,15 +428,6 @@ spdk_vhost_blk_get_dev(struct spdk_vhost_dev *vdev)
return bvdev->bdev;
}
bool
spdk_vhost_blk_get_readonly(struct spdk_vhost_dev *vdev)
{
struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev);
assert(bvdev != NULL);
return bvdev->readonly;
}
static void
bdev_remove_cb(void *remove_ctx)
{
@ -517,6 +508,29 @@ destroy_device(int vid)
spdk_vhost_dev_unload(vdev);
}
static void
spdk_vhost_blk_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
{
struct spdk_bdev *bdev = spdk_vhost_blk_get_dev(vdev);
struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev);
assert(bvdev != NULL);
spdk_json_write_name(w, "block");
spdk_json_write_object_begin(w);
spdk_json_write_name(w, "readonly");
spdk_json_write_bool(w, bvdev->readonly);
spdk_json_write_name(w, "bdev");
if (bdev) {
spdk_json_write_string(w, spdk_bdev_get_name(bdev));
} else {
spdk_json_write_null(w);
}
spdk_json_write_object_end(w);
}
static const struct spdk_vhost_dev_backend vhost_blk_device_backend = {
.virtio_features = (1ULL << VHOST_F_LOG_ALL) | (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) |
(1ULL << VIRTIO_F_VERSION_1) | (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) |
@ -528,6 +542,7 @@ static const struct spdk_vhost_dev_backend vhost_blk_device_backend = {
.disabled_features = (1ULL << VHOST_F_LOG_ALL) | (1ULL << VIRTIO_BLK_F_GEOMETRY) |
(1ULL << VIRTIO_BLK_F_RO) | (1ULL << VIRTIO_BLK_F_FLUSH) | (1ULL << VIRTIO_BLK_F_CONFIG_WCE) |
(1ULL << VIRTIO_BLK_F_BARRIER) | (1ULL << VIRTIO_BLK_F_SCSI),
.dump_config_json = spdk_vhost_blk_dump_config_json,
.ops = {
.new_device = new_device,
.destroy_device = destroy_device,

View File

@ -40,6 +40,7 @@
#include "spdk_internal/log.h"
#include "spdk/event.h"
#include "spdk/rpc.h"
#define SPDK_CACHE_LINE_SIZE RTE_CACHE_LINE_SIZE
@ -66,6 +67,13 @@ enum spdk_vhost_dev_type {
SPDK_VHOST_DEV_T_BLK,
};
struct spdk_vhost_dev_backend {
uint64_t virtio_features;
uint64_t disabled_features;
void (*dump_config_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
const struct vhost_device_ops ops;
};
struct spdk_vhost_dev {
struct rte_vhost_memory *mem;
char *name;
@ -82,13 +90,7 @@ struct spdk_vhost_dev {
uint64_t negotiated_features;
struct rte_vhost_vring virtqueue[SPDK_VHOST_MAX_VQUEUES] __attribute((aligned(
SPDK_CACHE_LINE_SIZE)));
};
struct spdk_vhost_dev_backend {
uint64_t virtio_features;
uint64_t disabled_features;
const struct vhost_device_ops ops;
const struct spdk_vhost_dev_backend *vhost_backend;
};
void spdk_vhost_dev_mem_register(struct spdk_vhost_dev *vdev);
@ -145,5 +147,6 @@ void spdk_vhost_timed_event_send(int32_t lcore, spdk_vhost_timed_event_fn cn_fn,
void spdk_vhost_timed_event_wait(struct spdk_vhost_timed_event *event, const char *errmsg);
int spdk_vhost_blk_controller_construct(void);
void spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
#endif /* SPDK_VHOST_INTERNAL_H */

View File

@ -42,99 +42,6 @@
#include "vhost_internal.h"
#include "spdk/bdev.h"
static void
json_scsi_dev_write(struct spdk_json_write_ctx *ctx, struct spdk_scsi_dev *dev)
{
int l;
spdk_json_write_name(ctx, "id");
spdk_json_write_int32(ctx, spdk_scsi_dev_get_id(dev));
spdk_json_write_name(ctx, "device_name");
spdk_json_write_string(ctx, spdk_scsi_dev_get_name(dev));
spdk_json_write_name(ctx, "luns");
spdk_json_write_array_begin(ctx);
for (l = 0; l < SPDK_SCSI_DEV_MAX_LUN; l++) {
struct spdk_scsi_lun *lun = spdk_scsi_dev_get_lun(dev, l);
if (!lun) {
continue;
}
spdk_json_write_object_begin(ctx);
spdk_json_write_name(ctx, "id");
spdk_json_write_int32(ctx, spdk_scsi_lun_get_id(lun));
spdk_json_write_name(ctx, "lun_name");
spdk_json_write_string(ctx, spdk_scsi_lun_get_name(lun));
spdk_json_write_object_end(ctx);
}
spdk_json_write_array_end(ctx);
}
static void
spdk_rpc_get_vhost_scsi_controllers(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct spdk_json_write_ctx *w;
struct spdk_vhost_dev *vdev = NULL;
struct spdk_scsi_dev *dev;
uint32_t i;
if (params != NULL) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
"get_vhost_scsi_controllers requires no parameters");
return;
}
w = spdk_jsonrpc_begin_result(request);
if (w == NULL) {
return;
}
spdk_json_write_array_begin(w);
while ((vdev = spdk_vhost_dev_next(vdev)) != NULL) {
if (vdev->type != SPDK_VHOST_DEV_T_SCSI) {
continue;
}
spdk_json_write_object_begin(w);
spdk_json_write_name(w, "ctrlr");
spdk_json_write_string(w, spdk_vhost_dev_get_name(vdev));
spdk_json_write_name(w, "cpumask");
spdk_json_write_string_fmt(w, "%#" PRIx64, spdk_vhost_dev_get_cpumask(vdev));
spdk_json_write_name(w, "scsi_devs");
spdk_json_write_array_begin(w);
for (i = 0; i < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; i++) {
dev = spdk_vhost_scsi_dev_get_dev(vdev, i);
if (!dev)
continue;
spdk_json_write_object_begin(w);
spdk_json_write_name(w, "scsi_dev_num");
spdk_json_write_uint32(w, i);
json_scsi_dev_write(w, dev);
spdk_json_write_object_end(w);
}
spdk_json_write_array_end(w); // devs
spdk_json_write_object_end(w); // ctrl
}
spdk_json_write_array_end(w);
spdk_jsonrpc_end_result(request, w);
return;
}
SPDK_RPC_REGISTER("get_vhost_scsi_controllers", spdk_rpc_get_vhost_scsi_controllers)
struct rpc_vhost_scsi_ctrlr {
char *ctrlr;
char *cpumask;
@ -502,17 +409,15 @@ invalid:
SPDK_RPC_REGISTER("remove_vhost_blk_controller", spdk_rpc_remove_vhost_blk_controller)
static void
spdk_rpc_get_vhost_blk_controllers(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
spdk_rpc_get_vhost_controllers(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct spdk_json_write_ctx *w;
struct spdk_vhost_dev *vdev = NULL;
struct spdk_bdev *bdev;
if (params != NULL) {
spdk_jsonrpc_send_error_response(request,
SPDK_JSONRPC_ERROR_INVALID_PARAMS,
"get_vhost_block_controllers requires no parameters");
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
"get_vhost_controllers requires no parameters");
return;
}
@ -523,8 +428,6 @@ spdk_rpc_get_vhost_blk_controllers(struct spdk_jsonrpc_request *request,
spdk_json_write_array_begin(w);
while ((vdev = spdk_vhost_dev_next(vdev)) != NULL) {
if (vdev->type != SPDK_VHOST_DEV_T_BLK)
continue;
spdk_json_write_object_begin(w);
spdk_json_write_name(w, "ctrlr");
@ -533,19 +436,16 @@ spdk_rpc_get_vhost_blk_controllers(struct spdk_jsonrpc_request *request,
spdk_json_write_name(w, "cpumask");
spdk_json_write_string_fmt(w, "%#" PRIx64, spdk_vhost_dev_get_cpumask(vdev));
spdk_json_write_name(w, "readonly");
spdk_json_write_bool(w, spdk_vhost_blk_get_readonly(vdev));
spdk_json_write_name(w, "backend_specific");
bdev = spdk_vhost_blk_get_dev(vdev);
spdk_json_write_name(w, "dev_name");
if (bdev)
spdk_json_write_string(w, spdk_bdev_get_name(bdev));
else
spdk_json_write_null(w);
spdk_json_write_object_begin(w);
spdk_vhost_dump_config_json(vdev, w);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
}
spdk_json_write_array_end(w);
spdk_jsonrpc_end_result(request, w);
}
SPDK_RPC_REGISTER("get_vhost_blk_controllers", spdk_rpc_get_vhost_blk_controllers)
SPDK_RPC_REGISTER("get_vhost_controllers", spdk_rpc_get_vhost_controllers)

View File

@ -114,10 +114,12 @@ struct spdk_vhost_scsi_event {
static int new_device(int vid);
static void destroy_device(int vid);
static void spdk_vhost_scsi_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
const struct spdk_vhost_dev_backend spdk_vhost_scsi_device_backend = {
.virtio_features = SPDK_VHOST_SCSI_FEATURES,
.disabled_features = SPDK_VHOST_SCSI_DISABLED_FEATURES,
.dump_config_json = spdk_vhost_scsi_config_json,
.ops = {
.new_device = new_device,
.destroy_device = destroy_device,
@ -1203,6 +1205,58 @@ spdk_vhost_fini(void)
return 0;
}
static void
spdk_vhost_scsi_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
{
struct spdk_scsi_dev *sdev;
struct spdk_scsi_lun *lun;
uint32_t dev_idx;
uint32_t lun_idx;
assert(vdev != NULL);
spdk_json_write_name(w, "scsi");
spdk_json_write_object_begin(w);
for (dev_idx = 0; dev_idx < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; dev_idx++) {
sdev = spdk_vhost_scsi_dev_get_dev(vdev, dev_idx);
if (!sdev) {
continue;
}
spdk_json_write_name(w, "scsi_dev_num");
spdk_json_write_uint32(w, dev_idx);
spdk_json_write_name(w, "id");
spdk_json_write_int32(w, spdk_scsi_dev_get_id(sdev));
spdk_json_write_name(w, "device_name");
spdk_json_write_string(w, spdk_scsi_dev_get_name(sdev));
spdk_json_write_name(w, "luns");
spdk_json_write_array_begin(w);
for (lun_idx = 0; lun_idx < SPDK_SCSI_DEV_MAX_LUN; lun_idx++) {
lun = spdk_scsi_dev_get_lun(sdev, lun_idx);
if (!lun) {
continue;
}
spdk_json_write_object_begin(w);
spdk_json_write_name(w, "id");
spdk_json_write_int32(w, spdk_scsi_lun_get_id(lun));
spdk_json_write_name(w, "name");
spdk_json_write_string(w, spdk_scsi_lun_get_name(lun));
spdk_json_write_object_end(w);
}
spdk_json_write_array_end(w);
}
spdk_json_write_object_end(w);
}
SPDK_LOG_REGISTER_TRACE_FLAG("vhost_scsi", SPDK_TRACE_VHOST_SCSI)
SPDK_LOG_REGISTER_TRACE_FLAG("vhost_scsi_queue", SPDK_TRACE_VHOST_SCSI_QUEUE)
SPDK_LOG_REGISTER_TRACE_FLAG("vhost_scsi_data", SPDK_TRACE_VHOST_SCSI_DATA)

View File

@ -470,12 +470,6 @@ p = subparsers.add_parser('kill_instance', help='Send signal to instance')
p.add_argument('sig_name', help='signal will be sent to server.')
p.set_defaults(func=kill_instance)
def get_vhost_scsi_controllers(args):
print_dict(jsonrpc_call('get_vhost_scsi_controllers'))
p = subparsers.add_parser('get_vhost_scsi_controllers', help='List vhost controllers')
p.set_defaults(func=get_vhost_scsi_controllers)
def construct_vhost_scsi_controller(args):
params = {'ctrlr': args.ctrlr}
@ -549,11 +543,11 @@ p = subparsers.add_parser('remove_vhost_blk_controller', help='Remove a vhost bl
p.add_argument('ctrlr', help='controller name')
p.set_defaults(func=remove_vhost_blk_controller)
def get_vhost_blk_controllers(args):
print_dict(jsonrpc_call('get_vhost_blk_controllers'))
def get_vhost_controllers(args):
print_dict(jsonrpc_call('get_vhost_controllers'))
p = subparsers.add_parser('get_vhost_blk_controllers', help='List vhost block controllers')
p.set_defaults(func=get_vhost_blk_controllers)
p = subparsers.add_parser('get_vhost_controllers', help='List vhost controllers')
p.set_defaults(func=get_vhost_controllers)
def get_rpc_methods(args):
print_dict(jsonrpc_call('get_rpc_methods'))

View File

@ -198,8 +198,7 @@ for vm_conf in ${vms[@]}; do
done
done <<< "${conf[2]}"
unset IFS;
$rpc_py get_vhost_scsi_controllers
$rpc_py get_vhost_blk_controllers
$rpc_py get_vhost_controllers
fi
$setup_cmd
done