Skip to content

Commit 27b30e7

Browse files
committed
Convert to FUSE3.
1 parent e93d668 commit 27b30e7

22 files changed

+143
-64
lines changed

.github/workflows/cpp.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v2
1616
- name: apt-get
17-
run: sudo apt-get update ; sudo apt-get -y install libfuse-dev fuse libprotobuf-dev protobuf-compiler liblz4-dev python-protobuf libzstd1 libzstd-dev libattr1-dev libacl1-dev s3cmd valgrind nlohmann-json3-dev meson
17+
run: sudo apt-get update ; sudo apt-get -y install libfuse3-dev fuse3 libprotobuf-dev protobuf-compiler liblz4-dev python3-protobuf libzstd1 libzstd-dev libattr1-dev libacl1-dev s3cmd valgrind nlohmann-json3-dev meson python3-pip
1818
- name: pip
1919
run: sudo env PATH=$PATH pip install zstd==1.4.9.1
2020
- name: fetch fdb

meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ add_project_arguments(
1313
protoc = find_program('protoc', required : true)
1414

1515
deps = [
16-
dependency('fuse'),
16+
dependency('fuse3'),
1717
dependency('libzstd'),
1818
dependency('protobuf'),
1919
dependency('foundationdb-client')

src/fdbfs_ops.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#ifndef __FDBFS_OPS_H__
22
#define __FDBFS_OPS_H__
33

4-
#define FUSE_USE_VERSION 26
4+
#define FUSE_USE_VERSION 35
55
#include <fuse_lowlevel.h>
66

7+
extern "C" void fdbfs_init(void *userdata, struct fuse_conn_info *conn);
78
extern "C" void fdbfs_lookup(fuse_req_t req, fuse_ino_t parent, const char *name);
89
extern "C" void fdbfs_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
910
extern "C" void fdbfs_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi);
@@ -19,7 +20,7 @@ extern "C" void fdbfs_readlink(fuse_req_t req, fuse_ino_t ino);
1920
extern "C" void fdbfs_symlink(fuse_req_t req, const char *link,
2021
fuse_ino_t parent, const char *name);
2122
extern "C" void fdbfs_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr, int to_set, struct fuse_file_info *fi);
22-
extern "C" void fdbfs_rename(fuse_req_t req, fuse_ino_t parent, const char *name, fuse_ino_t newparent, const char *newname);
23+
extern "C" void fdbfs_rename(fuse_req_t req, fuse_ino_t parent, const char *name, fuse_ino_t newparent, const char *newname, unsigned int flags);
2324
extern "C" void fdbfs_write(fuse_req_t req, fuse_ino_t ino, const char *buf, size_t size, off_t off, struct fuse_file_info *fi);
2425
extern "C" void fdbfs_forget(fuse_req_t req, fuse_ino_t ino, uint64_t ncount);
2526
extern "C" void fdbfs_forget_multi(fuse_req_t req, size_t count, struct fuse_forget_data *forgets);

src/forget.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/garbage_collector.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
#define FUSE_USE_VERSION 26
3+
#define FUSE_USE_VERSION 35
44
#include <fuse_lowlevel.h>
55
#define FDB_API_VERSION 630
66
#include <foundationdb/fdb_c.h>

src/getattr.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/getxattr.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/inflight.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/listxattr.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/liveness.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/main.cc

+115-38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>
@@ -37,6 +37,7 @@ uint32_t BLOCKSIZE; // 1<<BLOCKBITS
3737
*/
3838
static struct fuse_lowlevel_ops fdbfs_oper =
3939
{
40+
.init = fdbfs_init,
4041
.lookup = fdbfs_lookup,
4142
.forget = fdbfs_forget,
4243
.getattr = fdbfs_getattr,
@@ -64,6 +65,30 @@ static struct fuse_lowlevel_ops fdbfs_oper =
6465
// .flock = fdbfs_flock
6566
};
6667

