mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
qemu: Introduce qemuBuildNetCommandLine
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@redhat.com>
This commit is contained in:
parent
3dbc2a149f
commit
ef2ab8fdc5
@ -7428,6 +7428,84 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
|
|||||||
return ret;
|
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 *
|
char *
|
||||||
qemuBuildShmemDevStr(virDomainDefPtr def,
|
qemuBuildShmemDevStr(virDomainDefPtr def,
|
||||||
virDomainShmemDefPtr shmem,
|
virDomainShmemDefPtr shmem,
|
||||||
@ -7927,7 +8005,6 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
size_t i, j;
|
size_t i, j;
|
||||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
bool havespice = false;
|
bool havespice = false;
|
||||||
int last_good_net = -1;
|
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
bool emitBootindex = false;
|
bool emitBootindex = false;
|
||||||
int actualSerials = 0;
|
int actualSerials = 0;
|
||||||
@ -8052,54 +8129,10 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
if (qemuBuildFSDevCommandLine(cmd, def, qemuCaps) < 0)
|
if (qemuBuildFSDevCommandLine(cmd, def, qemuCaps) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!def->nnets) {
|
if (qemuBuildNetCommandLine(cmd, driver, def, qemuCaps, vmop, standalone,
|
||||||
/* If we have -device, then we set -nodefault already */
|
emitBootindex, nnicindexes, nicindexes,
|
||||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))
|
&bootHostdevNet) < 0)
|
||||||
virCommandAddArgList(cmd, "-net", "none", NULL);
|
goto error;
|
||||||
} 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 (def->nsmartcards) {
|
if (def->nsmartcards) {
|
||||||
/* -device usb-ccid was already emitted along with other
|
/* -device usb-ccid was already emitted along with other
|
||||||
@ -9143,8 +9176,6 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
/* free up any resources in the network driver
|
/* free up any resources in the network driver
|
||||||
* but don't overwrite the original error */
|
* but don't overwrite the original error */
|
||||||
originalError = virSaveLastError();
|
originalError = virSaveLastError();
|
||||||
for (i = 0; last_good_net != -1 && i <= last_good_net; i++)
|
|
||||||
virDomainConfNWFilterTeardown(def->nets[i]);
|
|
||||||
virSetError(originalError);
|
virSetError(originalError);
|
||||||
virFreeError(originalError);
|
virFreeError(originalError);
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user