Changeset View
Changeset View
Standalone View
Standalone View
sbin/nvmecontrol/devlist.c
| Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | ns_get_sector_size(struct nvme_namespace_data *nsdata) | ||||
| flbas_fmt = NVMEV(NVME_NS_DATA_FLBAS_FORMAT, nsdata->flbas); | flbas_fmt = NVMEV(NVME_NS_DATA_FLBAS_FORMAT, nsdata->flbas); | ||||
| lbads = NVMEV(NVME_NS_DATA_LBAF_LBADS, nsdata->lbaf[flbas_fmt]); | lbads = NVMEV(NVME_NS_DATA_LBAF_LBADS, nsdata->lbaf[flbas_fmt]); | ||||
| return (1 << lbads); | return (1 << lbads); | ||||
| } | } | ||||
| static void | static void | ||||
| devlist(const struct cmd *f, int argc, char *argv[]) | scan_namespace(int fd, int ctrlr, uint32_t nsid) | ||||
| { | { | ||||
| struct nvme_controller_data cdata; | |||||
| struct nvme_namespace_data nsdata; | struct nvme_namespace_data nsdata; | ||||
| char name[64]; | char name[64]; | ||||
imp: Is there a better #define that we can use? 64 is fine, but I can't say why | |||||
Done Inline ActionsThat is in the old code and I just kept it. 64 is arbitrary, but as long as it's only in one place and everything else uses sizeof(name) I'm fine with that. If we had a constant for the largest possible filename in a component, maybe that could be used instead? (So not PATH_MAX, but NAME_MAX I guess?) jhb: That is in the old code and I just kept it. 64 is arbitrary, but as long as it's only in one… | |||||
Not Done Inline ActionsGotcha! imp: Gotcha! | |||||
| uint8_t mn[64]; | |||||
| uint8_t buf[7]; | uint8_t buf[7]; | ||||
| uint32_t i; | |||||
| uint64_t size; | uint64_t size; | ||||
| int ctrlr, fd, found, ret; | |||||
| if (arg_parse(argc, argv, f)) | if (read_namespace_data(fd, nsid, &nsdata) != 0) | ||||
| return; | return; | ||||
| if (nsdata.nsze == 0) | |||||
| return; | |||||
| snprintf(name, sizeof(name), "%s%d%s%d", NVME_CTRLR_PREFIX, ctrlr, | |||||
| NVME_NS_PREFIX, nsid); | |||||
| size = nsdata.nsze * (uint64_t)ns_get_sector_size(&nsdata); | |||||
| if (opt.human) { | |||||
| humanize_number(buf, sizeof(buf), size, "B", | |||||
| HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); | |||||
| printf(" %10s (%s)\n", name, buf); | |||||
| } else { | |||||
| printf(" %10s (%juMB)\n", name, (uintmax_t)size / 1024 / 1024); | |||||
| } | |||||
| } | |||||
| ctrlr = -1; | static bool | ||||
| found = 0; | scan_controller(int ctrlr) | ||||
| { | |||||
| struct nvme_controller_data cdata; | |||||
| char name[64]; | |||||
| uint8_t mn[64]; | |||||
| uint32_t i; | |||||
| int fd, ret; | |||||
| while (ctrlr < NVME_MAX_UNIT) { | snprintf(name, sizeof(name), "%s%d", NVME_CTRLR_PREFIX, ctrlr); | ||||
| ctrlr++; | |||||
| sprintf(name, "%s%d", NVME_CTRLR_PREFIX, ctrlr); | |||||
| ret = open_dev(name, &fd, 0, 0); | ret = open_dev(name, &fd, 0, 0); | ||||
| if (ret == EACCES) { | if (ret == EACCES) { | ||||
| warnx("could not open "_PATH_DEV"%s\n", name); | warnx("could not open "_PATH_DEV"%s\n", name); | ||||
| continue; | return (false); | ||||
| } else if (ret != 0) | } else if (ret != 0) | ||||
| continue; | return (false); | ||||
| found++; | if (read_controller_data(fd, &cdata) != 0) { | ||||
| if (read_controller_data(fd, &cdata)) | close(fd); | ||||
| continue; | return (true); | ||||
| } | |||||
| nvme_strvis(mn, cdata.mn, sizeof(mn), NVME_MODEL_NUMBER_LENGTH); | nvme_strvis(mn, cdata.mn, sizeof(mn), NVME_MODEL_NUMBER_LENGTH); | ||||
| printf("%6s: %s\n", name, mn); | printf("%6s: %s\n", name, mn); | ||||
| for (i = 0; i < cdata.nn; i++) { | for (i = 0; i < cdata.nn; i++) { | ||||
| if (read_namespace_data(fd, i + 1, &nsdata)) | scan_namespace(fd, ctrlr, i + 1); | ||||
| continue; | |||||
| if (nsdata.nsze == 0) | |||||
| continue; | |||||
| sprintf(name, "%s%d%s%d", NVME_CTRLR_PREFIX, ctrlr, | |||||
| NVME_NS_PREFIX, i + 1); | |||||
| size = nsdata.nsze * (uint64_t)ns_get_sector_size(&nsdata); | |||||
| if (opt.human) { | |||||
| humanize_number(buf, sizeof(buf), size, "B", | |||||
| HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); | |||||
| printf(" %10s (%s)\n", name, buf); | |||||
| } else { | |||||
| printf(" %10s (%juMB)\n", name, (uintmax_t)size / 1024 / 1024); | |||||
| } | } | ||||
| } | |||||
| close(fd); | close(fd); | ||||
| return (true); | |||||
| } | |||||
| static void | |||||
| devlist(const struct cmd *f, int argc, char *argv[]) | |||||
| { | |||||
| int ctrlr, found; | |||||
| if (arg_parse(argc, argv, f)) | |||||
| return; | |||||
| ctrlr = -1; | |||||
| found = 0; | |||||
| while (ctrlr < NVME_MAX_UNIT) { | |||||
| ctrlr++; | |||||
| if (scan_controller(ctrlr)) | |||||
| found++; | |||||
| } | } | ||||
| if (found == 0) { | if (found == 0) { | ||||
| printf("No NVMe controllers found.\n"); | printf("No NVMe controllers found.\n"); | ||||
| exit(EX_UNAVAILABLE); | exit(EX_UNAVAILABLE); | ||||
| } | } | ||||
| exit(0); | exit(0); | ||||
| } | } | ||||
Is there a better #define that we can use? 64 is fine, but I can't say why