35bb946
From c5e8935962eadc9e901f4fe13e187aaaad487142 Mon Sep 17 00:00:00 2001
ca246f9
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
ca246f9
Date: Thu, 12 Oct 2017 22:34:54 +0200
ca246f9
Subject: [PATCH] units: replace remote-cryptsetup-pre.target with
ca246f9
 remote-fs-pre.target
ca246f9
ca246f9
remote-cryptsetup-pre.target was designed as an active unit (that pulls in
ca246f9
network-online.target), the opposite of remote-fs-pre.target (a passive unit,
ca246f9
with individual provider services ordering itself before it and pulling it in,
ca246f9
for example iscsi.service and nfs-client.target).
ca246f9
ca246f9
To make remote-cryptsetup-pre.target really work, those services should be
ca246f9
ordered before it too. But this would require updates to all those services,
ca246f9
not just changes from systemd side.
ca246f9
ca246f9
But the requirements for remote-fs-pre.target and remote-cryptset-pre.target
ca246f9
are fairly similar (e.g. iscsi devices can certainly be used for both), so
ca246f9
let's reuse remote-fs-pre.target also for remote cryptsetup units. This loses
ca246f9
a bit of flexibility, but does away with the requirement for various provider
ca246f9
services to know about remote-cryptsetup-pre.target.
35bb946
35bb946
(cherry picked from commit a0dd209763f9e67054ee322a2dfd52bccf345c2e)
ca246f9
---
ca246f9
 man/crypttab.xml                      |  2 +-
ca246f9
 man/systemd.special.xml               | 20 ++++----------------
ca246f9
 src/cryptsetup/cryptsetup-generator.c |  2 +-
ca246f9
 units/meson.build                     |  1 -
ca246f9
 units/remote-cryptsetup-pre.target    | 15 ---------------
ca246f9
 units/remote-cryptsetup.target        |  2 +-
ca246f9
 6 files changed, 7 insertions(+), 35 deletions(-)
ca246f9
 delete mode 100644 units/remote-cryptsetup-pre.target
ca246f9
ca246f9
diff --git a/man/crypttab.xml b/man/crypttab.xml
ca246f9
index ac7d55271c..caed04836e 100644
ca246f9
--- a/man/crypttab.xml
ca246f9
+++ b/man/crypttab.xml
ca246f9
@@ -198,7 +198,7 @@
ca246f9
         started after the network is available, similarly to
ca246f9
         <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>
ca246f9
         units marked with <option>_netdev</option>. The service unit to set up this device
ca246f9
-        will be ordered between <filename>remote-cryptsetup-pre.target</filename> and
ca246f9
+        will be ordered between <filename>remote-fs-pre.target</filename> and
ca246f9
         <filename>remote-cryptsetup.target</filename>, instead of
ca246f9
         <filename>cryptsetup-pre.target</filename> and
ca246f9
         <filename>cryptsetup.target</filename>.</para></listitem>
ca246f9
diff --git a/man/systemd.special.xml b/man/systemd.special.xml
35bb946
index 4beef07dd5..32706dc6cf 100644
ca246f9
--- a/man/systemd.special.xml
ca246f9
+++ b/man/systemd.special.xml
ca246f9
@@ -81,7 +81,6 @@
ca246f9
     <filename>poweroff.target</filename>,
ca246f9
     <filename>printer.target</filename>,
ca246f9
     <filename>reboot.target</filename>,
ca246f9
-    <filename>remote-cryptsetup-pre.target</filename>,
ca246f9
     <filename>remote-cryptsetup.target</filename>,
ca246f9
     <filename>remote-fs-pre.target</filename>,
ca246f9
     <filename>remote-fs.target</filename>,
ca246f9
@@ -494,18 +493,6 @@
ca246f9
           this target unit, for compatibility with SysV.</para>
ca246f9
         </listitem>
ca246f9
       </varlistentry>
ca246f9
-      <varlistentry>
ca246f9
-        <term><filename>remote-cryptsetup-pre.target</filename></term>
ca246f9
-        <listitem>
ca246f9
-          <para>This target unit is automatically ordered before all cryptsetup devices
ca246f9
-          marked with the <option>_netdev</option>. It can be used to execute additional
ca246f9
-          units before such devices are set up.</para>
ca246f9
-
ca246f9
-          <para>It is ordered after <filename>network.target</filename> and
ca246f9
-          <filename>network-online.target</filename>, and also pulls the latter in as a
ca246f9
-          <varname>Wants=</varname> dependency.</para>
ca246f9
-        </listitem>
ca246f9
-      </varlistentry>
ca246f9
       <varlistentry>
