cam nvme: Add nvme_command_string

Replace nvme_cmd_string and nvme_opcode_string with a single function.
nvme_cmd_string was already using an sbuf around a caller-supplied
string, so use the same pattern for the entire command string.

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D50651
This commit is contained in:
John Baldwin 2025-06-04 11:14:13 -04:00
parent 7aac4b22f9
commit 5304a20ff1
3 changed files with 6 additions and 23 deletions

View file

@ -269,22 +269,7 @@ nvme_print_ident_short(const struct nvme_controller_data *cdata,
}
const char *
nvme_op_string(const struct nvme_command *cmd, int admin)
{
const char *s;
if (admin)
s = admin_opcode[cmd->opc];
else
s = nvm_opcode[cmd->opc];
if (s == NULL)
return ("UNKNOWN");
else
return (s);
}
const char *
nvme_cmd_string(const struct nvme_command *cmd, char *cmd_string, size_t len)
nvme_command_string(struct ccb_nvmeio *nvmeio, char *cmd_string, size_t len)
{
struct sbuf sb;
int error;
@ -293,7 +278,7 @@ nvme_cmd_string(const struct nvme_command *cmd, char *cmd_string, size_t len)
return ("");
sbuf_new(&sb, cmd_string, len, SBUF_FIXEDLEN);
nvme_cmd_sbuf(cmd, &sb);
nvme_command_sbuf(nvmeio, &sb);
error = sbuf_finish(&sb);
if (error != 0 &&

View file

@ -42,11 +42,10 @@ struct sbuf;
void nvme_print_ident(const struct nvme_controller_data *, const struct nvme_namespace_data *, struct sbuf *);
void nvme_print_ident_short(const struct nvme_controller_data *,
const struct nvme_namespace_data *, struct sbuf *);
const char *nvme_op_string(const struct nvme_command *, int admin);
const char *nvme_cmd_string(const struct nvme_command *, char *, size_t);
void nvme_opcode_sbuf(bool admin, uint8_t opc, struct sbuf *sb);
void nvme_cmd_sbuf(const struct nvme_command *, struct sbuf *sb);
int nvme_command_sbuf(struct ccb_nvmeio *nvmeio, struct sbuf *sb);
const char *nvme_command_string(struct ccb_nvmeio *nvmeio, char *, size_t);
void nvme_cpl_sbuf(const struct nvme_completion *cpl, struct sbuf *sbuf);
int nvme_status_sbuf(struct ccb_nvmeio *nvmeio, struct sbuf *sb);
const void *nvme_get_identify_cntrl(struct cam_periph *);

View file

@ -833,14 +833,13 @@ nvme_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
static void
nvme_proto_debug_out(union ccb *ccb)
{
char cdb_str[(sizeof(struct nvme_command) * 3) + 1];
char command_str[128];
if (ccb->ccb_h.func_code != XPT_NVME_IO &&
ccb->ccb_h.func_code != XPT_NVME_ADMIN)
return;
CAM_DEBUG(ccb->ccb_h.path,
CAM_DEBUG_CDB,("%s. NCB: %s\n", nvme_op_string(&ccb->nvmeio.cmd,
ccb->ccb_h.func_code == XPT_NVME_ADMIN),
nvme_cmd_string(&ccb->nvmeio.cmd, cdb_str, sizeof(cdb_str))));
CAM_DEBUG_CDB,("%s\n", nvme_command_string(&ccb->nvmeio,
command_str, sizeof(command_str))));
}