Replace use of qemudLog with logging.h APIs/macros

This commit is contained in:
Daniel P. Berrange 2009-03-03 11:40:08 +00:00
parent 10e3148f0a
commit b756b005ec
5 changed files with 52 additions and 55 deletions

View File

@ -1,3 +1,9 @@
Tue Mar 3 11:31:13 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
* src/iptables.c, src/qemu_conf.c, src/qemu_driver.c,
src/uuid.c: Replace qemudLogging with calls to logging.h
APIs
Tue Mar 3 12:22:51 +0100 2009 Jim Meyering <meyering@redhat.com> Tue Mar 3 12:22:51 +0100 2009 Jim Meyering <meyering@redhat.com>
avoid file descriptor leak when fd == 0 avoid file descriptor leak when fd == 0

View File

@ -45,8 +45,7 @@
#include "util.h" #include "util.h"
#include "memory.h" #include "memory.h"
#include "virterror_internal.h" #include "virterror_internal.h"
#include "logging.h"
#define qemudLog(level, msg...) fprintf(stderr, msg)
enum { enum {
ADD = 0, ADD = 0,
@ -101,7 +100,7 @@ notifyRulesUpdated(const char *table,
char ebuf[1024]; char ebuf[1024];
if (virRun(NULL, argv, NULL) < 0) if (virRun(NULL, argv, NULL) < 0)
qemudLog(QEMUD_WARN, _("Failed to run '%s %s': %s"), VIR_WARN(_("Failed to run '%s %s': %s"),
LOKKIT_PATH, arg, virStrerror(errno, ebuf, sizeof ebuf)); LOKKIT_PATH, arg, virStrerror(errno, ebuf, sizeof ebuf));
} }
@ -149,8 +148,8 @@ notifyRulesRemoved(const char *table,
len = virFileReadAll(SYSCONF_DIR "/sysconfig/system-config-firewall", len = virFileReadAll(SYSCONF_DIR "/sysconfig/system-config-firewall",
MAX_FILE_LEN, &content); MAX_FILE_LEN, &content);
if (len < 0) { if (len < 0) {
qemudLog(QEMUD_WARN, "%s", _("Failed to read " SYSCONF_DIR VIR_WARN("%s", _("Failed to read " SYSCONF_DIR
"/sysconfig/system-config-firewall")); "/sysconfig/system-config-firewall"));
return; return;
} }
@ -178,8 +177,8 @@ notifyRulesRemoved(const char *table,
write_error:; write_error:;
char ebuf[1024]; char ebuf[1024];
qemudLog(QEMUD_WARN, _("Failed to write to " SYSCONF_DIR VIR_WARN(_("Failed to write to " SYSCONF_DIR
"/sysconfig/system-config-firewall : %s"), "/sysconfig/system-config-firewall : %s"),
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
if (f) if (f)
fclose(f); fclose(f);
@ -244,13 +243,13 @@ iptRulesSave(iptRules *rules)
char ebuf[1024]; char ebuf[1024];
if ((err = virFileMakePath(rules->dir))) { if ((err = virFileMakePath(rules->dir))) {
qemudLog(QEMUD_WARN, _("Failed to create directory %s : %s"), VIR_WARN(_("Failed to create directory %s : %s"),
rules->dir, virStrerror(err, ebuf, sizeof ebuf)); rules->dir, virStrerror(err, ebuf, sizeof ebuf));
return; return;
} }
if ((err = writeRules(rules->path, rules->rules, rules->nrules))) { if ((err = writeRules(rules->path, rules->rules, rules->nrules))) {
qemudLog(QEMUD_WARN, _("Failed to saves iptables rules to %s : %s"), VIR_WARN(_("Failed to saves iptables rules to %s : %s"),
rules->path, virStrerror(err, ebuf, sizeof ebuf)); rules->path, virStrerror(err, ebuf, sizeof ebuf));
return; return;
} }
@ -551,8 +550,7 @@ iptRulesReload(iptRules *rules)
rule->argv[rule->command_idx] = (char *) "--delete"; rule->argv[rule->command_idx] = (char *) "--delete";
if (virRun(NULL, rule->argv, NULL) < 0) if (virRun(NULL, rule->argv, NULL) < 0)
qemudLog(QEMUD_WARN, VIR_WARN(_("Failed to remove iptables rule '%s'"
_("Failed to remove iptables rule '%s'"
" from chain '%s' in table '%s': %s"), " from chain '%s' in table '%s': %s"),
rule->rule, rules->chain, rules->table, rule->rule, rules->chain, rules->table,
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
@ -562,8 +560,8 @@ iptRulesReload(iptRules *rules)
for (i = 0; i < rules->nrules; i++) for (i = 0; i < rules->nrules; i++)
if (virRun(NULL, rules->rules[i].argv, NULL) < 0) if (virRun(NULL, rules->rules[i].argv, NULL) < 0)
qemudLog(QEMUD_WARN, _("Failed to add iptables rule '%s'" VIR_WARN(_("Failed to add iptables rule '%s'"
" to chain '%s' in table '%s': %s"), " to chain '%s' in table '%s': %s"),
rules->rules[i].rule, rules->chain, rules->table, rules->rules[i].rule, rules->chain, rules->table,
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
} }

View File

@ -47,6 +47,7 @@
#include "datatypes.h" #include "datatypes.h"
#include "xml.h" #include "xml.h"
#include "nodeinfo.h" #include "nodeinfo.h"
#include "logging.h"
#define VIR_FROM_THIS VIR_FROM_QEMU #define VIR_FROM_THIS VIR_FROM_QEMU
@ -77,8 +78,6 @@ VIR_ENUM_IMPL(qemuDiskCacheV2, VIR_DOMAIN_DISK_CACHE_LAST,
"writeback"); "writeback");
#define qemudLog(level, msg...) fprintf(stderr, msg)
int qemudLoadDriverConfig(struct qemud_driver *driver, int qemudLoadDriverConfig(struct qemud_driver *driver,
const char *filename) { const char *filename) {
virConfPtr conf; virConfPtr conf;
@ -469,17 +468,15 @@ rewait:
if (errno == EINTR) if (errno == EINTR)
goto rewait; goto rewait;
qemudLog(QEMUD_ERR, VIR_ERROR(_("Unexpected exit status from qemu %d pid %lu"),
_("Unexpected exit status from qemu %d pid %lu"), WEXITSTATUS(status), (unsigned long)child);
WEXITSTATUS(status), (unsigned long)child);
ret = -1; ret = -1;
} }
/* Check & log unexpected exit status, but don't fail, /* Check & log unexpected exit status, but don't fail,
* as there's really no need to throw an error if we did * as there's really no need to throw an error if we did
* actually read a valid version number above */ * actually read a valid version number above */
if (WEXITSTATUS(status) != 0) { if (WEXITSTATUS(status) != 0) {
qemudLog(QEMUD_WARN, VIR_WARN(_("Unexpected exit status '%d', qemu probably failed"),
_("Unexpected exit status '%d', qemu probably failed"),
WEXITSTATUS(status)); WEXITSTATUS(status));
} }

View File

@ -82,8 +82,6 @@
static int qemudShutdown(void); static int qemudShutdown(void);
#define qemudLog(level, msg...) fprintf(stderr, msg)
static void qemuDriverLock(struct qemud_driver *driver) static void qemuDriverLock(struct qemud_driver *driver)
{ {
virMutexLock(&driver->lock); virMutexLock(&driver->lock);
@ -220,9 +218,9 @@ qemudAutostartConfigs(struct qemud_driver *driver) {
int ret = qemudStartVMDaemon(conn, driver, vm, NULL, -1); int ret = qemudStartVMDaemon(conn, driver, vm, NULL, -1);
if (ret < 0) { if (ret < 0) {
virErrorPtr err = virGetLastError(); virErrorPtr err = virGetLastError();
qemudLog(QEMUD_ERROR, _("Failed to autostart VM '%s': %s\n"), VIR_ERROR(_("Failed to autostart VM '%s': %s\n"),
vm->def->name, vm->def->name,
err ? err->message : NULL); err ? err->message : NULL);
} else { } else {
virDomainEventPtr event = virDomainEventPtr event =
virDomainEventNewFromObj(vm, virDomainEventNewFromObj(vm,
@ -306,8 +304,8 @@ qemudReconnectVMs(struct qemud_driver *driver)
if ((config = virDomainConfigFile(NULL, if ((config = virDomainConfigFile(NULL,
driver->stateDir, driver->stateDir,
vm->def->name)) == NULL) { vm->def->name)) == NULL) {
qemudLog(QEMUD_ERROR, _("Failed to read domain status for %s\n"), VIR_ERROR(_("Failed to read domain status for %s\n"),
vm->def->name); vm->def->name);
goto next_error; goto next_error;
} }
@ -316,14 +314,14 @@ qemudReconnectVMs(struct qemud_driver *driver)
vm->newDef = vm->def; vm->newDef = vm->def;
vm->def = status->def; vm->def = status->def;
} else { } else {
qemudLog(QEMUD_ERROR, _("Failed to parse domain status for %s\n"), VIR_ERROR(_("Failed to parse domain status for %s\n"),
vm->def->name); vm->def->name);
goto next_error; goto next_error;
} }
if ((rc = qemudOpenMonitor(NULL, driver, vm, status->monitorpath, 1)) != 0) { if ((rc = qemudOpenMonitor(NULL, driver, vm, status->monitorpath, 1)) != 0) {
qemudLog(QEMUD_ERROR, _("Failed to reconnect monitor for %s: %d\n"), VIR_ERROR(_("Failed to reconnect monitor for %s: %d\n"),
vm->def->name, rc); vm->def->name, rc);
goto next_error; goto next_error;
} }
@ -369,7 +367,7 @@ qemudStartup(void) {
return -1; return -1;
if (virMutexInit(&qemu_driver->lock) < 0) { if (virMutexInit(&qemu_driver->lock) < 0) {
qemudLog(QEMUD_ERROR, "%s", _("cannot initialize mutex")); VIR_ERROR("%s", _("cannot initialize mutex"));
VIR_FREE(qemu_driver); VIR_FREE(qemu_driver);
return -1; return -1;
} }
@ -422,8 +420,8 @@ qemudStartup(void) {
if (virFileMakePath(qemu_driver->stateDir) < 0) { if (virFileMakePath(qemu_driver->stateDir) < 0) {
char ebuf[1024]; char ebuf[1024];
qemudLog(QEMUD_ERROR, _("Failed to create state dir '%s': %s\n"), VIR_ERROR(_("Failed to create state dir '%s': %s\n"),
qemu_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf)); qemu_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
goto error; goto error;
} }
@ -901,7 +899,7 @@ static int qemudWaitForMonitor(virConnectPtr conn,
"console", 3); "console", 3);
if (close(logfd) < 0) { if (close(logfd) < 0) {
char ebuf[1024]; char ebuf[1024];
qemudLog(QEMUD_WARN, _("Unable to close logfile: %s\n"), VIR_WARN(_("Unable to close logfile: %s\n"),
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
} }
@ -1299,29 +1297,29 @@ static int qemudStartVMDaemon(virConnectPtr conn,
tmp = progenv; tmp = progenv;
while (*tmp) { while (*tmp) {
if (safewrite(vm->logfile, *tmp, strlen(*tmp)) < 0) if (safewrite(vm->logfile, *tmp, strlen(*tmp)) < 0)
qemudLog(QEMUD_WARN, _("Unable to write envv to logfile: %s\n"), VIR_WARN(_("Unable to write envv to logfile: %s\n"),
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
if (safewrite(vm->logfile, " ", 1) < 0) if (safewrite(vm->logfile, " ", 1) < 0)
qemudLog(QEMUD_WARN, _("Unable to write envv to logfile: %s\n"), VIR_WARN(_("Unable to write envv to logfile: %s\n"),
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
tmp++; tmp++;
} }
tmp = argv; tmp = argv;
while (*tmp) { while (*tmp) {
if (safewrite(vm->logfile, *tmp, strlen(*tmp)) < 0) if (safewrite(vm->logfile, *tmp, strlen(*tmp)) < 0)
qemudLog(QEMUD_WARN, _("Unable to write argv to logfile: %s\n"), VIR_WARN(_("Unable to write argv to logfile: %s\n"),
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
if (safewrite(vm->logfile, " ", 1) < 0) if (safewrite(vm->logfile, " ", 1) < 0)
qemudLog(QEMUD_WARN, _("Unable to write argv to logfile: %s\n"), VIR_WARN(_("Unable to write argv to logfile: %s\n"),
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
tmp++; tmp++;
} }
if (safewrite(vm->logfile, "\n", 1) < 0) if (safewrite(vm->logfile, "\n", 1) < 0)
qemudLog(QEMUD_WARN, _("Unable to write argv to logfile: %s\n"), VIR_WARN(_("Unable to write argv to logfile: %s\n"),
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
if ((pos = lseek(vm->logfile, 0, SEEK_END)) < 0) if ((pos = lseek(vm->logfile, 0, SEEK_END)) < 0)
qemudLog(QEMUD_WARN, _("Unable to seek to end of logfile: %s\n"), VIR_WARN(_("Unable to seek to end of logfile: %s\n"),
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
for (i = 0 ; i < ntapfds ; i++) for (i = 0 ; i < ntapfds ; i++)
@ -1399,7 +1397,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
if (!virDomainIsActive(vm)) if (!virDomainIsActive(vm))
return; return;
qemudLog(QEMUD_DEBUG, _("Shutting down VM '%s'\n"), vm->def->name); VIR_DEBUG(_("Shutting down VM '%s'\n"), vm->def->name);
if (virKillProcess(vm->pid, 0) == 0 && if (virKillProcess(vm->pid, 0) == 0 &&
virKillProcess(vm->pid, SIGTERM) < 0) virKillProcess(vm->pid, SIGTERM) < 0)
@ -1414,7 +1412,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
if (close(vm->logfile) < 0) { if (close(vm->logfile) < 0) {
char ebuf[1024]; char ebuf[1024];
qemudLog(QEMUD_WARN, _("Unable to close logfile: %s\n"), VIR_WARN(_("Unable to close logfile: %s\n"),
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
} }
if (vm->monitor != -1) if (vm->monitor != -1)
@ -1426,7 +1424,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
virKillProcess(vm->pid, SIGKILL); virKillProcess(vm->pid, SIGKILL);
if (qemudRemoveDomainStatus(conn, driver, vm) < 0) { if (qemudRemoveDomainStatus(conn, driver, vm) < 0) {
qemudLog(QEMUD_WARN, _("Failed to remove domain status for %s"), VIR_WARN(_("Failed to remove domain status for %s"),
vm->def->name); vm->def->name);
} }
vm->pid = -1; vm->pid = -1;
@ -1473,8 +1471,8 @@ qemudDispatchVMEvent(int watch, int fd, int events, void *opaque) {
if (events & (VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR)) if (events & (VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR))
quit = 1; quit = 1;
else { else {
qemudLog(QEMUD_ERROR, _("unhandled fd event %d for %s"), VIR_ERROR(_("unhandled fd event %d for %s"),
events, vm->def->name); events, vm->def->name);
failed = 1; failed = 1;
} }
} }
@ -1587,7 +1585,7 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm,
/* Log, but ignore failures to write logfile for VM */ /* Log, but ignore failures to write logfile for VM */
if (safewrite(vm->logfile, buf, strlen(buf)) < 0) { if (safewrite(vm->logfile, buf, strlen(buf)) < 0) {
char ebuf[1024]; char ebuf[1024];
qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s\n"), VIR_WARN(_("Unable to log VM console data: %s\n"),
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
} }
@ -1599,7 +1597,7 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm,
/* Log, but ignore failures to write logfile for VM */ /* Log, but ignore failures to write logfile for VM */
if (safewrite(vm->logfile, buf, strlen(buf)) < 0) { if (safewrite(vm->logfile, buf, strlen(buf)) < 0) {
char ebuf[1024]; char ebuf[1024];
qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s\n"), VIR_WARN(_("Unable to log VM console data: %s\n"),
virStrerror(errno, ebuf, sizeof ebuf)); virStrerror(errno, ebuf, sizeof ebuf));
} }
VIR_FREE(buf); VIR_FREE(buf);
@ -3380,7 +3378,7 @@ static int qemudDomainAttachPciDiskDevice(virConnectPtr conn,
s += strlen(PCI_ATTACH_OK_MSG); s += strlen(PCI_ATTACH_OK_MSG);
if (virStrToLong_i ((const char*)s, &dummy, 10, &dev->data.disk->slotnum) == -1) if (virStrToLong_i ((const char*)s, &dummy, 10, &dev->data.disk->slotnum) == -1)
qemudLog(QEMUD_WARN, "%s", _("Unable to parse slot number\n")); VIR_WARN("%s", _("Unable to parse slot number\n"));
} else { } else {
qemudReportError (conn, dom, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError (conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
_("adding %s disk failed"), type); _("adding %s disk failed"), type);
@ -4512,8 +4510,8 @@ cleanup:
* overwrite the previous error, though, so we just throw something * overwrite the previous error, though, so we just throw something
* to the logs and hope for the best * to the logs and hope for the best
*/ */
qemudLog(QEMUD_ERROR, _("Failed to resume guest %s after failure\n"), VIR_ERROR(_("Failed to resume guest %s after failure\n"),
vm->def->name); vm->def->name);
} }
else { else {
DEBUG ("cont reply: %s", info); DEBUG ("cont reply: %s", info);

View File

@ -37,8 +37,7 @@
#include "internal.h" #include "internal.h"
#include "util.h" #include "util.h"
#include "virterror_internal.h" #include "virterror_internal.h"
#include "logging.h"
#define qemudLog(level, msg...) fprintf(stderr, msg)
#ifndef ENODATA #ifndef ENODATA
#define ENODATA EIO #define ENODATA EIO
@ -102,8 +101,7 @@ virUUIDGenerate(unsigned char *uuid)
if ((err = virUUIDGenerateRandomBytes(uuid, VIR_UUID_BUFLEN))) { if ((err = virUUIDGenerateRandomBytes(uuid, VIR_UUID_BUFLEN))) {
char ebuf[1024]; char ebuf[1024];
qemudLog(QEMUD_WARN, VIR_WARN(_("Falling back to pseudorandom UUID,"
_("Falling back to pseudorandom UUID,"
" failed to generate random bytes: %s"), " failed to generate random bytes: %s"),
virStrerror(err, ebuf, sizeof ebuf)); virStrerror(err, ebuf, sizeof ebuf));
} }