]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Add UUID option to config files
authorTobias Hunger <tobias.hunger@gmail.com>
Wed, 20 May 2020 08:44:33 +0000 (10:44 +0200)
committerTobias Hunger <tobias.hunger@gmail.com>
Mon, 25 May 2020 13:48:59 +0000 (15:48 +0200)
Add a option to provide a UUID for the partition that will get
created and document that.

man/repart.d.xml
src/nspawn/nspawn-settings.c
src/nspawn/nspawn-settings.h
src/partition/repart.c
src/shared/conf-parser.c
src/shared/conf-parser.h

index 49936086701bf063487f9a5f08b9c95c08b16401..f2c155e2002cd093e0d351c0e3f23aefb9399c5a 100644 (file)
         automatically used.</para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><varname>UUID=</varname></term>
+
+        <listitem><para>The UUID to assign to the partition if none is assigned yet. Note that this
+        setting is not used for matching. It is also not used when a UUID is already set for an existing
+        partition. It is thus only used when a partition is newly created or when an existing one had a
+        all-zero UUID set. If not specified a UUID derived from the partition type is automatically
+        used.</para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><varname>Priority=</varname></term>
 
index 4b1115b6e852394bca3fae259bc768ae4f602be2..4e1cb3835c67b38c5b5c363ef095bdd15f2b117e 100644 (file)
@@ -295,35 +295,6 @@ int config_parse_capability(
         return 0;
 }
 
-int config_parse_id128(
-                const char *unit,
-                const char *filename,
-                unsigned line,
-                const char *section,
-                unsigned section_line,
-                const char *lvalue,
-                int ltype,
-                const char *rvalue,
-                void *data,
-                void *userdata) {
-
-        sd_id128_t t, *result = data;
-        int r;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-
-        r = sd_id128_from_string(rvalue, &t);
-        if (r < 0) {
-                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue);
-                return 0;
-        }
-
-        *result = t;
-        return 0;
-}
-
 int config_parse_pivot_root(
                 const char *unit,
                 const char *filename,
index 6f2c1141e63e6799c1a2a736e54c689ce85ca2a9..24f98fd7ef7b084870c84b4b1b87b07fe8453756 100644 (file)
@@ -234,7 +234,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Settings*, settings_free);
 const struct ConfigPerfItem* nspawn_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_capability);
-CONFIG_PARSER_PROTOTYPE(config_parse_id128);
 CONFIG_PARSER_PROTOTYPE(config_parse_expose_port);
 CONFIG_PARSER_PROTOTYPE(config_parse_volatile_mode);
 CONFIG_PARSER_PROTOTYPE(config_parse_pivot_root);
index 46e82eaf90a360c6d46e21a39c60c2d63c225472..16cb5e45c451e6df3c090d9b1637c0f97c550f82 100644 (file)
@@ -963,6 +963,7 @@ static int partition_read_definition(Partition *p, const char *path) {
         ConfigTableItem table[] = {
                 { "Partition", "Type",            config_parse_type,     0,  &p->type_uuid      },
                 { "Partition", "Label",           config_parse_label,    0,  &p->new_label      },
+                { "Partition", "UUID",            config_parse_id128,    0,  &p->new_uuid       },
                 { "Partition", "Priority",        config_parse_int32,    0,  &p->priority       },
                 { "Partition", "Weight",          config_parse_weight,   0,  &p->weight         },
                 { "Partition", "PaddingWeight",   config_parse_weight,   0,  &p->padding_weight },
@@ -2232,13 +2233,12 @@ static int context_acquire_partition_uuids_and_labels(Context *context) {
         assert(context);
 
         LIST_FOREACH(partitions, p, context->partitions) {
-                assert(sd_id128_is_null(p->new_uuid));
-
                 /* Never touch foreign partitions */
                 if (PARTITION_IS_FOREIGN(p)) {
                         p->new_uuid = p->current_uuid;
 
                         if (p->current_label) {
+                                free(p->new_label);
                                 p->new_label = strdup(p->current_label);
                                 if (!p->new_label)
                                         return log_oom();
@@ -2249,20 +2249,21 @@ static int context_acquire_partition_uuids_and_labels(Context *context) {
 
                 if (!sd_id128_is_null(p->current_uuid))
                         p->new_uuid = p->current_uuid; /* Never change initialized UUIDs */
-                else {
+                else if (sd_id128_is_null(p->new_uuid)) {
+                        /* Not explicitly set by user! */
                         r = partition_acquire_uuid(context, p, &p->new_uuid);
                         if (r < 0)
                                 return r;
                 }
 
-                if (p->new_label) /* Explicitly set by user? */
-                        continue;
-
                 if (!isempty(p->current_label)) {
+                        free(p->new_label);
                         p->new_label = strdup(p->current_label); /* never change initialized labels */
                         if (!p->new_label)
                                 return log_oom();
-                } else {
+                } else if (!p->new_label) {
+                        /* Not explicitly set by user! */
+
                         r = partition_acquire_label(context, p, &p->new_label);
                         if (r < 0)
                                 return r;
index 23cb3b65b67678c84727a1c680d1a194d70ae72e..e685ecbff7af8779c7a42926dc14488fd0e4dc69 100644 (file)
@@ -23,6 +23,7 @@
 #include "path-util.h"
 #include "process-util.h"
 #include "rlimit-util.h"
+#include "sd-id128.h"
 #include "signal-util.h"
 #include "socket-util.h"
 #include "string-util.h"
@@ -648,6 +649,35 @@ int config_parse_bool(const char* unit,
         return 0;
 }
 
+int config_parse_id128(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        sd_id128_t t, *result = data;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        r = sd_id128_from_string(rvalue, &t);
+        if (r < 0)
+                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue);
+        else if (sd_id128_is_null(t))
+                log_syntax(unit, LOG_ERR, filename, line, 0, "128bit ID/UUID is all 0, ignoring: %s", rvalue);
+
+        *result = t;
+        return 0;
+}
+
 int config_parse_tristate(
                 const char* unit,
                 const char *filename,
index 59e74590cabff84870530ee816a5c1817b03c180..82c692af10c3a91366dd0f4aaf5876ab181788ed 100644 (file)
@@ -122,6 +122,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_iec_size);
 CONFIG_PARSER_PROTOTYPE(config_parse_si_uint64);
 CONFIG_PARSER_PROTOTYPE(config_parse_iec_uint64);
 CONFIG_PARSER_PROTOTYPE(config_parse_bool);
+CONFIG_PARSER_PROTOTYPE(config_parse_id128);
 CONFIG_PARSER_PROTOTYPE(config_parse_tristate);
 CONFIG_PARSER_PROTOTYPE(config_parse_string);
 CONFIG_PARSER_PROTOTYPE(config_parse_path);