bdev/rbd: add JSON config dump
Change-Id: I3122c899f76c1ce1eb422bcf73af87d1b41b9364 Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-on: https://review.gerrithub.io/401223 Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
parent
e301860fb3
commit
13a05f59cc
@ -557,16 +557,36 @@ bdev_rbd_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bdev_rbd_write_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w)
|
||||||
|
{
|
||||||
|
struct bdev_rbd *rbd = bdev->ctxt;
|
||||||
|
|
||||||
|
spdk_json_write_object_begin(w);
|
||||||
|
|
||||||
|
spdk_json_write_named_string(w, "method", "construct_rbd_bdev");
|
||||||
|
|
||||||
|
spdk_json_write_named_object_begin(w, "params");
|
||||||
|
spdk_json_write_named_string(w, "name", bdev->name);
|
||||||
|
spdk_json_write_named_string(w, "pool_name", rbd->pool_name);
|
||||||
|
spdk_json_write_named_string(w, "rbd_name", rbd->rbd_name);
|
||||||
|
spdk_json_write_object_end(w);
|
||||||
|
|
||||||
|
spdk_json_write_object_end(w);
|
||||||
|
}
|
||||||
|
|
||||||
static const struct spdk_bdev_fn_table rbd_fn_table = {
|
static const struct spdk_bdev_fn_table rbd_fn_table = {
|
||||||
.destruct = bdev_rbd_destruct,
|
.destruct = bdev_rbd_destruct,
|
||||||
.submit_request = bdev_rbd_submit_request,
|
.submit_request = bdev_rbd_submit_request,
|
||||||
.io_type_supported = bdev_rbd_io_type_supported,
|
.io_type_supported = bdev_rbd_io_type_supported,
|
||||||
.get_io_channel = bdev_rbd_get_io_channel,
|
.get_io_channel = bdev_rbd_get_io_channel,
|
||||||
.dump_info_json = bdev_rbd_dump_info_json,
|
.dump_info_json = bdev_rbd_dump_info_json,
|
||||||
|
.write_config_json = bdev_rbd_write_config_json,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct spdk_bdev *
|
struct spdk_bdev *
|
||||||
spdk_bdev_rbd_create(const char *pool_name, const char *rbd_name, uint32_t block_size)
|
spdk_bdev_rbd_create(const char *name, const char *pool_name, const char *rbd_name,
|
||||||
|
uint32_t block_size)
|
||||||
{
|
{
|
||||||
struct bdev_rbd *rbd;
|
struct bdev_rbd *rbd;
|
||||||
int ret;
|
int ret;
|
||||||
@ -600,7 +620,11 @@ spdk_bdev_rbd_create(const char *pool_name, const char *rbd_name, uint32_t block
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rbd->disk.name = spdk_sprintf_alloc("Ceph%d", bdev_rbd_count);
|
if (name) {
|
||||||
|
rbd->disk.name = strdup(name);
|
||||||
|
} else {
|
||||||
|
rbd->disk.name = spdk_sprintf_alloc("Ceph%d", bdev_rbd_count);
|
||||||
|
}
|
||||||
if (!rbd->disk.name) {
|
if (!rbd->disk.name) {
|
||||||
bdev_rbd_free(rbd);
|
bdev_rbd_free(rbd);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -684,7 +708,7 @@ bdev_rbd_library_init(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spdk_bdev_rbd_create(pool_name, rbd_name, block_size) == NULL) {
|
if (spdk_bdev_rbd_create(NULL, pool_name, rbd_name, block_size) == NULL) {
|
||||||
rc = -1;
|
rc = -1;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
#include "spdk/bdev.h"
|
#include "spdk/bdev.h"
|
||||||
|
|
||||||
struct spdk_bdev *spdk_bdev_rbd_create(const char *pool_name, const char *rbd_name,
|
struct spdk_bdev *spdk_bdev_rbd_create(const char *name, const char *pool_name,
|
||||||
uint32_t block_size);
|
const char *rbd_name, uint32_t block_size);
|
||||||
|
|
||||||
#endif // SPDK_BDEV_RBD_H
|
#endif // SPDK_BDEV_RBD_H
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "spdk_internal/log.h"
|
#include "spdk_internal/log.h"
|
||||||
|
|
||||||
struct rpc_construct_rbd {
|
struct rpc_construct_rbd {
|
||||||
|
char *name;
|
||||||
char *pool_name;
|
char *pool_name;
|
||||||
char *rbd_name;
|
char *rbd_name;
|
||||||
uint32_t block_size;
|
uint32_t block_size;
|
||||||
@ -46,11 +47,13 @@ struct rpc_construct_rbd {
|
|||||||
static void
|
static void
|
||||||
free_rpc_construct_rbd(struct rpc_construct_rbd *req)
|
free_rpc_construct_rbd(struct rpc_construct_rbd *req)
|
||||||
{
|
{
|
||||||
|
free(req->name);
|
||||||
free(req->pool_name);
|
free(req->pool_name);
|
||||||
free(req->rbd_name);
|
free(req->rbd_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct spdk_json_object_decoder rpc_construct_rbd_decoders[] = {
|
static const struct spdk_json_object_decoder rpc_construct_rbd_decoders[] = {
|
||||||
|
{"name", offsetof(struct rpc_construct_rbd, name), spdk_json_decode_string, true},
|
||||||
{"pool_name", offsetof(struct rpc_construct_rbd, pool_name), spdk_json_decode_string},
|
{"pool_name", offsetof(struct rpc_construct_rbd, pool_name), spdk_json_decode_string},
|
||||||
{"rbd_name", offsetof(struct rpc_construct_rbd, rbd_name), spdk_json_decode_string},
|
{"rbd_name", offsetof(struct rpc_construct_rbd, rbd_name), spdk_json_decode_string},
|
||||||
{"block_size", offsetof(struct rpc_construct_rbd, block_size), spdk_json_decode_uint32},
|
{"block_size", offsetof(struct rpc_construct_rbd, block_size), spdk_json_decode_uint32},
|
||||||
@ -71,7 +74,7 @@ spdk_rpc_construct_rbd_bdev(struct spdk_jsonrpc_request *request,
|
|||||||
goto invalid;
|
goto invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bdev = spdk_bdev_rbd_create(req.pool_name, req.rbd_name, req.block_size);
|
bdev = spdk_bdev_rbd_create(req.name, req.pool_name, req.rbd_name, req.block_size);
|
||||||
if (bdev == NULL) {
|
if (bdev == NULL) {
|
||||||
goto invalid;
|
goto invalid;
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
p = subparsers.add_parser('construct_rbd_bdev',
|
p = subparsers.add_parser('construct_rbd_bdev',
|
||||||
help='Add a bdev with ceph rbd backend')
|
help='Add a bdev with ceph rbd backend')
|
||||||
|
p.add_argument('-b', '--name', help="Name of the bdev", required=False)
|
||||||
p.add_argument('pool_name', help='rbd pool name')
|
p.add_argument('pool_name', help='rbd pool name')
|
||||||
p.add_argument('rbd_name', help='rbd image name')
|
p.add_argument('rbd_name', help='rbd image name')
|
||||||
p.add_argument('block_size', help='rbd block size', type=int)
|
p.add_argument('block_size', help='rbd block size', type=int)
|
||||||
|
@ -56,6 +56,10 @@ def construct_rbd_bdev(args):
|
|||||||
'rbd_name': args.rbd_name,
|
'rbd_name': args.rbd_name,
|
||||||
'block_size': args.block_size,
|
'block_size': args.block_size,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if args.name:
|
||||||
|
params['name'] = args.name
|
||||||
|
|
||||||
print_array(args.client.call(
|
print_array(args.client.call(
|
||||||
'construct_rbd_bdev', params))
|
'construct_rbd_bdev', params))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user