qemu: Introduce qemuFirmwareEnsureNVRAM()

This helper replaces qemuDomainNVRAMPathFormat() and also
incorporates some common operations that all callers of that
helper needed.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Andrea Bolognani 2023-02-03 19:21:03 +01:00
parent d4383682c4
commit e057a29b76

View File

@ -979,12 +979,32 @@ qemuFirmwareOSInterfaceTypeFromOsDefLoaderType(virDomainLoader type)
} }
/**
* qemuFirmwareEnsureNVRAM:
* @def: domain definition
* @cfg: QEMU driver configuration
*
* Make sure that a source for the NVRAM file exists, possibly by
* creating it. This might involve automatically generating the
* corresponding path.
*/
static void static void
qemuDomainNVRAMPathFormat(virQEMUDriverConfig *cfg, qemuFirmwareEnsureNVRAM(virDomainDef *def,
virDomainDef *def, const virQEMUDriverConfig *cfg)
char **path)
{ {
*path = g_strdup_printf("%s/%s_VARS.fd", cfg->nvramDir, def->name); virDomainLoaderDef *loader = def->os.loader;
if (!loader)
return;
if (loader->nvram)
return;
loader->nvram = virStorageSourceNew();
loader->nvram->type = VIR_STORAGE_TYPE_FILE;
loader->nvram->format = VIR_STORAGE_FILE_RAW;
loader->nvram->path = g_strdup_printf("%s/%s_VARS.fd", cfg->nvramDir, def->name);
} }
@ -1209,12 +1229,7 @@ qemuFirmwareEnableFeaturesModern(virQEMUDriverConfig *cfg,
loader->path = g_strdup(flash->executable.filename); loader->path = g_strdup(flash->executable.filename);
if (flash->mode == QEMU_FIRMWARE_FLASH_MODE_SPLIT) { if (flash->mode == QEMU_FIRMWARE_FLASH_MODE_SPLIT) {
if (!loader->nvram) { qemuFirmwareEnsureNVRAM(def, cfg);
loader->nvram = virStorageSourceNew();
loader->nvram->type = VIR_STORAGE_TYPE_FILE;
loader->nvram->format = VIR_STORAGE_FILE_RAW;
qemuDomainNVRAMPathFormat(cfg, def, &loader->nvram->path);
}
/* If the NVRAM is not a local path then we can't create or /* If the NVRAM is not a local path then we can't create or
* reset it, so in that case filling in the nvramTemplate * reset it, so in that case filling in the nvramTemplate
@ -1417,12 +1432,7 @@ qemuFirmwareFillDomainLegacy(virQEMUDriver *driver,
loader->readonly = VIR_TRISTATE_BOOL_YES; loader->readonly = VIR_TRISTATE_BOOL_YES;
loader->nvramTemplate = g_strdup(cfg->firmwares[i]->nvram); loader->nvramTemplate = g_strdup(cfg->firmwares[i]->nvram);
if (!loader->nvram) { qemuFirmwareEnsureNVRAM(def, cfg);
loader->nvram = virStorageSourceNew();
loader->nvram->type = VIR_STORAGE_TYPE_FILE;
loader->nvram->format = VIR_STORAGE_FILE_RAW;
qemuDomainNVRAMPathFormat(cfg, def, &loader->nvram->path);
}
VIR_DEBUG("decided on firmware '%s' template '%s'", VIR_DEBUG("decided on firmware '%s' template '%s'",
loader->path, NULLSTR(loader->nvramTemplate)); loader->path, NULLSTR(loader->nvramTemplate));
@ -1574,12 +1584,7 @@ qemuFirmwareFillDomain(virQEMUDriver *driver,
* generate a path to the domain-specific NVRAM file, but * generate a path to the domain-specific NVRAM file, but
* otherwise we're good to go */ * otherwise we're good to go */
if (loader->nvramTemplate) { if (loader->nvramTemplate) {
if (!loader->nvram) { qemuFirmwareEnsureNVRAM(def, cfg);
loader->nvram = virStorageSourceNew();
loader->nvram->type = VIR_STORAGE_TYPE_FILE;
loader->nvram->format = VIR_STORAGE_FILE_RAW;
qemuDomainNVRAMPathFormat(cfg, def, &loader->nvram->path);
}
return 0; return 0;
} }
} }