68+
void fdbfs_init(void *userdata, struct fuse_conn_info *conn)
69+
{
70+
/*
71+
printf("max_write %i\n", conn->max_write);
72+
printf("max_read %i\n", conn->max_read);
73+
printf("max_readahead %i\n", conn->max_readahead);
74+
printf("max_background %i\n", conn->max_background);
75+
printf("congestion_threshold %i\n", conn->congestion_threshold);
76+
printf("capable %x\n", conn->capable);
77+
printf("want %x\n", conn->want);
78+
*/
79+
// per the docs, transactions should be kept under 1MB.
80+
// let's stay well below that.
81+
if(conn->max_write > (1<<17))
82+
conn->max_write = 1<<17;
83+
// TODO maybe set this to the number of storage servers, or
84+
// half that, or somethimg. using 4 at the moment, to be
85+
// interesting.
86+
conn->max_background = 4;
87+
// TODO some intelligent way to set this?
88+
conn->congestion_threshold = 0;
89+
}
90+
91+
6792
/* Purely to get the FoundationDB network stuff running in a
6893
* background thread. Passing fdb_run_network straight to
6994
* pthread_create kind of works, but let's pretend this will
@@ -83,10 +108,14 @@ void *network_runner(void *ignore)
83108
int main(int argc, char *argv[])
84109
{
85110
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
86-
struct fuse_chan *ch;
87-
char *mountpoint;
111+
struct fuse_session *se;
112+
struct fuse_cmdline_opts opts;
113+
struct fuse_loop_config config;
88114
int err = -1;
89115

116+
pthread_t network_thread;
117+
pthread_t gc_thread;
118+
90119
GOOGLE_PROTOBUF_VERIFY_VERSION;
91120

92121
key_prefix.push_back('F');
@@ -109,48 +138,96 @@ int main(int argc, char *argv[])
109138
}
110139
// TODO put our inode_use_identifier into the pid table somehow
111140

112-
if(fdb_select_api_version(FDB_API_VERSION))
113-
return -1;
114-
if(fdb_setup_network())
115-
return -1;
141+
if(fuse_parse_cmdline(&args, &opts) != 0)
142+
return 1;
143+
144+
if(opts.show_help) {
145+
printf("usage: %s [options] <mountpoint>\n\n", argv[0]);
146+
fuse_cmdline_help();
147+
fuse_lowlevel_help();
148+
err = 0;
149+
goto shutdown_args;
150+
} else if(opts.show_version) {
151+
printf("FUSE library version %s\n", fuse_pkgversion());
152+
fuse_lowlevel_version();
153+
err = 0;
154+
goto shutdown_args;
155+
}
156+
157+
if(opts.mountpoint == NULL) {
158+
printf("usage: %s [options] <mountpoint>\n", argv[0]);
159+
printf(" %s --help\n", argv[0]);
160+
err = 1;
161+
goto shutdown_args;
162+
}
163+
164+
se = fuse_session_new(&args, &fdbfs_oper,
165+
sizeof(fdbfs_oper), NULL);
166+
if(se == NULL) {
167+
err = 1;
168+
goto shutdown_args;
169+
}
170+
if (fuse_set_signal_handlers(se) != 0) {
171+
fuse_session_destroy(se);
172+
err = 1;
173+
goto shutdown_session;
174+
}
175+
if (fuse_session_mount(se, opts.mountpoint) != 0) {
176+
fuse_remove_signal_handlers(se);
177+
fuse_session_destroy(se);
178+
err = 1;
179+
goto shutdown_handlers;
180+
}
181+
182+
// This appears to lock things up
183+
/*
184+
if(fuse_daemonize(opts.foreground)) {
185+
err = 1;
186+
goto shutdown_handlers;
187+
}
188+
*/
189+
190+
if(fdb_select_api_version(FDB_API_VERSION)) {
191+
err = 1;
192+
goto shutdown_unmount;
193+
}
194+
195+
if(fdb_setup_network()) {
196+
err = 1;
197+
goto shutdown_unmount;
198+
}
116199

117-
pthread_t network_thread;
118200
pthread_create(&network_thread, NULL, network_runner, NULL);
119201

120-
if(fdb_create_database(NULL, &database))
121-
return -1;
202+
if(fdb_create_database(NULL, &database)) {
203+
goto shutdown_fdb;
204+
}
122205

