[Virtio-fs] [PATCH 13/24] DAX: virtiofsd: Make lo_removemapping() work

Dr. David Alan Gilbert (git) dgilbert at redhat.com
Tue Feb 9 19:02:13 UTC 2021


From: Vivek Goyal <vgoyal at redhat.com>

Let guest pass in the offset in dax window a mapping is currently
mapped at and needs to be removed.

Vivek added the initial support to remove single mapping and later Peng
added patch to support removing multiple mappings in single command.

Signed-off-by: Vivek Goyal <vgoyal at redhat.com>
Signed-off-by: Peng Tao <tao.peng at linux.alibaba.com>
---
 tools/virtiofsd/passthrough_ll.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 0493f00756..971ff2b2ea 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -3023,8 +3023,30 @@ static void lo_removemapping(fuse_req_t req, struct fuse_session *se,
                              fuse_ino_t ino, unsigned num,
                              struct fuse_removemapping_one *argp)
 {
-    /* TODO */
-    fuse_reply_err(req, ENOSYS);
+    VhostUserFSSlaveMsg msg = { 0 };
+    int ret = 0;
+
+    for (int i = 0; num > 0; i++, argp++) {
+        msg.len[i] = argp->len;
+        msg.c_offset[i] = argp->moffset;
+
+        if (--num == 0 || i == VHOST_USER_FS_SLAVE_ENTRIES - 1) {
+            ret = fuse_virtio_unmap(se, &msg);
+            if (ret < 0) {
+                fuse_log(FUSE_LOG_ERR,
+                         "%s: unmap over virtio failed "
+                         "(offset=0x%lx, len=0x%lx). err=%d\n",
+                         __func__, argp->moffset, argp->len, ret);
+                break;
+            }
+            if (num > 0) {
+                i = 0;
+                memset(&msg, 0, sizeof(msg));
+            }
+        }
+    }
+
+    fuse_reply_err(req, -ret);
 }
 
 static struct fuse_lowlevel_ops lo_oper = {
-- 
2.29.2




More information about the Virtio-fs mailing list