From 95d548026f203c05c834bb3d829c01350efd7c53 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 10 Nov 2023 16:58:50 +0100 Subject: [PATCH 1/2] storagetm: show connection data also via plymouth Pretty! --- TODO | 1 - src/storagetm/storagetm.c | 61 +++++++++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 04c232e37e..4e216a2cf4 100644 --- a/TODO +++ b/TODO @@ -182,7 +182,6 @@ Features: as mass storage devices on systems that have a USB controller that can operate in device mode - add NVMe authentication - - show login details also via plymouth * add support for activating nvme-oF devices at boot automatically via kernel cmdline, and maybe even support a syntax such as diff --git a/src/storagetm/storagetm.c b/src/storagetm/storagetm.c index dfde848434..8d36184b76 100644 --- a/src/storagetm/storagetm.c +++ b/src/storagetm/storagetm.c @@ -18,6 +18,7 @@ #include "main-func.h" #include "parse-argument.h" #include "path-util.h" +#include "plymouth-util.h" #include "pretty-print.h" #include "process-util.h" #include "random-util.h" @@ -568,7 +569,41 @@ static int nvme_subsystem_report(NvmeSubsystem *subsystem, NvmePort *ipv4, NvmeP return 0; } -static int nvme_port_report(NvmePort *port) { +static int plymouth_send_text(const char *text) { + _cleanup_free_ char *plymouth_message = NULL; + int c, r; + + assert(text); + + c = asprintf(&plymouth_message, + "M\x02%c%s%c" + "A%c", /* pause spinner */ + (int) strlen(text) + 1, text, '\x00', + '\x00'); + if (c < 0) + return log_oom(); + + r = plymouth_send_raw(plymouth_message, c, SOCK_NONBLOCK); + if (r < 0) + return log_full_errno(ERRNO_IS_NO_PLYMOUTH(r) ? LOG_DEBUG : LOG_WARNING, r, + "Failed to communicate with plymouth, ignoring: %m"); + + return 0; +} + +static int plymouth_notify_port(NvmePort *port, struct local_address *a) { + _cleanup_free_ char *m = NULL; + + if (!port || !a) + return 0; + + if (asprintf(&m, "nvme connect-all -t tcp -a %s -s %" PRIu16, IN_ADDR_TO_STRING(a->family, &a->address), port->portnr) < 0) + return log_oom(); + + return plymouth_send_text(m); +} + +static int nvme_port_report(NvmePort *port, bool *plymouth_done) { if (!port) return 0; @@ -590,6 +625,11 @@ static int nvme_port_report(NvmePort *port) { IN_ADDR_TO_STRING(a->family, &a->address), port->portnr); + if (plymouth_done && !*plymouth_done) { + (void) plymouth_notify_port(port, n_addresses > 0 ? addresses : NULL); + *plymouth_done = n_addresses > 0; + } + return 0; } @@ -861,8 +901,15 @@ static int on_display_refresh(sd_event_source *s, uint64_t usec, void *userdata) if (isatty(STDERR_FILENO) > 0) fputs(ANSI_HOME_CLEAR, stderr); - (void) nvme_port_report(c->ipv4_port); - (void) nvme_port_report(c->ipv6_port); + /* If we have both IPv4 and IPv6, we display IPv4 info via Plymouth, since it doesn't have much + * space, and IPv4 is simply shorter (and easy to type off screen) */ + + bool plymouth_done = false; + (void) nvme_port_report(c->ipv4_port, &plymouth_done); + (void) nvme_port_report(c->ipv6_port, &plymouth_done); + + if (!plymouth_done) + (void) plymouth_send_text("Network disconnected."); NvmeSubsystem *i; HASHMAP_FOREACH(i, c->subsystems) @@ -946,16 +993,20 @@ static int run(int argc, char* argv[]) { if (r < 0) return r; - nvme_port_report(context.ipv4_port); + bool plymouth_done = false; + nvme_port_report(context.ipv4_port, &plymouth_done); if (socket_ipv6_is_enabled()) { r = nvme_port_add(arg_nqn, AF_INET6, &context.ipv6_port); if (r < 0) return r; - nvme_port_report(context.ipv6_port); + nvme_port_report(context.ipv6_port, &plymouth_done); } + if (!plymouth_done) + (void) plymouth_send_text("Network disconnected."); + NvmeSubsystem *i; HASHMAP_FOREACH(i, context.subsystems) { if (context.ipv4_port) { From 4134f47de22fb0a5745ba5a807e6513067fb05c5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 10 Nov 2023 17:00:38 +0100 Subject: [PATCH 2/2] units: pull in plymouth when booting into storagetm mode --- units/storage-target-mode.target | 4 ++-- units/systemd-storagetm.service.in | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/units/storage-target-mode.target b/units/storage-target-mode.target index 38f78a286e..e5c6778962 100644 --- a/units/storage-target-mode.target +++ b/units/storage-target-mode.target @@ -10,7 +10,7 @@ [Unit] Description=Storage Target Mode Documentation=man:systemd.special(7) -Wants=systemd-storagetm.service systemd-udevd.service systemd-udev-trigger.service systemd-networkd.service systemd-network-generator.service systemd-journald.socket systemd-journald-dev-log.socket +Wants=systemd-storagetm.service systemd-udevd.service systemd-udev-trigger.service systemd-networkd.service systemd-network-generator.service systemd-journald.socket systemd-journald-dev-log.socket plymouth-start.service Conflicts=rescue.service rescue.target -After=systemd-storagetm.service systemd-udevd.service systemd-udev-trigger.service systemd-networkd.service systemd-network-generator.service systemd-journald.socket systemd-journald-dev-log.socket rescue.service rescue.target +After=systemd-storagetm.service systemd-udevd.service systemd-udev-trigger.service systemd-networkd.service systemd-network-generator.service systemd-journald.socket systemd-journald-dev-log.socket plymouth-start.service rescue.service rescue.target AllowIsolate=yes diff --git a/units/systemd-storagetm.service.in b/units/systemd-storagetm.service.in index 0fe91eff27..3c26f22e7f 100644 --- a/units/systemd-storagetm.service.in +++ b/units/systemd-storagetm.service.in @@ -13,7 +13,7 @@ Documentation=man:systemd-storagetm.service(8) ConditionVirtualization=!container DefaultDependencies=no Wants=modprobe@nvmet_tcp.service modprobe@thunderbolt_net.service sys-kernel-config.mount -After=modprobe@nvmet_tcp.service modprobe@thunderbolt_net.service sys-kernel-config.mount +After=modprobe@nvmet_tcp.service modprobe@thunderbolt_net.service sys-kernel-config.mount plymouth-start.service Conflicts=shutdown.target Before=shutdown.target FailureAction=reboot