thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-virtiofsd-Make-fsync-work-even-if-only-inode-is-pass.patch

ddf19c
From f09f13f9a001a50ee3465c165f4bbaf870fcadb9 Mon Sep 17 00:00:00 2001
ddf19c
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
ddf19c
Date: Mon, 27 Jan 2020 19:00:53 +0100
ddf19c
Subject: [PATCH 022/116] virtiofsd: Make fsync work even if only inode is
ddf19c
 passed in
ddf19c
MIME-Version: 1.0
ddf19c
Content-Type: text/plain; charset=UTF-8
ddf19c
Content-Transfer-Encoding: 8bit
ddf19c
ddf19c
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
Message-id: <20200127190227.40942-19-dgilbert@redhat.com>
ddf19c
Patchwork-id: 93472
ddf19c
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 018/112] virtiofsd: Make fsync work even if only inode is passed in
ddf19c
Bugzilla: 1694164
ddf19c
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ddf19c
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
ddf19c
ddf19c
From: Vivek Goyal <vgoyal@redhat.com>
ddf19c
ddf19c
If caller has not sent file handle in request, then using inode, retrieve
ddf19c
the fd opened using O_PATH and use that to open file again and issue
ddf19c
fsync. This will be needed when dax_flush() calls fsync. At that time
ddf19c
we only have inode information (and not file).
ddf19c
ddf19c
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
ddf19c
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
ddf19c
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
(cherry picked from commit 1b209805f8159c3f4d89ddb9390a5f64887cebff)
ddf19c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
---
ddf19c
 tools/virtiofsd/fuse_lowlevel.c  |  6 +++++-
ddf19c
 tools/virtiofsd/passthrough_ll.c | 28 ++++++++++++++++++++++++++--
ddf19c
 2 files changed, 31 insertions(+), 3 deletions(-)
ddf19c
ddf19c
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
ddf19c
index 514d79c..8552cfb 100644
ddf19c
--- a/tools/virtiofsd/fuse_lowlevel.c
ddf19c
+++ b/tools/virtiofsd/fuse_lowlevel.c
ddf19c
@@ -1075,7 +1075,11 @@ static void do_fsync(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
ddf19c
     fi.fh = arg->fh;
ddf19c
 
ddf19c
     if (req->se->op.fsync) {
ddf19c
-        req->se->op.fsync(req, nodeid, datasync, &fi);
ddf19c
+        if (fi.fh == (uint64_t)-1) {
ddf19c
+            req->se->op.fsync(req, nodeid, datasync, NULL);
ddf19c
+        } else {
ddf19c
+            req->se->op.fsync(req, nodeid, datasync, &fi);
ddf19c
+        }
ddf19c
     } else {
ddf19c
         fuse_reply_err(req, ENOSYS);
ddf19c
     }
ddf19c
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
ddf19c
index 6c4da18..26ac870 100644
ddf19c
--- a/tools/virtiofsd/passthrough_ll.c
ddf19c
+++ b/tools/virtiofsd/passthrough_ll.c
ddf19c
@@ -903,10 +903,34 @@ static void lo_fsync(fuse_req_t req, fuse_ino_t ino, int datasync,
ddf19c
 {
ddf19c
     int res;
ddf19c
     (void)ino;
ddf19c
+    int fd;
ddf19c
+    char *buf;
ddf19c
+
ddf19c
+    fuse_log(FUSE_LOG_DEBUG, "lo_fsync(ino=%" PRIu64 ", fi=0x%p)\n", ino,
ddf19c
+             (void *)fi);
ddf19c
+
ddf19c
+    if (!fi) {
ddf19c
+        res = asprintf(&buf, "/proc/self/fd/%i", lo_fd(req, ino));
ddf19c
+        if (res == -1) {
ddf19c
+            return (void)fuse_reply_err(req, errno);
ddf19c
+        }
ddf19c
+
ddf19c
+        fd = open(buf, O_RDWR);
ddf19c
+        free(buf);
ddf19c
+        if (fd == -1) {
ddf19c
+            return (void)fuse_reply_err(req, errno);
ddf19c
+        }
ddf19c
+    } else {
ddf19c
+        fd = fi->fh;
ddf19c
+    }
ddf19c
+
ddf19c
     if (datasync) {
ddf19c
-        res = fdatasync(fi->fh);
ddf19c
+        res = fdatasync(fd);
ddf19c
     } else {
ddf19c
-        res = fsync(fi->fh);
ddf19c
+        res = fsync(fd);
ddf19c
+    }
ddf19c
+    if (!fi) {
ddf19c
+        close(fd);
ddf19c
     }
ddf19c
     fuse_reply_err(req, res == -1 ? errno : 0);
ddf19c
 }
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c