DM: add init/deinit function for mevent
Current, mevent cleanup path has issue. There are possible following calling sequence happen when reboot/poweroff UOS: 1. mevent_dispatch() calls mevent_destroy 2. do_close_post calls some virtual device deinit to delete mevent. This patch introduce mevent init/deinit to make sure: 1. mevent init 2. mevent_add is called when init virtual device 3. mevent_del is called when deinit virtual device 4. mevent deinit Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Reviewed-by: Zhao Yakui <yakui.zhao@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
parent
c8116fc7c9
commit
db46df940e
|
@ -770,6 +770,13 @@ main(int argc, char *argv[])
|
|||
goto fail;
|
||||
}
|
||||
|
||||
err = mevent_init();
|
||||
if (err) {
|
||||
fprintf(stderr, "Unable to initialize mevent (%d)\n",
|
||||
errno);
|
||||
goto mevent_fail;
|
||||
}
|
||||
|
||||
init_mem();
|
||||
init_inout();
|
||||
pci_irq_init(ctx);
|
||||
|
@ -848,6 +855,7 @@ main(int argc, char *argv[])
|
|||
vrtc_deinit(ctx);
|
||||
atkbdc_deinit(ctx);
|
||||
vm_unsetup_memory(ctx);
|
||||
mevent_deinit();
|
||||
vm_destroy(ctx);
|
||||
vm_close(ctx);
|
||||
_ctx = 0;
|
||||
|
@ -861,6 +869,7 @@ pci_fail:
|
|||
monitor_close();
|
||||
vrtc_deinit(ctx);
|
||||
atkbdc_deinit(ctx);
|
||||
mevent_fail:
|
||||
vm_unsetup_memory(ctx);
|
||||
fail:
|
||||
vm_destroy(ctx);
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
#define MEV_DISABLE 3
|
||||
#define MEV_DEL_PENDING 4
|
||||
|
||||
static int epoll_fd;
|
||||
static pthread_t mevent_tid;
|
||||
static int mevent_pipefd[2];
|
||||
static pthread_mutex_t mevent_lmutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
@ -341,6 +342,25 @@ mevent_set_name(void)
|
|||
pthread_setname_np(mevent_tid, "mevent");
|
||||
}
|
||||
|
||||
int
|
||||
mevent_init(void)
|
||||
{
|
||||
epoll_fd = epoll_create1(0);
|
||||
assert(epoll_fd >= 0);
|
||||
|
||||
if (epoll_fd >= 0)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
mevent_deinit(void)
|
||||
{
|
||||
mevent_destroy();
|
||||
close(epoll_fd);
|
||||
}
|
||||
|
||||
void
|
||||
mevent_dispatch(void)
|
||||
{
|
||||
|
@ -348,16 +368,12 @@ mevent_dispatch(void)
|
|||
struct epoll_event eventlist[MEVENT_MAX];
|
||||
|
||||
struct mevent *pipev;
|
||||
int mfd;
|
||||
int numev;
|
||||
int ret;
|
||||
|
||||
mevent_tid = pthread_self();
|
||||
mevent_set_name();
|
||||
|
||||
mfd = epoll_create1(0);
|
||||
assert(mfd > 0);
|
||||
|
||||
/*
|
||||
* Open the pipe that will be used for other threads to force
|
||||
* the blocking kqueue call to exit by writing to it. Set the
|
||||
|
@ -385,11 +401,11 @@ mevent_dispatch(void)
|
|||
int i;
|
||||
struct epoll_event *e;
|
||||
|
||||
numev = mevent_build(mfd, clist);
|
||||
numev = mevent_build(epoll_fd, clist);
|
||||
|
||||
for (i = 0; i < numev; i++) {
|
||||
e = &clist[i].ee;
|
||||
ret = epoll_ctl(mfd, clist[i].op, clist[i].fd, e);
|
||||
ret = epoll_ctl(epoll_fd, clist[i].op, clist[i].fd, e);
|
||||
if (ret == -1)
|
||||
perror("Error return from epoll_ctl");
|
||||
}
|
||||
|
@ -397,7 +413,7 @@ mevent_dispatch(void)
|
|||
/*
|
||||
* Block awaiting events
|
||||
*/
|
||||
ret = epoll_wait(mfd, eventlist, MEVENT_MAX, -1);
|
||||
ret = epoll_wait(epoll_fd, eventlist, MEVENT_MAX, -1);
|
||||
if (ret == -1 && errno != EINTR)
|
||||
perror("Error return from epoll_wait");
|
||||
|
||||
|
@ -409,7 +425,5 @@ mevent_dispatch(void)
|
|||
if (vm_get_suspend_mode() != VM_SUSPEND_NONE)
|
||||
break;
|
||||
}
|
||||
mevent_build(mfd, clist);
|
||||
mevent_destroy();
|
||||
close(mfd);
|
||||
mevent_build(epoll_fd, clist);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ int mevent_delete_close(struct mevent *evp);
|
|||
int mevent_notify(void);
|
||||
|
||||
void mevent_dispatch(void);
|
||||
int mevent_init(void);
|
||||
void mevent_deinit(void);
|
||||
|
||||
#define list_foreach_safe(var, head, field, tvar) \
|
||||
for ((var) = LIST_FIRST((head)); \
|
||||
|
|
Loading…
Reference in New Issue