cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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