[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 14/26] DAX: virtiofsd: Wire up passthrough_ll's lo_setupmappin
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[PATCH v3 14/26] DAX: virtiofsd: Wire up passthrough_ll's lo_setupmapping |
Date: |
Wed, 28 Apr 2021 12:00:48 +0100 |
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Wire up passthrough_ll's setupmapping to allocate, send to virtio
and then reply OK.
Guest might not pass file pointer. In that case using inode info, open
the file again, mmap() and close fd.
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
With fix from:
Signed-off-by: Fotis Xenakis <foxen@windowslive.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
tools/virtiofsd/fuse_lowlevel.c | 13 ++++++--
tools/virtiofsd/passthrough_ll.c | 57 ++++++++++++++++++++++++++++++--
2 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
index a1a8730b73..4921f1bbb7 100644
--- a/tools/virtiofsd/fuse_lowlevel.c
+++ b/tools/virtiofsd/fuse_lowlevel.c
@@ -1899,8 +1899,17 @@ static void do_setupmapping(fuse_req_t req, fuse_ino_t
nodeid,
}
if (req->se->op.setupmapping) {
- req->se->op.setupmapping(req, nodeid, arg->foffset, arg->len,
- arg->moffset, genflags, &fi);
+ /*
+ * TODO: Add a flag to request which tells if arg->fh is
+ * valid or not.
+ */
+ if (fi.fh == (uint64_t)-1) {
+ req->se->op.setupmapping(req, nodeid, arg->foffset, arg->len,
+ arg->moffset, genflags, NULL);
+ } else {
+ req->se->op.setupmapping(req, nodeid, arg->foffset, arg->len,
+ arg->moffset, genflags, &fi);
+ }
} else {
fuse_reply_err(req, ENOSYS);
}
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index a16d425b78..6981737389 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -3149,8 +3149,61 @@ static void lo_setupmapping(fuse_req_t req, fuse_ino_t
ino, uint64_t foffset,
uint64_t len, uint64_t moffset, uint64_t flags,
struct fuse_file_info *fi)
{
- /* TODO */
- fuse_reply_err(req, ENOSYS);
+ struct lo_data *lo = lo_data(req);
+ int ret = 0, fd;
+ VhostUserFSSlaveMsg *msg = g_malloc0(sizeof(VhostUserFSSlaveMsg) +
+ sizeof(VhostUserFSSlaveMsgEntry));
+ uint64_t vhu_flags;
+ char *buf;
+ bool writable = flags & O_RDWR;
+
+ fuse_log(FUSE_LOG_DEBUG,
+ "lo_setupmapping(ino=%" PRIu64 ", fi=0x%p,"
+ " foffset=%" PRIu64 ", len=%" PRIu64 ", moffset=%" PRIu64
+ ", flags=%" PRIu64 ")\n",
+ ino, (void *)fi, foffset, len, moffset, flags);
+
+ vhu_flags = VHOST_USER_FS_FLAG_MAP_R;
+ if (writable) {
+ vhu_flags |= VHOST_USER_FS_FLAG_MAP_W;
+ }
+
+ msg->count = 1;
+ msg->entries[0].fd_offset = foffset;
+ msg->entries[0].len = len;
+ msg->entries[0].c_offset = moffset;
+ msg->entries[0].flags = vhu_flags;
+
+ if (fi) {
+ fd = lo_fi_fd(req, fi);
+ } else {
+ ret = asprintf(&buf, "%i", lo_fd(req, ino));
+ if (ret == -1) {
+ g_free(msg);
+ return (void)fuse_reply_err(req, errno);
+ }
+
+ fd = openat(lo->proc_self_fd, buf, flags);
+ free(buf);
+ if (fd == -1) {
+ g_free(msg);
+ return (void)fuse_reply_err(req, errno);
+ }
+ }
+
+ ret = fuse_virtio_map(req, msg, fd);
+ if (ret < 0) {
+ fuse_log(FUSE_LOG_ERR,
+ "%s: map over virtio failed (ino=%" PRId64
+ "fd=%d moffset=0x%" PRIx64 "). err = %d\n",
+ __func__, ino, fd, moffset, ret);
+ }
+
+ if (!fi) {
+ close(fd);
+ }
+ fuse_reply_err(req, -ret);
+ g_free(msg);
}
static void lo_removemapping(fuse_req_t req, struct fuse_session *se,
--
2.31.1
- [PATCH v3 02/26] virtiofsd: Don't assume header layout, (continued)
- [PATCH v3 02/26] virtiofsd: Don't assume header layout, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 04/26] DAX: libvhost-user: Route slave message payload, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 06/26] DAX subprojects/libvhost-user: Add virtio-fs slave types, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 08/26] DAX: virtio-fs: Add cache BAR, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 07/26] DAX: virtio: Add shared memory capability, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 09/26] DAX: virtio-fs: Add vhost-user slave commands for mapping, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 05/26] DAX: libvhost-user: Allow popping a queue element with bad pointers, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 10/26] DAX: virtio-fs: Fill in slave commands for mapping, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 11/26] DAX: virtiofsd Add cache accessor functions, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 12/26] DAX: virtiofsd: Add setup/remove mappings fuse commands, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 14/26] DAX: virtiofsd: Wire up passthrough_ll's lo_setupmapping,
Dr. David Alan Gilbert (git) <=
- [PATCH v3 13/26] DAX: virtiofsd: Add setup/remove mapping handlers to passthrough_ll, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 15/26] DAX: virtiofsd: Make lo_removemapping() work, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 16/26] DAX: virtiofsd: route se down to destroy method, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 17/26] DAX: virtiofsd: Perform an unmap on destroy, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 18/26] DAX/unmap: virtiofsd: Add VHOST_USER_SLAVE_FS_IO, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 19/26] DAX/unmap virtiofsd: Add wrappers for VHOST_USER_SLAVE_FS_IO, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 21/26] DAX/unmap virtiofsd: Route unmappable reads, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 23/26] DAX:virtiofsd: implement FUSE_INIT map_alignment field, Dr. David Alan Gilbert (git), 2021/04/28
- [PATCH v3 20/26] DAX/unmap virtiofsd: Parse unmappable elements, Dr. David Alan Gilbert (git), 2021/04/28