Loading lib/nvmf/conf.c +85 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ #include <string.h> #include "conf.h" #include "controller.h" #include "host.h" #include "nvmf_internal.h" #include "port.h" Loading Loading @@ -298,6 +299,84 @@ spdk_nvmf_parse_hosts(void) return 0; } static int spdk_nvmf_parse_nvme(void) { struct spdk_conf_section *sp; struct nvme_bdf_whitelist *whitelist = NULL; const char *val; bool claim_all = false; bool unbind_from_kernel = false; int i = 0; int rc; sp = spdk_conf_find_section(NULL, "Nvme"); if (sp == NULL) { SPDK_ERRLOG("NVMe device section in config file not found!\n"); return -1; } val = spdk_conf_section_get_val(sp, "ClaimAllDevices"); if (val != NULL) { if (!strcmp(val, "Yes")) { claim_all = true; } } val = spdk_conf_section_get_val(sp, "UnbindFromKernel"); if (val != NULL) { if (!strcmp(val, "Yes")) { unbind_from_kernel = true; } } if (!claim_all) { for (i = 0; ; i++) { unsigned int domain, bus, dev, func; val = spdk_conf_section_get_nmval(sp, "BDF", i, 0); if (val == NULL) { break; } whitelist = realloc(whitelist, sizeof(*whitelist) * (i + 1)); rc = sscanf(val, "%x:%x:%x.%x", &domain, &bus, &dev, &func); if (rc != 4) { SPDK_ERRLOG("Invalid format for BDF: %s\n", val); free(whitelist); return -1; } whitelist[i].domain = domain; whitelist[i].bus = bus; whitelist[i].dev = dev; whitelist[i].func = func; val = spdk_conf_section_get_nmval(sp, "BDF", i, 1); if (val == NULL) { SPDK_ERRLOG("BDF section with no device name\n"); free(whitelist); return -1; } snprintf(whitelist[i].name, MAX_NVME_NAME_LENGTH, "%s", val); } if (i == 0) { SPDK_ERRLOG("No BDF section\n"); return -1; } } rc = spdk_nvmf_init_nvme(whitelist, i, claim_all, unbind_from_kernel); free(whitelist); return rc; } int spdk_nvmf_parse_conf(void) { Loading @@ -321,5 +400,11 @@ spdk_nvmf_parse_conf(void) return rc; } /* NVMe sections */ rc = spdk_nvmf_parse_nvme(); if (rc < 0) { return rc; } return 0; } lib/nvmf/controller.c +7 −70 Original line number Diff line number Diff line Loading @@ -41,19 +41,11 @@ static TAILQ_HEAD(, spdk_nvmf_ctrlr) g_ctrlrs = TAILQ_HEAD_INITIALIZER(g_ctrlrs) #define SPDK_NVMF_MAX_NVME_DEVICES 64 struct nvme_bdf_whitelist { uint16_t domain; uint8_t bus; uint8_t dev; uint8_t func; char name[MAX_NVME_NAME_LENGTH]; }; struct spdk_nvmf_probe_ctx { bool claim_all; bool unbind_from_kernel; int whitelist_count; struct nvme_bdf_whitelist whitelist[SPDK_NVMF_MAX_NVME_DEVICES]; struct nvme_bdf_whitelist *whitelist; }; static void Loading Loading @@ -213,70 +205,15 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctr } int spdk_nvmf_init_nvme(void) spdk_nvmf_init_nvme(struct nvme_bdf_whitelist *whitelist, size_t whitelist_count, bool claim_all, bool unbind_from_kernel) { struct spdk_conf_section *sp; struct spdk_nvmf_probe_ctx ctx = { 0 }; const char *val; int i, rc; SPDK_NOTICELOG("*** Initialize NVMe Devices ***\n"); sp = spdk_conf_find_section(NULL, "Nvme"); if (sp == NULL) { SPDK_ERRLOG("NVMe device section in config file not found!\n"); return -1; } val = spdk_conf_section_get_val(sp, "ClaimAllDevices"); if (val != NULL) { if (!strcmp(val, "Yes")) { ctx.claim_all = true; } } val = spdk_conf_section_get_val(sp, "UnbindFromKernel"); if (val != NULL) { if (!strcmp(val, "Yes")) { ctx.unbind_from_kernel = true; } } if (!ctx.claim_all) { for (i = 0; ; i++) { unsigned int domain, bus, dev, func; val = spdk_conf_section_get_nmval(sp, "BDF", i, 0); if (val == NULL) { break; } rc = sscanf(val, "%x:%x:%x.%x", &domain, &bus, &dev, &func); if (rc != 4) { SPDK_ERRLOG("Invalid format for BDF: %s\n", val); return -1; } ctx.whitelist[ctx.whitelist_count].domain = domain; ctx.whitelist[ctx.whitelist_count].bus = bus; ctx.whitelist[ctx.whitelist_count].dev = dev; ctx.whitelist[ctx.whitelist_count].func = func; val = spdk_conf_section_get_nmval(sp, "BDF", i, 1); if (val == NULL) { SPDK_ERRLOG("BDF section with no device name\n"); return -1; } snprintf(ctx.whitelist[ctx.whitelist_count].name, MAX_NVME_NAME_LENGTH, "%s", val); ctx.whitelist_count++; } if (ctx.whitelist_count == 0) { SPDK_ERRLOG("No BDF section\n"); return -1; } } ctx.whitelist = whitelist; ctx.whitelist_count = whitelist_count; ctx.claim_all = claim_all; ctx.unbind_from_kernel = unbind_from_kernel; /* Probe the physical NVMe devices */ if (spdk_nvme_probe(&ctx, probe_cb, attach_cb, NULL)) { Loading lib/nvmf/controller.h +10 −1 Original line number Diff line number Diff line Loading @@ -40,6 +40,14 @@ #define MAX_NVME_NAME_LENGTH 64 struct nvme_bdf_whitelist { uint16_t domain; uint8_t bus; uint8_t dev; uint8_t func; char name[MAX_NVME_NAME_LENGTH]; }; struct spdk_nvmf_ctrlr { struct spdk_nvme_ctrlr *ctrlr; char name[MAX_NVME_NAME_LENGTH]; Loading @@ -47,7 +55,8 @@ struct spdk_nvmf_ctrlr { TAILQ_ENTRY(spdk_nvmf_ctrlr) entry; }; int spdk_nvmf_init_nvme(void); int spdk_nvmf_init_nvme(struct nvme_bdf_whitelist *whitelist, size_t whitelist_count, bool claim_all, bool unbind_from_kernel); int spdk_nvmf_shutdown_nvme(void); struct spdk_nvmf_ctrlr * Loading lib/nvmf/nvmf.c +0 −6 Original line number Diff line number Diff line Loading @@ -170,12 +170,6 @@ nvmf_tgt_subsystem_initialize(void) SPDK_ERRLOG("spdk_nvmf_rdma_init() failed\n"); return rc; } /* initialize NVMe/NVMf backend */ rc = spdk_nvmf_init_nvme(); if (rc < 0) { fprintf(stderr, "NVMf could not initialize NVMe devices.\n"); return -1; } rc = spdk_initialize_nvmf_subsystems(); if (rc < 0) { Loading Loading
lib/nvmf/conf.c +85 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ #include <string.h> #include "conf.h" #include "controller.h" #include "host.h" #include "nvmf_internal.h" #include "port.h" Loading Loading @@ -298,6 +299,84 @@ spdk_nvmf_parse_hosts(void) return 0; } static int spdk_nvmf_parse_nvme(void) { struct spdk_conf_section *sp; struct nvme_bdf_whitelist *whitelist = NULL; const char *val; bool claim_all = false; bool unbind_from_kernel = false; int i = 0; int rc; sp = spdk_conf_find_section(NULL, "Nvme"); if (sp == NULL) { SPDK_ERRLOG("NVMe device section in config file not found!\n"); return -1; } val = spdk_conf_section_get_val(sp, "ClaimAllDevices"); if (val != NULL) { if (!strcmp(val, "Yes")) { claim_all = true; } } val = spdk_conf_section_get_val(sp, "UnbindFromKernel"); if (val != NULL) { if (!strcmp(val, "Yes")) { unbind_from_kernel = true; } } if (!claim_all) { for (i = 0; ; i++) { unsigned int domain, bus, dev, func; val = spdk_conf_section_get_nmval(sp, "BDF", i, 0); if (val == NULL) { break; } whitelist = realloc(whitelist, sizeof(*whitelist) * (i + 1)); rc = sscanf(val, "%x:%x:%x.%x", &domain, &bus, &dev, &func); if (rc != 4) { SPDK_ERRLOG("Invalid format for BDF: %s\n", val); free(whitelist); return -1; } whitelist[i].domain = domain; whitelist[i].bus = bus; whitelist[i].dev = dev; whitelist[i].func = func; val = spdk_conf_section_get_nmval(sp, "BDF", i, 1); if (val == NULL) { SPDK_ERRLOG("BDF section with no device name\n"); free(whitelist); return -1; } snprintf(whitelist[i].name, MAX_NVME_NAME_LENGTH, "%s", val); } if (i == 0) { SPDK_ERRLOG("No BDF section\n"); return -1; } } rc = spdk_nvmf_init_nvme(whitelist, i, claim_all, unbind_from_kernel); free(whitelist); return rc; } int spdk_nvmf_parse_conf(void) { Loading @@ -321,5 +400,11 @@ spdk_nvmf_parse_conf(void) return rc; } /* NVMe sections */ rc = spdk_nvmf_parse_nvme(); if (rc < 0) { return rc; } return 0; }
lib/nvmf/controller.c +7 −70 Original line number Diff line number Diff line Loading @@ -41,19 +41,11 @@ static TAILQ_HEAD(, spdk_nvmf_ctrlr) g_ctrlrs = TAILQ_HEAD_INITIALIZER(g_ctrlrs) #define SPDK_NVMF_MAX_NVME_DEVICES 64 struct nvme_bdf_whitelist { uint16_t domain; uint8_t bus; uint8_t dev; uint8_t func; char name[MAX_NVME_NAME_LENGTH]; }; struct spdk_nvmf_probe_ctx { bool claim_all; bool unbind_from_kernel; int whitelist_count; struct nvme_bdf_whitelist whitelist[SPDK_NVMF_MAX_NVME_DEVICES]; struct nvme_bdf_whitelist *whitelist; }; static void Loading Loading @@ -213,70 +205,15 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctr } int spdk_nvmf_init_nvme(void) spdk_nvmf_init_nvme(struct nvme_bdf_whitelist *whitelist, size_t whitelist_count, bool claim_all, bool unbind_from_kernel) { struct spdk_conf_section *sp; struct spdk_nvmf_probe_ctx ctx = { 0 }; const char *val; int i, rc; SPDK_NOTICELOG("*** Initialize NVMe Devices ***\n"); sp = spdk_conf_find_section(NULL, "Nvme"); if (sp == NULL) { SPDK_ERRLOG("NVMe device section in config file not found!\n"); return -1; } val = spdk_conf_section_get_val(sp, "ClaimAllDevices"); if (val != NULL) { if (!strcmp(val, "Yes")) { ctx.claim_all = true; } } val = spdk_conf_section_get_val(sp, "UnbindFromKernel"); if (val != NULL) { if (!strcmp(val, "Yes")) { ctx.unbind_from_kernel = true; } } if (!ctx.claim_all) { for (i = 0; ; i++) { unsigned int domain, bus, dev, func; val = spdk_conf_section_get_nmval(sp, "BDF", i, 0); if (val == NULL) { break; } rc = sscanf(val, "%x:%x:%x.%x", &domain, &bus, &dev, &func); if (rc != 4) { SPDK_ERRLOG("Invalid format for BDF: %s\n", val); return -1; } ctx.whitelist[ctx.whitelist_count].domain = domain; ctx.whitelist[ctx.whitelist_count].bus = bus; ctx.whitelist[ctx.whitelist_count].dev = dev; ctx.whitelist[ctx.whitelist_count].func = func; val = spdk_conf_section_get_nmval(sp, "BDF", i, 1); if (val == NULL) { SPDK_ERRLOG("BDF section with no device name\n"); return -1; } snprintf(ctx.whitelist[ctx.whitelist_count].name, MAX_NVME_NAME_LENGTH, "%s", val); ctx.whitelist_count++; } if (ctx.whitelist_count == 0) { SPDK_ERRLOG("No BDF section\n"); return -1; } } ctx.whitelist = whitelist; ctx.whitelist_count = whitelist_count; ctx.claim_all = claim_all; ctx.unbind_from_kernel = unbind_from_kernel; /* Probe the physical NVMe devices */ if (spdk_nvme_probe(&ctx, probe_cb, attach_cb, NULL)) { Loading
lib/nvmf/controller.h +10 −1 Original line number Diff line number Diff line Loading @@ -40,6 +40,14 @@ #define MAX_NVME_NAME_LENGTH 64 struct nvme_bdf_whitelist { uint16_t domain; uint8_t bus; uint8_t dev; uint8_t func; char name[MAX_NVME_NAME_LENGTH]; }; struct spdk_nvmf_ctrlr { struct spdk_nvme_ctrlr *ctrlr; char name[MAX_NVME_NAME_LENGTH]; Loading @@ -47,7 +55,8 @@ struct spdk_nvmf_ctrlr { TAILQ_ENTRY(spdk_nvmf_ctrlr) entry; }; int spdk_nvmf_init_nvme(void); int spdk_nvmf_init_nvme(struct nvme_bdf_whitelist *whitelist, size_t whitelist_count, bool claim_all, bool unbind_from_kernel); int spdk_nvmf_shutdown_nvme(void); struct spdk_nvmf_ctrlr * Loading
lib/nvmf/nvmf.c +0 −6 Original line number Diff line number Diff line Loading @@ -170,12 +170,6 @@ nvmf_tgt_subsystem_initialize(void) SPDK_ERRLOG("spdk_nvmf_rdma_init() failed\n"); return rc; } /* initialize NVMe/NVMf backend */ rc = spdk_nvmf_init_nvme(); if (rc < 0) { fprintf(stderr, "NVMf could not initialize NVMe devices.\n"); return -1; } rc = spdk_initialize_nvmf_subsystems(); if (rc < 0) { Loading