aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-15 16:09:16 -0700
committerGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-15 16:49:23 -0700
commitd49f2e77b4741706ec125cc62ea913ed5d39bd39 (patch)
treeecdb3d8c7aad836d43844333b87139a105bf1171 /lib
parent587df370419e641ed47489f08069ad5f4ca4fe5f (diff)
Unify handling of fuse_conn_info options
Instead of using command line options to modify struct fuse_conn_info before and after calling the init() handler, we now give the file system explicit control over this.
Diffstat (limited to 'lib')
-rw-r--r--lib/fuse.c1
-rw-r--r--lib/fuse_i.h23
-rw-r--r--lib/fuse_lowlevel.c99
-rw-r--r--lib/helper.c127
4 files changed, 127 insertions, 123 deletions
diff --git a/lib/fuse.c b/lib/fuse.c
index fb15b04..ff46f78 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -4661,7 +4661,6 @@ struct fuse *fuse_new(struct fuse_args *args,
if (f->conf.show_help) {
fuse_lib_help();
- fuse_lowlevel_help();
fuse_mount_help();
/* Defer printing module help until modules
have been loaded */
diff --git a/lib/fuse_i.h b/lib/fuse_i.h
index 5ed23c7..e612b3f 100644
--- a/lib/fuse_i.h
+++ b/lib/fuse_i.h
@@ -41,34 +41,11 @@ struct fuse_notify_req {
struct fuse_notify_req *prev;
};
-struct session_opts {
- int atomic_o_trunc;
- int no_remote_posix_lock;
- int no_remote_flock;
- int splice_write;
- int splice_move;
- int splice_read;
- int no_splice_write;
- int no_splice_move;
- int no_splice_read;
- int auto_inval_data;
- int no_auto_inval_data;
- int no_readdirplus;
- int no_readdirplus_auto;
- int async_dio;
- int no_async_dio;
- int writeback_cache;
- int no_writeback_cache;
- int async_read;
- int sync_read;
-};
-
struct fuse_session {
char *mountpoint;
volatile int exited;
int fd;
struct mount_opts *mo;
- struct session_opts opts;
int debug;
int allow_root;
struct fuse_lowlevel_ops op;
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index a96f3a5..736cec6 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -1809,42 +1809,6 @@ static void do_fallocate(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
fuse_reply_err(req, ENOSYS);
}
-static void apply_want_options(struct session_opts *opts,
- struct fuse_conn_info *conn)
-{
-#define LL_ENABLE(cond,cap) \
- if (cond) conn->want |= (cap)
-#define LL_DISABLE(cond,cap) \
- if (cond) conn->want &= ~(cap)
-
- LL_ENABLE(opts->splice_read, FUSE_CAP_SPLICE_READ);
- LL_DISABLE(opts->no_splice_read, FUSE_CAP_SPLICE_READ);
-
- LL_ENABLE(opts->splice_write, FUSE_CAP_SPLICE_WRITE);
- LL_DISABLE(opts->no_splice_write, FUSE_CAP_SPLICE_WRITE);
-
- LL_ENABLE(opts->splice_move, FUSE_CAP_SPLICE_MOVE);
- LL_DISABLE(opts->no_splice_move, FUSE_CAP_SPLICE_MOVE);
-
- LL_ENABLE(opts->auto_inval_data, FUSE_CAP_AUTO_INVAL_DATA);
- LL_DISABLE(opts->no_auto_inval_data, FUSE_CAP_AUTO_INVAL_DATA);
-
- LL_DISABLE(opts->no_readdirplus, FUSE_CAP_READDIRPLUS);
- LL_DISABLE(opts->no_readdirplus_auto, FUSE_CAP_READDIRPLUS_AUTO);
-
- LL_ENABLE(opts->async_dio, FUSE_CAP_ASYNC_DIO);
- LL_DISABLE(opts->no_async_dio, FUSE_CAP_ASYNC_DIO);
-
- LL_ENABLE(opts->writeback_cache, FUSE_CAP_WRITEBACK_CACHE);
- LL_DISABLE(opts->no_writeback_cache, FUSE_CAP_WRITEBACK_CACHE);
-
- LL_ENABLE(opts->async_read, FUSE_CAP_ASYNC_READ);
- LL_DISABLE(opts->sync_read, FUSE_CAP_ASYNC_READ);
-
- LL_DISABLE(opts->no_remote_posix_lock, FUSE_CAP_POSIX_LOCKS);
- LL_DISABLE(opts->no_remote_flock, FUSE_CAP_FLOCK_LOCKS);
-}
-
static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
{
struct fuse_init_in *arg = (struct fuse_init_in *) inarg;
@@ -1949,19 +1913,9 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
f->conn.max_write = bufsize;
f->got_init = 1;
-
- /* Apply command-line options (so that init() handler has
- an idea about user preferences */
- apply_want_options(&f->opts, &f->conn);
-
- /* Allow file-system to overwrite defaults */
if (f->op.init)
f->op.init(f->userdata, &f->conn);
- /* Now explicitly overwrite file-system's decision
- with command-line options */
- apply_want_options(&f->opts, &f->conn);
-
/* Always enable big writes, this is superseded
by the max_write option */
outarg.flags |= FUSE_BIG_WRITES;
@@ -2570,35 +2524,6 @@ static const struct fuse_opt fuse_ll_opts[] = {
LL_OPTION("debug", debug, 1),
LL_OPTION("-d", debug, 1),
LL_OPTION("allow_root", allow_root, 1),
- LL_OPTION("max_write=%u", conn.max_write, 0),
- LL_OPTION("max_readahead=%u", conn.max_readahead, 0),
- LL_OPTION("max_background=%u", conn.max_background, 0),
- LL_OPTION("congestion_threshold=%u", conn.congestion_threshold, 0),
- LL_OPTION("sync_read", opts.sync_read, 1),
- LL_OPTION("async_read", opts.async_read, 1),
- LL_OPTION("atomic_o_trunc", opts.atomic_o_trunc, 1),
- LL_OPTION("no_remote_lock", opts.no_remote_posix_lock, 1),
- LL_OPTION("no_remote_lock", opts.no_remote_flock, 1),
- LL_OPTION("no_remote_flock", opts.no_remote_flock, 1),
- LL_OPTION("no_remote_posix_lock", opts.no_remote_posix_lock, 1),
- LL_OPTION("splice_write", opts.splice_write, 1),
- LL_OPTION("no_splice_write", opts.no_splice_write, 1),
- LL_OPTION("splice_move", opts.splice_move, 1),
- LL_OPTION("no_splice_move", opts.no_splice_move, 1),
- LL_OPTION("splice_read", opts.splice_read, 1),
- LL_OPTION("no_splice_read", opts.no_splice_read, 1),
- LL_OPTION("auto_inval_data", opts.auto_inval_data, 1),
- LL_OPTION("no_auto_inval_data", opts.no_auto_inval_data, 1),
- LL_OPTION("readdirplus=no", opts.no_readdirplus, 1),
- LL_OPTION("readdirplus=yes", opts.no_readdirplus, 0),
- LL_OPTION("readdirplus=yes", opts.no_readdirplus_auto, 1),
- LL_OPTION("readdirplus=auto", opts.no_readdirplus, 0),
- LL_OPTION("readdirplus=auto", opts.no_readdirplus_auto, 0),
- LL_OPTION("async_dio", opts.async_dio, 1),
- LL_OPTION("no_async_dio", opts.no_async_dio, 1),
- LL_OPTION("writeback_cache", opts.writeback_cache, 1),
- LL_OPTION("no_writeback_cache", opts.no_writeback_cache, 1),
- LL_OPTION("time_gran=%u", conn.time_gran, 0),
FUSE_OPT_END
};
@@ -2608,30 +2533,6 @@ void fuse_lowlevel_version(void)
FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
}
-void fuse_lowlevel_help(void)
-{
- printf(
-"Low-level options\n"
-" -o max_write=N set maximum size of write requests\n"
-" -o max_readahead=N set maximum readahead\n"
-" -o max_background=N set number of maximum background requests\n"
-" -o congestion_threshold=N set kernel's congestion threshold\n"
-" -o async_read perform reads asynchronously (default)\n"
-" -o sync_read perform reads synchronously\n"
-" -o atomic_o_trunc enable atomic open+truncate support\n"
-" -o no_remote_lock disable remote file locking\n"
-" -o no_remote_flock disable remote file locking (BSD)\n"
-" -o no_remote_posix_lock disable remote file locking (POSIX)\n"
-" -o [no_]splice_write use splice to write to the fuse device\n"
-" -o [no_]splice_move move data while splicing to the fuse device\n"
-" -o [no_]splice_read use splice to read from the fuse device\n"
-" -o [no_]auto_inval_data use automatic kernel cache invalidation logic\n"
-" -o readdirplus=S control readdirplus use (yes|no|auto)\n"
-" -o [no_]async_dio asynchronous direct I/O\n"
-" -o [no_]writeback_cache asynchronous, buffered writes\n"
-" -o time_gran=N time granularity in nsec\n\n");
-}
-
void fuse_session_destroy(struct fuse_session *se)
{
struct fuse_ll_pipe *llp;
diff --git a/lib/helper.c b/lib/helper.c
index ea06d81..6044bb3 100644
--- a/lib/helper.c
+++ b/lib/helper.c
@@ -49,6 +49,69 @@ static const struct fuse_opt fuse_helper_opts[] = {
FUSE_OPT_END
};
+struct fuse_conn_info_opts {
+ int atomic_o_trunc;
+ int no_remote_posix_lock;
+ int no_remote_flock;
+ int splice_write;
+ int splice_move;
+ int splice_read;
+ int no_splice_write;
+ int no_splice_move;
+ int no_splice_read;
+ int auto_inval_data;
+ int no_auto_inval_data;
+ int no_readdirplus;
+ int no_readdirplus_auto;
+ int async_dio;
+ int no_async_dio;
+ int writeback_cache;
+ int no_writeback_cache;
+ int async_read;
+ int sync_read;
+ unsigned max_write;
+ unsigned max_readahead;
+ unsigned max_background;
+ unsigned congestion_threshold;
+ unsigned time_gran;
+};
+
+#define CONN_OPTION(t, p, v) \
+ { t, offsetof(struct fuse_conn_info_opts, p), v }
+static const struct fuse_opt conn_info_opt_spec[] = {
+ CONN_OPTION("max_write=%u", max_write, 0),
+ CONN_OPTION("max_readahead=%u", max_readahead, 0),
+ CONN_OPTION("max_background=%u", max_background, 0),
+ CONN_OPTION("congestion_threshold=%u", congestion_threshold, 0),
+ CONN_OPTION("sync_read", sync_read, 1),
+ CONN_OPTION("async_read", async_read, 1),
+ CONN_OPTION("atomic_o_trunc", atomic_o_trunc, 1),
+ CONN_OPTION("no_remote_lock", no_remote_posix_lock, 1),
+ CONN_OPTION("no_remote_lock", no_remote_flock, 1),
+ CONN_OPTION("no_remote_flock", no_remote_flock, 1),
+ CONN_OPTION("no_remote_posix_lock", no_remote_posix_lock, 1),
+ CONN_OPTION("splice_write", splice_write, 1),
+ CONN_OPTION("no_splice_write", no_splice_write, 1),
+ CONN_OPTION("splice_move", splice_move, 1),
+ CONN_OPTION("no_splice_move", no_splice_move, 1),
+ CONN_OPTION("splice_read", splice_read, 1),
+ CONN_OPTION("no_splice_read", no_splice_read, 1),
+ CONN_OPTION("auto_inval_data", auto_inval_data, 1),
+ CONN_OPTION("no_auto_inval_data", no_auto_inval_data, 1),
+ CONN_OPTION("readdirplus=no", no_readdirplus, 1),
+ CONN_OPTION("readdirplus=yes", no_readdirplus, 0),
+ CONN_OPTION("readdirplus=yes", no_readdirplus_auto, 1),
+ CONN_OPTION("readdirplus=auto", no_readdirplus, 0),
+ CONN_OPTION("readdirplus=auto", no_readdirplus_auto, 0),
+ CONN_OPTION("async_dio", async_dio, 1),
+ CONN_OPTION("no_async_dio", no_async_dio, 1),
+ CONN_OPTION("writeback_cache", writeback_cache, 1),
+ CONN_OPTION("no_writeback_cache", no_writeback_cache, 1),
+ CONN_OPTION("time_gran=%u", time_gran, 0),
+ FUSE_OPT_END
+};
+
+
void fuse_cmdline_help(void)
{
printf("General options:\n"
@@ -262,3 +325,67 @@ out1:
fuse_opt_free_args(&args);
return res;
}
+
+
+void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts,
+ struct fuse_conn_info *conn)
+{
+ if(opts->max_write)
+ conn->max_write = opts->max_write;
+ if(opts->max_background)
+ conn->max_background = opts->max_background;
+ if(opts->congestion_threshold)
+ conn->congestion_threshold = opts->congestion_threshold;
+ if(opts->time_gran)
+ conn->time_gran = opts->time_gran;
+ if(opts->max_readahead)
+ conn->max_readahead = opts->max_readahead;
+
+#define LL_ENABLE(cond,cap) \
+ if (cond) conn->want |= (cap)
+#define LL_DISABLE(cond,cap) \
+ if (cond) conn->want &= ~(cap)
+
+ LL_ENABLE(opts->splice_read, FUSE_CAP_SPLICE_READ);
+ LL_DISABLE(opts->no_splice_read, FUSE_CAP_SPLICE_READ);
+
+ LL_ENABLE(opts->splice_write, FUSE_CAP_SPLICE_WRITE);
+ LL_DISABLE(opts->no_splice_write, FUSE_CAP_SPLICE_WRITE);
+
+ LL_ENABLE(opts->splice_move, FUSE_CAP_SPLICE_MOVE);
+ LL_DISABLE(opts->no_splice_move, FUSE_CAP_SPLICE_MOVE);
+
+ LL_ENABLE(opts->auto_inval_data, FUSE_CAP_AUTO_INVAL_DATA);
+ LL_DISABLE(opts->no_auto_inval_data, FUSE_CAP_AUTO_INVAL_DATA);
+
+ LL_DISABLE(opts->no_readdirplus, FUSE_CAP_READDIRPLUS);
+ LL_DISABLE(opts->no_readdirplus_auto, FUSE_CAP_READDIRPLUS_AUTO);
+
+ LL_ENABLE(opts->async_dio, FUSE_CAP_ASYNC_DIO);
+ LL_DISABLE(opts->no_async_dio, FUSE_CAP_ASYNC_DIO);
+
+ LL_ENABLE(opts->writeback_cache, FUSE_CAP_WRITEBACK_CACHE);
+ LL_DISABLE(opts->no_writeback_cache, FUSE_CAP_WRITEBACK_CACHE);
+
+ LL_ENABLE(opts->async_read, FUSE_CAP_ASYNC_READ);
+ LL_DISABLE(opts->sync_read, FUSE_CAP_ASYNC_READ);
+
+ LL_DISABLE(opts->no_remote_posix_lock, FUSE_CAP_POSIX_LOCKS);
+ LL_DISABLE(opts->no_remote_flock, FUSE_CAP_FLOCK_LOCKS);
+}
+
+struct fuse_conn_info_opts* fuse_parse_conn_info_opts(struct fuse_args *args)
+{
+ struct fuse_conn_info_opts *opts;
+
+ opts = calloc(1, sizeof(struct fuse_conn_info_opts));
+ if(opts == NULL) {
+ fprintf(stderr, "calloc failed\n");
+ return NULL;
+ }
+ if(fuse_opt_parse(args, opts, conn_info_opt_spec, NULL) == -1) {
+ free(opts);
+ return NULL;
+ }
+ return opts;
+}