提交 ca122578 编写于 作者: E Eric Blake

esx: reject unknown flags

Silently ignored flags get in the way of new features that
use those flags.

Regarding ESX migration flags - right now, ESX silently enforces
VIR_MIGRATE_PERSIST_DEST, VIR_MIGRATE_UNDEFINE_SOURCE, and
VIR_MIGRATE_LIVE, even if those flags were not supplied; it ignored
other flags.  This patch does not change the implied bits (it permits
but does not require them), but enforces only the supported bits.
If further cleanup is needed to be more particular about migration
flags, that should be a separate patch.

* src/esx/esx_device_monitor.c (esxDeviceOpen): Reject unknown
flags.
* src/esx/esx_driver.c (esxOpen, esxDomainReboot)
(esxDomainXMLFromNative, esxDomainXMLToNative)
(esxDomainMigratePrepare, esxDomainMigratePerform)
(esxDomainMigrateFinish): Likewise.
* src/esx/esx_interface_driver.c (esxInterfaceOpen): Likewise.
* src/esx/esx_network_driver.c (esxNetworkOpen): Likewise.
* src/esx/esx_nwfilter_driver.c (esxNWFilterOpen): Likewise.
* src/esx/esx_secret_driver.c (esxSecretOpen): Likewise.
* src/esx/esx_storage_driver.c (esxStorageOpen): Likewise.
上级 ca92c857
......@@ -42,8 +42,10 @@
static virDrvOpenStatus
esxDeviceOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
return VIR_DRV_OPEN_DECLINED;
}
......
......@@ -935,13 +935,15 @@ esxConnectToVCenter(esxPrivate *priv, virConnectAuthPtr auth,
*/
static virDrvOpenStatus
esxOpen(virConnectPtr conn, virConnectAuthPtr auth,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
esxPrivate *priv = NULL;
char *potentialVCenterIpAddress = NULL;
char vCenterIpAddress[NI_MAXHOST] = "";
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
/* Decline if the URI is NULL or the scheme is not one of {vpx|esx|gsx} */
if (conn->uri == NULL || conn->uri->scheme == NULL ||
(STRCASENEQ(conn->uri->scheme, "vpx") &&
......@@ -1890,7 +1892,7 @@ esxDomainShutdown(virDomainPtr domain)
static int
esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED)
esxDomainReboot(virDomainPtr domain, unsigned int flags)
{
int result = -1;
esxPrivate *priv = domain->conn->privateData;
......@@ -1898,6 +1900,8 @@ esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED)
esxVI_String *propertyNameList = NULL;
esxVI_VirtualMachinePowerState powerState;
virCheckFlags(0, -1);
if (esxVI_EnsureSession(priv->primary) < 0) {
return -1;
}
......@@ -2701,6 +2705,8 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
virDomainDefPtr def = NULL;
char *xml = NULL;
/* Flags checked by virDomainDefFormat */
memset(&data, 0, sizeof (data));
if (esxVI_EnsureSession(priv->primary) < 0) {
......@@ -2798,7 +2804,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
static char *
esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
const char *nativeConfig,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
esxPrivate *priv = conn->privateData;
virVMXContext ctx;
......@@ -2806,6 +2812,8 @@ esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
virDomainDefPtr def = NULL;
char *xml = NULL;
virCheckFlags(0, NULL);
memset(&data, 0, sizeof (data));
if (STRNEQ(nativeFormat, "vmware-vmx")) {
......@@ -2838,7 +2846,7 @@ esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
static char *
esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
const char *domainXml,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
esxPrivate *priv = conn->privateData;
int virtualHW_version;
......@@ -2847,6 +2855,8 @@ esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
virDomainDefPtr def = NULL;
char *vmx = NULL;
virCheckFlags(0, NULL);
memset(&data, 0, sizeof (data));
if (STRNEQ(nativeFormat, "vmware-vmx")) {
......@@ -3831,6 +3841,12 @@ esxDomainSetSchedulerParameters(virDomainPtr domain,
return esxDomainSetSchedulerParametersFlags(domain, params, nparams, 0);
}
/* The subset of migration flags we are able to support. */
#define ESX_MIGRATION_FLAGS \
(VIR_MIGRATE_PERSIST_DEST | \
VIR_MIGRATE_UNDEFINE_SOURCE | \
VIR_MIGRATE_LIVE | \
VIR_MIGRATE_PAUSED)
static int
esxDomainMigratePrepare(virConnectPtr dconn,
......@@ -3838,12 +3854,14 @@ esxDomainMigratePrepare(virConnectPtr dconn,
int *cookielen ATTRIBUTE_UNUSED,
const char *uri_in ATTRIBUTE_UNUSED,
char **uri_out,
unsigned long flags ATTRIBUTE_UNUSED,
unsigned long flags,
const char *dname ATTRIBUTE_UNUSED,
unsigned long resource ATTRIBUTE_UNUSED)
{
esxPrivate *priv = dconn->privateData;
virCheckFlags(ESX_MIGRATION_FLAGS, -1);
if (uri_in == NULL) {
if (virAsprintf(uri_out, "vpxmigr://%s/%s/%s",
priv->vCenter->ipAddress,
......@@ -3864,7 +3882,7 @@ esxDomainMigratePerform(virDomainPtr domain,
const char *cookie ATTRIBUTE_UNUSED,
int cookielen ATTRIBUTE_UNUSED,
const char *uri,
unsigned long flags ATTRIBUTE_UNUSED,
unsigned long flags,
const char *dname,
unsigned long bandwidth ATTRIBUTE_UNUSED)
{
......@@ -3882,6 +3900,8 @@ esxDomainMigratePerform(virDomainPtr domain,
esxVI_TaskInfoState taskInfoState;
char *taskInfoErrorMessage = NULL;
virCheckFlags(ESX_MIGRATION_FLAGS, -1);
if (priv->vCenter == NULL) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
_("Migration not possible without a vCenter"));
......@@ -4010,8 +4030,10 @@ esxDomainMigrateFinish(virConnectPtr dconn, const char *dname,
const char *cookie ATTRIBUTE_UNUSED,
int cookielen ATTRIBUTE_UNUSED,
const char *uri ATTRIBUTE_UNUSED,
unsigned long flags ATTRIBUTE_UNUSED)
unsigned long flags)
{
virCheckFlags(ESX_MIGRATION_FLAGS, NULL);
return esxDomainLookupByName(dconn, dname);
}
......
......@@ -42,8 +42,10 @@
static virDrvOpenStatus
esxInterfaceOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
return VIR_DRV_OPEN_DECLINED;
}
......
......@@ -42,8 +42,10 @@
static virDrvOpenStatus
esxNetworkOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
return VIR_DRV_OPEN_DECLINED;
}
......
......@@ -42,8 +42,10 @@
static virDrvOpenStatus
esxNWFilterOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
return VIR_DRV_OPEN_DECLINED;
}
......
......@@ -40,8 +40,10 @@
static virDrvOpenStatus
esxSecretOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
return VIR_DRV_OPEN_DECLINED;
}
......
......@@ -104,8 +104,10 @@ esxStoragePoolLookupType(esxVI_Context *ctx, const char *poolName,
static virDrvOpenStatus
esxStorageOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
return VIR_DRV_OPEN_DECLINED;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册