qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: qemu-devel@nongnu.org
Cc: German Maglione <gmaglione@redhat.com>,
	Sebastian Hasler <sebastian.hasler@stuvus.uni-stuttgart.de>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Greg Kurz <groug@kaod.org>,
	virtio-fs@redhat.com, Stefan Hajnoczi <stefanha@redhat.com>,
	Vivek Goyal <vgoyal@redhat.com>
Subject: [PATCH 2/2] virtiofsd: Support FUSE_SYNCFS on unannounced submounts
Date: Thu,  3 Mar 2022 18:13:23 +0100	[thread overview]
Message-ID: <20220303171323.580712-3-groug@kaod.org> (raw)
In-Reply-To: <20220303171323.580712-1-groug@kaod.org>

This adds the missing bits to support FUSE_SYNCFS in the case submounts
aren't announced to the client.

Iterate over all submounts and call syncfs() on them. Since syncfs() can
block for an indefinite time, we cannot call it with lo->mutex held as
it would prevent the server to process other requests. Generate a list
of submounts with lo->mutex held and bump their reference count to
ensure they don't vanish when lo->mutex is dropped.

Each individual call to syncfs() can legitimately fail. Try to flush
as much as possible anyway. A single error will be returned to the
client so that it knows that the flush didn't fully succeed.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 tools/virtiofsd/passthrough_ll.c | 37 ++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 177e4b46c1bb..628ae0e9589d 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -3746,9 +3746,42 @@ static void lo_syncfs(fuse_req_t req, fuse_ino_t ino)
 
     /*
      * If submounts aren't announced, the client only sends a request to
-     * sync the root inode. TODO: Track submounts internally and iterate
-     * over them as well.
+     * sync the root inode. Iterate over the known submounts to sync them
+     * as well.
      */
+    if (!lo->announce_submounts) {
+        g_autoptr(GSList) submount_list = NULL;
+        GSList *elem;
+        GHashTableIter iter;
+        gpointer key, value;
+
+        pthread_mutex_lock(&lo->mutex);
+
+        g_hash_table_iter_init(&iter, lo->submounts);
+        while (g_hash_table_iter_next(&iter, &key, &value)) {
+            struct lo_inode *inode = value;
+
+            g_atomic_int_inc(&inode->refcount);
+            submount_list = g_slist_prepend(submount_list, inode);
+        }
+
+        pthread_mutex_unlock(&lo->mutex);
+
+        for (elem = submount_list; elem; elem = g_slist_next(elem)) {
+            struct lo_inode *inode = elem->data;
+            int r;
+
+            r = lo_do_syncfs(lo, inode);
+            if (r) {
+                /*
+                 * Try to sync as much as possible. Only one error can be
+                 * reported to the client though, arbitrarily the last one.
+                 */
+                err = r;
+            }
+            lo_inode_put(lo, &inode);
+        }
+    }
 
     fuse_reply_err(req, err);
 }
-- 
2.34.1



  parent reply	other threads:[~2022-03-03 17:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03 17:13 [PATCH 0/2] virtiofsd: Support FUSE_SYNCFS on unannounced submounts Greg Kurz
2022-03-03 17:13 ` [PATCH 1/2] virtiofsd: Track submounts Greg Kurz
2022-03-03 17:13 ` Greg Kurz [this message]
2022-03-04 12:11 ` [PATCH 0/2] virtiofsd: Support FUSE_SYNCFS on unannounced submounts Vivek Goyal
2022-03-04 13:56   ` Greg Kurz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220303171323.580712-3-groug@kaod.org \
    --to=groug@kaod.org \
    --cc=dgilbert@redhat.com \
    --cc=gmaglione@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sebastian.hasler@stuvus.uni-stuttgart.de \
    --cc=stefanha@redhat.com \
    --cc=vgoyal@redhat.com \
    --cc=virtio-fs@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).