yeahuh / 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

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