All character-like devices. * src/conf/domain_conf.c (virDomainSmartcardDefFormat) (virDomainChrSourceDefFormat, virDomainChrDefFormat) (virDomainRedirdevDefFormat): Alter signature. (virDomainDefFormatInternal): Adjust caller. --- src/conf/domain_conf.c | 104 +++++++++++++++++++++++++++--------------------- 1 files changed, 58 insertions(+), 46 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 64bb337..16feb27 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9590,6 +9590,7 @@ static int virDomainChrSourceDefFormat(virBufferPtr buf, virDomainChrSourceDefPtr def, bool tty_compat, + int indent, unsigned int flags) { const char *type = virDomainChrTypeToString(def->type); @@ -9600,7 +9601,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf, return -1; } - /* Compat with legacy <console tty='/dev/pts/5'/> syntax */ + /* Compat with legacy <console tty='/dev/pts/5'/> syntax */ virBufferAsprintf(buf, " type='%s'", type); if (tty_compat) { virBufferEscapeString(buf, " tty='%s'", @@ -9623,8 +9624,9 @@ virDomainChrSourceDefFormat(virBufferPtr buf, if (def->type != VIR_DOMAIN_CHR_TYPE_PTY || (def->data.file.path && !(flags & VIR_DOMAIN_XML_INACTIVE))) { - virBufferEscapeString(buf, " <source path='%s'/>\n", - def->data.file.path); + virBufferIndentEscapeString(buf, indent + 2, + "<source path='%s'/>\n", + def->data.file.path); } break; @@ -9632,48 +9634,49 @@ virDomainChrSourceDefFormat(virBufferPtr buf, if (def->data.udp.bindService && def->data.udp.bindHost) { virBufferAsprintf(buf, - " <source mode='bind' host='%s' " - "service='%s'/>\n", + "%*s<source mode='bind' host='%s' " + "service='%s'/>\n", indent + 2, "", def->data.udp.bindHost, def->data.udp.bindService); } else if (def->data.udp.bindHost) { - virBufferAsprintf(buf, " <source mode='bind' host='%s'/>\n", - def->data.udp.bindHost); + virBufferAsprintf(buf, "%*s<source mode='bind' host='%s'/>\n", + indent + 2, "", def->data.udp.bindHost); } else if (def->data.udp.bindService) { - virBufferAsprintf(buf, " <source mode='bind' service='%s'/>\n", - def->data.udp.bindService); + virBufferAsprintf(buf, "%*s<source mode='bind' service='%s'/>\n", + indent + 2, "", def->data.udp.bindService); } if (def->data.udp.connectService && def->data.udp.connectHost) { virBufferAsprintf(buf, - " <source mode='connect' host='%s' " - "service='%s'/>\n", + "%*s<source mode='connect' host='%s' " + "service='%s'/>\n", indent + 2, "", def->data.udp.connectHost, def->data.udp.connectService); } else if (def->data.udp.connectHost) { - virBufferAsprintf(buf, " <source mode='connect' host='%s'/>\n", - def->data.udp.connectHost); + virBufferAsprintf(buf, "%*s<source mode='connect' host='%s'/>\n", + indent + 2, "", def->data.udp.connectHost); } else if (def->data.udp.connectService) { virBufferAsprintf(buf, - " <source mode='connect' service='%s'/>\n", - def->data.udp.connectService); + "%*s<source mode='connect' service='%s'/>\n", + indent + 2, "", def->data.udp.connectService); } break; case VIR_DOMAIN_CHR_TYPE_TCP: virBufferAsprintf(buf, - " <source mode='%s' host='%s' service='%s'/>\n", + "%*s<source mode='%s' host='%s' service='%s'/>\n", + indent + 2, "", def->data.tcp.listen ? "bind" : "connect", def->data.tcp.host, def->data.tcp.service); - virBufferAsprintf(buf, " <protocol type='%s'/>\n", + virBufferAsprintf(buf, "%*s<protocol type='%s'/>\n", indent + 2, "", virDomainChrTcpProtocolTypeToString( def->data.tcp.protocol)); break; case VIR_DOMAIN_CHR_TYPE_UNIX: - virBufferAsprintf(buf, " <source mode='%s'", + virBufferAsprintf(buf, "%*s<source mode='%s'", indent + 2, "", def->data.nix.listen ? "bind" : "connect"); virBufferEscapeString(buf, " path='%s'/>\n", def->data.nix.path); @@ -9686,6 +9689,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf, static int virDomainChrDefFormat(virBufferPtr buf, virDomainChrDefPtr def, + int indent, unsigned int flags) { const char *elementName = virDomainChrDeviceTypeToString(def->deviceType); @@ -9702,13 +9706,14 @@ virDomainChrDefFormat(virBufferPtr buf, return -1; } - virBufferAsprintf(buf, " <%s", elementName); + virBufferAsprintf(buf, "%*s<%s", indent, "", elementName); tty_compat = (def->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE && def->target.port == 0 && def->source.type == VIR_DOMAIN_CHR_TYPE_PTY && !(flags & VIR_DOMAIN_XML_INACTIVE) && def->source.data.file.path); - if (virDomainChrSourceDefFormat(buf, &def->source, tty_compat, flags) < 0) + if (virDomainChrSourceDefFormat(buf, &def->source, tty_compat, indent, + flags) < 0) return -1; /* Format <target> block */ @@ -9719,7 +9724,8 @@ virDomainChrDefFormat(virBufferPtr buf, _("Could not format channel target type")); return -1; } - virBufferAsprintf(buf, " <target type='%s'", targetType); + virBufferAsprintf(buf, "%*s<target type='%s'", indent + 2, "", + targetType); switch (def->targetType) { case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: { @@ -9754,25 +9760,25 @@ virDomainChrDefFormat(virBufferPtr buf, case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE: virBufferAsprintf(buf, - " <target type='%s' port='%d'/>\n", + "%*s<target type='%s' port='%d'/>\n", + indent + 2, "", virDomainChrTargetTypeToString(def->deviceType, def->targetType), def->target.port); break; default: - virBufferAsprintf(buf, " <target port='%d'/>\n", + virBufferAsprintf(buf, "%*s<target port='%d'/>\n", indent + 2, "", def->target.port); break; } if (virDomainDeviceInfoIsSet(&def->info, flags)) { - if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0) + if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0) return -1; } - virBufferAsprintf(buf, " </%s>\n", - elementName); + virBufferAsprintf(buf, "%*s</%s>\n", indent, "", elementName); return ret; } @@ -9780,6 +9786,7 @@ virDomainChrDefFormat(virBufferPtr buf, static int virDomainSmartcardDefFormat(virBufferPtr buf, virDomainSmartcardDefPtr def, + int indent, unsigned int flags) { const char *mode = virDomainSmartcardTypeToString(def->type); @@ -9791,7 +9798,7 @@ virDomainSmartcardDefFormat(virBufferPtr buf, return -1; } - virBufferAsprintf(buf, " <smartcard mode='%s'", mode); + virBufferAsprintf(buf, "%*s<smartcard mode='%s'", indent, "", mode); switch (def->type) { case VIR_DOMAIN_SMARTCARD_TYPE_HOST: if (!virDomainDeviceInfoIsSet(&def->info, flags)) { @@ -9804,16 +9811,17 @@ virDomainSmartcardDefFormat(virBufferPtr buf, case VIR_DOMAIN_SMARTCARD_TYPE_HOST_CERTIFICATES: virBufferAddLit(buf, ">\n"); for (i = 0; i < VIR_DOMAIN_SMARTCARD_NUM_CERTIFICATES; i++) - virBufferEscapeString(buf, " <certificate>%s</certificate>\n", - def->data.cert.file[i]); - if (def->data.cert.database) - virBufferEscapeString(buf, " <database>%s</database>\n", - def->data.cert.database); + virBufferIndentEscapeString(buf, indent + 2, + "<certificate>%s</certificate>\n", + def->data.cert.file[i]); + virBufferIndentEscapeString(buf, indent + 2, + "<database>%s</database>\n", + def->data.cert.database); break; case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH: if (virDomainChrSourceDefFormat(buf, &def->data.passthru, false, - flags) < 0) + indent, flags) < 0) return -1; break; @@ -9822,9 +9830,9 @@ virDomainSmartcardDefFormat(virBufferPtr buf, _("unexpected smartcard type %d"), def->type); return -1; } - if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0) + if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0) return -1; - virBufferAddLit(buf, " </smartcard>\n"); + virBufferIndentAddLit(buf, indent, "</smartcard>\n"); return 0; } @@ -10412,18 +10420,20 @@ virDomainHostdevDefFormat(virBufferPtr buf, static int virDomainRedirdevDefFormat(virBufferPtr buf, virDomainRedirdevDefPtr def, + int indent, unsigned int flags) { const char *bus; bus = virDomainRedirdevBusTypeToString(def->bus); - virBufferAsprintf(buf, " <redirdev bus='%s'", bus); - if (virDomainChrSourceDefFormat(buf, &def->source.chr, false, flags) < 0) + virBufferAsprintf(buf, "%*s<redirdev bus='%s'", indent, "", bus); + if (virDomainChrSourceDefFormat(buf, &def->source.chr, false, indent, + flags) < 0) return -1; - if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0) + if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0) return -1; - virBufferAddLit(buf, " </redirdev>\n"); + virBufferIndentAddLit(buf, indent, "</redirdev>\n"); return 0; } @@ -10805,20 +10815,21 @@ virDomainDefFormatInternal(virDomainDefPtr def, goto cleanup; for (n = 0 ; n < def->nsmartcards ; n++) - if (virDomainSmartcardDefFormat(buf, def->smartcards[n], flags) < 0) /* XXX indent */ + if (virDomainSmartcardDefFormat(buf, def->smartcards[n], indent, + flags) < 0) goto cleanup; for (n = 0 ; n < def->nserials ; n++) - if (virDomainChrDefFormat(buf, def->serials[n], flags) < 0) /* XXX indent */ + if (virDomainChrDefFormat(buf, def->serials[n], indent, flags) < 0) goto cleanup; for (n = 0 ; n < def->nparallels ; n++) - if (virDomainChrDefFormat(buf, def->parallels[n], flags) < 0) /* XXX indent */ + if (virDomainChrDefFormat(buf, def->parallels[n], indent, flags) < 0) goto cleanup; /* If there's a PV console that's preferred.. */ if (def->console) { - if (virDomainChrDefFormat(buf, def->console, flags) < 0) /* XXX indent */ + if (virDomainChrDefFormat(buf, def->console, indent, flags) < 0) goto cleanup; } else if (def->nserials != 0) { /* ..else for legacy compat duplicate the first serial device as a @@ -10826,12 +10837,12 @@ virDomainDefFormatInternal(virDomainDefPtr def, virDomainChrDef console; memcpy(&console, def->serials[0], sizeof(console)); console.deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE; - if (virDomainChrDefFormat(buf, &console, flags) < 0) /* XXX indent */ + if (virDomainChrDefFormat(buf, &console, indent, flags) < 0) goto cleanup; } for (n = 0 ; n < def->nchannels ; n++) - if (virDomainChrDefFormat(buf, def->channels[n], flags) < 0) /* XXX indent */ + if (virDomainChrDefFormat(buf, def->channels[n], indent, flags) < 0) goto cleanup; for (n = 0 ; n < def->ninputs ; n++) @@ -10869,7 +10880,8 @@ virDomainDefFormatInternal(virDomainDefPtr def, goto cleanup; for (n = 0 ; n < def->nredirdevs ; n++) - if (virDomainRedirdevDefFormat(buf, def->redirdevs[n], flags) < 0) /* XXX indent */ + if (virDomainRedirdevDefFormat(buf, def->redirdevs[n], indent, + flags) < 0) goto cleanup; for (n = 0 ; n < def->nhubs ; n++) -- 1.7.4.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list