mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
snapshot: only pass snapshot to qemu command line when reverting
Changing the current vm, and writing that change to the file system, all before a new qemu starts, is risky; it's hard to roll back if starting the new qemu fails for some reason. Instead of abusing vm->current_snapshot and making the command line generator decide whether the current snapshot warrants using -loadvm, it is better to just directly pass a snapshot all the way through the call chain if it is to be loaded. This frees up the last use of snapshot->def->active for qemu's use, so the next patch can repurpose that field for tracking which snapshot is current. * src/qemu/qemu_command.c (qemuBuildCommandLine): Don't use active field of snapshot. * src/qemu/qemu_process.c (qemuProcessStart): Add a parameter. * src/qemu/qemu_process.h (qemuProcessStart): Update prototype. * src/qemu/qemu_migration.c (qemuMigrationPrepareAny): Update callers. * src/qemu/qemu_driver.c (qemudDomainCreate) (qemuDomainSaveImageStartVM, qemuDomainObjStart) (qemuDomainRevertToSnapshot): Likewise. (qemuDomainSnapshotSetCurrentActive) (qemuDomainSnapshotSetCurrentInactive): Delete unused functions.
This commit is contained in:
parent
861dc84bb5
commit
5e47785b85
@ -2866,7 +2866,7 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
virBitmapPtr qemuCaps,
|
virBitmapPtr qemuCaps,
|
||||||
const char *migrateFrom,
|
const char *migrateFrom,
|
||||||
int migrateFd,
|
int migrateFd,
|
||||||
virDomainSnapshotObjPtr current_snapshot,
|
virDomainSnapshotObjPtr snapshot,
|
||||||
enum virVMOperationType vmop)
|
enum virVMOperationType vmop)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -4782,9 +4782,8 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_snapshot && current_snapshot->def->active)
|
if (snapshot)
|
||||||
virCommandAddArgList(cmd, "-loadvm", current_snapshot->def->name,
|
virCommandAddArgList(cmd, "-loadvm", snapshot->def->name, NULL);
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (def->namespaceData) {
|
if (def->namespaceData) {
|
||||||
qemuDomainCmdlineDefPtr qemucmd;
|
qemuDomainCmdlineDefPtr qemucmd;
|
||||||
|
@ -804,12 +804,6 @@ qemudShutdown(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int qemuDomainSnapshotSetCurrentActive(virDomainObjPtr vm,
|
|
||||||
char *snapshotDir);
|
|
||||||
static int qemuDomainSnapshotSetCurrentInactive(virDomainObjPtr vm,
|
|
||||||
char *snapshotDir);
|
|
||||||
|
|
||||||
|
|
||||||
static virDrvOpenStatus qemudOpen(virConnectPtr conn,
|
static virDrvOpenStatus qemudOpen(virConnectPtr conn,
|
||||||
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
@ -1297,7 +1291,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
|
|||||||
if (qemuProcessStart(conn, driver, vm, NULL,
|
if (qemuProcessStart(conn, driver, vm, NULL,
|
||||||
(flags & VIR_DOMAIN_START_PAUSED) != 0,
|
(flags & VIR_DOMAIN_START_PAUSED) != 0,
|
||||||
(flags & VIR_DOMAIN_START_AUTODESTROY) != 0,
|
(flags & VIR_DOMAIN_START_AUTODESTROY) != 0,
|
||||||
-1, NULL, VIR_VM_OP_CREATE) < 0) {
|
-1, NULL, NULL, VIR_VM_OP_CREATE) < 0) {
|
||||||
virDomainAuditStart(vm, "booted", false);
|
virDomainAuditStart(vm, "booted", false);
|
||||||
if (qemuDomainObjEndJob(driver, vm) > 0)
|
if (qemuDomainObjEndJob(driver, vm) > 0)
|
||||||
virDomainRemoveInactive(&driver->domains,
|
virDomainRemoveInactive(&driver->domains,
|
||||||
@ -3920,7 +3914,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
|
|||||||
|
|
||||||
/* Set the migration source and start it up. */
|
/* Set the migration source and start it up. */
|
||||||
ret = qemuProcessStart(conn, driver, vm, "stdio", true,
|
ret = qemuProcessStart(conn, driver, vm, "stdio", true,
|
||||||
false, *fd, path, VIR_VM_OP_RESTORE);
|
false, *fd, path, NULL, VIR_VM_OP_RESTORE);
|
||||||
|
|
||||||
if (intermediatefd != -1) {
|
if (intermediatefd != -1) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -4462,7 +4456,7 @@ qemuDomainObjStart(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = qemuProcessStart(conn, driver, vm, NULL, start_paused,
|
ret = qemuProcessStart(conn, driver, vm, NULL, start_paused,
|
||||||
autodestroy, -1, NULL, VIR_VM_OP_CREATE);
|
autodestroy, -1, NULL, NULL, VIR_VM_OP_CREATE);
|
||||||
virDomainAuditStart(vm, "booted", ret >= 0);
|
virDomainAuditStart(vm, "booted", ret >= 0);
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
virDomainEventPtr event =
|
virDomainEventPtr event =
|
||||||
@ -8318,32 +8312,6 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemuDomainSnapshotSetCurrentActive(virDomainObjPtr vm,
|
|
||||||
char *snapshotDir)
|
|
||||||
{
|
|
||||||
if (vm->current_snapshot) {
|
|
||||||
vm->current_snapshot->def->active = 1;
|
|
||||||
|
|
||||||
return qemuDomainSnapshotWriteMetadata(vm, vm->current_snapshot,
|
|
||||||
snapshotDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qemuDomainSnapshotSetCurrentInactive(virDomainObjPtr vm,
|
|
||||||
char *snapshotDir)
|
|
||||||
{
|
|
||||||
if (vm->current_snapshot) {
|
|
||||||
vm->current_snapshot->def->active = 0;
|
|
||||||
|
|
||||||
return qemuDomainSnapshotWriteMetadata(vm, vm->current_snapshot,
|
|
||||||
snapshotDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int qemuDomainSnapshotIsAllowed(virDomainObjPtr vm)
|
static int qemuDomainSnapshotIsAllowed(virDomainObjPtr vm)
|
||||||
{
|
{
|
||||||
@ -8790,15 +8758,10 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
} else {
|
} else {
|
||||||
if (qemuDomainSnapshotSetCurrentActive(vm, driver->snapshotDir) < 0)
|
|
||||||
goto endjob;
|
|
||||||
|
|
||||||
rc = qemuProcessStart(snapshot->domain->conn, driver, vm, NULL,
|
rc = qemuProcessStart(snapshot->domain->conn, driver, vm, NULL,
|
||||||
false, false, -1, NULL, VIR_VM_OP_CREATE);
|
false, false, -1, NULL, vm->current_snapshot,
|
||||||
|
VIR_VM_OP_CREATE);
|
||||||
virDomainAuditStart(vm, "from-snapshot", rc >= 0);
|
virDomainAuditStart(vm, "from-snapshot", rc >= 0);
|
||||||
if (qemuDomainSnapshotSetCurrentInactive(vm,
|
|
||||||
driver->snapshotDir) < 0)
|
|
||||||
goto endjob;
|
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
@ -8845,9 +8808,6 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuDomainSnapshotSetCurrentActive(vm, driver->snapshotDir) < 0)
|
|
||||||
goto endjob;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
@ -1034,7 +1034,7 @@ qemuMigrationPrepareAny(struct qemud_driver *driver,
|
|||||||
* -incoming $migrateFrom
|
* -incoming $migrateFrom
|
||||||
*/
|
*/
|
||||||
if (qemuProcessStart(dconn, driver, vm, migrateFrom, true,
|
if (qemuProcessStart(dconn, driver, vm, migrateFrom, true,
|
||||||
true, dataFD[0], NULL,
|
true, dataFD[0], NULL, NULL,
|
||||||
VIR_VM_OP_MIGRATE_IN_START) < 0) {
|
VIR_VM_OP_MIGRATE_IN_START) < 0) {
|
||||||
virDomainAuditStart(vm, "migrated", false);
|
virDomainAuditStart(vm, "migrated", false);
|
||||||
/* Note that we don't set an error here because qemuProcessStart
|
/* Note that we don't set an error here because qemuProcessStart
|
||||||
|
@ -2614,6 +2614,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
bool autodestroy,
|
bool autodestroy,
|
||||||
int stdin_fd,
|
int stdin_fd,
|
||||||
const char *stdin_path,
|
const char *stdin_path,
|
||||||
|
virDomainSnapshotObjPtr snapshot,
|
||||||
enum virVMOperationType vmop)
|
enum virVMOperationType vmop)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -2816,16 +2817,9 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
VIR_DEBUG("Building emulator command line");
|
VIR_DEBUG("Building emulator command line");
|
||||||
if (!(cmd = qemuBuildCommandLine(conn, driver, vm->def, priv->monConfig,
|
if (!(cmd = qemuBuildCommandLine(conn, driver, vm->def, priv->monConfig,
|
||||||
priv->monJSON != 0, priv->qemuCaps,
|
priv->monJSON != 0, priv->qemuCaps,
|
||||||
migrateFrom, stdin_fd,
|
migrateFrom, stdin_fd, snapshot, vmop)))
|
||||||
vm->current_snapshot, vmop)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* XXX */
|
|
||||||
if (qemuDomainSnapshotSetCurrentInactive(vm, driver->snapshotDir) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* now that we know it is about to start call the hook if present */
|
/* now that we know it is about to start call the hook if present */
|
||||||
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
|
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
|
||||||
char *xml = virDomainDefFormat(vm->def, 0);
|
char *xml = virDomainDefFormat(vm->def, 0);
|
||||||
|
@ -52,6 +52,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
bool autodestroy,
|
bool autodestroy,
|
||||||
int stdin_fd,
|
int stdin_fd,
|
||||||
const char *stdin_path,
|
const char *stdin_path,
|
||||||
|
virDomainSnapshotObjPtr snapshot,
|
||||||
enum virVMOperationType vmop);
|
enum virVMOperationType vmop);
|
||||||
|
|
||||||
void qemuProcessStop(struct qemud_driver *driver,
|
void qemuProcessStop(struct qemud_driver *driver,
|
||||||
|
Loading…
Reference in New Issue
Block a user