Vmspawn fixes (#37320)

Fixes
https://github.com/systemd/systemd/pull/36618#issuecomment-2844694845

and 

```
qemu-kvm: -device vmgenid,guid=5f303a47-6fae-4dd7-969c-6c1ea61e816e: 'vmgenid' is not a valid device model name
```
This commit is contained in:
Yu Watanabe
2025-05-04 12:24:04 +09:00
committed by GitHub
2 changed files with 27 additions and 19 deletions

View File

@@ -12,6 +12,12 @@
# define ARCHITECTURE_SUPPORTS_SMBIOS 0
#endif
#if defined(__x86_64__) || defined(__i386__)
# define ARCHITECTURE_SUPPORTS_VMGENID 1
#else
# define ARCHITECTURE_SUPPORTS_VMGENID 0
#endif
#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
# define ARCHITECTURE_SUPPORTS_TPM 1
#else

View File

@@ -1656,24 +1656,26 @@ 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");
if (ARCHITECTURE_SUPPORTS_VMGENID) {
/* 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");
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();
}
_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 */
_cleanup_free_ char *runtime_dir = NULL;
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir_destroy = NULL;
@@ -2039,6 +2041,10 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
r = strv_extend_many(&cmdline, "-device", "scsi-hd,drive=vmspawn,bootindex=1");
if (r < 0)
return log_oom();
r = grow_image(arg_image, arg_grow_image);
if (r < 0)
return r;
}
if (arg_directory) {
@@ -2334,10 +2340,6 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
return log_error_errno(r, "Failed to parse $SYSTEMD_VMSPAWN_QEMU_EXTRA: %m");
}
r = grow_image(arg_image, arg_grow_image);
if (r < 0)
return r;
if (DEBUG_LOGGING) {
_cleanup_free_ char *joined = quote_command_line(cmdline, SHELL_ESCAPE_EMPTY);
if (!joined)