qemu: Avoid holding the driver lock in trivial snapshot API's

In most of the snapshot API's there's no need to hold the driver lock
the whole time.

This patch adds helper functions that get the domain object in functions
that don't require the driver lock and simplifies call paths from
snapshot-related API's.
This commit is contained in:
Peter Krempa 2012-09-24 22:31:35 +02:00
parent de7f0774c3
commit 35fe4e7e2e
1 changed files with 81 additions and 186 deletions

View File

@ -187,6 +187,63 @@ struct qemuAutostartData {
virConnectPtr conn; virConnectPtr conn;
}; };
/* Looks up the domain object and unlocks the driver. The returned domain
* object is locked and the caller is responsible for unlocking it. */
static virDomainObjPtr
qemuDomObjFromDomain(virDomainPtr domain)
{
struct qemud_driver *driver = domain->conn->privateData;
virDomainObjPtr vm;
char uuidstr[VIR_UUID_STRING_BUFLEN];
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
qemuDriverUnlock(driver);
if (!vm) {
virUUIDFormat(domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
}
return vm;
}
/* Looks up the domain object from snapshot and unlocks the driver. The
* returned domain object is locked and the caller is responsible for
* unlocking it */
static virDomainObjPtr
qemuDomObjFromSnapshot(virDomainSnapshotPtr snapshot)
{
return qemuDomObjFromDomain(snapshot->domain);
}
/* Looks up snapshot object from VM and name */
static virDomainSnapshotObjPtr
qemuSnapObjFromName(virDomainObjPtr vm,
const char *name)
{
virDomainSnapshotObjPtr snap = NULL;
snap = virDomainSnapshotFindByName(vm->snapshots, name);
if (!snap)
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("no domain snapshot with matching name '%s'"),
name);
return snap;
}
/* Looks up snapshot object from VM and snapshotPtr */
static virDomainSnapshotObjPtr
qemuSnapObjFromSnapshot(virDomainObjPtr vm,
virDomainSnapshotPtr snapshot)
{
return qemuSnapObjFromName(vm, snapshot->name);
}
static void static void
qemuAutostartDomain(void *payload, const void *name ATTRIBUTE_UNUSED, qemuAutostartDomain(void *payload, const void *name ATTRIBUTE_UNUSED,
void *opaque) void *opaque)
@ -11305,22 +11362,14 @@ static int qemuDomainSnapshotListNames(virDomainPtr domain, char **names,
int nameslen, int nameslen,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = domain->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
int n = -1; int n = -1;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromDomain(domain)))
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
n = virDomainSnapshotObjListGetNames(vm->snapshots, NULL, names, nameslen, n = virDomainSnapshotObjListGetNames(vm->snapshots, NULL, names, nameslen,
flags); flags);
@ -11328,36 +11377,26 @@ static int qemuDomainSnapshotListNames(virDomainPtr domain, char **names,
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return n; return n;
} }
static int qemuDomainSnapshotNum(virDomainPtr domain, static int qemuDomainSnapshotNum(virDomainPtr domain,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = domain->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
int n = -1; int n = -1;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromDomain(domain)))
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
n = virDomainSnapshotObjListNum(vm->snapshots, NULL, flags); n = virDomainSnapshotObjListNum(vm->snapshots, NULL, flags);
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return n; return n;
} }
@ -11365,29 +11404,20 @@ static int
qemuDomainListAllSnapshots(virDomainPtr domain, virDomainSnapshotPtr **snaps, qemuDomainListAllSnapshots(virDomainPtr domain, virDomainSnapshotPtr **snaps,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = domain->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
int n = -1; int n = -1;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromDomain(domain)))
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
n = virDomainListSnapshots(vm->snapshots, NULL, domain, snaps, flags); n = virDomainListSnapshots(vm->snapshots, NULL, domain, snaps, flags);
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return n; return n;
} }
@ -11397,7 +11427,6 @@ qemuDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
int nameslen, int nameslen,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = snapshot->domain->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
virDomainSnapshotObjPtr snap = NULL; virDomainSnapshotObjPtr snap = NULL;
int n = -1; int n = -1;
@ -11405,23 +11434,11 @@ qemuDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromSnapshot(snapshot)))
vm = virDomainFindByUUID(&driver->domains, snapshot->domain->uuid);
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(snapshot->domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
snap = virDomainSnapshotFindByName(vm->snapshots, snapshot->name); if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
if (!snap) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("no domain snapshot with matching name '%s'"),
snapshot->name);
goto cleanup; goto cleanup;
}
n = virDomainSnapshotObjListGetNames(vm->snapshots, snap, names, nameslen, n = virDomainSnapshotObjListGetNames(vm->snapshots, snap, names, nameslen,
flags); flags);
@ -11429,7 +11446,6 @@ qemuDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return n; return n;
} }
@ -11437,7 +11453,6 @@ static int
qemuDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot, qemuDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = snapshot->domain->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
virDomainSnapshotObjPtr snap = NULL; virDomainSnapshotObjPtr snap = NULL;
int n = -1; int n = -1;
@ -11445,30 +11460,17 @@ qemuDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot,
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromSnapshot(snapshot)))
vm = virDomainFindByUUID(&driver->domains, snapshot->domain->uuid);
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(snapshot->domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
snap = virDomainSnapshotFindByName(vm->snapshots, snapshot->name); if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
if (!snap) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("no domain snapshot with matching name '%s'"),
snapshot->name);
goto cleanup; goto cleanup;
}
n = virDomainSnapshotObjListNum(vm->snapshots, snap, flags); n = virDomainSnapshotObjListNum(vm->snapshots, snap, flags);
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return n; return n;
} }
@ -11477,7 +11479,6 @@ qemuDomainSnapshotListAllChildren(virDomainSnapshotPtr snapshot,
virDomainSnapshotPtr **snaps, virDomainSnapshotPtr **snaps,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = snapshot->domain->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
virDomainSnapshotObjPtr snap = NULL; virDomainSnapshotObjPtr snap = NULL;
int n = -1; int n = -1;
@ -11485,23 +11486,11 @@ qemuDomainSnapshotListAllChildren(virDomainSnapshotPtr snapshot,
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromSnapshot(snapshot)))
vm = virDomainFindByUUID(&driver->domains, snapshot->domain->uuid);
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(snapshot->domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
snap = virDomainSnapshotFindByName(vm->snapshots, snapshot->name); if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
if (!snap) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("no domain snapshot with matching name '%s'"),
snapshot->name);
goto cleanup; goto cleanup;
}
n = virDomainListSnapshots(vm->snapshots, snap, snapshot->domain, snaps, n = virDomainListSnapshots(vm->snapshots, snap, snapshot->domain, snaps,
flags); flags);
@ -11509,7 +11498,6 @@ qemuDomainSnapshotListAllChildren(virDomainSnapshotPtr snapshot,
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return n; return n;
} }
@ -11517,64 +11505,42 @@ static virDomainSnapshotPtr qemuDomainSnapshotLookupByName(virDomainPtr domain,
const char *name, const char *name,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = domain->conn->privateData;
virDomainObjPtr vm; virDomainObjPtr vm;
virDomainSnapshotObjPtr snap = NULL; virDomainSnapshotObjPtr snap = NULL;
virDomainSnapshotPtr snapshot = NULL; virDomainSnapshotPtr snapshot = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromDomain(domain)))
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
snap = virDomainSnapshotFindByName(vm->snapshots, name); if (!(snap = qemuSnapObjFromName(vm, name)))
if (!snap) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("no snapshot with matching name '%s'"), name);
goto cleanup; goto cleanup;
}
snapshot = virGetDomainSnapshot(domain, snap->def->name); snapshot = virGetDomainSnapshot(domain, snap->def->name);
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return snapshot; return snapshot;
} }
static int qemuDomainHasCurrentSnapshot(virDomainPtr domain, static int qemuDomainHasCurrentSnapshot(virDomainPtr domain,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = domain->conn->privateData;
virDomainObjPtr vm; virDomainObjPtr vm;
int ret = -1; int ret = -1;
virCheckFlags(0, -1); virCheckFlags(0, -1);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromDomain(domain)))
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
ret = (vm->current_snapshot != NULL); ret = (vm->current_snapshot != NULL);
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return ret; return ret;
} }
@ -11582,30 +11548,17 @@ static virDomainSnapshotPtr
qemuDomainSnapshotGetParent(virDomainSnapshotPtr snapshot, qemuDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = snapshot->domain->conn->privateData;
virDomainObjPtr vm; virDomainObjPtr vm;
virDomainSnapshotObjPtr snap = NULL; virDomainSnapshotObjPtr snap = NULL;
virDomainSnapshotPtr parent = NULL; virDomainSnapshotPtr parent = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromSnapshot(snapshot)))
vm = virDomainFindByUUID(&driver->domains, snapshot->domain->uuid);
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(snapshot->domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
snap = virDomainSnapshotFindByName(vm->snapshots, snapshot->name); if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
if (!snap) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("no domain snapshot with matching name '%s'"),
snapshot->name);
goto cleanup; goto cleanup;
}
if (!snap->def->parent) { if (!snap->def->parent) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT, virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
@ -11619,28 +11572,19 @@ qemuDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return parent; return parent;
} }
static virDomainSnapshotPtr qemuDomainSnapshotCurrent(virDomainPtr domain, static virDomainSnapshotPtr qemuDomainSnapshotCurrent(virDomainPtr domain,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = domain->conn->privateData;
virDomainObjPtr vm; virDomainObjPtr vm;
virDomainSnapshotPtr snapshot = NULL; virDomainSnapshotPtr snapshot = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromDomain(domain)))
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
if (!vm->current_snapshot) { if (!vm->current_snapshot) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT, "%s", virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT, "%s",
@ -11653,14 +11597,12 @@ static virDomainSnapshotPtr qemuDomainSnapshotCurrent(virDomainPtr domain,
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return snapshot; return snapshot;
} }
static char *qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, static char *qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = snapshot->domain->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
char *xml = NULL; char *xml = NULL;
virDomainSnapshotObjPtr snap = NULL; virDomainSnapshotObjPtr snap = NULL;
@ -11668,29 +11610,19 @@ static char *qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL); virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromSnapshot(snapshot)))
virUUIDFormat(snapshot->domain->uuid, uuidstr);
vm = virDomainFindByUUID(&driver->domains, snapshot->domain->uuid);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
snap = virDomainSnapshotFindByName(vm->snapshots, snapshot->name); if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
if (!snap) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("no domain snapshot with matching name '%s'"),
snapshot->name);
goto cleanup; goto cleanup;
}
virUUIDFormat(snapshot->domain->uuid, uuidstr);
xml = virDomainSnapshotDefFormat(uuidstr, snap->def, flags, 0); xml = virDomainSnapshotDefFormat(uuidstr, snap->def, flags, 0);
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return xml; return xml;
} }
@ -11698,30 +11630,17 @@ static int
qemuDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot, qemuDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = snapshot->domain->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
int ret = -1; int ret = -1;
virDomainSnapshotObjPtr snap = NULL; virDomainSnapshotObjPtr snap = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virCheckFlags(0, -1); virCheckFlags(0, -1);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromSnapshot(snapshot)))
virUUIDFormat(snapshot->domain->uuid, uuidstr);
vm = virDomainFindByUUID(&driver->domains, snapshot->domain->uuid);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
snap = virDomainSnapshotFindByName(vm->snapshots, snapshot->name); if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
if (!snap) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("no domain snapshot with matching name '%s'"),
snapshot->name);
goto cleanup; goto cleanup;
}
ret = (vm->current_snapshot && ret = (vm->current_snapshot &&
STREQ(snapshot->name, vm->current_snapshot->def->name)); STREQ(snapshot->name, vm->current_snapshot->def->name));
@ -11729,7 +11648,6 @@ qemuDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return ret; return ret;
} }
@ -11738,30 +11656,17 @@ static int
qemuDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot, qemuDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = snapshot->domain->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
int ret = -1; int ret = -1;
virDomainSnapshotObjPtr snap = NULL; virDomainSnapshotObjPtr snap = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virCheckFlags(0, -1); virCheckFlags(0, -1);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromSnapshot(snapshot)))
virUUIDFormat(snapshot->domain->uuid, uuidstr);
vm = virDomainFindByUUID(&driver->domains, snapshot->domain->uuid);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
snap = virDomainSnapshotFindByName(vm->snapshots, snapshot->name); if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
if (!snap) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("no domain snapshot with matching name '%s'"),
snapshot->name);
goto cleanup; goto cleanup;
}
/* XXX Someday, we should recognize internal snapshots in qcow2 /* XXX Someday, we should recognize internal snapshots in qcow2
* images that are not tied to a libvirt snapshot; if we ever do * images that are not tied to a libvirt snapshot; if we ever do
@ -11771,7 +11676,6 @@ qemuDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return ret; return ret;
} }
@ -12439,9 +12343,7 @@ qemuDomainOpenConsole(virDomainPtr dom,
virStreamPtr st, virStreamPtr st,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = dom->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
int ret = -1; int ret = -1;
int i; int i;
virDomainChrDefPtr chr = NULL; virDomainChrDefPtr chr = NULL;
@ -12450,15 +12352,8 @@ qemuDomainOpenConsole(virDomainPtr dom,
virCheckFlags(VIR_DOMAIN_CONSOLE_SAFE | virCheckFlags(VIR_DOMAIN_CONSOLE_SAFE |
VIR_DOMAIN_CONSOLE_FORCE, -1); VIR_DOMAIN_CONSOLE_FORCE, -1);
qemuDriverLock(driver); if (!(vm = qemuDomObjFromDomain(dom)))
virUUIDFormat(dom->uuid, uuidstr);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
if (!virDomainObjIsActive(vm)) { if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,