mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
qemu: process: Extract setup of file-backed nvram from template
The setup of nvram will later be extended to also support block-device backed nvram, so extract the file-backed nvram setup steps from 'qemuPrepareNVRAM' into 'qemuPrepareNVRAMFile'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
32228ecb02
commit
fce4319f58
@ -4584,39 +4584,18 @@ qemuPrepareNVRAMHelper(int dstFD,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuPrepareNVRAM(virQEMUDriver *driver,
|
qemuPrepareNVRAMFile(virDomainObj *vm,
|
||||||
virDomainObj *vm,
|
bool reset_nvram)
|
||||||
bool reset_nvram)
|
|
||||||
{
|
{
|
||||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
qemuDomainObjPrivate *priv = vm->privateData;
|
||||||
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(priv->driver);
|
||||||
VIR_AUTOCLOSE srcFD = -1;
|
VIR_AUTOCLOSE srcFD = -1;
|
||||||
virDomainLoaderDef *loader = vm->def->os.loader;
|
virDomainLoaderDef *loader = vm->def->os.loader;
|
||||||
struct qemuPrepareNVRAMHelperData data;
|
struct qemuPrepareNVRAMHelperData data;
|
||||||
|
|
||||||
if (!loader || !loader->nvram)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!virStorageSourceIsLocalStorage(loader->nvram)) {
|
|
||||||
if (!reset_nvram) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
||||||
_("resetting of nvram is not supported with network backed nvram"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virFileExists(loader->nvram->path) && !reset_nvram)
|
if (virFileExists(loader->nvram->path) && !reset_nvram)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* virFileRewrite() would overwrite the device node-file/symlink rather than
|
|
||||||
* just write the data to it, thus block-device nvram is not yet supported */
|
|
||||||
if (virStorageSourceIsBlockLocal(loader->nvram)) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
||||||
_("creation or formatting of nvram type='block' is not supported"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!loader->nvramTemplate) {
|
if (!loader->nvramTemplate) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("unable to find any master var store for loader: %1$s"),
|
_("unable to find any master var store for loader: %1$s"),
|
||||||
@ -4653,6 +4632,52 @@ qemuPrepareNVRAM(virQEMUDriver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuPrepareNVRAM(virDomainObj *vm,
|
||||||
|
bool reset_nvram)
|
||||||
|
{
|
||||||
|
virDomainLoaderDef *loader = vm->def->os.loader;
|
||||||
|
|
||||||
|
if (!loader || !loader->nvram)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch (virStorageSourceGetActualType(loader->nvram)) {
|
||||||
|
case VIR_STORAGE_TYPE_FILE:
|
||||||
|
return qemuPrepareNVRAMFile(vm, reset_nvram);
|
||||||
|
|
||||||
|
case VIR_STORAGE_TYPE_BLOCK:
|
||||||
|
/* virFileRewrite() would overwrite the device node-file/symlink rather than
|
||||||
|
* just write the data to it, thus block-device nvram is not yet supported */
|
||||||
|
if (virFileExists(loader->nvram->path) && !reset_nvram)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||||
|
_("creation or formatting of nvram type='block' is not supported"));
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
case VIR_STORAGE_TYPE_DIR:
|
||||||
|
case VIR_STORAGE_TYPE_NETWORK:
|
||||||
|
case VIR_STORAGE_TYPE_VOLUME:
|
||||||
|
case VIR_STORAGE_TYPE_NVME:
|
||||||
|
case VIR_STORAGE_TYPE_VHOST_USER:
|
||||||
|
case VIR_STORAGE_TYPE_VHOST_VDPA:
|
||||||
|
case VIR_STORAGE_TYPE_LAST:
|
||||||
|
case VIR_STORAGE_TYPE_NONE:
|
||||||
|
if (reset_nvram) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
|
||||||
|
_("resetting of nvram is not supported with nvram device backed by '%1$s'"),
|
||||||
|
virStorageTypeToString(virStorageSourceGetActualType(loader->nvram)));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* otherwise we just assume that the user did set up stuff correctly */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
qemuLogOperation(virDomainObj *vm,
|
qemuLogOperation(virDomainObj *vm,
|
||||||
const char *msg,
|
const char *msg,
|
||||||
@ -7283,7 +7308,7 @@ qemuProcessPrepareHost(virQEMUDriver *driver,
|
|||||||
qemuProcessMakeDir(driver, vm, priv->channelTargetDir) < 0)
|
qemuProcessMakeDir(driver, vm, priv->channelTargetDir) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (qemuPrepareNVRAM(driver, vm, !!(flags & VIR_QEMU_PROCESS_START_RESET_NVRAM)) < 0)
|
if (qemuPrepareNVRAM(vm, !!(flags & VIR_QEMU_PROCESS_START_RESET_NVRAM)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (vm->def->vsock) {
|
if (vm->def->vsock) {
|
||||||
|
Loading…
Reference in New Issue
Block a user