[PATCH 35/35] monitor: add option --keep/-K

mwilck at suse.com mwilck at suse.com
Tue Jan 26 15:33:24 EST 2021


From: Martin Wilck <mwilck at suse.com>

With this option, "nvme monitor" will keep created discovery controllers
running even after it exits. If running in the initrd, this is will be
done automatically. That has the advantage that the new monitor instance
that will be started automatically after switching root can simply take
over the already created discovery controllers.

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 Documentation/nvme-monitor.1    | 28 +++++++++++++++++++++-------
 Documentation/nvme-monitor.html | 30 ++++++++++++++++++++++++------
 Documentation/nvme-monitor.txt  |  1 +
 monitor.c                       | 15 ++++++++++++++-
 4 files changed, 60 insertions(+), 14 deletions(-)

diff --git a/Documentation/nvme-monitor.1 b/Documentation/nvme-monitor.1
index 1578e4c..36b015d 100644
--- a/Documentation/nvme-monitor.1
+++ b/Documentation/nvme-monitor.1
@@ -2,12 +2,12 @@
 .\"     Title: nvme-monitor
 .\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
-.\"      Date: 01/20/2021
+.\"      Date: 01/25/2021
 .\"    Manual: NVMe Manual
 .\"    Source: NVMe
 .\"  Language: English
 .\"
-.TH "NVME\-MONITOR" "1" "01/20/2021" "NVMe" "NVMe Manual"
+.TH "NVME\-MONITOR" "1" "01/25/2021" "NVMe" "NVMe Manual"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -33,9 +33,10 @@ nvme-monitor \- Monitor Discovery events and Discover and Connect automatically
 .sp
 .nf
 \fInvme discover\fR
