mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-29 17:33:09 +00:00
* src/driver.h src/libvirt.c src/openvz_driver.c src/qemu_driver.c
src/remote_internal.c src/test.c src/util.c src/util.h src/xen_unified.c: added probe interface at the driver level, use that to improve default hypervisor selection in the absence of a given URI when connecting Daniel
This commit is contained in:
parent
9b1cd481b8
commit
36c6bfa63d
@ -1,3 +1,11 @@
|
|||||||
|
Tue Feb 26 08:02:57 CET 2008 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
|
* src/driver.h src/libvirt.c src/openvz_driver.c src/qemu_driver.c
|
||||||
|
src/remote_internal.c src/test.c src/util.c src/util.h
|
||||||
|
src/xen_unified.c: added probe interface at the driver level,
|
||||||
|
use that to improve default hypervisor selection in the absence
|
||||||
|
of a given URI when connecting
|
||||||
|
|
||||||
Mon Feb 25 14:53:59 CET 2008 Daniel Veillard <veillard@redhat.com>
|
Mon Feb 25 14:53:59 CET 2008 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* src/Makefile.am src/util-lib.h: fix done with Jim to allow
|
* src/Makefile.am src/util-lib.h: fix done with Jim to allow
|
||||||
|
99
src/driver.h
99
src/driver.h
@ -69,6 +69,8 @@ typedef enum {
|
|||||||
#define VIR_DRV_SUPPORTS_FEATURE(drv,conn,feature) \
|
#define VIR_DRV_SUPPORTS_FEATURE(drv,conn,feature) \
|
||||||
((drv)->supports_feature ? (drv)->supports_feature((conn),(feature)) : 0)
|
((drv)->supports_feature ? (drv)->supports_feature((conn),(feature)) : 0)
|
||||||
|
|
||||||
|
typedef const char *
|
||||||
|
(*virDrvProbe) (void);
|
||||||
typedef virDrvOpenStatus
|
typedef virDrvOpenStatus
|
||||||
(*virDrvOpen) (virConnectPtr conn,
|
(*virDrvOpen) (virConnectPtr conn,
|
||||||
xmlURIPtr uri,
|
xmlURIPtr uri,
|
||||||
@ -277,62 +279,63 @@ typedef unsigned long long
|
|||||||
* - close
|
* - close
|
||||||
*/
|
*/
|
||||||
struct _virDriver {
|
struct _virDriver {
|
||||||
int no; /* the number virDrvNo */
|
int no; /* the number virDrvNo */
|
||||||
const char * name; /* the name of the driver */
|
const char * name; /* the name of the driver */
|
||||||
unsigned long ver; /* the version of the backend */
|
unsigned long ver; /* the version of the backend */
|
||||||
virDrvOpen open;
|
virDrvProbe probe;
|
||||||
virDrvClose close;
|
virDrvOpen open;
|
||||||
|
virDrvClose close;
|
||||||
virDrvSupportsFeature supports_feature;
|
virDrvSupportsFeature supports_feature;
|
||||||
virDrvGetType type;
|
virDrvGetType type;
|
||||||
virDrvGetVersion version;
|
virDrvGetVersion version;
|
||||||
virDrvGetHostname getHostname;
|
virDrvGetHostname getHostname;
|
||||||
virDrvGetURI getURI;
|
virDrvGetURI getURI;
|
||||||
virDrvGetMaxVcpus getMaxVcpus;
|
virDrvGetMaxVcpus getMaxVcpus;
|
||||||
virDrvNodeGetInfo nodeGetInfo;
|
virDrvNodeGetInfo nodeGetInfo;
|
||||||
virDrvGetCapabilities getCapabilities;
|
virDrvGetCapabilities getCapabilities;
|
||||||
virDrvListDomains listDomains;
|
virDrvListDomains listDomains;
|
||||||
virDrvNumOfDomains numOfDomains;
|
virDrvNumOfDomains numOfDomains;
|
||||||
virDrvDomainCreateLinux domainCreateLinux;
|
virDrvDomainCreateLinux domainCreateLinux;
|
||||||
virDrvDomainLookupByID domainLookupByID;
|
virDrvDomainLookupByID domainLookupByID;
|
||||||
virDrvDomainLookupByUUID domainLookupByUUID;
|
virDrvDomainLookupByUUID domainLookupByUUID;
|
||||||
virDrvDomainLookupByName domainLookupByName;
|
virDrvDomainLookupByName domainLookupByName;
|
||||||
virDrvDomainSuspend domainSuspend;
|
virDrvDomainSuspend domainSuspend;
|
||||||
virDrvDomainResume domainResume;
|
virDrvDomainResume domainResume;
|
||||||
virDrvDomainShutdown domainShutdown;
|
virDrvDomainShutdown domainShutdown;
|
||||||
virDrvDomainReboot domainReboot;
|
virDrvDomainReboot domainReboot;
|
||||||
virDrvDomainDestroy domainDestroy;
|
virDrvDomainDestroy domainDestroy;
|
||||||
virDrvDomainGetOSType domainGetOSType;
|
virDrvDomainGetOSType domainGetOSType;
|
||||||
virDrvDomainGetMaxMemory domainGetMaxMemory;
|
virDrvDomainGetMaxMemory domainGetMaxMemory;
|
||||||
virDrvDomainSetMaxMemory domainSetMaxMemory;
|
virDrvDomainSetMaxMemory domainSetMaxMemory;
|
||||||
virDrvDomainSetMemory domainSetMemory;
|
virDrvDomainSetMemory domainSetMemory;
|
||||||
virDrvDomainGetInfo domainGetInfo;
|
virDrvDomainGetInfo domainGetInfo;
|
||||||
virDrvDomainSave domainSave;
|
virDrvDomainSave domainSave;
|
||||||
virDrvDomainRestore domainRestore;
|
virDrvDomainRestore domainRestore;
|
||||||
virDrvDomainCoreDump domainCoreDump;
|
virDrvDomainCoreDump domainCoreDump;
|
||||||
virDrvDomainSetVcpus domainSetVcpus;
|
virDrvDomainSetVcpus domainSetVcpus;
|
||||||
virDrvDomainPinVcpu domainPinVcpu;
|
virDrvDomainPinVcpu domainPinVcpu;
|
||||||
virDrvDomainGetVcpus domainGetVcpus;
|
virDrvDomainGetVcpus domainGetVcpus;
|
||||||
virDrvDomainGetMaxVcpus domainGetMaxVcpus;
|
virDrvDomainGetMaxVcpus domainGetMaxVcpus;
|
||||||
virDrvDomainDumpXML domainDumpXML;
|
virDrvDomainDumpXML domainDumpXML;
|
||||||
virDrvListDefinedDomains listDefinedDomains;
|
virDrvListDefinedDomains listDefinedDomains;
|
||||||
virDrvNumOfDefinedDomains numOfDefinedDomains;
|
virDrvNumOfDefinedDomains numOfDefinedDomains;
|
||||||
virDrvDomainCreate domainCreate;
|
virDrvDomainCreate domainCreate;
|
||||||
virDrvDomainDefineXML domainDefineXML;
|
virDrvDomainDefineXML domainDefineXML;
|
||||||
virDrvDomainUndefine domainUndefine;
|
virDrvDomainUndefine domainUndefine;
|
||||||
virDrvDomainAttachDevice domainAttachDevice;
|
virDrvDomainAttachDevice domainAttachDevice;
|
||||||
virDrvDomainDetachDevice domainDetachDevice;
|
virDrvDomainDetachDevice domainDetachDevice;
|
||||||
virDrvDomainGetAutostart domainGetAutostart;
|
virDrvDomainGetAutostart domainGetAutostart;
|
||||||
virDrvDomainSetAutostart domainSetAutostart;
|
virDrvDomainSetAutostart domainSetAutostart;
|
||||||
virDrvDomainGetSchedulerType domainGetSchedulerType;
|
virDrvDomainGetSchedulerType domainGetSchedulerType;
|
||||||
virDrvDomainGetSchedulerParameters domainGetSchedulerParameters;
|
virDrvDomainGetSchedulerParameters domainGetSchedulerParameters;
|
||||||
virDrvDomainSetSchedulerParameters domainSetSchedulerParameters;
|
virDrvDomainSetSchedulerParameters domainSetSchedulerParameters;
|
||||||
virDrvDomainMigratePrepare domainMigratePrepare;
|
virDrvDomainMigratePrepare domainMigratePrepare;
|
||||||
virDrvDomainMigratePerform domainMigratePerform;
|
virDrvDomainMigratePerform domainMigratePerform;
|
||||||
virDrvDomainMigrateFinish domainMigrateFinish;
|
virDrvDomainMigrateFinish domainMigrateFinish;
|
||||||
virDrvDomainBlockStats domainBlockStats;
|
virDrvDomainBlockStats domainBlockStats;
|
||||||
virDrvDomainInterfaceStats domainInterfaceStats;
|
virDrvDomainInterfaceStats domainInterfaceStats;
|
||||||
virDrvNodeGetCellsFreeMemory nodeGetCellsFreeMemory;
|
virDrvNodeGetCellsFreeMemory nodeGetCellsFreeMemory;
|
||||||
virDrvNodeGetFreeMemory getFreeMemory;
|
virDrvNodeGetFreeMemory getFreeMemory;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef int
|
typedef int
|
||||||
|
@ -632,9 +632,47 @@ do_open (const char *name,
|
|||||||
virConnectPtr ret = NULL;
|
virConnectPtr ret = NULL;
|
||||||
xmlURIPtr uri;
|
xmlURIPtr uri;
|
||||||
|
|
||||||
/* Convert NULL or "" to xen:/// for back compat */
|
/*
|
||||||
if (!name || name[0] == '\0')
|
* If no URI is passed, then check for an environment string if not
|
||||||
name = "xen:///";
|
* available probe the compiled in drivers to find a default hypervisor
|
||||||
|
* if detectable.
|
||||||
|
*/
|
||||||
|
if (!name || name[0] == '\0') {
|
||||||
|
char *defname = getenv("LIBVIRT_DEFAULT_URI");
|
||||||
|
if (defname && *defname) {
|
||||||
|
DEBUG("Using LIBVIRT_DEFAULT_URI %s", defname);
|
||||||
|
name = defname;
|
||||||
|
} else {
|
||||||
|
const char *use = NULL;
|
||||||
|
const char *latest;
|
||||||
|
int probes = 0;
|
||||||
|
for (i = 0; i < virNetworkDriverTabCount; i++) {
|
||||||
|
if ((virDriverTab[i]->probe != NULL) &&
|
||||||
|
((latest = virDriverTab[i]->probe()) != NULL)) {
|
||||||
|
probes++;
|
||||||
|
|
||||||
|
DEBUG("Probed %s", latest);
|
||||||
|
/*
|
||||||
|
* if running a xen kernel, give it priority over
|
||||||
|
* QEmu emultation
|
||||||
|
*/
|
||||||
|
if (STREQ(latest, "xen:///"))
|
||||||
|
use = latest;
|
||||||
|
else if (use == NULL)
|
||||||
|
use = latest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (use == NULL) {
|
||||||
|
name = "xen:///";
|
||||||
|
DEBUG("Could not probe any hypervisor defaulting to %s",
|
||||||
|
name);
|
||||||
|
} else {
|
||||||
|
name = use;
|
||||||
|
DEBUG("Using %s as default URI, %d hypervisor found",
|
||||||
|
use, probes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Convert xen -> xen:/// for back compat */
|
/* Convert xen -> xen:/// for back compat */
|
||||||
if (!strcasecmp(name, "xen"))
|
if (!strcasecmp(name, "xen"))
|
||||||
|
@ -546,6 +546,15 @@ bail_out5:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *openvzProbe(void)
|
||||||
|
{
|
||||||
|
#ifdef __linux__
|
||||||
|
if ((getuid() == 0) && (virFileExists("/proc/vz")))
|
||||||
|
return("openvz:///");
|
||||||
|
#endif
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static virDrvOpenStatus openvzOpen(virConnectPtr conn,
|
static virDrvOpenStatus openvzOpen(virConnectPtr conn,
|
||||||
xmlURIPtr uri,
|
xmlURIPtr uri,
|
||||||
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
||||||
@ -694,6 +703,7 @@ static virDriver openvzDriver = {
|
|||||||
VIR_DRV_OPENVZ,
|
VIR_DRV_OPENVZ,
|
||||||
"OPENVZ",
|
"OPENVZ",
|
||||||
LIBVIR_VERSION_NUMBER,
|
LIBVIR_VERSION_NUMBER,
|
||||||
|
openvzProbe, /* probe */
|
||||||
openvzOpen, /* open */
|
openvzOpen, /* open */
|
||||||
openvzClose, /* close */
|
openvzClose, /* close */
|
||||||
NULL, /* supports_feature */
|
NULL, /* supports_feature */
|
||||||
|
@ -1388,6 +1388,25 @@ static int qemudMonitorCommand(struct qemud_driver *driver ATTRIBUTE_UNUSED,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qemudProbe:
|
||||||
|
*
|
||||||
|
* Probe for the availability of the qemu driver, assume the
|
||||||
|
* presence of QEmu emulation if the binaries are installed
|
||||||
|
*/
|
||||||
|
static const char *qemudProbe(void)
|
||||||
|
{
|
||||||
|
if ((virFileExists("/usr/bin/qemu")) ||
|
||||||
|
(virFileExists("/usr/bin/qemu-kvm")) ||
|
||||||
|
(virFileExists("/usr/bin/xenner"))) {
|
||||||
|
if (getuid() == 0) {
|
||||||
|
return("qemu:///system");
|
||||||
|
} else {
|
||||||
|
return("qemu:///session");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static virDrvOpenStatus qemudOpen(virConnectPtr conn,
|
static virDrvOpenStatus qemudOpen(virConnectPtr conn,
|
||||||
xmlURIPtr uri,
|
xmlURIPtr uri,
|
||||||
@ -2859,6 +2878,7 @@ static virDriver qemuDriver = {
|
|||||||
VIR_DRV_QEMU,
|
VIR_DRV_QEMU,
|
||||||
"QEMU",
|
"QEMU",
|
||||||
LIBVIR_VERSION_NUMBER,
|
LIBVIR_VERSION_NUMBER,
|
||||||
|
qemudProbe, /* probe */
|
||||||
qemudOpen, /* open */
|
qemudOpen, /* open */
|
||||||
qemudClose, /* close */
|
qemudClose, /* close */
|
||||||
NULL, /* supports_feature */
|
NULL, /* supports_feature */
|
||||||
|
@ -4599,6 +4599,7 @@ static virDriver driver = {
|
|||||||
.no = VIR_DRV_REMOTE,
|
.no = VIR_DRV_REMOTE,
|
||||||
.name = "remote",
|
.name = "remote",
|
||||||
.ver = REMOTE_PROTOCOL_VERSION,
|
.ver = REMOTE_PROTOCOL_VERSION,
|
||||||
|
.probe = NULL,
|
||||||
.open = remoteOpen,
|
.open = remoteOpen,
|
||||||
.close = remoteClose,
|
.close = remoteClose,
|
||||||
.supports_feature = remoteSupportsFeature,
|
.supports_feature = remoteSupportsFeature,
|
||||||
|
@ -1939,6 +1939,7 @@ static virDriver testDriver = {
|
|||||||
VIR_DRV_TEST,
|
VIR_DRV_TEST,
|
||||||
"Test",
|
"Test",
|
||||||
LIBVIR_VERSION_NUMBER,
|
LIBVIR_VERSION_NUMBER,
|
||||||
|
NULL, /* probe */
|
||||||
testOpen, /* open */
|
testOpen, /* open */
|
||||||
testClose, /* close */
|
testClose, /* close */
|
||||||
NULL, /* supports_feature */
|
NULL, /* supports_feature */
|
||||||
|
@ -463,6 +463,15 @@ virFileLinkPointsTo (const char *checkLink ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
#endif /*! __MINGW32__ */
|
#endif /*! __MINGW32__ */
|
||||||
|
|
||||||
|
int virFileExists(const char *path)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (stat(path, &st) >= 0)
|
||||||
|
return(1);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
int virFileMakePath(const char *path)
|
int virFileMakePath(const char *path)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
@ -47,6 +47,9 @@ int virFileHasSuffix(const char *str,
|
|||||||
|
|
||||||
int virFileLinkPointsTo(const char *checkLink,
|
int virFileLinkPointsTo(const char *checkLink,
|
||||||
const char *checkDest);
|
const char *checkDest);
|
||||||
|
|
||||||
|
int virFileExists(const char *path);
|
||||||
|
|
||||||
int virFileMakePath(const char *path);
|
int virFileMakePath(const char *path);
|
||||||
|
|
||||||
int virFileBuildPath(const char *dir,
|
int virFileBuildPath(const char *dir,
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "xs_internal.h"
|
#include "xs_internal.h"
|
||||||
#include "xm_internal.h"
|
#include "xm_internal.h"
|
||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
|
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
|
||||||
|
|
||||||
@ -217,6 +218,24 @@ done:
|
|||||||
* in the low level drivers directly.
|
* in the low level drivers directly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
xenUnifiedProbe (void)
|
||||||
|
{
|
||||||
|
#ifdef __linux__
|
||||||
|
if (virFileExists("/proc/xen"))
|
||||||
|
return("xen:///");
|
||||||
|
#endif
|
||||||
|
#ifdef __sun__
|
||||||
|
FILE *fh;
|
||||||
|
|
||||||
|
if (fh = fopen("/dev/xen/domcaps", "r")) {
|
||||||
|
fclose(fh);
|
||||||
|
return("xen:///");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int flags)
|
xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int flags)
|
||||||
{
|
{
|
||||||
@ -1198,6 +1217,7 @@ static virDriver xenUnifiedDriver = {
|
|||||||
.no = VIR_DRV_XEN_UNIFIED,
|
.no = VIR_DRV_XEN_UNIFIED,
|
||||||
.name = "Xen",
|
.name = "Xen",
|
||||||
.ver = HV_VERSION,
|
.ver = HV_VERSION,
|
||||||
|
.probe = xenUnifiedProbe,
|
||||||
.open = xenUnifiedOpen,
|
.open = xenUnifiedOpen,
|
||||||
.close = xenUnifiedClose,
|
.close = xenUnifiedClose,
|
||||||
.supports_feature = xenUnifiedSupportsFeature,
|
.supports_feature = xenUnifiedSupportsFeature,
|
||||||
|
Loading…
Reference in New Issue
Block a user