summaryrefslogtreecommitdiffstats
path: root/tools/virtiofsd/passthrough_ll.c
diff options
context:
space:
mode:
authorVivek Goyal2018-08-30 20:22:10 +0200
committerDr. David Alan Gilbert2020-01-23 17:41:36 +0100
commit1b209805f8159c3f4d89ddb9390a5f64887cebff (patch)
treee53ff3056e6afaab2f0ad28a6510a9a05bade438 /tools/virtiofsd/passthrough_ll.c
parentvitriofsd/passthrough_ll: fix fallocate() ifdefs (diff)
downloadqemu-1b209805f8159c3f4d89ddb9390a5f64887cebff.tar.gz
qemu-1b209805f8159c3f4d89ddb9390a5f64887cebff.tar.xz
qemu-1b209805f8159c3f4d89ddb9390a5f64887cebff.zip
virtiofsd: Make fsync work even if only inode is passed in
If caller has not sent file handle in request, then using inode, retrieve the fd opened using O_PATH and use that to open file again and issue fsync. This will be needed when dax_flush() calls fsync. At that time we only have inode information (and not file). Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Diffstat (limited to 'tools/virtiofsd/passthrough_ll.c')
-rw-r--r--tools/virtiofsd/passthrough_ll.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 6c4da18075..26ac87013b 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -903,10 +903,34 @@ static void lo_fsync(fuse_req_t req, fuse_ino_t ino, int datasync,
{
int res;
(void)ino;
+ int fd;
+ char *buf;
+
+ fuse_log(FUSE_LOG_DEBUG, "lo_fsync(ino=%" PRIu64 ", fi=0x%p)\n", ino,
+ (void *)fi);
+
+ if (!fi) {
+ res = asprintf(&buf, "/proc/self/fd/%i", lo_fd(req, ino));
+ if (res == -1) {
+ return (void)fuse_reply_err(req, errno);
+ }
+
+ fd = open(buf, O_RDWR);
+ free(buf);
+ if (fd == -1) {
+ return (void)fuse_reply_err(req, errno);
+ }
+ } else {
+ fd = fi->fh;
+ }
+
if (datasync) {
- res = fdatasync(fi->fh);
+ res = fdatasync(fd);
} else {
- res = fsync(fi->fh);
+ res = fsync(fd);
+ }
+ if (!fi) {
+ close(fd);
}
fuse_reply_err(req, res == -1 ? errno : 0);
}