Skip to content

Commit

Permalink
virtio-fs: expose FUSE reply length
Browse files Browse the repository at this point in the history
Signed-off-by: Fotis Xenakis <[email protected]>
Message-Id: <AM0PR03MB6292EFEA10E0C7A9B7BFF516A67A0@AM0PR03MB6292.eurprd03.prod.outlook.com>
  • Loading branch information
foxeng authored and wkozaczuk committed Jul 22, 2020
1 parent a6fb0d6 commit afe903f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions fs/virtiofs/virtiofs_dax.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int dax_manager::map_ll(uint64_t nodeid, uint64_t file_handle, chunk nchunks,
"moffset=%lld)\n", nodeid, in_args->foffset, in_args->len,
in_args->moffset);
auto error = fuse_req_send_and_receive_reply(&_drv, FUSE_SETUPMAPPING,
nodeid, in_args.get(), sizeof(*in_args), nullptr, 0);
nodeid, in_args.get(), sizeof(*in_args), nullptr, 0).second;
if (error) {
kprintf("[virtiofs] inode %lld, mapping setup failed\n", nodeid);
return error;
Expand Down Expand Up @@ -230,7 +230,7 @@ int dax_manager::unmap_ll(chunk nchunks, chunk mstart)
virtiofs_debug("inode %lld, removing mapping (moffset=%lld, len=%lld)\n",
nodeid, r_one->moffset, r_one->len);
auto error = fuse_req_send_and_receive_reply(&_drv, FUSE_REMOVEMAPPING,
nodeid, in_args.get(), in_args_size, nullptr, 0);
nodeid, in_args.get(), in_args_size, nullptr, 0).second;
if (error) {
kprintf("[virtiofs] inode %lld, mapping removal failed\n", nodeid);
return error;
Expand Down
8 changes: 5 additions & 3 deletions fs/virtiofs/virtiofs_i.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#ifndef VIRTIOFS_IO_H
#define VIRTIOFS_IO_H

#include <utility>

#include "drivers/virtio-fs.hh"

int fuse_req_send_and_receive_reply(virtio::fs* drv, uint32_t opcode,
uint64_t nodeid, void* input_args_data, size_t input_args_size,
void* output_args_data, size_t output_args_size);
std::pair<size_t, int> fuse_req_send_and_receive_reply(virtio::fs* drv,
uint32_t opcode, uint64_t nodeid, void* input_args_data,
size_t input_args_size, void* output_args_data, size_t output_args_size);

#endif
16 changes: 10 additions & 6 deletions fs/virtiofs/virtiofs_vfsops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <mutex>
#include <new>
#include <sys/types.h>
#include <utility>

#include <api/assert.h>
#include <osv/debug.h>
Expand All @@ -32,14 +33,14 @@ static struct {
mutex lock;
} dax_managers;

int fuse_req_send_and_receive_reply(virtio::fs* drv, uint32_t opcode,
uint64_t nodeid, void* input_args_data, size_t input_args_size,
void* output_args_data, size_t output_args_size)
std::pair<size_t, int> fuse_req_send_and_receive_reply(virtio::fs* drv,
uint32_t opcode, uint64_t nodeid, void* input_args_data,
size_t input_args_size, void* output_args_data, size_t output_args_size)
{
std::unique_ptr<fuse_request> req {
new (std::nothrow) fuse_request(sched::thread::current())};
if (!req) {
return ENOMEM;
return std::make_pair(0, ENOMEM);
}
req->in_header.len = sizeof(req->in_header) + input_args_size;
req->in_header.opcode = opcode;
Expand All @@ -57,9 +58,11 @@ int fuse_req_send_and_receive_reply(virtio::fs* drv, uint32_t opcode,
drv->make_request(*req);
req->wait();

// return the length of the response's payload
size_t len = req->out_header.len - sizeof(fuse_out_header);
int error = -req->out_header.error;

return error;
return std::make_pair(len, error);
}

void virtiofs_set_vnode(struct vnode* vnode, struct virtiofs_inode* inode)
Expand Down Expand Up @@ -107,7 +110,8 @@ static int virtiofs_mount(struct mount* mp, const char* dev, int flags,

auto* drv = static_cast<virtio::fs*>(device->private_data);
error = fuse_req_send_and_receive_reply(drv, FUSE_INIT, FUSE_ROOT_ID,
in_args.get(), sizeof(*in_args), out_args.get(), sizeof(*out_args));
in_args.get(), sizeof(*in_args), out_args.get(),
sizeof(*out_args)).second;
if (error) {
kprintf("[virtiofs] Failed to initialize fuse filesystem!\n");
return error;
Expand Down
11 changes: 6 additions & 5 deletions fs/virtiofs/virtiofs_vnops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int virtiofs_lookup(struct vnode* vnode, char* name, struct vnode** vpp)
auto* drv = m_data->drv;
auto error = fuse_req_send_and_receive_reply(drv, FUSE_LOOKUP,
inode->nodeid, in_args.get(), in_args_len, out_args.get(),
sizeof(*out_args));
sizeof(*out_args)).second;
if (error) {
kprintf("[virtiofs] inode %lld, lookup failed to find %s\n",
inode->nodeid, name);
Expand Down Expand Up @@ -114,7 +114,7 @@ static int virtiofs_open(struct file* fp)
auto* drv = m_data->drv;
auto error = fuse_req_send_and_receive_reply(drv, FUSE_OPEN,
inode->nodeid, in_args.get(), sizeof(*in_args), out_args.get(),
sizeof(*out_args));
sizeof(*out_args)).second;
if (error) {
kprintf("[virtiofs] inode %lld, open failed\n", inode->nodeid);
return error;
Expand Down Expand Up @@ -149,7 +149,7 @@ static int virtiofs_close(struct vnode* vnode, struct file* fp)
auto* m_data = static_cast<virtiofs_mount_data*>(vnode->v_mount->m_data);
auto* drv = m_data->drv;
auto error = fuse_req_send_and_receive_reply(drv, FUSE_RELEASE,
inode->nodeid, in_args.get(), sizeof(*in_args), nullptr, 0);
inode->nodeid, in_args.get(), sizeof(*in_args), nullptr, 0).second;
if (error) {
kprintf("[virtiofs] inode %lld, close failed\n", inode->nodeid);
return error;
Expand Down Expand Up @@ -177,7 +177,7 @@ static int virtiofs_readlink(struct vnode* vnode, struct uio* uio)
auto* m_data = static_cast<virtiofs_mount_data*>(vnode->v_mount->m_data);
auto* drv = m_data->drv;
auto error = fuse_req_send_and_receive_reply(drv, FUSE_READLINK,
inode->nodeid, nullptr, 0, link_path.get(), PATH_MAX);
inode->nodeid, nullptr, 0, link_path.get(), PATH_MAX).second;
if (error) {
kprintf("[virtiofs] inode %lld, readlink failed\n", inode->nodeid);
return error;
Expand Down Expand Up @@ -207,7 +207,8 @@ static int virtiofs_read_fallback(virtiofs_inode& inode, u64 file_handle,
virtiofs_debug("inode %lld, reading %lld bytes at offset %lld\n",
inode.nodeid, read_amt, uio.uio_offset);
auto error = fuse_req_send_and_receive_reply(&drv, FUSE_READ,
inode.nodeid, in_args.get(), sizeof(*in_args), buf.get(), read_amt);
inode.nodeid, in_args.get(), sizeof(*in_args), buf.get(),
read_amt).second;
if (error) {
kprintf("[virtiofs] inode %lld, read failed\n", inode.nodeid);
return error;
Expand Down

0 comments on commit afe903f

Please sign in to comment.