[libvirt] adding tests....
by Jim Meyering
In adding a couple of tests, I noticed that libvirtd --config=no-such
didn't diagnose my mistake.
I fixed that with the first patch below:
diagnose "libvirtd --config=no-such-file"
* qemud/qemud.c (remoteReadConfigFile): Don't return 0 (success)
when the config file is unreadable or nonexistent
Return -1, not 0, upon virConfReadFile failure.
(main): If remote_config_file is not specified via --config(-f),
use the default config file only if it exists. Otherwise,
use /dev/null.
However, that made it so libvirtd gave two diagnostics:
Failed to open file 'no-such': No such file or directory
libvir: Config error : failed to open no-such for reading
The latter part of that patch fixes it like this:
* src/conf.c (virConfReadFile): Don't diagnose virFileReadAll
failure, since it already does that.
Finally, I went to add the two tests,
one to ensure libvirtd --config=no-such-file now fails, as I expected
another to start libvirtd and then run a small pool-related test via
a separate virsh invocation.
But that made me see a bug in tests/Makefile.am:
A missing backslash made it so the virsh-all test wasn't being run.
Easy to fix. But then, I saw when virsh-all runs it generated too
much output, so I did this:
tests: quiet virsh-all
* tests/virsh-all: For now, ignore diagnostics and exit status,
when running all virsh commands.
Finally, here are the two tests:
add tests
* tests/libvirtd-pool: New file.
* tests/libvirtd-fail: New file.
* tests/Makefile.am (test_scripts): Add omitted backslash,
so that the virsh-all test is run.
Add libvirtd-fail and libvirtd-pool.
>From aaea6d51f5200e58086d9cabf8b6e7fac7c460f8 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 8 Jan 2009 20:17:35 +0100
Subject: [PATCH 1/3] diagnose "libvirtd --config=no-such-file"
* qemud/qemud.c (remoteReadConfigFile): Don't return 0 (success)
when the config file is unreadable or nonexistent
Return -1, not 0, upon virConfReadFile failure.
(main): If remote_config_file is not specified via --config(-f),
use the default config file only if it exists. Otherwise,
use /dev/null.
* src/conf.c (virConfReadFile): Don't diagnose virFileReadAll
failure, since it already does that.
---
qemud/qemud.c | 20 ++++++++++++--------
src/conf.c | 3 +--
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/qemud/qemud.c b/qemud/qemud.c
index c3d3c02..9835e0a 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -1,7 +1,7 @@
/*
* qemud.c: daemon start of day, guest process & i/o management
*
- * Copyright (C) 2006, 2007, 2008 Red Hat, Inc.
+ * Copyright (C) 2006, 2007, 2008, 2009 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -2116,13 +2116,8 @@ remoteReadConfigFile (struct qemud_server *server, const char *filename)
auth_unix_ro = REMOTE_AUTH_NONE;
#endif
- /* Just check the file is readable before opening it, otherwise
- * libvirt emits an error.
- */
- if (access (filename, R_OK) == -1) return 0;
-
conf = virConfReadFile (filename);
- if (!conf) return 0;
+ if (!conf) return -1;
/*
* First get all the logging settings and activate them
@@ -2301,7 +2296,7 @@ int main(int argc, char **argv) {
struct sigaction sig_action;
int sigpipe[2];
const char *pid_file = NULL;
- const char *remote_config_file = SYSCONF_DIR "/libvirt/libvirtd.conf";
+ const char *remote_config_file = NULL;
int ret = 1;
struct option opts[] = {
@@ -2372,6 +2367,15 @@ int main(int argc, char **argv) {
}
}
+ if (remote_config_file == NULL) {
+ static const char *default_config_file
+ = SYSCONF_DIR "/libvirt/libvirtd.conf";
+ remote_config_file =
+ (access(default_config_file, X_OK) == 0
+ ? default_config_file
+ : "/dev/null");
+ }
+
if (godaemon) {
if (qemudGoDaemon() < 0) {
VIR_ERROR(_("Failed to fork as daemon: %s"), strerror(errno));
diff --git a/src/conf.c b/src/conf.c
index 9f0fc34..339a150 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -1,7 +1,7 @@
/**
* conf.c: parser for a subset of the Python encoded Xen configuration files
*
- * Copyright (C) 2006, 2007, 2008 Red Hat, Inc.
+ * Copyright (C) 2006, 2007, 2008, 2009 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
@@ -712,7 +712,6 @@ virConfReadFile(const char *filename)
}
if ((len = virFileReadAll(filename, MAX_CONFIG_FILE_SIZE, &content)) < 0) {
- virConfError(NULL, VIR_ERR_OPEN_FAILED, filename);
return NULL;
}
--
1.6.1.141.gfe98e
>From e70a4556a8422779b7997ab03997af4b9a03087c Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 8 Jan 2009 19:58:19 +0100
Subject: [PATCH 2/3] tests: quiet virsh-all
* tests/virsh-all: For now, ignore diagnostics and exit status,
when running all virsh commands.
---
tests/virsh-all | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/tests/virsh-all b/tests/virsh-all
index f1c84a3..03ea466 100755
--- a/tests/virsh-all
+++ b/tests/virsh-all
@@ -1,7 +1,7 @@
#!/bin/sh
# blindly run each and every command listed by "virsh help"
-# Copyright (C) 2008 Free Software Foundation, Inc.
+# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -35,7 +35,8 @@ test -n "$cmds" || framework_failure
for i in $cmds; do
echo testing $i... 1>&2
- virsh -c $test_url $i < /dev/null
+ # For now, just run the command and ignore output and exit status.
+ virsh -c $test_url $i < /dev/null > /dev/null 2>&1
done
(exit $fail); exit $fail
--
1.6.1.141.gfe98e
>From 307c465a008cbb4a497a6553046a036e95843519 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 8 Jan 2009 20:18:17 +0100
Subject: [PATCH 3/3] add two tests
* tests/libvirtd-pool: New file.
* tests/libvirtd-fail: New file.
* tests/Makefile.am (test_scripts): Add omitted backslash,
so that the virsh-all test is run.
Add libvirtd-fail and libvirtd-pool.
---
tests/Makefile.am | 24 ++++++++++++----------
tests/libvirtd-fail | 20 +++++++++++++++++++
tests/libvirtd-pool | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 86 insertions(+), 11 deletions(-)
create mode 100755 tests/libvirtd-fail
create mode 100755 tests/libvirtd-pool
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d8b5e44..a3e4383 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -56,17 +56,19 @@ endif
test_scripts = domainschematest
if WITH_LIBVIRTD
-test_scripts += \
- test_conf.sh \
- cpuset \
- daemon-conf \
- int-overflow \
- read-bufsiz \
- read-non-seekable \
- start \
- undefine \
- vcpupin
- virsh-all
+test_scripts += \
+ cpuset \
+ daemon-conf \
+ int-overflow \
+ libvirtd-fail \
+ libvirtd-pool \
+ read-bufsiz \
+ read-non-seekable \
+ start \
+ test_conf.sh \
+ undefine \
+ vcpupin \
+ virsh-all \
virsh-synopsis
endif
diff --git a/tests/libvirtd-fail b/tests/libvirtd-fail
new file mode 100755
index 0000000..724d7c6
--- /dev/null
+++ b/tests/libvirtd-fail
@@ -0,0 +1,20 @@
+#!/bin/sh
+# Ensure that libvirt fails when given nonexistent --config=FILE
+
+if test "$VERBOSE" = yes; then
+ set -x
+ libvirtd --version
+fi
+
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+. "$srcdir/test-lib.sh"
+
+fail=0
+
+libvirtd --config=no-such-file > log 2>&1 && fail=1
+cat <<\EOF > exp
+Failed to open file 'no-such-file': No such file or directory
+EOF
+
+compare exp log
diff --git a/tests/libvirtd-pool b/tests/libvirtd-pool
new file mode 100755
index 0000000..72afa12
--- /dev/null
+++ b/tests/libvirtd-pool
@@ -0,0 +1,53 @@
+#!/bin/sh
+# Get coverage of libvirtd's config-parsing code.
+
+if test "$VERBOSE" = yes; then
+ set -x
+ libvirtd --version
+ virsh --version
+fi
+
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+. "$srcdir/test-lib.sh"
+
+fail=0
+
+libvirtd > log 2>&1 & pid=$!
+sleep 1
+
+virsh --connect qemu:///session \
+ pool-define-as P dir src-host /src/path /src/dev S /target-path > out 2>&1 \
+ || fail=1
+virsh --connect qemu:///session pool-dumpxml P >> out 2>&1 || fail=1
+
+# remove random uuid
+sed 's/<uuid>.*/-/' out > k && mv k out || fail=1
+
+kill $pid
+
+cat <<EOF > exp
+Pool P defined
+
+<pool type='dir'>
+ <name>P</name>
+ -
+ <capacity>0</capacity>
+ <allocation>0</allocation>
+ <available>0</available>
+ <source>
+ </source>
+ <target>
+ <path>/target-path</path>
+ <permissions>
+ <mode>0700</mode>
+ <owner>500</owner>
+ <group>500</group>
+ </permissions>
+ </target>
+</pool>
+
+EOF
+
+compare exp out
+compare /dev/null log
--
1.6.1.141.gfe98e
16 years, 2 months
[libvirt] [PATCH] Solaris PV is localtime. Allow this setting through the conversions
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1233198416 28800
# Node ID 76d670ab6ea5476be96441ea88af94644c985201
# Parent f0247b9f4da199c01412d5bd0f9d7d888cbb84de
Solaris PV is localtime. Allow this setting through the conversions.
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
@@ -2272,10 +2272,12 @@ xenDaemonParseSxpr(virConnectPtr conn,
def->features |= (1 << VIR_DOMAIN_FEATURE_APIC);
if (sexpr_int(root, "domain/image/hvm/pae"))
def->features |= (1 << VIR_DOMAIN_FEATURE_PAE);
-
- if (sexpr_int(root, "domain/image/hvm/localtime"))
+ }
+
+ if (sexpr_int(root, "domain/localtime") ||
+ sexpr_int(root, "domain/image/hvm/localtime") ||
+ sexpr_int(root, "domain/image/linux/localtime"))
def->localtime = 1;
- }
if (sexpr_node_copy(root, hvm ?
"domain/image/hvm/device_model" :
@@ -5338,6 +5340,14 @@ xenDaemonFormatSxpr(virConnectPtr conn,
}
virBufferVSprintf(&buf, "(on_crash '%s')", tmp);
+ /*
+ * xend puts localtime in image/{hvm,linux}/, but is clearly
+ * bootloader independent. As a simple workaround, we define it
+ * here - xend happily picks it up from here.
+ */
+ if (def->localtime)
+ virBufferAddLit(&buf, "(localtime 1)");
+
if (!def->os.bootloader) {
if (STREQ(def->os.type, "hvm"))
hvm = 1;
@@ -5453,9 +5463,6 @@ xenDaemonFormatSxpr(virConnectPtr conn,
virBufferAddLit(&buf, "(serial none)");
}
- if (def->localtime)
- virBufferAddLit(&buf, "(localtime 1)");
-
if (def->sounds) {
virBufferAddLit(&buf, "(soundhw '");
if (xenDaemonFormatSxprSound(conn, def, &buf) < 0)
diff --git a/src/xm_internal.c b/src/xm_internal.c
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -818,10 +818,11 @@ xenXMDomainConfigParse(virConnectPtr con
goto cleanup;
else if (val)
def->features |= (1 << VIR_DOMAIN_FEATURE_APIC);
-
- if (xenXMConfigGetBool(conn, conf, "localtime", &def->localtime, 0) < 0)
- goto cleanup;
- }
+ }
+
+ if (xenXMConfigGetBool(conn, conf, "localtime", &def->localtime, 0) < 0)
+ goto cleanup;
+
if (xenXMConfigCopyStringOpt(conn, conf, "device_model", &def->emulator) < 0)
goto cleanup;
@@ -1972,6 +1973,9 @@ virConfPtr xenXMDomainConfigFormat(virCo
if (xenXMConfigSetInt(conf, "vcpus", def->vcpus) < 0)
goto no_memory;
+ if (def->localtime && xenXMConfigSetInt(conf, "localtime", 1) < 0)
+ goto no_memory;
+
if (def->cpumask &&
!(cpus = virDomainCpuSetFormat(conn, def->cpumask, def->cpumasklen)) < 0)
goto cleanup;
@@ -2034,9 +2038,6 @@ virConfPtr xenXMDomainConfigFormat(virCo
(1 << VIR_DOMAIN_FEATURE_APIC)) ? 1 : 0) < 0)
goto no_memory;
-
- if (xenXMConfigSetInt(conf, "localtime", def->localtime ? 1 : 0) < 0)
- goto no_memory;
if (priv->xendConfigVersion == 1) {
for (i = 0 ; i < def->ndisks ; i++) {
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-localtime2.sexpr b/tests/sexpr2xmldata/sexpr2xml-fv-localtime2.sexpr
new file mode 100644
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-localtime2.sexpr
@@ -0,0 +1,1 @@
+(domain (domid 3)(name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')(localtime 1)(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(device_model '/usr/lib64/xen/bin/qemu-dm')(boot c)(cdrom '/root/boot.iso')(acpi 1)(vnc 1)(keymap ja)))(device (vbd (dev 'ioemu:hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu))))
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-localtime2.xml b/tests/sexpr2xmldata/sexpr2xml-fv-localtime2.xml
new file mode 100644
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-localtime2.xml
@@ -0,0 +1,41 @@
+<domain type='xen' id='3'>
+ <name>fvtest</name>
+ <uuid>b5d70dd2-75cd-aca5-1776-9660b059d8bc</uuid>
+ <memory>409600</memory>
+ <currentMemory>409600</currentMemory>
+ <vcpu>1</vcpu>
+ <os>
+ <type>hvm</type>
+ <loader>/usr/lib/xen/boot/hvmloader</loader>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <acpi/>
+ </features>
+ <clock offset='localtime'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
+ <disk type='file' device='disk'>
+ <driver name='file'/>
+ <source file='/root/foo.img'/>
+ <target dev='hda' bus='ide'/>
+ </disk>
+ <disk type='file' device='cdrom'>
+ <driver name='file'/>
+ <source file='/root/boot.iso'/>
+ <target dev='hdc' bus='ide'/>
+ <readonly/>
+ </disk>
+ <interface type='bridge'>
+ <mac address='00:16:3e:1b:b1:47'/>
+ <source bridge='xenbr0'/>
+ <script path='vif-bridge'/>
+ <target dev='vif3.0'/>
+ </interface>
+ <input type='mouse' bus='ps2'/>
+ <graphics type='vnc' port='5903' autoport='no' keymap='ja'/>
+ </devices>
+</domain>
diff --git a/tests/sexpr2xmldata/sexpr2xml-pv-localtime.sexpr b/tests/sexpr2xmldata/sexpr2xml-pv-localtime.sexpr
new file mode 100644
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-pv-localtime.sexpr
@@ -0,0 +1,2 @@
+(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(localtime 1)(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test... ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
+
diff --git a/tests/sexpr2xmldata/sexpr2xml-pv-localtime.xml b/tests/sexpr2xmldata/sexpr2xml-pv-localtime.xml
new file mode 100644
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-pv-localtime.xml
@@ -0,0 +1,27 @@
+<domain type='xen' id='6'>
+ <name>pvtest</name>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
+ <memory>430080</memory>
+ <currentMemory>430080</currentMemory>
+ <vcpu>2</vcpu>
+ <os>
+ <type>linux</type>
+ <kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
+ <initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
+ <cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test... </cmdline>
+ </os>
+ <clock offset='localtime'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>destroy</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='file'/>
+ <source file='/root/some.img'/>
+ <target dev='xvda' bus='xen'/>
+ </disk>
+ <console type='pty'>
+ <target port='0'/>
+ </console>
+ </devices>
+</domain>
diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c
--- a/tests/sexpr2xmltest.c
+++ b/tests/sexpr2xmltest.c
@@ -129,6 +129,7 @@ mymain(int argc, char **argv)
DO_TEST("pv-vfb-new-vncdisplay", "pv-vfb-new-vncdisplay", 3);
DO_TEST("fv-autoport", "fv-autoport", 3);
DO_TEST("pv-bootloader", "pv-bootloader", 1);
+ DO_TEST("pv-localtime", "pv-localtime", 1);
DO_TEST("disk-file", "disk-file", 2);
DO_TEST("disk-block", "disk-block", 2);
@@ -145,6 +146,7 @@ mymain(int argc, char **argv)
DO_TEST("fv-utc", "fv-utc", 1);
DO_TEST("fv-localtime", "fv-localtime", 1);
+ DO_TEST("fv-localtime2", "fv-localtime2", 1);
DO_TEST("fv-usbmouse", "fv-usbmouse", 1);
DO_TEST("fv-usbtablet", "fv-usbtablet", 1);
DO_TEST("fv-kernel", "fv-kernel", 1);
diff --git a/tests/xmconfigdata/test-escape-paths.cfg b/tests/xmconfigdata/test-escape-paths.cfg
--- a/tests/xmconfigdata/test-escape-paths.cfg
+++ b/tests/xmconfigdata/test-escape-paths.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-localtime.cfg b/tests/xmconfigdata/test-fullvirt-localtime.cfg
--- a/tests/xmconfigdata/test-fullvirt-localtime.cfg
+++ b/tests/xmconfigdata/test-fullvirt-localtime.cfg
@@ -3,13 +3,13 @@ maxmem = 579
maxmem = 579
memory = 394
vcpus = 1
+localtime = 1
builder = "hvm"
kernel = "/usr/lib/xen/boot/hvmloader"
boot = "d"
pae = 1
acpi = 1
apic = 1
-localtime = 1
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg b/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg
--- a/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg
+++ b/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg b/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg
--- a/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg
+++ b/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
cdrom = "/root/boot.iso"
on_poweroff = "destroy"
on_reboot = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg b/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg
--- a/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg
+++ b/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-serial-file.cfg b/tests/xmconfigdata/test-fullvirt-serial-file.cfg
--- a/tests/xmconfigdata/test-fullvirt-serial-file.cfg
+++ b/tests/xmconfigdata/test-fullvirt-serial-file.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-serial-null.cfg b/tests/xmconfigdata/test-fullvirt-serial-null.cfg
--- a/tests/xmconfigdata/test-fullvirt-serial-null.cfg
+++ b/tests/xmconfigdata/test-fullvirt-serial-null.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg b/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg
--- a/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg
+++ b/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-serial-pty.cfg b/tests/xmconfigdata/test-fullvirt-serial-pty.cfg
--- a/tests/xmconfigdata/test-fullvirt-serial-pty.cfg
+++ b/tests/xmconfigdata/test-fullvirt-serial-pty.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg b/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg
--- a/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg
+++ b/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg b/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg
--- a/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg
+++ b/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg b/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg
--- a/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg
+++ b/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-serial-udp.cfg b/tests/xmconfigdata/test-fullvirt-serial-udp.cfg
--- a/tests/xmconfigdata/test-fullvirt-serial-udp.cfg
+++ b/tests/xmconfigdata/test-fullvirt-serial-udp.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-serial-unix.cfg b/tests/xmconfigdata/test-fullvirt-serial-unix.cfg
--- a/tests/xmconfigdata/test-fullvirt-serial-unix.cfg
+++ b/tests/xmconfigdata/test-fullvirt-serial-unix.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-sound.cfg b/tests/xmconfigdata/test-fullvirt-sound.cfg
--- a/tests/xmconfigdata/test-fullvirt-sound.cfg
+++ b/tests/xmconfigdata/test-fullvirt-sound.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-usbmouse.cfg b/tests/xmconfigdata/test-fullvirt-usbmouse.cfg
--- a/tests/xmconfigdata/test-fullvirt-usbmouse.cfg
+++ b/tests/xmconfigdata/test-fullvirt-usbmouse.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-usbtablet.cfg b/tests/xmconfigdata/test-fullvirt-usbtablet.cfg
--- a/tests/xmconfigdata/test-fullvirt-usbtablet.cfg
+++ b/tests/xmconfigdata/test-fullvirt-usbtablet.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-fullvirt-utc.cfg b/tests/xmconfigdata/test-fullvirt-utc.cfg
--- a/tests/xmconfigdata/test-fullvirt-utc.cfg
+++ b/tests/xmconfigdata/test-fullvirt-utc.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
diff --git a/tests/xmconfigdata/test-no-source-cdrom.cfg b/tests/xmconfigdata/test-no-source-cdrom.cfg
--- a/tests/xmconfigdata/test-no-source-cdrom.cfg
+++ b/tests/xmconfigdata/test-no-source-cdrom.cfg
@@ -9,7 +9,6 @@ pae = 1
pae = 1
acpi = 1
apic = 1
-localtime = 0
on_poweroff = "destroy"
on_reboot = "destroy"
on_crash = "destroy"
diff --git a/tests/xml2sexprdata/xml2sexpr-fv-localtime.sexpr b/tests/xml2sexprdata/xml2sexpr-fv-localtime.sexpr
--- a/tests/xml2sexprdata/xml2sexpr-fv-localtime.sexpr
+++ b/tests/xml2sexprdata/xml2sexpr-fv-localtime.sexpr
@@ -1,1 +1,1 @@
-(vm (name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)(uuid 'b5d70dd2-75cd-aca5-1776-9660b059d8bc')(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(vcpus 1)(boot c)(cdrom '/root/boot.iso')(acpi 1)(usb 1)(parallel none)(serial none)(localtime 1)(device_model '/usr/lib64/xen/bin/qemu-dm')(vnc 1)))(device (vbd (dev 'ioemu:hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu))))
\ No newline at end of file
+(vm (name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)(uuid 'b5d70dd2-75cd-aca5-1776-9660b059d8bc')(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')(localtime 1)(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(vcpus 1)(boot c)(cdrom '/root/boot.iso')(acpi 1)(usb 1)(parallel none)(serial none)(device_model '/usr/lib64/xen/bin/qemu-dm')(vnc 1)))(device (vbd (dev 'ioemu:hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu))))
\ No newline at end of file
diff --git a/tests/xml2sexprdata/xml2sexpr-pv-localtime.sexpr b/tests/xml2sexprdata/xml2sexpr-pv-localtime.sexpr
new file mode 100644
--- /dev/null
+++ b/tests/xml2sexprdata/xml2sexpr-pv-localtime.sexpr
@@ -0,0 +1,1 @@
+(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d21-71f4-8fb2-e068-e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(localtime 1)(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test... ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
\ No newline at end of file
diff --git a/tests/xml2sexprdata/xml2sexpr-pv-localtime.xml b/tests/xml2sexprdata/xml2sexpr-pv-localtime.xml
new file mode 100644
--- /dev/null
+++ b/tests/xml2sexprdata/xml2sexpr-pv-localtime.xml
@@ -0,0 +1,24 @@
+<domain type='xen' id='15'>
+ <name>pvtest</name>
+ <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <os>
+ <type>linux</type>
+ <kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
+ <initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
+ <cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test... </cmdline>
+ </os>
+ <memory>430080</memory>
+ <vcpu>2</vcpu>
+ <clock offset='localtime'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>destroy</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <source file='/root/some.img'/>
+ <target dev='xvda'/>
+ </disk>
+ <console tty='/dev/pts/4'/>
+ </devices>
+</domain>
+
diff --git a/tests/xml2sexprdata/xml2sexpr-pv-utc.sexpr b/tests/xml2sexprdata/xml2sexpr-pv-utc.sexpr
new file mode 100644
--- /dev/null
+++ b/tests/xml2sexprdata/xml2sexpr-pv-utc.sexpr
@@ -0,0 +1,1 @@
+(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d21-71f4-8fb2-e068-e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test... ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
\ No newline at end of file
diff --git a/tests/xml2sexprdata/xml2sexpr-pv-utc.xml b/tests/xml2sexprdata/xml2sexpr-pv-utc.xml
new file mode 100644
--- /dev/null
+++ b/tests/xml2sexprdata/xml2sexpr-pv-utc.xml
@@ -0,0 +1,24 @@
+<domain type='xen' id='15'>
+ <name>pvtest</name>
+ <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <os>
+ <type>linux</type>
+ <kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
+ <initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
+ <cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test... </cmdline>
+ </os>
+ <memory>430080</memory>
+ <vcpu>2</vcpu>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>destroy</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <source file='/root/some.img'/>
+ <target dev='xvda'/>
+ </disk>
+ <console tty='/dev/pts/4'/>
+ </devices>
+</domain>
+
diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c
--- a/tests/xml2sexprtest.c
+++ b/tests/xml2sexprtest.c
@@ -112,6 +112,8 @@ mymain(int argc, char **argv)
DO_TEST("pv-vfb-new", "pv-vfb-new", "pvtest", 3);
DO_TEST("pv-vfb-new-auto", "pv-vfb-new-auto", "pvtest", 3);
DO_TEST("pv-bootloader", "pv-bootloader", "pvtest", 1);
+ DO_TEST("pv-localtime", "pv-localtime", "pvtest", 1);
+ DO_TEST("pv-utc", "pv-utc", "pvtest", 1);
DO_TEST("disk-file", "disk-file", "pvtest", 2);
DO_TEST("disk-block", "disk-block", "pvtest", 2);
16 years, 2 months
[libvirt] [PATCH] don't print uninitialized in debug diagnostic
by Jim Meyering
FYI, this was caught by bleeding-edge gcc (built from git just this morning).
There are a few other problems, too.
>From a3149ae688f4f7eac3ee001f8f4d5997d3f23eeb Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 5 Feb 2009 18:57:07 +0100
Subject: [PATCH] don't print uninitialized in debug diagnostic
* qemud/mdns.c (libvirtd_mdns_timeout_new): Don't use local, t,
uninitialized.
---
qemud/mdns.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/qemud/mdns.c b/qemud/mdns.c
index b13a6e5..ae6ff08 100644
--- a/qemud/mdns.c
+++ b/qemud/mdns.c
@@ -309,7 +309,7 @@ static AvahiTimeout *libvirtd_mdns_timeout_new(const AvahiPoll *api ATTRIBUTE_UN
AvahiTimeout *t;
struct timeval now;
long long nowms, thenms, timeout;
- AVAHI_DEBUG("Add timeout %p TV %p", t, tv);
+ AVAHI_DEBUG("Add timeout TV %p", tv);
if (VIR_ALLOC(t) < 0)
return NULL;
--
1.6.1.2.511.gc5d3f
16 years, 2 months
[libvirt] [PATCH] Allow off-line removal of devices via xend
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1233806617 28800
# Node ID 507c2058c5f3c37894c573c4559eab58c5b52d7d
# Parent 0b9d8336e5e089b19ac8381fdc77eadc72ef9eb7
Allow off-line removal of devices via xend
We must avoid xenstore if the domain isn't running. For disks, this
works in all xend versions; for NICs, however, this requires a change in
netif.py to allow matching by MAC address. Preferring the device ID but
falling back to the device ref works best with all versions of xend.
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
@@ -92,11 +92,17 @@ xenDaemonFormatSxprNet(virConnectPtr con
int xendConfigVersion,
int isAttach);
static int
-virDomainXMLDevID(virDomainPtr domain,
- virDomainDeviceDefPtr dev,
- char *class,
- char *ref,
- int ref_len);
+virDomainDevRef(virDomainPtr domain,
+ virDomainDeviceDefPtr dev,
+ char *class,
+ char *ref,
+ int ref_len);
+static int
+virDomainDevID(virDomainPtr domain,
+ int type,
+ const char *ref,
+ char *devid,
+ int devid_len);
#endif
#define virXendError(conn, code, fmt...) \
@@ -3858,7 +3864,7 @@ xenDaemonAttachDevice(virDomainPtr domai
virDomainDeviceDefPtr dev = NULL;
virDomainDefPtr def = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
- char class[8], ref[80];
+ char class[8], ref[80], devid[80];
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
@@ -3914,15 +3920,24 @@ xenDaemonAttachDevice(virDomainPtr domai
sexpr = virBufferContentAndReset(&buf);
- if (virDomainXMLDevID(domain, dev, class, ref, sizeof(ref))) {
+ devid[0] = '\0';
+
+ if (virDomainDevRef(domain, dev, class, ref, sizeof(ref)) == -1)
+ goto cleanup;
+
+ if (domain->id > 0 &&
+ virDomainDevID(domain, dev->type, ref, devid, sizeof(devid)) != -1) {
+ VIR_DEBUG("device_configure(ref = %s, devid = %s): %s",
+ ref, devid, sexpr);
+ /* device exists, attempt to modify it */
+ ret = xend_op(domain->conn, domain->name, "op", "device_configure",
+ "config", sexpr, "dev", devid, NULL);
+ } else {
+ VIR_DEBUG("device_create(ref = %s, devid = %s): %s",
+ ref, devid, sexpr);
/* device doesn't exist, define it */
ret = xend_op(domain->conn, domain->name, "op", "device_create",
"config", sexpr, NULL);
- }
- else {
- /* device exists, attempt to modify it */
- ret = xend_op(domain->conn, domain->name, "op", "device_configure",
- "config", sexpr, "dev", ref, NULL);
}
cleanup:
@@ -3945,7 +3960,7 @@ xenDaemonDetachDevice(virDomainPtr domai
xenDaemonDetachDevice(virDomainPtr domain, const char *xml)
{
xenUnifiedPrivatePtr priv;
- char class[8], ref[80];
+ char class[8], ref[80], devid[80];
virDomainDeviceDefPtr dev = NULL;
virDomainDefPtr def = NULL;
int ret = -1;
@@ -3976,11 +3991,41 @@ xenDaemonDetachDevice(virDomainPtr domai
def, xml, VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
- if (virDomainXMLDevID(domain, dev, class, ref, sizeof(ref)))
+ if (dev->type != VIR_DOMAIN_DEVICE_NET &&
+ dev->type != VIR_DOMAIN_DEVICE_DISK) {
+ virXendError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("can't detach device of type %d"), dev->type);
goto cleanup;
+ }
+
+ /*
+ * First acquire a static reference to the device (MAC address or
+ * destination disk). We'll use this if the domain isn't running,
+ * otherwise we'll rely upon the XenStore devid.
+ */
+
+ if (virDomainDevRef(domain, dev, class, ref, sizeof(ref)) == -1) {
+ virXendError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("can't detach device: not found "));
+ goto cleanup;
+ }
+
+ if (domain->id >= 0) {
+ if (virDomainDevID(domain, dev->type, ref, devid, sizeof(devid))) {
+ virXendError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("can't detach device: not found "));
+ goto cleanup;
+ }
+ } else {
+ strncpy(devid, ref, 80);
+ }
+
+ VIR_DEBUG("device_destroy(type = %s, ref = %s, devid = %s)",
+ class, ref, devid);
ret = xend_op(domain->conn, domain->name, "op", "device_destroy",
- "type", class, "dev", ref, "force", "0", "rm_cfg", "1", NULL);
+ "type", class, "dev", devid, "force", "0",
+ "rm_cfg", "1", NULL);
cleanup:
virDomainDefFree(def);
@@ -5502,12 +5547,48 @@ error:
/**
- * virDomainXMLDevID:
+ * virDomainXMLDevRef:
* @domain: pointer to domain object
* @dev: pointer to device config object
* @class: Xen device class "vbd" or "vif" (OUT)
* @ref: Xen device reference (OUT)
*
+ * Return the class (vbd/vif) and reference (MAC address / disk
+ * destination) of the given device.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+static int
+virDomainDevRef(virDomainPtr domain,
+ virDomainDeviceDefPtr dev,
+ char *class,
+ char *ref,
+ int ref_len)
+{
+ if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
+ if (dev->data.disk->dst == NULL)
+ return -1;
+ strncpy(ref, dev->data.disk->dst, ref_len);
+ strcpy(class, "vbd");
+ } else if (dev->type == VIR_DOMAIN_DEVICE_NET) {
+ virFormatMacAddr(dev->data.net->mac, ref);
+ strcpy(class, "vif");
+ } else {
+ virXendError(NULL, VIR_ERR_NO_SUPPORT,
+ _("no support for device type %d"), dev->type);
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * virDomainXMLDevID:
+ * @domain: pointer to domain object
+ * @class: either 'vbd' or 'vif'
+ * @ref: Xen device reference
+ * @devid: Xen device ID (OUT)
+ *
* Set class according to XML root, and:
* - if disk, copy in ref the target name from description
* - if network, get MAC address from description, scan XenStore and
@@ -5516,54 +5597,41 @@ error:
* Returns 0 in case of success, -1 in case of failure.
*/
static int
-virDomainXMLDevID(virDomainPtr domain,
- virDomainDeviceDefPtr dev,
- char *class,
- char *ref,
- int ref_len)
+virDomainDevID(virDomainPtr domain,
+ int type,
+ const char *ref,
+ char *devid,
+ int devid_len)
{
xenUnifiedPrivatePtr priv = domain->conn->privateData;
- char *xref;
-
- if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
- strcpy(class, "vbd");
- if (dev->data.disk->dst == NULL)
- return -1;
- xenUnifiedLock(priv);
- xref = xenStoreDomainGetDiskID(domain->conn, domain->id,
- dev->data.disk->dst);
- xenUnifiedUnlock(priv);
- if (xref == NULL)
- return -1;
-
- strncpy(ref, xref, ref_len);
- free(xref);
- ref[ref_len - 1] = '\0';
- } else if (dev->type == VIR_DOMAIN_DEVICE_NET) {
- char mac[30];
- virDomainNetDefPtr def = dev->data.net;
- snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
- def->mac[0], def->mac[1], def->mac[2],
- def->mac[3], def->mac[4], def->mac[5]);
-
- strcpy(class, "vif");
-
- xenUnifiedLock(priv);
- xref = xenStoreDomainGetNetworkID(domain->conn, domain->id,
- mac);
- xenUnifiedUnlock(priv);
- if (xref == NULL)
- return -1;
-
- strncpy(ref, xref, ref_len);
- free(xref);
- ref[ref_len - 1] = '\0';
+ char *id = NULL;
+
+ if (domain->id < 0) {
+ virXendError(domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("devid not available for shutdown domain"));
+ return -1;
+ }
+
+ xenUnifiedLock(priv);
+
+ if (type == VIR_DOMAIN_DEVICE_DISK) {
+ id = xenStoreDomainGetDiskID(domain->conn, domain->id, ref);
+
+ } else if (type == VIR_DOMAIN_DEVICE_NET) {
+ id = xenStoreDomainGetNetworkID(domain->conn, domain->id, ref);
} else {
virXendError(NULL, VIR_ERR_NO_SUPPORT,
- "%s", _("hotplug of device type not supported"));
+ _("no support for device type %d"), type);
+ }
+
+ xenUnifiedUnlock(priv);
+
+ if (id == NULL)
return -1;
- }
-
+
+ strncpy(devid, id, devid_len);
+ VIR_FREE(id);
+ devid[devid_len - 1] = '\0';
return 0;
}
16 years, 2 months
[libvirt] [PATCH] Improve error reporting in virsh
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1233870902 28800
# Node ID fe7d1aae6184476568fcd3da379207375d8a05a6
# Parent 9fecb1254ee1dad6efeedc50239852104a6f40e2
Improve error reporting in virsh
Rather than verbosely printing every error, save the last error and
report that only if the entire command fails.
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/src/virsh.c b/src/virsh.c
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -93,22 +93,6 @@ typedef enum {
} vshErrorLevel;
/*
- * The error handler for virsh
- */
-static void
-virshErrorHandler(void *unused, virErrorPtr error)
-{
- if ((unused != NULL) || (error == NULL))
- return;
-
- /* Suppress the VIR_ERR_NO_XEN error which fails as non-root */
- if ((error->code == VIR_ERR_NO_XEN) || (error->code == VIR_ERR_OK))
- return;
-
- virDefaultErrorFunc(error);
-}
-
-/*
* virsh command line grammar:
*
* command_line = <command>\n | <command>; <command>; ...
@@ -319,6 +303,46 @@ static int namesorter(const void *a, con
const char **sb = (const char**)b;
return strcasecmp(*sa, *sb);
+}
+
+static virErrorPtr last_error;
+
+/*
+ * Quieten libvirt until we're done with the command.
+ */
+static void
+virshErrorHandler(void *unused, virErrorPtr error)
+{
+ virFreeError(last_error);
+ last_error = virSaveLastError();
+ if (getenv("VIRSH_DEBUG") != NULL)
+ virDefaultErrorFunc(error);
+}
+
+/*
+ * Report an error when a command finishes. This is better than before
+ * (when correct operation would report errors), but it has some
+ * problems: we lose the smarter formatting of virDefaultErrorFunc(),
+ * and it can become harder to debug problems, if errors get reported
+ * twice during one command. This case shouldn't really happen anyway,
+ * and it's IMHO a bug that libvirt does that sometimes.
+ */
+static void
+virshReportError(vshControl *ctl)
+{
+ if (last_error == NULL)
+ return;
+
+ if (last_error->code == VIR_ERR_OK) {
+ vshError(ctl, FALSE, "%s", _("unknown error"));
+ goto out;
+ }
+
+ vshError(ctl, FALSE, "%s", last_error->message);
+
+out:
+ virFreeError(last_error);
+ last_error = NULL;
}
@@ -6102,6 +6126,9 @@ vshCommandRun(vshControl *ctl, const vsh
if (ctl->timing)
GETTIMEOFDAY(&after);
+
+ if (ret == FALSE)
+ virshReportError(ctl);
if (STREQ(cmd->def->name, "quit")) /* hack ... */
return ret;
16 years, 2 months
[libvirt] [PATCH] Introduce virSaveLastError(), virFreeError()
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1233870901 28800
# Node ID 2c12bdf95e5e5f7d00b606df679364463555d76e
# Parent 059167552cb467c107870c3b739438ca107116a8
Introduce virSaveLastError(), virFreeError()
Allow applications to store a copy of the last error reported.
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -172,8 +172,10 @@ typedef void (*virErrorFunc) (void *user
*/
virErrorPtr virGetLastError (void);
+virErrorPtr virSaveLastError (void);
void virResetLastError (void);
void virResetError (virErrorPtr err);
+void virFreeError (virErrorPtr err);
virErrorPtr virConnGetLastError (virConnectPtr conn);
void virConnResetLastError (virConnectPtr conn);
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -247,4 +247,10 @@ LIBVIRT_0.6.0 {
} LIBVIRT_0.5.0;
+LIBVIRT_0.6.1 {
+ global:
+ virFreeError;
+ virSaveLastError;
+} LIBVIRT_0.6.0;
+
# .... define new API here using predicted next version number ....
diff --git a/src/virterror.c b/src/virterror.c
--- a/src/virterror.c
+++ b/src/virterror.c
@@ -286,6 +286,27 @@ virCopyLastError(virErrorPtr to)
}
/**
+ * virSaveLastError:
+ *
+ * Save the last error into a new error object.
+ *
+ * Returns a pointer to the copied error or NULL if allocation failed.
+ * It is the caller's responsibility to free the error with
+ * virFreeError().
+ */
+virErrorPtr
+virSaveLastError(void)
+{
+ virErrorPtr to;
+
+ if (VIR_ALLOC(to) < 0)
+ return NULL;
+
+ virCopyLastError(to);
+ return to;
+}
+
+/**
* virResetError:
* @err: pointer to the virError to clean up
*
@@ -303,6 +324,18 @@ virResetError(virErrorPtr err)
memset(err, 0, sizeof(virError));
}
+/**
+ * virFreeError:
+ * @err: error to free
+ *
+ * Resets and frees the given error.
+ */
+void
+virFreeError(virErrorPtr err)
+{
+ virResetError(err);
+ VIR_FREE(err);
+}
/**
* virResetLastError:
16 years, 2 months
[libvirt] Leaky virsh?
by John Levon
Running virsh with the remote driver (as it always is on Solaris), it
leaks pretty heavily:
thewhip:~ # yes "start fewfewf" | virsh >/dev/null 2>&1 &
[1] 6388
# prstat -c -p 6388
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
6388 root 10M 6788K sleep 59 0 0:00:02 0.2% virsh/1
Total: 1 processes, 1 lwps, load averages: 0.32, 0.12, 0.06
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
6388 root 11M 7104K sleep 59 0 0:00:02 0.3% virsh/1
Total: 1 processes, 1 lwps, load averages: 0.34, 0.12, 0.06
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
6388 root 11M 7160K sleep 59 0 0:00:02 0.3% virsh/1
Total: 1 processes, 1 lwps, load averages: 0.36, 0.13, 0.07
Can you reproduce on Linux anyone?
regards
john
16 years, 2 months
[libvirt] [PATCH/RFC]: don't ignore errors to save the domain status file
by Guido Günther
Hi,
we currently don't report errors to save qemu's domain status file back
to the caller. That was o.k. as long as the code was there for testing
but now that the XML is being picked up on daemon restart we must
handle these.
The attached patch does that, although I'm not confident that it's
enough. While we return error on device attach/unattach the device
actually got attached/unattached already. Same is true for
suspend/resume.
A better solution would be to write out the new domain status into a
temp file and simply call rename(2) on it when the attach/unattach
succeeds and discard it if it fails. This would minimize the possible
error conditions like disk full, missing permissions to write into that
directory etc. Does this sound reasonable?
O.k. to apply the attached version for now?
Cheers,
-- Guido
16 years, 2 months
[libvirt] [PATCH] turn off strict-aliasing warnings in two files
by Jim Meyering
Without these changes and with gcc-4.4,
I'd get 4 warnings (2 in each file)
about strict-aliasing violations.
-Wstrict-aliasing is worth keeping in general, so I
have disabled it only for the two offending files.
The #if avoids the pragma on versions of gcc that don't recognize it.
>From 7d7f8e5dd9754d2bbca1a0ec2f3a47d4eae9df30 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 6 Feb 2009 11:45:39 +0100
Subject: [PATCH] turn off strict-aliasing warnings in two files
* qemud/qemud.c: Disable gcc's strict-aliasing warnings in this file.
* src/bridge.c: Likewise.
---
qemud/qemud.c | 5 +++++
src/bridge.c | 5 +++++
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/qemud/qemud.c b/qemud/qemud.c
index effb336..c3521e3 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -21,6 +21,11 @@
* Author: Daniel P. Berrange <berrange(a)redhat.com>
*/
+/* Tell gcc not to warn about aliasing (e.g., sockaddr_in) in this file. */
+#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
+# pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif
+
#include <config.h>
#include <sys/types.h>
diff --git a/src/bridge.c b/src/bridge.c
index 8e577dd..62fa711 100644
--- a/src/bridge.c
+++ b/src/bridge.c
@@ -19,6 +19,11 @@
* Mark McLoughlin <markmc(a)redhat.com>
*/
+/* Tell gcc not to warn about aliasing (e.g., sockaddr_in) in this file. */
+#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
+# pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif
+
#include <config.h>
#if defined(WITH_BRIDGE)
--
1.6.1.2.511.gc5d3f
16 years, 2 months
[libvirt] I have been looking over James Morris patches for svirt.
by Daniel J Walsh
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
What is the process to get them into libvirt?
I have begun to look at the second componant of the libvirt change.
James patch, allows libvirt to read the SELinux context out of the xml
database and execute qemu with the context. The second componant is to
pass the context of the image(s) and allow libvirt to not only set the
image, but also update the default labels on disk, so a relabel will not
change the context.
I have some patches to do this, but want to make sure the original
patches are acceptable?
The last changes and perhaps the most difficult is figuring out how to
get the labels into the XML database in the first place.
I guess virt_manager will somehow figure out what the labels should be
and assign them.
Dan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iEYEARECAAYFAkmMeZEACgkQrlYvE4MpobMZcwCePmE1aF3zJURS2up7ERoxNU4V
Ho8AoIwBMN7/f4zBCIDTpbnLg13FfPOG
=rHH5
-----END PGP SIGNATURE-----
16 years, 2 months