Re: [libvirt] [PATCH 3/4] chardev: Add function to output -chardev options

2009-11-04 Thread Richard W.M. Jones
On Tue, Nov 03, 2009 at 04:07:40PM +, Matthew Booth wrote:
 Note that, on its own, this patch will generate a warning about an unused 
 static
 function.
 +/* This function outputs a -chardev command line option which describes only 
 the
 + * host side of the character device */
 +static int qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr dev,
 + const char *const id,
 + char *buf,
 + int buflen)
 +{
 +switch(dev-type) {
 +case VIR_DOMAIN_CHR_TYPE_NULL:
 +if (snprintf(buf, buflen, null,id=%s, id) = buflen)
 +return -1;
 +break;

Looks OK, but wouldn't it be preferable to use a virBuffer here
instead of depending on the caller to allocate a large enough buffer?

http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/util/buf.h;hb=HEAD

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v

--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 3/4] chardev: Add function to output -chardev options

2009-11-04 Thread Matthew Booth
Agree virBuffer is nicer here, although it's not used anywhere else in
qemu_conf.c. Here's an updated patch which uses a virBuffer instead.

--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 3/4] chardev: Add function to output -chardev options

2009-11-02 Thread Matthew Booth
Note that, on its own, this patch will generate a warning about an unused static
function.
---
 src/qemu/qemu_conf.c |   87 ++
 1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index c4690b2..3f0fbc1 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1386,6 +1386,93 @@ qemuBuildHostNetStr(virConnectPtr conn,
 return 0;
 }
 
+/* This function outputs a -chardev command line option which describes only 
the
+ * host side of the character device */
+static int qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr dev,
+ const char *const id,
+ char *buf,
+ int buflen)
+{
+switch(dev-type) {
+case VIR_DOMAIN_CHR_TYPE_NULL:
+if (snprintf(buf, buflen, null,id=%s, id) = buflen)
+return -1;
+break;
+
+case VIR_DOMAIN_CHR_TYPE_VC:
+if (snprintf(buf, buflen, vc,id=%s, id) = buflen)
+return -1;
+break;
+
+case VIR_DOMAIN_CHR_TYPE_PTY:
+if (snprintf(buf, buflen, pty,id=%s, id) = buflen)
+return -1;
+break;
+
+case VIR_DOMAIN_CHR_TYPE_DEV:
+if (snprintf(buf, buflen, tty,id=%s,path=%s,
+ id, dev-data.file.path) = buflen)
+return -1;
+break;
+
+case VIR_DOMAIN_CHR_TYPE_FILE:
+if (snprintf(buf, buflen, file,id=%s,path=%s,
+ id, dev-data.file.path) = buflen)
+return -1;
+break;
+
+case VIR_DOMAIN_CHR_TYPE_PIPE:
+if (snprintf(buf, buflen, pipe,id=%s,path=%s,
+ id, dev-data.file.path) = buflen)
+return -1;
+break;
+
+case VIR_DOMAIN_CHR_TYPE_STDIO:
+if (snprintf(buf, buflen, stdio,id=%s, id) = buflen)
+return -1;
+break;
+
+case VIR_DOMAIN_CHR_TYPE_UDP:
+if (snprintf(buf, buflen,
+udp,id=%s,host=%s,port=%s,localaddr=%s,localport=%s,
+ id,
+ dev-data.udp.connectHost,
+ dev-data.udp.connectService,
+ dev-data.udp.bindHost,
+ dev-data.udp.bindService) = buflen)
+return -1;
+break;
+
+case VIR_DOMAIN_CHR_TYPE_TCP:
+{
+bool telnet =
+dev-data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET;
+
+if (snprintf(buf, buflen,
+ socket,id=%s,host=%s,port=%s%s%s,
+ id,
+ dev-data.tcp.host,
+ dev-data.tcp.service,
+ telnet ? ,telnet : ,
+ dev-data.tcp.listen ? ,server,nowait : ) = buflen)
+return -1;
+break;
+}
+
+case VIR_DOMAIN_CHR_TYPE_UNIX:
+if (snprintf(buf, buflen,
+ socket,id=%s,path=%s%s,
+ id,
+ dev-data.nix.path,
+ dev-data.nix.listen ? ,server,nowait : ) = buflen)
+return -1;
+break;
+}
+
+return 0;
+}
+
+/* This function outputs an all-in-one character device command line option */
 static int qemudBuildCommandLineChrDevStr(virDomainChrDefPtr dev,
   char *buf,
   int buflen)
-- 
1.6.2.5

--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list