Skip to content

Commit

Permalink
aio is alive again, not properly tested
Browse files Browse the repository at this point in the history
Signed-off-by: Peter-Jan Gootzen <[email protected]>
  • Loading branch information
Peter-JanGootzen committed Apr 20, 2023
1 parent 9663f34 commit 97dd721
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 500 deletions.
4 changes: 4 additions & 0 deletions conf_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ two_threads = true
[kv]
# The remote RAMCloud server that KV will connect to
ramcloud_coordinator = "PLACEHOLDER"

[local_mirror]
dir = "/mnt/shared"
cached = false
2 changes: 1 addition & 1 deletion dpfs_aio/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
virtiofuser_aio
dpfs_aio
15 changes: 11 additions & 4 deletions dpfs_aio/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ if HAVE_SNAP

bin_PROGRAMS = dpfs_aio

dpfs_aio_LDADD = $(srcdir)/../dpfs_fuse/libdpfs_fuse.a \
$(IBVERBS_LDFLAGS) $(SNAP_LDFLAGS) $(PYTHON3_LDFLAGS) -lpthread
dpfs_aio_LDADD = $(srcdir)/../dpfs_fuse/libdpfs_fuse.la \
$(srcdir)/../dpfs_hal/libdpfs_hal.la \
-lck -lpthread

dpfs_aio_CFLAGS = $(BASE_CFLAGS) -I$(srcdir)/../../src -I$(srcdir)/../dpfs_fuse -I$(srcdir)/../dpfs_hal $(SNAP_CFLAGS)
dpfs_aio_SOURCES = fuser.c mpool.c mirror_impl.c main.c
dpfs_aio_CFLAGS = $(BASE_CFLAGS) -I$(srcdir) -I$(srcdir)/../lib \
-I/usr/local/include \
-I$(srcdir)/../extern/tomlcpp \
-I$(srcdir)/../dpfs_fuse -I$(srcdir)/../dpfs_hal/include

dpfs_aio_SOURCES = fuser.c mirror_impl.c main.c \
../lib/mpool.c \
../extern/tomlcpp/toml.c

endif
15 changes: 7 additions & 8 deletions dpfs_aio/fuser.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <limits.h>
#include <pthread.h>
#include <fcntl.h>
#include <linux/aio_abi.h>

#include "fuser.h"
#include "virtiofs_emu_ll.h"
#include "mirror_impl.h"
#include "common.h"
#include "aio.h"

struct inode *inode_new(fuse_ino_t ino) {
Expand Down Expand Up @@ -171,24 +170,24 @@ static void *fuser_io_poll_thread(struct fuser *f) {
struct fuser_rw_cb_data *cb_data = (struct fuser_rw_cb_data *) e.data;
if (e.res == -1) {
cb_data->out_hdr->error = -errno;
cb_data->cb->cb(SNAP_FS_DEV_OP_SUCCESS, cb_data->cb->user_arg);
dpfs_hal_async_complete(cb_data->completion_context, DPFS_HAL_COMPLETION_SUCCES);
}

if (cb_data->op == FUSER_RW_CB_WRITE) {
cb_data->rw.write.out_write->size = e.res;
cb_data->out_hdr->len += sizeof(*cb_data->rw.write.out_write);
cb_data->cb->cb(SNAP_FS_DEV_OP_SUCCESS, cb_data->cb->user_arg);
dpfs_hal_async_complete(cb_data->completion_context, DPFS_HAL_COMPLETION_SUCCES);
} else { // READ
cb_data->out_hdr->len += e.res;
cb_data->cb->cb(SNAP_FS_DEV_OP_SUCCESS, cb_data->cb->user_arg);
dpfs_hal_async_complete(cb_data->completion_context, DPFS_HAL_COMPLETION_SUCCES);
}
mpool_free(f->cb_data_pool, cb_data);
}
return NULL;
}

