Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/nvmecontrol/ns.c
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | #define NSDELETE_USAGE \ | ||||
"ns delete -n nsid nvmeN\n" | "ns delete -n nsid nvmeN\n" | ||||
#define NSATTACH_USAGE \ | #define NSATTACH_USAGE \ | ||||
"ns attach -n nsid [-c ctrlrid] nvmeN \n" | "ns attach -n nsid [-c ctrlrid] nvmeN \n" | ||||
#define NSDETACH_USAGE \ | #define NSDETACH_USAGE \ | ||||
"ns detach -n nsid [-c ctrlrid] nvmeN\n" | "ns detach -n nsid [-c ctrlrid] nvmeN\n" | ||||
void nscreate(struct nvme_function *nf, int argc, char *argv[]); | static void nscreate(const struct nvme_function *nf, int argc, char *argv[]); | ||||
void nsdelete(struct nvme_function *nf, int argc, char *argv[]); | static void nsdelete(const struct nvme_function *nf, int argc, char *argv[]); | ||||
void nsattach(struct nvme_function *nf, int argc, char *argv[]); | static void nsattach(const struct nvme_function *nf, int argc, char *argv[]); | ||||
void nsdetach(struct nvme_function *nf, int argc, char *argv[]); | static void nsdetach(const struct nvme_function *nf, int argc, char *argv[]); | ||||
NVME_COMMAND(ns, create, nscreate, NSCREATE_USAGE); | NVME_COMMAND(ns, create, nscreate, NSCREATE_USAGE); | ||||
NVME_COMMAND(ns, delete, nsdelete, NSDELETE_USAGE); | NVME_COMMAND(ns, delete, nsdelete, NSDELETE_USAGE); | ||||
NVME_COMMAND(ns, attach, nsattach, NSATTACH_USAGE); | NVME_COMMAND(ns, attach, nsattach, NSATTACH_USAGE); | ||||
NVME_COMMAND(ns, detach, nsdetach, NSDETACH_USAGE); | NVME_COMMAND(ns, detach, nsdetach, NSDETACH_USAGE); | ||||
struct ns_result_str { | struct ns_result_str { | ||||
uint16_t res; | uint16_t res; | ||||
Show All 29 Lines | |||||
/* | /* | ||||
* NS MGMT Command specific status values: | * NS MGMT Command specific status values: | ||||
* 0xa = Invalid Format | * 0xa = Invalid Format | ||||
* 0x15 = Namespace Insuffience capacity | * 0x15 = Namespace Insuffience capacity | ||||
* 0x16 = Namespace ID unavailable (number namespaces exceeded) | * 0x16 = Namespace ID unavailable (number namespaces exceeded) | ||||
* 0xb = Thin Provisioning Not supported | * 0xb = Thin Provisioning Not supported | ||||
*/ | */ | ||||
void | static void | ||||
nscreate(struct nvme_function *nf, int argc, char *argv[]) | nscreate(const struct nvme_function *nf, int argc, char *argv[]) | ||||
{ | { | ||||
struct nvme_pt_command pt; | struct nvme_pt_command pt; | ||||
struct nvme_controller_data cd; | struct nvme_controller_data cd; | ||||
struct nvme_namespace_data nsdata; | struct nvme_namespace_data nsdata; | ||||
int64_t nsze = -1, cap = -1; | int64_t nsze = -1, cap = -1; | ||||
int ch, fd, result, lbaf = 0, mset = 0, nmic = -1, pi = 0, pil = 0; | int ch, fd, result, lbaf = 0, mset = 0, nmic = -1, pi = 0, pil = 0; | ||||
if (optind >= argc) | if (optind >= argc) | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | if (nvme_completion_is_error(&pt.cpl)) { | ||||
errx(1, "namespace creation failed: %s", | errx(1, "namespace creation failed: %s", | ||||
get_res_str((pt.cpl.status >> NVME_STATUS_SC_SHIFT) & | get_res_str((pt.cpl.status >> NVME_STATUS_SC_SHIFT) & | ||||
NVME_STATUS_SC_MASK)); | NVME_STATUS_SC_MASK)); | ||||
} | } | ||||
printf("namespace %d created\n", pt.cpl.cdw0); | printf("namespace %d created\n", pt.cpl.cdw0); | ||||
exit(0); | exit(0); | ||||
} | } | ||||
void | static void | ||||
nsdelete(struct nvme_function *nf, int argc, char *argv[]) | nsdelete(const struct nvme_function *nf, int argc, char *argv[]) | ||||
{ | { | ||||
struct nvme_pt_command pt; | struct nvme_pt_command pt; | ||||
struct nvme_controller_data cd; | struct nvme_controller_data cd; | ||||
int ch, fd, result, nsid = -2; | int ch, fd, result, nsid = -2; | ||||
char buf[2]; | char buf[2]; | ||||
if (optind >= argc) | if (optind >= argc) | ||||
usage(nf); | usage(nf); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* Completion 18h = Already attached | * Completion 18h = Already attached | ||||
* 19h = NS is private and already attached to a controller | * 19h = NS is private and already attached to a controller | ||||
* 1Ah = Not attached, request could not be completed | * 1Ah = Not attached, request could not be completed | ||||
* 1Ch = Controller list invalid. | * 1Ch = Controller list invalid. | ||||
* | * | ||||
* 0x2 Invalid Field can occur if ctrlrid d.n.e in system. | * 0x2 Invalid Field can occur if ctrlrid d.n.e in system. | ||||
*/ | */ | ||||
void | static void | ||||
nsattach(struct nvme_function *nf, int argc, char *argv[]) | nsattach(const struct nvme_function *nf, int argc, char *argv[]) | ||||
{ | { | ||||
struct nvme_pt_command pt; | struct nvme_pt_command pt; | ||||
struct nvme_controller_data cd; | struct nvme_controller_data cd; | ||||
int ctrlrid = -2; | int ctrlrid = -2; | ||||
int fd, ch, result, nsid = -1; | int fd, ch, result, nsid = -1; | ||||
uint16_t clist[2048]; | uint16_t clist[2048]; | ||||
if (optind >= argc) | if (optind >= argc) | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | if (nvme_completion_is_error(&pt.cpl)) { | ||||
errx(1, "namespace attach failed: %s", | errx(1, "namespace attach failed: %s", | ||||
get_res_str((pt.cpl.status >> NVME_STATUS_SC_SHIFT) & | get_res_str((pt.cpl.status >> NVME_STATUS_SC_SHIFT) & | ||||
NVME_STATUS_SC_MASK)); | NVME_STATUS_SC_MASK)); | ||||
} | } | ||||
printf("namespace %d attached\n", nsid); | printf("namespace %d attached\n", nsid); | ||||
exit(0); | exit(0); | ||||
} | } | ||||
void | static void | ||||
nsdetach(struct nvme_function *nf, int argc, char *argv[]) | nsdetach(const struct nvme_function *nf, int argc, char *argv[]) | ||||
{ | { | ||||
struct nvme_pt_command pt; | struct nvme_pt_command pt; | ||||
struct nvme_controller_data cd; | struct nvme_controller_data cd; | ||||
int ctrlrid = -2; | int ctrlrid = -2; | ||||
int fd, ch, result, nsid = -1; | int fd, ch, result, nsid = -1; | ||||
uint16_t clist[2048]; | uint16_t clist[2048]; | ||||
if (optind >= argc) | if (optind >= argc) | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | errx(1, "namespace detach failed: %s", | ||||
get_res_str((pt.cpl.status >> NVME_STATUS_SC_SHIFT) & | get_res_str((pt.cpl.status >> NVME_STATUS_SC_SHIFT) & | ||||
NVME_STATUS_SC_MASK)); | NVME_STATUS_SC_MASK)); | ||||
} | } | ||||
printf("namespace %d detached\n", nsid); | printf("namespace %d detached\n", nsid); | ||||
exit(0); | exit(0); | ||||
} | } | ||||
static void | static void | ||||
ns(struct nvme_function *nf __unused, int argc, char *argv[]) | ns(const struct nvme_function *nf __unused, int argc, char *argv[]) | ||||
{ | { | ||||
DISPATCH(argc, argv, ns); | DISPATCH(argc, argv, ns); | ||||
} | } | ||||
NVME_COMMAND(top, ns, ns, NS_USAGE); | NVME_COMMAND(top, ns, ns, NS_USAGE); |