mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 10:31:16 +00:00
qemu_driver.c: use virReportSystemError in place of some qemudLog uses
...thus eliminating many uses of strerror. (kvmGetMaxVCPUs): Rather than merely warning, diagnose an error and return -1 upon failure to open KVM_DEVICE. Suggested by Daniel P. Berrange.
This commit is contained in:
parent
7bc569dda9
commit
caea9c00e3
@ -1,3 +1,11 @@
|
|||||||
|
Thu, 5 Feb 2009 17:03:35 +0100 Jim Meyering <meyering@redhat.com>
|
||||||
|
|
||||||
|
qemu_driver.c: use virReportSystemError in place of some qemudLog uses
|
||||||
|
...thus eliminating many uses of strerror.
|
||||||
|
(kvmGetMaxVCPUs): Rather than merely warning, diagnose an error
|
||||||
|
and return -1 upon failure to open KVM_DEVICE. Suggested by
|
||||||
|
Daniel P. Berrange.
|
||||||
|
|
||||||
Thu, 5 Feb 2009 17:03:34 +0100 Jim Meyering <meyering@redhat.com>
|
Thu, 5 Feb 2009 17:03:34 +0100 Jim Meyering <meyering@redhat.com>
|
||||||
|
|
||||||
publicize virStrerror
|
publicize virStrerror
|
||||||
|
@ -207,22 +207,21 @@ qemudLogReadFD(virConnectPtr conn, const char* logDir, const char* name, off_t p
|
|||||||
|
|
||||||
|
|
||||||
if ((fd = open(logfile, logmode)) < 0) {
|
if ((fd = open(logfile, logmode)) < 0) {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("failed to create logfile %s: %s"),
|
_("failed to create logfile %s"),
|
||||||
logfile, strerror(errno));
|
logfile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (qemudSetCloseExec(fd) < 0) {
|
if (qemudSetCloseExec(fd) < 0) {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("Unable to set VM logfile close-on-exec flag: %s"),
|
_("Unable to set VM logfile close-on-exec flag"));
|
||||||
strerror(errno));
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (lseek(fd, pos, SEEK_SET) < 0) {
|
if (lseek(fd, pos, SEEK_SET) < 0) {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Unable to seek to %lld in %s: %s"),
|
_("Unable to seek to %lld in %s"),
|
||||||
(long long) pos, logfile, strerror(errno));
|
(long long) pos, logfile);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
@ -250,7 +249,7 @@ 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_ERR, _("Failed to autostart VM '%s': %s\n"),
|
qemudLog(QEMUD_ERROR, _("Failed to autostart VM '%s': %s\n"),
|
||||||
vm->def->name,
|
vm->def->name,
|
||||||
err ? err->message : NULL);
|
err ? err->message : NULL);
|
||||||
} else {
|
} else {
|
||||||
@ -336,7 +335,7 @@ 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_ERR, _("Failed to read domain status for %s\n"),
|
qemudLog(QEMUD_ERROR, _("Failed to read domain status for %s\n"),
|
||||||
vm->def->name);
|
vm->def->name);
|
||||||
goto next_error;
|
goto next_error;
|
||||||
}
|
}
|
||||||
@ -346,13 +345,13 @@ 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_ERR, _("Failed to parse domain status for %s\n"),
|
qemudLog(QEMUD_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_ERR, _("Failed to reconnect monitor for %s: %d\n"),
|
qemudLog(QEMUD_ERROR, _("Failed to reconnect monitor for %s: %d\n"),
|
||||||
vm->def->name, rc);
|
vm->def->name, rc);
|
||||||
goto next_error;
|
goto next_error;
|
||||||
}
|
}
|
||||||
@ -451,7 +450,7 @@ qemudStartup(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(qemu_driver->stateDir) < 0) {
|
if (virFileMakePath(qemu_driver->stateDir) < 0) {
|
||||||
qemudLog(QEMUD_ERR, _("Failed to create state dir '%s': %s\n"),
|
qemudLog(QEMUD_ERROR, _("Failed to create state dir '%s': %s\n"),
|
||||||
qemu_driver->stateDir, strerror(errno));
|
qemu_driver->stateDir, strerror(errno));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -493,7 +492,7 @@ qemudStartup(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_of_memory:
|
out_of_memory:
|
||||||
qemudLog (QEMUD_ERR,
|
qemudLog (QEMUD_ERROR,
|
||||||
"%s", _("qemudStartup: out of memory\n"));
|
"%s", _("qemudStartup: out of memory\n"));
|
||||||
error:
|
error:
|
||||||
if (qemu_driver)
|
if (qemu_driver)
|
||||||
@ -1200,30 +1199,30 @@ 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 %d: %s\n"),
|
qemudLog(QEMUD_WARN, _("Unable to write envv to logfile: %s\n"),
|
||||||
errno, strerror(errno));
|
strerror(errno));
|
||||||
if (safewrite(vm->logfile, " ", 1) < 0)
|
if (safewrite(vm->logfile, " ", 1) < 0)
|
||||||
qemudLog(QEMUD_WARN, _("Unable to write envv to logfile %d: %s\n"),
|
qemudLog(QEMUD_WARN, _("Unable to write envv to logfile: %s\n"),
|
||||||
errno, strerror(errno));
|
strerror(errno));
|
||||||
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 %d: %s\n"),
|
qemudLog(QEMUD_WARN, _("Unable to write argv to logfile: %s\n"),
|
||||||
errno, strerror(errno));
|
strerror(errno));
|
||||||
if (safewrite(vm->logfile, " ", 1) < 0)
|
if (safewrite(vm->logfile, " ", 1) < 0)
|
||||||
qemudLog(QEMUD_WARN, _("Unable to write argv to logfile %d: %s\n"),
|
qemudLog(QEMUD_WARN, _("Unable to write argv to logfile: %s\n"),
|
||||||
errno, strerror(errno));
|
strerror(errno));
|
||||||
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 %d: %s\n"),
|
qemudLog(QEMUD_WARN, _("Unable to write argv to logfile: %s\n"),
|
||||||
errno, strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
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 %d: %s\n"),
|
qemudLog(QEMUD_WARN, _("Unable to seek to end of logfile: %s\n"),
|
||||||
errno, strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
for (i = 0 ; i < ntapfds ; i++)
|
for (i = 0 ; i < ntapfds ; i++)
|
||||||
FD_SET(tapfds[i], &keepfd);
|
FD_SET(tapfds[i], &keepfd);
|
||||||
@ -1292,7 +1291,8 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
|
|
||||||
|
|
||||||
static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
|
static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
struct qemud_driver *driver, virDomainObjPtr vm) {
|
struct qemud_driver *driver,
|
||||||
|
virDomainObjPtr vm) {
|
||||||
if (!virDomainIsActive(vm))
|
if (!virDomainIsActive(vm))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1300,8 +1300,9 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
if (virKillProcess(vm->pid, 0) == 0 &&
|
if (virKillProcess(vm->pid, 0) == 0 &&
|
||||||
virKillProcess(vm->pid, SIGTERM) < 0)
|
virKillProcess(vm->pid, SIGTERM) < 0)
|
||||||
qemudLog(QEMUD_ERROR, _("Failed to send SIGTERM to %s (%d): %s\n"),
|
virReportSystemError(conn, errno,
|
||||||
vm->def->name, vm->pid, strerror(errno));
|
_("Failed to send SIGTERM to %s (%d)"),
|
||||||
|
vm->def->name, vm->pid);
|
||||||
|
|
||||||
if (vm->monitor_watch != -1) {
|
if (vm->monitor_watch != -1) {
|
||||||
virEventRemoveHandle(vm->monitor_watch);
|
virEventRemoveHandle(vm->monitor_watch);
|
||||||
@ -1309,8 +1310,8 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (close(vm->logfile) < 0)
|
if (close(vm->logfile) < 0)
|
||||||
qemudLog(QEMUD_WARN, _("Unable to close logfile %d: %s\n"),
|
qemudLog(QEMUD_WARN, _("Unable to close logfile: %s\n"),
|
||||||
errno, strerror(errno));
|
strerror(errno));
|
||||||
if (vm->monitor != -1)
|
if (vm->monitor != -1)
|
||||||
close(vm->monitor);
|
close(vm->monitor);
|
||||||
vm->logfile = -1;
|
vm->logfile = -1;
|
||||||
@ -1593,8 +1594,8 @@ static int kvmGetMaxVCPUs(void) {
|
|||||||
|
|
||||||
fd = open(KVM_DEVICE, O_RDONLY);
|
fd = open(KVM_DEVICE, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
qemudLog(QEMUD_WARN, _("Unable to open %s: %s\n"), KVM_DEVICE, strerror(errno));
|
virReportSystemError(NULL, errno, _("Unable to open %s"), KVM_DEVICE);
|
||||||
return maxvcpus;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS);
|
r = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS);
|
||||||
@ -1836,8 +1837,8 @@ qemudGetHostname (virConnectPtr conn)
|
|||||||
|
|
||||||
result = virGetHostname();
|
result = virGetHostname();
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
qemudReportError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError (conn, errno,
|
||||||
"%s", strerror (errno));
|
"%s", _("failed to determine host name"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Caller frees this string. */
|
/* Caller frees this string. */
|
||||||
@ -3922,8 +3923,8 @@ qemudDomainBlockPeek (virDomainPtr dom,
|
|||||||
/* The path is correct, now try to open it and get its size. */
|
/* The path is correct, now try to open it and get its size. */
|
||||||
fd = open (path, O_RDONLY);
|
fd = open (path, O_RDONLY);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
qemudReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError (dom->conn, errno,
|
||||||
"%s", strerror (errno));
|
_("%s: failed to open"), path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3933,8 +3934,8 @@ qemudDomainBlockPeek (virDomainPtr dom,
|
|||||||
*/
|
*/
|
||||||
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
|
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
|
||||||
saferead (fd, buffer, size) == (ssize_t) -1) {
|
saferead (fd, buffer, size) == (ssize_t) -1) {
|
||||||
qemudReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError (dom->conn, errno,
|
||||||
"%s", strerror (errno));
|
_("%s: failed to seek or read"), path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3988,8 +3989,8 @@ qemudDomainMemoryPeek (virDomainPtr dom,
|
|||||||
|
|
||||||
/* Create a temporary filename. */
|
/* Create a temporary filename. */
|
||||||
if ((fd = mkstemp (tmp)) == -1) {
|
if ((fd = mkstemp (tmp)) == -1) {
|
||||||
qemudReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError (dom->conn, errno,
|
||||||
"%s", strerror (errno));
|
_("mkstemp(\"%s\") failed"), tmp);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4005,8 +4006,9 @@ qemudDomainMemoryPeek (virDomainPtr dom,
|
|||||||
|
|
||||||
/* Read the memory file into buffer. */
|
/* Read the memory file into buffer. */
|
||||||
if (saferead (fd, buffer, size) == (ssize_t) -1) {
|
if (saferead (fd, buffer, size) == (ssize_t) -1) {
|
||||||
qemudReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError (dom->conn, errno,
|
||||||
"%s", strerror (errno));
|
_("failed to read temporary file "
|
||||||
|
"created with template %s"), tmp);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4165,8 +4167,8 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn,
|
|||||||
|
|
||||||
/* Get hostname */
|
/* Get hostname */
|
||||||
if (gethostname (hostname, HOST_NAME_MAX+1) == -1) {
|
if (gethostname (hostname, HOST_NAME_MAX+1) == -1) {
|
||||||
qemudReportError (dconn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError (dconn, errno,
|
||||||
"%s", strerror (errno));
|
"%s", _("failed to determine host name"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4336,8 +4338,7 @@ qemudDomainMigratePerform (virDomainPtr dom,
|
|||||||
/* Issue the migrate command. */
|
/* Issue the migrate command. */
|
||||||
safe_uri = qemudEscapeMonitorArg (uri);
|
safe_uri = qemudEscapeMonitorArg (uri);
|
||||||
if (!safe_uri) {
|
if (!safe_uri) {
|
||||||
qemudReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
|
virReportOOMError (dom->conn);
|
||||||
"%s", strerror (errno));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
snprintf (cmd, sizeof cmd, "migrate \"%s\"", safe_uri);
|
snprintf (cmd, sizeof cmd, "migrate \"%s\"", safe_uri);
|
||||||
|
Loading…
Reference in New Issue
Block a user