mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
Simplify the Xen domain get OS type driver method
Make xenUnifiedDomainGetOSType directly call either the xenHypervisorDomainGetOSType or xenDaemonDomainGetOSType method depending on whether the domain is active or not. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
13c9ef29c0
commit
846576eb38
@ -793,18 +793,21 @@ static char *
|
||||
xenUnifiedDomainGetOSType(virDomainPtr dom)
|
||||
{
|
||||
xenUnifiedPrivatePtr priv = dom->conn->privateData;
|
||||
int i;
|
||||
char *ret;
|
||||
|
||||
for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
|
||||
if (priv->opened[i] && drivers[i]->xenDomainGetOSType) {
|
||||
ret = drivers[i]->xenDomainGetOSType(dom);
|
||||
if (ret) return ret;
|
||||
if (dom->id < 0) {
|
||||
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unable to query OS type for inactive domain"));
|
||||
return NULL;
|
||||
} else {
|
||||
return xenDaemonDomainGetOSType(dom);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
} else {
|
||||
return xenHypervisorDomainGetOSType(dom);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static unsigned long long
|
||||
xenUnifiedDomainGetMaxMemory(virDomainPtr dom)
|
||||
{
|
||||
|
@ -94,7 +94,6 @@ extern int xenRegister (void);
|
||||
*/
|
||||
struct xenUnifiedDriver {
|
||||
virDrvConnectGetHostname xenGetHostname;
|
||||
virDrvDomainGetOSType xenDomainGetOSType;
|
||||
virDrvDomainGetMaxMemory xenDomainGetMaxMemory;
|
||||
virDrvDomainSetMaxMemory xenDomainSetMaxMemory;
|
||||
virDrvDomainSetMemory xenDomainSetMemory;
|
||||
|
@ -873,7 +873,6 @@ typedef struct xen_op_v2_dom xen_op_v2_dom;
|
||||
static unsigned long long xenHypervisorGetMaxMemory(virDomainPtr domain);
|
||||
|
||||
struct xenUnifiedDriver xenHypervisorDriver = {
|
||||
.xenDomainGetOSType = xenHypervisorDomainGetOSType,
|
||||
.xenDomainGetMaxMemory = xenHypervisorGetMaxMemory,
|
||||
.xenDomainSetMaxMemory = xenHypervisorSetMaxMemory,
|
||||
.xenDomainGetInfo = xenHypervisorGetDomainInfo,
|
||||
@ -2613,9 +2612,7 @@ xenHypervisorDomainGetOSType(virDomainPtr dom)
|
||||
/* HV's earlier than 3.1.0 don't include the HVM flags in guests status*/
|
||||
if (hv_versions.hypervisor < 2 ||
|
||||
hv_versions.dom_interface < 4) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("unsupported in dom interface < 4"));
|
||||
return NULL;
|
||||
return xenDaemonDomainGetOSType(dom);
|
||||
}
|
||||
|
||||
XEN_GETDOMAININFO_CLEAR(dominfo);
|
||||
|
@ -1373,15 +1373,11 @@ xenDaemonDomainDestroy(virDomainPtr domain)
|
||||
* Returns the new string or NULL in case of error, the string must be
|
||||
* freed by the caller.
|
||||
*/
|
||||
static char *
|
||||
char *
|
||||
xenDaemonDomainGetOSType(virDomainPtr domain)
|
||||
{
|
||||
char *type;
|
||||
struct sexpr *root;
|
||||
xenUnifiedPrivatePtr priv = domain->conn->privateData;
|
||||
|
||||
if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
|
||||
return NULL;
|
||||
|
||||
/* can we ask for a subset ? worth it ? */
|
||||
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
|
||||
@ -3441,7 +3437,6 @@ xenDaemonDomainBlockPeek(virDomainPtr domain,
|
||||
}
|
||||
|
||||
struct xenUnifiedDriver xenDaemonDriver = {
|
||||
.xenDomainGetOSType = xenDaemonDomainGetOSType,
|
||||
.xenDomainGetMaxMemory = xenDaemonDomainGetMaxMemory,
|
||||
.xenDomainSetMaxMemory = xenDaemonDomainSetMaxMemory,
|
||||
.xenDomainSetMemory = xenDaemonDomainSetMemory,
|
||||
|
@ -108,6 +108,8 @@ char *xenDaemonDomainGetXMLDesc(virDomainPtr domain, unsigned int flags,
|
||||
unsigned long long xenDaemonDomainGetMaxMemory(virDomainPtr domain);
|
||||
char **xenDaemonListDomainsOld(virConnectPtr xend);
|
||||
|
||||
char *xenDaemonDomainGetOSType(virDomainPtr domain);
|
||||
|
||||
virDomainPtr xenDaemonDomainDefineXML(virConnectPtr xend, const char *sexpr);
|
||||
int xenDaemonDomainCreate(virDomainPtr domain);
|
||||
int xenDaemonDomainUndefine(virDomainPtr domain);
|
||||
|
@ -53,12 +53,10 @@
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_XEN
|
||||
|
||||
static char *xenStoreDomainGetOSType(virDomainPtr domain);
|
||||
static void xenStoreWatchEvent(int watch, int fd, int events, void *data);
|
||||
static void xenStoreWatchListFree(xenStoreWatchListPtr list);
|
||||
|
||||
struct xenUnifiedDriver xenStoreDriver = {
|
||||
.xenDomainGetOSType = xenStoreDomainGetOSType,
|
||||
.xenDomainGetMaxMemory = xenStoreDomainGetMaxMemory,
|
||||
.xenDomainSetMemory = xenStoreDomainSetMemory,
|
||||
.xenDomainGetInfo = xenStoreGetDomainInfo,
|
||||
@ -142,63 +140,6 @@ virDomainDoStoreWrite(virDomainPtr domain, const char *path, const char *value)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainGetVM:
|
||||
* @domain: a domain object
|
||||
*
|
||||
* Internal API extracting a xenstore vm path.
|
||||
*
|
||||
* Returns the new string or NULL in case of error
|
||||
*/
|
||||
static char *
|
||||
virDomainGetVM(virDomainPtr domain)
|
||||
{
|
||||
char *vm;
|
||||
char query[200];
|
||||
unsigned int len;
|
||||
xenUnifiedPrivatePtr priv = domain->conn->privateData;
|
||||
|
||||
if (priv->xshandle == NULL)
|
||||
return NULL;
|
||||
|
||||
snprintf(query, 199, "/local/domain/%d/vm", virDomainGetID(domain));
|
||||
query[199] = 0;
|
||||
|
||||
vm = xs_read(priv->xshandle, 0, &query[0], &len);
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainGetVMInfo:
|
||||
* @domain: a domain object
|
||||
* @vm: the xenstore vm path
|
||||
* @name: the value's path
|
||||
*
|
||||
* Internal API extracting one information the device used
|
||||
* by the domain from xensttore
|
||||
*
|
||||
* Returns the new string or NULL in case of error
|
||||
*/
|
||||
static char *
|
||||
virDomainGetVMInfo(virDomainPtr domain, const char *vm, const char *name)
|
||||
{
|
||||
char s[256];
|
||||
char *ret = NULL;
|
||||
unsigned int len = 0;
|
||||
xenUnifiedPrivatePtr priv = domain->conn->privateData;
|
||||
|
||||
if (priv->xshandle == NULL)
|
||||
return NULL;
|
||||
|
||||
snprintf(s, 255, "%s/%s", vm, name);
|
||||
s[255] = 0;
|
||||
|
||||
ret = xs_read(priv->xshandle, 0, &s[0], &len);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* *
|
||||
@ -579,32 +520,6 @@ xenStoreListDomains(virConnectPtr conn, int *ids, int maxids)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* xenStoreDomainGetOSType:
|
||||
* @domain: a domain object
|
||||
*
|
||||
* Get the type of domain operation system.
|
||||
*
|
||||
* Returns the new string or NULL in case of error, the string must be
|
||||
* freed by the caller.
|
||||
*/
|
||||
static char *
|
||||
xenStoreDomainGetOSType(virDomainPtr domain)
|
||||
{
|
||||
char *vm, *str = NULL;
|
||||
|
||||
vm = virDomainGetVM(domain);
|
||||
if (vm) {
|
||||
xenUnifiedPrivatePtr priv = domain->conn->privateData;
|
||||
xenUnifiedLock(priv);
|
||||
str = virDomainGetVMInfo(domain, vm, "image/ostype");
|
||||
xenUnifiedUnlock(priv);
|
||||
VIR_FREE(vm);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* xenStoreDomainGetVNCPort:
|
||||
* @conn: the hypervisor connection
|
||||
|
Loading…
Reference in New Issue
Block a user