bdev: add remove_virtio_bdev call

Since delete_bdev should be used only for debug purpose,
this patch adds delete call specific for virtio  bdev.
This is generic call for both - blk and scsi.
Scsi specific call has been removed.

Signed-off-by: Maciej Szwed <maciej.szwed@intel.com>
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I3ed629942e9ef6067b488d94ca508b40e9e74f42
Reviewed-on: https://review.gerrithub.io/417008
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Tomasz Zawadzki 2018-07-26 10:08:16 -04:00 committed by Ben Walker
parent 3a56fabce3
commit 43fe36672b
7 changed files with 130 additions and 47 deletions

View File

@ -112,9 +112,22 @@ int bdev_virtio_pci_scsi_dev_create(const char *name, struct spdk_pci_addr *pci_
* * ENODEV - couldn't find device with given name
* * EBUSY - device is already being removed
* \param cb_arg argument for the `cb_fn`
* \return zero on success or -ENODEV if scsi dev does not exist
*/
void bdev_virtio_scsi_dev_remove(const char *name,
bdev_virtio_remove_cb cb_fn, void *cb_arg);
int bdev_virtio_scsi_dev_remove(const char *name,
bdev_virtio_remove_cb cb_fn, void *cb_arg);
/**
* Remove a Virtio device with given name.
*
* \param bdev virtio blk device bdev
* \param cb_fn function to be called after removing bdev
* \param cb_arg argument for the `cb_fn`
* \return zero on success, -ENODEV if bdev with 'name' does not exist or
* -EINVAL if bdev with 'name' is not a virtio blk device.
*/
int bdev_virtio_blk_dev_remove(const char *name,
bdev_virtio_remove_cb cb_fn, void *cb_arg);
/**
* List all created Virtio-SCSI devices.

View File

@ -241,6 +241,25 @@ bdev_virtio_disk_destruct(void *ctx)
return 0;
}
int
bdev_virtio_blk_dev_remove(const char *name, bdev_virtio_remove_cb cb_fn, void *cb_arg)
{
struct spdk_bdev *bdev;
bdev = spdk_bdev_get_by_name(name);
if (bdev == NULL) {
return -ENODEV;
}
if (bdev->module != &virtio_blk_if) {
return -ENODEV;
}
spdk_bdev_unregister(bdev, cb_fn, cb_arg);
return 0;
}
static int
bdev_virtio_dump_json_config(void *ctx, struct spdk_json_write_ctx *w)
{

View File

@ -194,35 +194,20 @@ invalid:
SPDK_RPC_REGISTER("construct_virtio_pci_scsi_bdev", spdk_rpc_construct_virtio_pci_scsi_dev,
SPDK_RPC_RUNTIME);
struct rpc_remove_virtio_scsi_dev {
struct rpc_remove_virtio_dev {
char *name;
struct spdk_jsonrpc_request *request;
};
static const struct spdk_json_object_decoder rpc_remove_virtio_scsi_dev[] = {
{"name", offsetof(struct rpc_remove_virtio_scsi_dev, name), spdk_json_decode_string },
static const struct spdk_json_object_decoder rpc_remove_virtio_dev[] = {
{"name", offsetof(struct rpc_remove_virtio_dev, name), spdk_json_decode_string },
};
static void
free_rpc_remove_virtio_scsi_dev(struct rpc_remove_virtio_scsi_dev *req)
{
if (!req) {
return;
}
free(req->name);
free(req);
}
static void
spdk_rpc_remove_virtio_scsi_bdev_cb(void *ctx, int errnum)
{
struct rpc_remove_virtio_scsi_dev *req = ctx;
struct spdk_jsonrpc_request *request = req->request;
struct spdk_jsonrpc_request *request = ctx;
struct spdk_json_write_ctx *w;
free_rpc_remove_virtio_scsi_dev(req);
if (errnum != 0) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
spdk_strerror(-errnum));
@ -242,34 +227,87 @@ static void
spdk_rpc_remove_virtio_scsi_bdev(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct rpc_remove_virtio_scsi_dev *req;
struct rpc_remove_virtio_dev req = {NULL};
int rc;
req = calloc(1, sizeof(*req));
if (!req) {
rc = -ENOMEM;
goto invalid;
}
if (spdk_json_decode_object(params, rpc_remove_virtio_scsi_dev,
SPDK_COUNTOF(rpc_remove_virtio_scsi_dev),
req)) {
if (spdk_json_decode_object(params, rpc_remove_virtio_dev,
SPDK_COUNTOF(rpc_remove_virtio_dev),
&req)) {
rc = -EINVAL;
goto invalid;
}
req->request = request;
bdev_virtio_scsi_dev_remove(req->name, spdk_rpc_remove_virtio_scsi_bdev_cb, req);
rc = bdev_virtio_scsi_dev_remove(req.name, spdk_rpc_remove_virtio_scsi_bdev_cb, request);
if (rc != 0) {
goto invalid;
}
free(req.name);
return;
invalid:
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
spdk_strerror(-rc));
free_rpc_remove_virtio_scsi_dev(req);
free(req.name);
}
SPDK_RPC_REGISTER("remove_virtio_scsi_bdev", spdk_rpc_remove_virtio_scsi_bdev, SPDK_RPC_RUNTIME);
static void
spdk_rpc_remove_virtio_bdev_cb(void *ctx, int errnum)
{
struct spdk_jsonrpc_request *request = ctx;
struct spdk_json_write_ctx *w;
if (errnum != 0) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
spdk_strerror(-errnum));
return;
}
w = spdk_jsonrpc_begin_result(request);
if (w == NULL) {
return;
}
spdk_json_write_bool(w, true);
spdk_jsonrpc_end_result(request, w);
}
static void
spdk_rpc_remove_virtio_bdev(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct rpc_remove_virtio_dev req = {NULL};
int rc;
if (spdk_json_decode_object(params, rpc_remove_virtio_dev,
SPDK_COUNTOF(rpc_remove_virtio_dev),
&req)) {
rc = -EINVAL;
goto invalid;
}
rc = bdev_virtio_blk_dev_remove(req.name, spdk_rpc_remove_virtio_bdev_cb, request);
if (rc == -ENODEV) {
rc = bdev_virtio_scsi_dev_remove(req.name, spdk_rpc_remove_virtio_bdev_cb, request);
}
if (rc != 0) {
goto invalid;
}
free(req.name);
return;
invalid:
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
spdk_strerror(-rc));
free(req.name);
}
SPDK_RPC_REGISTER("remove_virtio_bdev", spdk_rpc_remove_virtio_bdev, SPDK_RPC_RUNTIME);
static void
spdk_rpc_get_virtio_scsi_devs(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)

View File

@ -1966,7 +1966,7 @@ bdev_virtio_pci_scsi_dev_create(const char *name, struct spdk_pci_addr *pci_addr
PCI_DEVICE_ID_VIRTIO_SCSI_MODERN, pci_addr);
}
void
int
bdev_virtio_scsi_dev_remove(const char *name, bdev_virtio_remove_cb cb_fn, void *cb_arg)
{
struct virtio_scsi_dev *svdev;
@ -1981,12 +1981,13 @@ bdev_virtio_scsi_dev_remove(const char *name, bdev_virtio_remove_cb cb_fn, void
if (svdev == NULL) {
pthread_mutex_unlock(&g_virtio_scsi_mutex);
SPDK_ERRLOG("Cannot find Virtio-SCSI device named '%s'\n", name);
cb_fn(cb_arg, -ENODEV);
return;
return -ENODEV;
}
virtio_scsi_dev_remove(svdev, cb_fn, cb_arg);
pthread_mutex_unlock(&g_virtio_scsi_mutex);
return 0;
}
void

View File

@ -1536,10 +1536,20 @@ if __name__ == "__main__":
name=args.name)
p = subparsers.add_parser('remove_virtio_scsi_bdev', help="""Remove a Virtio-SCSI device
This will delete all bdevs exposed by this device""")
This will delete all bdevs exposed by this device (this call is deprecated - please use remove_virtio_bdev call instead).""")
p.add_argument('name', help='Virtio device name. E.g. VirtioUser0')
p.set_defaults(func=remove_virtio_scsi_bdev)
@call_cmd
def remove_virtio_bdev(args):
rpc.vhost.remove_virtio_bdev(args.client,
name=args.name)
p = subparsers.add_parser('remove_virtio_bdev', help="""Remove a Virtio device
This will delete all bdevs exposed by this device""")
p.add_argument('name', help='Virtio device name. E.g. VirtioUser0')
p.set_defaults(func=remove_virtio_bdev)
@call_cmd
def construct_virtio_user_blk_bdev(args):
print(rpc.vhost.construct_virtio_user_blk_bdev(args.client,

View File

@ -193,6 +193,16 @@ def remove_virtio_scsi_bdev(client, name):
return client.call('remove_virtio_scsi_bdev', params)
def remove_virtio_bdev(client, name):
"""Remove a Virtio device
This will delete all bdevs exposed by this device.
Args:
name: virtio device name
"""
params = {'name': name}
return client.call('remove_virtio_bdev', params)
def get_virtio_scsi_devs(client):
"""Get list of virtio scsi devices."""
return client.call('get_virtio_scsi_devs')

View File

@ -54,21 +54,13 @@ def get_bdev_destroy_method(bdev):
'construct_aio_bdev': "delete_aio_bdev",
'construct_error_bdev': "delete_error_bdev",
'construct_split_vbdev': "destruct_split_vbdev",
'construct_virtio_dev': {
'blk': "delete_bdev",
'scsi': "remove_virtio_scsi_bdev"
}
'construct_virtio_dev': "remove_virtio_bdev"
}
destroy_method = None
if 'method' in bdev:
construct_method = bdev['method']
if construct_method in destroy_method_map.keys():
destroy_method = destroy_method_map[construct_method]
if construct_method == 'construct_virtio_dev':
if bdev['params']['dev_type'] == 'blk':
destroy_method = destroy_method['blk']
else:
destroy_method = destroy_method['scsi']
return destroy_method