qemu: monitor: Remove 'timeout' argument from qemuMonitorOpen

The 'timeout' argument is used by 'qemuMonitorOpenUnix' only when the
'retry' argument is true. The callers of 'qemuMonitorOpen' only pass '0'
for timeout when they call it with 'retry' true and use other values
when 'retry' is false and thus ignored.

This means we can remove the argument and simply have it set to the
default value of QEMU_DEFAULT_MONITOR_WAIT.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
Peter Krempa 2022-08-02 13:45:49 +02:00
parent d79216188d
commit dce9047496
4 changed files with 7 additions and 28 deletions

View File

@ -223,12 +223,12 @@ qemuMonitorDispose(void *obj)
g_free(mon->domainName);
}
#define QEMU_DEFAULT_MONITOR_WAIT 30
static int
qemuMonitorOpenUnix(const char *monitor,
pid_t cpid,
bool retry,
unsigned long long timeout)
bool retry)
{
struct sockaddr_un addr;
VIR_AUTOCLOSE monfd = -1;
@ -250,7 +250,7 @@ qemuMonitorOpenUnix(const char *monitor,
}
if (retry) {
if (virTimeBackOffStart(&timebackoff, 1, timeout * 1000) < 0)
if (virTimeBackOffStart(&timebackoff, 1, QEMU_DEFAULT_MONITOR_WAIT * 1000) < 0)
return -1;
while (virTimeBackOffWait(&timebackoff)) {
ret = connect(monfd, (struct sockaddr *)&addr, sizeof(addr));
@ -694,20 +694,13 @@ qemuMonitorOpenInternal(virDomainObj *vm,
}
#define QEMU_DEFAULT_MONITOR_WAIT 30
/**
* qemuMonitorOpen:
* @vm: domain object
* @config: monitor configuration
* @timeout: number of seconds to add to default timeout
* @cb: monitor event handles
*
* Opens the monitor for running qemu. It may happen that it
* takes some time for qemu to create the monitor socket (e.g.
* because kernel is zeroing configured hugepages), therefore we
* wait up to default + timeout seconds for the monitor to show
* up after which a failure is claimed.
* Opens the monitor for running qemu.
*
* Returns monitor object, NULL on error.
*/
@ -715,15 +708,12 @@ qemuMonitor *
qemuMonitorOpen(virDomainObj *vm,
virDomainChrSourceDef *config,
bool retry,
unsigned long long timeout,
GMainContext *context,
qemuMonitorCallbacks *cb)
{
VIR_AUTOCLOSE fd = -1;
qemuMonitor *ret = NULL;
timeout += QEMU_DEFAULT_MONITOR_WAIT;
if (config->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to handle monitor type: %s"),
@ -732,8 +722,7 @@ qemuMonitorOpen(virDomainObj *vm,
}
virObjectUnlock(vm);
fd = qemuMonitorOpenUnix(config->data.nix.path,
vm->pid, retry, timeout);
fd = qemuMonitorOpenUnix(config->data.nix.path, vm->pid, retry);
virObjectLock(vm);
if (fd < 0)

View File

@ -409,10 +409,9 @@ struct _qemuMonitorCallbacks {
qemuMonitor *qemuMonitorOpen(virDomainObj *vm,
virDomainChrSourceDef *config,
bool retry,
unsigned long long timeout,
GMainContext *context,
qemuMonitorCallbacks *cb)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5);
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
void qemuMonitorWatchDispose(void);
bool qemuMonitorWasDisposed(void);

View File

@ -1888,7 +1888,6 @@ qemuConnectMonitor(virQEMUDriver *driver,
{
qemuDomainObjPrivate *priv = vm->privateData;
qemuMonitor *mon = NULL;
unsigned long long timeout = 0;
if (qemuSecuritySetDaemonSocketLabel(driver->securityManager, vm->def) < 0) {
VIR_ERROR(_("Failed to set security context for monitor for %s"),
@ -1896,18 +1895,11 @@ qemuConnectMonitor(virQEMUDriver *driver,
return -1;
}
/* When using hugepages, kernel zeroes them out before
* handing them over to qemu. This can be very time
* consuming. Therefore, add a second to timeout for each
* 1GiB of guest RAM. */
timeout = virDomainDefGetMemoryTotal(vm->def) / (1024 * 1024);
ignore_value(virTimeMillisNow(&priv->monStart));
mon = qemuMonitorOpen(vm,
priv->monConfig,
false,
timeout,
virEventThreadGetContext(priv->eventThread),
&monitorCallbacks);
@ -9501,7 +9493,7 @@ qemuProcessQMPConnectMonitor(qemuProcessQMP *proc)
proc->vm->pid = proc->pid;
if (!(proc->mon = qemuMonitorOpen(proc->vm, &monConfig, true, 0,
if (!(proc->mon = qemuMonitorOpen(proc->vm, &monConfig, true,
virEventThreadGetContext(proc->eventThread),
&callbacks)))
return -1;

View File

@ -1110,7 +1110,6 @@ qemuMonitorTestNew(virDomainXMLOption *xmlopt,
if (!(test->mon = qemuMonitorOpen(test->vm,
&src,
true,
0,
virEventThreadGetContext(test->eventThread),
&qemuMonitorTestCallbacks)))
goto error;