/** * virCapabilitiesFree: * @caps: object to free * * Free all memory associated with capabilities */ void virCapabilitiesFree(virCapsPtr caps) { int i; if (caps == NULL) return; for (i = 0 ; i < caps->nguests ; i++) virCapabilitiesFreeGuest(caps->guests[i]); VIR_FREE(caps->guests); for (i = 0 ; i < caps->host.nfeatures ; i++) VIR_FREE(caps->host.features[i]); VIR_FREE(caps->host.features); virCapabilitiesFreeNUMAInfo(caps); for (i = 0 ; i < caps->host.nmigrateTrans ; i++) VIR_FREE(caps->host.migrateTrans[i]); VIR_FREE(caps->host.migrateTrans); VIR_FREE(caps->host.arch); VIR_FREE(caps->host.secModel.model); VIR_FREE(caps->host.secModel.doi); virCPUDefFree(caps->host.cpu); VIR_FREE(caps); }
static void virCapabilitiesDispose(void *object) { virCapsPtr caps = object; size_t i; for (i = 0; i < caps->nguests; i++) virCapabilitiesFreeGuest(caps->guests[i]); VIR_FREE(caps->guests); for (i = 0; i < caps->host.nfeatures; i++) VIR_FREE(caps->host.features[i]); VIR_FREE(caps->host.features); virCapabilitiesFreeNUMAInfo(caps); for (i = 0; i < caps->host.nmigrateTrans; i++) VIR_FREE(caps->host.migrateTrans[i]); VIR_FREE(caps->host.migrateTrans); for (i = 0; i < caps->host.nsecModels; i++) { virCapabilitiesClearSecModel(&caps->host.secModels[i]); } VIR_FREE(caps->host.secModels); virCPUDefFree(caps->host.cpu); }
/** * virCapabilitiesAddGuest: * @caps: capabilities to extend * @ostype: guest operating system type ('hvm' or 'xen') * @arch: guest CPU architecture ('i686', or 'x86_64', etc) * @wordsize: number of bits in CPU word * @emulator: path to default device emulator for arch/ostype * @loader: path to default BIOS loader for arch/ostype * @nmachines: number of machine variants for emulator * @machines: machine variants for emulator ('pc', or 'isapc', etc) * * Registers a new guest operating system. This should be * followed by registration of at least one domain for * running the guest */ virCapsGuestPtr virCapabilitiesAddGuest(virCapsPtr caps, const char *ostype, const char *arch, int wordsize, const char *emulator, const char *loader, int nmachines, virCapsGuestMachinePtr *machines) { virCapsGuestPtr guest; if (VIR_ALLOC(guest) < 0) goto no_memory; if ((guest->ostype = strdup(ostype)) == NULL) goto no_memory; if ((guest->arch.name = strdup(arch)) == NULL) goto no_memory; guest->arch.wordsize = wordsize; if (emulator && (guest->arch.defaultInfo.emulator = strdup(emulator)) == NULL) goto no_memory; if (loader && (guest->arch.defaultInfo.loader = strdup(loader)) == NULL) goto no_memory; if (VIR_RESIZE_N(caps->guests, caps->nguests_max, caps->nguests, 1) < 0) goto no_memory; caps->guests[caps->nguests++] = guest; if (nmachines) { guest->arch.defaultInfo.nmachines = nmachines; guest->arch.defaultInfo.machines = machines; } return guest; no_memory: virCapabilitiesFreeGuest(guest); return NULL; }
/** * virCapabilitiesAddGuest: * @caps: capabilities to extend * @ostype: guest operating system type ('hvm' or 'xen') * @arch: guest CPU architecture * @wordsize: number of bits in CPU word * @emulator: path to default device emulator for arch/ostype * @loader: path to default BIOS loader for arch/ostype * @nmachines: number of machine variants for emulator * @machines: machine variants for emulator ('pc', or 'isapc', etc) * * Registers a new guest operating system. This should be * followed by registration of at least one domain for * running the guest */ virCapsGuestPtr virCapabilitiesAddGuest(virCapsPtr caps, const char *ostype, virArch arch, const char *emulator, const char *loader, int nmachines, virCapsGuestMachinePtr *machines) { virCapsGuestPtr guest; if (VIR_ALLOC(guest) < 0) goto error; if (VIR_STRDUP(guest->ostype, ostype) < 0) goto error; guest->arch.id = arch; guest->arch.wordsize = virArchGetWordSize(arch); if (VIR_STRDUP(guest->arch.defaultInfo.emulator, emulator) < 0 || VIR_STRDUP(guest->arch.defaultInfo.loader, loader) < 0) goto error; if (VIR_RESIZE_N(caps->guests, caps->nguests_max, caps->nguests, 1) < 0) goto error; caps->guests[caps->nguests++] = guest; if (nmachines) { guest->arch.defaultInfo.nmachines = nmachines; guest->arch.defaultInfo.machines = machines; } return guest; error: virCapabilitiesFreeGuest(guest); return NULL; }