[libvirt] PATCH: Support VNC password for QEMU guests
by Daniel P. Berrange
This patch adds support for using the monitor interface to set the VNC
password
(qemu) change vnc password
Password: ********
A minor tricky thing is that we can't just send the command and password
all in one go, we must wait for the 'Password' prompt before sending the
password.
When doing this I noticed that virsh dumpxml has no way to request a
secure XML dump (required to see the password element), nor did the
virsh edit command set the SECURE or INACTIVE flags when changing
the XML.
qemu_conf.c | 45 ++++++++++++-----------
qemu_driver.c | 112 ++++++++++++++++++++++++++++++++++++++++++++--------------
virsh.c | 30 ++++++++++-----
3 files changed, 131 insertions(+), 56 deletions(-)
Daniel
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -1138,37 +1138,42 @@ int qemudBuildCommandLine(virConnectPtr
if (vm->def->graphics &&
vm->def->graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
- char vncdisplay[PATH_MAX];
- int ret;
+ virBuffer opt = VIR_BUFFER_INITIALIZER;
+ char *optstr;
if (qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON) {
- char options[PATH_MAX] = "";
+ if (vm->def->graphics->data.vnc.listenAddr)
+ virBufferAdd(&opt, vm->def->graphics->data.vnc.listenAddr, -1);
+ else if (driver->vncListen)
+ virBufferAdd(&opt, driver->vncListen, -1);
+
+ virBufferVSprintf(&opt, ":%d",
+ vm->def->graphics->data.vnc.port - 5900);
+
+ if (vm->def->graphics->data.vnc.passwd)
+ virBufferAddLit(&opt, ",password");
+
if (driver->vncTLS) {
- strcat(options, ",tls");
+ virBufferAddLit(&opt, ",tls");
if (driver->vncTLSx509verify) {
- strcat(options, ",x509verify=");
+ virBufferVSprintf(&opt, ",x509verify=%s",
+ driver->vncTLSx509certdir);
} else {
- strcat(options, ",x509=");
+ virBufferVSprintf(&opt, ",x509=%s",
+ driver->vncTLSx509certdir);
}
- strncat(options, driver->vncTLSx509certdir,
- sizeof(options) - (strlen(driver->vncTLSx509certdir)-1));
- options[sizeof(options)-1] = '\0';
}
- ret = snprintf(vncdisplay, sizeof(vncdisplay), "%s:%d%s",
- (vm->def->graphics->data.vnc.listenAddr ?
- vm->def->graphics->data.vnc.listenAddr :
- (driver->vncListen ? driver->vncListen : "")),
- vm->def->graphics->data.vnc.port - 5900,
- options);
} else {
- ret = snprintf(vncdisplay, sizeof(vncdisplay), "%d",
- vm->def->graphics->data.vnc.port - 5900);
+ virBufferVSprintf(&opt, "%d",
+ vm->def->graphics->data.vnc.port - 5900);
}
- if (ret < 0 || ret >= (int)sizeof(vncdisplay))
- goto error;
+ if (virBufferError(&opt))
+ goto no_memory;
+
+ optstr = virBufferContentAndReset(&opt);
ADD_ARG_LIT("-vnc");
- ADD_ARG_LIT(vncdisplay);
+ ADD_ARG(optstr);
if (vm->def->graphics->data.vnc.keymap) {
ADD_ARG_LIT("-k");
ADD_ARG_LIT(vm->def->graphics->data.vnc.keymap);
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -74,6 +74,10 @@
/* For storing short-lived temporary files. */
#define TEMPDIR LOCAL_STATE_DIR "/cache/libvirt"
+#define QEMU_CMD_PROMPT "\n(qemu) "
+#define QEMU_PASSWD_PROMPT "Password: "
+
+
static int qemudShutdown(void);
#define qemudLog(level, msg...) fprintf(stderr, msg)
@@ -138,9 +142,14 @@ static void qemudShutdownVMDaemon(virCon
static int qemudDomainGetMaxVcpus(virDomainPtr dom);
-static int qemudMonitorCommand (const virDomainObjPtr vm,
- const char *cmd,
- char **reply);
+static int qemudMonitorCommand(const virDomainObjPtr vm,
+ const char *cmd,
+ char **reply);
+static int qemudMonitorCommandExtra(const virDomainObjPtr vm,
+ const char *cmd,
+ const char *extra,
+ const char *extraPrompt,
+ char **reply);
static struct qemud_driver *qemu_driver = NULL;
@@ -1012,6 +1021,36 @@ qemudInitCpus(virConnectPtr conn,
}
+static int
+qemudInitPasswords(virConnectPtr conn,
+ virDomainObjPtr vm) {
+ char *info = NULL;
+
+ /*
+ * NB: Might have more passwords to set in the future. eg a qcow
+ * disk decryption password, but there's no monitor command
+ * for that yet...
+ */
+
+ if (vm->def->graphics &&
+ vm->def->graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
+ vm->def->graphics->data.vnc.passwd) {
+
+ if (qemudMonitorCommandExtra(vm, "change vnc password",
+ vm->def->graphics->data.vnc.passwd,
+ QEMU_PASSWD_PROMPT,
+ &info) < 0) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ "%s", _("resume operation failed"));
+ return -1;
+ }
+ VIR_FREE(info);
+ }
+
+ return 0;
+}
+
+
static int qemudNextFreeVNCPort(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
int i;
@@ -1204,7 +1243,8 @@ static int qemudStartVMDaemon(virConnect
if (ret == 0) {
if ((qemudWaitForMonitor(conn, driver, vm, pos) < 0) ||
(qemudDetectVcpuPIDs(conn, vm) < 0) ||
- (qemudInitCpus(conn, vm, migrateFrom) < 0)) {
+ (qemudInitCpus(conn, vm, migrateFrom) < 0) ||
+ (qemudInitPasswords(conn, vm) < 0)) {
qemudShutdownVMDaemon(conn, driver, vm);
return -1;
}
@@ -1314,12 +1354,15 @@ cleanup:
}
static int
-qemudMonitorCommand (const virDomainObjPtr vm,
- const char *cmd,
- char **reply) {
+qemudMonitorCommandExtra(const virDomainObjPtr vm,
+ const char *cmd,
+ const char *extra,
+ const char *extraPrompt,
+ char **reply) {
int size = 0;
char *buf = NULL;
size_t cmdlen = strlen(cmd);
+ size_t extralen = extra ? strlen(extra) : 0;
if (safewrite(vm->monitor, cmd, cmdlen) != cmdlen)
return -1;
@@ -1355,25 +1398,34 @@ qemudMonitorCommand (const virDomainObjP
}
/* Look for QEMU prompt to indicate completion */
- if (buf && ((tmp = strstr(buf, "\n(qemu) ")) != NULL)) {
- char *commptr = NULL, *nlptr = NULL;
-
- /* Preserve the newline */
- tmp[1] = '\0';
-
- /* The monitor doesn't dump clean output after we have written to
- * it. Every character we write dumps a bunch of useless stuff,
- * so the result looks like "cXcoXcomXcommXcommaXcommanXcommand"
- * Try to throw away everything before the first full command
- * occurence, and inbetween the command and the newline starting
- * the response
- */
- if ((commptr = strstr(buf, cmd)))
- memmove(buf, commptr, strlen(commptr)+1);
- if ((nlptr = strchr(buf, '\n')))
- memmove(buf+strlen(cmd), nlptr, strlen(nlptr)+1);
-
- break;
+ if (buf) {
+ if (extra) {
+ if (strstr(buf, extraPrompt) != NULL) {
+ if (safewrite(vm->monitor, extra, extralen) != extralen)
+ return -1;
+ if (safewrite(vm->monitor, "\r", 1) != 1)
+ return -1;
+ extra = NULL;
+ }
+ } else if ((tmp = strstr(buf, QEMU_CMD_PROMPT)) != NULL) {
+ char *commptr = NULL, *nlptr = NULL;
+ /* Preserve the newline */
+ tmp[1] = '\0';
+
+ /* The monitor doesn't dump clean output after we have written to
+ * it. Every character we write dumps a bunch of useless stuff,
+ * so the result looks like "cXcoXcomXcommXcommaXcommanXcommand"
+ * Try to throw away everything before the first full command
+ * occurence, and inbetween the command and the newline starting
+ * the response
+ */
+ if ((commptr = strstr(buf, cmd)))
+ memmove(buf, commptr, strlen(commptr)+1);
+ if ((nlptr = strchr(buf, '\n')))
+ memmove(buf+strlen(cmd), nlptr, strlen(nlptr)+1);
+
+ break;
+ }
}
pollagain:
/* Need to wait for more data */
@@ -1403,6 +1455,14 @@ qemudMonitorCommand (const virDomainObjP
return -1;
}
+static int
+qemudMonitorCommand(const virDomainObjPtr vm,
+ const char *cmd,
+ char **reply) {
+ return qemudMonitorCommandExtra(vm, cmd, NULL, NULL, reply);
+}
+
+
/**
* qemudProbe:
*
diff --git a/src/virsh.c b/src/virsh.c
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -2079,6 +2079,8 @@ static const vshCmdInfo info_dumpxml[] =
static const vshCmdOptDef opts_dumpxml[] = {
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
+ {"inactive", VSH_OT_BOOL, 0, gettext_noop("show inactive defined XML")},
+ {"secure", VSH_OT_BOOL, 0, gettext_noop("include security sensitive data")},
{NULL, 0, 0, NULL}
};
@@ -2088,14 +2090,22 @@ cmdDumpXML(vshControl *ctl, const vshCmd
virDomainPtr dom;
int ret = TRUE;
char *dump;
-
- if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
- return FALSE;
-
- if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
- return FALSE;
-
- dump = virDomainGetXMLDesc(dom, 0);
+ int flags = 0;
+ int inactive = vshCommandOptBool(cmd, "inactive");
+ int secure = vshCommandOptBool(cmd, "secure");
+
+ if (inactive)
+ flags |= VIR_DOMAIN_XML_INACTIVE;
+ if(secure)
+ flags |= VIR_DOMAIN_XML_SECURE;
+
+ if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+ return FALSE;
+
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+ return FALSE;
+
+ dump = virDomainGetXMLDesc(dom, flags);
if (dump != NULL) {
printf("%s", dump);
free(dump);
@@ -5374,7 +5384,7 @@ cmdEdit (vshControl *ctl, const vshCmd *
goto cleanup;
/* Get the XML configuration of the domain. */
- doc = virDomainGetXMLDesc (dom, 0);
+ doc = virDomainGetXMLDesc (dom, VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_INACTIVE);
if (!doc)
goto cleanup;
@@ -5404,7 +5414,7 @@ cmdEdit (vshControl *ctl, const vshCmd *
* it was being edited? This also catches problems such as us
* losing a connection or the domain going away.
*/
- doc_reread = virDomainGetXMLDesc (dom, 0);
+ doc_reread = virDomainGetXMLDesc (dom, VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_INACTIVE);
if (!doc_reread)
goto cleanup;
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
16 years, 2 months
[libvirt] [PATCH] Fix another printf("%s", NULL) case
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1233199841 28800
# Node ID 3f2af372963ddbae509bd0d1b2e7bdf3ebb4f217
# Parent 76d670ab6ea5476be96441ea88af94644c985201
Fix another printf("%s", NULL) case
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
@@ -6922,7 +6922,7 @@ int
int
virNodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags)
{
- DEBUG("conn=%p, cap=%s, flags=%d", conn, cap, flags);
+ DEBUG("conn=%p, cap=%s, flags=%d", conn, NULLSTR(cap), flags);
virResetLastError();
16 years, 2 months
[libvirt] [PATCH] Fixes for VNC port handling
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1233162577 28800
# Node ID 6ab030d99574ee01193e92846eb7c9b41bfcd149
# Parent 5a0860d81ed44d5f189788fc340f975517595160
Fixes for VNC port handling
When parsing sexpr, the VNC port should not be ignored, even when vncunused is
set. Fix the parsing of vncdisplay, which was broken due to strtol() (never
use this function!).
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/src/util.c b/src/util.c
--- a/src/util.c
+++ b/src/util.c
@@ -1041,6 +1041,7 @@ cleanup:
return rc;
}
+#endif /* PROXY */
/* Like strtol, but produce an "int" result, and check more carefully.
@@ -1123,7 +1124,6 @@ virStrToLong_ull(char const *s, char **e
*result = val;
return 0;
}
-#endif /* PROXY */
/**
* virSkipSpaces:
diff --git a/src/xend_internal.c b/src/xend_internal.c
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -612,7 +612,9 @@ sexpr_get(virConnectPtr xend, const char
*
* convenience function to lookup an int value in the S-Expression
*
- * Returns the value found or 0 if not found (but may not be an error)
+ * Returns the value found or 0 if not found (but may not be an error).
+ * This function suffers from the flaw that zero is both a correct
+ * return value and an error indicator: careful!
*/
static int
sexpr_int(const struct sexpr *sexpr, const char *name)
@@ -2091,15 +2093,16 @@ xenDaemonParseSxprGraphicsNew(virConnect
port = xenStoreDomainGetVNCPort(conn, def->id);
xenUnifiedUnlock(priv);
+ // Didn't find port entry in xenstore
if (port == -1) {
- // Didn't find port entry in xenstore
- port = sexpr_int(node, "device/vfb/vncdisplay");
+ const char *str = sexpr_node(node, "device/vfb/vncdisplay");
+ int val;
+ if (str != NULL && virStrToLong_i(str, NULL, 0, &val) == 0)
+ port = val;
}
- if ((unused && STREQ(unused, "1")) || port == -1) {
+ if ((unused && STREQ(unused, "1")) || port == -1)
graphics->data.vnc.autoport = 1;
- port = -1;
- }
if (port >= 0 && port < 5900)
port += 5900;
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-autoport.sexpr b/tests/sexpr2xmldata/sexpr2xml-fv-autoport.sexpr
new file mode 100644
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-autoport.sexpr
@@ -0,0 +1,86 @@
+(domain
+ (domid 21)
+ (on_crash destroy)
+ (uuid e0c172e6-4ad8-7353-0ece-515d2f181365)
+ (bootloader_args )
+ (vcpus 1)
+ (name domu-224)
+ (on_poweroff destroy)
+ (on_reboot destroy)
+ (bootloader )
+ (maxmem 512)
+ (memory 512)
+ (shadow_memory 5)
+ (cpu_weight 256)
+ (cpu_cap 0)
+ (features )
+ (on_xend_start ignore)
+ (on_xend_stop shutdown)
+ (start_time 1233108538.42)
+ (cpu_time 907.159661051)
+ (online_vcpus 1)
+ (image
+ (hvm
+ (kernel /usr/lib/xen/boot/hvmloader)
+ (boot d)
+ (device_model /usr/lib/xen/bin/qemu-dm)
+ (keymap en-us)
+ (localtime 1)
+ (pae 1)
+ (serial pty)
+ (usb 1)
+ (usbdevice tablet)
+ (notes (SUSPEND_CANCEL 1))
+ )
+ )
+ (status 2)
+ (state r-----)
+ (store_mfn 131070)
+ (device
+ (vif
+ (bridge e1000g0)
+ (mac 00:16:3e:1b:e8:18)
+ (script vif-vnic)
+ (uuid 7da8c614-018b-dc87-6bfc-a296a95bca4f)
+ (backend 0)
+ )
+ )
+ (device
+ (vbd
+ (uname phy:/iscsi/winxp)
+ (uuid 65e19258-f4a2-a9ff-3b31-469ceaf4ec8d)
+ (mode w)
+ (dev hda:disk)
+ (backend 0)
+ (bootable 1)
+ )
+ )
+ (device
+ (vbd
+ (uname file:/net/heaped/export/netimage/windows/xp-sp2-vol.iso)
+ (uuid 87d9383b-f0ad-11a4-d668-b965f55edc3f)
+ (mode r)
+ (dev hdc:cdrom)
+ (backend 0)
+ (bootable 0)
+ )
+ )
+ (device (vkbd (backend 0)))
+ (device
+ (vfb
+ (vncdisplay 25)
+ (vncunused 1)
+ (keymap en-us)
+ (type vnc)
+ (uuid 09666ad1-0c94-d79c-1439-99e05394ee51)
+ (location localhost:5925)
+ )
+ )
+ (device
+ (console
+ (protocol vt100)
+ (location 3)
+ (uuid cabfc0f5-1c9c-0e6f-aaa8-9974262aff66)
+ )
+ )
+)
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-autoport.xml b/tests/sexpr2xmldata/sexpr2xml-fv-autoport.xml
new file mode 100644
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-autoport.xml
@@ -0,0 +1,48 @@
+<domain type='xen' id='21'>
+ <name>domu-224</name>
+ <uuid>e0c172e6-4ad8-7353-0ece-515d2f181365</uuid>
+ <memory>524288</memory>
+ <currentMemory>524288</currentMemory>
+ <vcpu>1</vcpu>
+ <os>
+ <type>hvm</type>
+ <loader>/usr/lib/xen/boot/hvmloader</loader>
+ <boot dev='cdrom'/>
+ </os>
+ <features>
+ <pae/>
+ </features>
+ <clock offset='localtime'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>destroy</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
+ <disk type='block' device='disk'>
+ <driver name='phy'/>
+ <source dev='/iscsi/winxp'/>
+ <target dev='hda' bus='ide'/>
+ </disk>
+ <disk type='file' device='cdrom'>
+ <driver name='file'/>
+ <source file='/net/heaped/export/netimage/windows/xp-sp2-vol.iso'/>
+ <target dev='hdc' bus='ide'/>
+ <readonly/>
+ </disk>
+ <interface type='bridge'>
+ <mac address='00:16:3e:1b:e8:18'/>
+ <source bridge='e1000g0'/>
+ <script path='vif-vnic'/>
+ <target dev='vif21.0'/>
+ </interface>
+ <serial type='pty'>
+ <target port='0'/>
+ </serial>
+ <console type='pty'>
+ <target port='0'/>
+ </console>
+ <input type='tablet' bus='usb'/>
+ <input type='mouse' bus='ps2'/>
+ <graphics type='vnc' port='5925' autoport='yes' keymap='en-us'/>
+ </devices>
+</domain>
diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c
--- a/tests/sexpr2xmltest.c
+++ b/tests/sexpr2xmltest.c
@@ -127,6 +127,7 @@ mymain(int argc, char **argv)
DO_TEST("pv-vfb-orig", "pv-vfb-orig", 2);
DO_TEST("pv-vfb-new", "pv-vfb-new", 3);
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("disk-file", "disk-file", 2);
16 years, 2 months
[libvirt] [Patch][RFC] Fine grained access control in libvirt by rbac (0/3)
by Syunsuke HAYASHI
The series of patches introduces a fine grained access control to
libvirt. They enable libvirt to enforce users what operations to invoke
in role-based way. Our team found that Konrad and Daniel have similar
interest to ours. Comments and suggestions are very welcome.
Patches:
- Embedding hooks in libvirt (1/3)
- Access control library (2/3)
- Example policy files (3/3)
16 years, 2 months
[libvirt] PATCH: rpcgen portability fixes for remote_protocol.c/h
by Daniel P. Berrange
As per previous patches from John for Solaris, we ned a couple more fixes
to the generated remote_protocol.c/h files for good portability.
Specifically we need
s/u_quad_t/uint64_t/g;
s/quad_t/int64_t/g;
s/xdr_u_quad_t/xdr_uint64_t/g;
s/xdr_quad_t/xdr_int64_t/g;
s/IXDR_GET_LONG/IXDR_GET_INT32/g;
I have finally got around to verifying that this won't change wire
ABI on Linux
The first two data types int64 and quad_t are all fixed 64-bit ints,
so that's safe.
And the xdr_quad functions have this in the source
strong_alias (xdr_int64_t, xdr_quad_t)
strong_alias (xdr_int64_t, xdr_u_quad_t)
So that change is no-op.
Finally the glibc rpc/xdr.h has
#define IXDR_GET_LONG(buf) ((long)IXDR_GET_U_INT32(buf))
So I believe this is all safe.
Daniel
Index: configure.in
===================================================================
RCS file: /data/cvs/libvirt/configure.in,v
retrieving revision 1.202
diff -u -p -r1.202 configure.in
--- configure.in 27 Jan 2009 15:29:53 -0000 1.202
+++ configure.in 28 Jan 2009 12:30:59 -0000
@@ -92,9 +92,9 @@ AC_CHECK_LIB([intl],[gettext],[])
dnl Do we have rpcgen?
AC_PATH_PROG([RPCGEN], [rpcgen], [no])
-AM_CONDITIONAL([RPCGEN], [test "x$ac_cv_path_RPCGEN" != "xno"])
+AM_CONDITIONAL([HAVE_RPCGEN], [test "x$ac_cv_path_RPCGEN" != "xno"])
dnl Is this GLIBC's buggy rpcgen?
-AM_CONDITIONAL([GLIBC_RPCGEN],
+AM_CONDITIONAL([HAVE_GLIBC_RPCGEN],
[test "x$ac_cv_path_RPCGEN" != "xno" &&
$ac_cv_path_RPCGEN -t </dev/null >/dev/null 2>&1])
Index: qemud/Makefile.am
===================================================================
RCS file: /data/cvs/libvirt/qemud/Makefile.am,v
retrieving revision 1.72
diff -u -p -r1.72 Makefile.am
--- qemud/Makefile.am 12 Jan 2009 19:19:22 -0000 1.72
+++ qemud/Makefile.am 28 Jan 2009 12:31:00 -0000
@@ -1,7 +1,5 @@
## Process this file with automake to produce Makefile.in
-RPCGEN = $(RPCGEN)
-
DAEMON_SOURCES = \
event.c event.h \
qemud.c qemud.h \
@@ -33,32 +31,34 @@ EXTRA_DIST = \
$(AVAHI_SOURCES) \
$(DAEMON_SOURCES)
-if RPCGEN
-SUFFIXES = .x
-# The subshell ensures that remote_protocol.c ends up
-# including <config.h> before "remote_protocol.h".
-.x.c:
- rm -f $@ $@-t $@-t1 $@-t2
- $(RPCGEN) -c -o $@-t $<
- (echo '#include <config.h>'; cat $@-t) > $@-t1
-if GLIBC_RPCGEN
- perl -w rpcgen_fix.pl $@-t1 > $@-t2
- rm $@-t1
- chmod 444 $@-t2
- mv $@-t2 $@
+if HAVE_RPCGEN
+#
+# Maintainer-only target for re-generating the derived .c/.h source
+# files, which are actually derived from the .x file.
+#
+# For committing protocol changes to CVS, the GLIBC rpcgen *must*
+# be used.
+#
+# Support for non-GLIB rpcgen is here as a convenience for
+# non-Linux people needing to test changes during dev.
+#
+rpcgen:
+ rm -f rp.c-t rp.h-t rp.c-t1 rp.c-t2 rp.h-t1
+ $(RPCGEN) -h -o rp.h-t $(srcdir)/remote_protocol.x
+ $(RPCGEN) -c -o rp.c-t $(srcdir)/remote_protocol.x
+if HAVE_GLIBC_RPCGEN
+ perl -w $(srcdir)/rpcgen_fix.pl rp.h-t > rp.h-t1
+ perl -w $(srcdir)/rpcgen_fix.pl rp.c-t > rp.c-t1
+ (echo '#include <config.h>'; cat rp.c-t1) > rp.c-t2
+ chmod 0444 rp.c-t2 rp.h-t1
+ mv -f rp.h-t1 $(srcdir)/remote_protocol.h
+ mv -f rp.c-t2 $(srcdir)/remote_protocol.c
+ rm -f rp.c-t rp.h-t rp.c-t1
else
- chmod 444 $@-t1
- mv $@-t1 $@
-endif
-
-.x.h:
- rm -f $@ $@-t
- $(RPCGEN) -h -o $@-t $<
-if GLIBC_RPCGEN
- perl -pi -e 's/\t/ /g' $@-t
+ chmod 0444 rp.c-t rp.h-t
+ mv -f rp.h-t $(srcdir)/remote_protocol.h
+ mv -f rp.c-t $(srcdir)/remote_protocol.c
endif
- chmod 444 $@-t
- mv $@-t $@
endif
remote_protocol.c: remote_protocol.h
Index: qemud/remote_protocol.c
===================================================================
RCS file: /data/cvs/libvirt/qemud/remote_protocol.c,v
retrieving revision 1.27
diff -u -p -r1.27 remote_protocol.c
--- qemud/remote_protocol.c 6 Jan 2009 18:32:03 -0000 1.27
+++ qemud/remote_protocol.c 28 Jan 2009 12:31:00 -0000
@@ -183,7 +183,7 @@ xdr_remote_vcpu_info (XDR *xdrs, remote_
return FALSE;
if (!xdr_int (xdrs, &objp->state))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->cpu_time))
+ if (!xdr_uint64_t (xdrs, &objp->cpu_time))
return FALSE;
if (!xdr_int (xdrs, &objp->cpu))
return FALSE;
@@ -205,11 +205,11 @@ xdr_remote_sched_param_value (XDR *xdrs,
return FALSE;
break;
case VIR_DOMAIN_SCHED_FIELD_LLONG:
- if (!xdr_quad_t (xdrs, &objp->remote_sched_param_value_u.l))
+ if (!xdr_int64_t (xdrs, &objp->remote_sched_param_value_u.l))
return FALSE;
break;
case VIR_DOMAIN_SCHED_FIELD_ULLONG:
- if (!xdr_u_quad_t (xdrs, &objp->remote_sched_param_value_u.ul))
+ if (!xdr_uint64_t (xdrs, &objp->remote_sched_param_value_u.ul))
return FALSE;
break;
case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
@@ -279,7 +279,7 @@ bool_t
xdr_remote_get_version_ret (XDR *xdrs, remote_get_version_ret *objp)
{
- if (!xdr_quad_t (xdrs, &objp->hv_ver))
+ if (!xdr_int64_t (xdrs, &objp->hv_ver))
return FALSE;
return TRUE;
}
@@ -330,7 +330,7 @@ xdr_remote_node_get_info_ret (XDR *xdrs,
if (!xdr_vector (xdrs, (char *)objp->model, 32,
sizeof (char), (xdrproc_t) xdr_char))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->memory))
+ if (!xdr_int64_t (xdrs, &objp->memory))
return FALSE;
buf = (int32_t*)XDR_INLINE (xdrs, 6 * BYTES_PER_XDR_UNIT);
if (buf == NULL) {
@@ -359,7 +359,7 @@ xdr_remote_node_get_info_ret (XDR *xdrs,
if (!xdr_vector (xdrs, (char *)objp->model, 32,
sizeof (char), (xdrproc_t) xdr_char))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->memory))
+ if (!xdr_int64_t (xdrs, &objp->memory))
return FALSE;
buf = (int32_t*)XDR_INLINE (xdrs, 6 * BYTES_PER_XDR_UNIT);
if (buf == NULL) {
@@ -376,12 +376,12 @@ xdr_remote_node_get_info_ret (XDR *xdrs,
if (!xdr_int (xdrs, &objp->threads))
return FALSE;
} else {
- objp->cpus = IXDR_GET_LONG(buf);
- objp->mhz = IXDR_GET_LONG(buf);
- objp->nodes = IXDR_GET_LONG(buf);
- objp->sockets = IXDR_GET_LONG(buf);
- objp->cores = IXDR_GET_LONG(buf);
- objp->threads = IXDR_GET_LONG(buf);
+ objp->cpus = IXDR_GET_INT32(buf);
+ objp->mhz = IXDR_GET_INT32(buf);
+ objp->nodes = IXDR_GET_INT32(buf);
+ objp->sockets = IXDR_GET_INT32(buf);
+ objp->cores = IXDR_GET_INT32(buf);
+ objp->threads = IXDR_GET_INT32(buf);
}
return TRUE;
}
@@ -389,7 +389,7 @@ xdr_remote_node_get_info_ret (XDR *xdrs,
if (!xdr_vector (xdrs, (char *)objp->model, 32,
sizeof (char), (xdrproc_t) xdr_char))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->memory))
+ if (!xdr_int64_t (xdrs, &objp->memory))
return FALSE;
if (!xdr_int (xdrs, &objp->cpus))
return FALSE;
@@ -432,7 +432,7 @@ xdr_remote_node_get_cells_free_memory_re
char **objp_cpp0 = (char **) (void *) &objp->freeMems.freeMems_val;
if (!xdr_array (xdrs, objp_cpp0, (u_int *) &objp->freeMems.freeMems_len, REMOTE_NODE_MAX_CELLS,
- sizeof (quad_t), (xdrproc_t) xdr_quad_t))
+ sizeof (int64_t), (xdrproc_t) xdr_int64_t))
return FALSE;
return TRUE;
}
@@ -441,7 +441,7 @@ bool_t
xdr_remote_node_get_free_memory_ret (XDR *xdrs, remote_node_get_free_memory_ret *objp)
{
- if (!xdr_quad_t (xdrs, &objp->freeMem))
+ if (!xdr_int64_t (xdrs, &objp->freeMem))
return FALSE;
return TRUE;
}
@@ -516,15 +516,15 @@ bool_t
xdr_remote_domain_block_stats_ret (XDR *xdrs, remote_domain_block_stats_ret *objp)
{
- if (!xdr_quad_t (xdrs, &objp->rd_req))
+ if (!xdr_int64_t (xdrs, &objp->rd_req))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->rd_bytes))
+ if (!xdr_int64_t (xdrs, &objp->rd_bytes))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->wr_req))
+ if (!xdr_int64_t (xdrs, &objp->wr_req))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->wr_bytes))
+ if (!xdr_int64_t (xdrs, &objp->wr_bytes))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->errs))
+ if (!xdr_int64_t (xdrs, &objp->errs))
return FALSE;
return TRUE;
}
@@ -544,21 +544,21 @@ bool_t
xdr_remote_domain_interface_stats_ret (XDR *xdrs, remote_domain_interface_stats_ret *objp)
{
- if (!xdr_quad_t (xdrs, &objp->rx_bytes))
+ if (!xdr_int64_t (xdrs, &objp->rx_bytes))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->rx_packets))
+ if (!xdr_int64_t (xdrs, &objp->rx_packets))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->rx_errs))
+ if (!xdr_int64_t (xdrs, &objp->rx_errs))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->rx_drop))
+ if (!xdr_int64_t (xdrs, &objp->rx_drop))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->tx_bytes))
+ if (!xdr_int64_t (xdrs, &objp->tx_bytes))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->tx_packets))
+ if (!xdr_int64_t (xdrs, &objp->tx_packets))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->tx_errs))
+ if (!xdr_int64_t (xdrs, &objp->tx_errs))
return FALSE;
- if (!xdr_quad_t (xdrs, &objp->tx_drop))
+ if (!xdr_int64_t (xdrs, &objp->tx_drop))
return FALSE;
return TRUE;
}
@@ -571,7 +571,7 @@ xdr_remote_domain_block_peek_args (XDR *
return FALSE;
if (!xdr_remote_nonnull_string (xdrs, &objp->path))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->offset))
+ if (!xdr_uint64_t (xdrs, &objp->offset))
return FALSE;
if (!xdr_u_int (xdrs, &objp->size))
return FALSE;
@@ -596,7 +596,7 @@ xdr_remote_domain_memory_peek_args (XDR
if (!xdr_remote_nonnull_domain (xdrs, &objp->dom))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->offset))
+ if (!xdr_uint64_t (xdrs, &objp->offset))
return FALSE;
if (!xdr_u_int (xdrs, &objp->size))
return FALSE;
@@ -796,7 +796,7 @@ bool_t
xdr_remote_domain_get_max_memory_ret (XDR *xdrs, remote_domain_get_max_memory_ret *objp)
{
- if (!xdr_u_quad_t (xdrs, &objp->memory))
+ if (!xdr_uint64_t (xdrs, &objp->memory))
return FALSE;
return TRUE;
}
@@ -807,7 +807,7 @@ xdr_remote_domain_set_max_memory_args (X
if (!xdr_remote_nonnull_domain (xdrs, &objp->dom))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->memory))
+ if (!xdr_uint64_t (xdrs, &objp->memory))
return FALSE;
return TRUE;
}
@@ -818,7 +818,7 @@ xdr_remote_domain_set_memory_args (XDR *
if (!xdr_remote_nonnull_domain (xdrs, &objp->dom))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->memory))
+ if (!xdr_uint64_t (xdrs, &objp->memory))
return FALSE;
return TRUE;
}
@@ -838,13 +838,13 @@ xdr_remote_domain_get_info_ret (XDR *xdr
if (!xdr_u_char (xdrs, &objp->state))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->max_mem))
+ if (!xdr_uint64_t (xdrs, &objp->max_mem))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->memory))
+ if (!xdr_uint64_t (xdrs, &objp->memory))
return FALSE;
if (!xdr_u_short (xdrs, &objp->nr_virt_cpu))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->cpu_time))
+ if (!xdr_uint64_t (xdrs, &objp->cpu_time))
return FALSE;
return TRUE;
}
@@ -908,11 +908,11 @@ xdr_remote_domain_migrate_prepare_args (
if (!xdr_remote_string (xdrs, &objp->uri_in))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->flags))
+ if (!xdr_uint64_t (xdrs, &objp->flags))
return FALSE;
if (!xdr_remote_string (xdrs, &objp->dname))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->resource))
+ if (!xdr_uint64_t (xdrs, &objp->resource))
return FALSE;
return TRUE;
}
@@ -940,11 +940,11 @@ xdr_remote_domain_migrate_perform_args (
return FALSE;
if (!xdr_remote_nonnull_string (xdrs, &objp->uri))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->flags))
+ if (!xdr_uint64_t (xdrs, &objp->flags))
return FALSE;
if (!xdr_remote_string (xdrs, &objp->dname))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->resource))
+ if (!xdr_uint64_t (xdrs, &objp->resource))
return FALSE;
return TRUE;
}
@@ -960,7 +960,7 @@ xdr_remote_domain_migrate_finish_args (X
return FALSE;
if (!xdr_remote_nonnull_string (xdrs, &objp->uri))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->flags))
+ if (!xdr_uint64_t (xdrs, &objp->flags))
return FALSE;
return TRUE;
}
@@ -980,11 +980,11 @@ xdr_remote_domain_migrate_prepare2_args
if (!xdr_remote_string (xdrs, &objp->uri_in))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->flags))
+ if (!xdr_uint64_t (xdrs, &objp->flags))
return FALSE;
if (!xdr_remote_string (xdrs, &objp->dname))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->resource))
+ if (!xdr_uint64_t (xdrs, &objp->resource))
return FALSE;
if (!xdr_remote_nonnull_string (xdrs, &objp->dom_xml))
return FALSE;
@@ -1014,7 +1014,7 @@ xdr_remote_domain_migrate_finish2_args (
return FALSE;
if (!xdr_remote_nonnull_string (xdrs, &objp->uri))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->flags))
+ if (!xdr_uint64_t (xdrs, &objp->flags))
return FALSE;
if (!xdr_int (xdrs, &objp->retcode))
return FALSE;
@@ -1798,11 +1798,11 @@ xdr_remote_storage_pool_get_info_ret (XD
if (!xdr_u_char (xdrs, &objp->state))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->capacity))
+ if (!xdr_uint64_t (xdrs, &objp->capacity))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->allocation))
+ if (!xdr_uint64_t (xdrs, &objp->allocation))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->available))
+ if (!xdr_uint64_t (xdrs, &objp->available))
return FALSE;
return TRUE;
}
@@ -2000,9 +2000,9 @@ xdr_remote_storage_vol_get_info_ret (XDR
if (!xdr_char (xdrs, &objp->type))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->capacity))
+ if (!xdr_uint64_t (xdrs, &objp->capacity))
return FALSE;
- if (!xdr_u_quad_t (xdrs, &objp->allocation))
+ if (!xdr_uint64_t (xdrs, &objp->allocation))
return FALSE;
return TRUE;
}
Index: qemud/remote_protocol.h
===================================================================
RCS file: /data/cvs/libvirt/qemud/remote_protocol.h,v
retrieving revision 1.26
diff -u -p -r1.26 remote_protocol.h
--- qemud/remote_protocol.h 17 Dec 2008 17:23:21 -0000 1.26
+++ qemud/remote_protocol.h 28 Jan 2009 12:31:00 -0000
@@ -3,8 +3,8 @@
* It was generated using rpcgen.
*/
-#ifndef _REMOTE_PROTOCOL_H_RPCGEN
-#define _REMOTE_PROTOCOL_H_RPCGEN
+#ifndef _RP_H_RPCGEN
+#define _RP_H_RPCGEN
#include <rpc/rpc.h>
@@ -107,7 +107,7 @@ typedef enum remote_auth_type remote_aut
struct remote_vcpu_info {
u_int number;
int state;
- u_quad_t cpu_time;
+ uint64_t cpu_time;
int cpu;
};
typedef struct remote_vcpu_info remote_vcpu_info;
@@ -117,8 +117,8 @@ struct remote_sched_param_value {
union {
int i;
u_int ui;
- quad_t l;
- u_quad_t ul;
+ int64_t l;
+ uint64_t ul;
double d;
int b;
} remote_sched_param_value_u;
@@ -153,7 +153,7 @@ struct remote_get_type_ret {
typedef struct remote_get_type_ret remote_get_type_ret;
struct remote_get_version_ret {
- quad_t hv_ver;
+ int64_t hv_ver;
};
typedef struct remote_get_version_ret remote_get_version_ret;
@@ -179,7 +179,7 @@ typedef struct remote_get_max_vcpus_ret
struct remote_node_get_info_ret {
char model[32];
- quad_t memory;
+ int64_t memory;
int cpus;
int mhz;
int nodes;
@@ -203,13 +203,13 @@ typedef struct remote_node_get_cells_fre
struct remote_node_get_cells_free_memory_ret {
struct {
u_int freeMems_len;
- quad_t *freeMems_val;
+ int64_t *freeMems_val;
} freeMems;
};
typedef struct remote_node_get_cells_free_memory_ret remote_node_get_cells_free_memory_ret;
struct remote_node_get_free_memory_ret {
- quad_t freeMem;
+ int64_t freeMem;
};
typedef struct remote_node_get_free_memory_ret remote_node_get_free_memory_ret;
@@ -254,11 +254,11 @@ struct remote_domain_block_stats_args {
typedef struct remote_domain_block_stats_args remote_domain_block_stats_args;
struct remote_domain_block_stats_ret {
- quad_t rd_req;
- quad_t rd_bytes;
- quad_t wr_req;
- quad_t wr_bytes;
- quad_t errs;
+ int64_t rd_req;
+ int64_t rd_bytes;
+ int64_t wr_req;
+ int64_t wr_bytes;
+ int64_t errs;
};
typedef struct remote_domain_block_stats_ret remote_domain_block_stats_ret;
@@ -269,21 +269,21 @@ struct remote_domain_interface_stats_arg
typedef struct remote_domain_interface_stats_args remote_domain_interface_stats_args;
struct remote_domain_interface_stats_ret {
- quad_t rx_bytes;
- quad_t rx_packets;
- quad_t rx_errs;
- quad_t rx_drop;
- quad_t tx_bytes;
- quad_t tx_packets;
- quad_t tx_errs;
- quad_t tx_drop;
+ int64_t rx_bytes;
+ int64_t rx_packets;
+ int64_t rx_errs;
+ int64_t rx_drop;
+ int64_t tx_bytes;
+ int64_t tx_packets;
+ int64_t tx_errs;
+ int64_t tx_drop;
};
typedef struct remote_domain_interface_stats_ret remote_domain_interface_stats_ret;
struct remote_domain_block_peek_args {
remote_nonnull_domain dom;
remote_nonnull_string path;
- u_quad_t offset;
+ uint64_t offset;
u_int size;
u_int flags;
};
@@ -299,7 +299,7 @@ typedef struct remote_domain_block_peek_
struct remote_domain_memory_peek_args {
remote_nonnull_domain dom;
- u_quad_t offset;
+ uint64_t offset;
u_int size;
u_int flags;
};
@@ -414,19 +414,19 @@ struct remote_domain_get_max_memory_args
typedef struct remote_domain_get_max_memory_args remote_domain_get_max_memory_args;
struct remote_domain_get_max_memory_ret {
- u_quad_t memory;
+ uint64_t memory;
};
typedef struct remote_domain_get_max_memory_ret remote_domain_get_max_memory_ret;
struct remote_domain_set_max_memory_args {
remote_nonnull_domain dom;
- u_quad_t memory;
+ uint64_t memory;
};
typedef struct remote_domain_set_max_memory_args remote_domain_set_max_memory_args;
struct remote_domain_set_memory_args {
remote_nonnull_domain dom;
- u_quad_t memory;
+ uint64_t memory;
};
typedef struct remote_domain_set_memory_args remote_domain_set_memory_args;
@@ -437,10 +437,10 @@ typedef struct remote_domain_get_info_ar
struct remote_domain_get_info_ret {
u_char state;
- u_quad_t max_mem;
- u_quad_t memory;
+ uint64_t max_mem;
+ uint64_t memory;
u_short nr_virt_cpu;
- u_quad_t cpu_time;
+ uint64_t cpu_time;
};
typedef struct remote_domain_get_info_ret remote_domain_get_info_ret;
@@ -475,9 +475,9 @@ typedef struct remote_domain_dump_xml_re
struct remote_domain_migrate_prepare_args {
remote_string uri_in;
- u_quad_t flags;
+ uint64_t flags;
remote_string dname;
- u_quad_t resource;
+ uint64_t resource;
};
typedef struct remote_domain_migrate_prepare_args remote_domain_migrate_prepare_args;
@@ -497,9 +497,9 @@ struct remote_domain_migrate_perform_arg
char *cookie_val;
} cookie;
remote_nonnull_string uri;
- u_quad_t flags;
+ uint64_t flags;
remote_string dname;
- u_quad_t resource;
+ uint64_t resource;
};
typedef struct remote_domain_migrate_perform_args remote_domain_migrate_perform_args;
@@ -510,7 +510,7 @@ struct remote_domain_migrate_finish_args
char *cookie_val;
} cookie;
remote_nonnull_string uri;
- u_quad_t flags;
+ uint64_t flags;
};
typedef struct remote_domain_migrate_finish_args remote_domain_migrate_finish_args;
@@ -521,9 +521,9 @@ typedef struct remote_domain_migrate_fin
struct remote_domain_migrate_prepare2_args {
remote_string uri_in;
- u_quad_t flags;
+ uint64_t flags;
remote_string dname;
- u_quad_t resource;
+ uint64_t resource;
remote_nonnull_string dom_xml;
};
typedef struct remote_domain_migrate_prepare2_args remote_domain_migrate_prepare2_args;
@@ -544,7 +544,7 @@ struct remote_domain_migrate_finish2_arg
char *cookie_val;
} cookie;
remote_nonnull_string uri;
- u_quad_t flags;
+ uint64_t flags;
int retcode;
};
typedef struct remote_domain_migrate_finish2_args remote_domain_migrate_finish2_args;
@@ -1002,9 +1002,9 @@ typedef struct remote_storage_pool_get_i
struct remote_storage_pool_get_info_ret {
u_char state;
- u_quad_t capacity;
- u_quad_t allocation;
- u_quad_t available;
+ uint64_t capacity;
+ uint64_t allocation;
+ uint64_t available;
};
typedef struct remote_storage_pool_get_info_ret remote_storage_pool_get_info_ret;
@@ -1115,8 +1115,8 @@ typedef struct remote_storage_vol_get_in
struct remote_storage_vol_get_info_ret {
char type;
- u_quad_t capacity;
- u_quad_t allocation;
+ uint64_t capacity;
+ uint64_t allocation;
};
typedef struct remote_storage_vol_get_info_ret remote_storage_vol_get_info_ret;
@@ -1793,4 +1793,4 @@ extern bool_t xdr_remote_message_header
}
#endif
-#endif /* !_REMOTE_PROTOCOL_H_RPCGEN */
+#endif /* !_RP_H_RPCGEN */
Index: qemud/rpcgen_fix.pl
===================================================================
RCS file: /data/cvs/libvirt/qemud/rpcgen_fix.pl,v
retrieving revision 1.4
diff -u -p -r1.4 rpcgen_fix.pl
--- qemud/rpcgen_fix.pl 6 Jan 2009 18:32:03 -0000 1.4
+++ qemud/rpcgen_fix.pl 28 Jan 2009 12:31:00 -0000
@@ -26,6 +26,14 @@ while (<>) {
s/\t/ /g;
+ # Portability for Solaris RPC
+ s/u_quad_t/uint64_t/g;
+ s/quad_t/int64_t/g;
+ s/xdr_u_quad_t/xdr_uint64_t/g;
+ s/xdr_quad_t/xdr_int64_t/g;
+ s/IXDR_GET_LONG/IXDR_GET_INT32/g;
+ s,#include "\./remote_protocol\.h",#include "remote_protocol.h",;
+
if (m/^}/) {
$in_function = 0;
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
16 years, 2 months
[libvirt] PATCH: Fix remote driver RPC recv handling
by Daniel P. Berrange
I noticed a odd error message randomly appearing from virsh after all
commands had been run
# virsh dominfo VirtTest
Id: -
Name: VirtTest
UUID: 82038f2a-1344-aaf7-1a85-2a7250be2076
OS Type: hvm
State: shut off
CPU(s): 3
Max memory: 256000 kB
Used memory: 256000 kB
Autostart: disable
libvir: Remote error : server closed connection
It turns out that inthe for(;;) loop where I'm procesing incoming data,
it was forgetting to break out of the loop when a completed RPC call
had been received. Most of the time this wasn't problem, because there'd
rarely be more data following, so it'd get EAGAIN next iteration & quit
the loop. When shutting down though, you'd occassionally see the SIGHUP
from read() before you get an EAGAIN, causing this error to be raised
even though the RPC call had been successfully received.
In addition, if there was a 2nd RPC reply already pending, we'd read and
loose some of its data. Though I never saw this happen, it is a definite
theoretical possibility, particularly over a TCP link with bad latency
or fragementation or bursty traffic.
Daniel
diff -r e582072116a3 src/remote_internal.c
--- a/src/remote_internal.c Mon Jan 26 16:21:42 2009 +0000
+++ b/src/remote_internal.c Mon Jan 26 17:02:15 2009 +0000
@@ -6135,12 +6135,27 @@ processCallRecv(virConnectPtr conn, stru
if (priv->bufferOffset == priv->bufferLength) {
if (priv->bufferOffset == 4) {
ret = processCallRecvLen(conn, priv, in_open);
+ if (ret < 0)
+ return -1;
+
+ /*
+ * We'll carry on around the loop to immediately
+ * process the message body, because it has probably
+ * already arrived. Worst case, we'll get EAGAIN on
+ * next iteration.
+ */
} else {
ret = processCallRecvMsg(conn, priv, in_open);
priv->bufferOffset = priv->bufferLength = 0;
- }
- if (ret < 0)
- return -1;
+ /*
+ * We've completed one call, so return even
+ * though there might still be more data on
+ * the wire. We need to actually let the caller
+ * deal with this arrived message to keep good
+ * response, and also to correctly handle EOF.
+ */
+ return ret;
+ }
}
}
}
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
16 years, 2 months
[libvirt] setting up dnsmasq options for PXE boot
by Dmitry Guryanov
Hello,
I want to use PXE boot in kvm's virtual machines, but I've not found, how to
configure libvirt for starting dhcp server with correct options for this.
Now i have libvirt-0.5.1-2.fc10.x86_64 and virt-manager-0.6.0-5.fc10.x86_64,
I've created VM using virt manager, with specifying PXE boot option. VM config
contains following sections:
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='network'/>
</os>
.....
<interface type='network'>
<mac address='54:52:00:0a:f6:00'/>
<source network='nat_net'/>
<model type='virtio'/>
</interface>
and config for virtual network nat_net:
<network>
<name>nat_net</name>
<uuid>e02cfc6f-d7f8-6f81-8c19-bfa9d2a13a85</uuid>
<forward dev='eth0' mode='nat'/>
<bridge stp='on' forwardDelay='0' />
<ip address='192.168.107.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.107.128' end='192.168.107.254' />
</dhcp>
</ip>
</network>
dnsmasq starts with following command line:
/usr/sbin/dnsmasq --keep-in-foreground --strict-order --bind-interfaces--pid-
file --conf-file --listen-address 192.168.107.1 --except-interface lo --dhcp-
leasefile=/var/lib/libvirt/dhcp-nat_net.leases --dhcp-range
192.168.107.128,192.168.107.254
But for working PXE boot it should have also something like
--dhcp-boot=pxelinux.0,itchy,192.168.107.1
So after starting VM it tries to boot from network, gets DHCP response and
reports, that it doesn't contains filename option.
So the question is - how to get it working correctly ? (If i start dnsmasq by
hand with option --dhcp-boot=pxelinux.0,itchy,192.168.107.1 PXE boot works)
--
Dmitry Guryanov
16 years, 2 months
[libvirt] PATCH: Misc Xen driver bug fixes
by Daniel P. Berrange
Testing current CVS on RHEL-5 host exposed a number of problems in the
Xen driver
- When opening the remote driver for the network / storage / nodedev
APIs, we had missed the initialization of several fields, resulting
in a crash
- Reporting of errors from the remote driver was leaking memory, due
to missing xdr_free call.
- Small possibility of de-referencing NULL when handling an error
from the server, if no error message were provided
- Mistakenly tries to activate Xen INotify driver when non-root, even
though the directories it needs to monitor are chmod 0700 root.root
- Gratuitous reporting of failure to connect to XenD's TCP port when
running non-root, even though the proxy / remote driver will suceed
- Bad return values from the xenDaemonOpen() method
- Double free in the new xenStoreDoListDomains() method probably due
to merge error
The only really intreresting bit of the patch is for the first issue
in the remote driver. I've basically pulled out alot of duplicated
code into a couple of helper methods, so make these missing initialization
less likely in future.
remote_internal.c | 153 +++++++++++++++++++++++++-----------------------------
xen_unified.c | 12 ++--
xend_internal.c | 50 ++++++-----------
xs_internal.c | 2
4 files changed, 97 insertions(+), 120 deletions(-)
Daniel
Index: src/remote_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/remote_internal.c,v
retrieving revision 1.130
diff -u -p -u -p -r1.130 remote_internal.c
--- src/remote_internal.c 28 Jan 2009 16:14:24 -0000 1.130
+++ src/remote_internal.c 28 Jan 2009 16:24:20 -0000
@@ -892,31 +892,70 @@ doRemoteOpen (virConnectPtr conn,
goto cleanup;
}
-static virDrvOpenStatus
-remoteOpen (virConnectPtr conn,
- virConnectAuthPtr auth,
- int flags)
+static struct private_data *
+remoteAllocPrivateData(virConnectPtr conn)
{
struct private_data *priv;
- int ret, rflags = 0;
-
- if (inside_daemon)
- return VIR_DRV_OPEN_DECLINED;
-
if (VIR_ALLOC(priv) < 0) {
- error (conn, VIR_ERR_NO_MEMORY, _("struct private_data"));
- return VIR_DRV_OPEN_ERROR;
+ virReportOOMError(conn);
+ return NULL;
}
if (virMutexInit(&priv->lock) < 0) {
error(conn, VIR_ERR_INTERNAL_ERROR,
_("cannot initialize mutex"));
VIR_FREE(priv);
- return VIR_DRV_OPEN_ERROR;
+ return NULL;
}
remoteDriverLock(priv);
priv->localUses = 1;
priv->watch = -1;
+ priv->sock = -1;
+
+ return priv;
+}
+
+static int
+remoteOpenSecondaryDriver(virConnectPtr conn,
+ virConnectAuthPtr auth,
+ int flags,
+ struct private_data **priv)
+{
+ int ret;
+ int rflags = 0;
+
+ if (!((*priv) = remoteAllocPrivateData(conn)))
+ return VIR_DRV_OPEN_ERROR;
+
+ if (flags & VIR_CONNECT_RO)
+ rflags |= VIR_DRV_OPEN_REMOTE_RO;
+ rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
+
+ ret = doRemoteOpen(conn, *priv, auth, rflags);
+ if (ret != VIR_DRV_OPEN_SUCCESS) {
+ remoteDriverUnlock(*priv);
+ VIR_FREE(*priv);
+ } else {
+ (*priv)->localUses = 1;
+ remoteDriverUnlock(*priv);
+ }
+
+ return ret;
+}
+
+static virDrvOpenStatus
+remoteOpen (virConnectPtr conn,
+ virConnectAuthPtr auth,
+ int flags)
+{
+ struct private_data *priv;
+ int ret, rflags = 0;
+
+ if (inside_daemon)
+ return VIR_DRV_OPEN_DECLINED;
+
+ if (!(priv = remoteAllocPrivateData(conn)))
+ return VIR_DRV_OPEN_ERROR;
if (flags & VIR_CONNECT_RO)
rflags |= VIR_DRV_OPEN_REMOTE_RO;
@@ -971,7 +1010,6 @@ remoteOpen (virConnectPtr conn,
#endif
}
- priv->sock = -1;
ret = doRemoteOpen(conn, priv, auth, rflags);
if (ret != VIR_DRV_OPEN_SUCCESS) {
conn->privateData = NULL;
@@ -3085,30 +3123,13 @@ remoteNetworkOpen (virConnectPtr conn,
* which doesn't have its own impl of the network APIs.
*/
struct private_data *priv;
- int ret, rflags = 0;
- if (VIR_ALLOC(priv) < 0) {
- error (conn, VIR_ERR_NO_MEMORY, _("struct private_data"));
- return VIR_DRV_OPEN_ERROR;
- }
- if (virMutexInit(&priv->lock) < 0) {
- error(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot initialize mutex"));
- VIR_FREE(priv);
- return VIR_DRV_OPEN_ERROR;
- }
- if (flags & VIR_CONNECT_RO)
- rflags |= VIR_DRV_OPEN_REMOTE_RO;
- rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
-
- priv->sock = -1;
- ret = doRemoteOpen(conn, priv, auth, rflags);
- if (ret != VIR_DRV_OPEN_SUCCESS) {
- conn->networkPrivateData = NULL;
- VIR_FREE(priv);
- } else {
- priv->localUses = 1;
+ int ret;
+ ret = remoteOpenSecondaryDriver(conn,
+ auth,
+ flags,
+ &priv);
+ if (ret == VIR_DRV_OPEN_SUCCESS)
conn->networkPrivateData = priv;
- }
return ret;
}
}
@@ -3598,30 +3619,13 @@ remoteStorageOpen (virConnectPtr conn,
* which doesn't have its own impl of the network APIs.
*/
struct private_data *priv;
- int ret, rflags = 0;
- if (VIR_ALLOC(priv) < 0) {
- error (NULL, VIR_ERR_NO_MEMORY, _("struct private_data"));
- return VIR_DRV_OPEN_ERROR;
- }
- if (virMutexInit(&priv->lock) < 0) {
- error(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot initialize mutex"));
- VIR_FREE(priv);
- return VIR_DRV_OPEN_ERROR;
- }
- if (flags & VIR_CONNECT_RO)
- rflags |= VIR_DRV_OPEN_REMOTE_RO;
- rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
-
- priv->sock = -1;
- ret = doRemoteOpen(conn, priv, auth, rflags);
- if (ret != VIR_DRV_OPEN_SUCCESS) {
- conn->storagePrivateData = NULL;
- VIR_FREE(priv);
- } else {
- priv->localUses = 1;
+ int ret;
+ ret = remoteOpenSecondaryDriver(conn,
+ auth,
+ flags,
+ &priv);
+ if (ret == VIR_DRV_OPEN_SUCCESS)
conn->storagePrivateData = priv;
- }
return ret;
}
}
@@ -4551,30 +4555,13 @@ remoteDevMonOpen(virConnectPtr conn,
* which doesn't have its own impl of the network APIs.
*/
struct private_data *priv;
- int ret, rflags = 0;
- if (VIR_ALLOC(priv) < 0) {
- error (NULL, VIR_ERR_NO_MEMORY, _("struct private_data"));
- return VIR_DRV_OPEN_ERROR;
- }
- if (virMutexInit(&priv->lock) < 0) {
- error(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot initialize mutex"));
- VIR_FREE(priv);
- return VIR_DRV_OPEN_ERROR;
- }
- if (flags & VIR_CONNECT_RO)
- rflags |= VIR_DRV_OPEN_REMOTE_RO;
- rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
-
- priv->sock = -1;
- ret = doRemoteOpen(conn, priv, auth, rflags);
- if (ret != VIR_DRV_OPEN_SUCCESS) {
- conn->devMonPrivateData = NULL;
- VIR_FREE(priv);
- } else {
- priv->localUses = 1;
+ int ret;
+ ret = remoteOpenSecondaryDriver(conn,
+ auth,
+ flags,
+ &priv);
+ if (ret == VIR_DRV_OPEN_SUCCESS)
conn->devMonPrivateData = priv;
- }
return ret;
}
}
@@ -6419,6 +6406,7 @@ cleanup:
thiscall->err.domain == VIR_FROM_REMOTE &&
thiscall->err.code == VIR_ERR_RPC &&
thiscall->err.level == VIR_ERR_ERROR &&
+ thiscall->err.message &&
STRPREFIX(*thiscall->err.message, "unknown procedure")) {
rv = -2;
} else {
@@ -6426,6 +6414,7 @@ cleanup:
&thiscall->err);
rv = -1;
}
+ xdr_free((xdrproc_t)xdr_remote_error, (char *)&thiscall->err);
} else {
rv = 0;
}
Index: src/xen_unified.c
===================================================================
RCS file: /data/cvs/libvirt/src/xen_unified.c,v
retrieving revision 1.81
diff -u -p -u -p -r1.81 xen_unified.c
--- src/xen_unified.c 27 Jan 2009 08:50:04 -0000 1.81
+++ src/xen_unified.c 28 Jan 2009 16:24:21 -0000
@@ -355,11 +355,13 @@ xenUnifiedOpen (virConnectPtr conn, virC
}
#if WITH_XEN_INOTIFY
- DEBUG0("Trying Xen inotify sub-driver");
- if (drivers[XEN_UNIFIED_INOTIFY_OFFSET]->open(conn, auth, flags) ==
- VIR_DRV_OPEN_SUCCESS) {
- DEBUG0("Activated Xen inotify sub-driver");
- priv->opened[XEN_UNIFIED_INOTIFY_OFFSET] = 1;
+ if (xenHavePrivilege()) {
+ DEBUG0("Trying Xen inotify sub-driver");
+ if (drivers[XEN_UNIFIED_INOTIFY_OFFSET]->open(conn, auth, flags) ==
+ VIR_DRV_OPEN_SUCCESS) {
+ DEBUG0("Activated Xen inotify sub-driver");
+ priv->opened[XEN_UNIFIED_INOTIFY_OFFSET] = 1;
+ }
}
#endif
Index: src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.243
diff -u -p -u -p -r1.243 xend_internal.c
--- src/xend_internal.c 28 Jan 2009 14:36:23 -0000 1.243
+++ src/xend_internal.c 28 Jan 2009 16:24:21 -0000
@@ -838,9 +838,11 @@ xenDaemonOpen_tcp(virConnectPtr conn, co
freeaddrinfo (res);
if (!priv->addrlen) {
- virReportSystemError(conn, saved_errno,
- _("unable to connect to '%s:%s'"),
- host, port);
+ /* Don't raise error when unprivileged, since proxy takes over */
+ if (xenHavePrivilege())
+ virReportSystemError(conn, saved_errno,
+ _("unable to connect to '%s:%s'"),
+ host, port);
return -1;
}
@@ -2721,7 +2723,6 @@ error:
* @flags: combination of virDrvOpenFlag(s)
*
* Creates a localhost Xen Daemon connection
- * Note: this doesn't try to check if the connection actually works
*
* Returns 0 in case of success, -1 in case of error.
*/
@@ -2730,7 +2731,8 @@ xenDaemonOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED)
{
- int ret;
+ char *port = NULL;
+ int ret = VIR_DRV_OPEN_ERROR;
/* Switch on the scheme, which we expect to be NULL (file),
* "http" or "xen".
@@ -2741,45 +2743,30 @@ xenDaemonOpen(virConnectPtr conn,
virXendError(NULL, VIR_ERR_NO_CONNECT, __FUNCTION__);
goto failed;
}
- ret = xenDaemonOpen_unix(conn, conn->uri->path);
- if (ret < 0)
- goto failed;
-
- ret = xend_detect_config_version(conn);
- if (ret == -1)
+ if (xenDaemonOpen_unix(conn, conn->uri->path) < 0 ||
+ xend_detect_config_version(conn) == -1)
goto failed;
}
else if (STRCASEEQ (conn->uri->scheme, "xen")) {
/*
* try first to open the unix socket
*/
- ret = xenDaemonOpen_unix(conn, "/var/lib/xend/xend-socket");
- if (ret < 0)
- goto try_http;
- ret = xend_detect_config_version(conn);
- if (ret != -1)
+ if (xenDaemonOpen_unix(conn, "/var/lib/xend/xend-socket") == 0 &&
+ xend_detect_config_version(conn) != -1)
goto done;
- try_http:
/*
* try though http on port 8000
*/
- ret = xenDaemonOpen_tcp(conn, "localhost", "8000");
- if (ret < 0)
- goto failed;
- ret = xend_detect_config_version(conn);
- if (ret == -1)
+ if (xenDaemonOpen_tcp(conn, "localhost", "8000") < 0 ||
+ xend_detect_config_version(conn) == -1)
goto failed;
} else if (STRCASEEQ (conn->uri->scheme, "http")) {
- char *port;
if (virAsprintf(&port, "%d", conn->uri->port) == -1)
goto failed;
- ret = xenDaemonOpen_tcp(conn, conn->uri->server, port);
- VIR_FREE(port);
- if (ret < 0)
- goto failed;
- ret = xend_detect_config_version(conn);
- if (ret == -1)
+
+ if (xenDaemonOpen_tcp(conn, conn->uri->server, port) < 0 ||
+ xend_detect_config_version(conn) == -1)
goto failed;
} else {
virXendError(NULL, VIR_ERR_NO_CONNECT, __FUNCTION__);
@@ -2787,10 +2774,11 @@ xenDaemonOpen(virConnectPtr conn,
}
done:
- return(ret);
+ ret = VIR_DRV_OPEN_SUCCESS;
failed:
- return(-1);
+ VIR_FREE(port);
+ return ret;
}
Index: src/xs_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xs_internal.c,v
retrieving revision 1.85
diff -u -p -u -p -r1.85 xs_internal.c
--- src/xs_internal.c 23 Jan 2009 19:18:24 -0000 1.85
+++ src/xs_internal.c 28 Jan 2009 16:24:21 -0000
@@ -597,8 +597,6 @@ xenStoreDoListDomains(xenUnifiedPrivateP
ids[ret++] = (int) id;
}
- free(idlist);
-
out:
VIR_FREE (idlist);
return ret;
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
16 years, 2 months