mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
conf: split out virtio net driver formatting
Instead of checking upfront if the <driver> element will be needed in a big condition, just format all the attributes into a string and output the <driver> element if the string is not empty.
This commit is contained in:
parent
76a81b1d31
commit
fb78d1cee7
@ -16484,6 +16484,41 @@ virDomainActualNetDefFormat(virBufferPtr buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virDomainVirtioNetDriverFormat(char **outstr,
|
||||
virDomainNetDefPtr def)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
if (def->driver.virtio.name) {
|
||||
virBufferAsprintf(&buf, "name='%s' ",
|
||||
virDomainNetBackendTypeToString(def->driver.virtio.name));
|
||||
}
|
||||
if (def->driver.virtio.txmode) {
|
||||
virBufferAsprintf(&buf, "txmode='%s' ",
|
||||
virDomainNetVirtioTxModeTypeToString(def->driver.virtio.txmode));
|
||||
}
|
||||
if (def->driver.virtio.ioeventfd) {
|
||||
virBufferAsprintf(&buf, "ioeventfd='%s' ",
|
||||
virTristateSwitchTypeToString(def->driver.virtio.ioeventfd));
|
||||
}
|
||||
if (def->driver.virtio.event_idx) {
|
||||
virBufferAsprintf(&buf, "event_idx='%s' ",
|
||||
virTristateSwitchTypeToString(def->driver.virtio.event_idx));
|
||||
}
|
||||
if (def->driver.virtio.queues)
|
||||
virBufferAsprintf(&buf, "queues='%u' ", def->driver.virtio.queues);
|
||||
|
||||
virBufferTrim(&buf, " ", -1);
|
||||
|
||||
if (virBufferCheckError(&buf) < 0)
|
||||
return -1;
|
||||
|
||||
*outstr = virBufferContentAndReset(&buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virDomainNetDefFormat(virBufferPtr buf,
|
||||
virDomainNetDefPtr def,
|
||||
@ -16659,30 +16694,15 @@ virDomainNetDefFormat(virBufferPtr buf,
|
||||
if (def->model) {
|
||||
virBufferEscapeString(buf, "<model type='%s'/>\n",
|
||||
def->model);
|
||||
if (STREQ(def->model, "virtio") &&
|
||||
(def->driver.virtio.name || def->driver.virtio.txmode ||
|
||||
def->driver.virtio.ioeventfd || def->driver.virtio.event_idx ||
|
||||
def->driver.virtio.queues)) {
|
||||
virBufferAddLit(buf, "<driver");
|
||||
if (def->driver.virtio.name) {
|
||||
virBufferAsprintf(buf, " name='%s'",
|
||||
virDomainNetBackendTypeToString(def->driver.virtio.name));
|
||||
}
|
||||
if (def->driver.virtio.txmode) {
|
||||
virBufferAsprintf(buf, " txmode='%s'",
|
||||
virDomainNetVirtioTxModeTypeToString(def->driver.virtio.txmode));
|
||||
}
|
||||
if (def->driver.virtio.ioeventfd) {
|
||||
virBufferAsprintf(buf, " ioeventfd='%s'",
|
||||
virTristateSwitchTypeToString(def->driver.virtio.ioeventfd));
|
||||
}
|
||||
if (def->driver.virtio.event_idx) {
|
||||
virBufferAsprintf(buf, " event_idx='%s'",
|
||||
virTristateSwitchTypeToString(def->driver.virtio.event_idx));
|
||||
}
|
||||
if (def->driver.virtio.queues)
|
||||
virBufferAsprintf(buf, " queues='%u'", def->driver.virtio.queues);
|
||||
virBufferAddLit(buf, "/>\n");
|
||||
if (STREQ(def->model, "virtio")) {
|
||||
char *str;
|
||||
|
||||
if (virDomainVirtioNetDriverFormat(&str, def) < 0)
|
||||
return -1;
|
||||
|
||||
if (str)
|
||||
virBufferAsprintf(buf, "<driver %s/>\n", str);
|
||||
VIR_FREE(str);
|
||||
}
|
||||
}
|
||||
if (def->filter) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user