mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
qemu: remove duplicated code for allocating spice ports
We have two different places that needs to be updated while touching code for allocation spice ports. Add a bool option to 'qemuProcessSPICEAllocatePorts' function to switch between true and fake allocation so we can use this function also in qemu_driver to generate native domain definition. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
8672a1e496
commit
e4983952b4
@ -6590,49 +6590,8 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
|
||||
!graphics->data.vnc.socket && graphics->data.vnc.autoport) {
|
||||
graphics->data.vnc.port = 5900;
|
||||
} else if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
|
||||
size_t j;
|
||||
bool needTLSPort = false;
|
||||
bool needPort = false;
|
||||
int defaultMode = graphics->data.spice.defaultMode;
|
||||
|
||||
if (graphics->data.spice.autoport) {
|
||||
/* check if tlsPort or port need allocation */
|
||||
for (j = 0; j < VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST; j++) {
|
||||
switch (graphics->data.spice.channels[j]) {
|
||||
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE:
|
||||
needTLSPort = true;
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE:
|
||||
needPort = true;
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY:
|
||||
switch (defaultMode) {
|
||||
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE:
|
||||
needTLSPort = true;
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE:
|
||||
needPort = true;
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY:
|
||||
if (cfg->spiceTLS)
|
||||
needTLSPort = true;
|
||||
needPort = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (needPort || graphics->data.spice.port == -1)
|
||||
graphics->data.spice.port = 5901;
|
||||
|
||||
if (needTLSPort || graphics->data.spice.tlsPort == -1)
|
||||
graphics->data.spice.tlsPort = 5902;
|
||||
if (qemuProcessSPICEAllocatePorts(driver, cfg, graphics, false) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4019,10 +4019,11 @@ qemuProcessVNCAllocatePorts(virQEMUDriverPtr driver,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
|
||||
virQEMUDriverConfigPtr cfg,
|
||||
virDomainGraphicsDefPtr graphics)
|
||||
virDomainGraphicsDefPtr graphics,
|
||||
bool allocate)
|
||||
{
|
||||
unsigned short port = 0;
|
||||
unsigned short tlsPort;
|
||||
@ -4065,6 +4066,16 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
|
||||
}
|
||||
}
|
||||
|
||||
if (!allocate) {
|
||||
if (needPort || graphics->data.spice.port == -1)
|
||||
graphics->data.spice.port = 5901;
|
||||
|
||||
if (needTLSPort || graphics->data.spice.tlsPort == -1)
|
||||
graphics->data.spice.tlsPort = 5902;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (needPort || graphics->data.spice.port == -1) {
|
||||
if (virPortAllocatorAcquire(driver->remotePorts, &port) < 0)
|
||||
goto error;
|
||||
@ -4573,7 +4584,7 @@ int qemuProcessStart(virConnectPtr conn,
|
||||
if (qemuProcessVNCAllocatePorts(driver, graphics) < 0)
|
||||
goto cleanup;
|
||||
} else if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
|
||||
if (qemuProcessSPICEAllocatePorts(driver, cfg, graphics) < 0)
|
||||
if (qemuProcessSPICEAllocatePorts(driver, cfg, graphics, true) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -107,4 +107,9 @@ int qemuProcessReadLog(int fd, char *buf, int buflen, int off, bool skipchar);
|
||||
int qemuProcessSetSchedParams(int id, pid_t pid, size_t nsp,
|
||||
virDomainThreadSchedParamPtr sp);
|
||||
|
||||
int qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
|
||||
virQEMUDriverConfigPtr cfg,
|
||||
virDomainGraphicsDefPtr graphics,
|
||||
bool allocate);
|
||||
|
||||
#endif /* __QEMU_PROCESS_H__ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user