[systemd-devel] [PATCH 3/3] cryptsetup-generator: Add support for naming luks devices on kernel cmdline

Jan Janssen medhefgo at web.de
Fri Nov 7 03:43:27 PST 2014


---
 man/kernel-command-line.xml           |  2 ++
 man/systemd-cryptsetup-generator.xml  | 19 +++++++++++++++++++
 src/cryptsetup/cryptsetup-generator.c | 32 ++++++++++++++++++++++++++------
 3 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/man/kernel-command-line.xml b/man/kernel-command-line.xml
index 68460ac..e32ed19 100644
--- a/man/kernel-command-line.xml
+++ b/man/kernel-command-line.xml
@@ -283,6 +283,8 @@
                                 <term><varname>rd.luks=</varname></term>
                                 <term><varname>luks.crypttab=</varname></term>
                                 <term><varname>rd.luks.crypttab=</varname></term>
+                                <term><varname>luks.name=</varname></term>
+                                <term><varname>rd.luks.name=</varname></term>
                                 <term><varname>luks.uuid=</varname></term>
                                 <term><varname>rd.luks.uuid=</varname></term>
                                 <term><varname>luks.options=</varname></term>
diff --git a/man/systemd-cryptsetup-generator.xml b/man/systemd-cryptsetup-generator.xml
index d4a9cc7..c8753ce 100644
--- a/man/systemd-cryptsetup-generator.xml
+++ b/man/systemd-cryptsetup-generator.xml
@@ -140,6 +140,25 @@
                         </varlistentry>
 
                         <varlistentry>
+                                <term><varname>luks.name=</varname></term>
+                                <term><varname>rd.luks.name=</varname></term>
+
+                                <listitem><para>Takes a LUKS super
+                                block UUID followed by an '=' and a name. This implies
+                                <varname>rd.luks.uuid=</varname> or <varname>luks.uuid=</varname>
+                                and will additionally make the LUKS device given by
+                                the UUID appear under the provided name.</para>
+
+                                <para><varname>rd.luks.name=</varname>
+                                is honored only by initial RAM disk
+                                (initrd) while
+                                <varname>luks.name=</varname> is
+                                honored by both the main system and
+                                the initrd.</para>
+                                </listitem>
+                        </varlistentry>
+
+                        <varlistentry>
                                 <term><varname>luks.options=</varname></term>
                                 <term><varname>rd.luks.options=</varname></term>
 
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index 09374c2..faf6caf 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -37,6 +37,7 @@
 typedef struct crypto_device {
         char *uuid;
         char *keyfile;
+        char *name;
         char *options;
         bool create;
 } crypto_device;
@@ -278,6 +279,7 @@ static void free_arg_disks(void) {
         while ((d = hashmap_steal_first(arg_disks))) {
                 free(d->uuid);
                 free(d->keyfile);
+                free(d->name);
                 free(d->options);
                 free(d);
         }
@@ -298,7 +300,7 @@ static crypto_device *get_crypto_device(const char *uuid) {
                         return NULL;
 
                 d->create = false;
-                d->keyfile = d->options = NULL;
+                d->keyfile = d->options = d->name = NULL;
 
                 d->uuid = strdup(uuid);
                 if (!d->uuid) {
@@ -374,6 +376,22 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
                 } else if (free_and_strdup(&arg_default_keyfile, value))
                         return log_oom();
 
+        } else if (STR_IN_SET(key, "luks.name", "rd.luks.name") && value) {
+
+                r = sscanf(value, "%m[0-9a-fA-F-]=%ms", &uuid, &uuid_value);
+                if (r == 2) {
+                        d = get_crypto_device(uuid);
+                        if (!d)
+                                return log_oom();
+
+                        d->create = arg_whitelist = true;
+
+                        free(d->name);
+                        d->name = uuid_value;
+                        uuid_value = NULL;
+                } else
+                        log_warning("Failed to parse luks name switch %s. Ignoring.", value);
+
         }
 
         return 0;
@@ -458,14 +476,16 @@ static int add_proc_cmdline_devices(void) {
 
         HASHMAP_FOREACH(d, arg_disks, i) {
                 const char *options;
-                _cleanup_free_ char *name = NULL, *device = NULL;
+                _cleanup_free_ char *device = NULL;
 
                 if (!d->create)
                         continue;
 
-                name = strappend("luks-", d->uuid);
-                if (!name)
-                        return log_oom();
+                if (!d->name) {
+                        d->name = strappend("luks-", d->uuid);
+                        if (!d->name)
+                                return log_oom();
+                }
 
                 device = strappend("UUID=", d->uuid);
                 if (!device)
@@ -478,7 +498,7 @@ static int add_proc_cmdline_devices(void) {
                 else
                         options = "timeout=0";
 
-                r = create_disk(name, device, d->keyfile ?: arg_default_keyfile, options);
+                r = create_disk(d->name, device, d->keyfile ?: arg_default_keyfile, options);
                 if (r < 0)
                         return r;
         }
-- 
2.1.3



More information about the systemd-devel mailing list