<div dir="ltr">





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue"">Hi all,</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue";min-height:15px"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue"">We are going to develop the v2 patch for virtio-fs crash reconnection. As suggested by Marc-André and Stefan, except for the inflight I/O tracking log area, all the other internal statuses of virtiofsd will be saved to some places other than QEMU. Specifically, the three lo_maps (ino_map, dirp_map, and fd_map) could be saved to several mmapped files, and the opened fds could be saved to systemd. I'd like to get some feedback on our further thoughts before we work on the revision.</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue";min-height:15px"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue"">1. What about by default save the opened fds as file handles to host kernel, instead of saving them to systemd. After some internal discussion, we think introducing systemd may introduce more uncertainness to the system, as we need to create one service for each daemon, and all the daemons may suffer the single-point failure of the systemd process.</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue";min-height:15px"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue"">2. Like the btree map implementation (<a href="http://multikey.rs">multikey.rs</a>) of virtiofsd-rs, what about splitting the flatten lo_map implementation, which supports to be persisted to files, from passhtrough_ll.c to a new separated source file. This way, maybe we can more easily wrap it with some Rust compatible interfaces, and enable crash recovery for virtiofsd-rs based on it.</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue";min-height:15px"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue"">3. What about dropping the dirp_map, and integrate the opened directory fds to fd_map. The virtiofsd-rs implementation only has two maps (inodes and handles). In the C version, dirp_map may also unnecessary.</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue";min-height:15px"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue"">All the best,</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:"Helvetica Neue"">Jiachen</p></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 16, 2020 at 12:21 AM Jiachen Zhang <<a href="mailto:zhangjiachen.jaycee@bytedance.com">zhangjiachen.jaycee@bytedance.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi, all<br>
<br>
We implement virtio-fs crash reconnection in this patchset. The crash<br>
reconnection of virtiofsd here is completely transparent to guest, no<br>
remount in guest is needed, even the inflight requests can be handled<br>
normally after reconnection. We are looking forward to any comments. <br>
<br>
Thanks,<br>
Jiachen<br>
<br>
<br>
OVERVIEW:<br>
<br>
To support virtio-fs crash reconnection, we need to support the recovery<br>
of 1) inflight FUSE request, and 2) virtiofsd internal status information.<br>
<br>
Fortunately, QEMU's vhost-user reconnection framework already supports<br>
inflight I/O tracking by using VHOST_USER_GET_INFLIGHT_FD and<br>
VHOST_USER_SET_INFLIGHT_FD (see 5ad204bf2 and 5f9ff1eff for details).<br>
As the FUSE requests are transferred by virtqueue I/O requests, by using<br>
the vhost-user inflight I/O tracking, we can recover the inflight FUSE<br>
requests.<br>
<br>
To support virtiofsd internal status recovery, we introduce 4 new<br>
vhost-user message types. As shown in the following diagram, two of them<br>
are used to persist shared lo_maps and opened fds to QEMU, the other two<br>
message types are used to restore the status when reconnecting.<br>
<br>
                               VHOST_USER_SLAVE_SHM<br>
                               VHOST_USER_SLAVE_FD<br>
    +--------------+       Persist       +--------------------+<br>
    |              <---------------------+                    |<br>
    |     QEMU     |                     |  Virtio-fs Daemon  |<br>
    |              +--------------------->                    |<br>
    +--------------+       Restore       +--------------------+<br>
            VHOST_USER_SET_SHM<br>
            VHOST_USER_SET_FD<br>
<br>
Although the 4 newly added message types are to support virtiofsd<br>
reconnection in this patchset, it might be potential in other situation.<br>
So we keep in mind to make them more general when add them to vhost<br>
related source files. VHOST_USER_SLAVE_SHM and VHOST_USER_SET_SHM can be<br>
used for memory sharing between a vhost-user daemon and QEMU,<br>
VHOST_USER_SLAVE_FD and VHOST_USER_SET_FD would be useful if we want to<br>
shared opened fds between QEMU process and vhost-user daemon process.<br>
<br>
<br>
USAGE and NOTES:<br>
<br>
- The commits are rebased to a recent QEMU master commit b4d939133dca0fa2b.<br>
<br>
- ",reconnect=1" should be added to the "-chardev socket" of vhost-user-fs-pci<br>
in the QEMU command line, for example:<br>
<br>
    qemu-system-x86_64 ... \<br>
    -chardev socket,id=char0,path=/tmp/vhostqemu,reconnect=1 \<br>
    -device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs \<br>
    ...<br>
<br>
- We add new options for virtiofsd to enable or disable crash reconnection.<br>
And some options are not supported by crash reconnection. So add following<br>
options to virtiofsd to enable reconnection:<br>
<br>
    virtiofsd ... -o reconnect -o no_mount_ns -o no_flock -o no_posix_lock<br>
    -o no_xattr ...<br>
<br>
- The reasons why virtiofsd-side locking, extended attributes, and mount<br>
namespace are not supported is explained in the commit message of the 6th<br>
patch (virtiofsd: Add two new options for crash reconnection).<br>
<br>
- The 9th patch is a work-around that will not affect the overall correctness.<br>
We remove the qsort related codes because we found that when resubmit_num is<br>
larger than 64, seccomp will kill the virtiofsd process.<br>
<br>
- Support for dax version virtiofsd is very possible and requires almost no<br>
additional change to this patchset.<br>
<br>
<br>
Jiachen Zhang (9):<br>
  vhost-user-fs: Add support for reconnection of vhost-user-fs backend<br>
  vhost: Add vhost-user message types for sending shared memory and file<br>
    fds<br>
  vhost-user-fs: Support virtiofsd crash reconnection<br>
  libvhost-user: Add vhost-user message types for sending shared memory<br>
    and file fds<br>
  virtiofsd: Convert the struct lo_map array to a more flatten layout<br>
  virtiofsd: Add two new options for crash reconnection<br>
  virtiofsd: Persist/restore lo_map and opened fds to/from QEMU<br>
  virtiofsd: Ensure crash consistency after reconnection<br>
  virtiofsd: (work around) Comment qsort in inflight I/O tracking<br>
<br>
 contrib/libvhost-user/libvhost-user.c | 106 +++-<br>
 contrib/libvhost-user/libvhost-user.h |  70 +++<br>
 docs/interop/vhost-user.rst           |  41 ++<br>
 hw/virtio/vhost-user-fs.c             | 334 ++++++++++-<br>
 hw/virtio/vhost-user.c                | 123 ++++<br>
 hw/virtio/vhost.c                     |  42 ++<br>
 include/hw/virtio/vhost-backend.h     |   6 +<br>
 include/hw/virtio/vhost-user-fs.h     |  16 +-<br>
 include/hw/virtio/vhost.h             |  42 ++<br>
 tools/virtiofsd/fuse_lowlevel.c       |  24 +-<br>
 tools/virtiofsd/fuse_virtio.c         |  44 ++<br>
 tools/virtiofsd/fuse_virtio.h         |   1 +<br>
 tools/virtiofsd/helper.c              |   9 +<br>
 tools/virtiofsd/passthrough_helpers.h |   2 +-<br>
 tools/virtiofsd/passthrough_ll.c      | 830 ++++++++++++++++++--------<br>
 tools/virtiofsd/passthrough_seccomp.c |   1 +<br>
 16 files changed, 1413 insertions(+), 278 deletions(-)<br>
<br>
-- <br>
2.20.1<br>
<br>
</blockquote></div>