mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06: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)
|
xenUnifiedDomainGetOSType(virDomainPtr dom)
|
||||||
{
|
{
|
||||||
xenUnifiedPrivatePtr priv = dom->conn->privateData;
|
xenUnifiedPrivatePtr priv = dom->conn->privateData;
|
||||||
int i;
|
|
||||||
char *ret;
|
|
||||||
|
|
||||||
for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
|
if (dom->id < 0) {
|
||||||
if (priv->opened[i] && drivers[i]->xenDomainGetOSType) {
|
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
|
||||||
ret = drivers[i]->xenDomainGetOSType(dom);
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
if (ret) return ret;
|
_("Unable to query OS type for inactive domain"));
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
return xenDaemonDomainGetOSType(dom);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
return NULL;
|
return xenHypervisorDomainGetOSType(dom);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static unsigned long long
|
static unsigned long long
|
||||||
xenUnifiedDomainGetMaxMemory(virDomainPtr dom)
|
xenUnifiedDomainGetMaxMemory(virDomainPtr dom)
|
||||||
{
|
{
|
||||||
|
@ -94,7 +94,6 @@ extern int xenRegister (void);
|
|||||||
*/
|
*/
|
||||||
struct xenUnifiedDriver {
|
struct xenUnifiedDriver {
|
||||||
virDrvConnectGetHostname xenGetHostname;
|
virDrvConnectGetHostname xenGetHostname;
|
||||||
virDrvDomainGetOSType xenDomainGetOSType;
|
|
||||||
virDrvDomainGetMaxMemory xenDomainGetMaxMemory;
|
virDrvDomainGetMaxMemory xenDomainGetMaxMemory;
|
||||||
virDrvDomainSetMaxMemory xenDomainSetMaxMemory;
|
virDrvDomainSetMaxMemory xenDomainSetMaxMemory;
|
||||||
virDrvDomainSetMemory xenDomainSetMemory;
|
virDrvDomainSetMemory xenDomainSetMemory;
|
||||||
|
@ -873,7 +873,6 @@ typedef struct xen_op_v2_dom xen_op_v2_dom;
|
|||||||
static unsigned long long xenHypervisorGetMaxMemory(virDomainPtr domain);
|
static unsigned long long xenHypervisorGetMaxMemory(virDomainPtr domain);
|
||||||
|
|
||||||
struct xenUnifiedDriver xenHypervisorDriver = {
|
struct xenUnifiedDriver xenHypervisorDriver = {
|
||||||
.xenDomainGetOSType = xenHypervisorDomainGetOSType,
|
|
||||||
.xenDomainGetMaxMemory = xenHypervisorGetMaxMemory,
|
.xenDomainGetMaxMemory = xenHypervisorGetMaxMemory,
|
||||||
.xenDomainSetMaxMemory = xenHypervisorSetMaxMemory,
|
.xenDomainSetMaxMemory = xenHypervisorSetMaxMemory,
|
||||||
.xenDomainGetInfo = xenHypervisorGetDomainInfo,
|
.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*/
|
/* HV's earlier than 3.1.0 don't include the HVM flags in guests status*/
|
||||||
if (hv_versions.hypervisor < 2 ||
|
if (hv_versions.hypervisor < 2 ||
|
||||||
hv_versions.dom_interface < 4) {
|
hv_versions.dom_interface < 4) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
return xenDaemonDomainGetOSType(dom);
|
||||||
_("unsupported in dom interface < 4"));
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XEN_GETDOMAININFO_CLEAR(dominfo);
|
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
|
* Returns the new string or NULL in case of error, the string must be
|
||||||
* freed by the caller.
|
* freed by the caller.
|
||||||
*/
|
*/
|
||||||
static char *
|
char *
|
||||||
xenDaemonDomainGetOSType(virDomainPtr domain)
|
xenDaemonDomainGetOSType(virDomainPtr domain)
|
||||||
{
|
{
|
||||||
char *type;
|
char *type;
|
||||||
struct sexpr *root;
|
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 ? */
|
/* can we ask for a subset ? worth it ? */
|
||||||
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
|
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
|
||||||
@ -3441,7 +3437,6 @@ xenDaemonDomainBlockPeek(virDomainPtr domain,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct xenUnifiedDriver xenDaemonDriver = {
|
struct xenUnifiedDriver xenDaemonDriver = {
|
||||||
.xenDomainGetOSType = xenDaemonDomainGetOSType,
|
|
||||||
.xenDomainGetMaxMemory = xenDaemonDomainGetMaxMemory,
|
.xenDomainGetMaxMemory = xenDaemonDomainGetMaxMemory,
|
||||||
.xenDomainSetMaxMemory = xenDaemonDomainSetMaxMemory,
|
.xenDomainSetMaxMemory = xenDaemonDomainSetMaxMemory,
|
||||||
.xenDomainSetMemory = xenDaemonDomainSetMemory,
|
.xenDomainSetMemory = xenDaemonDomainSetMemory,
|
||||||
|
@ -108,6 +108,8 @@ char *xenDaemonDomainGetXMLDesc(virDomainPtr domain, unsigned int flags,
|
|||||||
unsigned long long xenDaemonDomainGetMaxMemory(virDomainPtr domain);
|
unsigned long long xenDaemonDomainGetMaxMemory(virDomainPtr domain);
|
||||||
char **xenDaemonListDomainsOld(virConnectPtr xend);
|
char **xenDaemonListDomainsOld(virConnectPtr xend);
|
||||||
|
|
||||||
|
char *xenDaemonDomainGetOSType(virDomainPtr domain);
|
||||||
|
|
||||||
virDomainPtr xenDaemonDomainDefineXML(virConnectPtr xend, const char *sexpr);
|
virDomainPtr xenDaemonDomainDefineXML(virConnectPtr xend, const char *sexpr);
|
||||||
int xenDaemonDomainCreate(virDomainPtr domain);
|
int xenDaemonDomainCreate(virDomainPtr domain);
|
||||||
int xenDaemonDomainUndefine(virDomainPtr domain);
|
int xenDaemonDomainUndefine(virDomainPtr domain);
|
||||||
|
@ -53,12 +53,10 @@
|
|||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_XEN
|
#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 xenStoreWatchEvent(int watch, int fd, int events, void *data);
|
||||||
static void xenStoreWatchListFree(xenStoreWatchListPtr list);
|
static void xenStoreWatchListFree(xenStoreWatchListPtr list);
|
||||||
|
|
||||||
struct xenUnifiedDriver xenStoreDriver = {
|
struct xenUnifiedDriver xenStoreDriver = {
|
||||||
.xenDomainGetOSType = xenStoreDomainGetOSType,
|
|
||||||
.xenDomainGetMaxMemory = xenStoreDomainGetMaxMemory,
|
.xenDomainGetMaxMemory = xenStoreDomainGetMaxMemory,
|
||||||
.xenDomainSetMemory = xenStoreDomainSetMemory,
|
.xenDomainSetMemory = xenStoreDomainSetMemory,
|
||||||
.xenDomainGetInfo = xenStoreGetDomainInfo,
|
.xenDomainGetInfo = xenStoreGetDomainInfo,
|
||||||
@ -142,63 +140,6 @@ virDomainDoStoreWrite(virDomainPtr domain, const char *path, const char *value)
|
|||||||
return ret;
|
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:
|
* xenStoreDomainGetVNCPort:
|
||||||
* @conn: the hypervisor connection
|
* @conn: the hypervisor connection
|
||||||
|
Loading…
Reference in New Issue
Block a user