ca246f9
         <term><filename>remote-cryptsetup.target</filename></term>
ca246f9
         <listitem>
ca246f9
@@ -906,9 +893,10 @@
ca246f9
         <term><filename>remote-fs-pre.target</filename></term>
ca246f9
         <listitem>
ca246f9
           <para>This target unit is automatically ordered before all
ca246f9
-          remote mount point units (see above). It can be used to run
ca246f9
-          certain units before the remote mounts are established. Note
ca246f9
-          that this unit is generally not part of the initial
ca246f9
+          mount point units (see above) and cryptsetup devices
ca246f9
+          marked with the <option>_netdev</option>. It can be used to run
ca246f9
+          certain units before remote encrypted devices and mounts are established.
ca246f9
+          Note that this unit is generally not part of the initial
ca246f9
           transaction, unless the unit that wants to be ordered before
ca246f9
           all remote mounts pulls it in via a
ca246f9
           <varname>Wants=</varname> type dependency. If the unit wants
ca246f9
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
ca246f9
index 3752ca2ef2..040a1aa408 100644
ca246f9
--- a/src/cryptsetup/cryptsetup-generator.c
ca246f9
+++ b/src/cryptsetup/cryptsetup-generator.c
ca246f9
@@ -113,7 +113,7 @@ static int create_disk(
ca246f9
                 "Conflicts=umount.target\n"
ca246f9
                 "IgnoreOnIsolate=true\n"
ca246f9
                 "After=%s\n",
ca246f9
-                netdev ? "remote-cryptsetup-pre.target" : "cryptsetup-pre.target");
ca246f9
+                netdev ? "remote-fs-pre.target" : "cryptsetup-pre.target");
ca246f9
 
ca246f9
         if (!nofail)
ca246f9
                 fprintf(f,
ca246f9
diff --git a/units/meson.build b/units/meson.build
ca246f9
index 8494d23e9e..4e2ae3f302 100644
ca246f9
--- a/units/meson.build
ca246f9
+++ b/units/meson.build
ca246f9
@@ -48,7 +48,6 @@ units = [
ca246f9
         ['proc-sys-fs-binfmt_misc.mount',       'ENABLE_BINFMT'],
ca246f9
         ['reboot.target',                       '',
ca246f9
          'runlevel6.target ctrl-alt-del.target'],
ca246f9
-        ['remote-cryptsetup-pre.target',        'HAVE_LIBCRYPTSETUP'],
ca246f9
         ['remote-cryptsetup.target',            'HAVE_LIBCRYPTSETUP',
ca246f9
          join_paths(pkgsysconfdir, 'system/multi-user.target.wants/')],
ca246f9
         ['remote-fs-pre.target',                ''],
ca246f9
diff --git a/units/remote-cryptsetup-pre.target b/units/remote-cryptsetup-pre.target
ca246f9
deleted file mode 100644
ca246f9
index a375e61889..0000000000
ca246f9
--- a/units/remote-cryptsetup-pre.target
ca246f9
+++ /dev/null
ca246f9
@@ -1,15 +0,0 @@
ca246f9
-#  This file is part of systemd.
ca246f9
-#
ca246f9
-#  systemd is free software; you can redistribute it and/or modify it
ca246f9
-#  under the terms of the GNU Lesser General Public License as published by
ca246f9
-#  the Free Software Foundation; either version 2.1 of the License, or
ca246f9
-#  (at your option) any later version.
ca246f9
-
ca246f9
-[Unit]
ca246f9
-Description=Remote Encrypted Volumes (Pre)
ca246f9
-Documentation=man:systemd.special(7)
ca246f9
-RefuseManualStart=yes
ca246f9
-Before=remote-cryptsetup.target
ca246f9
-
ca246f9
-After=network.target network-online.target
ca246f9
-Wants=network-online.target
ca246f9
diff --git a/units/remote-cryptsetup.target b/units/remote-cryptsetup.target
ca246f9
index c306d521f7..d485b06726 100644
ca246f9
--- a/units/remote-cryptsetup.target
ca246f9
+++ b/units/remote-cryptsetup.target
ca246f9
@@ -8,7 +8,7 @@
ca246f9
 [Unit]
ca246f9
 Description=Remote Encrypted Volumes
ca246f9
 Documentation=man:systemd.special(7)
ca246f9
-After=remote-cryptsetup-pre.target
ca246f9
+After=remote-fs-pre.target
ca246f9
 DefaultDependencies=no
ca246f9
 Conflicts=shutdown.target
ca246f9