Commit 09e8e884 authored by Artur Paszkiewicz's avatar Artur Paszkiewicz Committed by Tomasz Zawadzki
Browse files

nvmf: allow setting custom handlers for namespace reservation operations



Currently, namespace reservation persistence is enabled by storing the
reservation information in a file. Make it possible to override the
default behavior by providing custom handlers for reservation
operations.

Change-Id: I247ea2d6cd41ae808030886d70172fad7a04291b
Signed-off-by: default avatarArtur Paszkiewicz <artur.paszkiewicz@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/21360


Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Mellanox Build Bot
parent 5bbe0c0b
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -1397,6 +1397,31 @@ struct spdk_nvmf_reservation_info {
	struct spdk_nvmf_registrant_info	registrants[SPDK_NVMF_MAX_NUM_REGISTRANTS];
};

struct spdk_nvmf_ns_reservation_ops {
	/* Checks if the namespace supports the Persist Through Power Loss capability. */
	bool (*is_ptpl_capable)(const struct spdk_nvmf_ns *ns);

	/* Called when namespace reservation information needs to be updated.
	 * The new reservation information is provided via the info parameter.
	 * Returns 0 on success, negated errno on failure. */
	int (*update)(const struct spdk_nvmf_ns *ns, const struct spdk_nvmf_reservation_info *info);

	/* Called when restoring the namespace reservation information.
	 * The new reservation information is returned via the info parameter.
	 * Returns 0 on success, negated errno on failure. */
	int (*load)(const struct spdk_nvmf_ns *ns, struct spdk_nvmf_reservation_info *info);
};

/**
 * Set custom handlers for namespace reservation operations.
 *
 * This call allows to override the default namespace reservation operations with custom handlers.
 * This function may only be called before any namespace has been added.
 *
 * @param ops The reservation ops handers
 */
void spdk_nvmf_set_custom_ns_reservation_ops(const struct spdk_nvmf_ns_reservation_ops *ops);

#ifdef __cplusplus
}
#endif
+1 −5
Original line number Diff line number Diff line
@@ -419,11 +419,7 @@ void nvmf_ctrlr_reservation_notice_log(struct spdk_nvmf_ctrlr *ctrlr,
				       struct spdk_nvmf_ns *ns,
				       enum spdk_nvme_reservation_notification_log_page_type type);

static inline bool
nvmf_ns_is_ptpl_capable(struct spdk_nvmf_ns *ns)
{
	return ns->ptpl_file != NULL;
}
bool nvmf_ns_is_ptpl_capable(const struct spdk_nvmf_ns *ns);

/*
 * Abort zero-copy requests that already got the buffer (received zcopy_start cb), but haven't
+1 −0
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@
	spdk_nvmf_subsystem_get_ana_reporting;
	spdk_nvmf_subsystem_set_ana_state;
	spdk_nvmf_subsystem_is_discovery;
	spdk_nvmf_set_custom_ns_reservation_ops;

	# public functions in nvmf_cmd.h
	spdk_nvmf_ctrlr_identify_ctrlr;
+47 −5
Original line number Diff line number Diff line
@@ -1700,7 +1700,9 @@ static struct spdk_bdev_module ns_bdev_module = {
	.name	= "NVMe-oF Target",
};

static int nvmf_ns_load_reservation(const struct spdk_nvmf_ns *ns,
static int nvmf_ns_reservation_update(const struct spdk_nvmf_ns *ns,
				      const struct spdk_nvmf_reservation_info *info);
static int nvmf_ns_reservation_load(const struct spdk_nvmf_ns *ns,
				    struct spdk_nvmf_reservation_info *info);
static int nvmf_ns_reservation_restore(struct spdk_nvmf_ns *ns,
				       struct spdk_nvmf_reservation_info *info);
@@ -1852,8 +1854,10 @@ spdk_nvmf_subsystem_add_ns_ext(struct spdk_nvmf_subsystem *subsystem, const char
			SPDK_ERRLOG("Namespace ns->ptpl_file allocation failed\n");
			goto err;
		}
	}

		rc = nvmf_ns_load_reservation(ns, &info);
	if (nvmf_ns_is_ptpl_capable(ns)) {
		rc = nvmf_ns_reservation_load(ns, &info);
		if (!rc) {
			rc = nvmf_ns_reservation_restore(ns, &info);
			if (rc) {
@@ -2215,7 +2219,8 @@ static const struct spdk_json_object_decoder nvmf_ns_pr_decoders[] = {
};

static int
nvmf_ns_load_reservation(const struct spdk_nvmf_ns *ns, struct spdk_nvmf_reservation_info *info)
nvmf_ns_reservation_load_json(const struct spdk_nvmf_ns *ns,
			      struct spdk_nvmf_reservation_info *info)
{
	FILE *fd;
	size_t json_size;
@@ -2387,7 +2392,7 @@ nvmf_ns_json_write_cb(void *cb_ctx, const void *data, size_t size)
}

static int
nvmf_ns_reservation_update(const struct spdk_nvmf_ns *ns,
nvmf_ns_reservation_update_json(const struct spdk_nvmf_ns *ns,
				const struct spdk_nvmf_reservation_info *info)
{
	const char *file = ns->ptpl_file;
@@ -3254,6 +3259,43 @@ nvmf_ns_reservation_request(void *ctx)
	_nvmf_ns_reservation_update_done(ctrlr->subsys, req, status);
}

static bool
nvmf_ns_is_ptpl_capable_json(const struct spdk_nvmf_ns *ns)
{
	return ns->ptpl_file != NULL;
}

static struct spdk_nvmf_ns_reservation_ops g_reservation_ops = {
	.is_ptpl_capable = nvmf_ns_is_ptpl_capable_json,
	.update = nvmf_ns_reservation_update_json,
	.load = nvmf_ns_reservation_load_json,
};

bool
nvmf_ns_is_ptpl_capable(const struct spdk_nvmf_ns *ns)
{
	return g_reservation_ops.is_ptpl_capable(ns);
}

static int
nvmf_ns_reservation_update(const struct spdk_nvmf_ns *ns,
			   const struct spdk_nvmf_reservation_info *info)
{
	return g_reservation_ops.update(ns, info);
}

static int
nvmf_ns_reservation_load(const struct spdk_nvmf_ns *ns, struct spdk_nvmf_reservation_info *info)
{
	return g_reservation_ops.load(ns, info);
}

void
spdk_nvmf_set_custom_ns_reservation_ops(const struct spdk_nvmf_ns_reservation_ops *ops)
{
	g_reservation_ops = *ops;
}

int
spdk_nvmf_subsystem_set_ana_reporting(struct spdk_nvmf_subsystem *subsystem,
				      bool ana_reporting)
+6 −0
Original line number Diff line number Diff line
@@ -309,6 +309,12 @@ nvmf_bdev_ctrlr_zcopy_end(struct spdk_nvmf_request *req, bool commit)
	spdk_nvmf_request_complete(req);
}

bool
nvmf_ns_is_ptpl_capable(const struct spdk_nvmf_ns *ns)
{
	return ns->ptpl_file != NULL;
}

static void
test_get_log_page(void)
{
Loading