Commit e48f0bf1 authored by Maciej Szwed's avatar Maciej Szwed Committed by Jim Harris
Browse files

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: default avatarMaciej Szwed <maciej.szwed@intel.com>
Change-Id: I8ea20b3003dd6539d84123c3b5363bd8bdfd6f7f

Reviewed-on: https://review.gerrithub.io/416535


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 1a0ce4de
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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
+19 −0
Original line number Diff line number Diff line
@@ -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 */
+63 −1
Original line number Diff line number Diff line
@@ -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)
+10 −1
Original line number Diff line number Diff line
@@ -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,
+10 −0
Original line number Diff line number Diff line
@@ -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.

Loading