mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
caps: Use an enum internally for ostype value
But the internal API stays the same, and we just convert the value as needed. Not useful yet, but this is the beginning step of using an enum for ostype throughout the code.
This commit is contained in:
parent
f1a89a8b6d
commit
4231485c1c
@ -32,6 +32,7 @@
|
||||
#include "cpu_conf.h"
|
||||
#include "virerror.h"
|
||||
#include "virstring.h"
|
||||
#include "domain_conf.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_CAPABILITIES
|
||||
|
||||
@ -155,8 +156,6 @@ virCapabilitiesFreeGuest(virCapsGuestPtr guest)
|
||||
if (guest == NULL)
|
||||
return;
|
||||
|
||||
VIR_FREE(guest->ostype);
|
||||
|
||||
VIR_FREE(guest->arch.defaultInfo.emulator);
|
||||
VIR_FREE(guest->arch.defaultInfo.loader);
|
||||
for (i = 0; i < guest->arch.defaultInfo.nmachines; i++)
|
||||
@ -408,7 +407,7 @@ virCapabilitiesFreeMachines(virCapsGuestMachinePtr *machines,
|
||||
*/
|
||||
virCapsGuestPtr
|
||||
virCapabilitiesAddGuest(virCapsPtr caps,
|
||||
const char *ostype,
|
||||
const char *ostypestr,
|
||||
virArch arch,
|
||||
const char *emulator,
|
||||
const char *loader,
|
||||
@ -416,13 +415,18 @@ virCapabilitiesAddGuest(virCapsPtr caps,
|
||||
virCapsGuestMachinePtr *machines)
|
||||
{
|
||||
virCapsGuestPtr guest;
|
||||
int ostype;
|
||||
|
||||
if (VIR_ALLOC(guest) < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_STRDUP(guest->ostype, ostype) < 0)
|
||||
if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("unknown OS type '%s'"), ostypestr);
|
||||
goto error;
|
||||
}
|
||||
|
||||
guest->ostype = ostype;
|
||||
guest->arch.id = arch;
|
||||
guest->arch.wordsize = virArchGetWordSize(arch);
|
||||
|
||||
@ -603,11 +607,19 @@ virCapabilitiesSupportsGuestArch(virCapsPtr caps,
|
||||
*/
|
||||
extern int
|
||||
virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
|
||||
const char *ostype)
|
||||
const char *ostypestr)
|
||||
{
|
||||
size_t i;
|
||||
int ostype;
|
||||
|
||||
if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("unknown OS type '%s'"), ostypestr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < caps->nguests; i++) {
|
||||
if (STREQ(caps->guests[i]->ostype, ostype))
|
||||
if (caps->guests[i]->ostype == ostype)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@ -625,12 +637,20 @@ virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
|
||||
*/
|
||||
extern int
|
||||
virCapabilitiesSupportsGuestOSTypeArch(virCapsPtr caps,
|
||||
const char *ostype,
|
||||
const char *ostypestr,
|
||||
virArch arch)
|
||||
{
|
||||
size_t i;
|
||||
int ostype;
|
||||
|
||||
if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("unknown OS type '%s'"), ostypestr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < caps->nguests; i++) {
|
||||
if (STREQ(caps->guests[i]->ostype, ostype) &&
|
||||
if (caps->guests[i]->ostype == ostype &&
|
||||
caps->guests[i]->arch.id == arch)
|
||||
return 1;
|
||||
}
|
||||
@ -648,14 +668,21 @@ virCapabilitiesSupportsGuestOSTypeArch(virCapsPtr caps,
|
||||
*/
|
||||
extern virArch
|
||||
virCapabilitiesDefaultGuestArch(virCapsPtr caps,
|
||||
const char *ostype,
|
||||
const char *ostypestr,
|
||||
const char *domain)
|
||||
{
|
||||
size_t i, j;
|
||||
int ostype;
|
||||
|
||||
if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("unknown OS type '%s'"), ostypestr);
|
||||
return VIR_ARCH_NONE;
|
||||
}
|
||||
|
||||
/* First try to find one matching host arch */
|
||||
for (i = 0; i < caps->nguests; i++) {
|
||||
if (STREQ(caps->guests[i]->ostype, ostype)) {
|
||||
if (caps->guests[i]->ostype == ostype) {
|
||||
for (j = 0; j < caps->guests[i]->arch.ndomains; j++) {
|
||||
if (STREQ(caps->guests[i]->arch.domains[j]->type, domain) &&
|
||||
caps->guests[i]->arch.id == caps->host.arch)
|
||||
@ -666,7 +693,7 @@ virCapabilitiesDefaultGuestArch(virCapsPtr caps,
|
||||
|
||||
/* Otherwise find the first match */
|
||||
for (i = 0; i < caps->nguests; i++) {
|
||||
if (STREQ(caps->guests[i]->ostype, ostype)) {
|
||||
if (caps->guests[i]->ostype == ostype) {
|
||||
for (j = 0; j < caps->guests[i]->arch.ndomains; j++) {
|
||||
if (STREQ(caps->guests[i]->arch.domains[j]->type, domain))
|
||||
return caps->guests[i]->arch.id;
|
||||
@ -690,17 +717,24 @@ virCapabilitiesDefaultGuestArch(virCapsPtr caps,
|
||||
*/
|
||||
extern const char *
|
||||
virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
|
||||
const char *ostype,
|
||||
const char *ostypestr,
|
||||
virArch arch,
|
||||
const char *domain)
|
||||
{
|
||||
size_t i;
|
||||
int ostype;
|
||||
|
||||
if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("unknown OS type '%s'"), ostypestr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < caps->nguests; i++) {
|
||||
virCapsGuestPtr guest = caps->guests[i];
|
||||
size_t j;
|
||||
|
||||
if (!STREQ(guest->ostype, ostype) ||
|
||||
if (guest->ostype != ostype ||
|
||||
guest->arch.id != arch)
|
||||
continue;
|
||||
|
||||
@ -736,14 +770,22 @@ virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
|
||||
*/
|
||||
extern const char *
|
||||
virCapabilitiesDefaultGuestEmulator(virCapsPtr caps,
|
||||
const char *ostype,
|
||||
const char *ostypestr,
|
||||
virArch arch,
|
||||
const char *domain)
|
||||
{
|
||||
size_t i, j;
|
||||
int ostype;
|
||||
|
||||
if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("unknown OS type '%s'"), ostypestr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < caps->nguests; i++) {
|
||||
char *emulator;
|
||||
if (STREQ(caps->guests[i]->ostype, ostype) &&
|
||||
if (caps->guests[i]->ostype == ostype &&
|
||||
caps->guests[i]->arch.id == arch) {
|
||||
emulator = caps->guests[i]->arch.defaultInfo.emulator;
|
||||
for (j = 0; j < caps->guests[i]->arch.ndomains; j++) {
|
||||
@ -944,7 +986,7 @@ virCapabilitiesFormatXML(virCapsPtr caps)
|
||||
virBufferAddLit(&buf, "<guest>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
virBufferAsprintf(&buf, "<os_type>%s</os_type>\n",
|
||||
caps->guests[i]->ostype);
|
||||
virDomainOSTypeToString(caps->guests[i]->ostype));
|
||||
if (caps->guests[i]->arch.id)
|
||||
virBufferAsprintf(&buf, "<arch name='%s'>\n",
|
||||
virArchToString(caps->guests[i]->arch.id));
|
||||
|
@ -79,7 +79,7 @@ struct _virCapsGuestArch {
|
||||
typedef struct _virCapsGuest virCapsGuest;
|
||||
typedef virCapsGuest *virCapsGuestPtr;
|
||||
struct _virCapsGuest {
|
||||
char *ostype;
|
||||
int ostype;
|
||||
virCapsGuestArch arch;
|
||||
size_t nfeatures;
|
||||
size_t nfeatures_max;
|
||||
|
@ -122,6 +122,14 @@ VIR_ENUM_IMPL(virDomainVirt, VIR_DOMAIN_VIRT_LAST,
|
||||
"parallels",
|
||||
"bhyve")
|
||||
|
||||
VIR_ENUM_IMPL(virDomainOS, VIR_DOMAIN_OSTYPE_LAST,
|
||||
"hvm",
|
||||
"xen",
|
||||
"linux",
|
||||
"exe",
|
||||
"uml",
|
||||
"aix")
|
||||
|
||||
VIR_ENUM_IMPL(virDomainBoot, VIR_DOMAIN_BOOT_LAST,
|
||||
"fd",
|
||||
"cdrom",
|
||||
|
@ -227,6 +227,19 @@ typedef enum {
|
||||
VIR_DOMAIN_VIRT_LAST
|
||||
} virDomainVirtType;
|
||||
|
||||
typedef enum {
|
||||
VIR_DOMAIN_OSTYPE_HVM,
|
||||
VIR_DOMAIN_OSTYPE_XEN,
|
||||
VIR_DOMAIN_OSTYPE_LINUX,
|
||||
VIR_DOMAIN_OSTYPE_EXE,
|
||||
VIR_DOMAIN_OSTYPE_UML,
|
||||
VIR_DOMAIN_OSTYPE_AIX,
|
||||
|
||||
VIR_DOMAIN_OSTYPE_LAST
|
||||
} virDomainOSType;
|
||||
VIR_ENUM_DECL(virDomainOS)
|
||||
|
||||
|
||||
typedef enum {
|
||||
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE,
|
||||
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI,
|
||||
|
@ -400,6 +400,8 @@ virDomainObjSetDefTransient;
|
||||
virDomainObjSetMetadata;
|
||||
virDomainObjSetState;
|
||||
virDomainObjTaint;
|
||||
virDomainOSTypeFromString;
|
||||
virDomainOSTypeToString;
|
||||
virDomainParseMemory;
|
||||
virDomainPausedReasonTypeFromString;
|
||||
virDomainPausedReasonTypeToString;
|
||||
|
@ -68,7 +68,7 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
|
||||
const char *boot;
|
||||
|
||||
for (i = 0; i < caps->nguests; i++) {
|
||||
if (STREQ(caps->guests[i]->ostype, "hvm") &&
|
||||
if (caps->guests[i]->ostype == VIR_DOMAIN_OSTYPE_HVM &&
|
||||
caps->guests[i]->arch.id == def->os.arch) {
|
||||
if (VIR_ALLOC(def->os.loader) < 0 ||
|
||||
VIR_STRDUP(def->os.loader->path,
|
||||
|
Loading…
x
Reference in New Issue
Block a user