dd65c9
From 0d13caa0714c32af45165310e93f62c965f45b01 Mon Sep 17 00:00:00 2001
dd65c9
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
dd65c9
Date: Thu, 12 Oct 2017 22:34:54 +0200
dd65c9
Subject: [PATCH] units: replace remote-cryptsetup-pre.target with
dd65c9
 remote-fs-pre.target
dd65c9
dd65c9
remote-cryptsetup-pre.target was designed as an active unit (that pulls in
dd65c9
network-online.target), the opposite of remote-fs-pre.target (a passive unit,
dd65c9
with individual provider services ordering itself before it and pulling it in,
dd65c9
for example iscsi.service and nfs-client.target).
dd65c9
dd65c9
To make remote-cryptsetup-pre.target really work, those services should be
dd65c9
ordered before it too. But this would require updates to all those services,
dd65c9
not just changes from systemd side.
dd65c9
dd65c9
But the requirements for remote-fs-pre.target and remote-cryptset-pre.target
dd65c9
are fairly similar (e.g. iscsi devices can certainly be used for both), so
dd65c9
let's reuse remote-fs-pre.target also for remote cryptsetup units. This loses
dd65c9
a bit of flexibility, but does away with the requirement for various provider
dd65c9
services to know about remote-cryptsetup-pre.target.
dd65c9
dd65c9
Cherry-picked from: a0dd209763f9e67054ee322a2dfd52bccf345c2e
dd65c9
Resolves: #1477757
dd65c9
---
dd65c9
 Makefile.am                           |  3 +--
dd65c9
 man/crypttab.xml                      |  2 +-
dd65c9
 man/systemd.special.xml               | 20 ++++----------------
dd65c9
 src/cryptsetup/cryptsetup-generator.c |  2 +-
dd65c9
 units/remote-cryptsetup-pre.target    | 15 ---------------
dd65c9
 units/remote-cryptsetup.target        |  2 +-
dd65c9
 6 files changed, 8 insertions(+), 36 deletions(-)
dd65c9
 delete mode 100644 units/remote-cryptsetup-pre.target
dd65c9
dd65c9
diff --git a/Makefile.am b/Makefile.am
dd65c9
index 13c93f485..f06bc29c2 100644
dd65c9
--- a/Makefile.am
dd65c9
+++ b/Makefile.am
dd65c9
@@ -4864,8 +4864,7 @@ systemgenerator_PROGRAMS += \
dd65c9
 dist_systemunit_DATA += \
dd65c9
 	units/cryptsetup.target \
dd65c9
 	units/cryptsetup-pre.target \
dd65c9
-	units/remote-cryptsetup.target \
dd65c9
-	units/remote-cryptsetup-pre.target
dd65c9
+	units/remote-cryptsetup.target
dd65c9
 
dd65c9
 systemd_cryptsetup_SOURCES = \
dd65c9
 	src/cryptsetup/cryptsetup.c
dd65c9
diff --git a/man/crypttab.xml b/man/crypttab.xml
dd65c9
index 7085a1623..a9197ab40 100644
dd65c9
--- a/man/crypttab.xml
dd65c9
+++ b/man/crypttab.xml
dd65c9
@@ -196,7 +196,7 @@
dd65c9
         started after the network is available, similarly to
dd65c9
         <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>
dd65c9
         units marked with <option>_netdev</option>. The service unit to set up this device
dd65c9
-        will be ordered between <filename>remote-cryptsetup-pre.target</filename> and
dd65c9
+        will be ordered between <filename>remote-fs-pre.target</filename> and
dd65c9
         <filename>remote-cryptsetup.target</filename>, instead of
dd65c9
         <filename>cryptsetup-pre.target</filename> and
dd65c9
         <filename>cryptsetup.target</filename>.</para></listitem>
dd65c9
diff --git a/man/systemd.special.xml b/man/systemd.special.xml
dd65c9
index 5529d3bf7..e04f08bd3 100644
dd65c9
--- a/man/systemd.special.xml
dd65c9
+++ b/man/systemd.special.xml
dd65c9
@@ -81,7 +81,6 @@
dd65c9
     <filename>poweroff.target</filename>,
dd65c9
     <filename>printer.target</filename>,
dd65c9
     <filename>reboot.target</filename>,
dd65c9
-    <filename>remote-cryptsetup-pre.target</filename>,
dd65c9
     <filename>remote-cryptsetup.target</filename>,
dd65c9
     <filename>remote-fs.target</filename>,
dd65c9
     <filename>remote-fs-pre.target</filename>,