-                [\-\-autoconnect            | \-A
-                [\-\-startup                | \-U
-                [\-\-persistent             | \-p
+                [\-\-autoconnect            | \-A]
+                [\-\-startup                | \-U]
+                [\-\-persistent             | \-p]
+                [\-\-keep                   | \-K]
                 [\-\-hostnqn=<hostnqn>      | \-q <hostnqn>]
                 [\-\-hostid=<hostid>        | \-I <hostid>]
                 [\-\-keep\-alive\-tmo=<#>     | \-k <#>]
@@ -118,9 +119,22 @@ option to make the Discovery Controllers persist after retrieving the Discovery
 This option has the same meaning as for
 \fInvme discover\fR; Discovery Controllers will remain after the Discovery Log Page has been retrieved\&. This is necessary for receiving AENs from the transport connection that the Discovery controller is associated with\&. Without this option, AENs can only be received and acted upon if the administrator manually creates persistent Discovery controller connections\&. When
 \fInvme monitor\fR
-terminates, it will attempt to take down all Discovery Controllers it has created (i\&.e\&. ones that didn\(cqt already exist when
+terminates and the, it will attempt to take down all Discovery Controllers it has created (i\&.e\&. ones that didn\(cqt already exist when
 \fInvme monitor\fR
-was started\&.
+was started (but see
+\fI\-\-keep\fR)\&.
+.RE
+.PP
+\-K, \-\-keep
+.RS 4
+Do not tear down created persistent discovery controllers when exiting\&. This option makes only sense together with
+\fI\-\-persistent\fR\&. When
+\fInvme monitor\fR
+detects that it is running in the initial RAM FS (initrd),
+\fI\-\-keep\fR
+is implicitly assumed, i\&.e\&. discovery connections are not stopped\&. This is because after switching from the initrd to the real root file system, another
+\fInvme monitor\fR
+instance will probably be started that can reuse the created controller instances\&.
 .RE
 .PP
 \-q <hostnqn>, \-\-hostnqn=<hostnqn>, \-I <hostid>, \-\-hostid=<hostid>, \-k <#>, \-\-keep\-alive\-tmo=<#>, \-c <#>, \-\-reconnect\-delay=<#>, \-l <#>, \-\-ctrl\-loss\-tmo=<#>, \-g, \-\-hdr\-digest, \-G, \-\-data\-digest, \-i <#>, \-\-nr\-io\-queues=<#>, \-W <#>, \-\-nr\-write\-queues=<#>, \-P <#>, \-\-nr\-poll\-queues=<#>, \-Q <#>, \-\-queue\-size=<#>, \-m, \-\-matching
diff --git a/Documentation/nvme-monitor.html b/Documentation/nvme-monitor.html
index c2b9a64..bd57a22 100644
--- a/Documentation/nvme-monitor.html
+++ b/Documentation/nvme-monitor.html
@@ -750,9 +750,10 @@ nvme-monitor(1) Manual Page
 <div class="sectionbody">
 <div class="verseblock">
 <pre class="content"><em>nvme discover</em>
-                [--autoconnect            | -A
-                [--startup                | -U
-                [--persistent             | -p
+                [--autoconnect            | -A]
+                [--startup                | -U]
+                [--persistent             | -p]
+                [--keep                   | -K]
                 [--hostnqn=<hostnqn>      | -q <hostnqn>]
                 [--hostid=<hostid>        | -I <hostid>]
                 [--keep-alive-tmo=<#>     | -k <#>]
@@ -863,9 +864,26 @@ commands for further background.</p></div>
         this option, AENs can only be received and acted upon if the
         administrator manually creates persistent Discovery controller
         connections.
-        When <em>nvme monitor</em> terminates, it will attempt to take down all
+        When <em>nvme monitor</em> terminates and the, it will attempt to take down all
         Discovery Controllers it has created (i.e. ones that didn’t already
-        exist when <em>nvme monitor</em> was started.
+        exist when <em>nvme monitor</em> was started (but see <em>--keep</em>).
+</p>
+</dd>
+<dt class="hdlist1">
+-K
+</dt>
+<dt class="hdlist1">
+--keep
+</dt>
+<dd>
+<p>
+        Do not tear down created persistent discovery controllers when
+        exiting. This option makes only sense together with <em>--persistent</em>.
+        When <em>nvme monitor</em> detects that it is running in the initial RAM FS
+        (initrd), <em>--keep</em> is implicitly assumed, i.e. discovery connections
+        are not stopped. This is because after switching from the initrd to
+        the real root file system, another <em>nvme monitor</em> instance will
+        probably be started that can reuse the created controller instances.
 </p>
 </dd>
 <dt class="hdlist1">
@@ -1042,7 +1060,7 @@ nvme-connect-all(1)</p></div>
 <div id="footer">
 <div id="footer-text">
 Last updated
- 2021-01-20 23:53:52 CET
+ 2021-01-25 22:35:29 CET
 </div>
 </div>
 </body>
diff --git a/Documentation/nvme-monitor.txt b/Documentation/nvme-monitor.txt
index 9232fab..517d036 100644
--- a/Documentation/nvme-monitor.txt
+++ b/Documentation/nvme-monitor.txt
@@ -12,6 +12,7 @@ SYNOPSIS
 		[--autoconnect            | -A]
 		[--startup                | -U]
 		[--persistent             | -p]
+		[--keep                   | -K]
 		[--hostnqn=<hostnqn>      | -q <hostnqn>]
 		[--hostid=<hostid>        | -I <hostid>]
 		[--keep-alive-tmo=<#>     | -k <#>]
diff --git a/monitor.c b/monitor.c
index ecf6706..40d1f29 100644
--- a/monitor.c
+++ b/monitor.c
@@ -44,6 +44,7 @@ static struct monitor_config {
 	bool autoconnect;
 	bool skip_udev_on_exit;
 	bool start_ctrls;
+	bool keep_ctrls;
 } mon_cfg;
 
 static struct udev *udev;
@@ -669,6 +670,7 @@ static int monitor_parse_opts(const char *desc, int argc, char **argv)
 		OPT_FLAG("autoconnect",    'A', &mon_cfg.autoconnect, "automatically connect newly discovered controllers"),
 		OPT_FLAG("startup",        'U', &mon_cfg.start_ctrls, "start discovery controllers on startup"),
 		OPT_FLAG("persistent",     'p', &cfg.persistent,      "persistent discovery connections"),
+		OPT_FLAG("keep",           'K', &mon_cfg.keep_ctrls,  "keep discovery controllers after exit"),
 		OPT_LIST("hostnqn",        'q', &cfg.hostnqn,         "user-defined hostnqn (if default not used)"),
 		OPT_LIST("hostid",         'I', &cfg.hostid,          "user-defined hostid (if default not used)"),
 		OPT_INT("keep-alive-tmo",  'k', &cfg.keep_alive_tmo,  "keep alive timeout period in seconds"),
@@ -716,6 +718,11 @@ static int monitor_parse_opts(const char *desc, int argc, char **argv)
 	return ret;
 }
 
+static bool running_in_initrd(void)
+{
+	return access("/etc/initrd-release", F_OK) >= 0;
+}
+
 int aen_monitor(const char *desc, int argc, char **argv)
 {
 	int ret;
@@ -724,11 +731,16 @@ int aen_monitor(const char *desc, int argc, char **argv)
 	ret = monitor_parse_opts(desc, argc, argv);
 	if (ret)
 		goto out;
+
 	ret = monitor_init_signals();
 	if (ret != 0) {
 		log(LOG_ERR, "monitor: failed to initialize signals: %m\n");
 		goto out;
 	}
+
+	if (running_in_initrd())
+		mon_cfg.keep_ctrls = true;
+
 	ret = create_udev_monitor(&monitor);
 	if (ret == 0) {
 		conndb_init_from_sysfs();
@@ -739,7 +751,8 @@ int aen_monitor(const char *desc, int argc, char **argv)
 	}
 
 	conndb_for_each(monitor_kill_discovery_task, NULL);
-	if (mon_cfg.autoconnect || mon_cfg.start_ctrls)
+	if ((mon_cfg.autoconnect || mon_cfg.start_ctrls) &&
+	    !mon_cfg.keep_ctrls)
 		conndb_for_each(monitor_remove_discovery_ctrl, NULL);
 	conndb_free();
 
-- 
2.29.2




More information about the Linux-nvme mailing list