[libvirt] Sendkey after shutdown
by Mario Wolff
Hello all,
first post, first contact! I hope my english is at least understandable.
I'm using libvirt to manage some kvm hosts with virtual
Windows-Systems. If i call 'shutdown <system>' in virsh, i get "Domain
<system> is being shutdown" but on the system a window is displayed
telling my about remote users.
Without libvirt i had the kvm-monitor on an ip-port and used 'sendkey
ret' to kill the dialog.
Is there a hook/script/extention-api to implement something like this?
Thanks a lot!
Regards,
Mario Wolff
PS: Is someone working on a drbd-storage-driver? Are there interests?
Is there an interface-description for storage-drivers? Should one wait
until the drbd is moved to lvm (i've heard there are plans?!?)? Thanks
again!
15 years, 10 months
[libvirt] [PATCH] Fix more printf("%s", NULL) usage
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1233580871 28800
# Node ID e61a2e486a59394ea422d90e1104f805ceabd0be
# Parent 430096efc257a704fdd6294829686d05f38da68e
Fix more printf("%s", NULL) usage
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/src/libvirt.c b/src/libvirt.c
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2871,7 +2871,9 @@ virDomainMigratePrepare (virConnectPtr d
const char *dname,
unsigned long bandwidth)
{
- DEBUG("dconn=%p, cookie=%p, cookielen=%p, uri_in=%s, uri_out=%p, flags=%lu, dname=%s, bandwidth=%lu", dconn, cookie, cookielen, uri_in, uri_out, flags, dname, bandwidth);
+ VIR_DEBUG("dconn=%p, cookie=%p, cookielen=%p, uri_in=%s, uri_out=%p, "
+ "flags=%lu, dname=%s, bandwidth=%lu", dconn, cookie, cookielen,
+ NULLSTR(uri_in), uri_out, flags, NULLSTR(dname), bandwidth);
virResetLastError();
@@ -2917,7 +2919,9 @@ virDomainMigratePerform (virDomainPtr do
unsigned long bandwidth)
{
virConnectPtr conn;
- DEBUG("domain=%p, cookie=%p, cookielen=%d, uri=%s, flags=%lu, dname=%s, bandwidth=%lu", domain, cookie, cookielen, uri, flags, dname, bandwidth);
+ VIR_DEBUG("domain=%p, cookie=%p, cookielen=%d, uri=%s, flags=%lu, "
+ "dname=%s, bandwidth=%lu", domain, cookie, cookielen, uri, flags,
+ NULLSTR(dname), bandwidth);
virResetLastError();
@@ -2962,7 +2966,8 @@ virDomainMigrateFinish (virConnectPtr dc
const char *uri,
unsigned long flags)
{
- DEBUG("dconn=%p, dname=%s, cookie=%p, cookielen=%d, uri=%s, flags=%lu", dconn, dname, cookie, cookielen, uri, flags);
+ VIR_DEBUG("dconn=%p, dname=%s, cookie=%p, cookielen=%d, uri=%s, "
+ "flags=%lu", dconn, NULLSTR(dname), cookie, cookielen, uri, flags);
virResetLastError();
@@ -3010,7 +3015,9 @@ virDomainMigratePrepare2 (virConnectPtr
unsigned long bandwidth,
const char *dom_xml)
{
- DEBUG("dconn=%p, cookie=%p, cookielen=%p, uri_in=%s, uri_out=%p, flags=%lu, dname=%s, bandwidth=%lu, dom_xml=%s", dconn, cookie, cookielen, uri_in, uri_out, flags, dname, bandwidth, dom_xml);
+ VIR_DEBUG("dconn=%p, cookie=%p, cookielen=%p, uri_in=%s, uri_out=%p,"
+ "flags=%lu, dname=%s, bandwidth=%lu, dom_xml=%s", dconn, cookie,
+ cookielen, uri_in, uri_out, flags, NULLSTR(dname), bandwidth, dom_xml);
virResetLastError();
@@ -3056,7 +3063,9 @@ virDomainMigrateFinish2 (virConnectPtr d
unsigned long flags,
int retcode)
{
- DEBUG("dconn=%p, dname=%s, cookie=%p, cookielen=%d, uri=%s, flags=%lu, retcode=%d", dconn, dname, cookie, cookielen, uri, flags, retcode);
+ VIR_DEBUG("dconn=%p, dname=%s, cookie=%p, cookielen=%d, uri=%s, "
+ "flags=%lu, retcode=%d", dconn, NULLSTR(dname), cookie,
+ cookielen, uri, flags, retcode);
virResetLastError();
15 years, 10 months
[libvirt] [PATCH]: don't hardcode default port 22 for ssh protocol
by Guido Günther
Hi,
attached patch removes the hardcoded port 22 when going through ssh, ssh
uses it by default. This makes it easier to override this via
.ssh/config on a per host basis instead of having to add this to the
connection URI explicitly.
While at that I cleaned up some free vs. VIR_FREE usage and replaced
pointer intializations with 0 by NULL.
Cheers,
-- Guido
P.S.: this originated from Debian Bug #513605
15 years, 10 months
[libvirt] failed test on Fedora 8
by John Levon
17) QEMU XML-2-ARGV disk-drive-shared ... FAILED
I have VIR_TEST_DEBUG set, but this is all I get. It's new
regards
john
15 years, 11 months
[libvirt] [PATCH] COW storage volume compile fix
by Markus Armbruster
Commit 2d4381d0 broke compilation for !HAVE_QEMU_IMG &&
HAVE_QCOW_CREATE. Fix that.
Signed-off-by: Markus Armbruster <armbru(a)redhat.com>
---
Compile-tested only.
diff --git a/src/storage_backend_fs.c b/src/storage_backend_fs.c
index 345dc40..0280c45 100644
--- a/src/storage_backend_fs.c
+++ b/src/storage_backend_fs.c
@@ -1130,7 +1130,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
vol->target.format);
return -1;
}
- if (vol->target.backingStore != NULL) {
+ if (vol->backingStore.path != NULL) {
virStorageReportError(conn, VIR_ERR_NO_SUPPORT,
_("copy-on-write image not supported with "
"qcow-create"));
15 years, 11 months
[libvirt] [PATCH] eliminate strerror from qemu_driver.c: use virReportSystemError instead
by Jim Meyering
I've begun eliminating the remaining problematic uses of strerror.
For example, those in virsh.c aren't a problem.
This is required for thread safety.
After this patch, there are about 60 uses left.
Note while reviewing:
- are there places where I've added uses of "conn" that I should not have?
- are there places where I've used NULL but it should be "conn"?
(there may well be -- I haven't tried hard, but that matters less)
- I've assumed that qemudEscapeMonitorArg failure will always be due to OOM
Currently it is.
I removed the calls to qemudLog from each of the qemudSet* functions
because now each caller of those functions already diagnoses failure, and
includes strerror(errno) information, while the qemudLog calls did not.
In addition, the eliminated qemudLog calls would clobber errno, making
each callers' attempt to report strerror(errno) use a potentially invalid
and misleading errno value.
>From ebe2ee1fbf20edbb07a78ecce76de6866e2ef558 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Wed, 28 Jan 2009 19:20:08 +0100
Subject: [PATCH] eliminate strerror from qemu_driver.c: use virReportSystemError instead
* src/qemu_driver.c (qemudSetCloseExec): Don't use qemudLog here.
Now, every caller diagnoses the failure.
Simplify, now that there's no logging.
* src/qemu_driver.c (qemudSetNonBlock): Rewrite not to use qemudLog.
---
src/qemu_driver.c | 126 ++++++++++++++++++++++++-----------------------------
1 files changed, 57 insertions(+), 69 deletions(-)
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 36e12b2..8fd789d 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -89,31 +89,19 @@ static void qemuDriverUnlock(struct qemud_driver *driver)
static int qemudSetCloseExec(int fd) {
int flags;
- if ((flags = fcntl(fd, F_GETFD)) < 0)
- goto error;
- flags |= FD_CLOEXEC;
- if ((fcntl(fd, F_SETFD, flags)) < 0)
- goto error;
- return 0;
- error:
- qemudLog(QEMUD_ERR,
- "%s", _("Failed to set close-on-exec file descriptor flag\n"));
- return -1;
+ return ((flags = fcntl(fd, F_GETFD)) < 0
+ || fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0
+ ? -1
+ : 0);
}
static int qemudSetNonBlock(int fd) {
int flags;
- if ((flags = fcntl(fd, F_GETFL)) < 0)
- goto error;
- flags |= O_NONBLOCK;
- if ((fcntl(fd, F_SETFL, flags)) < 0)
- goto error;
- return 0;
- error:
- qemudLog(QEMUD_ERR,
- "%s", _("Failed to set non-blocking file descriptor flag\n"));
- return -1;
+ return ((flags = fcntl(fd, F_GETFL)) < 0
+ || fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0
+ ? -1
+ : 0);
}
@@ -198,22 +186,21 @@ qemudLogReadFD(virConnectPtr conn, const char* logDir, const char* name, off_t p
if ((fd = open(logfile, logmode)) < 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("failed to create logfile %s: %s"),
- logfile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("failed to create logfile %s"),
+ logfile);
return -1;
}
if (qemudSetCloseExec(fd) < 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Unable to set VM logfile close-on-exec flag: %s"),
- strerror(errno));
+ virReportSystemError(conn, errno, "%s",
+ _("Unable to set VM logfile close-on-exec flag"));
close(fd);
return -1;
}
if (lseek(fd, pos, SEEK_SET) < 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Unable to seek to %lld in %s: %s"),
- (long long) pos, logfile, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Unable to seek to %lld in %s"),
+ (long long) pos, logfile);
close(fd);
}
return fd;
@@ -441,8 +428,9 @@ qemudStartup(void) {
}
if (virFileMakePath(qemu_driver->stateDir) < 0) {
- qemudLog(QEMUD_ERR, _("Failed to create state dir '%s': %s\n"),
- qemu_driver->stateDir, strerror(errno));
+ virReportSystemError(NULL, errno,
+ _("Failed to create state dir '%s'"),
+ qemu_driver->stateDir);
goto error;
}
@@ -854,8 +842,7 @@ static int qemudWaitForMonitor(virConnectPtr conn,
qemudFindCharDevicePTYs,
"console", 3000);
if (close(logfd) < 0)
- qemudLog(QEMUD_WARN, _("Unable to close logfile: %s\n"),
- strerror(errno));
+ virReportSystemError(NULL, errno, "%s", _("Unable to close logfile"));
return ret;
}
@@ -1134,30 +1121,30 @@ static int qemudStartVMDaemon(virConnectPtr conn,
tmp = progenv;
while (*tmp) {
if (safewrite(vm->logfile, *tmp, strlen(*tmp)) < 0)
- qemudLog(QEMUD_WARN, _("Unable to write envv to logfile %d: %s\n"),
- errno, strerror(errno));
+ virReportSystemError(NULL, errno,
+ "%s", _("Unable to write envv to logfile"));
if (safewrite(vm->logfile, " ", 1) < 0)
- qemudLog(QEMUD_WARN, _("Unable to write envv to logfile %d: %s\n"),
- errno, strerror(errno));
+ virReportSystemError(NULL, errno,
+ "%s", _("Unable to write envv to logfile"));
tmp++;
}
tmp = argv;
while (*tmp) {
if (safewrite(vm->logfile, *tmp, strlen(*tmp)) < 0)
- qemudLog(QEMUD_WARN, _("Unable to write argv to logfile %d: %s\n"),
- errno, strerror(errno));
+ virReportSystemError(NULL, errno,
+ "%s", _("Unable to write argv to logfile"));
if (safewrite(vm->logfile, " ", 1) < 0)
- qemudLog(QEMUD_WARN, _("Unable to write argv to logfile %d: %s\n"),
- errno, strerror(errno));
+ virReportSystemError(NULL, errno,
+ "%s", _("Unable to write argv to logfile"));
tmp++;
}
if (safewrite(vm->logfile, "\n", 1) < 0)
- qemudLog(QEMUD_WARN, _("Unable to write argv to logfile %d: %s\n"),
- errno, strerror(errno));
+ virReportSystemError(NULL, errno,
+ "%s", _("Unable to write argv to logfile"));
if ((pos = lseek(vm->logfile, 0, SEEK_END)) < 0)
- qemudLog(QEMUD_WARN, _("Unable to seek to end of logfile %d: %s\n"),
- errno, strerror(errno));
+ virReportSystemError(NULL, errno,
+ "%s", _("Unable to seek to end of logfile"));
for (i = 0 ; i < ntapfds ; i++)
FD_SET(tapfds[i], &keepfd);
@@ -1214,7 +1201,8 @@ static int qemudStartVMDaemon(virConnectPtr conn,
static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
- struct qemud_driver *driver, virDomainObjPtr vm) {
+ struct qemud_driver *driver,
+ virDomainObjPtr vm) {
if (!virDomainIsActive(vm))
return;
@@ -1222,14 +1210,14 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
if (virKillProcess(vm->pid, 0) == 0 &&
virKillProcess(vm->pid, SIGTERM) < 0)
- qemudLog(QEMUD_ERROR, _("Failed to send SIGTERM to %s (%d): %s\n"),
- vm->def->name, vm->pid, strerror(errno));
+ virReportSystemError(conn, errno,
+ _("Failed to send SIGTERM to %s (%d)"),
+ vm->def->name, vm->pid);
virEventRemoveHandle(vm->monitor_watch);
if (close(vm->logfile) < 0)
- qemudLog(QEMUD_WARN, _("Unable to close logfile %d: %s\n"),
- errno, strerror(errno));
+ virReportSystemError(conn, errno, "%s", _("Unable to close logfile"));
if (vm->monitor != -1)
close(vm->monitor);
vm->logfile = -1;
@@ -1384,8 +1372,8 @@ qemudMonitorCommand (const virDomainObjPtr vm,
/* Log, but ignore failures to write logfile for VM */
if (safewrite(vm->logfile, buf, strlen(buf)) < 0)
- qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s\n"),
- strerror(errno));
+ virReportSystemError(NULL, errno,
+ "%s", _("Unable to log VM console data"));
*reply = buf;
return 0;
@@ -1394,8 +1382,8 @@ qemudMonitorCommand (const virDomainObjPtr vm,
if (buf) {
/* Log, but ignore failures to write logfile for VM */
if (safewrite(vm->logfile, buf, strlen(buf)) < 0)
- qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s\n"),
- strerror(errno));
+ virReportSystemError(NULL, errno,
+ "%s", _("Unable to log VM console data"));
VIR_FREE(buf);
}
return -1;
@@ -1492,7 +1480,7 @@ static int kvmGetMaxVCPUs(void) {
fd = open(KVM_DEVICE, O_RDONLY);
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;
}
@@ -1735,8 +1723,8 @@ qemudGetHostname (virConnectPtr conn)
result = virGetHostname();
if (result == NULL) {
- qemudReportError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
+ virReportSystemError (conn, errno,
+ "%s", _("failed to determine host name"));
return NULL;
}
/* Caller frees this string. */
@@ -3821,8 +3809,8 @@ qemudDomainBlockPeek (virDomainPtr dom,
/* The path is correct, now try to open it and get its size. */
fd = open (path, O_RDONLY);
if (fd == -1) {
- qemudReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
+ virReportSystemError (dom->conn, errno,
+ _("%s: failed to open"), path);
goto cleanup;
}
@@ -3832,8 +3820,8 @@ qemudDomainBlockPeek (virDomainPtr dom,
*/
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
saferead (fd, buffer, size) == (ssize_t) -1) {
- qemudReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
+ virReportSystemError (dom->conn, errno,
+ _("%s: failed to seek or read"), path);
goto cleanup;
}
@@ -3887,8 +3875,8 @@ qemudDomainMemoryPeek (virDomainPtr dom,
/* Create a temporary filename. */
if ((fd = mkstemp (tmp)) == -1) {
- qemudReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
+ virReportSystemError (dom->conn, errno,
+ _("mkstemp(\"%s\") failed"), tmp);
goto cleanup;
}
@@ -3904,8 +3892,9 @@ qemudDomainMemoryPeek (virDomainPtr dom,
/* Read the memory file into buffer. */
if (saferead (fd, buffer, size) == (ssize_t) -1) {
- qemudReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
+ virReportSystemError (dom->conn, errno,
+ _("failed to read temporary file "
+ "created with template %s"), tmp);
goto cleanup;
}
@@ -4064,8 +4053,8 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn,
/* Get hostname */
if (gethostname (hostname, HOST_NAME_MAX+1) == -1) {
- qemudReportError (dconn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
+ virReportSystemError (dconn, errno,
+ "%s", _("failed to determine host name"));
goto cleanup;
}
@@ -4235,8 +4224,7 @@ qemudDomainMigratePerform (virDomainPtr dom,
/* Issue the migrate command. */
safe_uri = qemudEscapeMonitorArg (uri);
if (!safe_uri) {
- qemudReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
+ virReportOOMError (dom->conn);
goto cleanup;
}
snprintf (cmd, sizeof cmd, "migrate \"%s\"", safe_uri);
--
1.6.1.2.418.gd79e6
15 years, 11 months
[libvirt] [PATCH] Fix floppy definition for HVM guests
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1233177786 28800
# Node ID 2b9283e83c20ca2a18f2cafcb963ce254e11dbb4
# Parent 9a9bd34ec485ebaf4c3861bdfffd2953fd91a1fc
Fix floppy definition for HVM guests
Code was missing to define floppy disks for Xen HVM guests. Refuse to
attach disks that aren't supported by direct attach.
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/src/xend_internal.c b/src/xend_internal.c
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -5018,14 +5018,26 @@ xenDaemonFormatSxprDisk(virConnectPtr co
* under the hvm (image (os)) block
*/
if (hvm &&
- def->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
+ def->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
+ if (isAttach) {
+ virXendError(conn, VIR_ERR_INVALID_ARG,
+ _("Cannot directly attach floppy %s"), def->src);
+ return -1;
+ }
return 0;
+ }
/* Xend <= 3.0.2 doesn't include cdrom config here */
if (hvm &&
def->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
- xendConfigVersion == 1)
+ xendConfigVersion == 1) {
+ if (isAttach) {
+ virXendError(conn, VIR_ERR_INVALID_ARG,
+ _("Cannot directly attach CDROM %s"), def->src);
+ return -1;
+ }
return 0;
+ }
if (!isAttach)
virBufferAddLit(buf, "(device ");
@@ -5374,17 +5386,29 @@ xenDaemonFormatSxpr(virConnectPtr conn,
}
virBufferVSprintf(&buf, "(boot %s)", bootorder);
- /* get the cdrom device file */
- /* Only XenD <= 3.0.2 wants cdrom config here */
- if (xendConfigVersion == 1) {
- for (i = 0 ; i < def->ndisks ; i++) {
- if (def->disks[i]->type == VIR_DOMAIN_DISK_DEVICE_CDROM &&
- STREQ(def->disks[i]->dst, "hdc") &&
- def->disks[i]->src) {
- virBufferVSprintf(&buf, "(cdrom '%s')",
- def->disks[i]->src);
+ /* some disk devices are defined here */
+ for (i = 0 ; i < def->ndisks ; i++) {
+ switch (def->disks[i]->device) {
+ case VIR_DOMAIN_DISK_DEVICE_CDROM:
+ /* Only xend <= 3.0.2 wants cdrom config here */
+ if (xendConfigVersion != 1)
break;
- }
+ if (!STREQ(def->disks[i]->dst, "hdc") ||
+ def->disks[i]->src == NULL)
+ break;
+
+ virBufferVSprintf(&buf, "(cdrom '%s')",
+ def->disks[i]->src);
+ break;
+
+ case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+ /* all xend versions define floppies here */
+ virBufferVSprintf(&buf, "(%s '%s')", def->disks[i]->dst,
+ def->disks[i]->src);
+ break;
+
+ default:
+ break;
}
}
15 years, 11 months