Skip to content

Commit 1b26176

Browse files
committed
logging: output ioctl debugging info
Instead pushing insane logging infra code into the library, let's keep this stuff in the frontend. This is done by providing our own version of the low level ioctl function as the library is exposing this as weak symbol. This allows us to print the passthru structures and also the timing information. Signed-off-by: Daniel Wagner <dwagner@suse.de>
1 parent f0ff03c commit 1b26176

File tree

4 files changed

+101
-14
lines changed

4 files changed

+101
-14
lines changed

nvme-wrap.c

-6
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,3 @@ int nvme_cli_security_receive(struct nvme_dev *dev,
428428

429429
return -ENODEV;
430430
}
431-
432-
void nvme_cli_set_debug(struct nvme_dev *dev, bool set)
433-
{
434-
if (dev->type == NVME_DEV_DIRECT)
435-
nvme_set_debug(set);
436-
}

nvme-wrap.h

-1
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,4 @@ int nvme_cli_security_send(struct nvme_dev *dev,
147147
int nvme_cli_security_receive(struct nvme_dev *dev,
148148
struct nvme_security_receive_args* args);
149149

150-
void nvme_cli_set_debug(struct nvme_dev *dev, bool set);
151150
#endif /* _NVME_WRAP_H */

nvme.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ int parse_and_open(struct nvme_dev **dev, int argc, char **argv,
373373
ret = get_dev(dev, argc, argv, O_RDONLY);
374374
if (ret < 0)
375375
argconfig_print_help(desc, opts);
376-
else if (argconfig_parse_seen(opts, "verbose"))
377-
nvme_cli_set_debug(*dev, true);
376+
else
377+
log_level = map_log_level(verbose_level, false);
378378

379379
return ret;
380380
}
@@ -3224,7 +3224,6 @@ static int list_subsys(int argc, char **argv, struct command *cmd,
32243224
if (argconfig_parse_seen(opts, "verbose"))
32253225
flags |= VERBOSE;
32263226

3227-
log_level = map_log_level(verbose_level, false);
32283227

32293228
r = nvme_create_root(stderr, log_level);
32303229
if (!r) {
@@ -3283,8 +3282,6 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugi
32833282
if (argconfig_parse_seen(opts, "verbose"))
32843283
flags |= VERBOSE;
32853284

3286-
log_level = map_log_level(verbose_level, false);
3287-
32883285
r = nvme_create_root(stderr, log_level);
32893286
if (!r) {
32903287
nvme_show_error("Failed to create topology root: %s", nvme_strerror(errno));
@@ -8866,8 +8863,6 @@ static int show_topology_cmd(int argc, char **argv, struct command *command, str
88668863
return -EINVAL;
88678864
}
88688865

8869-
log_level = map_log_level(verbose_level, false);
8870-
88718866
r = nvme_create_root(stderr, log_level);
88728867
if (!r) {
88738868
nvme_show_error("Failed to create topology root: %s", nvme_strerror(errno));

util/logging.c

+99
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22

3+
#include <inttypes.h>
4+
5+
#include <stdint.h>
6+
#include <sys/ioctl.h>
7+
#include <sys/syslog.h>
8+
#include <sys/time.h>
9+
#include <linux/types.h>
10+
11+
#include <libnvme.h>
12+
313
#include "logging.h"
414

515
int log_level;
@@ -33,3 +43,92 @@ int map_log_level(int verbose, bool quiet)
3343

3444
return log_level;
3545
}
46+
47+
static void nvme_show_common(struct nvme_passthru_cmd *cmd)
48+
{
49+
printf("opcode : %02x\n", cmd->opcode);
50+
printf("flags : %02x\n", cmd->flags);
51+
printf("rsvd1 : %04x\n", cmd->rsvd1);
52+
printf("nsid : %08x\n", cmd->nsid);
53+
printf("cdw2 : %08x\n", cmd->cdw2);
54+
printf("cdw3 : %08x\n", cmd->cdw3);
55+
printf("data_len : %08x\n", cmd->data_len);
56+
printf("metadata_len : %08x\n", cmd->metadata_len);
57+
printf("addr : %"PRIx64"\n", (uint64_t)(uintptr_t)cmd->addr);
58+
printf("metadata : %"PRIx64"\n", (uint64_t)(uintptr_t)cmd->metadata);
59+
printf("cdw10 : %08x\n", cmd->cdw10);
60+
printf("cdw11 : %08x\n", cmd->cdw11);
61+
printf("cdw12 : %08x\n", cmd->cdw12);
62+
printf("cdw13 : %08x\n", cmd->cdw13);
63+
printf("cdw14 : %08x\n", cmd->cdw14);
64+
printf("cdw15 : %08x\n", cmd->cdw15);
65+
printf("timeout_ms : %08x\n", cmd->timeout_ms);
66+
}
67+
68+
static void nvme_show_command(struct nvme_passthru_cmd *cmd, int err, struct timeval start,
69+
struct timeval end)
70+
{
71+
nvme_show_common(cmd);
72+
printf("result : %08x\n", cmd->result);
73+
printf("err : %d\n", err);
74+
printf("latency : %lu us\n",
75+
(end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec));
76+
}
77+
78+
static void nvme_show_command64(struct nvme_passthru_cmd64 *cmd, int err, struct timeval start,
79+
struct timeval end)
80+
{
81+
nvme_show_common((struct nvme_passthru_cmd *)cmd);
82+
printf("result : %"PRIx64"\n", (uint64_t)(uintptr_t)cmd->result);
83+
printf("err : %d\n", err);
84+
printf("latency : %lu us\n",
85+
(end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec));
86+
}
87+
88+
int nvme_submit_passthru(int fd, unsigned long ioctl_cmd,
89+
struct nvme_passthru_cmd *cmd, __u32 *result)
90+
{
91+
struct timeval start;
92+
struct timeval end;
93+
int err;
94+
95+
if (log_level >= LOG_DEBUG)
96+
gettimeofday(&start, NULL);
97+
98+
err = ioctl(fd, ioctl_cmd, cmd);
99+
100+
if (log_level >= LOG_DEBUG) {
101+
gettimeofday(&end, NULL);
102+
nvme_show_command(cmd, err, start, end);
103+
}
104+
105+
if (err >= 0 && result)
106+
*result = cmd->result;
107+
108+
return err;
109+
}
110+
111+
int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,
112+
struct nvme_passthru_cmd64 *cmd,
113+
__u64 *result)
114+
{
115+
struct timeval start;
116+
struct timeval end;
117+
int err;
118+
119+
if (log_level >= LOG_DEBUG)
120+
gettimeofday(&start, NULL);
121+
122+
123+
err = ioctl(fd, ioctl_cmd, cmd);
124+
125+
if (log_level >= LOG_DEBUG) {
126+
gettimeofday(&end, NULL);
127+
nvme_show_command64(cmd, err, start, end);
128+
}
129+
130+
if (err >= 0 && result)
131+
*result = cmd->result;
132+
133+
return err;
134+
}

0 commit comments

Comments
 (0)