提交 758aea30 编写于 作者: D Daniel P. Berrange

Simplify the Xen domain attach/dettach driver methods

Make the domain attach/dettach driver methods directly call
into either the XenD or XM drivers
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 6e661001
......@@ -84,7 +84,6 @@ xenUnifiedDomainGetVcpus(virDomainPtr dom,
static struct xenUnifiedDriver const * const drivers[XEN_UNIFIED_NR_DRIVERS] = {
[XEN_UNIFIED_HYPERVISOR_OFFSET] = &xenHypervisorDriver,
[XEN_UNIFIED_XEND_OFFSET] = &xenDaemonDriver,
[XEN_UNIFIED_XM_OFFSET] = &xenXMDriver,
};
static bool is_privileged = false;
......@@ -1408,7 +1407,6 @@ static int
xenUnifiedDomainAttachDevice(virDomainPtr dom, const char *xml)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
int i;
unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_LIVE;
/*
......@@ -1416,14 +1414,13 @@ xenUnifiedDomainAttachDevice(virDomainPtr dom, const char *xml)
* config without touching persistent config, we add the extra flag here
* to make this API work
*/
if (priv->opened[XEN_UNIFIED_XEND_OFFSET] &&
priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
if (priv->opened[i] && drivers[i]->xenDomainAttachDeviceFlags &&
drivers[i]->xenDomainAttachDeviceFlags(dom, xml, flags) == 0)
return 0;
if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return xenXMDomainAttachDeviceFlags(dom, xml, flags);
else
return xenDaemonAttachDeviceFlags(dom, xml, flags);
return -1;
}
......@@ -1433,21 +1430,17 @@ xenUnifiedDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
int i;
for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
if (priv->opened[i] && drivers[i]->xenDomainAttachDeviceFlags &&
drivers[i]->xenDomainAttachDeviceFlags(dom, xml, flags) == 0)
return 0;
return -1;
if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return xenXMDomainAttachDeviceFlags(dom, xml, flags);
else
return xenDaemonAttachDeviceFlags(dom, xml, flags);
}
static int
xenUnifiedDomainDetachDevice(virDomainPtr dom, const char *xml)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
int i;
unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_LIVE;
/*
......@@ -1455,16 +1448,13 @@ xenUnifiedDomainDetachDevice(virDomainPtr dom, const char *xml)
* config without touching persistent config, we add the extra flag here
* to make this API work
*/
if (priv->opened[XEN_UNIFIED_XEND_OFFSET] &&
priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
if (priv->opened[i] && drivers[i]->xenDomainDetachDeviceFlags &&
drivers[i]->xenDomainDetachDeviceFlags(dom, xml, flags) == 0)
return 0;
return -1;
if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return xenXMDomainDetachDeviceFlags(dom, xml, flags);
else
return xenDaemonDetachDeviceFlags(dom, xml, flags);
}
static int
......@@ -1472,25 +1462,18 @@ xenUnifiedDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
int i;
for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
if (priv->opened[i] && drivers[i]->xenDomainDetachDeviceFlags &&
drivers[i]->xenDomainDetachDeviceFlags(dom, xml, flags) == 0)
return 0;
return -1;
if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return xenXMDomainDetachDeviceFlags(dom, xml, flags);
else
return xenDaemonDetachDeviceFlags(dom, xml, flags);
}
static int
xenUnifiedDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
if (priv->opened[XEN_UNIFIED_XEND_OFFSET])
return xenDaemonUpdateDeviceFlags(dom, xml, flags);
return -1;
return xenDaemonUpdateDeviceFlags(dom, xml, flags);
}
static int
......
......@@ -93,8 +93,6 @@ extern int xenRegister (void);
* structure with direct calls in xen_unified.c.
*/
struct xenUnifiedDriver {
virDrvDomainAttachDeviceFlags xenDomainAttachDeviceFlags;
virDrvDomainDetachDeviceFlags xenDomainDetachDeviceFlags;
virDrvDomainGetSchedulerType xenDomainGetSchedulerType;
virDrvDomainGetSchedulerParameters xenDomainGetSchedulerParameters;
virDrvDomainSetSchedulerParameters xenDomainSetSchedulerParameters;
......
......@@ -2195,7 +2195,7 @@ xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc)
*
* Returns 0 in case of success, -1 in case of failure.
*/
static int
int
xenDaemonAttachDeviceFlags(virDomainPtr domain,
const char *xml,
unsigned int flags)
......@@ -2218,13 +2218,6 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain,
_("Cannot modify live config if domain is inactive"));
return -1;
}
/* If xendConfigVersion < 3 only live config can be changed */
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Xend version does not support modifying "
"persistent config"));
return -1;
}
} else {
/* Only live config can be changed if xendConfigVersion < 3 */
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4 &&
......@@ -2378,13 +2371,6 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain,
_("Cannot modify live config if domain is inactive"));
return -1;
}
/* If xendConfigVersion < 3 only live config can be changed */
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Xend version does not support modifying "
"persistent config"));
return -1;
}
} else {
/* Only live config can be changed if xendConfigVersion < 3 */
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4 &&
......@@ -2463,7 +2449,7 @@ cleanup:
*
* Returns 0 in case of success, -1 in case of failure.
*/
static int
int
xenDaemonDetachDeviceFlags(virDomainPtr domain,
const char *xml,
unsigned int flags)
......@@ -2485,13 +2471,6 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain,
_("Cannot modify live config if domain is inactive"));
return -1;
}
/* If xendConfigVersion < 3 only live config can be changed */
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Xend version does not support modifying "
"persistent config"));
return -1;
}
} else {
/* Only live config can be changed if xendConfigVersion < 3 */
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4 &&
......@@ -3362,8 +3341,6 @@ xenDaemonDomainBlockPeek(virDomainPtr domain,
}
struct xenUnifiedDriver xenDaemonDriver = {
.xenDomainAttachDeviceFlags = xenDaemonAttachDeviceFlags,
.xenDomainDetachDeviceFlags = xenDaemonDetachDeviceFlags,
.xenDomainGetSchedulerType = xenDaemonGetSchedulerType,
.xenDomainGetSchedulerParameters = xenDaemonGetSchedulerParameters,
.xenDomainSetSchedulerParameters = xenDaemonSetSchedulerParameters,
......
......@@ -114,6 +114,13 @@ int xenDaemonListDefinedDomains(virConnectPtr conn,
char **const names,
int maxnames);
int xenDaemonAttachDeviceFlags(virDomainPtr domain,
const char *xml,
unsigned int flags);
int xenDaemonDetachDeviceFlags(virDomainPtr domain,
const char *xml,
unsigned int flags);
virDomainPtr xenDaemonDomainDefineXML(virConnectPtr xend, const char *sexpr);
int xenDaemonDomainCreate(virDomainPtr domain);
int xenDaemonDomainUndefine(virDomainPtr domain);
......
......@@ -66,10 +66,6 @@
#define XEN_MAX_PHYSICAL_CPU 1024
char * xenXMAutoAssignMac(void);
static int xenXMDomainAttachDeviceFlags(virDomainPtr domain, const char *xml,
unsigned int flags);
static int xenXMDomainDetachDeviceFlags(virDomainPtr domain, const char *xml,
unsigned int flags);
#define XM_REFRESH_INTERVAL 10
......@@ -80,11 +76,6 @@ static int xenXMDomainDetachDeviceFlags(virDomainPtr domain, const char *xml,
#define QEMU_IF_SCRIPT "qemu-ifup"
#define XM_XML_ERROR "Invalid xml"
struct xenUnifiedDriver xenXMDriver = {
.xenDomainAttachDeviceFlags = xenXMDomainAttachDeviceFlags,
.xenDomainDetachDeviceFlags = xenXMDomainDetachDeviceFlags,
};
#ifndef WITH_XEN_INOTIFY
static int xenInotifyActive(virConnectPtr conn ATTRIBUTE_UNUSED)
{
......@@ -1236,7 +1227,7 @@ cleanup:
*
* Returns 0 in case of success, -1 in case of failure.
*/
static int
int
xenXMDomainAttachDeviceFlags(virDomainPtr domain,
const char *xml,
unsigned int flags)
......@@ -1326,7 +1317,7 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain,
*
* Returns 0 in case of success, -1 in case of failure.
*/
static int
int
xenXMDomainDetachDeviceFlags(virDomainPtr domain,
const char *xml,
unsigned int flags)
......
......@@ -30,8 +30,6 @@
# include "virconf.h"
# include "domain_conf.h"
extern struct xenUnifiedDriver xenXMDriver;
int xenXMConfigCacheRefresh (virConnectPtr conn);
int xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename);
int xenXMConfigCacheRemoveFile(virConnectPtr conn, const char *filename);
......@@ -69,4 +67,12 @@ int xenXMDomainBlockPeek (virDomainPtr dom, const char *path, unsigned long long
int xenXMDomainGetAutostart(virDomainPtr dom, int *autostart);
int xenXMDomainSetAutostart(virDomainPtr dom, int autostart);
int xenXMDomainAttachDeviceFlags(virDomainPtr domain,
const char *xml,
unsigned int flags);
int xenXMDomainDetachDeviceFlags(virDomainPtr domain,
const char *xml,
unsigned int flags);
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册