[PATCH 01/35] nvme-monitor: add new stub

mwilck
2021-01-26T20:34:55Z

From: Martin Wilck <mwilck@suse.com>

This stub will become the nvme AEN monitor in follow-up commits.
monitor functionality depends on libudev.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
Makefile | 10 ++++++++++
monitor.c | 28 ++++++++++++++++++++++++++++
monitor.h | 6 ++++++
nvme-builtin.h | 1 +
nvme.c | 13 +++++++++++++
5 files changed, 58 insertions(+)
create mode 100644 monitor.c
create mode 100644 monitor.h

diff --git a/Makefile b/Makefile
index 3ea17b5..21c9a23 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ override CPPFLAGS += -D_GNU_SOURCE -D__CHECK_ENDIAN__
LIBUUID = $(shell $(LD) -o /dev/null -luuid >/dev/null 2>&1; echo $$?)
LIBHUGETLBFS = $(shell $(LD) -o /dev/null -lhugetlbfs >/dev/null 2>&1; echo $$?)
HAVE_SYSTEMD = $(shell pkg-config --exists libsystemd --atleast-version=242; echo $$?)
+HAVE_LIBUDEV = $(shell pkg-config --exists libudev; echo $$?)
NVME = nvme
INSTALL ?= install
DESTDIR =
@@ -32,6 +33,11 @@ endif

INC=-Iutil

+ifeq ($(HAVE_LIBUDEV),0)
+ override LDFLAGS += -ludev
+ override CFLAGS += -DHAVE_LIBUDEV
+endif
+
ifeq ($(HAVE_SYSTEMD),0)
override LDFLAGS += -lsystemd
override CFLAGS += -DHAVE_SYSTEMD
@@ -62,6 +68,10 @@ OBJS := nvme-print.o nvme-ioctl.o nvme-rpmb.o \
nvme-lightnvm.o fabrics.o nvme-models.o plugin.o \
nvme-status.o nvme-filters.o nvme-topology.o

+ifeq ($(HAVE_LIBUDEV),0)
+ OBJS += monitor.o
+endif
+
UTIL_OBJS := util/argconfig.o util/suffix.o util/json.o util/parser.o

PLUGIN_OBJS := \
diff --git a/monitor.c b/monitor.c
new file mode 100644
index 0000000..dae4975
--- /dev/null
+++ b/monitor.c
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2021 SUSE LLC
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This file implements a simple monitor for NVMe-related uevents.
+ */
+
+#include <errno.h>
+
+#include "nvme-status.h"
+#include "monitor.h"
+
+int aen_monitor(const char *desc, int argc, char **argv)
+{
+ /* Handle as unimplemented for now */
+ return nvme_status_to_errno(-ENOTTY, true);
+}
+
diff --git a/monitor.h b/monitor.h
new file mode 100644
index 0000000..e79d3a6
--- /dev/null
+++ b/monitor.h
@@ -0,0 +1,6 @@
+#ifndef _MONITOR_H
+#define _MONITOR_H
+
+extern int aen_monitor(const char *desc, int argc, char **argv);
+
+#endif
diff --git a/nvme-builtin.h b/nvme-builtin.h
index 59896dc..74f9a3e 100644
--- a/nvme-builtin.h
+++ b/nvme-builtin.h
@@ -80,6 +80,7 @@ COMMAND_LIST(
ENTRY("dir-send", "Submit a Directive Send command, return results", dir_send)
ENTRY("virt-mgmt", "Manage Flexible Resources between Primary and Secondary Controller ", virtual_mgmt)
ENTRY("rpmb", "Replay Protection Memory Block commands", rpmb_cmd)
+ ENTRY("monitor", "Monitor NVMeoF AEN events", monitor_cmd)
);

#endif
diff --git a/nvme.c b/nvme.c
index d1ef6e9..d2004a2 100644
--- a/nvme.c
+++ b/nvme.c
@@ -57,6 +57,7 @@

#include "argconfig.h"
#include "fabrics.h"
+#include "monitor.h"

#define CREATE_CMD
#include "nvme-builtin.h"
@@ -5320,6 +5321,18 @@ static int disconnect_all_cmd(int argc, char **argv, struct command *command, st
return fabrics_disconnect_all(desc, argc, argv);
}

+static int monitor_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
+{
+#ifdef HAVE_LIBUDEV
+ const char *desc = "Monitor NVMeoF AEN events";
+
+ return aen_monitor(desc, argc, argv);
+#else
+ fprintf(stderr, "nvme-cli built without libudev doesn't support the \"monitor\" subcommand\n");
+ return EOPNOTSUPP;
+#endif
+}
+
void register_extension(struct plugin *plugin)
{
plugin->parent = &nvme;
--
2.29.2