static int nvmf_direct_ctrlr_admin_identify_nslist(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvmf_request *req) { struct spdk_nvme_ns *ns; struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; uint32_t req_ns_id = cmd->nsid; uint32_t i, num_ns, count = 0; struct spdk_nvme_ns_list *ns_list; if (req_ns_id >= 0xfffffffeUL) { return -1; } memset(req->data, 0, req->length); num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr); ns_list = (struct spdk_nvme_ns_list *)req->data; for (i = 1; i <= num_ns; i++) { ns = spdk_nvme_ctrlr_get_ns(ctrlr, i); if (!spdk_nvme_ns_is_active(ns)) { continue; } if (i <= req_ns_id) { continue; } ns_list->ns_list[count++] = i; if (count == sizeof(*ns_list) / sizeof(uint32_t)) { break; } } return 0; }
static int u2_init(void) { if (rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]),ealargs) < 0) { fprintf(stderr, "failed to initialize DPDK EAL!\n"); return 1; } printf("\n========================================\n"); printf( " nvme_lat/u2_lat - ict.ncic.syssw.ufo" ); printf("\n========================================\n"); request_mempool = rte_mempool_create("nvme_request", U2_REQUEST_POOL_SIZE, spdk_nvme_request_size(), U2_REQUEST_CACHE_SIZE, U2_REQUEST_PRIVATE_SIZE, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); if (request_mempool == NULL) { fprintf(stderr, "failed to create request pool!\n"); return 1; } if (spdk_nvme_probe(NULL, probe_cb, attach_cb)) { fprintf(stderr, "failed to probe and attach to NVMe device!\n"); return 1; } if (!u2_ctrlr) { fprintf(stderr, "failed to probe a suitable controller!\n"); return 1; } if (!spdk_nvme_ns_is_active(u2_ns)) { fprintf(stderr, "namespace %d is IN-ACTIVE!\n", u2_ns_id); return 1; } if (u2_ns_size < io_size) { fprintf(stderr, "invalid I/O size %"PRIu32"!\n", io_size); return 1; } if (!u2_qpair) { fprintf(stderr, "failed to allocate queue pair!\n"); return 1; } return 0; }
static void register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns) { struct ns_entry *entry; const struct spdk_nvme_ctrlr_data *cdata; cdata = spdk_nvme_ctrlr_get_data(ctrlr); if (!spdk_nvme_ns_is_active(ns)) { printf("Controller %-20.20s (%-20.20s): Skipping inactive NS %u\n", cdata->mn, cdata->sn, spdk_nvme_ns_get_id(ns)); return; } 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, spdk_nvme_ns_get_id(ns), spdk_nvme_ns_get_size(ns), spdk_nvme_ns_get_sector_size(ns), g_io_size_bytes); return; } entry = malloc(sizeof(struct ns_entry)); if (entry == NULL) { perror("ns_entry malloc"); exit(1); } entry->type = ENTRY_TYPE_NVME_NS; entry->u.nvme.ctrlr = ctrlr; entry->u.nvme.ns = ns; entry->size_in_ios = spdk_nvme_ns_get_size(ns) / g_io_size_bytes; 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); g_num_namespaces++; entry->next = g_namespaces; g_namespaces = entry; }
static void register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns) { struct ns_entry *entry; const struct spdk_nvme_ctrlr_data *cdata; /* * spdk_nvme_ctrlr is the logical abstraction in SPDK for an NVMe * controller. During initialization, the IDENTIFY data for the * controller is read using an NVMe admin command, and that data * can be retrieved using spdk_nvme_ctrlr_get_data() to get * detailed information on the controller. Refer to the NVMe * specification for more details on IDENTIFY for NVMe controllers. */ cdata = spdk_nvme_ctrlr_get_data(ctrlr); if (!spdk_nvme_ns_is_active(ns)) { printf("Controller %-20.20s (%-20.20s): Skipping inactive NS %u\n", cdata->mn, cdata->sn, spdk_nvme_ns_get_id(ns)); return; } entry = malloc(sizeof(struct ns_entry)); if (entry == NULL) { perror("ns_entry malloc"); exit(1); } entry->ctrlr = ctrlr; entry->ns = ns; entry->next = g_namespaces; g_namespaces = entry; printf(" Namespace ID: %d size: %juGB\n", spdk_nvme_ns_get_id(ns), spdk_nvme_ns_get_size(ns) / 1000000000); }