Add new function to manage adding the network device options to the command line removing that task from the mainline qemuBuildCommandLine. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/qemu/qemu_command.c | 133 +++++++++++++++++++++++++++++------------------- 1 file changed, 82 insertions(+), 51 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index caf6f37..20c0147 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7274,6 +7274,84 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd, return ret; } + +/* NOTE: Not using const virDomainDef here since eventually a call is made + * into virSecurityManagerSetTapFDLabel which calls it's driver + * API domainSetSecurityTapFDLabel that doesn't use the const format. + */ +static int +qemuBuildNetCommandLine(virCommandPtr cmd, + virQEMUDriverPtr driver, + virDomainDefPtr def, + virQEMUCapsPtr qemuCaps, + virNetDevVPortProfileOp vmop, + bool standalone, + bool emitBootindex, + size_t *nnicindexes, + int **nicindexes, + int *bootHostdevNet) +{ + size_t i; + int last_good_net = -1; + + if (!def->nnets) { + /* If we have -device, then we set -nodefault already */ + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) + virCommandAddArgList(cmd, "-net", "none", NULL); + } else { + int bootNet = 0; + + if (emitBootindex) { + /* convert <boot dev='network'/> to bootindex since we didn't emit + * -boot n + */ + for (i = 0; i < def->os.nBootDevs; i++) { + if (def->os.bootDevs[i] == VIR_DOMAIN_BOOT_NET) { + bootNet = i + 1; + break; + } + } + } + + for (i = 0; i < def->nnets; i++) { + virDomainNetDefPtr net = def->nets[i]; + int vlan; + + /* VLANs are not used with -netdev, so don't record them */ + if (qemuDomainSupportsNetdev(def, qemuCaps, net)) + vlan = -1; + else + vlan = i; + + if (qemuBuildInterfaceCommandLine(cmd, driver, def, net, + qemuCaps, vlan, bootNet, vmop, + standalone, nnicindexes, + nicindexes) < 0) + goto error; + + last_good_net = i; + /* if this interface is a type='hostdev' interface and we + * haven't yet added a "bootindex" parameter to an + * emulated network device, save the bootindex - hostdev + * interface commandlines will be built later on when we + * cycle through all the hostdevs, and we'll use it then. + */ + if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV && + *bootHostdevNet == 0) { + *bootHostdevNet = bootNet; + } + bootNet = 0; + } + } + return 0; + + error: + for (i = 0; last_good_net != -1 && i <= last_good_net; i++) + virDomainConfNWFilterTeardown(def->nets[i]); + return -1; +} + + char * qemuBuildShmemDevStr(virDomainDefPtr def, virDomainShmemDefPtr shmem, @@ -7818,7 +7896,6 @@ qemuBuildCommandLine(virConnectPtr conn, size_t i, j; char uuid[VIR_UUID_STRING_BUFLEN]; bool havespice = false; - int last_good_net = -1; virCommandPtr cmd = NULL; bool emitBootindex = false; int actualSerials = 0; @@ -7948,54 +8025,10 @@ qemuBuildCommandLine(virConnectPtr conn, if (qemuBuildFSDevCommandLine(cmd, def, qemuCaps) < 0) goto error; - if (!def->nnets) { - /* If we have -device, then we set -nodefault already */ - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) - virCommandAddArgList(cmd, "-net", "none", NULL); - } else { - int bootNet = 0; - - if (emitBootindex) { - /* convert <boot dev='network'/> to bootindex since we didn't emit - * -boot n - */ - for (i = 0; i < def->os.nBootDevs; i++) { - if (def->os.bootDevs[i] == VIR_DOMAIN_BOOT_NET) { - bootNet = i + 1; - break; - } - } - } - - for (i = 0; i < def->nnets; i++) { - virDomainNetDefPtr net = def->nets[i]; - int vlan; - - /* VLANs are not used with -netdev, so don't record them */ - if (qemuDomainSupportsNetdev(def, qemuCaps, net)) - vlan = -1; - else - vlan = i; - - if (qemuBuildInterfaceCommandLine(cmd, driver, def, net, - qemuCaps, vlan, bootNet, vmop, - standalone, nnicindexes, nicindexes) < 0) - goto error; - - last_good_net = i; - /* if this interface is a type='hostdev' interface and we - * haven't yet added a "bootindex" parameter to an - * emulated network device, save the bootindex - hostdev - * interface commandlines will be built later on when we - * cycle through all the hostdevs, and we'll use it then. - */ - if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV && - bootHostdevNet == 0) { - bootHostdevNet = bootNet; - } - bootNet = 0; - } - } + if (qemuBuildNetCommandLine(cmd, driver, def, qemuCaps, vmop, standalone, + emitBootindex, nnicindexes, nicindexes, + &bootHostdevNet) < 0) + goto error; if (def->nsmartcards) { /* -device usb-ccid was already emitted along with other @@ -9029,8 +9062,6 @@ qemuBuildCommandLine(virConnectPtr conn, /* free up any resources in the network driver * but don't overwrite the original error */ originalError = virSaveLastError(); - for (i = 0; last_good_net != -1 && i <= last_good_net; i++) - virDomainConfNWFilterTeardown(def->nets[i]); virSetError(originalError); virFreeError(originalError); virCommandFree(cmd); -- 2.5.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list