aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@redhat.com>2021-02-11 09:19:30 +0100
committerMiklos Szeredi <mszeredi@redhat.com>2021-02-15 10:38:17 +0100
commit52ca81ef9ec4652f4480fabf195d868a674b3335 (patch)
tree87bbc399c0f54c16d1274d25320bd6f10cb30313
parentedb1412af48f60527fdfa381bcd298673bd8321d (diff)
downloadfuse-fs_fuse_split.tar.gz
fuse: alloc initial fuse_conn and fuse_mountfs_fuse_split
In fuse and virtiofs these are already allocated, so move the allocation in the common initialization helper. Also change cuse so that these objects are allocated separately, as opposed to having them inline in cuse_conn. This will aid in cleaning up the exported fuse transport interface. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
-rw-r--r--drivers/char/cuse.c75
-rw-r--r--fs/fuse/dev.c1
-rw-r--r--fs/fuse/fuse_i.h449
-rw-r--r--fs/fuse/inode.c88
-rw-r--r--fs/fuse/virtio_fs.c11
-rw-r--r--include/net/fuse.h466
6 files changed, 578 insertions, 512 deletions
diff --git a/drivers/char/cuse.c b/drivers/char/cuse.c
index acccdc263c96f..99ffa3330dc31 100644
--- a/drivers/char/cuse.c
+++ b/drivers/char/cuse.c
@@ -58,8 +58,7 @@
struct cuse_conn {
struct list_head list; /* linked on cuse_conntbl */
- struct fuse_mount fm; /* Dummy mount referencing fc */
- struct fuse_conn fc; /* fuse connection */
+ struct fuse_mount *fm; /* Dummy mount referencing fc */
struct cdev *cdev; /* associated character device */
struct device *dev; /* device representing @cdev */
@@ -73,7 +72,16 @@ static struct class *cuse_class;
static struct cuse_conn *fc_to_cc(struct fuse_conn *fc)
{
- return container_of(fc, struct cuse_conn, fc);
+ return fuse_conn_private(fc);
+}
+
+static struct cuse_conn *file_to_cc(struct file *file)
+{
+ struct fuse_file *ff = file->private_data;
+ struct fuse_mount *fm = fuse_file_mount(ff);
+ struct fuse_conn *fc = fuse_mount_conn(fm);
+
+ return fc_to_cc(fc);
}
static struct list_head *cuse_conntbl_head(dev_t devt)
@@ -116,14 +124,16 @@ static int cuse_open(struct inode *inode, struct file *file)
{
dev_t devt = inode->i_cdev->dev;
struct cuse_conn *cc = NULL, *pos;
+ struct fuse_conn *fc;
int rc;
/* look up and get the connection */
mutex_lock(&cuse_lock);
list_for_each_entry(pos, cuse_conntbl_head(devt), list)
if (pos->dev->devt == devt) {
- fuse_conn_get(&pos->fc);
cc = pos;
+ fc = fuse_mount_conn(cc->fm);
+ fuse_conn_get(fc);
break;
}
mutex_unlock(&cuse_lock);
@@ -136,19 +146,19 @@ static int cuse_open(struct inode *inode, struct file *file)
* Generic permission check is already done against the chrdev
* file, proceed to open.
*/
- rc = fuse_do_open(&cc->fm, 0, file, 0);
+ rc = fuse_do_open(cc->fm, 0, file, 0);
if (rc)
- fuse_conn_put(&cc->fc);
+ fuse_conn_put(fc);
return rc;
}
static int cuse_release(struct inode *inode, struct file *file)
{
struct fuse_file *ff = file->private_data;
- struct fuse_mount *fm = ff->fm;
+ struct fuse_mount *fm = fuse_file_mount(ff);
fuse_sync_release(NULL, ff, file->f_flags);
- fuse_conn_put(fm->fc);
+ fuse_conn_put(fuse_mount_conn(fm));
return 0;
}
@@ -156,8 +166,7 @@ static int cuse_release(struct inode *inode, struct file *file)
static long cuse_file_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
- struct fuse_file *ff = file->private_data;
- struct cuse_conn *cc = fc_to_cc(ff->fm->fc);
+ struct cuse_conn *cc = file_to_cc(file);
unsigned int flags = 0;
if (cc->unrestricted_ioctl)
@@ -169,8 +178,7 @@ static long cuse_file_ioctl(struct file *file, unsigned int cmd,
static long cuse_file_compat_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
- struct fuse_file *ff = file->private_data;
- struct cuse_conn *cc = fc_to_cc(ff->fm->fc);
+ struct cuse_conn *cc = file_to_cc(file);
unsigned int flags = FUSE_IOCTL_COMPAT;
if (cc->unrestricted_ioctl)
@@ -318,7 +326,7 @@ struct cuse_init_args {
static void cuse_process_init_reply(struct fuse_mount *fm,
struct fuse_args *args, int error)
{
- struct fuse_conn *fc = fm->fc;
+ struct fuse_conn *fc = fuse_mount_conn(fm);
struct cuse_init_args *ia = container_of(args, typeof(*ia), ap.args);
struct fuse_args_pages *ap = &ia->ap;
struct cuse_conn *cc = fc_to_cc(fc), *pos;
@@ -329,13 +337,14 @@ static void cuse_process_init_reply(struct fuse_mount *fm,
struct cdev *cdev;
dev_t devt;
int rc, i;
+ unsigned int max_read, max_write;
if (error || arg->major != FUSE_KERNEL_VERSION || arg->minor < 11)
goto err;
- fc->minor = arg->minor;
- fc->max_read = max_t(unsigned, arg->max_read, 4096);
- fc->max_write = max_t(unsigned, arg->max_write, 4096);
+ max_read = max_t(unsigned, arg->max_read, 4096);
+ max_write = max_t(unsigned, arg->max_write, 4096);
+ fuse_conn_update_param(fc, max_read, max_write, arg->minor);
/* parse init reply */
cc->unrestricted_ioctl = arg->flags & CUSE_UNRESTRICTED_IOCTL;
@@ -427,7 +436,7 @@ static int cuse_send_init(struct cuse_conn *cc)
{
int rc;
struct page *page;
- struct fuse_mount *fm = &cc->fm;
+ struct fuse_mount *fm = cc->fm;
struct cuse_init_args *ia;
struct fuse_args_pages *ap;
@@ -476,6 +485,7 @@ err:
static void cuse_fc_release(struct fuse_conn *fc)
{
struct cuse_conn *cc = fc_to_cc(fc);
+ struct fuse_mount *fm = cc->fm;
/* remove from the conntbl, no more access from this point on */
mutex_lock(&cuse_lock);
@@ -490,7 +500,11 @@ static void cuse_fc_release(struct fuse_conn *fc)
cdev_del(cc->cdev);
}
- kfree_rcu(cc, fc.rcu);
+ /* Must be the only "mount" */
+ WARN_ON(!fuse_mount_remove(fm));
+ kfree(fm);
+
+ kfree(cc);
}
/**
@@ -511,6 +525,8 @@ static void cuse_fc_release(struct fuse_conn *fc)
static int cuse_channel_open(struct inode *inode, struct file *file)
{
struct fuse_dev *fud;
+ struct fuse_mount *fm;
+ struct fuse_conn *fc;
struct cuse_conn *cc;
int rc;
@@ -523,18 +539,22 @@ static int cuse_channel_open(struct inode *inode, struct file *file)
* Limit the cuse channel to requests that can
* be represented in file->f_cred->user_ns.
*/
- fuse_conn_init(&cc->fc, &cc->fm, file->f_cred->user_ns,
- &fuse_dev_fiq_ops, NULL);
-
- cc->fc.release = cuse_fc_release;
- fud = fuse_dev_alloc_install(&cc->fc);
- fuse_conn_put(&cc->fc);
+ fm = fuse_conn_new(file->f_cred->user_ns, &fuse_dev_fiq_ops, NULL,
+ cc, cuse_fc_release);
+ if (!fm) {
+ kfree(cc);
+ return -ENOMEM;
+ }
+ cc->fm = fm;
+ fc = fuse_mount_conn(fm);
+ fud = fuse_dev_alloc_install(fc);
+ fuse_conn_put(fc);
if (!fud)
return -ENOMEM;
INIT_LIST_HEAD(&cc->list);
- cc->fc.initialized = 1;
+ fuse_set_initialized(fc);
rc = cuse_send_init(cc);
if (rc) {
fuse_dev_free(fud);
@@ -558,8 +578,9 @@ static ssize_t cuse_class_waiting_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct cuse_conn *cc = dev_get_drvdata(dev);
+ struct fuse_conn *fc = fuse_mount_conn(cc->fm);
- return sprintf(buf, "%d\n", atomic_read(&cc->fc.num_waiting));
+ return sprintf(buf, "%d\n", fuse_conn_waiting(fc));
}
static DEVICE_ATTR(waiting, 0400, cuse_class_waiting_show, NULL);
@@ -569,7 +590,7 @@ static ssize_t cuse_class_abort_store(struct device *dev,
{
struct cuse_conn *cc = dev_get_drvdata(dev);
- fuse_abort_conn(&cc->fc);
+ fuse_abort_conn(fuse_mount_conn(cc->fm));
return count;
}
static DEVICE_ATTR(abort, 0200, NULL, cuse_class_abort_store);
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 4f637c5add84b..9ec61b337399b 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -81,6 +81,7 @@ void fuse_set_initialized(struct fuse_conn *fc)
smp_wmb();
fc->initialized = 1;
}
+EXPORT_SYMBOL_GPL(fuse_set_initialized);
static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background)
{
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index e8d877de6daef..2b0475532baca 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -14,7 +14,6 @@
#endif
#include <net/fuse.h>
-
#include <linux/fs.h>
#include <linux/mount.h>
#include <linux/wait.h>
@@ -42,6 +41,9 @@
/** It could be as large as PATH_MAX, but would that have any uses? */
#define FUSE_NAME_MAX 1024
+/** Number of dentries for each connection in the control filesystem */
+#define FUSE_CTL_NUM_DENTRIES 5
+
/** List of active connections */
extern struct list_head fuse_conn_list;
@@ -52,6 +54,12 @@ extern struct mutex fuse_mutex;
extern unsigned max_user_bgreq;
extern unsigned max_user_congthresh;
+/* One forget request */
+struct fuse_forget_link {
+ struct fuse_forget_one forget_one;
+ struct fuse_forget_link *next;
+};
+
/** FUSE inode */
struct fuse_inode {
/** Inode data */
@@ -165,6 +173,63 @@ enum {
FUSE_I_BAD,
};
+struct fuse_release_args;
+
+/** FUSE specific file data */
+struct fuse_file {
+ /** Fuse connection for this file */
+ struct fuse_mount *fm;
+
+ /* Argument space reserved for release */
+ struct fuse_release_args *release_args;
+
+ /** Kernel file handle guaranteed to be unique */
+ u64 kh;
+
+ /** File handle used by userspace */
+ u64 fh;
+
+ /** Node id of this file */
+ u64 nodeid;
+
+ /** Refcount */
+ refcount_t count;
+
+ /** FOPEN_* flags returned by open */
+ u32 open_flags;
+
+ /** Entry on inode's write_files list */
+ struct list_head write_entry;
+
+ /* Readdir related */
+ struct {
+ /*
+ * Protects below fields against (crazy) parallel readdir on
+ * same open file. Uncontended in the normal case.
+ */
+ struct mutex lock;
+
+ /* Dir stream position */
+ loff_t pos;
+
+ /* Offset in cache */
+ loff_t cache_off;
+
+ /* Version of cache we are reading */
+ u64 version;
+
+ } readdir;
+
+ /** RB node to be linked on fuse_conn->polled_files */
+ struct rb_node polled_node;
+
+ /** Wait queue head for poll */
+ wait_queue_head_t poll_wait;
+
+ /** Has flock been performed on this file? */
+ bool flock:1;
+};
+
/**
* Request flags
*
@@ -277,9 +342,73 @@ struct fuse_iqueue_ops {
void (*release)(struct fuse_iqueue *fiq);
};
+struct fuse_iqueue {
+ /** Connection established */
+ unsigned connected;
+
+ /** Lock protecting accesses to members of this structure */
+ spinlock_t lock;
+
+ /** Readers of the connection are waiting on this */
+ wait_queue_head_t waitq;
+
+ /** The next unique request id */
+ u64 reqctr;
+
+ /** The list of pending requests */
+ struct list_head pending;
+
+ /** Pending interrupts */
+ struct list_head interrupts;
+
+ /** Queue of pending forgets */
+ struct fuse_forget_link forget_list_head;
+ struct fuse_forget_link *forget_list_tail;
+
+ /** Batching of FORGET requests (positive indicates FORGET batch) */
+ int forget_batch;
+
+ /** O_ASYNC requests */
+ struct fasync_struct *fasync;
+
+ /** Device-specific callbacks */
+ const struct fuse_iqueue_ops *ops;
+
+ /** Device-specific state */
+ void *priv;
+};
+
#define FUSE_PQ_HASH_BITS 8
#define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
+struct fuse_pqueue {
+ /** Connection established */
+ unsigned connected;
+
+ /** Lock protecting accessess to members of this structure */
+ spinlock_t lock;
+
+ /** Hash table of requests being processed */
+ struct list_head *processing;
+
+ /** The list of requests under I/O */
+ struct list_head io;
+};
+
+/**
+ * Fuse device instance
+ */
+struct fuse_dev {
+ /** Fuse connection for this device */
+ struct fuse_conn *fc;
+
+ /** Processing queue */
+ struct fuse_pqueue pq;
+
+ /** list entry on fc->devices */
+ struct list_head entry;
+};
+
struct fuse_fs_context {
int fd;
unsigned int rootmode;
@@ -308,6 +437,314 @@ struct fuse_fs_context {
void **fudptr;
};
+/**
+ * A Fuse connection.
+ *
+ * This structure is created, when the root filesystem is mounted, and
+ * is destroyed, when the client device is closed and the last
+ * fuse_mount is destroyed.
+ */
+struct fuse_conn {
+ /** Lock protecting accessess to members of this structure */
+ spinlock_t lock;
+
+ /** Refcount */
+ refcount_t count;
+
+ /** Number of fuse_dev's */
+ atomic_t dev_count;
+
+ struct rcu_head rcu;
+
+ /** The user id for this mount */
+ kuid_t user_id;
+
+ /** The group id for this mount */
+ kgid_t group_id;
+
+ /** The pid namespace for this mount */
+ struct pid_namespace *pid_ns;
+
+ /** The user namespace for this mount */
+ struct user_namespace *user_ns;
+
+ /** Maximum read size */
+ unsigned max_read;
+
+ /** Maximum write size */
+ unsigned max_write;
+
+ /** Maxmum number of pages that can be used in a single request */
+ unsigned int max_pages;
+
+ /** Input queue */
+ struct fuse_iqueue iq;
+
+ /** The next unique kernel file handle */
+ atomic64_t khctr;
+
+ /** rbtree of fuse_files waiting for poll events indexed by ph */
+ struct rb_root polled_files;
+
+ /** Maximum number of outstanding background requests */
+ unsigned max_background;
+
+ /** Number of background requests at which congestion starts */
+ unsigned congestion_threshold;
+
+ /** Number of requests currently in the background */
+ unsigned num_background;
+
+ /** Number of background requests currently queued for userspace */
+ unsigned active_background;
+
+ /** The list of background requests set aside for later queuing */
+ struct list_head bg_queue;
+
+ /** Protects: max_background, congestion_threshold, num_background,
+ * active_background, bg_queue, blocked */
+ spinlock_t bg_lock;
+
+ /** Flag indicating that INIT reply has been received. Allocating
+ * any fuse request will be suspended until the flag is set */
+ int initialized;
+
+ /** Flag indicating if connection is blocked. This will be
+ the case before the INIT reply is received, and if there
+ are too many outstading backgrounds requests */
+ int blocked;
+
+ /** waitq for blocked connection */
+ wait_queue_head_t blocked_waitq;
+
+ /** Connection established, cleared on umount, connection
+ abort and device release */
+ unsigned connected;
+
+ /** Connection aborted via sysfs */
+ bool aborted;
+
+ /** Connection failed (version mismatch). Cannot race with
+ setting other bitfields since it is only set once in INIT
+ reply, before any other request, and never cleared */
+ unsigned conn_error:1;
+
+ /** Connection successful. Only set in INIT */
+ unsigned conn_init:1;
+
+ /** Do readpages asynchronously? Only set in INIT */
+ unsigned async_read:1;
+
+ /** Return an unique read error after abort. Only set in INIT */
+ unsigned abort_err:1;
+
+ /** Do not send separate SETATTR request before open(O_TRUNC) */
+ unsigned atomic_o_trunc:1;
+
+ /** Filesystem supports NFS exporting. Only set in INIT */
+ unsigned export_support:1;
+
+ /** write-back cache policy (default is write-through) */
+ unsigned writeback_cache:1;
+
+ /** allow parallel lookups and readdir (default is serialized) */
+ unsigned parallel_dirops:1;
+
+ /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
+ unsigned handle_killpriv:1;
+
+ /** cache READLINK responses in page cache */
+ unsigned cache_symlinks:1;
+
+ /* show legacy mount options */
+ unsigned int legacy_opts_show:1;
+
+ /*
+ * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on
+ * write/trunc only if caller did not have CAP_FSETID. sgid is killed
+ * on write/truncate only if caller did not have CAP_FSETID as well as
+ * file has group execute permission.
+ */
+ unsigned handle_killpriv_v2:1;
+
+ /*
+ * The following bitfields are only for optimization purposes
+ * and hence races in setting them will not cause malfunction
+ */
+
+ /** Is open/release not implemented by fs? */
+ unsigned no_open:1;
+
+ /** Is opendir/releasedir not implemented by fs? */
+ unsigned no_opendir:1;
+
+ /** Is fsync not implemented by fs? */
+ unsigned no_fsync:1;
+
+ /** Is fsyncdir not implemented by fs? */
+ unsigned no_fsyncdir:1;
+
+ /** Is flush not implemented by fs? */
+ unsigned no_flush:1;
+
+ /** Is setxattr not implemented by fs? */
+ unsigned no_setxattr:1;
+
+ /** Is getxattr not implemented by fs? */
+ unsigned no_getxattr:1;
+
+ /** Is listxattr not implemented by fs? */
+ unsigned no_listxattr:1;
+
+ /** Is removexattr not implemented by fs? */
+ unsigned no_removexattr:1;
+
+ /** Are posix file locking primitives not implemented by fs? */
+ unsigned no_lock:1;
+
+ /** Is access not implemented by fs? */
+ unsigned no_access:1;
+
+ /** Is create not implemented by fs? */
+ unsigned no_create:1;
+
+ /** Is interrupt not implemented by fs? */
+ unsigned no_interrupt:1;
+
+ /** Is bmap not implemented by fs? */
+ unsigned no_bmap:1;
+
+ /** Is poll not implemented by fs? */
+ unsigned no_poll:1;
+
+ /** Do multi-page cached writes */
+ unsigned big_writes:1;
+
+ /** Don't apply umask to creation modes */
+ unsigned dont_mask:1;
+
+ /** Are BSD file locking primitives not implemented by fs? */
+ unsigned no_flock:1;
+
+ /** Is fallocate not implemented by fs? */
+ unsigned no_fallocate:1;
+
+ /** Is rename with flags implemented by fs? */
+ unsigned no_rename2:1;
+
+ /** Use enhanced/automatic page cache invalidation. */
+ unsigned auto_inval_data:1;
+
+ /** Filesystem is fully reponsible for page cache invalidation. */
+ unsigned explicit_inval_data:1;
+
+ /** Does the filesystem support readdirplus? */
+ unsigned do_readdirplus:1;
+
+ /** Does the filesystem want adaptive readdirplus? */
+ unsigned readdirplus_auto:1;
+
+ /** Does the filesystem support asynchronous direct-IO submission? */
+ unsigned async_dio:1;
+
+ /** Is lseek not implemented by fs? */
+ unsigned no_lseek:1;
+
+ /** Does the filesystem support posix acls? */
+ unsigned posix_acl:1;
+
+ /** Check permissions based on the file mode or not? */
+ unsigned default_permissions:1;
+
+ /** Allow other than the mounter user to access the filesystem ? */
+ unsigned allow_other:1;
+
+ /** Does the filesystem support copy_file_range? */
+ unsigned no_copy_file_range:1;
+
+ /* Send DESTROY request */
+ unsigned int destroy:1;
+
+ /* Delete dentries that have gone stale */
+ unsigned int delete_stale:1;
+
+ /** Do not create entry in fusectl fs */
+ unsigned int no_control:1;
+
+ /** Do not allow MNT_FORCE umount */
+ unsigned int no_force_umount:1;
+
+ /* Auto-mount submounts announced by the server */
+ unsigned int auto_submounts:1;
+
+ /** The number of requests waiting for completion */
+ atomic_t num_waiting;
+
+ /** Negotiated minor version */
+ unsigned minor;
+
+ /** Entry on the fuse_mount_list */
+ struct list_head entry;
+
+ /** Device ID from the root super block */
+ dev_t dev;
+
+ /** Dentries in the control filesystem */
+ struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
+
+ /** number of dentries used in the above array */
+ int ctl_ndents;
+
+ /** Key for lock owner ID scrambling */
+ u32 scramble_key[4];
+
+ /** Version counter for attribute changes */
+ atomic64_t attr_version;
+
+ /** Called on final put */
+ void (*release)(struct fuse_conn *);
+
+ /**
+ * Read/write semaphore to hold when accessing the sb of any
+ * fuse_mount belonging to this connection
+ */
+ struct rw_semaphore killsb;
+
+ /** List of device instances belonging to this connection */
+ struct list_head devices;
+
+#ifdef CONFIG_FUSE_DAX
+ /* Dax specific conn data, non-NULL if DAX is enabled */
+ struct fuse_conn_dax *dax;
+#endif
+
+ /* Private data */
+ void *private;
+
+ /** List of filesystems using this connection */
+ struct list_head mounts;
+};
+
+/*
+ * Represents a mounted filesystem, potentially a submount.
+ *
+ * This object allows sharing a fuse_conn between separate mounts to
+ * allow submounts with dedicated superblocks and thus separate device
+ * IDs.
+ */
+struct fuse_mount {
+ /* Underlying (potentially shared) connection to the FUSE server */
+ struct fuse_conn *fc;
+
+ /*
+ * Super block for this connection (fc->killsb must be held when
+ * accessing this).
+ */
+ struct super_block *sb;
+
+ /* Entry on fc->mounts */
+ struct list_head fc_entry;
+};
static inline struct fuse_mount *get_fuse_mount_super(struct super_block *sb)
{
@@ -520,13 +957,6 @@ int fuse_fill_super_submount(struct super_block *sb,
struct fuse_inode *parent_fi);
/*
- * Remove the mount from the connection
- *
- * Returns whether this was the last mount
- */
-bool fuse_mount_remove(struct fuse_mount *fm);
-
-/*
* Shut down the connection (possibly sending DESTROY request).
*/
void fuse_conn_destroy(struct fuse_mount *fm);
@@ -604,8 +1034,6 @@ int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
struct file *file);
-void fuse_set_initialized(struct fuse_conn *fc);
-
void fuse_unlock_inode(struct inode *inode, bool locked);
bool fuse_lock_inode(struct inode *inode);
@@ -636,7 +1064,6 @@ unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
* Get the next unique ID for a request
*/
u64 fuse_get_unique(struct fuse_iqueue *fiq);
-void fuse_free_conn(struct fuse_conn *fc);
/* dax.c */
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index b0e18b470e918..068bfd718dca1 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -684,11 +684,24 @@ static void fuse_pqueue_init(struct fuse_pqueue *fpq)
fpq->connected = 1;
}
-void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
- struct user_namespace *user_ns,
- const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv)
+struct fuse_mount *fuse_conn_new(struct user_namespace *user_ns,
+ const struct fuse_iqueue_ops *fiq_ops,
+ void *fiq_priv, void *private,
+ void (*release)(struct fuse_conn *))
{
- memset(fc, 0, sizeof(*fc));
+ struct fuse_conn *fc;
+ struct fuse_mount *fm;
+
+ fc = kzalloc(sizeof(struct fuse_conn), GFP_KERNEL);
+ if (!fc)
+ return NULL;
+
+ fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL);
+ if (!fm) {
+ kfree(fc);
+ return NULL;
+ }
+
spin_lock_init(&fc->lock);
spin_lock_init(&fc->bg_lock);
init_rwsem(&fc->killsb);
@@ -712,12 +725,16 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
fc->pid_ns = get_pid_ns(task_active_pid_ns(current));
fc->user_ns = get_user_ns(user_ns);
fc->max_pages = FUSE_DEFAULT_MAX_PAGES_PER_REQ;
+ fc->private = private;
+ fc->release = release;
INIT_LIST_HEAD(&fc->mounts);
list_add(&fm->fc_entry, &fc->mounts);
fm->fc = fc;
+
+ return fm;
}
-EXPORT_SYMBOL_GPL(fuse_conn_init);
+EXPORT_SYMBOL_GPL(fuse_conn_new);
void fuse_conn_put(struct fuse_conn *fc)
{
@@ -730,11 +747,35 @@ void fuse_conn_put(struct fuse_conn *fc)
fiq->ops->release(fiq);
put_pid_ns(fc->pid_ns);
put_user_ns(fc->user_ns);
- fc->release(fc);
+ if (fc->release)
+ fc->release(fc);
+ WARN_ON(!list_empty(&fc->devices));
+ kfree_rcu(fc, rcu);
}
}
EXPORT_SYMBOL_GPL(fuse_conn_put);
+void *fuse_conn_private(struct fuse_conn *fc)
+{
+ return fc->private;
+}
+EXPORT_SYMBOL_GPL(fuse_conn_private);
+
+void fuse_conn_update_param(struct fuse_conn *fc, unsigned int max_read,
+ unsigned int max_write, unsigned int minor)
+{
+ fc->max_read = max_read;
+ fc->max_write = max_write;
+ fc->minor = minor;
+}
+EXPORT_SYMBOL_GPL(fuse_conn_update_param);
+
+int fuse_conn_waiting(struct fuse_conn *fc)
+{
+ return atomic_read(&fc->num_waiting);
+}
+EXPORT_SYMBOL_GPL(fuse_conn_waiting);
+
struct fuse_conn *fuse_conn_get(struct fuse_conn *fc)
{
refcount_inc(&fc->count);
@@ -742,6 +783,18 @@ struct fuse_conn *fuse_conn_get(struct fuse_conn *fc)
}
EXPORT_SYMBOL_GPL(fuse_conn_get);
+struct fuse_conn *fuse_mount_conn(struct fuse_mount *fm)
+{
+ return fm->fc;
+}
+EXPORT_SYMBOL_GPL(fuse_mount_conn);
+
+struct fuse_mount *fuse_file_mount(struct fuse_file *ff)
+{
+ return ff->fm;
+}
+EXPORT_SYMBOL_GPL(fuse_file_mount);
+
static struct inode *fuse_get_root_inode(struct super_block *sb, unsigned mode)
{
struct fuse_attr attr;
@@ -1123,13 +1176,6 @@ void fuse_send_init(struct fuse_mount *fm)
}
EXPORT_SYMBOL_GPL(fuse_send_init);
-void fuse_free_conn(struct fuse_conn *fc)
-{
- WARN_ON(!list_empty(&fc->devices));
- kfree_rcu(fc, rcu);
-}
-EXPORT_SYMBOL_GPL(fuse_free_conn);
-
static int fuse_bdi_init(struct fuse_conn *fc, struct super_block *sb)
{
int err;
@@ -1417,7 +1463,6 @@ static int fuse_fill_super(struct super_block *sb, struct fs_context *fsc)
struct fuse_fs_context *ctx = fsc->fs_private;
struct file *file;
int err;
- struct fuse_conn *fc;
struct fuse_mount *fm;
err = -EINVAL;
@@ -1434,20 +1479,11 @@ static int fuse_fill_super(struct super_block *sb, struct fs_context *fsc)
goto err_fput;
ctx->fudptr = &file->private_data;
- fc = kmalloc(sizeof(*fc), GFP_KERNEL);
err = -ENOMEM;
- if (!fc)
+ fm = fuse_conn_new(sb->s_user_ns, &fuse_dev_fiq_ops, NULL, NULL, NULL);
+ if (!fm)
goto err_fput;
- fm = kzalloc(sizeof(*fm), GFP_KERNEL);
- if (!fm) {
- kfree(fc);
- goto err_fput;
- }
-
- fuse_conn_init(fc, fm, sb->s_user_ns, &fuse_dev_fiq_ops, NULL);
- fc->release = fuse_free_conn;
-
sb->s_fs_info = fm;
err = fuse_fill_super_common(sb, ctx);
@@ -1463,7 +1499,7 @@ static int fuse_fill_super(struct super_block *sb, struct fs_context *fsc)
return 0;
err_put_conn:
- fuse_conn_put(fc);
+ fuse_conn_put(fm->fc);
kfree(fm);
sb->s_fs_info = NULL;
err_fput:
diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 8868ac31a3c0a..22af786cc4605 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -1421,17 +1421,10 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
}
err = -ENOMEM;
- fc = kzalloc(sizeof(struct fuse_conn), GFP_KERNEL);
- if (!fc)
- goto out_err;
-
- fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL);
+ fm = fuse_conn_new(get_user_ns(current_user_ns()), &virtio_fs_fiq_ops, fs, NULL, NULL);
if (!fm)
goto out_err;
-
- fuse_conn_init(fc, fm, get_user_ns(current_user_ns()),
- &virtio_fs_fiq_ops, fs);
- fc->release = fuse_free_conn;
+ fc = fm->fc;
fc->delete_stale = true;
fc->auto_submounts = true;
diff --git a/include/net/fuse.h b/include/net/fuse.h
index 700cb3a6b788d..10cb15cbf0f62 100644
--- a/include/net/fuse.h
+++ b/include/net/fuse.h
@@ -13,75 +13,11 @@
#include <linux/poll.h>
#include <linux/kref.h>
-/** Number of dentries for each connection in the control filesystem */
-#define FUSE_CTL_NUM_DENTRIES 5
-
-/* One forget request */
-struct fuse_forget_link {
- struct fuse_forget_one forget_one;
- struct fuse_forget_link *next;
-};
-
struct fuse_conn;
struct fuse_mount;
-struct fuse_release_args;
struct fuse_inode;
-struct fuse_iqueue_ops;
-
-/** FUSE specific file data */
-struct fuse_file {
- /** Fuse connection for this file */
- struct fuse_mount *fm;
-
- /* Argument space reserved for release */
- struct fuse_release_args *release_args;
-
- /** Kernel file handle guaranteed to be unique */
- u64 kh;
-
- /** File handle used by userspace */
- u64 fh;
-
- /** Node id of this file */
- u64 nodeid;
-
- /** Refcount */
- refcount_t count;
-
- /** FOPEN_* flags returned by open */
- u32 open_flags;
-
- /** Entry on inode's write_files list */
- struct list_head write_entry;
-
- /* Readdir related */
- struct {
- /*
- * Protects below fields against (crazy) parallel readdir on
- * same open file. Uncontended in the normal case.
- */
- struct mutex lock;
-
- /* Dir stream position */
- loff_t pos;
-
- /* Offset in cache */
- loff_t cache_off;
-
- /* Version of cache we are reading */
- u64 version;
-
- } readdir;
-
- /** RB node to be linked on fuse_conn->polled_files */
- struct rb_node polled_node;
-
- /** Wait queue head for poll */
- wait_queue_head_t poll_wait;
-
- /** Has flock been performed on this file? */
- bool flock:1;
-};
+struct fuse_file;
+struct fuse_dev;
/** One input argument of a request */
struct fuse_in_arg {
@@ -156,376 +92,6 @@ struct fuse_io_priv {
/** /dev/fuse input queue operations */
extern const struct fuse_iqueue_ops fuse_dev_fiq_ops;
-struct fuse_iqueue {
- /** Connection established */
- unsigned connected;
-
- /** Lock protecting accesses to members of this structure */
- spinlock_t lock;
-
- /** Readers of the connection are waiting on this */
- wait_queue_head_t waitq;
-
- /** The next unique request id */
- u64 reqctr;
-
- /** The list of pending requests */
- struct list_head pending;
-
- /** Pending interrupts */
- struct list_head interrupts;
-
- /** Queue of pending forgets */
- struct fuse_forget_link forget_list_head;
- struct fuse_forget_link *forget_list_tail;
-
- /** Batching of FORGET requests (positive indicates FORGET batch) */
- int forget_batch;
-
- /** O_ASYNC requests */
- struct fasync_struct *fasync;
-
- /** Device-specific callbacks */
- const struct fuse_iqueue_ops *ops;
-
- /** Device-specific state */
- void *priv;
-};
-
-struct fuse_pqueue {
- /** Connection established */
- unsigned connected;
-
- /** Lock protecting accessess to members of this structure */
- spinlock_t lock;
-
- /** Hash table of requests being processed */
- struct list_head *processing;
-
- /** The list of requests under I/O */
- struct list_head io;
-};
-
-/**
- * Fuse device instance
- */
-struct fuse_dev {
- /** Fuse connection for this device */
- struct fuse_conn *fc;
-
- /** Processing queue */
- struct fuse_pqueue pq;
-
- /** list entry on fc->devices */
- struct list_head entry;
-};
-
-/**
- * A Fuse connection.
- *
- * This structure is created, when the root filesystem is mounted, and
- * is destroyed, when the client device is closed and the last
- * fuse_mount is destroyed.
- */
-struct fuse_conn {
- /** Lock protecting accessess to members of this structure */
- spinlock_t lock;
-
- /** Refcount */
- refcount_t count;
-
- /** Number of fuse_dev's */
- atomic_t dev_count;
-
- struct rcu_head rcu;
-
- /** The user id for this mount */
- kuid_t user_id;
-
- /** The group id for this mount */
- kgid_t group_id;
-
- /** The pid namespace for this mount */
- struct pid_namespace *pid_ns;
-
- /** The user namespace for this mount */
- struct user_namespace *user_ns;
-
- /** Maximum read size */
- unsigned max_read;
-
- /** Maximum write size */
- unsigned max_write;
-
- /** Maxmum number of pages that can be used in a single request */
- unsigned int max_pages;
-
- /** Input queue */
- struct fuse_iqueue iq;
-
- /** The next unique kernel file handle */
- atomic64_t khctr;
-
- /** rbtree of fuse_files waiting for poll events indexed by ph */
- struct rb_root polled_files;
-
- /** Maximum number of outstanding background requests */
- unsigned max_background;
-
- /** Number of background requests at which congestion starts */
- unsigned congestion_threshold;
-
- /** Number of requests currently in the background */
- unsigned num_background;
-
- /** Number of background requests currently queued for userspace */
- unsigned active_background;
-
- /** The list of background requests set aside for later queuing */
- struct list_head bg_queue;
-
- /** Protects: max_background, congestion_threshold, num_background,
- * active_background, bg_queue, blocked */
- spinlock_t bg_lock;
-
- /** Flag indicating that INIT reply has been received. Allocating
- * any fuse request will be suspended until the flag is set */
- int initialized;
-
- /** Flag indicating if connection is blocked. This will be
- the case before the INIT reply is received, and if there
- are too many outstading backgrounds requests */
- int blocked;
-
- /** waitq for blocked connection */
- wait_queue_head_t blocked_waitq;
-
- /** Connection established, cleared on umount, connection
- abort and device release */
- unsigned connected;
-
- /** Connection aborted via sysfs */
- bool aborted;
-
- /** Connection failed (version mismatch). Cannot race with
- setting other bitfields since it is only set once in INIT
- reply, before any other request, and never cleared */
- unsigned conn_error:1;
-
- /** Connection successful. Only set in INIT */
- unsigned conn_init:1;
-
- /** Do readpages asynchronously? Only set in INIT */
- unsigned async_read:1;
-
- /** Return an unique read error after abort. Only set in INIT */
- unsigned abort_err:1;
-
- /** Do not send separate SETATTR request before open(O_TRUNC) */
- unsigned atomic_o_trunc:1;
-
- /** Filesystem supports NFS exporting. Only set in INIT */
- unsigned export_support:1;
-
- /** write-back cache policy (default is write-through) */
- unsigned writeback_cache:1;
-
- /** allow parallel lookups and readdir (default is serialized) */
- unsigned parallel_dirops:1;
-
- /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
- unsigned handle_killpriv:1;
-
- /** cache READLINK responses in page cache */
- unsigned cache_symlinks:1;
-
- /* show legacy mount options */
- unsigned int legacy_opts_show:1;
-
- /*
- * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on
- * write/trunc only if caller did not have CAP_FSETID. sgid is killed
- * on write/truncate only if caller did not have CAP_FSETID as well as
- * file has group execute permission.
- */
- unsigned handle_killpriv_v2:1;
-
- /*
- * The following bitfields are only for optimization purposes
- * and hence races in setting them will not cause malfunction
- */
-
- /** Is open/release not implemented by fs? */
- unsigned no_open:1;
-
- /** Is opendir/releasedir not implemented by fs? */
- unsigned no_opendir:1;
-
- /** Is fsync not implemented by fs? */
- unsigned no_fsync:1;
-
- /** Is fsyncdir not implemented by fs? */
- unsigned no_fsyncdir:1;
-
- /** Is flush not implemented by fs? */
- unsigned no_flush:1;
-
- /** Is setxattr not implemented by fs? */
- unsigned no_setxattr:1;
-
- /** Is getxattr not implemented by fs? */
- unsigned no_getxattr:1;
-
- /** Is listxattr not implemented by fs? */
- unsigned no_listxattr:1;
-
- /** Is removexattr not implemented by fs? */
- unsigned no_removexattr:1;
-
- /** Are posix file locking primitives not implemented by fs? */
- unsigned no_lock:1;
-
- /** Is access not implemented by fs? */
- unsigned no_access:1;
-
- /** Is create not implemented by fs? */
- unsigned no_create:1;
-
- /** Is interrupt not implemented by fs? */
- unsigned no_interrupt:1;
-
- /** Is bmap not implemented by fs? */
- unsigned no_bmap:1;
-
- /** Is poll not implemented by fs? */
- unsigned no_poll:1;
-
- /** Do multi-page cached writes */
- unsigned big_writes:1;
-
- /** Don't apply umask to creation modes */
- unsigned dont_mask:1;
-
- /** Are BSD file locking primitives not implemented by fs? */
- unsigned no_flock:1;
-
- /** Is fallocate not implemented by fs? */
- unsigned no_fallocate:1;
-
- /** Is rename with flags implemented by fs? */
- unsigned no_rename2:1;
-
- /** Use enhanced/automatic page cache invalidation. */
- unsigned auto_inval_data:1;
-
- /** Filesystem is fully reponsible for page cache invalidation. */
- unsigned explicit_inval_data:1;
-
- /** Does the filesystem support readdirplus? */
- unsigned do_readdirplus:1;
-
- /** Does the filesystem want adaptive readdirplus? */
- unsigned readdirplus_auto:1;
-
- /** Does the filesystem support asynchronous direct-IO submission? */
- unsigned async_dio:1;
-
- /** Is lseek not implemented by fs? */
- unsigned no_lseek:1;
-
- /** Does the filesystem support posix acls? */
- unsigned posix_acl:1;
-
- /** Check permissions based on the file mode or not? */
- unsigned default_permissions:1;
-
- /** Allow other than the mounter user to access the filesystem ? */
- unsigned allow_other:1;
-
- /** Does the filesystem support copy_file_range? */
- unsigned no_copy_file_range:1;
-
- /* Send DESTROY request */
- unsigned int destroy:1;
-
- /* Delete dentries that have gone stale */
- unsigned int delete_stale:1;
-
- /** Do not create entry in fusectl fs */
- unsigned int no_control:1;
-
- /** Do not allow MNT_FORCE umount */
- unsigned int no_force_umount:1;
-
- /* Auto-mount submounts announced by the server */
- unsigned int auto_submounts:1;
-
- /** The number of requests waiting for completion */
- atomic_t num_waiting;
-
- /** Negotiated minor version */
- unsigned minor;
-
- /** Entry on the fuse_mount_list */
- struct list_head entry;
-
- /** Device ID from the root super block */
- dev_t dev;
-
- /** Dentries in the control filesystem */
- struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
-
- /** number of dentries used in the above array */
- int ctl_ndents;
-
- /** Key for lock owner ID scrambling */
- u32 scramble_key[4];
-
- /** Version counter for attribute changes */
- atomic64_t attr_version;
-
- /** Called on final put */
- void (*release)(struct fuse_conn *);
-
- /**
- * Read/write semaphore to hold when accessing the sb of any
- * fuse_mount belonging to this connection
- */
- struct rw_semaphore killsb;
-
- /** List of device instances belonging to this connection */
- struct list_head devices;
-
-#ifdef CONFIG_FUSE_DAX
- /* Dax specific conn data, non-NULL if DAX is enabled */
- struct fuse_conn_dax *dax;
-#endif
-
- /** List of filesystems using this connection */
- struct list_head mounts;
-};
-
-/*
- * Represents a mounted filesystem, potentially a submount.
- *
- * This object allows sharing a fuse_conn between separate mounts to
- * allow submounts with dedicated superblocks and thus separate device
- * IDs.
- */
-struct fuse_mount {
- /* Underlying (potentially shared) connection to the FUSE server */
- struct fuse_conn *fc;
-
- /*
- * Super block for this connection (fc->killsb must be held when
- * accessing this).
- */
- struct super_block *sb;
-
- /* Entry on fc->mounts */
- struct list_head fc_entry;
-};
-
/** Device operations */
extern const struct file_operations fuse_dev_operations;
@@ -545,18 +111,40 @@ struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
/**
* Initialize fuse_conn
*/
-void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
- struct user_namespace *user_ns,
- const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);
+struct fuse_mount *fuse_conn_new(struct user_namespace *user_ns,
+ const struct fuse_iqueue_ops *fiq_ops,
+ void *fiq_priv, void *private,
+ void (*release)(struct fuse_conn *));
/**
* Release reference to fuse_conn
*/
void fuse_conn_put(struct fuse_conn *fc);
+void *fuse_conn_private(struct fuse_conn *fc);
+
+void fuse_conn_update_param(struct fuse_conn *fc, unsigned int max_read,
+ unsigned int max_write, unsigned int minor);
+
+
+int fuse_conn_waiting(struct fuse_conn *fc);
+
+void fuse_set_initialized(struct fuse_conn *fc);
+
+struct fuse_conn *fuse_mount_conn(struct fuse_mount *fm);
+
+struct fuse_mount *fuse_file_mount(struct fuse_file *ff);
+
struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc);
void fuse_dev_free(struct fuse_dev *fud);
+/*
+ * Remove the mount from the connection
+ *
+ * Returns whether this was the last mount
+ */
+bool fuse_mount_remove(struct fuse_mount *fm);
+
int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file,
bool isdir);