Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/nvmecontrol/ns.c
Show First 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | nscreate(int argc, char *argv[]) | ||||
nsdata.dps = ((pi & NVME_NS_DATA_DPS_MD_START_MASK) | nsdata.dps = ((pi & NVME_NS_DATA_DPS_MD_START_MASK) | ||||
<< NVME_NS_DATA_DPS_MD_START_SHIFT) | | << NVME_NS_DATA_DPS_MD_START_SHIFT) | | ||||
((pil & NVME_NS_DATA_DPS_PIT_MASK) | ((pil & NVME_NS_DATA_DPS_PIT_MASK) | ||||
<< NVME_NS_DATA_DPS_PIT_SHIFT); | << NVME_NS_DATA_DPS_PIT_SHIFT); | ||||
nsdata.nmic = nmic; | nsdata.nmic = nmic; | ||||
nvme_namespace_data_swapbytes(&nsdata); | nvme_namespace_data_swapbytes(&nsdata); | ||||
memset(&pt, 0, sizeof(pt)); | memset(&pt, 0, sizeof(pt)); | ||||
pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_NAMESPACE_MANAGEMENT); | pt.cmd.opc = NVME_OPC_NAMESPACE_MANAGEMENT; | ||||
pt.cmd.cdw10 = 0; /* create */ | pt.cmd.cdw10 = 0; /* create */ | ||||
pt.buf = &nsdata; | pt.buf = &nsdata; | ||||
pt.len = sizeof(struct nvme_namespace_data); | pt.len = sizeof(struct nvme_namespace_data); | ||||
pt.is_read = 0; /* passthrough writes data to ctrlr */ | pt.is_read = 0; /* passthrough writes data to ctrlr */ | ||||
if ((result = ioctl(fd, NVME_PASSTHROUGH_CMD, &pt)) < 0) | if ((result = ioctl(fd, NVME_PASSTHROUGH_CMD, &pt)) < 0) | ||||
errx(1, "ioctl request to %s failed: %d", argv[optind], result); | errx(1, "ioctl request to %s failed: %d", argv[optind], result); | ||||
Show All 34 Lines | nsdelete(int argc, char *argv[]) | ||||
read_controller_data(fd, &cd); | read_controller_data(fd, &cd); | ||||
/* Check that controller can execute this command. */ | /* Check that controller can execute this command. */ | ||||
if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) & | if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) & | ||||
NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0) | NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0) | ||||
errx(1, "controller does not support namespace management"); | errx(1, "controller does not support namespace management"); | ||||
memset(&pt, 0, sizeof(pt)); | memset(&pt, 0, sizeof(pt)); | ||||
pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_NAMESPACE_MANAGEMENT); | pt.cmd.opc = NVME_OPC_NAMESPACE_MANAGEMENT; | ||||
pt.cmd.cdw10 = 1; /* delete */ | pt.cmd.cdw10 = 1; /* delete */ | ||||
pt.buf = buf; | pt.buf = buf; | ||||
pt.len = sizeof(buf); | pt.len = sizeof(buf); | ||||
pt.is_read = 1; | pt.is_read = 1; | ||||
pt.cmd.nsid = (uint32_t)nsid; | pt.cmd.nsid = (uint32_t)nsid; | ||||
if ((result = ioctl(fd, NVME_PASSTHROUGH_CMD, &pt)) < 0) | if ((result = ioctl(fd, NVME_PASSTHROUGH_CMD, &pt)) < 0) | ||||
errx(1, "ioctl request to %s failed: %d", argv[optind], result); | errx(1, "ioctl request to %s failed: %d", argv[optind], result); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | nsattach(int argc, char *argv[]) | ||||
/* Check that controller can execute this command. */ | /* Check that controller can execute this command. */ | ||||
if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) & | if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) & | ||||
NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0) | NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0) | ||||
errx(1, "controller does not support namespace management"); | errx(1, "controller does not support namespace management"); | ||||
if (ctrlrid == -1) { | if (ctrlrid == -1) { | ||||
/* Get full list of controllers to attach to. */ | /* Get full list of controllers to attach to. */ | ||||
memset(&pt, 0, sizeof(pt)); | memset(&pt, 0, sizeof(pt)); | ||||
pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_IDENTIFY); | pt.cmd.opc = NVME_OPC_IDENTIFY; | ||||
pt.cmd.cdw10 = htole32(0x13); | pt.cmd.cdw10 = htole32(0x13); | ||||
pt.buf = clist; | pt.buf = clist; | ||||
pt.len = sizeof(clist); | pt.len = sizeof(clist); | ||||
pt.is_read = 1; | pt.is_read = 1; | ||||
if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0) | if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0) | ||||
err(1, "identify request failed"); | err(1, "identify request failed"); | ||||
if (nvme_completion_is_error(&pt.cpl)) | if (nvme_completion_is_error(&pt.cpl)) | ||||
errx(1, "identify request returned error"); | errx(1, "identify request returned error"); | ||||
} else { | } else { | ||||
/* By default attach to this controller. */ | /* By default attach to this controller. */ | ||||
if (ctrlrid == -2) | if (ctrlrid == -2) | ||||
ctrlrid = cd.ctrlr_id; | ctrlrid = cd.ctrlr_id; | ||||
memset(&clist, 0, sizeof(clist)); | memset(&clist, 0, sizeof(clist)); | ||||
clist[0] = htole16(1); | clist[0] = htole16(1); | ||||
clist[1] = htole16(ctrlrid); | clist[1] = htole16(ctrlrid); | ||||
} | } | ||||
memset(&pt, 0, sizeof(pt)); | memset(&pt, 0, sizeof(pt)); | ||||
pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_NAMESPACE_ATTACHMENT); | pt.cmd.opc = NVME_OPC_NAMESPACE_ATTACHMENT; | ||||
pt.cmd.cdw10 = 0; /* attach */ | pt.cmd.cdw10 = 0; /* attach */ | ||||
pt.cmd.nsid = (uint32_t)nsid; | pt.cmd.nsid = (uint32_t)nsid; | ||||
pt.buf = &clist; | pt.buf = &clist; | ||||
pt.len = sizeof(clist); | pt.len = sizeof(clist); | ||||
if ((result = ioctl(fd, NVME_PASSTHROUGH_CMD, &pt)) < 0) | if ((result = ioctl(fd, NVME_PASSTHROUGH_CMD, &pt)) < 0) | ||||
errx(1, "ioctl request to %s failed: %d", argv[optind], result); | errx(1, "ioctl request to %s failed: %d", argv[optind], result); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | nsdetach(int argc, char *argv[]) | ||||
/* Check that controller can execute this command. */ | /* Check that controller can execute this command. */ | ||||
if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) & | if (((cd.oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) & | ||||
NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0) | NVME_CTRLR_DATA_OACS_NSMGMT_MASK) == 0) | ||||
errx(1, "controller does not support namespace management"); | errx(1, "controller does not support namespace management"); | ||||
if (ctrlrid == -1) { | if (ctrlrid == -1) { | ||||
/* Get list of controllers this namespace attached to. */ | /* Get list of controllers this namespace attached to. */ | ||||
memset(&pt, 0, sizeof(pt)); | memset(&pt, 0, sizeof(pt)); | ||||
pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_IDENTIFY); | pt.cmd.opc = NVME_OPC_IDENTIFY; | ||||
pt.cmd.nsid = htole32(nsid); | pt.cmd.nsid = htole32(nsid); | ||||
pt.cmd.cdw10 = htole32(0x12); | pt.cmd.cdw10 = htole32(0x12); | ||||
pt.buf = clist; | pt.buf = clist; | ||||
pt.len = sizeof(clist); | pt.len = sizeof(clist); | ||||
pt.is_read = 1; | pt.is_read = 1; | ||||
if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0) | if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0) | ||||
err(1, "identify request failed"); | err(1, "identify request failed"); | ||||
if (nvme_completion_is_error(&pt.cpl)) | if (nvme_completion_is_error(&pt.cpl)) | ||||
Show All 9 Lines | if (ctrlrid == -1) { | ||||
if (ctrlrid == -2) | if (ctrlrid == -2) | ||||
ctrlrid = cd.ctrlr_id; | ctrlrid = cd.ctrlr_id; | ||||
memset(&clist, 0, sizeof(clist)); | memset(&clist, 0, sizeof(clist)); | ||||
clist[0] = htole16(1); | clist[0] = htole16(1); | ||||
clist[1] = htole16(ctrlrid); | clist[1] = htole16(ctrlrid); | ||||
} | } | ||||
memset(&pt, 0, sizeof(pt)); | memset(&pt, 0, sizeof(pt)); | ||||
pt.cmd.opc_fuse = NVME_CMD_SET_OPC(NVME_OPC_NAMESPACE_ATTACHMENT); | pt.cmd.opc = NVME_OPC_NAMESPACE_ATTACHMENT; | ||||
pt.cmd.cdw10 = 1; /* detach */ | pt.cmd.cdw10 = 1; /* detach */ | ||||
pt.cmd.nsid = (uint32_t)nsid; | pt.cmd.nsid = (uint32_t)nsid; | ||||
pt.buf = &clist; | pt.buf = &clist; | ||||
pt.len = sizeof(clist); | pt.len = sizeof(clist); | ||||
if ((result = ioctl(fd, NVME_PASSTHROUGH_CMD, &pt)) < 0) | if ((result = ioctl(fd, NVME_PASSTHROUGH_CMD, &pt)) < 0) | ||||
errx(1, "ioctl request to %s failed: %d", argv[optind], result); | errx(1, "ioctl request to %s failed: %d", argv[optind], result); | ||||
Show All 15 Lines |