vmspawn: make sure to pass the right firmware image type to qemu

The JSON data reports whether firmware types are qcow or raw. Let's pass
that into the qemu cmdline.
This commit is contained in:
Lennart Poettering 2024-01-19 19:14:09 +01:00
parent e8ce204d86
commit 71e42c36d0
3 changed files with 27 additions and 9 deletions

View file

@ -29,7 +29,9 @@ OvmfConfig* ovmf_config_free(OvmfConfig *config) {
return NULL;
free(config->path);
free(config->format);
free(config->vars);
free(config->vars_format);
return mfree(config);
}
@ -78,7 +80,9 @@ int qemu_check_vsock_support(void) {
typedef struct FirmwareData {
char **features;
char *firmware;
char *firmware_format;
char *vars;
char *vars_format;
} FirmwareData;
static bool firmware_data_supports_sb(const FirmwareData *fwd) {
@ -91,9 +95,11 @@ static FirmwareData* firmware_data_free(FirmwareData *fwd) {
if (!fwd)
return NULL;
fwd->features = strv_free(fwd->features);
fwd->firmware = mfree(fwd->firmware);
fwd->vars = mfree(fwd->vars);
strv_free(fwd->features);
free(fwd->firmware);
free(fwd->firmware_format);
free(fwd->vars);
free(fwd->vars_format);
return mfree(fwd);
}
@ -101,8 +107,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(FirmwareData*, firmware_data_free);
static int firmware_executable(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) {
static const JsonDispatch table[] = {
{ "filename", JSON_VARIANT_STRING, json_dispatch_string, offsetof(FirmwareData, firmware), JSON_MANDATORY },
{ "format", JSON_VARIANT_STRING, NULL, 0, JSON_MANDATORY },
{ "filename", JSON_VARIANT_STRING, json_dispatch_string, offsetof(FirmwareData, firmware), JSON_MANDATORY },
{ "format", JSON_VARIANT_STRING, json_dispatch_string, offsetof(FirmwareData, firmware_format), JSON_MANDATORY },
{}
};
@ -111,8 +117,8 @@ static int firmware_executable(const char *name, JsonVariant *v, JsonDispatchFla
static int firmware_nvram_template(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) {
static const JsonDispatch table[] = {
{ "filename", JSON_VARIANT_STRING, json_dispatch_string, offsetof(FirmwareData, vars), JSON_MANDATORY },
{ "format", JSON_VARIANT_STRING, NULL, 0, JSON_MANDATORY },
{ "filename", JSON_VARIANT_STRING, json_dispatch_string, offsetof(FirmwareData, vars), JSON_MANDATORY },
{ "format", JSON_VARIANT_STRING, json_dispatch_string, offsetof(FirmwareData, vars_format), JSON_MANDATORY },
{}
};
@ -229,7 +235,9 @@ static int ovmf_config_make(FirmwareData *fwd, OvmfConfig **ret) {
*config = (OvmfConfig) {
.path = TAKE_PTR(fwd->firmware),
.format = TAKE_PTR(fwd->firmware_format),
.vars = TAKE_PTR(fwd->vars),
.vars_format = TAKE_PTR(fwd->vars_format),
.supports_sb = firmware_data_supports_sb(fwd),
};

View file

@ -22,10 +22,20 @@
typedef struct OvmfConfig {
char *path;
char *format;
char *vars;
char *vars_format;
bool supports_sb;
} OvmfConfig;
static inline const char *ovmf_config_format(const OvmfConfig *c) {
return ASSERT_PTR(c)->format ?: "raw";
}
static inline const char *ovmf_config_vars_format(const OvmfConfig *c) {
return ASSERT_PTR(c)->vars_format ?: "raw";
}
OvmfConfig* ovmf_config_free(OvmfConfig *ovmf_config);
DEFINE_TRIVIAL_CLEANUP_FUNC(OvmfConfig*, ovmf_config_free);

View file

@ -601,7 +601,7 @@ static int run_virtual_machine(void) {
if (r < 0)
return log_oom();
r = strv_extendf(&cmdline, "if=pflash,format=raw,readonly=on,file=%s", ovmf_config->path);
r = strv_extendf(&cmdline, "if=pflash,format=%s,readonly=on,file=%s", ovmf_config_format(ovmf_config), ovmf_config->path);
if (r < 0)
return log_oom();
@ -639,7 +639,7 @@ static int run_virtual_machine(void) {
if (r < 0)
return log_oom();
r = strv_extendf(&cmdline, "file=%s,if=pflash,format=raw", ovmf_vars_to);
r = strv_extendf(&cmdline, "file=%s,if=pflash,format=%s", ovmf_vars_to, ovmf_config_format(ovmf_config));
if (r < 0)
return log_oom();
}