bdev: add delete_passthru_bdev call
Since delete_bdev should be used only for debug purpose, this patch adds delete call specific for passthru bdev. Signed-off-by: Maciej Szwed <maciej.szwed@intel.com> Change-Id: I8ea20b3003dd6539d84123c3b5363bd8bdfd6f7f Reviewed-on: https://review.gerrithub.io/416535 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
1a0ce4ded0
commit
e48f0bf17d
@ -569,6 +569,17 @@ create_passthru_disk(const char *bdev_name, const char *vbdev_name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
delete_passthru_disk(struct spdk_bdev *bdev, spdk_delete_passthru_complete cb_fn, void *cb_arg)
|
||||
{
|
||||
if (!bdev || bdev->module != &passthru_if) {
|
||||
cb_fn(cb_arg, -ENODEV);
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_bdev_unregister(bdev, cb_fn, cb_arg);
|
||||
}
|
||||
|
||||
/* Because we specified this function in our pt bdev function table when we
|
||||
* registered our pt bdev, we'll get this call anytime a new bdev shows up.
|
||||
* Here we need to decide if we care about it and if so what to do. We
|
||||
|
@ -38,6 +38,25 @@
|
||||
|
||||
#include "spdk/bdev.h"
|
||||
|
||||
typedef void (*spdk_delete_passthru_complete)(void *cb_arg, int bdeverrno);
|
||||
|
||||
/**
|
||||
* Create new pass through bdev.
|
||||
*
|
||||
* \param bdev_name Bdev on which pass through vbdev will be created.
|
||||
* \param vbdev_name Vbdev name.
|
||||
* \return 0 on success, other on failure.
|
||||
*/
|
||||
int create_passthru_disk(const char *bdev_name, const char *vbdev_name);
|
||||
|
||||
/**
|
||||
* Delete passthru bdev.
|
||||
*
|
||||
* \param bdev Pointer to pass through bdev.
|
||||
* \param cb_fn Function to call after deletion.
|
||||
* \param cb_arg Argument to pass to cb_fn.
|
||||
*/
|
||||
void delete_passthru_disk(struct spdk_bdev *bdev, spdk_delete_passthru_complete cb_fn,
|
||||
void *cb_arg);
|
||||
|
||||
#endif /* SPDK_VBDEV_PASSTHRU_H */
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "vbdev_passthru.h"
|
||||
#include "spdk/rpc.h"
|
||||
#include "spdk/util.h"
|
||||
|
||||
#include "spdk/string.h"
|
||||
#include "spdk_internal/log.h"
|
||||
|
||||
/* Structure to hold the parameters for this RPC method. */
|
||||
@ -96,3 +96,65 @@ invalid:
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_passthru_bdev", spdk_rpc_construct_passthru_bdev, SPDK_RPC_RUNTIME)
|
||||
|
||||
struct rpc_delete_passthru {
|
||||
char *name;
|
||||
};
|
||||
|
||||
static void
|
||||
free_rpc_delete_passthru(struct rpc_delete_passthru *req)
|
||||
{
|
||||
free(req->name);
|
||||
}
|
||||
|
||||
static const struct spdk_json_object_decoder rpc_delete_passthru_decoders[] = {
|
||||
{"name", offsetof(struct rpc_delete_passthru, name), spdk_json_decode_string},
|
||||
};
|
||||
|
||||
static void
|
||||
_spdk_rpc_delete_passthru_bdev_cb(void *cb_arg, int bdeverrno)
|
||||
{
|
||||
struct spdk_jsonrpc_request *request = cb_arg;
|
||||
struct spdk_json_write_ctx *w;
|
||||
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_bool(w, bdeverrno == 0);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_rpc_delete_passthru_bdev(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_delete_passthru req = {NULL};
|
||||
struct spdk_bdev *bdev;
|
||||
int rc;
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_delete_passthru_decoders,
|
||||
SPDK_COUNTOF(rpc_delete_passthru_decoders),
|
||||
&req)) {
|
||||
rc = -EINVAL;
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
bdev = spdk_bdev_get_by_name(req.name);
|
||||
if (bdev == NULL) {
|
||||
rc = -ENODEV;
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
delete_passthru_disk(bdev, _spdk_rpc_delete_passthru_bdev_cb, request);
|
||||
|
||||
free_rpc_delete_passthru(&req);
|
||||
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free_rpc_delete_passthru(&req);
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(-rc));
|
||||
}
|
||||
SPDK_RPC_REGISTER("delete_passthru_bdev", spdk_rpc_delete_passthru_bdev, SPDK_RPC_RUNTIME)
|
||||
|
@ -330,9 +330,18 @@ if __name__ == "__main__":
|
||||
p = subparsers.add_parser('construct_passthru_bdev',
|
||||
help='Add a pass through bdev on existing bdev')
|
||||
p.add_argument('-b', '--base-bdev-name', help="Name of the existing bdev", required=True)
|
||||
p.add_argument('-p', '--passthru-bdev-name', help="Name of the passthru bdev", required=True)
|
||||
p.add_argument('-p', '--passthru-bdev-name', help="Name of the pass through bdev", required=True)
|
||||
p.set_defaults(func=construct_passthru_bdev)
|
||||
|
||||
@call_cmd
|
||||
def delete_passthru_bdev(args):
|
||||
rpc.bdev.delete_passthru_bdev(args.client,
|
||||
name=args.name)
|
||||
|
||||
p = subparsers.add_parser('delete_passthru_bdev', help='Delete a pass through bdev')
|
||||
p.add_argument('name', help='pass through bdev name')
|
||||
p.set_defaults(func=delete_passthru_bdev)
|
||||
|
||||
@call_cmd
|
||||
def get_bdevs(args):
|
||||
print_dict(rpc.bdev.get_bdevs(args.client,
|
||||
|
@ -261,6 +261,16 @@ def construct_passthru_bdev(client, base_bdev_name, passthru_bdev_name):
|
||||
return client.call('construct_passthru_bdev', params)
|
||||
|
||||
|
||||
def delete_passthru_bdev(client, name):
|
||||
"""Remove pass through bdev from the system.
|
||||
|
||||
Args:
|
||||
name: name of pass through bdev to delete
|
||||
"""
|
||||
params = {'name': name}
|
||||
return client.call('delete_passthru_bdev', params)
|
||||
|
||||
|
||||
def construct_split_vbdev(client, base_bdev, split_count, split_size_mb=None):
|
||||
"""Construct split block devices from a base bdev.
|
||||
|
||||
|
@ -5,6 +5,7 @@ set -e
|
||||
testdir=$(readlink -f $(dirname $0))
|
||||
rootdir=$(readlink -f $testdir/../..)
|
||||
plugindir=$rootdir/examples/bdev/fio_plugin
|
||||
rpc_py="python $rootdir/scripts/rpc.py"
|
||||
|
||||
function run_fio()
|
||||
{
|
||||
@ -42,6 +43,8 @@ function nbd_function_test() {
|
||||
|
||||
nbd_rpc_data_verify $rpc_server "${bdev_list[*]}" "${nbd_list[*]}"
|
||||
|
||||
$rpc_py -s $rpc_server delete_passthru_bdev TestPT
|
||||
|
||||
killprocess $nbd_pid
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user