ecbff1
From ea1a15b35b70573ab61ca0b8123205c6885c69e4 Mon Sep 17 00:00:00 2001
ecbff1
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
ecbff1
Date: Tue, 5 Sep 2017 10:15:13 +0200
ecbff1
Subject: [PATCH] units: add remote-cryptsetup.target and
ecbff1
 remote-cryptsetup-pre.target
ecbff1
ecbff1
The pair is similar to remote-fs.target and remote-fs-pre.target. Any
ecbff1
cryptsetup devices which require network shall be ordered after
ecbff1
remote-cryptsetup-pre.target and before remote-cryptsetup.target.
ecbff1
ecbff1
Cherry-picked from: 889128b8b27abb13e1691a72e4ce0562c564e257
ecbff1
Resolves: #1384014
ecbff1
---
ecbff1
 Makefile.am                        |  4 +++-
ecbff1
 man/systemd.special.xml            | 23 +++++++++++++++++++++++
ecbff1
 units/cryptsetup-pre.target        |  2 +-
ecbff1
 units/cryptsetup.target            |  2 +-
ecbff1
 units/remote-cryptsetup-pre.target | 15 +++++++++++++++
ecbff1
 units/remote-cryptsetup.target     | 10 ++++++++++
ecbff1
 6 files changed, 53 insertions(+), 3 deletions(-)
ecbff1
 create mode 100644 units/remote-cryptsetup-pre.target
ecbff1
 create mode 100644 units/remote-cryptsetup.target
ecbff1
ecbff1
diff --git a/Makefile.am b/Makefile.am
ecbff1
index 0e2f8d561..a1ebf5cb0 100644
ecbff1
--- a/Makefile.am
ecbff1
+++ b/Makefile.am
ecbff1
@@ -4861,7 +4861,9 @@ systemgenerator_PROGRAMS += \
ecbff1
 
ecbff1
 dist_systemunit_DATA += \
ecbff1
 	units/cryptsetup.target \
ecbff1
-	units/cryptsetup-pre.target
ecbff1
+	units/cryptsetup-pre.target \
ecbff1
+	units/remote-cryptsetup.target \
ecbff1
+	units/remote-cryptsetup-pre.target
ecbff1
 
ecbff1
 systemd_cryptsetup_SOURCES = \
ecbff1
 	src/cryptsetup/cryptsetup.c
ecbff1
diff --git a/man/systemd.special.xml b/man/systemd.special.xml
ecbff1
index eb464f9f8..5529d3bf7 100644
ecbff1
--- a/man/systemd.special.xml
ecbff1
+++ b/man/systemd.special.xml
ecbff1
@@ -81,6 +81,8 @@
ecbff1
     <filename>poweroff.target</filename>,
ecbff1
     <filename>printer.target</filename>,
ecbff1
     <filename>reboot.target</filename>,
ecbff1
+    <filename>remote-cryptsetup-pre.target</filename>,
ecbff1
+    <filename>remote-cryptsetup.target</filename>,
ecbff1
     <filename>remote-fs.target</filename>,
ecbff1
     <filename>remote-fs-pre.target</filename>,
ecbff1
     <filename>rescue.target</filename>,
ecbff1
@@ -404,6 +406,27 @@
ecbff1
           this target unit, for compatibility with SysV.</para>
ecbff1
         </listitem>
ecbff1
       </varlistentry>
ecbff1
+      <varlistentry>
ecbff1
+        <term><filename>remote-cryptsetup-pre.target</filename></term>
ecbff1
+        <listitem>
ecbff1
+          <para>This target unit is automatically ordered before all cryptsetup devices
ecbff1
+          marked with the <option>_netdev</option>. It can be used to execute additional
ecbff1
+          units before such devices are set up.</para>
ecbff1
+
ecbff1
+          <para>It is ordered after <filename>network.target</filename> and
ecbff1
+          <filename>network-online.target</filename>, and also pulls the latter in as a
ecbff1
+          <varname>Wants=</varname> dependency.</para>
ecbff1
+        </listitem>
ecbff1
+      </varlistentry>
ecbff1
+      <varlistentry>
ecbff1
+        <term><filename>remote-cryptsetup.target</filename></term>
ecbff1
+        <listitem>
ecbff1
+          <para>Similar to <filename>cryptsetup.target</filename>, but for encrypted
ecbff1
+          devices which are accessed over the network. It is used for
ecbff1
+          <citerefentry><refentrytitle>crypttab</refentrytitle><manvolnum>8</manvolnum></citerefentry>
ecbff1
+          entries marked with <option>_netdev</option>.</para>
ecbff1
+        </listitem>
ecbff1
+      </varlistentry>
ecbff1
       <varlistentry>
