Pass virQEMUDriverPtr into APIs managed shared disk list

Currently the APIs for managing the shared disk list take
a virHashTablePtr as the primary argument. This is bad
because it requires the caller to deal with locking of
the QEMU driver. Switch the APIs to take the full
virQEMUDriverPtr instance

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2013-02-06 14:18:34 +00:00
parent 48b49a631a
commit 8cdd5faf46
5 changed files with 35 additions and 38 deletions

View File

@ -825,65 +825,62 @@ qemuGetSharedDiskKey(const char *disk_path)
* add a new entry.
*/
int
qemuAddSharedDisk(virHashTablePtr sharedDisks,
qemuAddSharedDisk(virQEMUDriverPtr driver,
const char *disk_path)
{
size_t *ref = NULL;
char *key = NULL;
int ret = -1;
if (!(key = qemuGetSharedDiskKey(disk_path)))
return -1;
goto cleanup;
if ((ref = virHashLookup(sharedDisks, key))) {
if (virHashUpdateEntry(sharedDisks, key, ++ref) < 0) {
VIR_FREE(key);
return -1;
}
if ((ref = virHashLookup(driver->sharedDisks, key))) {
if (virHashUpdateEntry(driver->sharedDisks, key, ++ref) < 0)
goto cleanup;
} else {
if (virHashAddEntry(sharedDisks, key, (void *)0x1)) {
VIR_FREE(key);
return -1;
}
if (virHashAddEntry(driver->sharedDisks, key, (void *)0x1))
goto cleanup;
}
ret = 0;
cleanup:
VIR_FREE(key);
return 0;
return ret;
}
/* Decrease the ref count if the entry already exists, otherwise
* remove the entry.
*/
int
qemuRemoveSharedDisk(virHashTablePtr sharedDisks,
qemuRemoveSharedDisk(virQEMUDriverPtr driver,
const char *disk_path)
{
size_t *ref = NULL;
char *key = NULL;
int ret = -1;
if (!(key = qemuGetSharedDiskKey(disk_path)))
return -1;
goto cleanup;
if (!(ref = virHashLookup(sharedDisks, key))) {
VIR_FREE(key);
return -1;
}
if (!(ref = virHashLookup(driver->sharedDisks, key)))
goto cleanup;
if (ref != (void *)0x1) {
if (virHashUpdateEntry(sharedDisks, key, --ref) < 0) {
VIR_FREE(key);
return -1;
}
if (virHashUpdateEntry(driver->sharedDisks, key, --ref) < 0)
goto cleanup;
} else {
if (virHashRemoveEntry(sharedDisks, key) < 0) {
VIR_FREE(key);
return -1;
}
if (virHashRemoveEntry(driver->sharedDisks, key) < 0)
goto cleanup;
}
ret = 0;
cleanup:
VIR_FREE(key);
return 0;
return ret;
}
int qemuDriverAllocateID(virQEMUDriverPtr driver)
{
return virAtomicIntInc(&driver->nextvmid);

View File

@ -275,11 +275,11 @@ qemuDriverCloseCallback qemuDriverCloseCallbackGet(virQEMUDriverPtr driver,
void qemuDriverCloseCallbackRunAll(virQEMUDriverPtr driver,
virConnectPtr conn);
int qemuAddSharedDisk(virHashTablePtr sharedDisks,
int qemuAddSharedDisk(virQEMUDriverPtr driver,
const char *disk_path)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int qemuRemoveSharedDisk(virHashTablePtr sharedDisks,
int qemuRemoveSharedDisk(virQEMUDriverPtr driver,
const char *disk_path)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
char * qemuGetSharedDiskKey(const char *disk_path)

View File

@ -5827,7 +5827,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK &&
disk->shared &&
(qemuCheckSharedDisk(driver->sharedDisks, disk) < 0))
(qemuCheckSharedDisk(driver, disk) < 0))
goto end;
if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
@ -5883,7 +5883,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
if (ret == 0) {
if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK && disk->shared) {
if (qemuAddSharedDisk(driver->sharedDisks, disk->src) < 0)
if (qemuAddSharedDisk(driver, disk->src) < 0)
VIR_WARN("Failed to add disk '%s' to shared disk table",
disk->src);
}
@ -6010,7 +6010,7 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver,
if (ret == 0 &&
disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK &&
disk->shared) {
if (qemuRemoveSharedDisk(driver->sharedDisks, disk->src) < 0)
if (qemuRemoveSharedDisk(driver, disk->src) < 0)
VIR_WARN("Failed to remove disk '%s' from shared disk table",
disk->src);
}

View File

@ -3557,7 +3557,7 @@ qemuSetUnprivSGIO(virDomainDiskDefPtr disk)
* Returns 0 if no conflicts, otherwise returns -1.
*/
int
qemuCheckSharedDisk(virHashTablePtr sharedDisks,
qemuCheckSharedDisk(virQEMUDriverPtr driver,
virDomainDiskDefPtr disk)
{
int val;
@ -3571,7 +3571,7 @@ qemuCheckSharedDisk(virHashTablePtr sharedDisks,
/* It can't be conflict if no other domain is
* is sharing it.
*/
if (!(ref = virHashLookup(sharedDisks, key)))
if (!(ref = virHashLookup(driver->sharedDisks, key)))
goto cleanup;
if (ref == (void *)0x1)
@ -3953,10 +3953,10 @@ int qemuProcessStart(virConnectPtr conn,
#endif
if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK && disk->shared) {
if (qemuAddSharedDisk(driver->sharedDisks, disk->src) < 0)
if (qemuAddSharedDisk(driver, disk->src) < 0)
goto cleanup;
if (qemuCheckSharedDisk(driver->sharedDisks, disk) < 0)
if (qemuCheckSharedDisk(driver, disk) < 0)
goto cleanup;
}
@ -4368,7 +4368,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
virDomainDiskDefPtr disk = vm->def->disks[i];
if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK && disk->shared) {
ignore_value(qemuRemoveSharedDisk(driver->sharedDisks, disk->src));
ignore_value(qemuRemoveSharedDisk(driver, disk->src));
}
}

View File

@ -100,7 +100,7 @@ virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver,
virBitmapPtr nodemask);
int qemuSetUnprivSGIO(virDomainDiskDefPtr disk);
int qemuCheckSharedDisk(virHashTablePtr sharedDisks,
int qemuCheckSharedDisk(virQEMUDriverPtr driver,
virDomainDiskDefPtr disk);
#endif /* __QEMU_PROCESS_H__ */