// todo proper error handling
int fuser_main(bool debug, char *source, bool cached, struct virtiofs_emu_params *emu_params) {
int fuser_main(bool debug, char *source, bool cached, const char *conf_path) {
struct fuser *f = calloc(1, sizeof(struct fuser));
if (f == NULL)
err(1, "ERROR: Could not allocate memory for struct fuser");
Expand Down Expand Up @@ -230,11 +229,11 @@ int fuser_main(bool debug, char *source, bool cached, struct virtiofs_emu_params
struct fuse_ll_operations ops;
fuser_mirror_assign_ops(&ops);

mpool_init(f->cb_data_pool, 100, sizeof(struct fuser_rw_cb_data), 10);
mpool_init(&f->cb_data_pool, sizeof(struct fuser_rw_cb_data), 256);
pthread_t poll_thread;
pthread_create(&poll_thread, NULL, (void *(*)(void *))fuser_io_poll_thread, f);

virtiofs_emu_fuse_ll_main(&ops, emu_params, f, debug);
dpfs_fuse_main(&ops, conf_path, f, debug);

f->io_poll_thread_stop = true;
pthread_join(poll_thread, NULL);
Expand Down
5 changes: 2 additions & 3 deletions dpfs_aio/fuser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#include <linux/fuse.h>
#include <linux/aio_abi.h>

#include "fuse_ll.h"
#include "virtiofs_emu_ll.h"
#include "dpfs_fuse.h"
#include "mpool.h"

struct inode {
Expand Down Expand Up @@ -83,6 +82,6 @@ struct inode *ino_to_inodeptr(struct fuser *, fuse_ino_t);
int ino_to_fd(struct fuser *, fuse_ino_t);

int fuser_main(bool debug, char *source, bool cached,
struct virtiofs_emu_params *emu_params);
const char *conf_path);

#endif // FUSER_H
107 changes: 53 additions & 54 deletions dpfs_aio/main.c
Original file line number Diff line number Diff line change
@@ -1,89 +1,88 @@
/*
#
# Copyright 2022- IBM Inc. All rights reserved
# Copyright 2023- IBM Inc. All rights reserved
# SPDX-License-Identifier: LGPL-2.1-or-later
#
*/

#include <getopt.h>
#include "fuser.h"
#include <stdlib.h>
#include <errno.h>
#include "dpfs_fuse.h"
#include "toml.h"

#include "fuser.h"

void usage()
{
printf("dpfs_fuse [-p pf_id] [-v vf_id ] [-e emulation_manager_name] [-d dir_mirror_path]\n");
printf("aio_mirror [-c config_path]\n");
}

int main(int argc, char **argv)
{
int pf = -1;
int vf = -1;
char *emu_manager = NULL; // the rdma device name which supports being an emulation manager and virtio_fs emu
char *dir = NULL; // the directory that will be mirrored
char *conf_path = NULL;

int opt;
while ((opt = getopt(argc, argv, "p:v:e:d:")) != -1) {
while ((opt = getopt(argc, argv, "c:")) != -1) {
switch (opt) {
case 'p':
pf = atoi(optarg);
break;
case 'v':
vf = atoi(optarg);
break;
case 'e':
emu_manager = optarg;
break;
case 'd':
dir = optarg;
case 'c':
conf_path = optarg;
break;
default: /* '?' */
usage();
exit(1);
}
}

struct virtiofs_emu_params emu_params;
// just for safety
memset(&emu_params, 0, sizeof(struct virtiofs_emu_params));

if (pf >= 0)
emu_params.pf_id = pf;
else {
fprintf(stderr, "You must supply a pf with -p\n");

if (!conf_path) {
fprintf(stderr, "A config file is required!");
usage();
exit(1);
return -1;
}
if (vf >= 0)
emu_params.vf_id = vf;
else
emu_params.vf_id = -1;

FILE *fp;
char errbuf[200];

if (emu_manager != NULL) {
emu_params.emu_manager = emu_manager;
} else {
fprintf(stderr, "You must supply an emu manager name with -e\n");
usage();
exit(1);
// 1. Read and parse toml file
fp = fopen(conf_path, "r");
if (!fp) {
fprintf(stderr, "%s: cannot open %s - %s", __func__,
conf_path, strerror(errno));
return -1;
}
if (dir == NULL) {
fprintf(stderr, "You must supply an emu manager name with -e\n");
usage();
exit(1);

toml_table_t *conf = toml_parse_file(fp, errbuf, sizeof(errbuf));
fclose(fp);

if (!conf) {
fprintf(stderr, "%s: cannot parse - %s", __func__, errbuf);
return -1;
}
char *rp = realpath(dir, NULL);

toml_table_t *local_mirror_conf = toml_table_in(conf, "local_mirror");
if (!local_mirror_conf) {
fprintf(stderr, "%s: missing [local_mirror] in config file", __func__);
return -1;
}

toml_datum_t dir = toml_string_in(local_mirror_conf, "dir");
if (!dir.ok) {
fprintf(stderr, "You must supply a directory to mirror with `dir` under [local_mirror]\n");
return -1;
}
char *rp = realpath(dir.u.s, NULL);
if (rp == NULL) {
fprintf(stderr, "Could not parse dir %s, errno=%d\n", dir, errno);
fprintf(stderr, "Could not parse dir %s, errno=%d\n", dir.u.s, errno);
exit(errno);
}
dir = rp;
printf("virtiofuser starting up!\n");
printf("Mirroring %s\n", dir);

emu_params.polling_interval_usec = 0;
emu_params.nthreads = 0;
emu_params.tag = "virtiofuser";
toml_datum_t cached = toml_bool_in(local_mirror_conf, "cached");
if (!cached.ok) {
fprintf(stderr, "You must supply `cached` under [local_mirror]\n");
return -1;
}

fuser_main(false, dir, false, &emu_params);
printf("virtiofuser starting up!\n");
printf("Mirroring %s\n", rp);

return 0;
fuser_main(false, rp, cached.u.b, conf_path);
}
Loading

0 comments on commit 97dd721

Please sign in to comment.