qemu_process: graphics: extract for loop out of qemuProcessGraphicsReservePorts

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2016-08-13 21:01:38 +02:00
parent 675f9bde2b
commit f6a8df41db

View File

@ -4009,12 +4009,8 @@ qemuProcessStartHook(virQEMUDriverPtr driver,
static int static int
qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver, qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver,
virDomainObjPtr vm) virDomainGraphicsDefPtr graphics)
{ {
size_t i;
for (i = 0; i < vm->def->ngraphics; ++i) {
virDomainGraphicsDefPtr graphics = vm->def->graphics[i];
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC && if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
!graphics->data.vnc.autoport) { !graphics->data.vnc.autoport) {
if (virPortAllocatorSetUsed(driver->remotePorts, if (virPortAllocatorSetUsed(driver->remotePorts,
@ -4041,7 +4037,6 @@ qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver,
graphics->data.spice.tlsPortReserved = true; graphics->data.spice.tlsPortReserved = true;
} }
} }
}
return 0; return 0;
} }
@ -4204,15 +4199,22 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
unsigned int flags) unsigned int flags)
{ {
virDomainGraphicsDefPtr graphics;
bool allocate = !(flags & VIR_QEMU_PROCESS_START_PRETEND); bool allocate = !(flags & VIR_QEMU_PROCESS_START_PRETEND);
size_t i; size_t i;
int ret = -1; int ret = -1;
if (allocate && qemuProcessGraphicsReservePorts(driver, vm) < 0) if (allocate) {
for (i = 0; i < vm->def->ngraphics; i++) {
graphics = vm->def->graphics[i];
if (qemuProcessGraphicsReservePorts(driver, graphics) < 0)
goto cleanup; goto cleanup;
}
}
for (i = 0; i < vm->def->ngraphics; ++i) { for (i = 0; i < vm->def->ngraphics; ++i) {
virDomainGraphicsDefPtr graphics = vm->def->graphics[i]; graphics = vm->def->graphics[i];
if (qemuProcessGraphicsAllocatePorts(driver, graphics, allocate) < 0) if (qemuProcessGraphicsAllocatePorts(driver, graphics, allocate) < 0)
goto cleanup; goto cleanup;