Re: [libvirt] [PATCH 1/4] character device: Allow character devices to have different target types

2009-11-04 Thread Richard W.M. Jones
On Tue, Nov 03, 2009 at 04:07:38PM +, Matthew Booth wrote:
 @@ -1325,6 +1332,7 @@ virDomainChrDefParseXML(virConnectPtr conn,
  char *path = NULL;
  char *mode = NULL;
  char *protocol = NULL;
 +const char *targetType = NULL;
  virDomainChrDefPtr def;
  
  if (VIR_ALLOC(def)  0) {

Patch looks good to me.  I'm going to be a bit picky though and say
that if you unconditionally initialize variables when they are
declared, as in the hunk above, then you prevent the compiler from
detecting when you use a variable without first initializing it.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw

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


[libvirt] [PATCH 1/4] character device: Allow character devices to have different target types

2009-11-03 Thread Matthew Booth
Currently a character device's target (it's interface in the guest) has only a
single property: port. This patch is in preparation for adding targets which
require other properties.

Target properties are moved into a union in virDomainChrDef, and a targetType
field is added to identify which union member should be used. All current code
which touches a virDomainChrDef is updated both to use the new union field,
and to populate targetType if necessary.
---
 src/conf/domain_conf.c  |   66 +-
 src/conf/domain_conf.h  |   18 +++-
 src/esx/esx_vmx.c   |   56 +--
 src/qemu/qemu_conf.c|6 +++-
 src/qemu/qemu_driver.c  |2 +
 src/uml/uml_conf.c  |   12 
 src/uml/uml_driver.c|2 +-
 src/vbox/vbox_tmpl.c|   22 
 src/xen/xend_internal.c |3 ++
 src/xen/xm_internal.c   |3 ++
 10 files changed, 129 insertions(+), 61 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a9c8573..e050453 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -127,6 +127,13 @@ VIR_ENUM_IMPL(virDomainNet, VIR_DOMAIN_NET_TYPE_LAST,
   bridge,
   internal)
 
+VIR_ENUM_IMPL(virDomainChrTarget, VIR_DOMAIN_CHR_TARGET_TYPE_LAST,
+  null,
+  monitor,
+  parallel,
+  serial,
+  console)
+
 VIR_ENUM_IMPL(virDomainChr, VIR_DOMAIN_CHR_TYPE_LAST,
   null,
   vc,
@@ -1325,6 +1332,7 @@ virDomainChrDefParseXML(virConnectPtr conn,
 char *path = NULL;
 char *mode = NULL;
 char *protocol = NULL;
+const char *targetType = NULL;
 virDomainChrDefPtr def;
 
 if (VIR_ALLOC(def)  0) {
@@ -1338,6 +1346,21 @@ virDomainChrDefParseXML(virConnectPtr conn,
 else if ((def-type = virDomainChrTypeFromString(type))  0)
 def-type = VIR_DOMAIN_CHR_TYPE_NULL;
 
+targetType = (const char *) node-name;
+if (targetType == NULL) {
+/* Shouldn't be possible */
+virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ node-name is NULL at %s:%i,
+ __FILE__, __LINE__);
+return NULL;
+}
+if ((def-targetType = virDomainChrTargetTypeFromString(targetType))  0) {
+virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ _(unknown target type for character device: %s),
+ targetType);
+def-targetType = VIR_DOMAIN_CHR_TARGET_TYPE_NULL;
+}
+
 cur = node-children;
 while (cur != NULL) {
 if (cur-type == XML_ELEMENT_NODE) {
@@ -2931,7 +2954,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr 
conn,
 if (!chr)
 goto error;
 
-chr-dstPort = i;
+chr-target.port = i;
 def-parallels[def-nparallels++] = chr;
 }
 VIR_FREE(nodes);
@@ -2951,7 +2974,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr 
conn,
 if (!chr)
 goto error;
 
-chr-dstPort = i;
+chr-target.port = i;
 def-serials[def-nserials++] = chr;
 }
 VIR_FREE(nodes);
@@ -2963,7 +2986,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr 
conn,
 if (!chr)
 goto error;
 
-chr-dstPort = 0;
+chr-target.port = 0;
 /*
  * For HVM console actually created a serial device
  * while for non-HVM it was a parvirt console
@@ -3965,10 +3988,12 @@ static int
 virDomainChrDefFormat(virConnectPtr conn,
   virBufferPtr buf,
   virDomainChrDefPtr def,
-  const char *name,
   int flags)
 {
 const char *type = virDomainChrTypeToString(def-type);
+const char *targetName = virDomainChrTargetTypeToString(def-targetType);
+
+const char *elementName = targetName; /* Currently always the same */
 
 if (!type) {
 virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
@@ -3978,8 +4003,8 @@ virDomainChrDefFormat(virConnectPtr conn,
 
 /* Compat with legacy  console tty='/dev/pts/5'/ syntax */
 virBufferVSprintf(buf, %s type='%s',
-  name, type);
-if (STREQ(name, console) 
+  elementName, type);
+if (def-targetType == VIR_DOMAIN_CHR_TARGET_TYPE_CONSOLE 
 def-type == VIR_DOMAIN_CHR_TYPE_PTY 
 !(flags  VIR_DOMAIN_XML_INACTIVE) 
 def-data.file.path) {
@@ -4054,11 +4079,23 @@ virDomainChrDefFormat(virConnectPtr conn,
 break;
 }
 
-virBufferVSprintf(buf,   target port='%d'/\n,
-  def-dstPort);
+switch (def-targetType) {
+case VIR_DOMAIN_CHR_TARGET_TYPE_PARALLEL:
+case VIR_DOMAIN_CHR_TARGET_TYPE_SERIAL:
+case VIR_DOMAIN_CHR_TARGET_TYPE_CONSOLE:
+virBufferVSprintf(buf,   target port='%d'/\n,
+  def-target.port);

[libvirt] [PATCH 1/4] character device: Allow character devices to have different target types

2009-11-02 Thread Matthew Booth
Currently a character device's target (it's interface in the guest) has only a
single property: port. This patch is in preparation for adding targets which
require other properties.

Target properties are moved into a union in virDomainChrDef, and a targetType
field is added to identify which union member should be used. All current code
which touches a virDomainChrDef is updated both to use the new union field,
and to populate targetType if necessary.
---
 src/conf/domain_conf.c  |   66 +-
 src/conf/domain_conf.h  |   18 +++-
 src/esx/esx_vmx.c   |   56 +--
 src/qemu/qemu_conf.c|6 +++-
 src/qemu/qemu_driver.c  |2 +
 src/uml/uml_conf.c  |   12 
 src/uml/uml_driver.c|2 +-
 src/vbox/vbox_tmpl.c|   22 
 src/xen/xend_internal.c |3 ++
 src/xen/xm_internal.c   |3 ++
 10 files changed, 129 insertions(+), 61 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index de07e13..0e49482 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -127,6 +127,13 @@ VIR_ENUM_IMPL(virDomainNet, VIR_DOMAIN_NET_TYPE_LAST,
   bridge,
   internal)
 
+VIR_ENUM_IMPL(virDomainChrTarget, VIR_DOMAIN_CHR_TARGET_TYPE_LAST,
+  null,
+  monitor,
+  parallel,
+  serial,
+  console)
+
 VIR_ENUM_IMPL(virDomainChr, VIR_DOMAIN_CHR_TYPE_LAST,
   null,
   vc,
@@ -1305,6 +1312,7 @@ virDomainChrDefParseXML(virConnectPtr conn,
 char *path = NULL;
 char *mode = NULL;
 char *protocol = NULL;
+const char *targetType = NULL;
 virDomainChrDefPtr def;
 
 if (VIR_ALLOC(def)  0) {
@@ -1318,6 +1326,21 @@ virDomainChrDefParseXML(virConnectPtr conn,
 else if ((def-type = virDomainChrTypeFromString(type))  0)
 def-type = VIR_DOMAIN_CHR_TYPE_NULL;
 
+targetType = (const char *) node-name;
+if (targetType == NULL) {
+/* Shouldn't be possible */
+virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ node-name is NULL at %s:%i,
+ __FILE__, __LINE__);
+return NULL;
+}
+if ((def-targetType = virDomainChrTargetTypeFromString(targetType))  0) {
+virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ _(unknown target type for character device: %s),
+ targetType);
+def-targetType = VIR_DOMAIN_CHR_TARGET_TYPE_NULL;
+}
+
 cur = node-children;
 while (cur != NULL) {
 if (cur-type == XML_ELEMENT_NODE) {
@@ -2911,7 +2934,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr 
conn,
 if (!chr)
 goto error;
 
-chr-dstPort = i;
+chr-target.port = i;
 def-parallels[def-nparallels++] = chr;
 }
 VIR_FREE(nodes);
@@ -2931,7 +2954,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr 
conn,
 if (!chr)
 goto error;
 
-chr-dstPort = i;
+chr-target.port = i;
 def-serials[def-nserials++] = chr;
 }
 VIR_FREE(nodes);
@@ -2943,7 +2966,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr 
conn,
 if (!chr)
 goto error;
 
-chr-dstPort = 0;
+chr-target.port = 0;
 /*
  * For HVM console actually created a serial device
  * while for non-HVM it was a parvirt console
@@ -3945,10 +3968,12 @@ static int
 virDomainChrDefFormat(virConnectPtr conn,
   virBufferPtr buf,
   virDomainChrDefPtr def,
-  const char *name,
   int flags)
 {
 const char *type = virDomainChrTypeToString(def-type);
+const char *targetName = virDomainChrTargetTypeToString(def-targetType);
+
+const char *elementName = targetName; /* Currently always the same */
 
 if (!type) {
 virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
@@ -3958,8 +3983,8 @@ virDomainChrDefFormat(virConnectPtr conn,
 
 /* Compat with legacy  console tty='/dev/pts/5'/ syntax */
 virBufferVSprintf(buf, %s type='%s',
-  name, type);
-if (STREQ(name, console) 
+  elementName, type);
+if (def-targetType == VIR_DOMAIN_CHR_TARGET_TYPE_CONSOLE 
 def-type == VIR_DOMAIN_CHR_TYPE_PTY 
 !(flags  VIR_DOMAIN_XML_INACTIVE) 
 def-data.file.path) {
@@ -4034,11 +4059,23 @@ virDomainChrDefFormat(virConnectPtr conn,
 break;
 }
 
-virBufferVSprintf(buf,   target port='%d'/\n,
-  def-dstPort);
+switch (def-targetType) {
+case VIR_DOMAIN_CHR_TARGET_TYPE_PARALLEL:
+case VIR_DOMAIN_CHR_TARGET_TYPE_SERIAL:
+case VIR_DOMAIN_CHR_TARGET_TYPE_CONSOLE:
+virBufferVSprintf(buf,   target port='%d'/\n,
+  def-target.port);