mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-30 17:45:23 +00:00
Use virNetServerRun instead of custom main loop
The LXC controller code currently directly invokes the
libvirt main loop code. The problem is that this misses
the cleanup of virNetServerClient connections that
virNetServerRun takes care of.
The result is that when libvirtd is stopped, the
libvirt_lxc controller process gets stuck in a I/O loop.
When libvirtd is then started again, it fails to connect
to the controller and thus kills off the entire domain.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit f33e43c235
)
This commit is contained in:
parent
8b6567005c
commit
adc0bc4c1d
@ -97,6 +97,8 @@ struct _virLXCControllerConsole {
|
|||||||
char fromHostBuf[1024];
|
char fromHostBuf[1024];
|
||||||
size_t fromContLen;
|
size_t fromContLen;
|
||||||
char fromContBuf[1024];
|
char fromContBuf[1024];
|
||||||
|
|
||||||
|
virNetServerPtr server;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _virLXCController virLXCController;
|
typedef struct _virLXCController virLXCController;
|
||||||
@ -278,6 +280,7 @@ static int virLXCControllerAddConsole(virLXCControllerPtr ctrl,
|
|||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
ctrl->consoles[ctrl->nconsoles-1].server = ctrl->server;
|
||||||
ctrl->consoles[ctrl->nconsoles-1].hostFd = hostFd;
|
ctrl->consoles[ctrl->nconsoles-1].hostFd = hostFd;
|
||||||
ctrl->consoles[ctrl->nconsoles-1].hostWatch = -1;
|
ctrl->consoles[ctrl->nconsoles-1].hostWatch = -1;
|
||||||
|
|
||||||
@ -664,12 +667,11 @@ static int lxcControllerClearCapabilities(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool quit = false;
|
|
||||||
static bool wantReboot = false;
|
static bool wantReboot = false;
|
||||||
static virMutex lock;
|
static virMutex lock;
|
||||||
|
|
||||||
|
|
||||||
static void virLXCControllerSignalChildIO(virNetServerPtr server ATTRIBUTE_UNUSED,
|
static void virLXCControllerSignalChildIO(virNetServerPtr server,
|
||||||
siginfo_t *info ATTRIBUTE_UNUSED,
|
siginfo_t *info ATTRIBUTE_UNUSED,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
@ -679,8 +681,8 @@ static void virLXCControllerSignalChildIO(virNetServerPtr server ATTRIBUTE_UNUSE
|
|||||||
|
|
||||||
ret = waitpid(-1, &status, WNOHANG);
|
ret = waitpid(-1, &status, WNOHANG);
|
||||||
if (ret == ctrl->initpid) {
|
if (ret == ctrl->initpid) {
|
||||||
|
virNetServerQuit(server);
|
||||||
virMutexLock(&lock);
|
virMutexLock(&lock);
|
||||||
quit = true;
|
|
||||||
if (WIFSIGNALED(status) &&
|
if (WIFSIGNALED(status) &&
|
||||||
WTERMSIG(status) == SIGHUP)
|
WTERMSIG(status) == SIGHUP)
|
||||||
wantReboot = true;
|
wantReboot = true;
|
||||||
@ -732,7 +734,7 @@ static void virLXCControllerConsoleUpdateWatch(virLXCControllerConsolePtr consol
|
|||||||
VIR_DEBUG(":fail");
|
VIR_DEBUG(":fail");
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Unable to add epoll fd"));
|
_("Unable to add epoll fd"));
|
||||||
quit = true;
|
virNetServerQuit(console->server);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
console->hostEpoll = events;
|
console->hostEpoll = events;
|
||||||
@ -743,8 +745,8 @@ static void virLXCControllerConsoleUpdateWatch(virLXCControllerConsolePtr consol
|
|||||||
if (epoll_ctl(console->epollFd, EPOLL_CTL_DEL, console->hostFd, NULL) < 0) {
|
if (epoll_ctl(console->epollFd, EPOLL_CTL_DEL, console->hostFd, NULL) < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Unable to remove epoll fd"));
|
_("Unable to remove epoll fd"));
|
||||||
VIR_DEBUG(":fail");
|
VIR_DEBUG(":fail");
|
||||||
quit = true;
|
virNetServerQuit(console->server);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
console->hostEpoll = 0;
|
console->hostEpoll = 0;
|
||||||
@ -769,7 +771,7 @@ static void virLXCControllerConsoleUpdateWatch(virLXCControllerConsolePtr consol
|
|||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Unable to add epoll fd"));
|
_("Unable to add epoll fd"));
|
||||||
VIR_DEBUG(":fail");
|
VIR_DEBUG(":fail");
|
||||||
quit = true;
|
virNetServerQuit(console->server);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
console->contEpoll = events;
|
console->contEpoll = events;
|
||||||
@ -780,8 +782,8 @@ static void virLXCControllerConsoleUpdateWatch(virLXCControllerConsolePtr consol
|
|||||||
if (epoll_ctl(console->epollFd, EPOLL_CTL_DEL, console->contFd, NULL) < 0) {
|
if (epoll_ctl(console->epollFd, EPOLL_CTL_DEL, console->contFd, NULL) < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Unable to remove epoll fd"));
|
_("Unable to remove epoll fd"));
|
||||||
VIR_DEBUG(":fail");
|
VIR_DEBUG(":fail");
|
||||||
quit = true;
|
virNetServerQuit(console->server);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
console->contEpoll = 0;
|
console->contEpoll = 0;
|
||||||
@ -810,7 +812,7 @@ static void virLXCControllerConsoleEPoll(int watch, int fd, int events, void *op
|
|||||||
continue;
|
continue;
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Unable to wait on epoll"));
|
_("Unable to wait on epoll"));
|
||||||
quit = true;
|
virNetServerQuit(console->server);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -927,7 +929,7 @@ error:
|
|||||||
virEventRemoveHandle(console->contWatch);
|
virEventRemoveHandle(console->contWatch);
|
||||||
virEventRemoveHandle(console->hostWatch);
|
virEventRemoveHandle(console->hostWatch);
|
||||||
console->contWatch = console->hostWatch = -1;
|
console->contWatch = console->hostWatch = -1;
|
||||||
quit = true;
|
virNetServerQuit(console->server);
|
||||||
virMutexUnlock(&lock);
|
virMutexUnlock(&lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -996,14 +998,7 @@ static int virLXCControllerMain(virLXCControllerPtr ctrl)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexLock(&lock);
|
virNetServerRun(ctrl->server);
|
||||||
while (!quit) {
|
|
||||||
virMutexUnlock(&lock);
|
|
||||||
if (virEventRunDefaultImpl() < 0)
|
|
||||||
goto cleanup;
|
|
||||||
virMutexLock(&lock);
|
|
||||||
}
|
|
||||||
virMutexUnlock(&lock);
|
|
||||||
|
|
||||||
err = virGetLastError();
|
err = virGetLastError();
|
||||||
if (!err || err->code == VIR_ERR_OK)
|
if (!err || err->code == VIR_ERR_OK)
|
||||||
|
Loading…
Reference in New Issue
Block a user