dd65c9
@@ -406,18 +405,6 @@
dd65c9
           this target unit, for compatibility with SysV.</para>
dd65c9
         </listitem>
dd65c9
       </varlistentry>
dd65c9
-      <varlistentry>
dd65c9
-        <term><filename>remote-cryptsetup-pre.target</filename></term>
dd65c9
-        <listitem>
dd65c9
-          <para>This target unit is automatically ordered before all cryptsetup devices
dd65c9
-          marked with the <option>_netdev</option>. It can be used to execute additional
dd65c9
-          units before such devices are set up.</para>
dd65c9
-
dd65c9
-          <para>It is ordered after <filename>network.target</filename> and
dd65c9
-          <filename>network-online.target</filename>, and also pulls the latter in as a
dd65c9
-          <varname>Wants=</varname> dependency.</para>
dd65c9
-        </listitem>
dd65c9
-      </varlistentry>
dd65c9
       <varlistentry>
dd65c9
         <term><filename>remote-cryptsetup.target</filename></term>
dd65c9
         <listitem>
dd65c9
@@ -768,9 +755,10 @@
dd65c9
         <term><filename>remote-fs-pre.target</filename></term>
dd65c9
         <listitem>
dd65c9
           <para>This target unit is automatically ordered before all
dd65c9
-          remote mount point units (see above). It can be used to run
dd65c9
-          certain units before the remote mounts are established. Note
dd65c9
-          that this unit is generally not part of the initial
dd65c9
+          mount point units (see above) and cryptsetup devices
dd65c9
+          marked with the <option>_netdev</option>. It can be used to run
dd65c9
+          certain units before remote encrypted devices and mounts are established.
dd65c9
+          Note that this unit is generally not part of the initial
dd65c9
           transaction, unless the unit that wants to be ordered before
dd65c9
           all remote mounts pulls it in via a
dd65c9
           <varname>Wants=</varname> type dependency. If the unit wants
dd65c9
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
dd65c9
index 49dc8f14b..82a280d86 100644
dd65c9
--- a/src/cryptsetup/cryptsetup-generator.c
dd65c9
+++ b/src/cryptsetup/cryptsetup-generator.c
dd65c9
@@ -114,7 +114,7 @@ static int create_disk(
dd65c9
                 "IgnoreOnIsolate=true\n"
dd65c9
                 "After=systemd-readahead-collect.service systemd-readahead-replay.service\n"
dd65c9
                 "After=%s\n",
dd65c9
-                netdev ? "remote-cryptsetup-pre.target" : "cryptsetup-pre.target");
dd65c9
+                netdev ? "remote-fs-pre.target" : "cryptsetup-pre.target");
dd65c9
 
dd65c9
         if (!nofail)
dd65c9
                 fprintf(f,
dd65c9
diff --git a/units/remote-cryptsetup-pre.target b/units/remote-cryptsetup-pre.target
dd65c9
deleted file mode 100644
dd65c9
index a375e6188..000000000
dd65c9
--- a/units/remote-cryptsetup-pre.target
dd65c9
+++ /dev/null
dd65c9
@@ -1,15 +0,0 @@
dd65c9
-#  This file is part of systemd.
dd65c9
-#
dd65c9
-#  systemd is free software; you can redistribute it and/or modify it
dd65c9
-#  under the terms of the GNU Lesser General Public License as published by
dd65c9
-#  the Free Software Foundation; either version 2.1 of the License, or
dd65c9
-#  (at your option) any later version.
dd65c9
-
dd65c9
-[Unit]
dd65c9
-Description=Remote Encrypted Volumes (Pre)
dd65c9
-Documentation=man:systemd.special(7)
dd65c9
-RefuseManualStart=yes
dd65c9
-Before=remote-cryptsetup.target
dd65c9
-
dd65c9
-After=network.target network-online.target
dd65c9
-Wants=network-online.target
dd65c9
diff --git a/units/remote-cryptsetup.target b/units/remote-cryptsetup.target
dd65c9
index c306d521f..d485b0672 100644
dd65c9
--- a/units/remote-cryptsetup.target
dd65c9
+++ b/units/remote-cryptsetup.target
dd65c9
@@ -8,7 +8,7 @@
dd65c9
 [Unit]
dd65c9
 Description=Remote Encrypted Volumes
dd65c9
 Documentation=man:systemd.special(7)
dd65c9
-After=remote-cryptsetup-pre.target
dd65c9
+After=remote-fs-pre.target
dd65c9
 DefaultDependencies=no
dd65c9
 Conflicts=shutdown.target
dd65c9