Commit 6ce73aa6 authored by Daniel Verkamp's avatar Daniel Verkamp
Browse files

nvme: add spdk_ prefix



Shorten commonly-used names:
controller -> ctrlr
namespace -> ns

Change-Id: I64f0ce7c65385bab0283f8a8341a3447792b3312
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent ad35d6cd
Loading
Loading
Loading
Loading
+38 −37
Original line number Diff line number Diff line
@@ -134,18 +134,18 @@ get_log_page_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
}

static int
get_feature(struct nvme_controller *ctrlr, uint8_t fid)
get_feature(struct spdk_nvme_ctrlr *ctrlr, uint8_t fid)
{
	struct spdk_nvme_cmd cmd = {};

	cmd.opc = SPDK_NVME_OPC_GET_FEATURES;
	cmd.cdw10 = fid;

	return nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, NULL, 0, get_feature_completion, &features[fid]);
	return spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, NULL, 0, get_feature_completion, &features[fid]);
}

static void
get_features(struct nvme_controller *ctrlr)
get_features(struct spdk_nvme_ctrlr *ctrlr)
{
	size_t i;

@@ -167,12 +167,12 @@ get_features(struct nvme_controller *ctrlr)
	}

	while (outstanding_commands) {
		nvme_ctrlr_process_admin_completions(ctrlr);
		spdk_nvme_ctrlr_process_admin_completions(ctrlr);
	}
}

