mirror of https://gitee.com/openkylin/libvirt.git
snapshot: cache qemu-img location
As more clients start to want to know this information, doing a PATH stat walk and malloc for every client adds up. We are only caching the location, not the capabilities, so even if qemu-img is updated in the meantime, it will still probably live in the same location. So there is no need to worry about clearing this particular cache. * src/qemu/qemu_conf.h (qemud_driver): Add member. * src/qemu/qemu_driver.c (qemudShutdown): Cleanup. (qemuFindQemuImgBinary): Add an argument, and cache result. (qemuDomainSnapshotForEachQcow2, qemuDomainSnapshotDiscard) (qemuDomainSnapshotCreateInactive, qemuDomainSnapshotRevertInactive) (qemuDomainSnapshotCreateXML, qemuDomainRevertToSnapshot): Update callers.
This commit is contained in:
parent
8055e5af82
commit
3881a47088
|
@ -82,6 +82,7 @@ struct qemud_driver {
|
||||||
char *cacheDir;
|
char *cacheDir;
|
||||||
char *saveDir;
|
char *saveDir;
|
||||||
char *snapshotDir;
|
char *snapshotDir;
|
||||||
|
char *qemuImgBinary;
|
||||||
unsigned int vncAutoUnixSocket : 1;
|
unsigned int vncAutoUnixSocket : 1;
|
||||||
unsigned int vncTLS : 1;
|
unsigned int vncTLS : 1;
|
||||||
unsigned int vncTLSx509verify : 1;
|
unsigned int vncTLSx509verify : 1;
|
||||||
|
|
|
@ -777,6 +777,7 @@ qemudShutdown(void) {
|
||||||
VIR_FREE(qemu_driver->cacheDir);
|
VIR_FREE(qemu_driver->cacheDir);
|
||||||
VIR_FREE(qemu_driver->saveDir);
|
VIR_FREE(qemu_driver->saveDir);
|
||||||
VIR_FREE(qemu_driver->snapshotDir);
|
VIR_FREE(qemu_driver->snapshotDir);
|
||||||
|
VIR_FREE(qemu_driver->qemuImgBinary);
|
||||||
VIR_FREE(qemu_driver->autoDumpPath);
|
VIR_FREE(qemu_driver->autoDumpPath);
|
||||||
VIR_FREE(qemu_driver->vncTLSx509certdir);
|
VIR_FREE(qemu_driver->vncTLSx509certdir);
|
||||||
VIR_FREE(qemu_driver->vncListen);
|
VIR_FREE(qemu_driver->vncListen);
|
||||||
|
@ -1583,19 +1584,19 @@ cleanup:
|
||||||
|
|
||||||
|
|
||||||
/* Locate an appropriate 'qemu-img' binary. */
|
/* Locate an appropriate 'qemu-img' binary. */
|
||||||
static char *
|
static const char *
|
||||||
qemuFindQemuImgBinary(void)
|
qemuFindQemuImgBinary(struct qemud_driver *driver)
|
||||||
{
|
{
|
||||||
char *ret;
|
if (!driver->qemuImgBinary) {
|
||||||
|
driver->qemuImgBinary = virFindFileInPath("kvm-img");
|
||||||
ret = virFindFileInPath("kvm-img");
|
if (!driver->qemuImgBinary)
|
||||||
if (ret == NULL)
|
driver->qemuImgBinary = virFindFileInPath("qemu-img");
|
||||||
ret = virFindFileInPath("qemu-img");
|
if (!driver->qemuImgBinary)
|
||||||
if (ret == NULL)
|
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("unable to find kvm-img or qemu-img"));
|
"%s", _("unable to find kvm-img or qemu-img"));
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return driver->qemuImgBinary;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -1656,7 +1657,8 @@ cleanup:
|
||||||
/* The domain is expected to be locked and inactive. Return -1 on normal
|
/* The domain is expected to be locked and inactive. Return -1 on normal
|
||||||
* failure, 1 if we skipped a disk due to try_all. */
|
* failure, 1 if we skipped a disk due to try_all. */
|
||||||
static int
|
static int
|
||||||
qemuDomainSnapshotForEachQcow2(virDomainObjPtr vm,
|
qemuDomainSnapshotForEachQcow2(struct qemud_driver *driver,
|
||||||
|
virDomainObjPtr vm,
|
||||||
virDomainSnapshotObjPtr snap,
|
virDomainSnapshotObjPtr snap,
|
||||||
const char *op,
|
const char *op,
|
||||||
bool try_all)
|
bool try_all)
|
||||||
|
@ -1666,7 +1668,7 @@ qemuDomainSnapshotForEachQcow2(virDomainObjPtr vm,
|
||||||
int i;
|
int i;
|
||||||
bool skipped = false;
|
bool skipped = false;
|
||||||
|
|
||||||
qemuimgarg[0] = qemuFindQemuImgBinary();
|
qemuimgarg[0] = qemuFindQemuImgBinary(driver);
|
||||||
if (qemuimgarg[0] == NULL) {
|
if (qemuimgarg[0] == NULL) {
|
||||||
/* qemuFindQemuImgBinary set the error */
|
/* qemuFindQemuImgBinary set the error */
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -1736,7 +1738,8 @@ qemuDomainSnapshotDiscard(struct qemud_driver *driver,
|
||||||
if (!metadata_only) {
|
if (!metadata_only) {
|
||||||
if (!virDomainObjIsActive(vm)) {
|
if (!virDomainObjIsActive(vm)) {
|
||||||
/* Ignore any skipped disks */
|
/* Ignore any skipped disks */
|
||||||
if (qemuDomainSnapshotForEachQcow2(vm, snap, "-d", true) < 0)
|
if (qemuDomainSnapshotForEachQcow2(driver, vm, snap, "-d",
|
||||||
|
true) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
priv = vm->privateData;
|
priv = vm->privateData;
|
||||||
|
@ -8652,10 +8655,11 @@ static int qemuDomainSnapshotIsAllowed(virDomainObjPtr vm)
|
||||||
|
|
||||||
/* The domain is expected to be locked and inactive. */
|
/* The domain is expected to be locked and inactive. */
|
||||||
static int
|
static int
|
||||||
qemuDomainSnapshotCreateInactive(virDomainObjPtr vm,
|
qemuDomainSnapshotCreateInactive(struct qemud_driver *driver,
|
||||||
|
virDomainObjPtr vm,
|
||||||
virDomainSnapshotObjPtr snap)
|
virDomainSnapshotObjPtr snap)
|
||||||
{
|
{
|
||||||
return qemuDomainSnapshotForEachQcow2(vm, snap, "-c", false);
|
return qemuDomainSnapshotForEachQcow2(driver, vm, snap, "-c", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The domain is expected to be locked and active. */
|
/* The domain is expected to be locked and active. */
|
||||||
|
@ -8860,7 +8864,7 @@ static virDomainSnapshotPtr qemuDomainSnapshotCreateXML(virDomainPtr domain,
|
||||||
* qemu-img recognizes the snapshot name in at least one of
|
* qemu-img recognizes the snapshot name in at least one of
|
||||||
* the domain's disks? */
|
* the domain's disks? */
|
||||||
} else if (!virDomainObjIsActive(vm)) {
|
} else if (!virDomainObjIsActive(vm)) {
|
||||||
if (qemuDomainSnapshotCreateInactive(vm, snap) < 0)
|
if (qemuDomainSnapshotCreateInactive(driver, vm, snap) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
if (qemuDomainSnapshotCreateActive(domain->conn, driver,
|
if (qemuDomainSnapshotCreateActive(domain->conn, driver,
|
||||||
|
@ -9097,11 +9101,12 @@ cleanup:
|
||||||
|
|
||||||
/* The domain is expected to be locked and inactive. */
|
/* The domain is expected to be locked and inactive. */
|
||||||
static int
|
static int
|
||||||
qemuDomainSnapshotRevertInactive(virDomainObjPtr vm,
|
qemuDomainSnapshotRevertInactive(struct qemud_driver *driver,
|
||||||
|
virDomainObjPtr vm,
|
||||||
virDomainSnapshotObjPtr snap)
|
virDomainSnapshotObjPtr snap)
|
||||||
{
|
{
|
||||||
/* Try all disks, but report failure if we skipped any. */
|
/* Try all disks, but report failure if we skipped any. */
|
||||||
int ret = qemuDomainSnapshotForEachQcow2(vm, snap, "-a", true);
|
int ret = qemuDomainSnapshotForEachQcow2(driver, vm, snap, "-a", true);
|
||||||
return ret > 0 ? -1 : ret;
|
return ret > 0 ? -1 : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9294,7 +9299,7 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
||||||
detail);
|
detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuDomainSnapshotRevertInactive(vm, snap) < 0) {
|
if (qemuDomainSnapshotRevertInactive(driver, vm, snap) < 0) {
|
||||||
if (!vm->persistent) {
|
if (!vm->persistent) {
|
||||||
if (qemuDomainObjEndJob(driver, vm) > 0)
|
if (qemuDomainObjEndJob(driver, vm) > 0)
|
||||||
virDomainRemoveInactive(&driver->domains, vm);
|
virDomainRemoveInactive(&driver->domains, vm);
|
||||||
|
|
Loading…
Reference in New Issue