mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
conf: Store managed save image existence in virDomainObj
This patch stores existence of the image in the object. At start of the daemon the state is checked and then updated in key moments in domain lifecycle.
This commit is contained in:
parent
9c9de4e64d
commit
bc8e15592c
@ -1817,6 +1817,8 @@ struct _virDomainObj {
|
|||||||
virDomainSnapshotObjList snapshots;
|
virDomainSnapshotObjList snapshots;
|
||||||
virDomainSnapshotObjPtr current_snapshot;
|
virDomainSnapshotObjPtr current_snapshot;
|
||||||
|
|
||||||
|
bool hasManagedSave;
|
||||||
|
|
||||||
void *privateData;
|
void *privateData;
|
||||||
void (*privateDataFreeFunc)(void *);
|
void (*privateDataFreeFunc)(void *);
|
||||||
|
|
||||||
|
@ -59,6 +59,11 @@
|
|||||||
/* Number of Xen scheduler parameters */
|
/* Number of Xen scheduler parameters */
|
||||||
#define XEN_SCHED_CREDIT_NPARAM 2
|
#define XEN_SCHED_CREDIT_NPARAM 2
|
||||||
|
|
||||||
|
static void libxlDomainManagedSaveLoad(void *payload,
|
||||||
|
const void *n ATTRIBUTE_UNUSED,
|
||||||
|
void *opaque);
|
||||||
|
|
||||||
|
|
||||||
static libxlDriverPrivatePtr libxl_driver = NULL;
|
static libxlDriverPrivatePtr libxl_driver = NULL;
|
||||||
|
|
||||||
/* Function declarations */
|
/* Function declarations */
|
||||||
@ -647,6 +652,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
|||||||
VIR_WARN("Failed to remove the managed state %s",
|
VIR_WARN("Failed to remove the managed state %s",
|
||||||
managed_save_path);
|
managed_save_path);
|
||||||
}
|
}
|
||||||
|
vm->hasManagedSave = false;
|
||||||
}
|
}
|
||||||
VIR_FREE(managed_save_path);
|
VIR_FREE(managed_save_path);
|
||||||
}
|
}
|
||||||
@ -983,6 +989,9 @@ libxlStartup(int privileged) {
|
|||||||
virHashForEach(libxl_driver->domains.objs, libxlAutostartDomain,
|
virHashForEach(libxl_driver->domains.objs, libxlAutostartDomain,
|
||||||
libxl_driver);
|
libxl_driver);
|
||||||
|
|
||||||
|
virHashForEach(libxl_driver->domains.objs, libxlDomainManagedSaveLoad,
|
||||||
|
libxl_driver);
|
||||||
|
|
||||||
libxlDriverUnlock(libxl_driver);
|
libxlDriverUnlock(libxl_driver);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1868,6 +1877,8 @@ libxlDoDomainSave(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vm->hasManagedSave = true;
|
||||||
|
|
||||||
if (!vm->persistent) {
|
if (!vm->persistent) {
|
||||||
virDomainRemoveInactive(&driver->domains, vm);
|
virDomainRemoveInactive(&driver->domains, vm);
|
||||||
vm = NULL;
|
vm = NULL;
|
||||||
@ -2124,13 +2135,33 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
libxlDomainManagedSaveLoad(void *payload,
|
||||||
|
const void *n ATTRIBUTE_UNUSED,
|
||||||
|
void *opaque)
|
||||||
|
{
|
||||||
|
virDomainObjPtr vm = payload;
|
||||||
|
libxlDriverPrivatePtr driver = opaque;
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
virDomainObjLock(vm);
|
||||||
|
|
||||||
|
if (!(name = libxlDomainManagedSavePath(driver, vm)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
vm->hasManagedSave = virFileExists(name);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virDomainObjUnlock(vm);
|
||||||
|
VIR_FREE(name);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
libxlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
|
libxlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
|
||||||
{
|
{
|
||||||
libxlDriverPrivatePtr driver = dom->conn->privateData;
|
libxlDriverPrivatePtr driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *name = NULL;
|
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
@ -2144,14 +2175,9 @@ libxlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = libxlDomainManagedSavePath(driver, vm);
|
ret = vm->hasManagedSave;
|
||||||
if (name == NULL)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
ret = virFileExists(name);
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(name);
|
|
||||||
if (vm)
|
if (vm)
|
||||||
virDomainObjUnlock(vm);
|
virDomainObjUnlock(vm);
|
||||||
libxlDriverUnlock(driver);
|
libxlDriverUnlock(driver);
|
||||||
@ -2183,6 +2209,7 @@ libxlDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = unlink(name);
|
ret = unlink(name);
|
||||||
|
vm->hasManagedSave = false;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(name);
|
VIR_FREE(name);
|
||||||
|
@ -139,6 +139,11 @@ static int qemuDomainObjStart(virConnectPtr conn,
|
|||||||
|
|
||||||
static int qemudDomainGetMaxVcpus(virDomainPtr dom);
|
static int qemudDomainGetMaxVcpus(virDomainPtr dom);
|
||||||
|
|
||||||
|
static void qemuDomainManagedSaveLoad(void *payload,
|
||||||
|
const void *n ATTRIBUTE_UNUSED,
|
||||||
|
void *opaque);
|
||||||
|
|
||||||
|
|
||||||
struct qemud_driver *qemu_driver = NULL;
|
struct qemud_driver *qemu_driver = NULL;
|
||||||
|
|
||||||
|
|
||||||
@ -734,6 +739,9 @@ qemudStartup(int privileged) {
|
|||||||
virHashForEach(qemu_driver->domains.objs, qemuDomainSnapshotLoad,
|
virHashForEach(qemu_driver->domains.objs, qemuDomainSnapshotLoad,
|
||||||
qemu_driver->snapshotDir);
|
qemu_driver->snapshotDir);
|
||||||
|
|
||||||
|
virHashForEach(qemu_driver->domains.objs, qemuDomainManagedSaveLoad,
|
||||||
|
qemu_driver);
|
||||||
|
|
||||||
qemu_driver->workerPool = virThreadPoolNew(0, 1, 0, processWatchdogEvent, qemu_driver);
|
qemu_driver->workerPool = virThreadPoolNew(0, 1, 0, processWatchdogEvent, qemu_driver);
|
||||||
if (!qemu_driver->workerPool)
|
if (!qemu_driver->workerPool)
|
||||||
goto error;
|
goto error;
|
||||||
@ -2729,6 +2737,7 @@ qemuDomainSaveInternal(struct qemud_driver *driver, virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
vm->hasManagedSave = true;
|
||||||
|
|
||||||
/* Shut it down */
|
/* Shut it down */
|
||||||
qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SAVED, 0);
|
qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SAVED, 0);
|
||||||
@ -2918,13 +2927,33 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
qemuDomainManagedSaveLoad(void *payload,
|
||||||
|
const void *n ATTRIBUTE_UNUSED,
|
||||||
|
void *opaque)
|
||||||
|
{
|
||||||
|
virDomainObjPtr vm = payload;
|
||||||
|
struct qemud_driver *driver = opaque;
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
virDomainObjLock(vm);
|
||||||
|
|
||||||
|
if (!(name = qemuDomainManagedSavePath(driver, vm)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
vm->hasManagedSave = virFileExists(name);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virDomainObjUnlock(vm);
|
||||||
|
VIR_FREE(name);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
|
qemuDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
|
||||||
{
|
{
|
||||||
struct qemud_driver *driver = dom->conn->privateData;
|
struct qemud_driver *driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *name = NULL;
|
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
@ -2938,14 +2967,9 @@ qemuDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = qemuDomainManagedSavePath(driver, vm);
|
ret = vm->hasManagedSave;
|
||||||
if (name == NULL)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
ret = virFileExists(name);
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(name);
|
|
||||||
if (vm)
|
if (vm)
|
||||||
virDomainObjUnlock(vm);
|
virDomainObjUnlock(vm);
|
||||||
qemuDriverUnlock(driver);
|
qemuDriverUnlock(driver);
|
||||||
@ -2977,6 +3001,7 @@ qemuDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = unlink(name);
|
ret = unlink(name);
|
||||||
|
vm->hasManagedSave = false;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(name);
|
VIR_FREE(name);
|
||||||
@ -4820,8 +4845,13 @@ qemuDomainObjStart(virConnectPtr conn,
|
|||||||
ret = qemuDomainObjRestore(conn, driver, vm, managed_save,
|
ret = qemuDomainObjRestore(conn, driver, vm, managed_save,
|
||||||
start_paused, bypass_cache);
|
start_paused, bypass_cache);
|
||||||
|
|
||||||
if (ret == 0 && unlink(managed_save) < 0)
|
if (ret == 0) {
|
||||||
|
if (unlink(managed_save) < 0)
|
||||||
VIR_WARN("Failed to remove the managed state %s", managed_save);
|
VIR_WARN("Failed to remove the managed state %s", managed_save);
|
||||||
|
else
|
||||||
|
vm->hasManagedSave = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
VIR_WARN("Ignoring incomplete managed state %s", managed_save);
|
VIR_WARN("Ignoring incomplete managed state %s", managed_save);
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user