static int
get_health_log_page(struct nvme_controller *ctrlr)
get_health_log_page(struct spdk_nvme_ctrlr *ctrlr)
{
	if (health_page == NULL) {
		health_page = rte_zmalloc("nvme health", sizeof(*health_page), 4096);
@@ -182,9 +182,9 @@ get_health_log_page(struct nvme_controller *ctrlr)
		exit(1);
	}

	if (nvme_ctrlr_cmd_get_log_page(ctrlr, SPDK_NVME_LOG_HEALTH_INFORMATION, SPDK_NVME_GLOBAL_NS_TAG,
					health_page, sizeof(*health_page), get_log_page_completion, NULL)) {
		printf("nvme_ctrlr_cmd_get_log_page() failed\n");
	if (spdk_nvme_ctrlr_cmd_get_log_page(ctrlr, SPDK_NVME_LOG_HEALTH_INFORMATION,
					     SPDK_NVME_GLOBAL_NS_TAG, health_page, sizeof(*health_page), get_log_page_completion, NULL)) {
		printf("spdk_nvme_ctrlr_cmd_get_log_page() failed\n");
		exit(1);
	}

@@ -192,7 +192,7 @@ get_health_log_page(struct nvme_controller *ctrlr)
}

static int
get_intel_smart_log_page(struct nvme_controller *ctrlr)
get_intel_smart_log_page(struct spdk_nvme_ctrlr *ctrlr)
{
	if (intel_smart_page == NULL) {
		intel_smart_page = rte_zmalloc("nvme intel smart", sizeof(*intel_smart_page), 4096);
@@ -202,9 +202,9 @@ get_intel_smart_log_page(struct nvme_controller *ctrlr)
		exit(1);
	}

	if (nvme_ctrlr_cmd_get_log_page(ctrlr, SPDK_NVME_INTEL_LOG_SMART, SPDK_NVME_GLOBAL_NS_TAG,
	if (spdk_nvme_ctrlr_cmd_get_log_page(ctrlr, SPDK_NVME_INTEL_LOG_SMART, SPDK_NVME_GLOBAL_NS_TAG,
					     intel_smart_page, sizeof(*intel_smart_page), get_log_page_completion, NULL)) {
		printf("nvme_ctrlr_cmd_get_log_page() failed\n");
		printf("spdk_nvme_ctrlr_cmd_get_log_page() failed\n");
		exit(1);
	}

@@ -212,7 +212,7 @@ get_intel_smart_log_page(struct nvme_controller *ctrlr)
}

static int
get_intel_temperature_log_page(struct nvme_controller *ctrlr)
get_intel_temperature_log_page(struct spdk_nvme_ctrlr *ctrlr)
{
	if (intel_temperature_page == NULL) {
		intel_temperature_page = rte_zmalloc("nvme intel temperature", sizeof(*intel_temperature_page),
@@ -223,16 +223,17 @@ get_intel_temperature_log_page(struct nvme_controller *ctrlr)
		exit(1);
	}

	if (nvme_ctrlr_cmd_get_log_page(ctrlr, SPDK_NVME_INTEL_LOG_TEMPERATURE, SPDK_NVME_GLOBAL_NS_TAG,
					intel_temperature_page, sizeof(*intel_temperature_page), get_log_page_completion, NULL)) {
		printf("nvme_ctrlr_cmd_get_log_page() failed\n");
	if (spdk_nvme_ctrlr_cmd_get_log_page(ctrlr, SPDK_NVME_INTEL_LOG_TEMPERATURE,
					     SPDK_NVME_GLOBAL_NS_TAG, intel_temperature_page, sizeof(*intel_temperature_page),
					     get_log_page_completion, NULL)) {
		printf("spdk_nvme_ctrlr_cmd_get_log_page() failed\n");
		exit(1);
	}
	return 0;
}

static void
get_log_pages(struct nvme_controller *ctrlr)
get_log_pages(struct spdk_nvme_ctrlr *ctrlr)
{
	const struct spdk_nvme_ctrlr_data *ctrlr_data;
	outstanding_commands = 0;
@@ -243,16 +244,16 @@ get_log_pages(struct nvme_controller *ctrlr)
		printf("Get Log Page (SMART/health) failed\n");
	}

	ctrlr_data = nvme_ctrlr_get_data(ctrlr);
	ctrlr_data = spdk_nvme_ctrlr_get_data(ctrlr);
	if (ctrlr_data->vid == SPDK_PCI_VID_INTEL) {
		if (nvme_ctrlr_is_log_page_supported(ctrlr, SPDK_NVME_INTEL_LOG_SMART)) {
		if (spdk_nvme_ctrlr_is_log_page_supported(ctrlr, SPDK_NVME_INTEL_LOG_SMART)) {
			if (get_intel_smart_log_page(ctrlr) == 0) {
				outstanding_commands++;
			} else {
				printf("Get Log Page (Intel SMART/health) failed\n");
			}
		}
		if (nvme_ctrlr_is_log_page_supported(ctrlr, SPDK_NVME_INTEL_LOG_TEMPERATURE)) {
		if (spdk_nvme_ctrlr_is_log_page_supported(ctrlr, SPDK_NVME_INTEL_LOG_TEMPERATURE)) {
			if (get_intel_temperature_log_page(ctrlr) == 0) {
				outstanding_commands++;
			} else {
@@ -262,7 +263,7 @@ get_log_pages(struct nvme_controller *ctrlr)
	}

	while (outstanding_commands) {
		nvme_ctrlr_process_admin_completions(ctrlr);
		spdk_nvme_ctrlr_process_admin_completions(ctrlr);
	}
}

@@ -321,16 +322,16 @@ print_uint_var_dec(uint8_t *array, unsigned int len)
}

static void
print_namespace(struct nvme_namespace *ns)
print_namespace(struct spdk_nvme_ns *ns)
{
	const struct spdk_nvme_ns_data		*nsdata;
	uint32_t				i;
	uint32_t				flags;

	nsdata = nvme_ns_get_data(ns);
	flags  = nvme_ns_get_flags(ns);
	nsdata = spdk_nvme_ns_get_data(ns);
	flags  = spdk_nvme_ns_get_flags(ns);

	printf("Namespace ID:%d\n", nvme_ns_get_id(ns));
	printf("Namespace ID:%d\n", spdk_nvme_ns_get_id(ns));

	if (g_hex_dump) {
		hex_dump(nsdata, sizeof(*nsdata));
@@ -338,11 +339,11 @@ print_namespace(struct nvme_namespace *ns)
	}

	printf("Deallocate:                  %s\n",
	       (flags & NVME_NS_DEALLOCATE_SUPPORTED) ? "Supported" : "Not Supported");
	       (flags & SPDK_NVME_NS_DEALLOCATE_SUPPORTED) ? "Supported" : "Not Supported");
	printf("Flush:                       %s\n",
	       (flags & NVME_NS_FLUSH_SUPPORTED) ? "Supported" : "Not Supported");
	       (flags & SPDK_NVME_NS_FLUSH_SUPPORTED) ? "Supported" : "Not Supported");
	printf("Reservation:                 %s\n",
	       (flags & NVME_NS_RESERVATION_SUPPORTED) ? "Supported" : "Not Supported");
	       (flags & SPDK_NVME_NS_RESERVATION_SUPPORTED) ? "Supported" : "Not Supported");
	printf("Size (in LBAs):              %lld (%lldM)\n",
	       (long long)nsdata->nsze,
	       (long long)nsdata->nsze / 1024 / 1024);
@@ -364,7 +365,7 @@ print_namespace(struct nvme_namespace *ns)
}

static void
print_controller(struct nvme_controller *ctrlr, struct spdk_pci_device *pci_dev)
print_controller(struct spdk_nvme_ctrlr *ctrlr, struct spdk_pci_device *pci_dev)
{
	const struct spdk_nvme_ctrlr_data	*cdata;
	uint8_t					str[128];
@@ -373,7 +374,7 @@ print_controller(struct nvme_controller *ctrlr, struct spdk_pci_device *pci_dev)
	get_features(ctrlr);
	get_log_pages(ctrlr);

	cdata = nvme_ctrlr_get_data(ctrlr);
	cdata = spdk_nvme_ctrlr_get_data(ctrlr);

	printf("=====================================================\n");
	printf("NVMe Controller at PCI bus %d, device %d, function %d\n",
@@ -729,8 +730,8 @@ print_controller(struct nvme_controller *ctrlr, struct spdk_pci_device *pci_dev)
		printf("\n");

	}
	for (i = 1; i <= nvme_ctrlr_get_num_ns(ctrlr); i++) {
		print_namespace(nvme_ctrlr_get_ns(ctrlr, i));
	for (i = 1; i <= spdk_nvme_ctrlr_get_num_ns(ctrlr); i++) {
		print_namespace(spdk_nvme_ctrlr_get_ns(ctrlr, i));
	}
}

@@ -782,10 +783,10 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *dev)
}

static void
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct nvme_controller *ctrlr)
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr *ctrlr)
{
	print_controller(ctrlr, pci_dev);
	nvme_detach(ctrlr);
	spdk_nvme_detach(ctrlr);
}

static const char *ealargs[] = {
@@ -812,7 +813,7 @@ int main(int argc, char **argv)
	}

	request_mempool = rte_mempool_create("nvme_request", 8192,
					     nvme_request_size(), 128, 0,
					     spdk_nvme_request_size(), 128, 0,
					     NULL, NULL, NULL, NULL,
					     SOCKET_ID_ANY, 0);

@@ -822,8 +823,8 @@ int main(int argc, char **argv)
	}

	rc = 0;
	if (nvme_probe(NULL, probe_cb, attach_cb) != 0) {
		fprintf(stderr, "nvme_probe() failed\n");
	if (spdk_nvme_probe(NULL, probe_cb, attach_cb) != 0) {
		fprintf(stderr, "spdk_nvme_probe() failed\n");
		rc = 1;
	}

+41 −41
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@
#endif

struct ctrlr_entry {
	struct nvme_controller			*ctrlr;
	struct spdk_nvme_ctrlr			*ctrlr;
	struct spdk_nvme_intel_rw_latency_page	*latency_page;
	struct ctrlr_entry			*next;
	char					name[1024];
@@ -71,8 +71,8 @@ struct ns_entry {

	union {
		struct {
			struct nvme_controller	*ctrlr;
			struct nvme_namespace	*ns;
			struct spdk_nvme_ctrlr	*ctrlr;
			struct spdk_nvme_ns	*ns;
		} nvme;
#if HAVE_LIBAIO
		struct {
@@ -145,19 +145,19 @@ static void
task_complete(struct perf_task *task);

static void
register_ns(struct nvme_controller *ctrlr, struct nvme_namespace *ns)
register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns)
{
	struct ns_entry *entry;
	const struct spdk_nvme_ctrlr_data *cdata;

	cdata = nvme_ctrlr_get_data(ctrlr);
	cdata = spdk_nvme_ctrlr_get_data(ctrlr);

	if (nvme_ns_get_size(ns) < g_io_size_bytes ||
	    nvme_ns_get_sector_size(ns) > g_io_size_bytes) {
	if (spdk_nvme_ns_get_size(ns) < g_io_size_bytes ||
	    spdk_nvme_ns_get_sector_size(ns) > g_io_size_bytes) {
		printf("WARNING: controller %-20.20s (%-20.20s) ns %u has invalid "
		       "ns size %" PRIu64 " / block size %u for I/O size %u\n",
		       cdata->mn, cdata->sn, nvme_ns_get_id(ns),
		       nvme_ns_get_size(ns), nvme_ns_get_sector_size(ns), g_io_size_bytes);
		       cdata->mn, cdata->sn, spdk_nvme_ns_get_id(ns),
		       spdk_nvme_ns_get_size(ns), spdk_nvme_ns_get_sector_size(ns), g_io_size_bytes);
		return;
	}

@@ -170,9 +170,9 @@ register_ns(struct nvme_controller *ctrlr, struct nvme_namespace *ns)
	entry->type = ENTRY_TYPE_NVME_NS;
	entry->u.nvme.ctrlr = ctrlr;
	entry->u.nvme.ns = ns;
	entry->size_in_ios = nvme_ns_get_size(ns) /
	entry->size_in_ios = spdk_nvme_ns_get_size(ns) /
			     g_io_size_bytes;
	entry->io_size_blocks = g_io_size_bytes / nvme_ns_get_sector_size(ns);
	entry->io_size_blocks = g_io_size_bytes / spdk_nvme_ns_get_sector_size(ns);

	snprintf(entry->name, 44, "%-20.20s (%-20.20s)", cdata->mn, cdata->sn);

@@ -191,7 +191,7 @@ enable_latency_tracking_complete(void *cb_arg, const struct spdk_nvme_cpl *cpl)
}

static void
set_latency_tracking_feature(struct nvme_controller *ctrlr, bool enable)
set_latency_tracking_feature(struct spdk_nvme_ctrlr *ctrlr, bool enable)
{
	int res;
	union spdk_nvme_intel_feat_latency_tracking latency_tracking;
@@ -202,7 +202,7 @@ set_latency_tracking_feature(struct nvme_controller *ctrlr, bool enable)
		latency_tracking.bits.enable = 0x00;
	}

	res = nvme_ctrlr_cmd_set_feature(ctrlr, SPDK_NVME_INTEL_FEAT_LATENCY_TRACKING,
	res = spdk_nvme_ctrlr_cmd_set_feature(ctrlr, SPDK_NVME_INTEL_FEAT_LATENCY_TRACKING,
					      latency_tracking.raw, 0, NULL, 0, enable_latency_tracking_complete, NULL);
	if (res) {
		printf("fail to allocate nvme request.\n");
@@ -211,16 +211,16 @@ set_latency_tracking_feature(struct nvme_controller *ctrlr, bool enable)
	g_outstanding_commands++;

	while (g_outstanding_commands) {
		nvme_ctrlr_process_admin_completions(ctrlr);
		spdk_nvme_ctrlr_process_admin_completions(ctrlr);
	}
}

static void
register_ctrlr(struct nvme_controller *ctrlr)
register_ctrlr(struct spdk_nvme_ctrlr *ctrlr)
{
	int nsid, num_ns;
	struct ctrlr_entry *entry = malloc(sizeof(struct ctrlr_entry));
	const struct spdk_nvme_ctrlr_data *cdata = nvme_ctrlr_get_data(ctrlr);
	const struct spdk_nvme_ctrlr_data *cdata = spdk_nvme_ctrlr_get_data(ctrlr);

	if (entry == NULL) {
		perror("ctrlr_entry malloc");
@@ -241,12 +241,12 @@ register_ctrlr(struct nvme_controller *ctrlr)
	g_controllers = entry;

	if (g_latency_tracking_enable &&
	    nvme_ctrlr_is_feature_supported(ctrlr, SPDK_NVME_INTEL_FEAT_LATENCY_TRACKING))
	    spdk_nvme_ctrlr_is_feature_supported(ctrlr, SPDK_NVME_INTEL_FEAT_LATENCY_TRACKING))
		set_latency_tracking_feature(ctrlr, true);

	num_ns = nvme_ctrlr_get_num_ns(ctrlr);
	num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr);
	for (nsid = 1; nsid <= num_ns; nsid++) {
		register_ns(ctrlr, nvme_ctrlr_get_ns(ctrlr, nsid));
		register_ns(ctrlr, spdk_nvme_ctrlr_get_ns(ctrlr, nsid));
	}

}
@@ -398,7 +398,7 @@ submit_single_io(struct ns_worker_ctx *ns_ctx)
		} else
#endif
		{
			rc = nvme_ns_cmd_read(entry->u.nvme.ns, task->buf, offset_in_ios * entry->io_size_blocks,
			rc = spdk_nvme_ns_cmd_read(entry->u.nvme.ns, task->buf, offset_in_ios * entry->io_size_blocks,
						   entry->io_size_blocks, io_complete, task, 0);
		}
	} else {
@@ -409,7 +409,7 @@ submit_single_io(struct ns_worker_ctx *ns_ctx)
		} else
#endif
		{
			rc = nvme_ns_cmd_write(entry->u.nvme.ns, task->buf, offset_in_ios * entry->io_size_blocks,
			rc = spdk_nvme_ns_cmd_write(entry->u.nvme.ns, task->buf, offset_in_ios * entry->io_size_blocks,
						    entry->io_size_blocks, io_complete, task, 0);
		}
	}
@@ -458,7 +458,7 @@ check_io(struct ns_worker_ctx *ns_ctx)
	} else
#endif
	{
		nvme_ctrlr_process_io_completions(ns_ctx->entry->u.nvme.ctrlr, g_max_completions);
		spdk_nvme_ctrlr_process_io_completions(ns_ctx->entry->u.nvme.ctrlr, g_max_completions);
	}
}

@@ -488,8 +488,8 @@ work_fn(void *arg)

	printf("Starting thread on core %u\n", worker->lcore);

	if (nvme_register_io_thread() != 0) {
		fprintf(stderr, "nvme_register_io_thread() failed on core %u\n", worker->lcore);
	if (spdk_nvme_register_io_thread() != 0) {
		fprintf(stderr, "spdk_nvme_register_io_thread() failed on core %u\n", worker->lcore);
		return -1;
	}

@@ -523,7 +523,7 @@ work_fn(void *arg)
		ns_ctx = ns_ctx->next;
	}

	nvme_unregister_io_thread();
	spdk_nvme_unregister_io_thread();

	return 0;
}
@@ -614,8 +614,8 @@ print_latency_statistics(const char *op_name, enum spdk_nvme_intel_log_page log_
	printf("========================================================\n");
	ctrlr = g_controllers;
	while (ctrlr) {
		if (nvme_ctrlr_is_log_page_supported(ctrlr->ctrlr, log_page)) {
			if (nvme_ctrlr_cmd_get_log_page(ctrlr->ctrlr, log_page, SPDK_NVME_GLOBAL_NS_TAG,
		if (spdk_nvme_ctrlr_is_log_page_supported(ctrlr->ctrlr, log_page)) {
			if (spdk_nvme_ctrlr_cmd_get_log_page(ctrlr->ctrlr, log_page, SPDK_NVME_GLOBAL_NS_TAG,
							     ctrlr->latency_page, sizeof(struct spdk_nvme_intel_rw_latency_page),
							     enable_latency_tracking_complete,
							     NULL)) {
@@ -633,14 +633,14 @@ print_latency_statistics(const char *op_name, enum spdk_nvme_intel_log_page log_
	while (g_outstanding_commands) {
		ctrlr = g_controllers;
		while (ctrlr) {
			nvme_ctrlr_process_admin_completions(ctrlr->ctrlr);
			spdk_nvme_ctrlr_process_admin_completions(ctrlr->ctrlr);
			ctrlr = ctrlr->next;
		}
	}

	ctrlr = g_controllers;
	while (ctrlr) {
		if (nvme_ctrlr_is_log_page_supported(ctrlr->ctrlr, log_page)) {
		if (spdk_nvme_ctrlr_is_log_page_supported(ctrlr->ctrlr, log_page)) {
			print_latency_page(ctrlr);
		}
		ctrlr = ctrlr->next;
@@ -843,7 +843,7 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *dev)
}

static void
attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct nvme_controller *ctrlr)
attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctrlr)
{
	printf("Attached to %04x:%02x:%02x.%02x\n",
	       spdk_pci_device_get_domain(dev),
@@ -859,8 +859,8 @@ register_controllers(void)
{
	printf("Initializing NVMe Controllers\n");

	if (nvme_probe(NULL, probe_cb, attach_cb) != 0) {
		fprintf(stderr, "nvme_probe() failed\n");
	if (spdk_nvme_probe(NULL, probe_cb, attach_cb) != 0) {
		fprintf(stderr, "spdk_nvme_probe() failed\n");
		return 1;
	}

@@ -876,9 +876,9 @@ unregister_controllers(void)
		struct ctrlr_entry *next = entry->next;
		rte_free(entry->latency_page);
		if (g_latency_tracking_enable &&
		    nvme_ctrlr_is_feature_supported(entry->ctrlr, SPDK_NVME_INTEL_FEAT_LATENCY_TRACKING))
		    spdk_nvme_ctrlr_is_feature_supported(entry->ctrlr, SPDK_NVME_INTEL_FEAT_LATENCY_TRACKING))
			set_latency_tracking_feature(entry->ctrlr, false);
		nvme_detach(entry->ctrlr);
		spdk_nvme_detach(entry->ctrlr);
		free(entry);
		entry = next;
	}
@@ -988,7 +988,7 @@ int main(int argc, char **argv)
	}

	request_mempool = rte_mempool_create("nvme_request", 8192,
					     nvme_request_size(), 128, 0,
					     spdk_nvme_request_size(), 128, 0,
					     NULL, NULL, NULL, NULL,
					     SOCKET_ID_ANY, 0);

+50 −50
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ struct rte_mempool *request_mempool;

struct dev {
	struct spdk_pci_device			*pci_dev;
	struct nvme_controller 			*ctrlr;
	struct spdk_nvme_ctrlr 			*ctrlr;
	char 					name[100];
};

@@ -104,7 +104,7 @@ set_feature_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
}

static int
get_host_identifier(struct nvme_controller *ctrlr)
get_host_identifier(struct spdk_nvme_ctrlr *ctrlr)
{
	int ret;
	uint64_t *host_id;
@@ -116,7 +116,7 @@ get_host_identifier(struct nvme_controller *ctrlr)
	outstanding_commands = 0;

	host_id = rte_malloc(NULL, 8, 0);
	ret = nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, host_id, 8,
	ret = spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, host_id, 8,
					    get_feature_completion, &features[SPDK_NVME_FEAT_HOST_IDENTIFIER]);
	if (ret) {
		fprintf(stdout, "Get Feature: Failed\n");
@@ -126,7 +126,7 @@ get_host_identifier(struct nvme_controller *ctrlr)
	outstanding_commands++;

	while (outstanding_commands) {
		nvme_ctrlr_process_admin_completions(ctrlr);
		spdk_nvme_ctrlr_process_admin_completions(ctrlr);
	}

	if (features[SPDK_NVME_FEAT_HOST_IDENTIFIER].valid) {
@@ -137,7 +137,7 @@ get_host_identifier(struct nvme_controller *ctrlr)
}

static int
set_host_identifier(struct nvme_controller *ctrlr)
set_host_identifier(struct spdk_nvme_ctrlr *ctrlr)
{
	int ret;
	uint64_t *host_id;
@@ -153,7 +153,7 @@ set_host_identifier(struct nvme_controller *ctrlr)
	set_feature_result = -1;

	fprintf(stdout, "Set Feature: Host Identifier 0x%"PRIx64"\n", *host_id);
	ret = nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, host_id, 8,
	ret = spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, host_id, 8,
					    set_feature_completion, &features[SPDK_NVME_FEAT_HOST_IDENTIFIER]);
	if (ret) {
		fprintf(stdout, "Set Feature: Failed\n");
@@ -164,7 +164,7 @@ set_host_identifier(struct nvme_controller *ctrlr)
	outstanding_commands++;

	while (outstanding_commands) {
		nvme_ctrlr_process_admin_completions(ctrlr);
		spdk_nvme_ctrlr_process_admin_completions(ctrlr);
	}

	if (set_feature_result)
@@ -187,13 +187,13 @@ reservation_ns_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
}

static int
reservation_ns_register(struct nvme_controller *ctrlr, uint16_t ns_id)
reservation_ns_register(struct spdk_nvme_ctrlr *ctrlr, uint16_t ns_id)
{
	int ret;
	struct spdk_nvme_reservation_register_data *rr_data;
	struct nvme_namespace *ns;
	struct spdk_nvme_ns *ns;

	ns = nvme_ctrlr_get_ns(ctrlr, ns_id);
	ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);

	rr_data = rte_zmalloc(NULL, sizeof(struct spdk_nvme_reservation_register_data), 0);
	rr_data->crkey = CR_KEY;
@@ -202,7 +202,7 @@ reservation_ns_register(struct nvme_controller *ctrlr, uint16_t ns_id)
	outstanding_commands = 0;
	reserve_command_result = -1;

	ret = nvme_ns_cmd_reservation_register(ns, rr_data, 1,
	ret = spdk_nvme_ns_cmd_reservation_register(ns, rr_data, 1,
			SPDK_NVME_RESERVE_REGISTER_KEY,
			SPDK_NVME_RESERVE_PTPL_NO_CHANGES,
			reservation_ns_completion, NULL);
@@ -214,7 +214,7 @@ reservation_ns_register(struct nvme_controller *ctrlr, uint16_t ns_id)

	outstanding_commands++;
	while (outstanding_commands) {
		nvme_ctrlr_process_io_completions(ctrlr, 100);
		spdk_nvme_ctrlr_process_io_completions(ctrlr, 100);
	}

	if (reserve_command_result)
@@ -225,21 +225,21 @@ reservation_ns_register(struct nvme_controller *ctrlr, uint16_t ns_id)
}

static int
reservation_ns_report(struct nvme_controller *ctrlr, uint16_t ns_id)
reservation_ns_report(struct spdk_nvme_ctrlr *ctrlr, uint16_t ns_id)
{
	int ret, i;
	uint8_t *payload;
	struct spdk_nvme_reservation_status_data *status;
	struct spdk_nvme_reservation_ctrlr_data *cdata;
	struct nvme_namespace *ns;
	struct spdk_nvme_ns *ns;

	ns = nvme_ctrlr_get_ns(ctrlr, ns_id);
	ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);
	payload = rte_zmalloc(NULL, 0x1000, 0x1000);

	outstanding_commands = 0;
	reserve_command_result = -1;

	ret = nvme_ns_cmd_reservation_report(ns, payload, 0x1000,
	ret = spdk_nvme_ns_cmd_reservation_report(ns, payload, 0x1000,
			reservation_ns_completion, NULL);
	if (ret) {
		fprintf(stderr, "Reservation Report Failed\n");
@@ -249,7 +249,7 @@ reservation_ns_report(struct nvme_controller *ctrlr, uint16_t ns_id)

	outstanding_commands++;
	while (outstanding_commands) {
		nvme_ctrlr_process_io_completions(ctrlr, 100);
		spdk_nvme_ctrlr_process_io_completions(ctrlr, 100);
	}

	if (reserve_command_result) {
@@ -277,20 +277,20 @@ reservation_ns_report(struct nvme_controller *ctrlr, uint16_t ns_id)
}

static int
reservation_ns_acquire(struct nvme_controller *ctrlr, uint16_t ns_id)
reservation_ns_acquire(struct spdk_nvme_ctrlr *ctrlr, uint16_t ns_id)
{
	int ret;
	struct spdk_nvme_reservation_acquire_data *cdata;
	struct nvme_namespace *ns;
	struct spdk_nvme_ns *ns;

	ns = nvme_ctrlr_get_ns(ctrlr, ns_id);
	ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);
	cdata = rte_zmalloc(NULL, sizeof(struct spdk_nvme_reservation_acquire_data), 0);
	cdata->crkey = CR_KEY;

	outstanding_commands = 0;
	reserve_command_result = -1;

	ret = nvme_ns_cmd_reservation_acquire(ns, cdata,
	ret = spdk_nvme_ns_cmd_reservation_acquire(ns, cdata,
			0,
			SPDK_NVME_RESERVE_ACQUIRE,
			SPDK_NVME_RESERVE_WRITE_EXCLUSIVE,
@@ -303,7 +303,7 @@ reservation_ns_acquire(struct nvme_controller *ctrlr, uint16_t ns_id)

	outstanding_commands++;
	while (outstanding_commands) {
		nvme_ctrlr_process_io_completions(ctrlr, 100);
		spdk_nvme_ctrlr_process_io_completions(ctrlr, 100);
	}

	if (reserve_command_result)
@@ -314,20 +314,20 @@ reservation_ns_acquire(struct nvme_controller *ctrlr, uint16_t ns_id)
}

static int
reservation_ns_release(struct nvme_controller *ctrlr, uint16_t ns_id)
reservation_ns_release(struct spdk_nvme_ctrlr *ctrlr, uint16_t ns_id)
{
	int ret;
	struct spdk_nvme_reservation_key_data *cdata;
	struct nvme_namespace *ns;
	struct spdk_nvme_ns *ns;

	ns = nvme_ctrlr_get_ns(ctrlr, ns_id);
	ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);
	cdata = rte_zmalloc(NULL, sizeof(struct spdk_nvme_reservation_key_data), 0);
	cdata->crkey = CR_KEY;

	outstanding_commands = 0;
	reserve_command_result = -1;

	ret = nvme_ns_cmd_reservation_release(ns, cdata,
	ret = spdk_nvme_ns_cmd_reservation_release(ns, cdata,
			0,
			SPDK_NVME_RESERVE_RELEASE,
			SPDK_NVME_RESERVE_WRITE_EXCLUSIVE,
@@ -340,7 +340,7 @@ reservation_ns_release(struct nvme_controller *ctrlr, uint16_t ns_id)

	outstanding_commands++;
	while (outstanding_commands) {
		nvme_ctrlr_process_io_completions(ctrlr, 100);
		spdk_nvme_ctrlr_process_io_completions(ctrlr, 100);
	}

	if (reserve_command_result)
@@ -351,11 +351,11 @@ reservation_ns_release(struct nvme_controller *ctrlr, uint16_t ns_id)
}

static void
reserve_controller(struct nvme_controller *ctrlr, struct spdk_pci_device *pci_dev)
reserve_controller(struct spdk_nvme_ctrlr *ctrlr, struct spdk_pci_device *pci_dev)
{
	const struct spdk_nvme_ctrlr_data	*cdata;

	cdata = nvme_ctrlr_get_data(ctrlr);
	cdata = spdk_nvme_ctrlr_get_data(ctrlr);

	printf("=====================================================\n");
	printf("NVMe Controller at PCI bus %d, device %d, function %d\n",
@@ -397,7 +397,7 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *dev)
}

static void
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct nvme_controller *ctrlr)
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr *ctrlr)
{
	struct dev *dev;

@@ -427,7 +427,7 @@ int main(int argc, char **argv)
	}

	request_mempool = rte_mempool_create("nvme_request", 8192,
					     nvme_request_size(), 128, 0,
					     spdk_nvme_request_size(), 128, 0,
					     NULL, NULL, NULL, NULL,
					     SOCKET_ID_ANY, 0);

@@ -436,13 +436,13 @@ int main(int argc, char **argv)
		exit(1);
	}

	if (nvme_probe(NULL, probe_cb, attach_cb) != 0) {
		fprintf(stderr, "nvme_probe() failed\n");
	if (spdk_nvme_probe(NULL, probe_cb, attach_cb) != 0) {
		fprintf(stderr, "spdk_nvme_probe() failed\n");
		return 1;
	}

	if (num_devs) {
		rc = nvme_register_io_thread();
		rc = spdk_nvme_register_io_thread();
		if (rc != 0)
			return rc;
	}
@@ -455,11 +455,11 @@ int main(int argc, char **argv)

	for (i = 0; i < num_devs; i++) {
		struct dev *dev = &devs[i];
		nvme_detach(dev->ctrlr);
		spdk_nvme_detach(dev->ctrlr);
	}

	if (num_devs)
		nvme_unregister_io_thread();
		spdk_nvme_unregister_io_thread();

	return rc;
}
+143 −144

File changed.

Preview size limit exceeded, changes collapsed.

+16 −15
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ struct nvme_driver g_nvme_driver = {
	.attached_ctrlrs = TAILQ_HEAD_INITIALIZER(g_nvme_driver.attached_ctrlrs),
};

int32_t		nvme_retry_count;
int32_t		spdk_nvme_retry_count;
__thread int	nvme_thread_ioq_index = -1;


@@ -68,14 +68,14 @@ __thread int nvme_thread_ioq_index = -1;

 */

static struct nvme_controller *
static struct spdk_nvme_ctrlr *
nvme_attach(void *devhandle)
{
	struct nvme_controller	*ctrlr;
	struct spdk_nvme_ctrlr	*ctrlr;
	int			status;
	uint64_t		phys_addr = 0;

	ctrlr = nvme_malloc("nvme_ctrlr", sizeof(struct nvme_controller),
	ctrlr = nvme_malloc("nvme_ctrlr", sizeof(struct spdk_nvme_ctrlr),
			    64, &phys_addr);
	if (ctrlr == NULL) {
		nvme_printf(NULL, "could not allocate ctrlr\n");
@@ -92,7 +92,7 @@ nvme_attach(void *devhandle)
}

int
nvme_detach(struct nvme_controller *ctrlr)
spdk_nvme_detach(struct spdk_nvme_ctrlr *ctrlr)
{
	struct nvme_driver	*driver = &g_nvme_driver;

@@ -121,14 +121,14 @@ nvme_completion_poll_cb(void *arg, const struct spdk_nvme_cpl *cpl)
}

size_t
nvme_request_size(void)
spdk_nvme_request_size(void)
{
	return sizeof(struct nvme_request);
}

struct nvme_request *
nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size,
		      nvme_cb_fn_t cb_fn, void *cb_arg)
		      spdk_nvme_cmd_cb cb_fn, void *cb_arg)
{
	struct nvme_request *req = NULL;

@@ -158,7 +158,8 @@ nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size,
}

struct nvme_request *
nvme_allocate_request_contig(void *buffer, uint32_t payload_size, nvme_cb_fn_t cb_fn, void *cb_arg)
nvme_allocate_request_contig(void *buffer, uint32_t payload_size, spdk_nvme_cmd_cb cb_fn,
			     void *cb_arg)
{
	struct nvme_payload payload;

@@ -169,7 +170,7 @@ nvme_allocate_request_contig(void *buffer, uint32_t payload_size, nvme_cb_fn_t c
}

struct nvme_request *
nvme_allocate_request_null(nvme_cb_fn_t cb_fn, void *cb_arg)
nvme_allocate_request_null(spdk_nvme_cmd_cb cb_fn, void *cb_arg)
{
	return nvme_allocate_request_contig(NULL, 0, cb_fn, cb_arg);
}
@@ -229,7 +230,7 @@ nvme_free_ioq_index(void)
}

int
nvme_register_io_thread(void)
spdk_nvme_register_io_thread(void)
{
	int rc = 0;

@@ -247,13 +248,13 @@ nvme_register_io_thread(void)
}

void
nvme_unregister_io_thread(void)
spdk_nvme_unregister_io_thread(void)
{
	nvme_free_ioq_index();
}

struct nvme_enum_ctx {
	nvme_probe_cb probe_cb;
	spdk_nvme_probe_cb probe_cb;
	void *cb_ctx;
};

@@ -262,7 +263,7 @@ static int
nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
{
	struct nvme_enum_ctx *enum_ctx = ctx;
	struct nvme_controller *ctrlr;
	struct spdk_nvme_ctrlr *ctrlr;

	/* Verify that this controller is not already attached */
	TAILQ_FOREACH(ctrlr, &g_nvme_driver.attached_ctrlrs, tailq) {
@@ -288,11 +289,11 @@ nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
}

int
nvme_probe(void *cb_ctx, nvme_probe_cb probe_cb, nvme_attach_cb attach_cb)
spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_cb)
{
	int rc, start_rc;
	struct nvme_enum_ctx enum_ctx;
	struct nvme_controller *ctrlr;
	struct spdk_nvme_ctrlr *ctrlr;

	nvme_mutex_lock(&g_nvme_driver.lock);

Loading