File systemd-generator-add-lvm2-activation-net.service.patch of Package lvm2.1005

From ab53dbbfe5102d3961c91d39b48ffca4e85ff909 Mon Sep 17 00:00:00 2001
From: Liuhua Wang <lwang@suse.com>
Date: Thu, 24 Sep 2015 17:51:51 +0800
Subject: [PATCH] systemd: generator: add lvm2-activation-net.service

The new lvm2-activation-net.service activates LVM volumes
after network-attached devices are set up (iSCSI and FCoE)
if lvmetad is disabled and hence the autoactivation is not
used.

References: bnc#946651
comment: 8606bf316a683ebd14bb4cdf4eb1b3477a790b62
---
 .../lvm2_activation_generator_systemd_red_hat.c    | 62 ++++++++++++++--------
 1 file changed, 41 insertions(+), 21 deletions(-)

diff --git a/scripts/lvm2_activation_generator_systemd_red_hat.c b/scripts/lvm2_activation_generator_systemd_red_hat.c
index ba2081c..ea41d92 100644
--- a/scripts/lvm2_activation_generator_systemd_red_hat.c
+++ b/scripts/lvm2_activation_generator_systemd_red_hat.c
@@ -24,16 +24,27 @@
 #define KMSG_DEV_PATH        "/dev/kmsg"
 #define LVM_CONF_USE_LVMETAD "global/use_lvmetad"
 
-#define DEFAULT_UNIT_DIR     "/tmp"
-#define UNIT_NAME_EARLY      "lvm2-activation-early.service"
-#define UNIT_NAME            "lvm2-activation.service"
-#define UNIT_TARGET          "local-fs.target"
+#define DEFAULT_UNIT_DIR      "/tmp"
+#define UNIT_TARGET_LOCAL_FS  "local-fs.target"
+#define UNIT_TARGET_REMOTE_FS "remote-fs.target"
 
 static char unit_path[PATH_MAX];
 static char target_path[PATH_MAX];
 static char message[PATH_MAX];
 static int kmsg_fd = -1;
 
+enum {
+	UNIT_EARLY,
+	UNIT_MAIN,
+	UNIT_NET
+};
+
+static const char *unit_names[] = {
+	[UNIT_EARLY] = "lvm2-activation-early.service",
+	[UNIT_MAIN] = "lvm2-activation.service",
+	[UNIT_NET] = "lvm2-activation-net.service"
+};
+
 __attribute__ ((format(printf, 1, 2)))
 static void kmsg(const char *format, ...)
 {
@@ -91,16 +102,17 @@ out:
 	return r;
 }
 
-static int generate_unit(const char *dir, int early)
+static int generate_unit(const char *dir, int unit)
 {
 	FILE *f;
-	const char *unit = early ? UNIT_NAME_EARLY : UNIT_NAME;
+	const char *unit_name = unit_names[unit];
+	const char *target_name = unit == UNIT_NET ? UNIT_TARGET_REMOTE_FS : UNIT_TARGET_LOCAL_FS;
 
-	if (dm_snprintf(unit_path, PATH_MAX, "%s/%s", dir, unit) < 0)
+	if (dm_snprintf(unit_path, PATH_MAX, "%s/%s", dir, unit_name) < 0)
 		return 0;
 
 	if (!(f = fopen(unit_path, "wxe"))) {
-		kmsg("LVM: Failed to create unit file %s: %m.\n", unit);
+		kmsg("LVM: Failed to create unit file %s: %m.\n", unit_name);
 		return 0;
 	}
 
@@ -116,25 +128,31 @@ static int generate_unit(const char *dir, int early)
 	      "SourcePath=/etc/lvm/lvm.conf\n"
 	      "DefaultDependencies=no\n", f);
 
-	if (early) {
-		fputs("After=systemd-udev-settle.service\n", f);
-		fputs("Before=cryptsetup.target\n", f);
-	} else
-		fputs("After=lvm2-activation-early.service cryptsetup.target\n", f);
-
-	fputs("Before=local-fs.target shutdown.target\n"
-	      "Wants=systemd-udev-settle.service\n\n"
-	      "[Service]\n"
+   if (unit == UNIT_NET) {
+       fputs("After=iscsi.service fcoe.service\n"
+             "Before=remote-fs.target shutdown.target\n", f);
+   } else {
+       if (unit == UNIT_EARLY) {
+           fputs("After=systemd-udev-settle.service\n", f);
+           fputs("Before=cryptsetup.target\n", f);
+       } else
+           fputs("After=lvm2-activation-early.service cryptsetup.target\n", f);
+
+       fputs("Before=local-fs.target shutdown.target\n"
+             "Wants=systemd-udev-settle.service\n\n", f);
+   }
+
+   fputs("[Service]\n"
 	      "ExecStart=/sbin/lvm vgchange -aay --sysinit\n"
 	      "Type=oneshot\n", f);
 
 	if (fclose(f) < 0) {
-		kmsg("LVM: Failed to write unit file %s: %m.\n", unit);
+        kmsg("LVM: Failed to write unit file %s: %m.\n", unit_name);
 		return 0;
 	}
 
-	if (!register_unit_with_target(dir, unit, UNIT_TARGET)) {
-		kmsg("LVM: Failed to register unit %s with target %s.\n", unit, UNIT_TARGET);
+    if (!register_unit_with_target(dir, unit_name, target_name)) {
+        kmsg("LVM: Failed to register unit %s with target %s.\n", unit_name, target_name);
 		return 0;
 	}
 
@@ -162,7 +180,9 @@ int main(int argc, char *argv[])
  
        /* mark lvm2-activation.*.service as world-accessible */
         old_mask = umask(0022);
-	if (!generate_unit(dir, 1) || !generate_unit(dir, 0))
+    if (!generate_unit(dir, UNIT_EARLY) ||
+        !generate_unit(dir, UNIT_MAIN) ||
+        !generate_unit(dir, UNIT_NET))
 		r = EXIT_FAILURE;
 	umask(old_mask);
 
-- 
1.8.4.5

openSUSE Build Service is sponsored by