Commit 26b9be75 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Konrad Sztyber
Browse files

bdev/nvme: Add max_bdevs parameter for attach_controller RPC



The target subsystem may expose more than 128 namespaces. To support
such subsystem, add a new parameter max_bdevs for the
bdev_nvme_attach_controller RPC.

Signed-off-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Change-Id: I8fab20b9c4d52818205e05de6a31dbe0d31a10fe
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17651


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent f0a2538c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -3939,11 +3939,12 @@ hdgst | Optional | bool | Enable TCP header digest
ddgst                      | Optional | bool        | Enable TCP data digest
fabrics_connect_timeout_us | Optional | bool        | Timeout for fabrics connect (in microseconds)
multipath                  | Optional | string      | Multipathing behavior: disable, failover, multipath. Default is failover.
num_io_queues              | Optional | uint32_t    | The number of IO queues to request during initialization. Range: (0, UINT16_MAX + 1], Default is 1024.
num_io_queues              | Optional | number      | The number of IO queues to request during initialization. Range: (0, UINT16_MAX + 1], Default is 1024.
ctrlr_loss_timeout_sec     | Optional | number      | Time to wait until ctrlr is reconnected before deleting ctrlr.  -1 means infinite reconnects. 0 means no reconnect.
reconnect_delay_sec        | Optional | number      | Time to delay a reconnect trial. 0 means no reconnect.
fast_io_fail_timeout_sec   | Optional | number      | Time to wait until ctrlr is reconnected before failing I/O to ctrlr. 0 means no such timeout.
psk                        | Optional | string      | PSK in hexadecimal digits, e.g. 1234567890ABCDEF (Enables SSL socket implementation for TCP)
max_bdevs                  | Optional | number      | The size of the name array for newly created bdevs. Default is 128.

#### Example

+11 −5
Original line number Diff line number Diff line
@@ -165,6 +165,7 @@ struct rpc_bdev_nvme_attach_controller {
	enum bdev_nvme_multipath_mode multipath;
	struct nvme_ctrlr_opts bdev_opts;
	struct spdk_nvme_ctrlr_opts drv_opts;
	uint32_t max_bdevs;
};

static void
@@ -257,13 +258,13 @@ static const struct spdk_json_object_decoder rpc_bdev_nvme_attach_controller_dec
	{"reconnect_delay_sec", offsetof(struct rpc_bdev_nvme_attach_controller, bdev_opts.reconnect_delay_sec), spdk_json_decode_uint32, true},
	{"fast_io_fail_timeout_sec", offsetof(struct rpc_bdev_nvme_attach_controller, bdev_opts.fast_io_fail_timeout_sec), spdk_json_decode_uint32, true},
	{"psk", offsetof(struct rpc_bdev_nvme_attach_controller, psk), spdk_json_decode_string, true},
	{"max_bdevs", offsetof(struct rpc_bdev_nvme_attach_controller, max_bdevs), spdk_json_decode_uint32, true},
};

#define NVME_MAX_BDEVS_PER_RPC 128
#define DEFAULT_MAX_BDEVS_PER_RPC 128

struct rpc_bdev_nvme_attach_controller_ctx {
	struct rpc_bdev_nvme_attach_controller req;
	uint32_t count;
	size_t bdev_count;
	const char **names;
	struct spdk_jsonrpc_request *request;
@@ -336,6 +337,7 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request,
	/* For now, initialize the multipath parameter to add a failover path. This maintains backward
	 * compatibility with past behavior. In the future, this behavior will change to "disable". */
	ctx->req.multipath = BDEV_NVME_MP_MODE_FAILOVER;
	ctx->req.max_bdevs = DEFAULT_MAX_BDEVS_PER_RPC;

