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>
This commit is contained in:
Vivek Goyal 2018-08-30 14:22:10 -04:00 committed by Dr. David Alan Gilbert
parent 9776457ca6
commit 1b209805f8
2 changed files with 32 additions and 4 deletions

View File

@ -1075,7 +1075,11 @@ static void do_fsync(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
fi.fh = arg->fh; fi.fh = arg->fh;
if (req->se->op.fsync) { if (req->se->op.fsync) {
if (fi.fh == (uint64_t)-1) {
req->se->op.fsync(req, nodeid, datasync, NULL);
} else {
req->se->op.fsync(req, nodeid, datasync, &fi); req->se->op.fsync(req, nodeid, datasync, &fi);
}
} else { } else {
fuse_reply_err(req, ENOSYS); fuse_reply_err(req, ENOSYS);
} }

View File

@ -903,10 +903,34 @@ static void lo_fsync(fuse_req_t req, fuse_ino_t ino, int datasync,
{ {
int res; int res;
(void)ino; (void)ino;
if (datasync) { int fd;
res = fdatasync(fi->fh); 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 { } else {
res = fsync(fi->fh); fd = fi->fh;
}
if (datasync) {
res = fdatasync(fd);
} else {
res = fsync(fd);
}
if (!fi) {
close(fd);
} }
fuse_reply_err(req, res == -1 ? errno : 0); fuse_reply_err(req, res == -1 ? errno : 0);
} }