]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
vmspawn: enable vmgenid for all VMs
authorLennart Poettering <lennart@poettering.net>
Fri, 19 Apr 2024 12:54:12 +0000 (14:54 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 20 Apr 2024 10:10:42 +0000 (12:10 +0200)
This passes an ID derived from the vmgenid down to all VMs. This is
useful to have an identifier for this VM generation id. We derive it
from the invocation ID, if we have one, otherwise we randomize it.

Eventually we should make use of the vmgenid changing to re-acquire MAC
addresses, DHCP leases as such. Let's for now enable the VMM side of the
concept as first step towards that.

src/vmspawn/vmspawn.c

index 2ebb158640e7c333434ec9a169672f9e638ac927..9366ce111da4dadc164524e1402a042d4cee96fd 100644 (file)
@@ -1294,6 +1294,24 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
                 if (strv_extend_many(&cmdline, "-uuid", SD_ID128_TO_UUID_STRING(arg_uuid)) < 0)
                         return log_oom();
 
+        /* Derive a vmgenid automatically from the invocation ID, in a deterministic way. */
+        sd_id128_t vmgenid;
+        r = sd_id128_get_invocation_app_specific(SD_ID128_MAKE(bd,84,6d,e3,e4,7d,4b,6c,a6,85,4a,87,0f,3c,a3,a0), &vmgenid);
+        if (r < 0) {
+                log_debug_errno(r, "Failed to get invocation ID, making up randomized vmgenid: %m");
+
+                r = sd_id128_randomize(&vmgenid);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to make up randomized vmgenid: %m");
+        }
+
+        _cleanup_free_ char *vmgenid_device = NULL;
+        if (asprintf(&vmgenid_device, "vmgenid,guid=" SD_ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(vmgenid)) < 0)
+                return log_oom();
+
+        if (strv_extend_many(&cmdline, "-device", vmgenid_device) < 0)
+                return log_oom();
+
         /* if we are going to be starting any units with state then create our runtime dir */
         if (arg_tpm != 0 || arg_directory || arg_runtime_mounts.n_mounts != 0) {
                 r = runtime_directory(&arg_runtime_directory, arg_privileged ? RUNTIME_SCOPE_SYSTEM : RUNTIME_SCOPE_USER, "systemd/vmspawn");