summaryrefslogtreecommitdiffstats
path: root/nvme.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-05 18:23:26 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-05 18:23:26 +0000
commitfab3f41b7b3f080c215157a026ee6bc7efbfe968 (patch)
treef0fafb0805c3eb11eb2a278f9f8058376c8f0f2b /nvme.h
parentAdding upstream version 2.1.2. (diff)
downloadnvme-cli-fab3f41b7b3f080c215157a026ee6bc7efbfe968.tar.xz
nvme-cli-fab3f41b7b3f080c215157a026ee6bc7efbfe968.zip
Adding upstream version 2.2.1.upstream/2.2.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'nvme.h')
-rw-r--r--nvme.h63
1 files changed, 61 insertions, 2 deletions
diff --git a/nvme.h b/nvme.h
index 5afeece..c13ca8e 100644
--- a/nvme.h
+++ b/nvme.h
@@ -19,8 +19,12 @@
#include <dirent.h>
#include <stdbool.h>
#include <stdint.h>
+#include <stdio.h>
#include <endian.h>
#include <sys/time.h>
+#include <sys/stat.h>
+
+#include <libnvme-mi.h>
#include "plugin.h"
#include "util/json.h"
@@ -34,13 +38,68 @@ enum nvme_print_flags {
BINARY = 1 << 3, /* binary dump raw bytes */
};
+enum nvme_cli_topo_ranking {
+ NVME_CLI_TOPO_NAMESPACE,
+ NVME_CLI_TOPO_CTRL,
+};
+
#define SYS_NVME "/sys/class/nvme"
+enum nvme_dev_type {
+ NVME_DEV_DIRECT,
+ NVME_DEV_MI,
+};
+
+struct nvme_dev {
+ enum nvme_dev_type type;
+ union {
+ struct {
+ int fd;
+ struct stat stat;
+ } direct;
+ struct {
+ nvme_root_t root;
+ nvme_mi_ep_t ep;
+ nvme_mi_ctrl_t ctrl;
+ } mi;
+ };
+
+ const char *name;
+};
+
+#define dev_fd(d) __dev_fd(d, __func__, __LINE__)
+
+static inline int __dev_fd(struct nvme_dev *dev, const char *func, int line)
+{
+ if (dev->type != NVME_DEV_DIRECT) {
+ fprintf(stderr,
+ "warning: %s:%d not a direct transport!\n",
+ func, line);
+ return -1;
+ }
+ return dev->direct.fd;
+}
+
+static inline nvme_mi_ep_t dev_mi_ep(struct nvme_dev *dev)
+{
+ if (dev->type != NVME_DEV_MI) {
+ fprintf(stderr,
+ "warning: not a MI transport!\n");
+ return NULL;
+ }
+ return dev->mi.ep;
+}
+
void register_extension(struct plugin *plugin);
-int parse_and_open(int argc, char **argv, const char *desc,
+
+/*
+ * parse_and_open - parses arguments and opens the NVMe device, populating @dev
+ */
+int parse_and_open(struct nvme_dev **dev, int argc, char **argv, const char *desc,
const struct argconfig_commandline_options *clo);
-extern const char *devicename;
+void dev_close(struct nvme_dev *dev);
+
extern const char *output_format;
enum nvme_print_flags validate_output_format(const char *format);