static bool is_chardev(struct nvme_dev *dev)
{
- return S_ISCHR(dev->stat.st_mode);
+ return S_ISCHR(dev->direct.stat.st_mode);
}
static bool is_blkdev(struct nvme_dev *dev)
{
- return S_ISBLK(dev->stat.st_mode);
+ return S_ISBLK(dev->direct.stat.st_mode);
}
static int open_dev(struct nvme_dev **devp, char *devstr, int flags)
dev = calloc(1, sizeof(*dev));
if (!dev)
return -1;
+
+ dev->type = NVME_DEV_DIRECT;
dev->name = basename(devstr);
err = open(devstr, flags);
if (err < 0) {
perror(devstr);
goto err_free;
}
- dev->fd = err;
+ dev->direct.fd = err;
- err = fstat(dev_fd(dev), &dev->stat);
+ err = fstat(dev_fd(dev), &dev->direct.stat);
if (err < 0) {
perror(devstr);
goto err_close;
#include <dirent.h>
#include <stdbool.h>
#include <stdint.h>
+#include <stdio.h>
#include <endian.h>
#include <sys/time.h>
#include <sys/stat.h>
#define SYS_NVME "/sys/class/nvme"
+enum nvme_dev_type {
+ NVME_DEV_DIRECT,
+};
+
struct nvme_dev {
- int fd;
- struct stat stat;
+ enum nvme_dev_type type;
+ union {
+ struct {
+ int fd;
+ struct stat stat;
+ } direct;
+ };
+
const char *name;
};
-static inline int dev_fd(struct nvme_dev *dev)
+#define dev_fd(d) __dev_fd(d, __func__, __LINE__)
+
+static inline int __dev_fd(struct nvme_dev *dev, const char *func, int line)
{
- return dev->fd;
+ if (dev->type != NVME_DEV_DIRECT) {
+ fprintf(stderr,
+ "warning: %s:%d not a direct transport!\n",
+ func, line);
+ return -1;
+ }
+ return dev->direct.fd;
}
void register_extension(struct plugin *plugin);