Skip to content
Snippets Groups Projects
  • Sergio Lopez's avatar
    3bcf0fb3
    event_notifier: add event_notifier_get_wfd() · 3bcf0fb3
    Sergio Lopez authored
    
    event_notifier_get_fd(const EventNotifier *e) always returns
    EventNotifier's read file descriptor (rfd). This is not a problem when
    the EventNotifier is backed by a an eventfd, as a single file
    descriptor is used both for reading and triggering events (rfd ==
    wfd).
    
    But, when EventNotifier is backed by a pipe pair, we have two file
    descriptors, one that can only be used for reads (rfd), and the other
    only for writes (wfd).
    
    There's, at least, one known situation in which we need to obtain wfd
    instead of rfd, which is when setting up the file that's going to be
    sent to the peer in vhost's SET_VRING_CALL.
    
    Add a new event_notifier_get_wfd(const EventNotifier *e) that can be
    used to obtain wfd where needed.
    
    Signed-off-by: default avatarSergio Lopez <slp@redhat.com>
    Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
    Message-Id: <20220304100854.14829-2-slp@redhat.com>
    Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
    Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
    3bcf0fb3
    History
    event_notifier: add event_notifier_get_wfd()
    Sergio Lopez authored
    
    event_notifier_get_fd(const EventNotifier *e) always returns
    EventNotifier's read file descriptor (rfd). This is not a problem when
    the EventNotifier is backed by a an eventfd, as a single file
    descriptor is used both for reading and triggering events (rfd ==
    wfd).
    
    But, when EventNotifier is backed by a pipe pair, we have two file
    descriptors, one that can only be used for reads (rfd), and the other
    only for writes (wfd).
    
    There's, at least, one known situation in which we need to obtain wfd
    instead of rfd, which is when setting up the file that's going to be
    sent to the peer in vhost's SET_VRING_CALL.
    
    Add a new event_notifier_get_wfd(const EventNotifier *e) that can be
    used to obtain wfd where needed.
    
    Signed-off-by: default avatarSergio Lopez <slp@redhat.com>
    Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
    Message-Id: <20220304100854.14829-2-slp@redhat.com>
    Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
    Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
event_notifier.h 975 B
/*
 * event notifier support
 *
 * Copyright Red Hat, Inc. 2010
 *
 * Authors:
 *  Michael S. Tsirkin <mst@redhat.com>
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 * See the COPYING file in the top-level directory.
 */

#ifndef QEMU_EVENT_NOTIFIER_H
#define QEMU_EVENT_NOTIFIER_H


#ifdef _WIN32
#include <windows.h>
#endif

struct EventNotifier {
#ifdef _WIN32
    HANDLE event;
#else
    int rfd;
    int wfd;
    bool initialized;
#endif
};

typedef void EventNotifierHandler(EventNotifier *);

int event_notifier_init(EventNotifier *, int active);
void event_notifier_cleanup(EventNotifier *);
int event_notifier_set(EventNotifier *);
int event_notifier_test_and_clear(EventNotifier *);

#ifdef CONFIG_POSIX
void event_notifier_init_fd(EventNotifier *, int fd);
int event_notifier_get_fd(const EventNotifier *);
int event_notifier_get_wfd(const EventNotifier *);
#else
HANDLE event_notifier_get_handle(EventNotifier *);
#endif

#endif