From: Fotis Xenakis <fo...@windowslive.com>
Committer: Waldemar Kozaczuk <jwkozac...@gmail.com>
Branch: master

virtio-fs: implement FUSE_INIT map_alignment field

Signed-off-by: Fotis Xenakis <fo...@windowslive.com>
Message-Id: 
<vi1pr03mb4383ae2f61f985faa55c0826a6...@vi1pr03mb4383.eurprd03.prod.outlook.com>

---
diff --git a/drivers/virtio-fs.cc b/drivers/virtio-fs.cc
--- a/drivers/virtio-fs.cc
+++ b/drivers/virtio-fs.cc
@@ -103,7 +103,7 @@ bool fs::ack_irq()
 }
 
 fs::fs(virtio_device& virtio_dev)
-    : virtio_driver(virtio_dev)
+    : virtio_driver(virtio_dev), _map_align(-1)
 {
     _driver_name = "virtio-fs";
     _id = _instance++;
diff --git a/drivers/virtio-fs.hh b/drivers/virtio-fs.hh
--- a/drivers/virtio-fs.hh
+++ b/drivers/virtio-fs.hh
@@ -44,6 +44,12 @@ public:
     dax_window* get_dax() {
         return (_dax.addr != mmio_nullptr) ? &_dax : nullptr;
     }
+    // Set map alignment for DAX window. @map_align should be
+    // log2(byte_alignment), e.g. 12 for a 4096 byte alignment.
+    void set_map_alignment(int map_align) { _map_align = map_align; }
+    // Returns the map alignment for the DAX window as preiously set with
+    // set_map_alignment(), or < 0 if it has not been set.
+    int get_map_alignment() const { return _map_align; }
 
     void req_done();
     int64_t size();
@@ -63,6 +69,7 @@ private:
     std::string _driver_name;
     fs_config _config;
     dax_window _dax;
+    int _map_align;
 
     // maintains the virtio instance number for multiple drives
     static int _instance;
diff --git a/fs/virtiofs/virtiofs_vfsops.cc b/fs/virtiofs/virtiofs_vfsops.cc
--- a/fs/virtiofs/virtiofs_vfsops.cc
+++ b/fs/virtiofs/virtiofs_vfsops.cc
@@ -12,6 +12,7 @@
 #include <iostream>
 #include "virtiofs.hh"
 #include "virtiofs_i.hh"
+#include "drivers/virtio-fs.hh"
 
 static std::atomic<uint64_t> fuse_unique_id(1);
 
@@ -85,7 +86,7 @@ static int virtiofs_mount(struct mount* mp, const char* dev, 
int flags,
     in_args->major = FUSE_KERNEL_VERSION;
     in_args->minor = FUSE_KERNEL_MINOR_VERSION;
     in_args->max_readahead = PAGE_SIZE;
-    in_args->flags = 0; // TODO: Verify that we need not set any flag
+    in_args->flags |= FUSE_MAP_ALIGNMENT;
 
     auto* strategy = static_cast<fuse_strategy*>(device->private_data);
     error = fuse_req_send_and_receive_reply(strategy, FUSE_INIT, FUSE_ROOT_ID,
@@ -99,6 +100,11 @@ static int virtiofs_mount(struct mount* mp, const char* 
dev, int flags,
     virtiofs_debug("Initialized fuse filesystem with version major: %d, "
                    "minor: %d\n", out_args->major, out_args->minor);
 
+    if (out_args->flags & FUSE_MAP_ALIGNMENT) {
+        auto* drv = static_cast<virtio::fs*>(strategy->drv);
+        drv->set_map_alignment(out_args->map_alignment);
+    }
+
     auto* root_node {new (std::nothrow) virtiofs_inode()};
     if (!root_node) {
         return ENOMEM;

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/00000000000099a9d905a61eefbd%40google.com.

Reply via email to