Skip to content

Commit dc9e369

Browse files
committed
nvme: add sanitize ns specific status code string
Since the status code is duplicated with the fw-commit status code. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent f691b99 commit dc9e369

7 files changed

Lines changed: 99 additions & 1 deletion

File tree

libnvme/src/nvme/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7952,6 +7952,7 @@ struct nvme_mi_vpd_hdr {
79527952
* Maximum Time for Firmware Activation
79537953
* (MTFA) value reported in Identify
79547954
* Controller.
7955+
* @NVME_SC_EXCEEDS_MAX_NS_SANITIZE: Exceeds Max NS Sanitize Operations
79557956
* @NVME_SC_FW_ACTIVATE_PROHIBITED: Firmware Activation Prohibited: The image
79567957
* specified is being prohibited from
79577958
* activation by the controller for vendor
@@ -8277,6 +8278,7 @@ enum nvme_status_field {
82778278
NVME_SC_FW_NEEDS_SUBSYS_RESET = 0x10,
82788279
NVME_SC_FW_NEEDS_RESET = 0x11,
82798280
NVME_SC_FW_NEEDS_MAX_TIME = 0x12,
8281+
NVME_SC_EXCEEDS_MAX_NS_SANITIZE = 0x12,
82808282
NVME_SC_FW_ACTIVATE_PROHIBITED = 0x13,
82818283
NVME_SC_OVERLAPPING_RANGE = 0x14,
82828284
NVME_SC_NS_INSUFFICIENT_CAP = 0x15,

libnvme/src/nvme/util.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,52 @@ __u8 nvme_status_to_errno(int status, bool fabrics);
8787
*/
8888
const char *nvme_status_to_string(int status, bool fabrics);
8989

90+
/**
91+
* nvme_sanitize_ns_status_to_string() - Returns sanitize ns status string.
92+
* @sc: Return status code from an sanitize ns command
93+
*
94+
* Return: The sanitize ns status string if it is a specific status code.
95+
*/
96+
static inline const char *
97+
nvme_sanitize_ns_status_to_string(__u16 sc)
98+
{
99+
switch (sc) {
100+
case NVME_SC_EXCEEDS_MAX_NS_SANITIZE:
101+
return "Req Exceeds Max NS Sanitize Operations In Progress";
102+
default:
103+
break;
104+
}
105+
106+
return NULL;
107+
};
108+
109+
/**
110+
* nvme_opcode_status_to_string() - Returns nvme opcode status string.
111+
* @status: Return status from an nvme passthrough command
112+
* @admin: Set to true if an admin command
113+
* @opcode: Opcode from an nvme passthrough command
114+
*
115+
* Return: The nvme opcode status string if it is an nvme status field,
116+
* or a standard errno string if status is < 0.
117+
*/
118+
static inline const char *
119+
nvme_opcode_status_to_string(int status, bool admin, __u8 opcode)
120+
{
121+
__u16 sct = nvme_status_code_type(status);
122+
__u16 sc = nvme_status_code(status);
123+
const char *s = NULL;
124+
125+
if (status >= 0 && sct == NVME_SCT_CMD_SPECIFIC) {
126+
if (admin && opcode == nvme_admin_sanitize_ns)
127+
s = nvme_sanitize_ns_status_to_string(sc);
128+
}
129+
130+
if (s)
131+
return s;
132+
133+
return nvme_status_to_string(status, false);
134+
}
135+
90136
/**
91137
* nvme_errno_to_string() - Returns string describing nvme connect failures
92138
* @err: Returned error code from nvme_add_ctrl()

nvme-print-binary.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ static struct print_ops binary_print_ops = {
435435
.show_message = NULL,
436436
.show_perror = NULL,
437437
.show_status = NULL,
438+
.show_opcode_status = NULL,
438439
.show_error_status = NULL,
439440
.show_key_value = NULL,
440441
};

nvme-print-json.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5095,6 +5095,26 @@ static void json_output_status(int status)
50955095
obj_print(r);
50965096
}
50975097

5098+
static void json_output_opcode_status(int status, bool admin, __u8 opcode)
5099+
{
5100+
struct json_object *r;
5101+
char json_str[STR_LEN];
5102+
int val = nvme_status_get_value(status);
5103+
int type = nvme_status_get_type(status);
5104+
5105+
if (status >= 0 && type == NVME_STATUS_TYPE_NVME) {
5106+
sprintf(json_str, "status: %d", status);
5107+
r = obj_create(json_str);
5108+
obj_add_str(r, "error",
5109+
nvme_opcode_status_to_string(val, admin, opcode));
5110+
obj_add_str(r, "type", "nvme");
5111+
obj_print(r);
5112+
return;
5113+
}
5114+
5115+
json_output_status(status);
5116+
}
5117+
50985118
static void json_output_error_status(int status, const char *msg, va_list ap)
50995119
{
51005120
struct json_object *r;
@@ -5577,6 +5597,7 @@ static struct print_ops json_print_ops = {
55775597
.show_message = json_output_message,
55785598
.show_perror = json_output_perror,
55795599
.show_status = json_output_status,
5600+
.show_opcode_status = json_output_opcode_status,
55805601
.show_error_status = json_output_error_status,
55815602
.show_key_value = json_output_key_value,
55825603
};

nvme-print-stdout.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,20 @@ static void stdout_status(int status)
17471747
}
17481748
}
17491749

1750+
static void stdout_opcode_status(int status, bool admin, __u8 opcode)
1751+
{
1752+
int val = nvme_status_get_value(status);
1753+
int type = nvme_status_get_type(status);
1754+
1755+
if (status >= 0 && type == NVME_STATUS_TYPE_NVME) {
1756+
fprintf(stderr, "NVMe status: %s(0x%x)\n",
1757+
nvme_opcode_status_to_string(val, admin, opcode), val);
1758+
return;
1759+
}
1760+
1761+
stdout_status(status);
1762+
}
1763+
17501764
static void stdout_error_status(int status, const char *msg, va_list ap)
17511765
{
17521766
vfprintf(stderr, msg, ap);
@@ -6679,6 +6693,7 @@ static struct print_ops stdout_print_ops = {
66796693
.show_message = stdout_message,
66806694
.show_perror = stdout_perror,
66816695
.show_status = stdout_status,
6696+
.show_opcode_status = stdout_opcode_status,
66826697
.show_error_status = stdout_error_status,
66836698
.show_key_value = stdout_key_value,
66846699
};

nvme-print.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,17 @@ void nvme_show_status(int status)
520520
ops->show_status(status);
521521
}
522522

523+
void nvme_show_opcode_status(int status, bool admin, __u8 opcode)
524+
{
525+
struct print_ops *ops = nvme_print_ops(NORMAL);
526+
527+
if (nvme_is_output_format_json())
528+
ops = nvme_print_ops(JSON);
529+
530+
if (ops && ops->show_opcode_status)
531+
ops->show_opcode_status(status, admin, opcode);
532+
}
533+
523534
void nvme_show_error_status(int status, const char *msg, ...)
524535
{
525536
struct print_ops *ops = nvme_print_ops(NORMAL);
@@ -530,7 +541,7 @@ void nvme_show_error_status(int status, const char *msg, ...)
530541
if (nvme_is_output_format_json())
531542
ops = nvme_print_ops(JSON);
532543

533-
if (ops && ops->show_status)
544+
if (ops && ops->show_error_status)
534545
ops->show_error_status(status, msg, ap);
535546

536547
va_end(ap);

nvme-print.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ struct print_ops {
116116
void (*show_message)(bool error, const char *msg, va_list ap);
117117
void (*show_perror)(const char *msg, va_list ap);
118118
void (*show_status)(int status);
119+
void (*show_opcode_status)(int status, bool admin, __u8 opcode);
119120
void (*show_error_status)(int status, const char *msg, va_list ap);
120121
void (*show_key_value)(const char *key, const char *val, va_list ap);
121122

@@ -158,6 +159,7 @@ struct print_ops *nvme_get_stdout_print_ops(nvme_print_flags_t flags);
158159
struct print_ops *nvme_get_binary_print_ops(nvme_print_flags_t flags);
159160

160161
void nvme_show_status(int status);
162+
void nvme_show_opcode_status(int status, bool admin, __u8 opcode);
161163
void nvme_show_lba_status_info(__u64 result);
162164
void nvme_show_relatives(struct nvme_global_ctx *ctx, const char *name, nvme_print_flags_t flags);
163165

0 commit comments

Comments
 (0)