	if (spdk_json_decode_object(params, rpc_bdev_nvme_attach_controller_decoders,
				    SPDK_COUNTOF(rpc_bdev_nvme_attach_controller_decoders),
@@ -346,7 +348,12 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request,
		goto cleanup;
	}

	ctx->names = calloc(NVME_MAX_BDEVS_PER_RPC, sizeof(char *));
	if (ctx->req.max_bdevs == 0) {
		spdk_jsonrpc_send_error_response(request, -EINVAL, "max_bdevs cannot be zero");
		goto cleanup;
	}

	ctx->names = calloc(ctx->req.max_bdevs, sizeof(char *));
	if (ctx->names == NULL) {
		spdk_jsonrpc_send_error_response(request, -ENOMEM, spdk_strerror(ENOMEM));
		goto cleanup;
@@ -517,10 +524,9 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request,
	}

	ctx->request = request;
	ctx->count = NVME_MAX_BDEVS_PER_RPC;
	/* Should already be zero due to the calloc(), but set explicitly for clarity. */
	ctx->req.bdev_opts.from_discovery_service = false;
	rc = bdev_nvme_create(&trid, ctx->req.name, ctx->names, ctx->count,
	rc = bdev_nvme_create(&trid, ctx->req.name, ctx->names, ctx->req.max_bdevs,
			      rpc_bdev_nvme_attach_controller_done, ctx, &ctx->req.drv_opts,
			      &ctx->req.bdev_opts, multipath);
	if (rc) {
+5 −1
Original line number Diff line number Diff line
@@ -690,7 +690,7 @@ def bdev_nvme_attach_controller(client, name, trtype, traddr, adrfam=None, trsvc
                                hostsvcid=None, prchk_reftag=None, prchk_guard=None,
                                hdgst=None, ddgst=None, fabrics_timeout=None, multipath=None, num_io_queues=None,
                                ctrlr_loss_timeout_sec=None, reconnect_delay_sec=None,
                                fast_io_fail_timeout_sec=None, psk=None):
                                fast_io_fail_timeout_sec=None, psk=None, max_bdevs=None):
    """Construct block device for each NVMe namespace in the attached controller.

    Args:
@@ -726,6 +726,7 @@ def bdev_nvme_attach_controller(client, name, trtype, traddr, adrfam=None, trsvc
        If fast_io_fail_timeout_sec is not zero, it has to be not less than reconnect_delay_sec and less than
        ctrlr_loss_timeout_sec if ctrlr_loss_timeout_sec is not -1. (optional)
        psk: Set PSK and enable TCP SSL socket implementation (optional)
        max_bdevs: Size of the name array for newly created bdevs. Default is 128. (optional)

    Returns:
        Names of created block devices.
@@ -788,6 +789,9 @@ def bdev_nvme_attach_controller(client, name, trtype, traddr, adrfam=None, trsvc
    if psk:
        params['psk'] = psk

    if max_bdevs is not None:
        params['max_bdevs'] = max_bdevs

    return client.call('bdev_nvme_attach_controller', params)


+5 −1
Original line number Diff line number Diff line
@@ -675,7 +675,8 @@ if __name__ == "__main__":
                                                         ctrlr_loss_timeout_sec=args.ctrlr_loss_timeout_sec,
                                                         reconnect_delay_sec=args.reconnect_delay_sec,
                                                         fast_io_fail_timeout_sec=args.fast_io_fail_timeout_sec,
                                                         psk=args.psk))
                                                         psk=args.psk,
                                                         max_bdevs=args.max_bdevs))

    p = subparsers.add_parser('bdev_nvme_attach_controller', help='Add bdevs with nvme backend')
    p.add_argument('-b', '--name', help="Name of the NVMe controller, prefix for each bdev name", required=True)
@@ -728,6 +729,9 @@ if __name__ == "__main__":
                   type=int)
    p.add_argument('-k', '--psk',
                   help='Set PSK and enable TCP SSL socket implementation: e.g., 1234567890ABCDEF')
    p.add_argument('-m', '--max-bdevs', type=int,
                   help='The size of the name array for newly created bdevs. Default is 128',)

    p.set_defaults(func=bdev_nvme_attach_controller)

    def bdev_nvme_get_controllers(args):