123-
pthread_t gc_thread;
124206
pthread_create(&gc_thread, NULL, garbage_scanner, NULL);
125207

126-
if ((fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != -1) &&
127-
((ch = fuse_mount(mountpoint, &args)) != NULL))
128-
{
129-
struct fuse_session *se;
130-
131-
se = fuse_lowlevel_new(&args, &fdbfs_oper,
132-
sizeof(fdbfs_oper), NULL);
133-
start_liveness(se);
134-
135-
if (se != NULL)
136-
{
137-
if (fuse_set_signal_handlers(se) != -1)
138-
{
139-
fuse_session_add_chan(se, ch);
140-
err = fuse_session_loop(se);
141-
fuse_remove_signal_handlers(se);
142-
fuse_session_remove_chan(ch);
143-
}
144-
fuse_session_destroy(se);
145-
}
146-
fuse_unmount(mountpoint, ch);
147-
terminate_liveness();
148-
}
149-
fuse_opt_free_args(&args);
208+
if (opts.singlethread) {
209+
err = fuse_session_loop(se);
210+
} else {
211+
config.clone_fd = opts.clone_fd;
212+
config.max_idle_threads = opts.max_idle_threads;
213+
err = fuse_session_loop_mt(se, &config);
214+
}
150215

151-
fdb_database_destroy(database);
152-
database = NULL;
153-
err = fdb_stop_network();
154216
err = err || pthread_join( network_thread, NULL );
217+
fdb_database_destroy(database);
218+
shutdown_fdb:
219+
err = err || fdb_stop_network();
220+
221+
shutdown_unmount:
222+
fuse_session_unmount(se);
223+
terminate_liveness();
224+
shutdown_handlers:
225+
fuse_remove_signal_handlers(se);
226+
shutdown_session:
227+
fuse_session_destroy(se);
228+
229+
shutdown_args:
230+
fuse_opt_free_args(&args);
231+
155232
return err;
156233
}

src/mknod.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/read.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/readlink.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/removexattr.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/rename.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,17 @@ InflightCallback Inflight_rename::issue()
449449

450450
extern "C" void fdbfs_rename(fuse_req_t req,
451451
fuse_ino_t parent, const char *name,
452-
fuse_ino_t newparent, const char *newname)
452+
fuse_ino_t newparent, const char *newname,
453+
unsigned int flags)
453454
{
454455
if(filename_length_check(req, name) ||
455456
filename_length_check(req, newname)) {
456457
return;
457458
}
458459
Inflight_rename *inflight =
459460
new Inflight_rename(req, parent, std::string(name),
460-
newparent, std::string(newname), 0,
461+
newparent, std::string(newname),
462+
flags,
461463
make_transaction());
462464
inflight->start();
463465
}

src/setattr.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/setxattr.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/unlink.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define FUSE_USE_VERSION 26
2+
#define FUSE_USE_VERSION 35
33
#include <fuse_lowlevel.h>
44
#define FDB_API_VERSION 630
55
#include <foundationdb/fdb_c.h>

src/util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __UTIL_H__
22
#define __UTIL_H__
33

4-
#define FUSE_USE_VERSION 26
4+
#define FUSE_USE_VERSION 35
55
#include <fuse_lowlevel.h>
66
#define FDB_API_VERSION 630
77
#include <foundationdb/fdb_c.h>

src/write.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define FUSE_USE_VERSION 26
1+
#define FUSE_USE_VERSION 35
22
#include <fuse_lowlevel.h>
33
#define FDB_API_VERSION 630
44
#include <foundationdb/fdb_c.h>

test.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ fdbcli --exec status
55

66
rm -rf test_a test_b
77
mkdir -p test_a test_b
8-
MP=`stat -c %m test_a`
8+
MP=`stat -c %m .`
99
build/fs test_a &
1010
build/fs test_b &
11-
# wait for the mounts to work
12-
while [ $MP = `stat -c %m test_a` ] ; do sleep 1 ; done
13-
while [ $MP = `stat -c %m test_b` ] ; do sleep 1 ; done
11+
12+
sleep 5
1413

1514
df -h
1615

0 commit comments

Comments
 (0)