virtio-9p: add reset handler
commit0e44a0fd3f28cccb8963fdfc05c53c546b3f46b6
authorGreg Kurz <groug@kaod.org>
Mon, 17 Oct 2016 12:13:58 +0000 (17 14:13 +0200)
committerGreg Kurz <groug@kaod.org>
Mon, 17 Oct 2016 12:13:58 +0000 (17 14:13 +0200)
tree5bb0d01ef8e09b1b31d751c50e0f2a8e736049c5
parentf74e27bf0f07425aba6cb812aa7f5aa98bb68542
virtio-9p: add reset handler

Virtio devices should implement the VirtIODevice->reset() function to
perform necessary cleanup actions and to bring the device to a quiescent
state.

In the case of the virtio-9p device, this means:
- emptying the list of active PDUs (i.e. draining all in-flight I/O)
- freeing all fids (i.e. close open file descriptors and free memory)

That's what this patch does.

The reset handler first waits for all active PDUs to complete. Since
completion happens in the QEMU global aio context, we just have to
loop around aio_poll() until the active list is empty.

The freeing part involves some actions to be performed on the backend,
like closing file descriptors or flushing extended attributes to the
underlying filesystem. The virtfs_reset() function already does the
job: it calls free_fid() for all open fids not involved in an ongoing
I/O operation. We are sure this is the case since we have drained
the PDU active list.

The current code implements all backend accesses with coroutines, but we
want to stay synchronous on the reset path. We can either change the
current code to be able to run when not in coroutine context, or create
a coroutine context and wait for virtfs_reset() to complete. This patch
goes for the latter because it results in simpler code.

Note that we also need to create a dummy PDU because it is also an API
to pass the FsContext pointer to all backend callbacks.

Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
hw/9pfs/9p.c
hw/9pfs/9p.h
hw/9pfs/virtio-9p-device.c