Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | 1729a16 | 2008-11-26 12:03:54 +0100 | [diff] [blame] | 3 | Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 4 | |
| 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
| 7 | */ |
| 8 | |
| 9 | #include "fuse_i.h" |
| 10 | |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/module.h> |
David Howells | 29cc02d | 2019-03-27 23:44:19 +0000 | [diff] [blame] | 13 | #include <linux/fs_context.h> |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 14 | |
| 15 | #define FUSE_CTL_SUPER_MAGIC 0x65735543 |
| 16 | |
| 17 | /* |
| 18 | * This is non-NULL when the single instance of the control filesystem |
| 19 | * exists. Protected by fuse_mutex |
| 20 | */ |
| 21 | static struct super_block *fuse_control_sb; |
| 22 | |
| 23 | static struct fuse_conn *fuse_ctl_file_conn_get(struct file *file) |
| 24 | { |
| 25 | struct fuse_conn *fc; |
| 26 | mutex_lock(&fuse_mutex); |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 27 | fc = file_inode(file)->i_private; |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 28 | if (fc) |
| 29 | fc = fuse_conn_get(fc); |
| 30 | mutex_unlock(&fuse_mutex); |
| 31 | return fc; |
| 32 | } |
| 33 | |
| 34 | static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf, |
| 35 | size_t count, loff_t *ppos) |
| 36 | { |
| 37 | struct fuse_conn *fc = fuse_ctl_file_conn_get(file); |
| 38 | if (fc) { |
Miklos Szeredi | eb98e3bd | 2019-01-24 10:40:16 +0100 | [diff] [blame] | 39 | if (fc->abort_err) |
| 40 | fc->aborted = true; |
| 41 | fuse_abort_conn(fc); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 42 | fuse_conn_put(fc); |
| 43 | } |
| 44 | return count; |
| 45 | } |
| 46 | |
| 47 | static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf, |
| 48 | size_t len, loff_t *ppos) |
| 49 | { |
| 50 | char tmp[32]; |
| 51 | size_t size; |
| 52 | |
| 53 | if (!*ppos) { |
Miklos Szeredi | 1729a16 | 2008-11-26 12:03:54 +0100 | [diff] [blame] | 54 | long value; |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 55 | struct fuse_conn *fc = fuse_ctl_file_conn_get(file); |
| 56 | if (!fc) |
| 57 | return 0; |
| 58 | |
Miklos Szeredi | 1729a16 | 2008-11-26 12:03:54 +0100 | [diff] [blame] | 59 | value = atomic_read(&fc->num_waiting); |
| 60 | file->private_data = (void *)value; |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 61 | fuse_conn_put(fc); |
| 62 | } |
| 63 | size = sprintf(tmp, "%ld\n", (long)file->private_data); |
| 64 | return simple_read_from_buffer(buf, len, ppos, tmp, size); |
| 65 | } |
| 66 | |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 67 | static ssize_t fuse_conn_limit_read(struct file *file, char __user *buf, |
| 68 | size_t len, loff_t *ppos, unsigned val) |
| 69 | { |
| 70 | char tmp[32]; |
| 71 | size_t size = sprintf(tmp, "%u\n", val); |
| 72 | |
| 73 | return simple_read_from_buffer(buf, len, ppos, tmp, size); |
| 74 | } |
| 75 | |
| 76 | static ssize_t fuse_conn_limit_write(struct file *file, const char __user *buf, |
| 77 | size_t count, loff_t *ppos, unsigned *val, |
| 78 | unsigned global_limit) |
| 79 | { |
| 80 | unsigned long t; |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 81 | unsigned limit = (1 << 16) - 1; |
| 82 | int err; |
| 83 | |
Peter Huewe | e269069 | 2012-04-15 02:20:27 +0200 | [diff] [blame] | 84 | if (*ppos) |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 85 | return -EINVAL; |
| 86 | |
Peter Huewe | e269069 | 2012-04-15 02:20:27 +0200 | [diff] [blame] | 87 | err = kstrtoul_from_user(buf, count, 0, &t); |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 88 | if (err) |
| 89 | return err; |
| 90 | |
| 91 | if (!capable(CAP_SYS_ADMIN)) |
| 92 | limit = min(limit, global_limit); |
| 93 | |
| 94 | if (t > limit) |
| 95 | return -EINVAL; |
| 96 | |
| 97 | *val = t; |
| 98 | |
| 99 | return count; |
| 100 | } |
| 101 | |
| 102 | static ssize_t fuse_conn_max_background_read(struct file *file, |
| 103 | char __user *buf, size_t len, |
| 104 | loff_t *ppos) |
| 105 | { |
| 106 | struct fuse_conn *fc; |
| 107 | unsigned val; |
| 108 | |
| 109 | fc = fuse_ctl_file_conn_get(file); |
| 110 | if (!fc) |
| 111 | return 0; |
| 112 | |
Kirill Tkhai | 2a23f2b | 2018-08-27 18:29:29 +0300 | [diff] [blame] | 113 | val = READ_ONCE(fc->max_background); |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 114 | fuse_conn_put(fc); |
| 115 | |
| 116 | return fuse_conn_limit_read(file, buf, len, ppos, val); |
| 117 | } |
| 118 | |
| 119 | static ssize_t fuse_conn_max_background_write(struct file *file, |
| 120 | const char __user *buf, |
| 121 | size_t count, loff_t *ppos) |
| 122 | { |
Kees Cook | 3f649ab | 2020-06-03 13:09:38 -0700 | [diff] [blame] | 123 | unsigned val; |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 124 | ssize_t ret; |
| 125 | |
| 126 | ret = fuse_conn_limit_write(file, buf, count, ppos, &val, |
| 127 | max_user_bgreq); |
| 128 | if (ret > 0) { |
| 129 | struct fuse_conn *fc = fuse_ctl_file_conn_get(file); |
| 130 | if (fc) { |
Kirill Tkhai | ae2dffa | 2018-08-27 18:29:46 +0300 | [diff] [blame] | 131 | spin_lock(&fc->bg_lock); |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 132 | fc->max_background = val; |
Kirill Tkhai | 2b30a53 | 2018-08-27 18:29:37 +0300 | [diff] [blame] | 133 | fc->blocked = fc->num_background >= fc->max_background; |
| 134 | if (!fc->blocked) |
| 135 | wake_up(&fc->blocked_waitq); |
Kirill Tkhai | ae2dffa | 2018-08-27 18:29:46 +0300 | [diff] [blame] | 136 | spin_unlock(&fc->bg_lock); |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 137 | fuse_conn_put(fc); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | return ret; |
| 142 | } |
| 143 | |
| 144 | static ssize_t fuse_conn_congestion_threshold_read(struct file *file, |
| 145 | char __user *buf, size_t len, |
| 146 | loff_t *ppos) |
| 147 | { |
| 148 | struct fuse_conn *fc; |
| 149 | unsigned val; |
| 150 | |
| 151 | fc = fuse_ctl_file_conn_get(file); |
| 152 | if (!fc) |
| 153 | return 0; |
| 154 | |
Kirill Tkhai | 2a23f2b | 2018-08-27 18:29:29 +0300 | [diff] [blame] | 155 | val = READ_ONCE(fc->congestion_threshold); |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 156 | fuse_conn_put(fc); |
| 157 | |
| 158 | return fuse_conn_limit_read(file, buf, len, ppos, val); |
| 159 | } |
| 160 | |
| 161 | static ssize_t fuse_conn_congestion_threshold_write(struct file *file, |
| 162 | const char __user *buf, |
| 163 | size_t count, loff_t *ppos) |
| 164 | { |
Kees Cook | 3f649ab | 2020-06-03 13:09:38 -0700 | [diff] [blame] | 165 | unsigned val; |
Kirill Tkhai | 2b30a53 | 2018-08-27 18:29:37 +0300 | [diff] [blame] | 166 | struct fuse_conn *fc; |
Max Reitz | fcee216 | 2020-05-06 17:44:12 +0200 | [diff] [blame] | 167 | struct fuse_mount *fm; |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 168 | ssize_t ret; |
| 169 | |
| 170 | ret = fuse_conn_limit_write(file, buf, count, ppos, &val, |
| 171 | max_user_congthresh); |
Kirill Tkhai | 2b30a53 | 2018-08-27 18:29:37 +0300 | [diff] [blame] | 172 | if (ret <= 0) |
| 173 | goto out; |
| 174 | fc = fuse_ctl_file_conn_get(file); |
| 175 | if (!fc) |
| 176 | goto out; |
| 177 | |
Max Reitz | fcee216 | 2020-05-06 17:44:12 +0200 | [diff] [blame] | 178 | down_read(&fc->killsb); |
Kirill Tkhai | ae2dffa | 2018-08-27 18:29:46 +0300 | [diff] [blame] | 179 | spin_lock(&fc->bg_lock); |
Kirill Tkhai | 2b30a53 | 2018-08-27 18:29:37 +0300 | [diff] [blame] | 180 | fc->congestion_threshold = val; |
Max Reitz | fcee216 | 2020-05-06 17:44:12 +0200 | [diff] [blame] | 181 | |
| 182 | /* |
| 183 | * Get any fuse_mount belonging to this fuse_conn; s_bdi is |
| 184 | * shared between all of them |
| 185 | */ |
| 186 | |
| 187 | if (!list_empty(&fc->mounts)) { |
| 188 | fm = list_first_entry(&fc->mounts, struct fuse_mount, fc_entry); |
Kirill Tkhai | 2b30a53 | 2018-08-27 18:29:37 +0300 | [diff] [blame] | 189 | if (fc->num_background < fc->congestion_threshold) { |
Max Reitz | fcee216 | 2020-05-06 17:44:12 +0200 | [diff] [blame] | 190 | clear_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC); |
| 191 | clear_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC); |
Kirill Tkhai | 2b30a53 | 2018-08-27 18:29:37 +0300 | [diff] [blame] | 192 | } else { |
Max Reitz | fcee216 | 2020-05-06 17:44:12 +0200 | [diff] [blame] | 193 | set_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC); |
| 194 | set_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC); |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 195 | } |
| 196 | } |
Kirill Tkhai | ae2dffa | 2018-08-27 18:29:46 +0300 | [diff] [blame] | 197 | spin_unlock(&fc->bg_lock); |
Max Reitz | fcee216 | 2020-05-06 17:44:12 +0200 | [diff] [blame] | 198 | up_read(&fc->killsb); |
Kirill Tkhai | 2b30a53 | 2018-08-27 18:29:37 +0300 | [diff] [blame] | 199 | fuse_conn_put(fc); |
| 200 | out: |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 201 | return ret; |
| 202 | } |
| 203 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 204 | static const struct file_operations fuse_ctl_abort_ops = { |
| 205 | .open = nonseekable_open, |
| 206 | .write = fuse_conn_abort_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 207 | .llseek = no_llseek, |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | static const struct file_operations fuse_ctl_waiting_ops = { |
| 211 | .open = nonseekable_open, |
| 212 | .read = fuse_conn_waiting_read, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 213 | .llseek = no_llseek, |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 214 | }; |
| 215 | |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 216 | static const struct file_operations fuse_conn_max_background_ops = { |
| 217 | .open = nonseekable_open, |
| 218 | .read = fuse_conn_max_background_read, |
| 219 | .write = fuse_conn_max_background_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 220 | .llseek = no_llseek, |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | static const struct file_operations fuse_conn_congestion_threshold_ops = { |
| 224 | .open = nonseekable_open, |
| 225 | .read = fuse_conn_congestion_threshold_read, |
| 226 | .write = fuse_conn_congestion_threshold_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 227 | .llseek = no_llseek, |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 228 | }; |
| 229 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 230 | static struct dentry *fuse_ctl_add_dentry(struct dentry *parent, |
| 231 | struct fuse_conn *fc, |
| 232 | const char *name, |
| 233 | int mode, int nlink, |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 234 | const struct inode_operations *iop, |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 235 | const struct file_operations *fop) |
| 236 | { |
| 237 | struct dentry *dentry; |
| 238 | struct inode *inode; |
| 239 | |
| 240 | BUG_ON(fc->ctl_ndents >= FUSE_CTL_NUM_DENTRIES); |
| 241 | dentry = d_alloc_name(parent, name); |
| 242 | if (!dentry) |
| 243 | return NULL; |
| 244 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 245 | inode = new_inode(fuse_control_sb); |
Miklos Szeredi | 6becdb6 | 2018-05-31 12:26:10 +0200 | [diff] [blame] | 246 | if (!inode) { |
| 247 | dput(dentry); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 248 | return NULL; |
Miklos Szeredi | 6becdb6 | 2018-05-31 12:26:10 +0200 | [diff] [blame] | 249 | } |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 250 | |
Christoph Hellwig | 85fe402 | 2010-10-23 11:19:54 -0400 | [diff] [blame] | 251 | inode->i_ino = get_next_ino(); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 252 | inode->i_mode = mode; |
| 253 | inode->i_uid = fc->user_id; |
| 254 | inode->i_gid = fc->group_id; |
Deepa Dinamani | 078cd82 | 2016-09-14 07:48:04 -0700 | [diff] [blame] | 255 | inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 256 | /* setting ->i_op to NULL is not allowed */ |
| 257 | if (iop) |
| 258 | inode->i_op = iop; |
| 259 | inode->i_fop = fop; |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 260 | set_nlink(inode, nlink); |
Theodore Ts'o | 8e18e29 | 2006-09-27 01:50:46 -0700 | [diff] [blame] | 261 | inode->i_private = fc; |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 262 | d_add(dentry, inode); |
Miklos Szeredi | 6becdb6 | 2018-05-31 12:26:10 +0200 | [diff] [blame] | 263 | |
| 264 | fc->ctl_dentry[fc->ctl_ndents++] = dentry; |
| 265 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 266 | return dentry; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * Add a connection to the control filesystem (if it exists). Caller |
Miklos Szeredi | 873302c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 271 | * must hold fuse_mutex |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 272 | */ |
| 273 | int fuse_ctl_add_conn(struct fuse_conn *fc) |
| 274 | { |
| 275 | struct dentry *parent; |
| 276 | char name[32]; |
| 277 | |
| 278 | if (!fuse_control_sb) |
| 279 | return 0; |
| 280 | |
| 281 | parent = fuse_control_sb->s_root; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 282 | inc_nlink(d_inode(parent)); |
Miklos Szeredi | b6f2fcb | 2008-04-30 00:54:34 -0700 | [diff] [blame] | 283 | sprintf(name, "%u", fc->dev); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 284 | parent = fuse_ctl_add_dentry(parent, fc, name, S_IFDIR | 0500, 2, |
| 285 | &simple_dir_inode_operations, |
| 286 | &simple_dir_operations); |
| 287 | if (!parent) |
| 288 | goto err; |
| 289 | |
| 290 | if (!fuse_ctl_add_dentry(parent, fc, "waiting", S_IFREG | 0400, 1, |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 291 | NULL, &fuse_ctl_waiting_ops) || |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 292 | !fuse_ctl_add_dentry(parent, fc, "abort", S_IFREG | 0200, 1, |
Csaba Henk | 79a9d99 | 2009-08-26 19:18:24 +0200 | [diff] [blame] | 293 | NULL, &fuse_ctl_abort_ops) || |
| 294 | !fuse_ctl_add_dentry(parent, fc, "max_background", S_IFREG | 0600, |
| 295 | 1, NULL, &fuse_conn_max_background_ops) || |
| 296 | !fuse_ctl_add_dentry(parent, fc, "congestion_threshold", |
| 297 | S_IFREG | 0600, 1, NULL, |
| 298 | &fuse_conn_congestion_threshold_ops)) |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 299 | goto err; |
| 300 | |
| 301 | return 0; |
| 302 | |
| 303 | err: |
| 304 | fuse_ctl_remove_conn(fc); |
| 305 | return -ENOMEM; |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * Remove a connection from the control filesystem (if it exists). |
Miklos Szeredi | 873302c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 310 | * Caller must hold fuse_mutex |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 311 | */ |
| 312 | void fuse_ctl_remove_conn(struct fuse_conn *fc) |
| 313 | { |
| 314 | int i; |
| 315 | |
| 316 | if (!fuse_control_sb) |
| 317 | return; |
| 318 | |
| 319 | for (i = fc->ctl_ndents - 1; i >= 0; i--) { |
| 320 | struct dentry *dentry = fc->ctl_dentry[i]; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 321 | d_inode(dentry)->i_private = NULL; |
Miklos Szeredi | 6becdb6 | 2018-05-31 12:26:10 +0200 | [diff] [blame] | 322 | if (!i) { |
| 323 | /* Get rid of submounts: */ |
| 324 | d_invalidate(dentry); |
| 325 | } |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 326 | dput(dentry); |
| 327 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 328 | drop_nlink(d_inode(fuse_control_sb->s_root)); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Miklos Szeredi | 84c2150 | 2021-08-04 13:22:58 +0200 | [diff] [blame] | 331 | static int fuse_ctl_fill_super(struct super_block *sb, struct fs_context *fsc) |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 332 | { |
Eric Biggers | cda3712 | 2017-03-25 21:15:37 -0700 | [diff] [blame] | 333 | static const struct tree_descr empty_descr = {""}; |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 334 | struct fuse_conn *fc; |
| 335 | int err; |
| 336 | |
| 337 | err = simple_fill_super(sb, FUSE_CTL_SUPER_MAGIC, &empty_descr); |
| 338 | if (err) |
| 339 | return err; |
| 340 | |
| 341 | mutex_lock(&fuse_mutex); |
| 342 | BUG_ON(fuse_control_sb); |
| 343 | fuse_control_sb = sb; |
| 344 | list_for_each_entry(fc, &fuse_conn_list, entry) { |
| 345 | err = fuse_ctl_add_conn(fc); |
| 346 | if (err) { |
| 347 | fuse_control_sb = NULL; |
| 348 | mutex_unlock(&fuse_mutex); |
| 349 | return err; |
| 350 | } |
| 351 | } |
| 352 | mutex_unlock(&fuse_mutex); |
| 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
Miklos Szeredi | 84c2150 | 2021-08-04 13:22:58 +0200 | [diff] [blame] | 357 | static int fuse_ctl_get_tree(struct fs_context *fsc) |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 358 | { |
Miklos Szeredi | 84c2150 | 2021-08-04 13:22:58 +0200 | [diff] [blame] | 359 | return get_tree_single(fsc, fuse_ctl_fill_super); |
David Howells | 29cc02d | 2019-03-27 23:44:19 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static const struct fs_context_operations fuse_ctl_context_ops = { |
| 363 | .get_tree = fuse_ctl_get_tree, |
| 364 | }; |
| 365 | |
Miklos Szeredi | 84c2150 | 2021-08-04 13:22:58 +0200 | [diff] [blame] | 366 | static int fuse_ctl_init_fs_context(struct fs_context *fsc) |
David Howells | 29cc02d | 2019-03-27 23:44:19 +0000 | [diff] [blame] | 367 | { |
Miklos Szeredi | 84c2150 | 2021-08-04 13:22:58 +0200 | [diff] [blame] | 368 | fsc->ops = &fuse_ctl_context_ops; |
David Howells | 29cc02d | 2019-03-27 23:44:19 +0000 | [diff] [blame] | 369 | return 0; |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | static void fuse_ctl_kill_sb(struct super_block *sb) |
| 373 | { |
Miklos Szeredi | ff79544 | 2007-01-29 13:19:54 -0800 | [diff] [blame] | 374 | struct fuse_conn *fc; |
| 375 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 376 | mutex_lock(&fuse_mutex); |
| 377 | fuse_control_sb = NULL; |
Miklos Szeredi | ff79544 | 2007-01-29 13:19:54 -0800 | [diff] [blame] | 378 | list_for_each_entry(fc, &fuse_conn_list, entry) |
| 379 | fc->ctl_ndents = 0; |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 380 | mutex_unlock(&fuse_mutex); |
| 381 | |
| 382 | kill_litter_super(sb); |
| 383 | } |
| 384 | |
| 385 | static struct file_system_type fuse_ctl_fs_type = { |
| 386 | .owner = THIS_MODULE, |
| 387 | .name = "fusectl", |
David Howells | 29cc02d | 2019-03-27 23:44:19 +0000 | [diff] [blame] | 388 | .init_fs_context = fuse_ctl_init_fs_context, |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 389 | .kill_sb = fuse_ctl_kill_sb, |
| 390 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 391 | MODULE_ALIAS_FS("fusectl"); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 392 | |
| 393 | int __init fuse_ctl_init(void) |
| 394 | { |
| 395 | return register_filesystem(&fuse_ctl_fs_type); |
| 396 | } |
| 397 | |
Fabian Frederick | 7736e8c | 2014-04-23 18:14:42 +0200 | [diff] [blame] | 398 | void __exit fuse_ctl_cleanup(void) |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 399 | { |
| 400 | unregister_filesystem(&fuse_ctl_fs_type); |
| 401 | } |