提交 833fe8ab 编写于 作者: E Eric Blake

util: reject unknown flags, and prefer unsigned flags

Silently ignored flags get in the way of new features that
use those flags.  Also, an upcoming syntax check will favor
unsigned flags.

* src/nodeinfo.h (nodeGetCPUStats, nodeGetMemoryStats): Drop
unused attribute.
* src/interface/netcf_driver.c (interfaceOpenInterface)
(interfaceDefineXML, interfaceCreate, interfaceDestroy): Reject
unknown flags.
* src/network/bridge_driver.c (networkOpenNetwork)
(networkGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_driver.c (nwfilterOpen): Likewise.
* src/secret/secret_driver.c (secretOpen, secretDefineXML)
(secretGetXMLDesc, secretSetValue): Likewise.
* src/util/logging.c (virLogDefineFilter, virLogDefineOutput)
(virLogMessage): Likewise; also use unsigned flags.
* src/util/logging.h (virLogDefineFilter, virLogDefineOutput)
(virLogMessage): Change signature.
* src/util/command.c (virExecWithHook): Likewise.
上级 01ed9b56
......@@ -121,10 +121,12 @@ static struct netcf_if *interfaceDriverGetNetcfIF(struct netcf *ncf, virInterfac
static virDrvOpenStatus interfaceOpenInterface(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
struct interface_driver *driverState;
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (VIR_ALLOC(driverState) < 0)
{
virReportOOMError();
......@@ -387,7 +389,7 @@ cleanup:
static virInterfacePtr interfaceDefineXML(virConnectPtr conn,
const char *xml,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
struct interface_driver *driver = conn->interfacePrivateData;
struct netcf_if *iface = NULL;
......@@ -395,6 +397,8 @@ static virInterfacePtr interfaceDefineXML(virConnectPtr conn,
virInterfaceDefPtr ifacedef = NULL;
virInterfacePtr ret = NULL;
virCheckFlags(0, NULL);
interfaceDriverLock(driver);
ifacedef = virInterfaceDefParseString(xml);
......@@ -461,12 +465,14 @@ cleanup:
}
static int interfaceCreate(virInterfacePtr ifinfo,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
struct interface_driver *driver = ifinfo->conn->interfacePrivateData;
struct netcf_if *iface = NULL;
int ret = -1;
virCheckFlags(0, -1);
interfaceDriverLock(driver);
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
......@@ -493,12 +499,14 @@ cleanup:
}
static int interfaceDestroy(virInterfacePtr ifinfo,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
struct interface_driver *driver = ifinfo->conn->interfacePrivateData;
struct netcf_if *iface = NULL;
int ret = -1;
virCheckFlags(0, -1);
interfaceDriverLock(driver);
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
......
......@@ -2010,7 +2010,10 @@ cleanup:
static virDrvOpenStatus networkOpenNetwork(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED) {
unsigned int flags)
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (!driverState)
return VIR_DRV_OPEN_DECLINED;
......@@ -2416,12 +2419,14 @@ cleanup:
}
static char *networkGetXMLDesc(virNetworkPtr net,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
struct network_driver *driver = net->conn->networkPrivateData;
virNetworkObjPtr network;
char *ret = NULL;
virCheckFlags(0, NULL);
networkDriverLock(driver);
network = virNetworkFindByUUID(&driver->networks, net->uuid);
networkDriverUnlock(driver);
......
/*
* nodeinfo.c: Helper routines for OS specific node information
*
* Copyright (C) 2006-2008 Red Hat, Inc.
* Copyright (C) 2006-2008, 2011 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
......@@ -34,12 +34,12 @@ int nodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED,
int cpuNum,
virNodeCPUStatsPtr params,
int *nparams,
unsigned int flags ATTRIBUTE_UNUSED);
unsigned int flags);
int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED,
int cellNum,
virNodeMemoryStatsPtr params,
int *nparams,
unsigned int flags ATTRIBUTE_UNUSED);
unsigned int flags);
int nodeGetCellsFreeMemory(virConnectPtr conn,
unsigned long long *freeMems,
int startCell,
......
......@@ -272,8 +272,10 @@ cleanup:
static virDrvOpenStatus
nwfilterOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (!driverState)
return VIR_DRV_OPEN_DECLINED;
......
......@@ -525,7 +525,10 @@ cleanup:
static virDrvOpenStatus
secretOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED) {
unsigned int flags)
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (driverState == NULL)
return VIR_DRV_OPEN_DECLINED;
......@@ -667,7 +670,7 @@ cleanup:
static virSecretPtr
secretDefineXML(virConnectPtr conn, const char *xml,
unsigned int flags ATTRIBUTE_UNUSED)
unsigned int flags)
{
virSecretDriverStatePtr driver = conn->secretPrivateData;
virSecretPtr ret = NULL;
......@@ -675,6 +678,8 @@ secretDefineXML(virConnectPtr conn, const char *xml,
virSecretDefPtr backup = NULL;
virSecretDefPtr new_attrs;
virCheckFlags(0, NULL);
new_attrs = virSecretDefParseString(xml);
if (new_attrs == NULL)
return NULL;
......@@ -778,12 +783,14 @@ cleanup:
}
static char *
secretGetXMLDesc(virSecretPtr obj, unsigned int flags ATTRIBUTE_UNUSED)
secretGetXMLDesc(virSecretPtr obj, unsigned int flags)
{
virSecretDriverStatePtr driver = obj->conn->secretPrivateData;
char *ret = NULL;
virSecretEntryPtr secret;
virCheckFlags(0, NULL);
secretDriverLock(driver);
secret = secretFindByUUID(driver, obj->uuid);
......@@ -805,7 +812,7 @@ cleanup:
static int
secretSetValue(virSecretPtr obj, const unsigned char *value,
size_t value_size, unsigned int flags ATTRIBUTE_UNUSED)
size_t value_size, unsigned int flags)
{
virSecretDriverStatePtr driver = obj->conn->secretPrivateData;
int ret = -1;
......@@ -813,6 +820,8 @@ secretSetValue(virSecretPtr obj, const unsigned char *value,
size_t old_value_size;
virSecretEntryPtr secret;
virCheckFlags(0, -1);
if (VIR_ALLOC_N(new_value, value_size) < 0) {
virReportOOMError();
return -1;
......
......@@ -289,7 +289,7 @@ virExecWithHook(const char *const*argv,
const fd_set *keepfd,
pid_t *retpid,
int infd, int *outfd, int *errfd,
int flags,
unsigned int flags,
virExecHook hook,
void *data,
char *pidfile)
......
......@@ -481,10 +481,13 @@ static int virLogResetFilters(void) {
* Returns -1 in case of failure or the filter number if successful
*/
int virLogDefineFilter(const char *match, int priority,
int flags ATTRIBUTE_UNUSED) {
unsigned int flags)
{
int i;
char *mdup = NULL;
virCheckFlags(0, -1);
if ((match == NULL) || (priority < VIR_LOG_DEBUG) ||
(priority > VIR_LOG_ERROR))
return -1;
......@@ -579,10 +582,13 @@ static int virLogResetOutputs(void) {
*/
int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c, void *data,
int priority, int dest, const char *name,
int flags ATTRIBUTE_UNUSED) {
unsigned int flags)
{
int ret = -1;
char *ndup = NULL;
virCheckFlags(0, -1);
if (f == NULL)
return -1;
......@@ -683,7 +689,8 @@ virLogVersionString(char **msg,
* the message may be stored, sent to output or just discarded
*/
void virLogMessage(const char *category, int priority, const char *funcname,
long long linenr, int flags, const char *fmt, ...) {
long long linenr, unsigned int flags, const char *fmt, ...)
{
static bool logVersionStderr = true;
char *str = NULL;
char *msg = NULL;
......
......@@ -105,10 +105,11 @@ extern char *virLogGetOutputs(void);
extern int virLogGetDefaultPriority(void);
extern int virLogSetDefaultPriority(int priority);
extern void virLogSetFromEnv(void);
extern int virLogDefineFilter(const char *match, int priority, int flags);
extern int virLogDefineFilter(const char *match, int priority,
unsigned int flags);
extern int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c, void *data,
int priority, int dest, const char *name,
int flags);
unsigned int flags);
/*
* Internal logging API
......@@ -123,7 +124,8 @@ extern int virLogParseDefaultPriority(const char *priority);
extern int virLogParseFilters(const char *filters);
extern int virLogParseOutputs(const char *output);
extern void virLogMessage(const char *category, int priority,
const char *funcname, long long linenr, int flags,
const char *funcname, long long linenr,
unsigned int flags,
const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(6, 7);
extern int virLogSetBufferSize(int size);
extern void virLogEmergencyDumpAll(int signum);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册