#define VIR_DRV_SUPPORTS_FEATURE(drv,conn,feature) \
((drv)->supports_feature ? (drv)->supports_feature((conn),(feature)) : 0)
+typedef const char *
+ (*virDrvProbe) (void);
typedef virDrvOpenStatus
(*virDrvOpen) (virConnectPtr conn,
xmlURIPtr uri,
* - close
*/
struct _virDriver {
- int no; /* the number virDrvNo */
- const char * name; /* the name of the driver */
- unsigned long ver; /* the version of the backend */
- virDrvOpen open;
- virDrvClose close;
+ int no; /* the number virDrvNo */
+ const char * name; /* the name of the driver */
+ unsigned long ver; /* the version of the backend */
+ virDrvProbe probe;
+ virDrvOpen open;
+ virDrvClose close;
virDrvSupportsFeature supports_feature;
- virDrvGetType type;
- virDrvGetVersion version;
+ virDrvGetType type;
+ virDrvGetVersion version;
virDrvGetHostname getHostname;
virDrvGetURI getURI;
- virDrvGetMaxVcpus getMaxVcpus;
- virDrvNodeGetInfo nodeGetInfo;
- virDrvGetCapabilities getCapabilities;
- virDrvListDomains listDomains;
- virDrvNumOfDomains numOfDomains;
- virDrvDomainCreateLinux domainCreateLinux;
- virDrvDomainLookupByID domainLookupByID;
- virDrvDomainLookupByUUID domainLookupByUUID;
- virDrvDomainLookupByName domainLookupByName;
- virDrvDomainSuspend domainSuspend;
- virDrvDomainResume domainResume;
- virDrvDomainShutdown domainShutdown;
- virDrvDomainReboot domainReboot;
- virDrvDomainDestroy domainDestroy;
- virDrvDomainGetOSType domainGetOSType;
- virDrvDomainGetMaxMemory domainGetMaxMemory;
- virDrvDomainSetMaxMemory domainSetMaxMemory;
- virDrvDomainSetMemory domainSetMemory;
- virDrvDomainGetInfo domainGetInfo;
- virDrvDomainSave domainSave;
- virDrvDomainRestore domainRestore;
- virDrvDomainCoreDump domainCoreDump;
- virDrvDomainSetVcpus domainSetVcpus;
- virDrvDomainPinVcpu domainPinVcpu;
- virDrvDomainGetVcpus domainGetVcpus;
- virDrvDomainGetMaxVcpus domainGetMaxVcpus;
- virDrvDomainDumpXML domainDumpXML;
- virDrvListDefinedDomains listDefinedDomains;
- virDrvNumOfDefinedDomains numOfDefinedDomains;
- virDrvDomainCreate domainCreate;
- virDrvDomainDefineXML domainDefineXML;
- virDrvDomainUndefine domainUndefine;
- virDrvDomainAttachDevice domainAttachDevice;
- virDrvDomainDetachDevice domainDetachDevice;
- virDrvDomainGetAutostart domainGetAutostart;
- virDrvDomainSetAutostart domainSetAutostart;
- virDrvDomainGetSchedulerType domainGetSchedulerType;
- virDrvDomainGetSchedulerParameters domainGetSchedulerParameters;
- virDrvDomainSetSchedulerParameters domainSetSchedulerParameters;
+ virDrvGetMaxVcpus getMaxVcpus;
+ virDrvNodeGetInfo nodeGetInfo;
+ virDrvGetCapabilities getCapabilities;
+ virDrvListDomains listDomains;
+ virDrvNumOfDomains numOfDomains;
+ virDrvDomainCreateLinux domainCreateLinux;
+ virDrvDomainLookupByID domainLookupByID;
+ virDrvDomainLookupByUUID domainLookupByUUID;
+ virDrvDomainLookupByName domainLookupByName;
+ virDrvDomainSuspend domainSuspend;
+ virDrvDomainResume domainResume;
+ virDrvDomainShutdown domainShutdown;
+ virDrvDomainReboot domainReboot;
+ virDrvDomainDestroy domainDestroy;
+ virDrvDomainGetOSType domainGetOSType;
+ virDrvDomainGetMaxMemory domainGetMaxMemory;
+ virDrvDomainSetMaxMemory domainSetMaxMemory;
+ virDrvDomainSetMemory domainSetMemory;
+ virDrvDomainGetInfo domainGetInfo;
+ virDrvDomainSave domainSave;
+ virDrvDomainRestore domainRestore;
+ virDrvDomainCoreDump domainCoreDump;
+ virDrvDomainSetVcpus domainSetVcpus;
+ virDrvDomainPinVcpu domainPinVcpu;
+ virDrvDomainGetVcpus domainGetVcpus;
+ virDrvDomainGetMaxVcpus domainGetMaxVcpus;
+ virDrvDomainDumpXML domainDumpXML;
+ virDrvListDefinedDomains listDefinedDomains;
+ virDrvNumOfDefinedDomains numOfDefinedDomains;
+ virDrvDomainCreate domainCreate;
+ virDrvDomainDefineXML domainDefineXML;
+ virDrvDomainUndefine domainUndefine;
+ virDrvDomainAttachDevice domainAttachDevice;
+ virDrvDomainDetachDevice domainDetachDevice;
+ virDrvDomainGetAutostart domainGetAutostart;
+ virDrvDomainSetAutostart domainSetAutostart;
+ virDrvDomainGetSchedulerType domainGetSchedulerType;
+ virDrvDomainGetSchedulerParameters domainGetSchedulerParameters;
+ virDrvDomainSetSchedulerParameters domainSetSchedulerParameters;
virDrvDomainMigratePrepare domainMigratePrepare;
virDrvDomainMigratePerform domainMigratePerform;
virDrvDomainMigrateFinish domainMigrateFinish;
virDrvDomainBlockStats domainBlockStats;
virDrvDomainInterfaceStats domainInterfaceStats;
- virDrvNodeGetCellsFreeMemory nodeGetCellsFreeMemory;
- virDrvNodeGetFreeMemory getFreeMemory;
+ virDrvNodeGetCellsFreeMemory nodeGetCellsFreeMemory;
+ virDrvNodeGetFreeMemory getFreeMemory;
};
typedef int
virConnectPtr ret = NULL;
xmlURIPtr uri;
- /* Convert NULL or "" to xen:/// for back compat */
- if (!name || name[0] == '\0')
- name = "xen:///";
+ /*
+ * If no URI is passed, then check for an environment string if not
+ * 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 */
if (!strcasecmp(name, "xen"))