David Kiarie wrote:
From: Kiarie Kahurani <davidkiarie4(a)gmail.com>
Introduce function
xenFormatXMCharDev(....);
which formats char devices config
signed-off-by:David Kiarie<davidkiarie4(a)gmail.com>
---
src/xenxs/xen_xm.c | 155 ++++++++++++++++++++++++++++-------------------------
1 file changed, 82 insertions(+), 73 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 367a8cd..ee5dc19 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -1742,6 +1742,85 @@ static int xenFormatXMEventActions(virConfPtr conf,
virDomainDefPtr def)
return 0;
}
+static int xenFormatXMCharDev(virConfPtr conf, virDomainDefPtr def)
+{
+ size_t i;
+ if (STREQ(def->os.type, "hvm")) {
+ if (def->nparallels) {
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ char *str;
+ int ret;
+
+ ret = xenFormatSxprChr(def->parallels[0], &buf);
+ str = virBufferContentAndReset(&buf);
+ if (ret == 0)
+ ret = xenXMConfigSetString(conf, "parallel", str);
+ VIR_FREE(str);
+ if (ret < 0)
+ goto cleanup;
+ } else {
+ if (xenXMConfigSetString(conf, "parallel", "none") <
0)
+ goto cleanup;
+ }
+
+ if (def->nserials) {
+ if ((def->nserials == 1) && (def->serials[0]->target.port
== 0)) {
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ char *str;
+ int ret;
+
+ ret = xenFormatSxprChr(def->serials[0], &buf);
+ str = virBufferContentAndReset(&buf);
+ if (ret == 0)
+ ret = xenXMConfigSetString(conf, "serial", str);
+ VIR_FREE(str);
+ if (ret < 0)
+ goto cleanup;
+ } else {
+ size_t j = 0;
+ int maxport = -1, port;
+ virConfValuePtr serialVal = NULL;
+
+ if (VIR_ALLOC(serialVal) < 0)
+ goto cleanup;
+ serialVal->type = VIR_CONF_LIST;
+ serialVal->list = NULL;
+
+ for (i = 0; i < def->nserials; i++)
+ if (def->serials[i]->target.port > maxport)
+ maxport = def->serials[i]->target.port;
+
+ for (port = 0; port <= maxport; port++) {
+ virDomainChrDefPtr chr = NULL;
+ for (j = 0; j < def->nserials; j++) {
+ if (def->serials[j]->target.port == port) {
+ chr = def->serials[j];
+ break;
+ }
+ }
+ if (xenFormatXMSerial(serialVal, chr) < 0) {
+ virConfFreeValue(serialVal);
+ goto cleanup;
+ }
+ }
+
+ if (serialVal->list != NULL) {
+ int ret = virConfSetValue(conf, "serial", serialVal);
+ serialVal = NULL;
+ if (ret < 0)
+ goto cleanup;
+ }
+ VIR_FREE(serialVal);
+ }
+ } else {
+ if (xenXMConfigSetString(conf, "serial", "none") <
0)
+ goto cleanup;
+ }
+ }
+ return 0;
+cleanup:
+ return -1;
+}
virConfPtr xenFormatXM(virConnectPtr conn,
virDomainDefPtr def,
int xendConfigVersion)
@@ -2067,79 +2146,10 @@ virConfPtr xenFormatXM(virConnectPtr conn,
if (xenFormatXMPCI(conf, def) < 0)
goto cleanup;
- if (hvm) {
- if (def->nparallels) {
- virBuffer buf = VIR_BUFFER_INITIALIZER;
- char *str;
- int ret;
-
- ret = xenFormatSxprChr(def->parallels[0], &buf);
- str = virBufferContentAndReset(&buf);
- if (ret == 0)
- ret = xenXMConfigSetString(conf, "parallel", str);
- VIR_FREE(str);
- if (ret < 0)
- goto cleanup;
- } else {
- if (xenXMConfigSetString(conf, "parallel", "none") <
0)
- goto cleanup;
- }
-
- if (def->nserials) {
- if ((def->nserials == 1) && (def->serials[0]->target.port
== 0)) {
- virBuffer buf = VIR_BUFFER_INITIALIZER;
- char *str;
- int ret;
-
- ret = xenFormatSxprChr(def->serials[0], &buf);
- str = virBufferContentAndReset(&buf);
- if (ret == 0)
- ret = xenXMConfigSetString(conf, "serial", str);
- VIR_FREE(str);
- if (ret < 0)
- goto cleanup;
- } else {
- size_t j = 0;
- int maxport = -1, port;
- virConfValuePtr serialVal = NULL;
-
- if (VIR_ALLOC(serialVal) < 0)
- goto cleanup;
- serialVal->type = VIR_CONF_LIST;
- serialVal->list = NULL;
-
- for (i = 0; i < def->nserials; i++)
- if (def->serials[i]->target.port > maxport)
- maxport = def->serials[i]->target.port;
-
- for (port = 0; port <= maxport; port++) {
- virDomainChrDefPtr chr = NULL;
- for (j = 0; j < def->nserials; j++) {
- if (def->serials[j]->target.port == port) {
- chr = def->serials[j];
- break;
- }
- }
- if (xenFormatXMSerial(serialVal, chr) < 0) {
- virConfFreeValue(serialVal);
- goto cleanup;
- }
- }
-
- if (serialVal->list != NULL) {
- int ret = virConfSetValue(conf, "serial", serialVal);
- serialVal = NULL;
- if (ret < 0)
- goto cleanup;
- }
- VIR_FREE(serialVal);
- }
- } else {
- if (xenXMConfigSetString(conf, "serial", "none") <
0)
- goto cleanup;
- }
-
+ if (xenFormatXMCharDev(conf, def) < 0)
+ goto cleanup;
+ if (hvm) {
if (def->sounds) {
virBuffer buf = VIR_BUFFER_INITIALIZER;
char *str = NULL;
@@ -2153,7 +2163,6 @@ virConfPtr xenFormatXM(virConnectPtr conn,
goto cleanup;
}
}
-
Spurious whitespace change.
Regards,
Jim
return conf;
cleanup: