Commit 260f9a77 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Darek Stojaczyk
Browse files

bdev/nvme: Set per-controller PRCHK options by JSON RPC



Add prchk_reftag and prchk_guard to construct_nvme_bdev RPC.
In spdk_rpc_construct_nvme_bdev, create prchk_flags based on them
and pass it to spdk_bdev_nvme_create, and in spdk_bdev_nvme_create,
pass it to create_ctrlr.

A single option enable_prchk may be enough but add separate options
for reftag and guard to clarify that apptag is not supported yet.

The next patch will make per-controller PRCHK options configurable
by .INI config file.

Change-Id: I370ebbe984ee83d133b7f50bdc648ea746c8d42d
Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/443833


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent a827a91e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1459,6 +1459,8 @@ subnqn | Optional | string | NVMe-oF target subnqn
hostnqn                 | Optional | string      | NVMe-oF target hostnqn
hostaddr                | Optional | string      | NVMe-oF host address: ip address
hostsvcid               | Optional | string      | NVMe-oF host trsvcid: port number
prchk_reftag            | Optional | bool        | Enable checking of PI reference tag for I/O processing
prchk_guard             | Optional | bool        | Enable checking of PI guard for I/O processing

### Example

+7 −2
Original line number Diff line number Diff line
@@ -1216,7 +1216,8 @@ spdk_bdev_nvme_create(struct spdk_nvme_transport_id *trid,
		      struct spdk_nvme_host_id *hostid,
		      const char *base_name,
		      const char **names, size_t *count,
		      const char *hostnqn)
		      const char *hostnqn,
		      uint32_t prchk_flags)
{
	struct spdk_nvme_ctrlr_opts	opts;
	struct spdk_nvme_ctrlr		*ctrlr;
@@ -1255,7 +1256,7 @@ spdk_bdev_nvme_create(struct spdk_nvme_transport_id *trid,
		return -1;
	}

	if (create_ctrlr(ctrlr, base_name, trid, 0)) {
	if (create_ctrlr(ctrlr, base_name, trid, prchk_flags)) {
		SPDK_ERRLOG("Failed to create new device\n");
		return -1;
	}
@@ -1912,6 +1913,10 @@ bdev_nvme_config_json(struct spdk_json_write_ctx *w)
		spdk_json_write_named_object_begin(w, "params");
		spdk_json_write_named_string(w, "name", nvme_ctrlr->name);
		spdk_bdev_nvme_dump_trid_json(trid, w);
		spdk_json_write_named_bool(w, "prchk_reftag",
					   (nvme_ctrlr->prchk_flags & SPDK_NVME_IO_FLAGS_PRCHK_REFTAG) != 0);
		spdk_json_write_named_bool(w, "prchk_guard",
					   (nvme_ctrlr->prchk_flags & SPDK_NVME_IO_FLAGS_PRCHK_GUARD) != 0);

		spdk_json_write_object_end(w);

+2 −1
Original line number Diff line number Diff line
@@ -100,7 +100,8 @@ int spdk_bdev_nvme_create(struct spdk_nvme_transport_id *trid,
			  struct spdk_nvme_host_id *hostid,
			  const char *base_name,
			  const char **names, size_t *count,
			  const char *hostnqn);
			  const char *hostnqn,
			  uint32_t prchk_flags);
struct spdk_nvme_ctrlr *spdk_bdev_nvme_get_ctrlr(struct spdk_bdev *bdev);

/**
+16 −2
Original line number Diff line number Diff line
@@ -167,6 +167,8 @@ struct rpc_construct_nvme {
	char *hostnqn;
	char *hostaddr;
	char *hostsvcid;
	bool prchk_reftag;
	bool prchk_guard;
};

static void
@@ -193,8 +195,10 @@ static const struct spdk_json_object_decoder rpc_construct_nvme_decoders[] = {
	{"subnqn", offsetof(struct rpc_construct_nvme, subnqn), spdk_json_decode_string, true},
	{"hostnqn", offsetof(struct rpc_construct_nvme, hostnqn), spdk_json_decode_string, true},
	{"hostaddr", offsetof(struct rpc_construct_nvme, hostaddr), spdk_json_decode_string, true},
	{"hostsvcid", offsetof(struct rpc_construct_nvme, hostsvcid), spdk_json_decode_string, true}
	{"hostsvcid", offsetof(struct rpc_construct_nvme, hostsvcid), spdk_json_decode_string, true},

	{"prchk_reftag", offsetof(struct rpc_construct_nvme, prchk_reftag), spdk_json_decode_bool, true},
	{"prchk_guard", offsetof(struct rpc_construct_nvme, prchk_guard), spdk_json_decode_bool, true}
};

#define NVME_MAX_BDEVS_PER_RPC 128
@@ -210,6 +214,7 @@ spdk_rpc_construct_nvme_bdev(struct spdk_jsonrpc_request *request,
	const char *names[NVME_MAX_BDEVS_PER_RPC];
	size_t count;
	size_t i;
	uint32_t prchk_flags = 0;
	int rc;

	if (spdk_json_decode_object(params, rpc_construct_nvme_decoders,
@@ -256,8 +261,17 @@ spdk_rpc_construct_nvme_bdev(struct spdk_jsonrpc_request *request,
		snprintf(hostid.hostsvcid, sizeof(hostid.hostsvcid), "%s", req.hostsvcid);
	}

	if (req.prchk_reftag) {
		prchk_flags |= SPDK_NVME_IO_FLAGS_PRCHK_REFTAG;
	}

	if (req.prchk_guard) {
		prchk_flags |= SPDK_NVME_IO_FLAGS_PRCHK_GUARD;
	}

	count = NVME_MAX_BDEVS_PER_RPC;
	if (spdk_bdev_nvme_create(&trid, &hostid, req.name, names, &count, req.hostnqn)) {
	if (spdk_bdev_nvme_create(&trid, &hostid, req.name, names, &count, req.hostnqn,
				  prchk_flags)) {
		goto invalid;
	}

+7 −1
Original line number Diff line number Diff line
@@ -291,7 +291,9 @@ if __name__ == "__main__":
                                                 subnqn=args.subnqn,
                                                 hostnqn=args.hostnqn,
                                                 hostaddr=args.hostaddr,
                                                 hostsvcid=args.hostsvcid))
                                                 hostsvcid=args.hostsvcid,
                                                 prchk_reftag=args.prchk_reftag,
                                                 prchk_guard=args.prchk_guard))

    p = subparsers.add_parser('construct_nvme_bdev',
                              help='Add bdevs with nvme backend')
@@ -310,6 +312,10 @@ if __name__ == "__main__":
                   help='NVMe-oF host address: e.g., an ip address')
    p.add_argument('-c', '--hostsvcid',
                   help='NVMe-oF host svcid: e.g., a port number')
    p.add_argument('-r', '--prchk-reftag',
                   help='Enable checking of PI reference tag for I/O processing.', action='store_true')
    p.add_argument('-g', '--prchk-guard',
                   help='Enable checking of PI guard for I/O processing.', action='store_true')
    p.set_defaults(func=construct_nvme_bdev)

    def get_nvme_controllers(args):
Loading