dm: enhence the mevent API

There is one race issue between mevent callback (which is called
in mevent_dispatch thread) and mevent_delete (which could be called
in dev thread). And the callback is called after mevent_delete.

libevent have the exactly same issue. The issue is decripted here:
https://github.com/libevent/libevent/blob/master/whatsnew-2.1.txt

The fixing is:
We introduce a teardown callback to mevent and make sure there is
no race issue between callback and teardown call.

This patch updates the mevent API and the caller as well.

Tracked-On: #1877
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
Yin Fengwei
2018-11-22 14:42:01 +08:00
committed by wenlingz
parent eec3a342c4
commit 64d9c59aa1
10 changed files with 52 additions and 35 deletions

View File

@@ -283,7 +283,7 @@ vhost_vq_register_eventfd(struct vhost_dev *vdev,
*/
if (is_register) {
vq->mevp = mevent_add(vq->call_fd, EVF_READ,
vhost_vq_notify, vq);
vhost_vq_notify, vq, NULL, NULL);
if (!vq->mevp) {
WPRINTF("mevent_add failed\n");
rc = -1;

View File

@@ -679,7 +679,7 @@ virtio_console_add_backend(struct virtio_console *console,
if (virtio_console_backend_can_read(be_type)) {
if (isatty(fd)) {
be->evp = mevent_add(fd, EVF_READ,
virtio_console_backend_read, be);
virtio_console_backend_read, be, NULL, NULL);
if (be->evp == NULL) {
WPRINTF(("vtcon: mevent_add failed\n"));
error = -1;

View File

@@ -634,7 +634,7 @@ virtio_input_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
goto fail;
}
vi->mevp = mevent_add(vi->fd, EVF_READ, virtio_input_read_event, vi);
vi->mevp = mevent_add(vi->fd, EVF_READ, virtio_input_read_event, vi, NULL, NULL);
if (vi->mevp == NULL) {
WPRINTF(("vtinput: could not register event\n"));
goto fail;

View File

@@ -1017,7 +1017,7 @@ vmei_host_client_native_connect(struct vmei_host_client *hclient)
/* add READ event into mevent */
hclient->rx_mevp = mevent_add(hclient->client_fd, EVF_READ,
vmei_rx_callback, hclient);
vmei_rx_callback, hclient, NULL, NULL);
if (!hclient->rx_mevp)
return MEI_HBM_REJECTED;
@@ -1951,7 +1951,7 @@ vmei_start(struct virtio_mei *vmei, bool do_rescan)
hclient->client_fd = pipefd[0];
hclient->rx_mevp = mevent_add(hclient->client_fd, EVF_READ,
vmei_rx_callback, hclient);
vmei_rx_callback, hclient, NULL, NULL);
vmei->hbm_fd = pipefd[1];
if (do_rescan) {
@@ -2051,7 +2051,7 @@ static int vmei_add_reset_event(struct virtio_mei *vmei)
vmei->dev_state_first = true;
vmei->reset_mevp = mevent_add(dev_state_fd, EVF_READ_ET,
vmei_reset_callback, vmei);
vmei_reset_callback, vmei, NULL, NULL);
if (!vmei->reset_mevp) {
close(dev_state_fd);
return -ENOMEM;

View File

@@ -707,7 +707,7 @@ virtio_net_tap_setup(struct virtio_net *net, char *devname)
if (vhost_fd < 0) {
net->mevp = mevent_add(net->tapfd, EVF_READ,
virtio_net_rx_callback, net);
virtio_net_rx_callback, net, NULL, NULL);
if (net->mevp == NULL) {
WPRINTF(("Could not register event\n"));
close(net->tapfd);