Skip to content

Commit

Permalink
virtio-fs: implement FUSE_INIT map_alignment field
Browse files Browse the repository at this point in the history
Signed-off-by: Fotis Xenakis <[email protected]>
Message-Id: <VI1PR03MB4383AE2F61F985FAA55C0826A6BB0@VI1PR03MB4383.eurprd03.prod.outlook.com>
  • Loading branch information
foxeng authored and wkozaczuk committed May 21, 2020
1 parent 0dbb47d commit dbc9798
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/virtio-fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
7 changes: 7 additions & 0 deletions drivers/virtio-fs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion fs/virtiofs/virtiofs_vfsops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down

0 comments on commit dbc9798

Please sign in to comment.