[libvirt] [PATCH 1/5] character device: Allow character devices to have different target types
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 7dd3ce7..fc70cfd 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);
Re: [libvirt] [PATCH 1/5] character device: Allow character devices to have different target types
On Wed, Nov 04, 2009 at 04:21:58PM +, Matthew Booth wrote: 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(-) ACK, looks good. diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7dd3ce7..fc70cfd 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