2006-06-25 12:48:51 +00:00
|
|
|
/*
|
|
|
|
FUSE: Filesystem in Userspace
|
2008-11-26 11:03:54 +00:00
|
|
|
Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
|
2006-06-25 12:48:51 +00:00
|
|
|
|
|
|
|
This program can be distributed under the terms of the GNU GPL.
|
|
|
|
See the file COPYING.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fuse_i.h"
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
2019-03-27 23:44:19 +00:00
|
|
|
#include <linux/fs_context.h>
|
2006-06-25 12:48:51 +00:00
|
|
|
|
|
|
|
#define FUSE_CTL_SUPER_MAGIC 0x65735543
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is non-NULL when the single instance of the control filesystem
|
|
|
|
* exists. Protected by fuse_mutex
|
|
|
|
*/
|
|
|
|
static struct super_block *fuse_control_sb;
|
|
|
|
|
|
|
|
static struct fuse_conn *fuse_ctl_file_conn_get(struct file *file)
|
|
|
|
{
|
|
|
|
struct fuse_conn *fc;
|
|
|
|
mutex_lock(&fuse_mutex);
|
2013-01-23 22:07:38 +00:00
|
|
|
fc = file_inode(file)->i_private;
|
2006-06-25 12:48:51 +00:00
|
|
|
if (fc)
|
|
|
|
fc = fuse_conn_get(fc);
|
|
|
|
mutex_unlock(&fuse_mutex);
|
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
|
|
|
|
if (fc) {
|
2019-01-24 09:40:16 +00:00
|
|
|
if (fc->abort_err)
|
|
|
|
fc->aborted = true;
|
|
|
|
fuse_abort_conn(fc);
|
2006-06-25 12:48:51 +00:00
|
|
|
fuse_conn_put(fc);
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf,
|
|
|
|
size_t len, loff_t *ppos)
|
|
|
|
{
|
|
|
|
char tmp[32];
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if (!*ppos) {
|
2008-11-26 11:03:54 +00:00
|
|
|
long value;
|
2006-06-25 12:48:51 +00:00
|
|
|
struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
|
|
|
|
if (!fc)
|
|
|
|
return 0;
|
|
|
|
|
2008-11-26 11:03:54 +00:00
|
|
|
value = atomic_read(&fc->num_waiting);
|
|
|
|
file->private_data = (void *)value;
|
2006-06-25 12:48:51 +00:00
|
|
|
fuse_conn_put(fc);
|
|
|
|
}
|
|
|
|
size = sprintf(tmp, "%ld\n", (long)file->private_data);
|
|
|
|
return simple_read_from_buffer(buf, len, ppos, tmp, size);
|
|
|
|
}
|
|
|
|
|
2009-08-26 17:18:24 +00:00
|
|
|
static ssize_t fuse_conn_limit_read(struct file *file, char __user *buf,
|
|
|
|
size_t len, loff_t *ppos, unsigned val)
|
|
|
|
{
|
|
|
|
char tmp[32];
|
|
|
|
size_t size = sprintf(tmp, "%u\n", val);
|
|
|
|
|
|
|
|
return simple_read_from_buffer(buf, len, ppos, tmp, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t fuse_conn_limit_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos, unsigned *val,
|
|
|
|
unsigned global_limit)
|
|
|
|
{
|
|
|
|
unsigned long t;
|
|
|
|
unsigned limit = (1 << 16) - 1;
|
|
|
|
int err;
|
|
|
|
|
2012-04-15 00:20:27 +00:00
|
|
|
if (*ppos)
|
2009-08-26 17:18:24 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2012-04-15 00:20:27 +00:00
|
|
|
err = kstrtoul_from_user(buf, count, 0, &t);
|
2009-08-26 17:18:24 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
|
|
limit = min(limit, global_limit);
|
|
|
|
|
|
|
|
if (t > limit)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*val = t;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t fuse_conn_max_background_read(struct file *file,
|
|
|
|
char __user *buf, size_t len,
|
|
|
|
loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct fuse_conn *fc;
|
|
|
|
unsigned val;
|
|
|
|
|
|
|
|
fc = fuse_ctl_file_conn_get(file);
|
|
|
|
if (!fc)
|
|
|
|
return 0;
|
|
|
|
|
2018-08-27 15:29:29 +00:00
|
|
|
val = READ_ONCE(fc->max_background);
|
2009-08-26 17:18:24 +00:00
|
|
|
fuse_conn_put(fc);
|
|
|
|
|
|
|
|
return fuse_conn_limit_read(file, buf, len, ppos, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t fuse_conn_max_background_write(struct file *file,
|
|
|
|
const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
treewide: Remove uninitialized_var() usage
Using uninitialized_var() is dangerous as it papers over real bugs[1]
(or can in the future), and suppresses unrelated compiler warnings
(e.g. "unused variable"). If the compiler thinks it is uninitialized,
either simply initialize the variable or make compiler changes.
In preparation for removing[2] the[3] macro[4], remove all remaining
needless uses with the following script:
git grep '\buninitialized_var\b' | cut -d: -f1 | sort -u | \
xargs perl -pi -e \
's/\buninitialized_var\(([^\)]+)\)/\1/g;
s:\s*/\* (GCC be quiet|to make compiler happy) \*/$::g;'
drivers/video/fbdev/riva/riva_hw.c was manually tweaked to avoid
pathological white-space.
No outstanding warnings were found building allmodconfig with GCC 9.3.0
for x86_64, i386, arm64, arm, powerpc, powerpc64le, s390x, mips, sparc64,
alpha, and m68k.
[1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/
[2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/
[3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/
[4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/
Reviewed-by: Leon Romanovsky <leonro@mellanox.com> # drivers/infiniband and mlx4/mlx5
Acked-by: Jason Gunthorpe <jgg@mellanox.com> # IB
Acked-by: Kalle Valo <kvalo@codeaurora.org> # wireless drivers
Reviewed-by: Chao Yu <yuchao0@huawei.com> # erofs
Signed-off-by: Kees Cook <keescook@chromium.org>
2020-06-03 20:09:38 +00:00
|
|
|
unsigned val;
|
2009-08-26 17:18:24 +00:00
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
|
|
|
|
max_user_bgreq);
|
|
|
|
if (ret > 0) {
|
|
|
|
struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
|
|
|
|
if (fc) {
|
2018-08-27 15:29:46 +00:00
|
|
|
spin_lock(&fc->bg_lock);
|
2009-08-26 17:18:24 +00:00
|
|
|
fc->max_background = val;
|
2018-08-27 15:29:37 +00:00
|
|
|
fc->blocked = fc->num_background >= fc->max_background;
|
|
|
|
if (!fc->blocked)
|
|
|
|
wake_up(&fc->blocked_waitq);
|
2018-08-27 15:29:46 +00:00
|
|
|
spin_unlock(&fc->bg_lock);
|
2009-08-26 17:18:24 +00:00
|
|
|
fuse_conn_put(fc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t fuse_conn_congestion_threshold_read(struct file *file,
|
|
|
|
char __user *buf, size_t len,
|
|
|
|
loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct fuse_conn *fc;
|
|
|
|
unsigned val;
|
|
|
|
|
|
|
|
fc = fuse_ctl_file_conn_get(file);
|
|
|
|
if (!fc)
|
|
|
|
return 0;
|
|
|
|
|
2018-08-27 15:29:29 +00:00
|
|
|
val = READ_ONCE(fc->congestion_threshold);
|
2009-08-26 17:18:24 +00:00
|
|
|
fuse_conn_put(fc);
|
|
|
|
|
|
|
|
return fuse_conn_limit_read(file, buf, len, ppos, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
|
|
|
|
const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
treewide: Remove uninitialized_var() usage
Using uninitialized_var() is dangerous as it papers over real bugs[1]
(or can in the future), and suppresses unrelated compiler warnings
(e.g. "unused variable"). If the compiler thinks it is uninitialized,
either simply initialize the variable or make compiler changes.
In preparation for removing[2] the[3] macro[4], remove all remaining
needless uses with the following script:
git grep '\buninitialized_var\b' | cut -d: -f1 | sort -u | \
xargs perl -pi -e \
's/\buninitialized_var\(([^\)]+)\)/\1/g;
s:\s*/\* (GCC be quiet|to make compiler happy) \*/$::g;'
drivers/video/fbdev/riva/riva_hw.c was manually tweaked to avoid
pathological white-space.
No outstanding warnings were found building allmodconfig with GCC 9.3.0
for x86_64, i386, arm64, arm, powerpc, powerpc64le, s390x, mips, sparc64,
alpha, and m68k.
[1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/
[2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/
[3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/
[4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/
Reviewed-by: Leon Romanovsky <leonro@mellanox.com> # drivers/infiniband and mlx4/mlx5
Acked-by: Jason Gunthorpe <jgg@mellanox.com> # IB
Acked-by: Kalle Valo <kvalo@codeaurora.org> # wireless drivers
Reviewed-by: Chao Yu <yuchao0@huawei.com> # erofs
Signed-off-by: Kees Cook <keescook@chromium.org>
2020-06-03 20:09:38 +00:00
|
|
|
unsigned val;
|
2018-08-27 15:29:37 +00:00
|
|
|
struct fuse_conn *fc;
|
2009-08-26 17:18:24 +00:00
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
|
|
|
|
max_user_congthresh);
|
2018-08-27 15:29:37 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
goto out;
|
|
|
|
fc = fuse_ctl_file_conn_get(file);
|
|
|
|
if (!fc)
|
|
|
|
goto out;
|
|
|
|
|
2020-05-06 15:44:12 +00:00
|
|
|
down_read(&fc->killsb);
|
2018-08-27 15:29:46 +00:00
|
|
|
spin_lock(&fc->bg_lock);
|
2018-08-27 15:29:37 +00:00
|
|
|
fc->congestion_threshold = val;
|
2018-08-27 15:29:46 +00:00
|
|
|
spin_unlock(&fc->bg_lock);
|
2020-05-06 15:44:12 +00:00
|
|
|
up_read(&fc->killsb);
|
2018-08-27 15:29:37 +00:00
|
|
|
fuse_conn_put(fc);
|
|
|
|
out:
|
2009-08-26 17:18:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-06-25 12:48:51 +00:00
|
|
|
static const struct file_operations fuse_ctl_abort_ops = {
|
|
|
|
.open = nonseekable_open,
|
|
|
|
.write = fuse_conn_abort_write,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 16:52:59 +00:00
|
|
|
.llseek = no_llseek,
|
2006-06-25 12:48:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_operations fuse_ctl_waiting_ops = {
|
|
|
|
.open = nonseekable_open,
|
|
|
|
.read = fuse_conn_waiting_read,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 16:52:59 +00:00
|
|
|
.llseek = no_llseek,
|
2006-06-25 12:48:51 +00:00
|
|
|
};
|
|
|
|
|
2009-08-26 17:18:24 +00:00
|
|
|
static const struct file_operations fuse_conn_max_background_ops = {
|
|
|
|
.open = nonseekable_open,
|
|
|
|
.read = fuse_conn_max_background_read,
|
|
|
|
.write = fuse_conn_max_background_write,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 16:52:59 +00:00
|
|
|
.llseek = no_llseek,
|
2009-08-26 17:18:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_operations fuse_conn_congestion_threshold_ops = {
|
|
|
|
.open = nonseekable_open,
|
|
|
|
.read = fuse_conn_congestion_threshold_read,
|
|
|
|
.write = fuse_conn_congestion_threshold_write,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 16:52:59 +00:00
|
|
|
.llseek = no_llseek,
|
2009-08-26 17:18:24 +00:00
|
|
|
};
|
|
|
|
|
2006-06-25 12:48:51 +00:00
|
|
|
static struct dentry *fuse_ctl_add_dentry(struct dentry *parent,
|
|
|
|
struct fuse_conn *fc,
|
|
|
|
const char *name,
|
|
|
|
int mode, int nlink,
|
2007-02-12 08:55:38 +00:00
|
|
|
const struct inode_operations *iop,
|
2006-06-25 12:48:51 +00:00
|
|
|
const struct file_operations *fop)
|
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
BUG_ON(fc->ctl_ndents >= FUSE_CTL_NUM_DENTRIES);
|
|
|
|
dentry = d_alloc_name(parent, name);
|
|
|
|
if (!dentry)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
inode = new_inode(fuse_control_sb);
|
2018-05-31 10:26:10 +00:00
|
|
|
if (!inode) {
|
|
|
|
dput(dentry);
|
2006-06-25 12:48:51 +00:00
|
|
|
return NULL;
|
2018-05-31 10:26:10 +00:00
|
|
|
}
|
2006-06-25 12:48:51 +00:00
|
|
|
|
2010-10-23 15:19:54 +00:00
|
|
|
inode->i_ino = get_next_ino();
|
2006-06-25 12:48:51 +00:00
|
|
|
inode->i_mode = mode;
|
|
|
|
inode->i_uid = fc->user_id;
|
|
|
|
inode->i_gid = fc->group_id;
|
2016-09-14 14:48:04 +00:00
|
|
|
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
|
2006-06-25 12:48:51 +00:00
|
|
|
/* setting ->i_op to NULL is not allowed */
|
|
|
|
if (iop)
|
|
|
|
inode->i_op = iop;
|
|
|
|
inode->i_fop = fop;
|
2011-10-28 12:13:29 +00:00
|
|
|
set_nlink(inode, nlink);
|
2006-09-27 08:50:46 +00:00
|
|
|
inode->i_private = fc;
|
2006-06-25 12:48:51 +00:00
|
|
|
d_add(dentry, inode);
|
2018-05-31 10:26:10 +00:00
|
|
|
|
|
|
|
fc->ctl_dentry[fc->ctl_ndents++] = dentry;
|
|
|
|
|
2006-06-25 12:48:51 +00:00
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a connection to the control filesystem (if it exists). Caller
|
2006-07-30 10:04:10 +00:00
|
|
|
* must hold fuse_mutex
|
2006-06-25 12:48:51 +00:00
|
|
|
*/
|
|
|
|
int fuse_ctl_add_conn(struct fuse_conn *fc)
|
|
|
|
{
|
|
|
|
struct dentry *parent;
|
|
|
|
char name[32];
|
|
|
|
|
2022-07-18 08:50:12 +00:00
|
|
|
if (!fuse_control_sb || fc->no_control)
|
2006-06-25 12:48:51 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
parent = fuse_control_sb->s_root;
|
2015-03-17 22:25:59 +00:00
|
|
|
inc_nlink(d_inode(parent));
|
2008-04-30 07:54:34 +00:00
|
|
|
sprintf(name, "%u", fc->dev);
|
2006-06-25 12:48:51 +00:00
|
|
|
parent = fuse_ctl_add_dentry(parent, fc, name, S_IFDIR | 0500, 2,
|
|
|
|
&simple_dir_inode_operations,
|
|
|
|
&simple_dir_operations);
|
|
|
|
if (!parent)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (!fuse_ctl_add_dentry(parent, fc, "waiting", S_IFREG | 0400, 1,
|
2009-08-26 17:18:24 +00:00
|
|
|
NULL, &fuse_ctl_waiting_ops) ||
|
2006-06-25 12:48:51 +00:00
|
|
|
!fuse_ctl_add_dentry(parent, fc, "abort", S_IFREG | 0200, 1,
|
2009-08-26 17:18:24 +00:00
|
|
|
NULL, &fuse_ctl_abort_ops) ||
|
|
|
|
!fuse_ctl_add_dentry(parent, fc, "max_background", S_IFREG | 0600,
|
|
|
|
1, NULL, &fuse_conn_max_background_ops) ||
|
|
|
|
!fuse_ctl_add_dentry(parent, fc, "congestion_threshold",
|
|
|
|
S_IFREG | 0600, 1, NULL,
|
|
|
|
&fuse_conn_congestion_threshold_ops))
|
2006-06-25 12:48:51 +00:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
fuse_ctl_remove_conn(fc);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a connection from the control filesystem (if it exists).
|
2006-07-30 10:04:10 +00:00
|
|
|
* Caller must hold fuse_mutex
|
2006-06-25 12:48:51 +00:00
|
|
|
*/
|
|
|
|
void fuse_ctl_remove_conn(struct fuse_conn *fc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2022-07-18 08:50:12 +00:00
|
|
|
if (!fuse_control_sb || fc->no_control)
|
2006-06-25 12:48:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = fc->ctl_ndents - 1; i >= 0; i--) {
|
|
|
|
struct dentry *dentry = fc->ctl_dentry[i];
|
2015-03-17 22:25:59 +00:00
|
|
|
d_inode(dentry)->i_private = NULL;
|
2018-05-31 10:26:10 +00:00
|
|
|
if (!i) {
|
|
|
|
/* Get rid of submounts: */
|
|
|
|
d_invalidate(dentry);
|
|
|
|
}
|
2006-06-25 12:48:51 +00:00
|
|
|
dput(dentry);
|
|
|
|
}
|
2015-03-17 22:25:59 +00:00
|
|
|
drop_nlink(d_inode(fuse_control_sb->s_root));
|
2006-06-25 12:48:51 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 11:22:58 +00:00
|
|
|
static int fuse_ctl_fill_super(struct super_block *sb, struct fs_context *fsc)
|
2006-06-25 12:48:51 +00:00
|
|
|
{
|
2017-03-26 04:15:37 +00:00
|
|
|
static const struct tree_descr empty_descr = {""};
|
2006-06-25 12:48:51 +00:00
|
|
|
struct fuse_conn *fc;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = simple_fill_super(sb, FUSE_CTL_SUPER_MAGIC, &empty_descr);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
mutex_lock(&fuse_mutex);
|
|
|
|
BUG_ON(fuse_control_sb);
|
|
|
|
fuse_control_sb = sb;
|
|
|
|
list_for_each_entry(fc, &fuse_conn_list, entry) {
|
|
|
|
err = fuse_ctl_add_conn(fc);
|
|
|
|
if (err) {
|
|
|
|
fuse_control_sb = NULL;
|
|
|
|
mutex_unlock(&fuse_mutex);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&fuse_mutex);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-04 11:22:58 +00:00
|
|
|
static int fuse_ctl_get_tree(struct fs_context *fsc)
|
2006-06-25 12:48:51 +00:00
|
|
|
{
|
2021-08-04 11:22:58 +00:00
|
|
|
return get_tree_single(fsc, fuse_ctl_fill_super);
|
2019-03-27 23:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct fs_context_operations fuse_ctl_context_ops = {
|
|
|
|
.get_tree = fuse_ctl_get_tree,
|
|
|
|
};
|
|
|
|
|
2021-08-04 11:22:58 +00:00
|
|
|
static int fuse_ctl_init_fs_context(struct fs_context *fsc)
|
2019-03-27 23:44:19 +00:00
|
|
|
{
|
2021-08-04 11:22:58 +00:00
|
|
|
fsc->ops = &fuse_ctl_context_ops;
|
2019-03-27 23:44:19 +00:00
|
|
|
return 0;
|
2006-06-25 12:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fuse_ctl_kill_sb(struct super_block *sb)
|
|
|
|
{
|
2007-01-29 21:19:54 +00:00
|
|
|
struct fuse_conn *fc;
|
|
|
|
|
2006-06-25 12:48:51 +00:00
|
|
|
mutex_lock(&fuse_mutex);
|
|
|
|
fuse_control_sb = NULL;
|
2007-01-29 21:19:54 +00:00
|
|
|
list_for_each_entry(fc, &fuse_conn_list, entry)
|
|
|
|
fc->ctl_ndents = 0;
|
2006-06-25 12:48:51 +00:00
|
|
|
mutex_unlock(&fuse_mutex);
|
|
|
|
|
|
|
|
kill_litter_super(sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type fuse_ctl_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "fusectl",
|
2019-03-27 23:44:19 +00:00
|
|
|
.init_fs_context = fuse_ctl_init_fs_context,
|
2006-06-25 12:48:51 +00:00
|
|
|
.kill_sb = fuse_ctl_kill_sb,
|
|
|
|
};
|
2013-03-03 03:39:14 +00:00
|
|
|
MODULE_ALIAS_FS("fusectl");
|
2006-06-25 12:48:51 +00:00
|
|
|
|
|
|
|
int __init fuse_ctl_init(void)
|
|
|
|
{
|
|
|
|
return register_filesystem(&fuse_ctl_fs_type);
|
|
|
|
}
|
|
|
|
|
2014-04-23 16:14:42 +00:00
|
|
|
void __exit fuse_ctl_cleanup(void)
|
2006-06-25 12:48:51 +00:00
|
|
|
{
|
|
|
|
unregister_filesystem(&fuse_ctl_fs_type);
|
|
|
|
}
|