Commit 59dee78b authored by Tomasz Zawadzki's avatar Tomasz Zawadzki Committed by Jim Harris
Browse files

bdev: add delete_malloc_bdev call



Since delete_bdev should be used only for debug purpose,
this patch adds delete call specific for malloc.

Changes in tests and spdkcli done accordingly.

Change-Id: I5296452f552ee6eaba4d012d47aea022f17b9d6e
Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.gerrithub.io/415259


Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
parent 635a1aa8
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -448,6 +448,17 @@ struct spdk_bdev *create_malloc_disk(const char *name, const struct spdk_uuid *u
	return &mdisk->disk;
}

void
delete_malloc_disk(struct spdk_bdev *bdev, spdk_delete_malloc_complete cb_fn, void *cb_arg)
{
	if (!bdev || bdev->module != &malloc_if) {
		cb_fn(cb_arg, -ENODEV);
		return;
	}

	spdk_bdev_unregister(bdev, cb_fn, cb_arg);
}

static int bdev_malloc_initialize(void)
{
	struct spdk_conf_section *sp = spdk_conf_find_section(NULL, "Malloc");
+4 −0
Original line number Diff line number Diff line
@@ -38,7 +38,11 @@

#include "spdk/bdev.h"

typedef void (*spdk_delete_malloc_complete)(void *cb_arg, int bdeverrno);

struct spdk_bdev *create_malloc_disk(const char *name, const struct spdk_uuid *uuid,
				     uint64_t num_blocks, uint32_t block_size);

void delete_malloc_disk(struct spdk_bdev *bdev, spdk_delete_malloc_complete cb_fn, void *cb_arg);

#endif /* SPDK_BDEV_MALLOC_H */
+65 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@
#include "spdk/rpc.h"
#include "spdk/util.h"
#include "spdk/uuid.h"

#include "spdk/string.h"
#include "spdk_internal/log.h"

struct rpc_construct_malloc {
@@ -106,3 +106,67 @@ invalid:
	spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
}
SPDK_RPC_REGISTER("construct_malloc_bdev", spdk_rpc_construct_malloc_bdev, SPDK_RPC_RUNTIME)

struct rpc_delete_malloc {
	char *name;
};

static void
free_rpc_delete_malloc(struct rpc_delete_malloc *r)
{
	free(r->name);
}

static const struct spdk_json_object_decoder rpc_delete_malloc_decoders[] = {
	{"name", offsetof(struct rpc_delete_malloc, name), spdk_json_decode_string},
};

static void
_spdk_rpc_delete_malloc_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_malloc_bdev(struct spdk_jsonrpc_request *request,
			    const struct spdk_json_val *params)
{
	struct rpc_delete_malloc req = {NULL};
	struct spdk_bdev *bdev;
	int rc;

	if (spdk_json_decode_object(params, rpc_delete_malloc_decoders,
				    SPDK_COUNTOF(rpc_delete_malloc_decoders),
				    &req)) {
		SPDK_DEBUGLOG(SPDK_LOG_BDEV_MALLOC, "spdk_json_decode_object failed\n");
		rc = -EINVAL;
		goto invalid;
	}

	bdev = spdk_bdev_get_by_name(req.name);
	if (bdev == NULL) {
		SPDK_INFOLOG(SPDK_LOG_BDEV_MALLOC, "bdev '%s' does not exist\n", req.name);
		rc = -ENODEV;
		goto invalid;
	}

	delete_malloc_disk(bdev, _spdk_rpc_delete_malloc_bdev_cb, request);

	free_rpc_delete_malloc(&req);

	return;

invalid:
	free_rpc_delete_malloc(&req);
	spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(-rc));
}
SPDK_RPC_REGISTER("delete_malloc_bdev", spdk_rpc_delete_malloc_bdev, SPDK_RPC_RUNTIME)
+9 −0
Original line number Diff line number Diff line
@@ -139,6 +139,15 @@ if __name__ == "__main__":
    p.add_argument('block_size', help='Block size for this bdev', type=int)
    p.set_defaults(func=construct_malloc_bdev)

    @call_cmd
    def delete_malloc_bdev(args):
        rpc.bdev.delete_malloc_bdev(args.client,
                                    name=args.name)

    p = subparsers.add_parser('delete_malloc_bdev', help='Delete a malloc disk')
    p.add_argument('name', help='malloc bdev name')
    p.set_defaults(func=delete_malloc_bdev)

    @call_cmd
    def construct_null_bdev(args):
        num_blocks = (args.total_size * 1024 * 1024) // args.block_size
+10 −0
Original line number Diff line number Diff line
@@ -35,6 +35,16 @@ def construct_malloc_bdev(client, num_blocks, block_size, name=None, uuid=None):
    return client.call('construct_malloc_bdev', params)


def delete_malloc_bdev(client, name):
    """Delete malloc block device.

    Args:
        bdev_name: name of malloc bdev to delete
    """
    params = {'name': name}
    return client.call('delete_malloc_bdev', params)


def construct_null_bdev(client, num_blocks, block_size, name, uuid=None):
    """Construct a null block device.

Loading