ecbff1
         <term><filename>remote-fs.target</filename></term>
ecbff1
         <listitem>
ecbff1
diff --git a/units/cryptsetup-pre.target b/units/cryptsetup-pre.target
ecbff1
index 42e35dd4e..6cb28a61a 100644
ecbff1
--- a/units/cryptsetup-pre.target
ecbff1
+++ b/units/cryptsetup-pre.target
ecbff1
@@ -6,7 +6,7 @@
ecbff1
 #  (at your option) any later version.
ecbff1
 
ecbff1
 [Unit]
ecbff1
-Description=Encrypted Volumes (Pre)
ecbff1
+Description=Local Encrypted Volumes (Pre)
ecbff1
 Documentation=man:systemd.special(7)
ecbff1
 RefuseManualStart=yes
ecbff1
 Before=cryptsetup.target
ecbff1
diff --git a/units/cryptsetup.target b/units/cryptsetup.target
ecbff1
index 25d3e33f6..10b17fd38 100644
ecbff1
--- a/units/cryptsetup.target
ecbff1
+++ b/units/cryptsetup.target
ecbff1
@@ -6,5 +6,5 @@
ecbff1
 #  (at your option) any later version.
ecbff1
 
ecbff1
 [Unit]
ecbff1
-Description=Encrypted Volumes
ecbff1
+Description=Local Encrypted Volumes
ecbff1
 Documentation=man:systemd.special(7)
ecbff1
diff --git a/units/remote-cryptsetup-pre.target b/units/remote-cryptsetup-pre.target
ecbff1
new file mode 100644
ecbff1
index 000000000..a375e6188
ecbff1
--- /dev/null
ecbff1
+++ b/units/remote-cryptsetup-pre.target
ecbff1
@@ -0,0 +1,15 @@
ecbff1
+#  This file is part of systemd.
ecbff1
+#
ecbff1
+#  systemd is free software; you can redistribute it and/or modify it
ecbff1
+#  under the terms of the GNU Lesser General Public License as published by
ecbff1
+#  the Free Software Foundation; either version 2.1 of the License, or
ecbff1
+#  (at your option) any later version.
ecbff1
+
ecbff1
+[Unit]
ecbff1
+Description=Remote Encrypted Volumes (Pre)
ecbff1
+Documentation=man:systemd.special(7)
ecbff1
+RefuseManualStart=yes
ecbff1
+Before=remote-cryptsetup.target
ecbff1
+
ecbff1
+After=network.target network-online.target
ecbff1
+Wants=network-online.target
ecbff1
diff --git a/units/remote-cryptsetup.target b/units/remote-cryptsetup.target
ecbff1
new file mode 100644
ecbff1
index 000000000..60943bd1c
ecbff1
--- /dev/null
ecbff1
+++ b/units/remote-cryptsetup.target
ecbff1
@@ -0,0 +1,10 @@
ecbff1
+#  This file is part of systemd.
ecbff1
+#
ecbff1
+#  systemd is free software; you can redistribute it and/or modify it
ecbff1
+#  under the terms of the GNU Lesser General Public License as published by
ecbff1
+#  the Free Software Foundation; either version 2.1 of the License, or
ecbff1
+#  (at your option) any later version.
ecbff1
+
ecbff1
+[Unit]
ecbff1
+Description=Remote Encrypted Volumes
ecbff1
+Documentation=man:systemd.special(7)