[Libvir] [PATCH 0/2] Re-organize generation / handling of capabilities data
by Daniel P. Berrange
Earlier today I started the 'simple' task of extending the QEMU driver to
support Xenner for running Xen paravirt guests under KVM. This was at first
glance easy because it basically looks like QEMU - in fact all we needed
was to extend the capabilities XML for the QEMU driver to include data
about Xen guests if Xenner is available.
Unfortunately this was easier said than done...
- The code generating the XML in qemu_driver.c was a mix of string
formatting for the XML, and functional logic for determining runtime
capabilities (kvm, kqemu, etc).
- More runtime logic was in the qemu_conf.c file and stuff that should
be runtime logic was static.
I attempted to fix up the QEMU code for capabilities but it quickly turned
into a horrible mess of spaghetti.
Looking at the Xen driver, the situation was pretty much the same, but
with the capabilities XML generation spread out over 3 files (xml.c,
xen_internal.c and xend_internal.c).
So I decided that we needed to have a internal API & structure to allow
drivers to formally register & query their capabilities , and also add a
central method for serializing it to XML. The following 2 patches implement
this idea, and porting the Xen, QEMU and Test drivers to use it.
This removes a lot of code duplication in XML formatting and makes the
resulting code easier to follow, and should make it much quicker to
adding capabilities info to new drivers too.
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
16 years, 7 months
[Libvir] [PATCH]check NULL of mac
by S.Sakamoto
Hi,
"attach-device" become the segmentation fault,
when it uses following xml. (There is no "address='xx'")
+----------------------------------------------------+
| <interface type='bridge'> |
| <source bridge='xenbr0'/> |
| <mac/> |
| <script path='/etc/xen/scripts/vif-bridge'/> |
| </interface> |
+----------------------------------------------------+
Libxml gives back NULL when there is not an attribute.
"xenXMAttachInterface" compares it in strcmp as NULL.
So, I make the patch which solved this problem.
Thanks,
Shigeki Sakamoto.
Index: src/xm_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xm_internal.c,v
retrieving revision 1.64
diff -u -p -r1.64 xm_internal.c
--- src/xm_internal.c 20 Feb 2008 15:29:13 -0000 1.64
+++ src/xm_internal.c 26 Feb 2008 06:39:05 -0000
@@ -2769,12 +2769,13 @@ xenXMAttachInterface(virDomainPtr domain
}
source = xmlGetProp(node, BAD_CAST type);
- if (!(node = virXPathNode("/interface/mac", ctxt))) {
+ if ((node = virXPathNode("/interface/mac", ctxt)))
+ mac = xmlGetProp(node, BAD_CAST "address");
+ if (!node || !mac) {
if (!(mac = (xmlChar *)xenXMAutoAssignMac()))
goto cleanup;
autoassign = 1;
- } else
- mac = xmlGetProp(node, BAD_CAST "address");
+ }
list_item = virConfGetValue(entry->conf, "vif");
if (list_item && list_item->type == VIR_CONF_LIST) {
16 years, 7 months
[Libvir] RFC: Supporting serial & parallel ports for QEMU (and improving Xen)
by Daniel P. Berrange
One user's feature request for our QEMU driver is to support serial ports.
Easy you might think... you'd be wrong :-)
On Xen we have very simple approach. When creating a guest simply add
<console/>
And it'll cause a serial port to be setup with an autoallocated pty, so
you get back
<console pty='/dev/pts/5'/>
In retrospect calling it 'console' was dumb, but hey we're stuck with that
now and its only a tiny naming issue so I don't mind really.
We can do the same thing with QEMU quite easily. QEMU, however, supports
many many many more ways to hooking up the serial port to Dom0. Indeed
so does Xen fullyvirt, but we don't expose this ability. Parallel ports
have identical config syntax to serial ports so we might as well deal
with both at once.
So, here's a stripped down version of the QEMU docs:
[quote http://fabrice.bellard.free.fr/qemu/qemu-doc.html#SEC10]
`-serial dev'
Redirect the virtual serial port to host character device dev. The
default device is vc in graphical mode and stdio in non graphical
mode. This option can be used several times to simulate up to 4
serials ports. Use -serial none to disable all serial ports.
Available character devices are:
vc
Virtual console
pty
[Linux only] Pseudo TTY (a new PTY is automatically allocated)
none
No device is allocated.
null
void device
/dev/XXX
[Linux only] Use host tty, e.g. `/dev/ttyS0'. The host serial port
parameters are set according to the emulated ones.
/dev/parportN
[Linux only, parallel port only] Use host parallel port N. Currently
only SPP parallel port features can be used.
file:filename
Write output to filename. No character can be read.
stdio
[Unix only] standard input/output
pipe:filename
name pipe filename
COMn
[Windows only] Use host serial port n
udp:[remote_host]:remote_port[@[src_ip]:src_port]
This implements UDP Net Console.
tcp:[host]:port[,server][,nowait][,nodelay]
The TCP Net Console has two modes of operation.
telnet:host:port[,server][,nowait][,nodelay]
The telnet protocol is used instead of raw tcp sockets.
unix:path[,server][,nowait]
A unix domain socket is used instead of a tcp socket.
[/quote]
I don't see any reason to not support all/most of these options. The things
I don't like here is that /dev/XXX, vs /dev/parportN, vs COMn differences
for connecting guest <-> host passthrough of the devices. I figure it could
be simpler if it was just represented as 'n' and we'd translate that to
be /dev/ttyS[n] or /dev/parport[n] or COM[n] as needed.
The question as ever is how to represent this in XML. For serial ports we'll
stick with '<console>', while parallel ports we might as well use a better
named '<parallel>'. Next up, I think should use a 'type' attribute on this
element to determine the main way ot connecting the device, and then more
type specific attributes or sub-elements as needed. If 'type' was not
specified then use a default of 'pty', since that gives compatability with
existing practice.
As an illustrative example
/*
* Parse the XML definition for a character device
*
* Top level node will be <console> or <parallel>, but all attributes
* and sub-elements are identical.
*
* type=vc|pty|null|host|file|pipe|udp|tcp|telnet, default is pty
*
* <console type='vc'/>
*
* <console type='pty' pty='/dev/pts/3'/>
*
* <console type='null'/>
*
* <console type='host' port='3'/>
*
* <console type='file' path='/some/file'/>
*
* <console type='pipe' path='/some/file'/>
*
* <console type='udp'>
* <sendto port='12356'/>
* </console>
*
* <console type='udp'>
* <sendto addr='127.0.0.1' port='12356'/>
* </console>
*
* <console type='udp'>
* <sendto addr='127.0.0.1' port='12356'/>
* <bind port='12356'/>
* </console>
*
* <console type='udp'>
* <sendto addr='127.0.0.1' port='12356'/>
* <bind addr='127.0.0.1' port='12356'/>
* </console>
*
* <console type='tcp'>
* <listen port='12356'/>
* </console>
*
* <console type='tcp'>
* <listen addr='127.0.0.1' port='12356'>
* <nowait/>
* <nodelay/>
* </listen>
* </console>
*
* <console type='tcp'>
* <connect addr='127.0.0.1' port='12356'>
* <nodelay/>
* </connect>
* </console>
*
* <console type='telnet'>
* <listen addr='127.0.0.1' port='12356'/>
* </console>
*
* <console type='telnet'>
* <connect addr='127.0.0.1' port='12356'/>
* </console>
*
*/
BTW, the udp, tcp, telnet options are only available on QEMU >= 0.9.0. We
already have ability to detect / validate that for both Xen & QEMU drivers.
NB, whereever there are IP addresses, hostnames can be used too, hence I
call the attriute 'addr' instead of 'ip'
Regards,
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
16 years, 7 months
[Libvir] default hypervisor selection
by Daniel Veillard
While going though the ovirt installation steps I got annoyed with
the need to add "-c qemu:///system" each time we are trying to start a
virsh command if using KVM. The dfault setup is basically to assume
a Xen hypervisor if the URI is not specified, this is glued in the
do_open internal opening routine associated to the opening of connections:
--------------------------------------
static virConnectPtr
do_open (const char *name,
virConnectAuthPtr auth,
int flags)
{
int i, res;
virConnectPtr ret = NULL;
xmlURIPtr uri;
/* Convert NULL or "" to xen:/// for back compat */
if (!name || name[0] == '\0')
name = "xen:///";
--------------------------------------
In one hand this is the default behaviour of the library, but
in my opinion it's not very smart. We should be able to be smarter than
that, for example:
- if /proc/xen doesn't exist (on linux, or /dev/xen on Solaris) well
we should not do that we are pretty sure we will get an error when
trying to connect
- if /proc/vz is present, well it's very likely that if the kernel
has been compiled with OpenVZ support, it's likely to be used as the
default virtualization
- if there is a kvm module loaded well we should probably use
qemu:///system if running as root or qemu:///session otherwise
I guess on Solaris an easy heuristic would allow to pick the right
hypervisor by default too.
At some point we may have multiple hypervisor support simultaneously
on a linux system thanks to pv_ops, but right now it doesn't make too
much sense to force a default Xen connection even when we know it won't
work.
For a virsh specific solution there is the VIRSH_DEFAULT_CONNECT_URI
environment variable, but it's not really user friendly and not very
generic,
What do people think ? I would be tempted to provide a patch to change
do_open() behaviour on linux in the case name is NULL or "", and
then check what hypervisor might be present and running,
Daniel
--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard | virtualization library http://libvirt.org/
veillard(a)redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
16 years, 7 months
[Libvir] [Discussion] 0/4 Implement DHCP host mappings for virtual networks
by Richard W.M. Jones
This is a series of patches to implement DHCP IP & hostname mappings
for libvirt virtual networks.
** NOTE: This patch is not to be applied. There is some memory
corruption bug which I'm still tracking down.
What this patch allows you to do is to create a table of IP address to
host (defined by its hardware / MAC address) for each virtual network.
Optionally you can also assign a hostname. When a host starts up and
requests an IP address through DHCP, if it is in this table then it
gets the fixed IP address from the table and, optionally, a fixed
hostname.
Four new API calls are added. Two are required to list the contents
of the mapping table. Two more allow you to add and delete a mapping.
The mapping table is semi-permanent. It is stored in
/var/lib/libvirt/hosts-<networkname>.conf and survives across libvirtd
restarts.
The implementation simply uses dnsmasq's --dhcp-hostsfile flag. Refer
to the dnsmasq(1) manual page.
Rich.
--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in
England and Wales under Company Registration No. 03798903
16 years, 7 months
[Libvir] [PATCH] Avoid new "make syntax-check" failures.
by Jim Meyering
With recent changes, I introduced some new "make syntax-check"
failures. Also, there were two remaining invalid uses of write(2).
This fixes all that.
Avoid new "make syntax-check" failures.
* .x-sc_avoid_write: Exempt src/util-lib.c, too.
* Makefile.maint (sc_unmarked_diagnostics): Filter out false positives.
* src/storage_backend_fs.c (virStorageBackendFileSystemVolCreate):
Use safewrite, not write.
* src/storage_backend_logical.c (virStorageBackendLogicalBuildPool):
Likewise.
---
.x-sc_avoid_write | 1 +
Makefile.maint | 6 +++++-
src/storage_backend_fs.c | 2 +-
src/storage_backend_logical.c | 2 +-
4 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/.x-sc_avoid_write b/.x-sc_avoid_write
index 72a196d..fe38d83 100644
--- a/.x-sc_avoid_write
+++ b/.x-sc_avoid_write
@@ -1,2 +1,3 @@
^src/util\.c$
^src/xend_internal\.c$
+^src/util-lib\.c$
diff --git a/Makefile.maint b/Makefile.maint
index fe964a5..0c3acf8 100644
--- a/Makefile.maint
+++ b/Makefile.maint
@@ -304,6 +304,9 @@ err_func_re = \
# Look for diagnostics that aren't marked for translation.
# This won't find any for which error's format string is on a separate line.
+# The sed filters eliminate false-positives like these:
+# _("...: "
+# "%s", _("no storage vol w..."
sc_unmarked_diagnostics:
@grep -nE \
'\<(vshError|error) \([^"]*"[^"]*[a-z]{3}' $$($(CVS_LIST_EXCEPT)) \
@@ -312,7 +315,8 @@ sc_unmarked_diagnostics:
exit 1; } || :
@{ grep -nE '\<$(err_func_re) *\(.*;$$' $$($(CVS_LIST_EXCEPT)); \
grep -A1 -nE '\<$(err_func_re) *\(.*,$$' $$($(CVS_LIST_EXCEPT)); } \
- | grep '[ ]"' && \
+ | sed 's/_("[^"][^"]*"//;s/[ ]"%s"//' \
+ | grep '[ ]"' && \
{ echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
exit 1; } || :
diff --git a/src/storage_backend_fs.c b/src/storage_backend_fs.c
index 9425cbc..1d540e1 100644
--- a/src/storage_backend_fs.c
+++ b/src/storage_backend_fs.c
@@ -854,7 +854,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
int bytes = sizeof(zeros);
if (bytes > remain)
bytes = remain;
- if ((bytes = write(fd, zeros, bytes)) < 0) {
+ if ((bytes = safewrite(fd, zeros, bytes)) < 0) {
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
_("cannot fill file '%s': %s"),
vol->target.path, strerror(errno));
diff --git a/src/storage_backend_logical.c b/src/storage_backend_logical.c
index a70c087..f8a075d 100644
--- a/src/storage_backend_logical.c
+++ b/src/storage_backend_logical.c
@@ -287,7 +287,7 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn,
strerror(errno));
goto cleanup;
}
- if (write(fd, zeros, sizeof(zeros)) != sizeof(zeros)) {
+ if (safewrite(fd, zeros, sizeof(zeros)) < 0) {
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
_("cannot clear device header %s"),
strerror(errno));
--
1.5.4.2.185.gf5f8
16 years, 7 months
[Libvir] Error - when compiling sample libvirt program - Failed to find libvirt proxy
by Sunil Lingappa
Hello Everybody
I am trying to compile the sample program which is present at the
libvirt.org sample program section. I am running the program which is used
to retrieve domain information.
While i am able to compile it with success, when i run it i get the
following error :
*" failed to find libvirt_proxy " *
But the output is still displayed.
Can anybody please help me how to overcome this error message.
find below the patch level info :
rpm -qa | grep libvirt
libvirt-devel-0.2.0-0.16
libvirt-0.2.0-0.16
libvirt-python-0.2.0-0.16
Thanks & Best Regards
Sunil
16 years, 7 months
[Libvir] [PATCH] 1/2: Move safewrite and saferead to a separate file.
by Jim Meyering
Move safewrite and saferead to a separate file.
We currently use safewrite from inside libvirt and don't want to publish
any such function name. However, we do want to use it in applications
like virsh, libvirtd and libvirt_proxy that link with libvirt. To that
end, this change moves that function definition (along with the nearly
identical saferead) into a new file, util-lib.c. To avoid maintaining
separate copies of even such small functions, we simply include that new
file from util.c. Then, the separate applications that need to use
safewrite simply compile and link with util-lib.c.
Of course, this does mean that each of those applications will
containing two copies of these functions. However, the functions
are so small that it's not worth worrying about that.
* src/util.c (saferead, safewrite): Move function definitions to
util-lib.c and include that .c file.
* src/util-lib.c (saferead, safewrite): New file. Functions from src/util.c
with slight change (s/int r =/ssize_t r =/) to reflect read/write return type.
* src/util-lib.h: Declare the two moved functions.
* src/util.h: Remove declarations. Include src/util-lib.h.
* proxy/Makefile.am (libvirt_proxy_SOURCES): Add src/util-lib.c.
* qemud/Makefile.am (libvirtd_SOURCES): Likewise.
* src/Makefile.am (virsh_SOURCES): Add util-lib.c. Remove some SP-before-TAB.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
proxy/Makefile.am | 6 +++-
proxy/libvirt_proxy.c | 16 ++++----------
qemud/Makefile.am | 3 +-
src/Makefile.am | 16 +++++++-------
src/util-lib.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
src/util-lib.h | 16 +++++++++++++++
src/util.c | 43 ++-------------------------------------
src/util.h | 10 ++++----
8 files changed, 95 insertions(+), 67 deletions(-)
create mode 100644 src/util-lib.c
create mode 100644 src/util-lib.h
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index ff9a3eb..68e3317 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -12,11 +12,13 @@ libexec_PROGRAMS = libvirt_proxy
libvirt_proxy_SOURCES = libvirt_proxy.c @top_srcdir(a)/src/xend_internal.c \
@top_srcdir(a)/src/xen_internal.c @top_srcdir(a)/src/virterror.c \
@top_srcdir(a)/src/sexpr.c @top_srcdir(a)/src/xml.c \
- @top_srcdir(a)/src/xs_internal.c @top_srcdir(a)/src/buf.c @top_srcdir(a)/src/uuid.c
+ @top_srcdir(a)/src/xs_internal.c @top_srcdir(a)/src/buf.c \
+ @top_srcdir(a)/src/util-lib.c \
+ @top_srcdir(a)/src/uuid.c
libvirt_proxy_LDFLAGS = $(WARN_CFLAGS)
libvirt_proxy_DEPENDENCIES =
libvirt_proxy_LDADD =
install-exec-hook:
chmod u+s $(DESTDIR)$(libexecdir)/libvirt_proxy
-endif
\ No newline at end of file
+endif
diff --git a/proxy/libvirt_proxy.c b/proxy/libvirt_proxy.c
index d96d3db..a22ba6c 100644
--- a/proxy/libvirt_proxy.c
+++ b/proxy/libvirt_proxy.c
@@ -2,7 +2,7 @@
* proxy_svr.c: root suid proxy server for Xen access to APIs with no
* side effects from unauthenticated clients.
*
- * Copyright (C) 2006, 2007 Red Hat, Inc.
+ * Copyright (C) 2006, 2007, 2008 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
@@ -26,6 +26,7 @@
#include "internal.h"
#include "proxy_internal.h"
+#include "util.h"
#include "xen_internal.h"
#include "xend_internal.h"
#include "xs_internal.h"
@@ -317,19 +318,12 @@ proxyWriteClientSocket(int nr, virProxyPacketPtr req) {
return(-1);
}
-retry:
- ret = write(pollInfos[nr].fd, (char *) req, req->len);
+ ret = safewrite(pollInfos[nr].fd, (char *) req, req->len);
if (ret < 0) {
- if (errno == EINTR) {
- if (debug > 0)
- fprintf(stderr, "write socket %d to client %d interrupted\n",
- pollInfos[nr].fd, nr);
- goto retry;
- }
fprintf(stderr, "write %d bytes to socket %d from client %d failed\n",
req->len, pollInfos[nr].fd, nr);
- proxyCloseClientSocket(nr);
- return(-1);
+ proxyCloseClientSocket(nr);
+ return(-1);
}
if (ret == 0) {
if (debug)
diff --git a/qemud/Makefile.am b/qemud/Makefile.am
index db6adb1..1e1f861 100644
--- a/qemud/Makefile.am
+++ b/qemud/Makefile.am
@@ -42,6 +42,7 @@ libvirtd_SOURCES = \
qemud.c internal.h \
remote_protocol.h remote_protocol.c \
remote.c \
+ $(srcdir)/../src/util-lib.c \
event.c event.h
#-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_POSIX_C_SOURCE=199506L
@@ -151,4 +152,4 @@ uninstall-init:
endif # DBUS_INIT_SCRIPTS_RED_HAT
-endif # WITH_LIBVIRTD
\ No newline at end of file
+endif # WITH_LIBVIRTD
diff --git a/src/Makefile.am b/src/Makefile.am
index 7bbf816..1da0d73 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,21 +51,21 @@ CLIENT_SOURCES = \
conf.c conf.h \
xm_internal.c xm_internal.h \
remote_internal.c remote_internal.h \
- bridge.c bridge.h \
- iptables.c iptables.h \
- uuid.c uuid.h \
- qemu_driver.c qemu_driver.h \
+ bridge.c bridge.h \
+ iptables.c iptables.h \
+ uuid.c uuid.h \
+ qemu_driver.c qemu_driver.h \
qemu_conf.c qemu_conf.h \
openvz_conf.c openvz_conf.h \
- openvz_driver.c openvz_driver.h \
+ openvz_driver.c openvz_driver.h \
nodeinfo.h nodeinfo.c \
storage_conf.h storage_conf.c \
storage_driver.h storage_driver.c \
storage_backend.h storage_backend.c \
- storage_backend_fs.h storage_backend_fs.c \
+ storage_backend_fs.h storage_backend_fs.c \
util.c util.h
-SERVER_SOURCES = \
+SERVER_SOURCES = \
../qemud/remote_protocol.c ../qemud/remote_protocol.h
if WITH_STORAGE_LVM
@@ -100,7 +100,7 @@ libvirt_la_CFLAGS = $(COVERAGE_CFLAGS)
bin_PROGRAMS = virsh
-virsh_SOURCES = virsh.c console.c console.h
+virsh_SOURCES = virsh.c console.c console.h util-lib.c
virsh_LDFLAGS = $(WARN_CFLAGS) $(COVERAGE_LDFLAGS)
virsh_DEPENDENCIES = $(DEPS)
virsh_LDADD = $(LDADDS) $(VIRSH_LIBS)
diff --git a/src/util-lib.c b/src/util-lib.c
new file mode 100644
index 0000000..92496cd
--- /dev/null
+++ b/src/util-lib.c
@@ -0,0 +1,52 @@
+/*
+ * common, generic utility functions
+ *
+ * Copyright (C) 2006, 2007, 2008 Red Hat, Inc.
+ * See COPYING.LIB for the License of this software
+ */
+
+#include <config.h>
+
+#include <unistd.h>
+#include <errno.h>
+
+#include "util-lib.h"
+
+/* Like read(), but restarts after EINTR */
+int saferead(int fd, void *buf, size_t count)
+{
+ size_t nread = 0;
+ while (count > 0) {
+ ssize_t r = read(fd, buf, count);
+ if (r < 0 && errno == EINTR)
+ continue;
+ if (r < 0)
+ return r;
+ if (r == 0)
+ return nread;
+ buf = (char *)buf + r;
+ count -= r;
+ nread += r;
+ }
+ return nread;
+}
+
+/* Like write(), but restarts after EINTR */
+ssize_t safewrite(int fd, const void *buf, size_t count)
+{
+ size_t nwritten = 0;
+ while (count > 0) {
+ ssize_t r = write(fd, buf, count);
+
+ if (r < 0 && errno == EINTR)
+ continue;
+ if (r < 0)
+ return r;
+ if (r == 0)
+ return nwritten;
+ buf = (const char *)buf + r;
+ count -= r;
+ nwritten += r;
+ }
+ return nwritten;
+}
diff --git a/src/util-lib.h b/src/util-lib.h
new file mode 100644
index 0000000..4a14810
--- /dev/null
+++ b/src/util-lib.h
@@ -0,0 +1,16 @@
+/*
+ * private utility functions
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ * See COPYING.LIB for the License of this software
+ */
+
+#ifndef __UTIL_LIB_H__
+#define __UTIL_LIB_H__
+
+#include <sys/types.h>
+
+int saferead(int fd, void *buf, size_t count);
+ssize_t safewrite(int fd, const void *buf, size_t count);
+
+#endif
diff --git a/src/util.c b/src/util.c
index 19131a7..67cb0b8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,7 +1,7 @@
/*
* utils.c: common, generic utility functions
*
- * Copyright (C) 2006, 2007 Red Hat, Inc.
+ * Copyright (C) 2006, 2007, 2008 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
* Copyright (C) 2006, 2007 Binary Karma
* Copyright (C) 2006 Shuveb Hussain
@@ -46,6 +46,8 @@
#include "buf.h"
#include "util.h"
+#include "util-lib.c"
+
#define MAX_ERROR_LEN 1024
#define virLog(msg...) fprintf(stderr, msg)
@@ -276,45 +278,6 @@ virExecNonBlock(virConnectPtr conn,
#endif /* __MINGW32__ */
-/* Like read(), but restarts after EINTR */
-int saferead(int fd, void *buf, size_t count)
-{
- size_t nread = 0;
- while (count > 0) {
- int r = read(fd, buf, count);
- if (r < 0 && errno == EINTR)
- continue;
- if (r < 0)
- return r;
- if (r == 0)
- return nread;
- buf = (unsigned char *)buf + r;
- count -= r;
- nread += r;
- }
- return nread;
-}
-
-/* Like write(), but restarts after EINTR */
-ssize_t safewrite(int fd, const void *buf, size_t count)
-{
- size_t nwritten = 0;
- while (count > 0) {
- int r = write(fd, buf, count);
-
- if (r < 0 && errno == EINTR)
- continue;
- if (r < 0)
- return r;
- if (r == 0)
- return nwritten;
- buf = (unsigned char *)buf + r;
- count -= r;
- nwritten += r;
- }
- return nwritten;
-}
-
int __virFileReadAll(const char *path,
int maxlen,
diff --git a/src/util.h b/src/util.h
index 7080ed0..23a016d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -25,14 +25,14 @@
#define __VIR_UTIL_H__
#include "internal.h"
+#include "util-lib.h"
-int virExec(virConnectPtr conn, char **argv, int *retpid, int infd, int *outfd, int *errfd);
-int virExecNonBlock(virConnectPtr conn, char **argv, int *retpid, int infd, int *outfd, int *errfd);
+int virExec(virConnectPtr conn, char **argv, int *retpid,
+ int infd, int *outfd, int *errfd);
+int virExecNonBlock(virConnectPtr conn, char **argv, int *retpid,
+ int infd, int *outfd, int *errfd);
int virRun(virConnectPtr conn, char **argv, int *status);
-int saferead(int fd, void *buf, size_t count);
-ssize_t safewrite(int fd, const void *buf, size_t count);
-
int __virFileReadAll(const char *path,
int maxlen,
char **buf);
--
1.5.4.2.185.gf5f8
16 years, 7 months