static void virDomainObjListDispose(void *obj) { virDomainObjListPtr doms = obj; virHashFree(doms->objs); virHashFree(doms->objsName); }
void virStoragePoolObjListDispose(void *opaque) { virStoragePoolObjListPtr pools = opaque; virHashFree(pools->objs); virHashFree(pools->objsName); }
static void virSecretObjListDispose(void *obj) { virSecretObjListPtr secrets = obj; virHashFree(secrets->objs); }
static void virCloseCallbacksDispose(void *obj) { virCloseCallbacksPtr closeCallbacks = obj; virHashFree(closeCallbacks->list); }
void virDomainCCWAddressSetFree(virDomainCCWAddressSetPtr addrs) { if (!addrs) return; virHashFree(addrs->defined); VIR_FREE(addrs); }
static int qemuMigrationCookieAddNBD(qemuMigrationCookiePtr mig, virQEMUDriverPtr driver, virDomainObjPtr vm) { qemuDomainObjPrivatePtr priv = vm->privateData; virHashTablePtr stats = NULL; size_t i; int ret = -1, rc; /* It is not a bug if there already is a NBD data */ qemuMigrationCookieNBDFree(mig->nbd); if (VIR_ALLOC(mig->nbd) < 0) return -1; if (vm->def->ndisks && VIR_ALLOC_N(mig->nbd->disks, vm->def->ndisks) < 0) return -1; mig->nbd->ndisks = 0; for (i = 0; i < vm->def->ndisks; i++) { virDomainDiskDefPtr disk = vm->def->disks[i]; qemuBlockStats *entry; if (!stats) { if (!(stats = virHashCreate(10, virHashValueFree))) goto cleanup; if (qemuDomainObjEnterMonitorAsync(driver, vm, priv->job.asyncJob) < 0) goto cleanup; rc = qemuMonitorBlockStatsUpdateCapacity(priv->mon, stats, false); if (qemuDomainObjExitMonitor(driver, vm) < 0) goto cleanup; if (rc < 0) goto cleanup; } if (!disk->info.alias || !(entry = virHashLookup(stats, disk->info.alias))) continue; if (VIR_STRDUP(mig->nbd->disks[mig->nbd->ndisks].target, disk->dst) < 0) goto cleanup; mig->nbd->disks[mig->nbd->ndisks].capacity = entry->capacity; mig->nbd->ndisks++; } mig->nbd->port = priv->nbdPort; mig->flags |= QEMU_MIGRATION_COOKIE_NBD; ret = 0; cleanup: virHashFree(stats); return ret; }
static virCPUCompareResult genericCompare(virCPUDefPtr host, virCPUDefPtr cpu, bool failIncompatible) { virHashTablePtr hash = NULL; virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR; size_t i; unsigned int reqfeatures; if ((cpu->arch != VIR_ARCH_NONE && host->arch != cpu->arch) || STRNEQ(host->model, cpu->model)) { ret = VIR_CPU_COMPARE_INCOMPATIBLE; goto cleanup; } if ((hash = genericHashFeatures(host)) == NULL) goto cleanup; reqfeatures = 0; for (i = 0; i < cpu->nfeatures; i++) { void *hval = virHashLookup(hash, cpu->features[i].name); if (hval) { if (cpu->type == VIR_CPU_TYPE_GUEST && cpu->features[i].policy == VIR_CPU_FEATURE_FORBID) { ret = VIR_CPU_COMPARE_INCOMPATIBLE; goto cleanup; } reqfeatures++; } else if (cpu->type == VIR_CPU_TYPE_HOST || cpu->features[i].policy == VIR_CPU_FEATURE_REQUIRE) { ret = VIR_CPU_COMPARE_INCOMPATIBLE; goto cleanup; } } if (host->nfeatures > reqfeatures) { if (cpu->type == VIR_CPU_TYPE_GUEST && cpu->match == VIR_CPU_MATCH_STRICT) ret = VIR_CPU_COMPARE_INCOMPATIBLE; else ret = VIR_CPU_COMPARE_SUPERSET; } else { ret = VIR_CPU_COMPARE_IDENTICAL; } cleanup: virHashFree(hash); if (failIncompatible && ret == VIR_CPU_COMPARE_INCOMPATIBLE) { ret = VIR_CPU_COMPARE_ERROR; virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL); } return ret; }
static virHashTablePtr testHashInit(int size) { virHashTablePtr hash; ssize_t i; if (!(hash = virHashCreate(size, NULL))) return NULL; /* entires are added in reverse order so that they will be linked in * collision list in the same order as in the uuids array */ for (i = ARRAY_CARDINALITY(uuids) - 1; i >= 0; i--) { ssize_t oldsize = virHashTableSize(hash); if (virHashAddEntry(hash, uuids[i], (void *) uuids[i]) < 0) { virHashFree(hash); return NULL; } if (virHashTableSize(hash) != oldsize && virTestGetDebug()) { VIR_WARN("hash grown from %zd to %zd", (size_t)oldsize, (size_t)virHashTableSize(hash)); } } for (i = 0; i < ARRAY_CARDINALITY(uuids); i++) { if (!virHashLookup(hash, uuids[i])) { if (virTestGetVerbose()) { VIR_WARN("\nentry \"%s\" could not be found\n", uuids[i]); } virHashFree(hash); return NULL; } } if (size && size != virHashTableSize(hash) && virTestGetDebug()) fprintf(stderr, "\n"); return hash; }
static virCPUCompareResult genericCompare(virCPUDefPtr host, virCPUDefPtr cpu) { virHashTablePtr hash; virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR; unsigned int i; unsigned int reqfeatures; if ((cpu->arch && STRNEQ(host->arch, cpu->arch)) || STRNEQ(host->model, cpu->model)) return VIR_CPU_COMPARE_INCOMPATIBLE; if ((hash = genericHashFeatures(host)) == NULL) { virReportOOMError(); goto cleanup; } reqfeatures = 0; for (i = 0; i < cpu->nfeatures; i++) { void *hval = virHashLookup(hash, cpu->features[i].name); if (hval) { if (cpu->type == VIR_CPU_TYPE_GUEST && cpu->features[i].policy == VIR_CPU_FEATURE_FORBID) { ret = VIR_CPU_COMPARE_INCOMPATIBLE; goto cleanup; } reqfeatures++; } else { if (cpu->type == VIR_CPU_TYPE_HOST || cpu->features[i].policy == VIR_CPU_FEATURE_REQUIRE) { ret = VIR_CPU_COMPARE_INCOMPATIBLE; goto cleanup; } } } if (host->nfeatures > reqfeatures) { if (cpu->type == VIR_CPU_TYPE_GUEST && cpu->match == VIR_CPU_MATCH_STRICT) ret = VIR_CPU_COMPARE_INCOMPATIBLE; else ret = VIR_CPU_COMPARE_SUPERSET; } else ret = VIR_CPU_COMPARE_IDENTICAL; cleanup: virHashFree(hash); return ret; }
static void virLockDaemonFree(virLockDaemonPtr lockd) { if (!lockd) return; virObjectUnref(lockd->srv); virHashFree(lockd->lockspaces); virLockSpaceFree(lockd->defaultLockspace); VIR_FREE(lockd); }
static int testHashGrow(const void *data) { const struct testInfo *info = data; virHashTablePtr hash; int ret = -1; if (!(hash = testHashInit(info->count))) return -1; if (testHashCheckCount(hash, ARRAY_CARDINALITY(uuids)) < 0) goto cleanup; ret = 0; cleanup: virHashFree(hash); return ret; }
static virHashTablePtr genericHashFeatures(virCPUDefPtr cpu) { virHashTablePtr hash; size_t i; if ((hash = virHashCreate(cpu->nfeatures, NULL)) == NULL) return NULL; for (i = 0; i < cpu->nfeatures; i++) { if (virHashAddEntry(hash, cpu->features[i].name, cpu->features + i)) { virHashFree(hash); return NULL; } } return hash; }
static virCPUDefPtr genericBaseline(virCPUDefPtr *cpus, unsigned int ncpus, const char **models, unsigned int nmodels, unsigned int flags) { virCPUDefPtr cpu = NULL; virCPUFeatureDefPtr features = NULL; unsigned int nfeatures; unsigned int count; size_t i, j; virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES | VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL); if (!cpuModelIsAllowed(cpus[0]->model, models, nmodels)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("CPU model %s is not supported by hypervisor"), cpus[0]->model); goto error; } if (VIR_ALLOC(cpu) < 0 || VIR_STRDUP(cpu->model, cpus[0]->model) < 0 || VIR_ALLOC_N(features, cpus[0]->nfeatures) < 0) goto error; cpu->arch = cpus[0]->arch; cpu->type = VIR_CPU_TYPE_HOST; count = nfeatures = cpus[0]->nfeatures; for (i = 0; i < nfeatures; i++) features[i].name = cpus[0]->features[i].name; for (i = 1; i < ncpus; i++) { virHashTablePtr hash; if (cpu->arch != cpus[i]->arch) { virReportError(VIR_ERR_INTERNAL_ERROR, _("CPUs have incompatible architectures: '%s' != '%s'"), virArchToString(cpu->arch), virArchToString(cpus[i]->arch)); goto error; } if (STRNEQ(cpu->model, cpus[i]->model)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("CPU models don't match: '%s' != '%s'"), cpu->model, cpus[i]->model); goto error; } if (!(hash = genericHashFeatures(cpus[i]))) goto error; for (j = 0; j < nfeatures; j++) { if (features[j].name && !virHashLookup(hash, features[j].name)) { features[j].name = NULL; count--; } } virHashFree(hash); } if (VIR_ALLOC_N(cpu->features, count) < 0) goto error; cpu->nfeatures = count; j = 0; for (i = 0; i < nfeatures; i++) { if (!features[i].name) continue; if (VIR_STRDUP(cpu->features[j++].name, features[i].name) < 0) goto error; } cleanup: VIR_FREE(features); return cpu; error: virCPUDefFree(cpu); cpu = NULL; goto cleanup; }
static int mymain(void) { int ret = 0; virQEMUDriver driver; struct testBackingXMLjsonXMLdata xmljsonxmldata; struct testQemuDiskXMLToJSONData diskxmljsondata; char *capslatest_x86_64 = NULL; virQEMUCapsPtr caps_x86_64 = NULL; if (qemuTestDriverInit(&driver) < 0) return EXIT_FAILURE; diskxmljsondata.driver = &driver; if (!(capslatest_x86_64 = testQemuGetLatestCapsForArch("x86_64", "xml"))) return EXIT_FAILURE; VIR_TEST_VERBOSE("\nlatest caps x86_64: %s\n", capslatest_x86_64); if (!(caps_x86_64 = qemuTestParseCapabilitiesArch(virArchFromString("x86_64"), capslatest_x86_64))) return EXIT_FAILURE; diskxmljsondata.qemuCaps = caps_x86_64; virTestCounterReset("qemu storage source xml->json->xml "); # define TEST_JSON_FORMAT(tpe, xmlstr) \ do { \ xmljsonxmldata.type = tpe; \ xmljsonxmldata.xml = xmlstr; \ if (virTestRun(virTestCounterNext(), testBackingXMLjsonXML, \ &xmljsonxmldata) < 0) \ ret = -1; \ } while (0) # define TEST_JSON_FORMAT_NET(xmlstr) \ TEST_JSON_FORMAT(VIR_STORAGE_TYPE_NETWORK, xmlstr) TEST_JSON_FORMAT(VIR_STORAGE_TYPE_FILE, "<source file='/path/to/file'/>\n"); /* type VIR_STORAGE_TYPE_BLOCK is not tested since it parses back to 'file' */ /* type VIR_STORAGE_TYPE_DIR it is a 'format' driver in qemu */ TEST_JSON_FORMAT_NET("<source protocol='http' name=''>\n" " <host name='example.com' port='80'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='http' name='file'>\n" " <host name='example.com' port='80'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='https' name='file'>\n" " <host name='example.com' port='432'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='gluster' name='vol/file'>\n" " <host name='example.com' port='24007'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='gluster' name='testvol/img.qcow2'>\n" " <host name='example.com' port='1234'/>\n" " <host transport='unix' socket='/path/socket'/>\n" " <host name='example.com' port='24007'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='nbd'>\n" " <host transport='unix' socket='/path/to/socket'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='nbd' name='blah'>\n" " <host name='example.org' port='6000'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='nbd'>\n" " <host name='example.org' port='6000'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='ssh' name='blah'>\n" " <host name='example.org' port='6000'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='rbd' name='libvirt/test'>\n" " <host name='example.com' port='1234'/>\n" " <host name='example2.com'/>\n" " <snapshot name='snapshotname'/>\n" " <config file='/path/to/conf'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/0'>\n" " <host name='test.org' port='3260'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n" " <host name='test.org' port='1234'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='sheepdog' name='test'>\n" " <host name='example.com' port='321'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='vxhs' name='c6718f6b-0401-441d-a8c3-1f0064d75ee0'>\n" " <host name='example.com' port='9999'/>\n" "</source>\n"); # define TEST_DISK_TO_JSON_FULL(nme, fl) \ do { \ diskxmljsondata.name = nme; \ diskxmljsondata.props = NULL; \ diskxmljsondata.nprops = 0; \ diskxmljsondata.fail = fl; \ if (virTestRun("disk xml to props " nme, testQemuDiskXMLToProps, \ &diskxmljsondata) < 0) \ ret = -1; \ if (virTestRun("disk xml to props validate schema " nme, \ testQemuDiskXMLToPropsValidateSchema, &diskxmljsondata) < 0) \ ret = -1; \ if (virTestRun("disk xml to props validate file " nme, \ testQemuDiskXMLToPropsValidateFile, &diskxmljsondata) < 0) \ ret = -1; \ testQemuDiskXMLToPropsClear(&diskxmljsondata); \ } while (0) # define TEST_DISK_TO_JSON(nme) TEST_DISK_TO_JSON_FULL(nme, false) if (!(diskxmljsondata.schema = testQEMUSchemaLoad())) { ret = -1; goto cleanup; } if (virQEMUQAPISchemaPathGet("blockdev-add/arg-type", diskxmljsondata.schema, &diskxmljsondata.schemaroot) < 0 || !diskxmljsondata.schemaroot) { VIR_TEST_VERBOSE("failed to find schema entry for blockdev-add\n"); ret = -1; goto cleanup; } TEST_DISK_TO_JSON_FULL("nodename-long-format", true); TEST_DISK_TO_JSON_FULL("nodename-long-protocol", true); TEST_DISK_TO_JSON("file-raw-noopts"); TEST_DISK_TO_JSON("file-bochs-noopts"); TEST_DISK_TO_JSON("file-cloop-noopts"); TEST_DISK_TO_JSON("file-dmg-noopts"); TEST_DISK_TO_JSON("file-ploop-noopts"); TEST_DISK_TO_JSON("file-vdi-noopts"); TEST_DISK_TO_JSON("file-vhd-noopts"); TEST_DISK_TO_JSON("file-vpc-noopts"); TEST_DISK_TO_JSON("file-backing_basic-noopts"); TEST_DISK_TO_JSON("dir-fat-readonly"); TEST_DISK_TO_JSON("dir-fat-floppy"); TEST_DISK_TO_JSON("file-raw-aio_native"); TEST_DISK_TO_JSON("file-backing_basic-aio_threads"); TEST_DISK_TO_JSON("file-raw-luks"); TEST_DISK_TO_JSON("file-qcow2-backing-chain-noopts"); TEST_DISK_TO_JSON("file-qcow2-backing-chain-unterminated"); TEST_DISK_TO_JSON("file-qcow2-backing-chain-encryption"); TEST_DISK_TO_JSON("network-qcow2-backing-chain-encryption_auth"); TEST_DISK_TO_JSON("file-backing_basic-unmap"); TEST_DISK_TO_JSON("file-backing_basic-unmap-detect"); TEST_DISK_TO_JSON("file-backing_basic-unmap-ignore"); TEST_DISK_TO_JSON("file-backing_basic-detect"); TEST_DISK_TO_JSON("file-backing_basic-cache-none"); TEST_DISK_TO_JSON("file-backing_basic-cache-writethrough"); TEST_DISK_TO_JSON("file-backing_basic-cache-writeback"); TEST_DISK_TO_JSON("file-backing_basic-cache-directsync"); TEST_DISK_TO_JSON("file-backing_basic-cache-unsafe"); TEST_DISK_TO_JSON("network-qcow2-backing-chain-cache-unsafe"); TEST_DISK_TO_JSON("dir-fat-cache"); TEST_DISK_TO_JSON("network-nbd-tls"); TEST_DISK_TO_JSON("block-raw-noopts"); TEST_DISK_TO_JSON("block-raw-reservations"); cleanup: virHashFree(diskxmljsondata.schema); qemuTestDriverFree(&driver); VIR_FREE(capslatest_x86_64); virObjectUnref(caps_x86_64); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; }
void virLXCProcessAutoDestroyShutdown(virLXCDriverPtr driver) { virHashFree(driver->autodestroy); }
static void virMacMapDispose(void *obj) { virMacMapPtr mgr = obj; virHashFree(mgr->macs); }
static virCPUDefPtr genericBaseline(virCPUDefPtr *cpus, unsigned int ncpus, const char **models, unsigned int nmodels) { virCPUDefPtr cpu = NULL; virCPUFeatureDefPtr features = NULL; unsigned int nfeatures; unsigned int count; unsigned int i, j; if (models) { bool found = false; for (i = 0; i < nmodels; i++) { if (STREQ(cpus[0]->model, models[i])) { found = true; break; } } if (!found) { virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("CPU model '%s' is not support by hypervisor"), cpus[0]->model); goto error; } } if (VIR_ALLOC(cpu) < 0 || !(cpu->arch = strdup(cpus[0]->arch)) || !(cpu->model = strdup(cpus[0]->model)) || VIR_ALLOC_N(features, cpus[0]->nfeatures) < 0) goto no_memory; cpu->type = VIR_CPU_TYPE_HOST; count = nfeatures = cpus[0]->nfeatures; for (i = 0; i < nfeatures; i++) features[i].name = cpus[0]->features[i].name; for (i = 1; i < ncpus; i++) { virHashTablePtr hash; if (STRNEQ(cpu->arch, cpus[i]->arch)) { virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("CPUs have incompatible architectures: '%s' != '%s'"), cpu->arch, cpus[i]->arch); goto error; } if (STRNEQ(cpu->model, cpus[i]->model)) { virCPUReportError(VIR_ERR_INTERNAL_ERROR, _("CPU models don't match: '%s' != '%s'"), cpu->model, cpus[i]->model); goto error; } if (!(hash = genericHashFeatures(cpus[i]))) goto no_memory; for (j = 0; j < nfeatures; j++) { if (features[j].name && !virHashLookup(hash, features[j].name)) { features[j].name = NULL; count--; } } virHashFree(hash); } if (VIR_ALLOC_N(cpu->features, count) < 0) goto no_memory; cpu->nfeatures = count; j = 0; for (i = 0; i < nfeatures; i++) { if (!features[i].name) continue; if (!(cpu->features[j++].name = strdup(features[i].name))) goto no_memory; } cleanup: VIR_FREE(features); return cpu; no_memory: virReportOOMError(); error: virCPUDefFree(cpu); cpu = NULL; goto cleanup; }