mirror of https://gitee.com/openkylin/libvirt.git
virtlogd: convert to typedef virConf accessors
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
2666b2905f
commit
46dbc97e65
|
@ -88,7 +88,6 @@ src/locking/lock_driver_sanlock.c
|
||||||
src/locking/lock_manager.c
|
src/locking/lock_manager.c
|
||||||
src/locking/sanlock_helper.c
|
src/locking/sanlock_helper.c
|
||||||
src/logging/log_daemon.c
|
src/logging/log_daemon.c
|
||||||
src/logging/log_daemon_config.c
|
|
||||||
src/logging/log_daemon_dispatch.c
|
src/logging/log_daemon_dispatch.c
|
||||||
src/logging/log_handler.c
|
src/logging/log_handler.c
|
||||||
src/logging/log_manager.c
|
src/logging/log_manager.c
|
||||||
|
|
|
@ -38,61 +38,6 @@
|
||||||
VIR_LOG_INIT("logging.log_daemon_config");
|
VIR_LOG_INIT("logging.log_daemon_config");
|
||||||
|
|
||||||
|
|
||||||
/* A helper function used by each of the following macros. */
|
|
||||||
static int
|
|
||||||
checkType(virConfValuePtr p, const char *filename,
|
|
||||||
const char *key, virConfType required_type)
|
|
||||||
{
|
|
||||||
if (p->type != required_type) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
||||||
_("remoteReadConfigFile: %s: %s: invalid type:"
|
|
||||||
" got %s; expected %s"), filename, key,
|
|
||||||
virConfTypeToString(p->type),
|
|
||||||
virConfTypeToString(required_type));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If there is no config data for the key, #var_name, then do nothing.
|
|
||||||
If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds,
|
|
||||||
store the result in var_name. Otherwise, (i.e. invalid type, or VIR_STRDUP
|
|
||||||
failure), give a diagnostic and "goto" the cleanup-and-fail label. */
|
|
||||||
#define GET_CONF_STR(conf, filename, var_name) \
|
|
||||||
do { \
|
|
||||||
virConfValuePtr p = virConfGetValue(conf, #var_name); \
|
|
||||||
if (p) { \
|
|
||||||
if (checkType(p, filename, #var_name, VIR_CONF_STRING) < 0) \
|
|
||||||
goto error; \
|
|
||||||
VIR_FREE(data->var_name); \
|
|
||||||
if (VIR_STRDUP(data->var_name, p->str) < 0) \
|
|
||||||
goto error; \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/* Like GET_CONF_STR, but for signed integer values. */
|
|
||||||
#define GET_CONF_INT(conf, filename, var_name) \
|
|
||||||
do { \
|
|
||||||
virConfValuePtr p = virConfGetValue(conf, #var_name); \
|
|
||||||
if (p) { \
|
|
||||||
if (p->type != VIR_CONF_ULONG && \
|
|
||||||
checkType(p, filename, #var_name, VIR_CONF_LONG) < 0) \
|
|
||||||
goto error; \
|
|
||||||
data->var_name = p->l; \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/* Like GET_CONF_STR, but for unsigned integer values. */
|
|
||||||
#define GET_CONF_UINT(conf, filename, var_name) \
|
|
||||||
do { \
|
|
||||||
virConfValuePtr p = virConfGetValue(conf, #var_name); \
|
|
||||||
if (p) { \
|
|
||||||
if (checkType(p, filename, #var_name, VIR_CONF_ULONG) < 0) \
|
|
||||||
goto error; \
|
|
||||||
data->var_name = p->l; \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
int
|
int
|
||||||
virLogDaemonConfigFilePath(bool privileged, char **configfile)
|
virLogDaemonConfigFilePath(bool privileged, char **configfile)
|
||||||
{
|
{
|
||||||
|
@ -148,21 +93,22 @@ virLogDaemonConfigFree(virLogDaemonConfigPtr data)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virLogDaemonConfigLoadOptions(virLogDaemonConfigPtr data,
|
virLogDaemonConfigLoadOptions(virLogDaemonConfigPtr data,
|
||||||
const char *filename,
|
|
||||||
virConfPtr conf)
|
virConfPtr conf)
|
||||||
{
|
{
|
||||||
GET_CONF_UINT(conf, filename, log_level);
|
if (virConfGetValueUInt(conf, "log_level", &data->log_level) < 0)
|
||||||
GET_CONF_STR(conf, filename, log_filters);
|
return -1;
|
||||||
GET_CONF_STR(conf, filename, log_outputs);
|
if (virConfGetValueString(conf, "log_filters", &data->log_filters) < 0)
|
||||||
GET_CONF_UINT(conf, filename, max_clients);
|
return -1;
|
||||||
|
if (virConfGetValueString(conf, "log_outputs", &data->log_filters) < 0)
|
||||||
GET_CONF_UINT(conf, filename, max_size);
|
return -1;
|
||||||
GET_CONF_UINT(conf, filename, max_backups);
|
if (virConfGetValueUInt(conf, "max_clients", &data->max_clients) < 0)
|
||||||
|
return -1;
|
||||||
|
if (virConfGetValueSizeT(conf, "max_size", &data->max_size) < 0)
|
||||||
|
return -1;
|
||||||
|
if (virConfGetValueSizeT(conf, "max_backups", &data->max_backups) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,23 +131,7 @@ virLogDaemonConfigLoadFile(virLogDaemonConfigPtr data,
|
||||||
if (!conf)
|
if (!conf)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = virLogDaemonConfigLoadOptions(data, filename, conf);
|
ret = virLogDaemonConfigLoadOptions(data, conf);
|
||||||
virConfFree(conf);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int virLogDaemonConfigLoadData(virLogDaemonConfigPtr data,
|
|
||||||
const char *filename,
|
|
||||||
const char *filedata)
|
|
||||||
{
|
|
||||||
virConfPtr conf;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
conf = virConfReadMem(filedata, strlen(filedata), 0);
|
|
||||||
if (!conf)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
ret = virLogDaemonConfigLoadOptions(data, filename, conf);
|
|
||||||
virConfFree(conf);
|
virConfFree(conf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,10 @@ typedef struct _virLogDaemonConfig virLogDaemonConfig;
|
||||||
typedef virLogDaemonConfig *virLogDaemonConfigPtr;
|
typedef virLogDaemonConfig *virLogDaemonConfigPtr;
|
||||||
|
|
||||||
struct _virLogDaemonConfig {
|
struct _virLogDaemonConfig {
|
||||||
int log_level;
|
unsigned int log_level;
|
||||||
char *log_filters;
|
char *log_filters;
|
||||||
char *log_outputs;
|
char *log_outputs;
|
||||||
int max_clients;
|
unsigned int max_clients;
|
||||||
|
|
||||||
size_t max_backups;
|
size_t max_backups;
|
||||||
size_t max_size;
|
size_t max_size;
|
||||||
|
@ -46,8 +46,5 @@ void virLogDaemonConfigFree(virLogDaemonConfigPtr data);
|
||||||
int virLogDaemonConfigLoadFile(virLogDaemonConfigPtr data,
|
int virLogDaemonConfigLoadFile(virLogDaemonConfigPtr data,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
bool allow_missing);
|
bool allow_missing);
|
||||||
int virLogDaemonConfigLoadData(virLogDaemonConfigPtr data,
|
|
||||||
const char *filename,
|
|
||||||
const char *filedata);
|
|
||||||
|
|
||||||
#endif /* __LIBVIRTD_CONFIG_H__ */
|
#endif /* __LIBVIRTD_CONFIG_H__ */
|
||||||
|
|
Loading…
Reference in New Issue