提交 539d0e19 编写于 作者: O Osier Yang

qemu: Rename qemu_driver->sharedDisks to qemu_driver->sharedDevices

"Shared disk" is not only the thing we should care about after "scsi
hostdev" is introduced. A same scsi device can be used as "disk" for
one domain, and as "scsi hostdev" for another domain at the same time.
That's why this patch renames qemu_driver->sharedDisks. Related functions
and structs are also renamed.
上级 f2c1d9a8
...@@ -947,23 +947,23 @@ virQEMUCloseCallbacksRun(virQEMUCloseCallbacksPtr closeCallbacks, ...@@ -947,23 +947,23 @@ virQEMUCloseCallbacksRun(virQEMUCloseCallbacksPtr closeCallbacks,
VIR_FREE(list); VIR_FREE(list);
} }
struct _qemuSharedDiskEntry { struct _qemuSharedDeviceEntry {
size_t ref; size_t ref;
char **domains; /* array of domain names */ char **domains; /* array of domain names */
}; };
/* Construct the hash key for sharedDisks as "major:minor" */ /* Construct the hash key for sharedDevices as "major:minor" */
char * char *
qemuGetSharedDiskKey(const char *disk_path) qemuGetSharedDeviceKey(const char *device_path)
{ {
int maj, min; int maj, min;
char *key = NULL; char *key = NULL;
int rc; int rc;
if ((rc = virGetDeviceID(disk_path, &maj, &min)) < 0) { if ((rc = virGetDeviceID(device_path, &maj, &min)) < 0) {
virReportSystemError(-rc, virReportSystemError(-rc,
_("Unable to get minor number of device '%s'"), _("Unable to get minor number of device '%s'"),
disk_path); device_path);
return NULL; return NULL;
} }
...@@ -983,7 +983,7 @@ qemuGetSharedDiskKey(const char *disk_path) ...@@ -983,7 +983,7 @@ qemuGetSharedDiskKey(const char *disk_path)
* Returns 0 if no conflicts, otherwise returns -1. * Returns 0 if no conflicts, otherwise returns -1.
*/ */
static int static int
qemuCheckSharedDisk(virHashTablePtr sharedDisks, qemuCheckSharedDisk(virHashTablePtr sharedDevices,
virDomainDiskDefPtr disk) virDomainDiskDefPtr disk)
{ {
char *sysfs_path = NULL; char *sysfs_path = NULL;
...@@ -1008,7 +1008,7 @@ qemuCheckSharedDisk(virHashTablePtr sharedDisks, ...@@ -1008,7 +1008,7 @@ qemuCheckSharedDisk(virHashTablePtr sharedDisks,
if (!virFileExists(sysfs_path)) if (!virFileExists(sysfs_path))
goto cleanup; goto cleanup;
if (!(key = qemuGetSharedDiskKey(disk->src))) { if (!(key = qemuGetSharedDeviceKey(disk->src))) {
ret = -1; ret = -1;
goto cleanup; goto cleanup;
} }
...@@ -1016,7 +1016,7 @@ qemuCheckSharedDisk(virHashTablePtr sharedDisks, ...@@ -1016,7 +1016,7 @@ qemuCheckSharedDisk(virHashTablePtr sharedDisks,
/* It can't be conflict if no other domain is /* It can't be conflict if no other domain is
* is sharing it. * is sharing it.
*/ */
if (!(virHashLookup(sharedDisks, key))) if (!(virHashLookup(sharedDevices, key)))
goto cleanup; goto cleanup;
if (virGetDeviceUnprivSGIO(disk->src, NULL, &val) < 0) { if (virGetDeviceUnprivSGIO(disk->src, NULL, &val) < 0) {
...@@ -1052,9 +1052,9 @@ cleanup: ...@@ -1052,9 +1052,9 @@ cleanup:
} }
bool bool
qemuSharedDiskEntryDomainExists(qemuSharedDiskEntryPtr entry, qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
const char *name, const char *name,
int *idx) int *idx)
{ {
size_t i; size_t i;
...@@ -1070,9 +1070,9 @@ qemuSharedDiskEntryDomainExists(qemuSharedDiskEntryPtr entry, ...@@ -1070,9 +1070,9 @@ qemuSharedDiskEntryDomainExists(qemuSharedDiskEntryPtr entry,
} }
void void
qemuSharedDiskEntryFree(void *payload, const void *name ATTRIBUTE_UNUSED) qemuSharedDeviceEntryFree(void *payload, const void *name ATTRIBUTE_UNUSED)
{ {
qemuSharedDiskEntryPtr entry = payload; qemuSharedDeviceEntryPtr entry = payload;
size_t i; size_t i;
if (!entry) if (!entry)
...@@ -1085,10 +1085,10 @@ qemuSharedDiskEntryFree(void *payload, const void *name ATTRIBUTE_UNUSED) ...@@ -1085,10 +1085,10 @@ qemuSharedDiskEntryFree(void *payload, const void *name ATTRIBUTE_UNUSED)
VIR_FREE(entry); VIR_FREE(entry);
} }
static qemuSharedDiskEntryPtr static qemuSharedDeviceEntryPtr
qemuSharedDiskEntryCopy(const qemuSharedDiskEntryPtr entry) qemuSharedDeviceEntryCopy(const qemuSharedDeviceEntryPtr entry)
{ {
qemuSharedDiskEntryPtr ret = NULL; qemuSharedDeviceEntryPtr ret = NULL;
size_t i; size_t i;
if (VIR_ALLOC(ret) < 0) { if (VIR_ALLOC(ret) < 0) {
...@@ -1112,7 +1112,7 @@ qemuSharedDiskEntryCopy(const qemuSharedDiskEntryPtr entry) ...@@ -1112,7 +1112,7 @@ qemuSharedDiskEntryCopy(const qemuSharedDiskEntryPtr entry)
return ret; return ret;
cleanup: cleanup:
qemuSharedDiskEntryFree(ret, NULL); qemuSharedDeviceEntryFree(ret, NULL);
return NULL; return NULL;
} }
...@@ -1130,8 +1130,8 @@ qemuAddSharedDisk(virQEMUDriverPtr driver, ...@@ -1130,8 +1130,8 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
virDomainDiskDefPtr disk, virDomainDiskDefPtr disk,
const char *name) const char *name)
{ {
qemuSharedDiskEntry *entry = NULL; qemuSharedDeviceEntry *entry = NULL;
qemuSharedDiskEntry *new_entry = NULL; qemuSharedDeviceEntry *new_entry = NULL;
char *key = NULL; char *key = NULL;
int ret = -1; int ret = -1;
...@@ -1148,47 +1148,47 @@ qemuAddSharedDisk(virQEMUDriverPtr driver, ...@@ -1148,47 +1148,47 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
return 0; return 0;
qemuDriverLock(driver); qemuDriverLock(driver);
if (qemuCheckSharedDisk(driver->sharedDisks, disk) < 0) if (qemuCheckSharedDisk(driver->sharedDevices, disk) < 0)
goto cleanup; goto cleanup;
if (!(key = qemuGetSharedDiskKey(disk->src))) if (!(key = qemuGetSharedDeviceKey(disk->src)))
goto cleanup; goto cleanup;
if ((entry = virHashLookup(driver->sharedDisks, key))) { if ((entry = virHashLookup(driver->sharedDevices, key))) {
/* Nothing to do if the shared disk is already recorded /* Nothing to do if the shared disk is already recorded
* in the table. * in the table.
*/ */
if (qemuSharedDiskEntryDomainExists(entry, name, NULL)) { if (qemuSharedDeviceEntryDomainExists(entry, name, NULL)) {
ret = 0; ret = 0;
goto cleanup; goto cleanup;
} }
if (!(new_entry = qemuSharedDiskEntryCopy(entry))) if (!(new_entry = qemuSharedDeviceEntryCopy(entry)))
goto cleanup; goto cleanup;
if ((VIR_EXPAND_N(new_entry->domains, new_entry->ref, 1) < 0) || if ((VIR_EXPAND_N(new_entry->domains, new_entry->ref, 1) < 0) ||
!(new_entry->domains[new_entry->ref - 1] = strdup(name))) { !(new_entry->domains[new_entry->ref - 1] = strdup(name))) {
qemuSharedDiskEntryFree(new_entry, NULL); qemuSharedDeviceEntryFree(new_entry, NULL);
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
if (virHashUpdateEntry(driver->sharedDisks, key, new_entry) < 0) { if (virHashUpdateEntry(driver->sharedDevices, key, new_entry) < 0) {
qemuSharedDiskEntryFree(new_entry, NULL); qemuSharedDeviceEntryFree(new_entry, NULL);
goto cleanup; goto cleanup;
} }
} else { } else {
if ((VIR_ALLOC(entry) < 0) || if ((VIR_ALLOC(entry) < 0) ||
(VIR_ALLOC_N(entry->domains, 1) < 0) || (VIR_ALLOC_N(entry->domains, 1) < 0) ||
!(entry->domains[0] = strdup(name))) { !(entry->domains[0] = strdup(name))) {
qemuSharedDiskEntryFree(entry, NULL); qemuSharedDeviceEntryFree(entry, NULL);
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
entry->ref = 1; entry->ref = 1;
if (virHashAddEntry(driver->sharedDisks, key, entry)) if (virHashAddEntry(driver->sharedDevices, key, entry))
goto cleanup; goto cleanup;
} }
...@@ -1213,8 +1213,8 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver, ...@@ -1213,8 +1213,8 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver,
virDomainDiskDefPtr disk, virDomainDiskDefPtr disk,
const char *name) const char *name)
{ {
qemuSharedDiskEntryPtr entry = NULL; qemuSharedDeviceEntryPtr entry = NULL;
qemuSharedDiskEntryPtr new_entry = NULL; qemuSharedDeviceEntryPtr new_entry = NULL;
char *key = NULL; char *key = NULL;
int ret = -1; int ret = -1;
int idx; int idx;
...@@ -1228,22 +1228,22 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver, ...@@ -1228,22 +1228,22 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver,
return 0; return 0;
qemuDriverLock(driver); qemuDriverLock(driver);
if (!(key = qemuGetSharedDiskKey(disk->src))) if (!(key = qemuGetSharedDeviceKey(disk->src)))
goto cleanup; goto cleanup;
if (!(entry = virHashLookup(driver->sharedDisks, key))) if (!(entry = virHashLookup(driver->sharedDevices, key)))
goto cleanup; goto cleanup;
/* Nothing to do if the shared disk is not recored in /* Nothing to do if the shared disk is not recored in
* the table. * the table.
*/ */
if (!qemuSharedDiskEntryDomainExists(entry, name, &idx)) { if (!qemuSharedDeviceEntryDomainExists(entry, name, &idx)) {
ret = 0; ret = 0;
goto cleanup; goto cleanup;
} }
if (entry->ref != 1) { if (entry->ref != 1) {
if (!(new_entry = qemuSharedDiskEntryCopy(entry))) if (!(new_entry = qemuSharedDeviceEntryCopy(entry)))
goto cleanup; goto cleanup;
if (idx != new_entry->ref - 1) if (idx != new_entry->ref - 1)
...@@ -1253,12 +1253,12 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver, ...@@ -1253,12 +1253,12 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver,
VIR_SHRINK_N(new_entry->domains, new_entry->ref, 1); VIR_SHRINK_N(new_entry->domains, new_entry->ref, 1);
if (virHashUpdateEntry(driver->sharedDisks, key, new_entry) < 0){ if (virHashUpdateEntry(driver->sharedDevices, key, new_entry) < 0){
qemuSharedDiskEntryFree(new_entry, NULL); qemuSharedDeviceEntryFree(new_entry, NULL);
goto cleanup; goto cleanup;
} }
} else { } else {
if (virHashRemoveEntry(driver->sharedDisks, key) < 0) if (virHashRemoveEntry(driver->sharedDevices, key) < 0)
goto cleanup; goto cleanup;
} }
......
...@@ -210,7 +210,7 @@ struct _virQEMUDriver { ...@@ -210,7 +210,7 @@ struct _virQEMUDriver {
virSCSIDeviceListPtr activeScsiHostdevs; virSCSIDeviceListPtr activeScsiHostdevs;
/* Immutable pointer. Unsafe APIs. XXX */ /* Immutable pointer. Unsafe APIs. XXX */
virHashTablePtr sharedDisks; virHashTablePtr sharedDevices;
/* Immutable pointer, self-locking APIs */ /* Immutable pointer, self-locking APIs */
virPortAllocatorPtr remotePorts; virPortAllocatorPtr remotePorts;
...@@ -281,12 +281,12 @@ void virQEMUCloseCallbacksRun(virQEMUCloseCallbacksPtr closeCallbacks, ...@@ -281,12 +281,12 @@ void virQEMUCloseCallbacksRun(virQEMUCloseCallbacksPtr closeCallbacks,
virConnectPtr conn, virConnectPtr conn,
virQEMUDriverPtr driver); virQEMUDriverPtr driver);
typedef struct _qemuSharedDiskEntry qemuSharedDiskEntry; typedef struct _qemuSharedDeviceEntry qemuSharedDeviceEntry;
typedef qemuSharedDiskEntry *qemuSharedDiskEntryPtr; typedef qemuSharedDeviceEntry *qemuSharedDeviceEntryPtr;
bool qemuSharedDiskEntryDomainExists(qemuSharedDiskEntryPtr entry, bool qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
const char *name, const char *name,
int *index) int *index)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int qemuAddSharedDisk(virQEMUDriverPtr driver, int qemuAddSharedDisk(virQEMUDriverPtr driver,
...@@ -299,10 +299,10 @@ int qemuRemoveSharedDisk(virQEMUDriverPtr driver, ...@@ -299,10 +299,10 @@ int qemuRemoveSharedDisk(virQEMUDriverPtr driver,
const char *name) const char *name)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
char * qemuGetSharedDiskKey(const char *disk_path) char * qemuGetSharedDeviceKey(const char *disk_path)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
void qemuSharedDiskEntryFree(void *payload, const void *name) void qemuSharedDeviceEntryFree(void *payload, const void *name)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
int qemuDriverAllocateID(virQEMUDriverPtr driver); int qemuDriverAllocateID(virQEMUDriverPtr driver);
......
...@@ -683,7 +683,7 @@ qemuStateInitialize(bool privileged, ...@@ -683,7 +683,7 @@ qemuStateInitialize(bool privileged,
if ((qemu_driver->activeScsiHostdevs = virSCSIDeviceListNew()) == NULL) if ((qemu_driver->activeScsiHostdevs = virSCSIDeviceListNew()) == NULL)
goto error; goto error;
if (!(qemu_driver->sharedDisks = virHashCreate(30, qemuSharedDiskEntryFree))) if (!(qemu_driver->sharedDevices = virHashCreate(30, qemuSharedDeviceEntryFree)))
goto error; goto error;
if (privileged) { if (privileged) {
...@@ -954,7 +954,7 @@ qemuStateCleanup(void) { ...@@ -954,7 +954,7 @@ qemuStateCleanup(void) {
virObjectUnref(qemu_driver->activePciHostdevs); virObjectUnref(qemu_driver->activePciHostdevs);
virObjectUnref(qemu_driver->inactivePciHostdevs); virObjectUnref(qemu_driver->inactivePciHostdevs);
virObjectUnref(qemu_driver->activeUsbHostdevs); virObjectUnref(qemu_driver->activeUsbHostdevs);
virHashFree(qemu_driver->sharedDisks); virHashFree(qemu_driver->sharedDevices);
virObjectUnref(qemu_driver->caps); virObjectUnref(qemu_driver->caps);
virQEMUCapsCacheFree(qemu_driver->qemuCapsCache); virQEMUCapsCacheFree(qemu_driver->qemuCapsCache);
......
...@@ -2979,7 +2979,7 @@ qemuProcessReconnect(void *opaque) ...@@ -2979,7 +2979,7 @@ qemuProcessReconnect(void *opaque)
goto error; goto error;
/* XXX: Need to change as long as lock is introduced for /* XXX: Need to change as long as lock is introduced for
* qemu_driver->sharedDisks. * qemu_driver->sharedDevices.
*/ */
for (i = 0; i < obj->def->ndisks; i++) { for (i = 0; i < obj->def->ndisks; i++) {
if (qemuTranslateDiskSourcePool(conn, obj->def->disks[i]) < 0) if (qemuTranslateDiskSourcePool(conn, obj->def->disks[i]) < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册