411132c979
The vhost-user-blk export implement AioContext switches in its drain
implementation. This means that on drain_begin, it detaches the server
from its AioContext and on drain_end, attaches it again and schedules
the server->co_trip coroutine in the updated AioContext.
However, nothing guarantees that server->co_trip is even safe to be
scheduled. Not only is it unclear that the coroutine is actually in a
state where it can be reentered externally without causing problems, but
with two consecutive drains, it is possible that the scheduled coroutine
didn't have a chance yet to run and trying to schedule an already
scheduled coroutine a second time crashes with an assertion failure.
Following the model of NBD, this commit makes the vhost-user-blk export
shut down server->co_trip during drain so that resuming the export means
creating and scheduling a new coroutine, which is always safe.
There is one exception: If the drain call didn't poll (for example, this
happens in the context of bdrv_graph_wrlock()), then the coroutine
didn't have a chance to shut down. However, in this case the AioContext
can't have changed; changing the AioContext always involves a polling
drain. So in this case we can simply assert that the AioContext is
unchanged and just leave the coroutine running or wake it up if it has
yielded to wait for the AioContext to be attached again.
Fixes: e1054cd4aa
Fixes: https://issues.redhat.com/browse/RHEL-1708
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20231127115755.22846-1-kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
74 lines
2.2 KiB
C
74 lines
2.2 KiB
C
/*
|
|
* Sharing QEMU devices via vhost-user protocol
|
|
*
|
|
* Copyright (c) Coiby Xu <coiby.xu@gmail.com>.
|
|
* Copyright (c) 2020 Red Hat, Inc.
|
|
*
|
|
* 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 VHOST_USER_SERVER_H
|
|
#define VHOST_USER_SERVER_H
|
|
|
|
#include "subprojects/libvhost-user/libvhost-user.h" /* only for the type definitions */
|
|
#include "io/channel-socket.h"
|
|
#include "io/channel-file.h"
|
|
#include "io/net-listener.h"
|
|
#include "qapi/error.h"
|
|
#include "standard-headers/linux/virtio_blk.h"
|
|
|
|
/* A kick fd that we monitor on behalf of libvhost-user */
|
|
typedef struct VuFdWatch {
|
|
VuDev *vu_dev;
|
|
int fd; /*kick fd*/
|
|
void *pvt;
|
|
vu_watch_cb cb;
|
|
QTAILQ_ENTRY(VuFdWatch) next;
|
|
} VuFdWatch;
|
|
|
|
/**
|
|
* VuServer:
|
|
* A vhost-user server instance with user-defined VuDevIface callbacks.
|
|
* Vhost-user device backends can be implemented using VuServer. VuDevIface
|
|
* callbacks and virtqueue kicks run in the given AioContext.
|
|
*/
|
|
typedef struct {
|
|
QIONetListener *listener;
|
|
QEMUBH *restart_listener_bh;
|
|
AioContext *ctx;
|
|
int max_queues;
|
|
const VuDevIface *vu_iface;
|
|
|
|
unsigned int in_flight; /* atomic */
|
|
|
|
/* Protected by ctx lock */
|
|
bool in_qio_channel_yield;
|
|
bool wait_idle;
|
|
bool quiescing;
|
|
VuDev vu_dev;
|
|
QIOChannel *ioc; /* The I/O channel with the client */
|
|
QIOChannelSocket *sioc; /* The underlying data channel with the client */
|
|
QTAILQ_HEAD(, VuFdWatch) vu_fd_watches;
|
|
|
|
Coroutine *co_trip; /* coroutine for processing VhostUserMsg */
|
|
} VuServer;
|
|
|
|
bool vhost_user_server_start(VuServer *server,
|
|
SocketAddress *unix_socket,
|
|
AioContext *ctx,
|
|
uint16_t max_queues,
|
|
const VuDevIface *vu_iface,
|
|
Error **errp);
|
|
|
|
void vhost_user_server_stop(VuServer *server);
|
|
|
|
void vhost_user_server_inc_in_flight(VuServer *server);
|
|
void vhost_user_server_dec_in_flight(VuServer *server);
|
|
bool vhost_user_server_has_in_flight(VuServer *server);
|
|
|
|
void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ctx);
|
|
void vhost_user_server_detach_aio_context(VuServer *server);
|
|
|
|
#endif /* VHOST_USER_SERVER_H */
|