render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

Blame 0024-virtiofsd-Make-fsync-work-even-if-only-inode-is-pass.patch

1d442b
From: Vivek Goyal <vgoyal@redhat.com>
1d442b
Date: Mon, 27 Jan 2020 19:00:53 +0000
1d442b
Subject: [PATCH] virtiofsd: Make fsync work even if only inode is passed in
1d442b
MIME-Version: 1.0
1d442b
Content-Type: text/plain; charset=UTF-8
1d442b
Content-Transfer-Encoding: 8bit
1d442b
1d442b
If caller has not sent file handle in request, then using inode, retrieve
1d442b
the fd opened using O_PATH and use that to open file again and issue
1d442b
fsync. This will be needed when dax_flush() calls fsync. At that time
1d442b
we only have inode information (and not file).
1d442b
1d442b
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
1d442b
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
(cherry picked from commit 1b209805f8159c3f4d89ddb9390a5f64887cebff)
1d442b
---
1d442b
 tools/virtiofsd/fuse_lowlevel.c  |  6 +++++-
1d442b
 tools/virtiofsd/passthrough_ll.c | 28 ++++++++++++++++++++++++++--
1d442b
 2 files changed, 31 insertions(+), 3 deletions(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
1d442b
index 514d79cb24..8552cfb8af 100644
1d442b
--- a/tools/virtiofsd/fuse_lowlevel.c
1d442b
+++ b/tools/virtiofsd/fuse_lowlevel.c
1d442b
@@ -1075,7 +1075,11 @@ static void do_fsync(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1d442b
     fi.fh = arg->fh;
1d442b
 
1d442b
     if (req->se->op.fsync) {
1d442b
-        req->se->op.fsync(req, nodeid, datasync, &fi);
1d442b
+        if (fi.fh == (uint64_t)-1) {
1d442b
+            req->se->op.fsync(req, nodeid, datasync, NULL);
1d442b
+        } else {
1d442b
+            req->se->op.fsync(req, nodeid, datasync, &fi);
1d442b
+        }
1d442b
     } else {
1d442b
         fuse_reply_err(req, ENOSYS);
1d442b
     }
1d442b
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
1d442b
index 6c4da18075..26ac87013b 100644
1d442b
--- a/tools/virtiofsd/passthrough_ll.c
1d442b
+++ b/tools/virtiofsd/passthrough_ll.c
1d442b
@@ -903,10 +903,34 @@ static void lo_fsync(fuse_req_t req, fuse_ino_t ino, int datasync,
1d442b
 {
1d442b
     int res;
1d442b
     (void)ino;
1d442b
+    int fd;
1d442b
+    char *buf;
1d442b
+
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "lo_fsync(ino=%" PRIu64 ", fi=0x%p)\n", ino,
1d442b
+             (void *)fi);
1d442b
+
1d442b
+    if (!fi) {
1d442b
+        res = asprintf(&buf, "/proc/self/fd/%i", lo_fd(req, ino));
1d442b
+        if (res == -1) {
1d442b
+            return (void)fuse_reply_err(req, errno);
1d442b
+        }
1d442b
+
1d442b
+        fd = open(buf, O_RDWR);
1d442b
+        free(buf);
1d442b
+        if (fd == -1) {
1d442b
+            return (void)fuse_reply_err(req, errno);
1d442b
+        }
1d442b
+    } else {
1d442b
+        fd = fi->fh;
1d442b
+    }
1d442b
+
1d442b
     if (datasync) {
1d442b
-        res = fdatasync(fi->fh);
1d442b
+        res = fdatasync(fd);
1d442b
     } else {
1d442b
-        res = fsync(fi->fh);
1d442b
+        res = fsync(fd);
1d442b
+    }
1d442b
+    if (!fi) {
1d442b
+        close(fd);
1d442b
     }
1d442b
     fuse_reply_err(req, res == -1 ? errno : 0);
1d442b
 }