rpc/vhost: unify RPC "remove_vhost_controller" for all backends

replaced "remove_vhost_scsi_controller" and "remove_vhost_blk_controller"
with "remove_vhost_controller".

Change-Id: I6f4b180054c13f25aae992e9be50375d3750a376
Signed-off-by: Pawel Niedzwiecki <pawelx.niedzwiecki@intel.com>
Reviewed-on: https://review.gerrithub.io/377197
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:
Pawel Niedzwiecki 2017-09-05 20:23:43 +02:00 committed by Jim Harris
parent 65b6d8f495
commit c63d9de433
8 changed files with 48 additions and 126 deletions

View File

@ -822,12 +822,19 @@ spdk_vhost_shutdown_cb(void)
}
void
spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev,
struct spdk_json_write_ctx *w)
{
assert(vdev->backend->dump_config_json != NULL);
vdev->backend->dump_config_json(vdev, w);
}
int
spdk_remove_vhost_controller(struct spdk_vhost_dev *vdev)
{
return vdev->backend->vhost_remove_controller(vdev);
}
static int
new_connection(int vid)
{

View File

@ -623,6 +623,7 @@ static const struct spdk_vhost_dev_backend vhost_blk_device_backend = {
.new_device = new_device,
.destroy_device = destroy_device,
.dump_config_json = spdk_vhost_blk_dump_config_json,
.vhost_remove_controller = spdk_vhost_blk_destroy,
};
int

View File

@ -99,6 +99,7 @@ struct spdk_vhost_dev_backend {
spdk_vhost_event_fn destroy_device;
void (*dump_config_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
int (*vhost_remove_controller)(struct spdk_vhost_dev *vdev);
};
struct spdk_vhost_dev {
@ -151,5 +152,6 @@ void spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_w
void spdk_vhost_dev_backend_event_done(void *event_ctx, int response);
void spdk_vhost_lock(void);
void spdk_vhost_unlock(void);
int spdk_remove_vhost_controller(struct spdk_vhost_dev *vdev);
#endif /* SPDK_VHOST_INTERNAL_H */

View File

@ -101,91 +101,6 @@ invalid:
}
SPDK_RPC_REGISTER("construct_vhost_scsi_controller", spdk_rpc_construct_vhost_scsi_controller)
struct rpc_remove_vhost_scsi_ctrlr {
char *ctrlr;
struct spdk_jsonrpc_request *request;
};
static void
free_rpc_remove_vhost_scsi_ctrlr(struct rpc_remove_vhost_scsi_ctrlr *req)
{
free(req->ctrlr);
free(req);
}
static const struct spdk_json_object_decoder rpc_remove_vhost_ctrlr[] = {
{"ctrlr", offsetof(struct rpc_remove_vhost_scsi_ctrlr, ctrlr), spdk_json_decode_string },
};
static int
spdk_rpc_remove_vhost_scsi_controller_cb(struct spdk_vhost_dev *vdev, void *arg)
{
struct rpc_remove_vhost_scsi_ctrlr *ctx = arg;
struct spdk_jsonrpc_request *request = ctx->request;
struct spdk_json_write_ctx *w;
int rc;
char buf[64];
rc = spdk_vhost_scsi_dev_remove(vdev);
if (rc < 0) {
goto invalid;
}
free_rpc_remove_vhost_scsi_ctrlr(ctx);
w = spdk_jsonrpc_begin_result(request);
if (w == NULL) {
return 0;
}
spdk_json_write_bool(w, true);
spdk_jsonrpc_end_result(request, w);
return 0;
invalid:
free_rpc_remove_vhost_scsi_ctrlr(ctx);
spdk_strerror_r(-rc, buf, sizeof(buf));
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf);
return -1;
}
static void
spdk_rpc_remove_vhost_scsi_controller(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct rpc_remove_vhost_scsi_ctrlr *req;
char buf[64];
int rc;
req = calloc(1, sizeof(*req));
if (req == NULL) {
rc = -ENOMEM;
goto invalid;
}
req->request = request;
if (spdk_json_decode_object(params, rpc_remove_vhost_ctrlr,
SPDK_COUNTOF(rpc_remove_vhost_ctrlr),
req)) {
SPDK_DEBUGLOG(SPDK_TRACE_VHOST_RPC, "spdk_json_decode_object failed\n");
rc = -EINVAL;
goto invalid;
}
spdk_vhost_call_external_event(req->ctrlr, spdk_rpc_remove_vhost_scsi_controller_cb, req);
return;
invalid:
if (req) {
free_rpc_remove_vhost_scsi_ctrlr(req);
}
spdk_strerror_r(-rc, buf, sizeof(buf));
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf);
}
SPDK_RPC_REGISTER("remove_vhost_scsi_controller", spdk_rpc_remove_vhost_scsi_controller)
struct rpc_add_vhost_scsi_ctrlr_lun {
char *ctrlr;
uint32_t scsi_dev_num;
@ -454,38 +369,43 @@ invalid:
}
SPDK_RPC_REGISTER("construct_vhost_blk_controller", spdk_rpc_construct_vhost_blk_controller)
struct rpc_remove_vhost_blk_ctrlr {
struct rpc_remove_vhost_ctrlr {
char *ctrlr;
struct spdk_jsonrpc_request *request;
};
static const struct spdk_json_object_decoder rpc_remove_vhost_blk_ctrlr[] = {
{"ctrlr", offsetof(struct rpc_remove_vhost_blk_ctrlr, ctrlr), spdk_json_decode_string },
static const struct spdk_json_object_decoder rpc_remove_vhost_ctrlr[] = {
{"ctrlr", offsetof(struct rpc_remove_vhost_ctrlr, ctrlr), spdk_json_decode_string },
};
static void
free_rpc_remove_vhost_blk_ctrlr(struct rpc_remove_vhost_blk_ctrlr *req)
free_rpc_remove_vhost_ctrlr(struct rpc_remove_vhost_ctrlr *req)
{
free(req->ctrlr);
free(req);
}
static int
spdk_rpc_remove_vhost_blk_controller_cb(struct spdk_vhost_dev *vdev, void *arg)
spdk_rpc_remove_vhost_controller_cb(struct spdk_vhost_dev *vdev, void *arg)
{
struct rpc_remove_vhost_blk_ctrlr *ctx = arg;
struct rpc_remove_vhost_ctrlr *ctx = arg;
struct spdk_jsonrpc_request *request = ctx->request;
struct spdk_json_write_ctx *w;
int rc;
char buf[64];
rc = spdk_vhost_blk_destroy(vdev);
if (vdev == NULL) {
rc = -ENODEV;
goto invalid;
}
rc = spdk_remove_vhost_controller(vdev);
if (rc < 0) {
goto invalid;
}
free_rpc_remove_vhost_blk_ctrlr(ctx);
free_rpc_remove_vhost_ctrlr(ctx);
w = spdk_jsonrpc_begin_result(request);
if (w == NULL) {
@ -497,7 +417,7 @@ spdk_rpc_remove_vhost_blk_controller_cb(struct spdk_vhost_dev *vdev, void *arg)
return 0;
invalid:
free_rpc_remove_vhost_blk_ctrlr(ctx);
free_rpc_remove_vhost_ctrlr(ctx);
spdk_strerror_r(-rc, buf, sizeof(buf));
spdk_jsonrpc_send_error_response(request,
SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf);
@ -505,10 +425,10 @@ invalid:
}
static void
spdk_rpc_remove_vhost_blk_controller(struct spdk_jsonrpc_request *request,
spdk_rpc_remove_vhost_controller(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct rpc_remove_vhost_blk_ctrlr *req;
struct rpc_remove_vhost_ctrlr *req;
char buf[64];
int rc;
@ -519,26 +439,26 @@ spdk_rpc_remove_vhost_blk_controller(struct spdk_jsonrpc_request *request,
}
req->request = request;
if (spdk_json_decode_object(params, rpc_remove_vhost_blk_ctrlr,
SPDK_COUNTOF(rpc_remove_vhost_blk_ctrlr), req)) {
if (spdk_json_decode_object(params, rpc_remove_vhost_ctrlr,
SPDK_COUNTOF(rpc_remove_vhost_ctrlr), req)) {
SPDK_DEBUGLOG(SPDK_TRACE_VHOST_RPC, "spdk_json_decode_object failed\n");
rc = -EINVAL;
goto invalid;
}
spdk_vhost_call_external_event(req->ctrlr, spdk_rpc_remove_vhost_blk_controller_cb, req);
spdk_vhost_call_external_event(req->ctrlr, spdk_rpc_remove_vhost_controller_cb, req);
return;
invalid:
if (req) {
free_rpc_remove_vhost_blk_ctrlr(req);
free_rpc_remove_vhost_ctrlr(req);
}
spdk_strerror_r(-rc, buf, sizeof(buf));
spdk_jsonrpc_send_error_response(request,
SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf);
}
SPDK_RPC_REGISTER("remove_vhost_blk_controller", spdk_rpc_remove_vhost_blk_controller)
SPDK_RPC_REGISTER("remove_vhost_controller", spdk_rpc_remove_vhost_controller)
static void
spdk_rpc_get_vhost_controllers(struct spdk_jsonrpc_request *request,

View File

@ -109,6 +109,7 @@ const struct spdk_vhost_dev_backend spdk_vhost_scsi_device_backend = {
.new_device = new_device,
.destroy_device = destroy_device,
.dump_config_json = spdk_vhost_scsi_config_json,
.vhost_remove_controller = spdk_vhost_scsi_dev_remove,
};
static void

View File

@ -555,14 +555,6 @@ p.add_argument('ctrlr', help='controller name')
p.add_argument('--cpumask', help='cpu mask for this controller')
p.set_defaults(func=construct_vhost_scsi_controller)
def remove_vhost_scsi_controller(args):
params = {'ctrlr': args.ctrlr}
jsonrpc_call('remove_vhost_scsi_controller', params)
p = subparsers.add_parser('remove_vhost_scsi_controller', help='Remove vhost controller')
p.add_argument('ctrlr', help='controller name')
p.set_defaults(func=remove_vhost_scsi_controller)
def add_vhost_scsi_lun(args):
params = {
'ctrlr': args.ctrlr,
@ -607,20 +599,20 @@ p.add_argument('--cpumask', help='cpu mask for this controller')
p.add_argument("-r", "--readonly", action='store_true', help='Set controller as read-only')
p.set_defaults(func=construct_vhost_blk_controller)
def remove_vhost_blk_controller(args):
params = {'ctrlr': args.ctrlr}
jsonrpc_call('remove_vhost_blk_controller', params)
p = subparsers.add_parser('remove_vhost_blk_controller', help='Remove a vhost block controller')
p.add_argument('ctrlr', help='controller name')
p.set_defaults(func=remove_vhost_blk_controller)
def get_vhost_controllers(args):
print_dict(jsonrpc_call('get_vhost_controllers'))
p = subparsers.add_parser('get_vhost_controllers', help='List vhost controllers')
p.set_defaults(func=get_vhost_controllers)
def remove_vhost_controller(args):
params = {'ctrlr': args.ctrlr}
jsonrpc_call('remove_vhost_controller', params)
p = subparsers.add_parser('remove_vhost_controller', help='Remove a vhost controller')
p.add_argument('ctrlr', help='controller name')
p.set_defaults(func=remove_vhost_controller)
def get_rpc_methods(args):
print_dict(jsonrpc_call('get_rpc_methods'))

View File

@ -168,7 +168,7 @@ for vm_conf in ${vms[@]}; do
$rpc_py construct_vhost_blk_controller naa.$disk.${conf[0]} $disk
else
echo "INFO: Trying to remove nonexistent controller"
if $rpc_py remove_vhost_scsi_controller unk0 > /dev/null; then
if $rpc_py remove_vhost_controller unk0 > /dev/null; then
echo "ERROR: Removing nonexistent controller succeeded, but it shouldn't"
false
fi
@ -354,12 +354,11 @@ if ! $no_shutdown; then
for disk in "${disks[@]}"; do
disk=${disk%%_*}
echo "INFO: Removing all vhost devices from controller naa.$disk.${conf[0]}"
if [[ "$test_type" == "spdk_vhost_blk" ]]; then
$rpc_py remove_vhost_blk_controller naa.$disk.${conf[0]}
else
if [[ "$test_type" == "spdk_vhost_scsi" ]]; then
$rpc_py remove_vhost_scsi_dev naa.$disk.${conf[0]} 0
$rpc_py remove_vhost_scsi_controller naa.$disk.${conf[0]}
fi
$rpc_py remove_vhost_controller naa.$disk.${conf[0]}
done
done <<< "${conf[2]}"
done

View File

@ -223,13 +223,13 @@ if [[ "$ctrl_type" == "vhost_scsi" ]]; then
echo -e "\tINFO: Removed device $j"
done
echo "Removing vhost SCSI controller naa.0.$i"
$rpc_py remove_vhost_scsi_controller naa.0.$i
$rpc_py remove_vhost_controller naa.0.$i
done
elif [[ "$ctrl_type" == "vhost_blk" ]]; then
for (( i=0; i<$vm_count; i++)); do
for (( j=0; j<${#bdevs[@]}; j++)); do
echo "INFO: Removing vhost BLK controller naa.$j.$i"
$rpc_py remove_vhost_blk_controller naa.$j.$i
$rpc_py remove_vhost_controller naa.$j.$i
echo -e "\tINFO: Removed naa.$j.$i"
done
done