diff options
author | Csaba Henk <csaba@gluster.com> | 2009-08-26 13:18:24 -0400 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2009-09-16 08:15:29 -0400 |
commit | 79a9d99434b104c562f30f21b75317667f444793 (patch) | |
tree | 181900c493e9aa0322b47dbcf2aa8251a956dd30 | |
parent | 487ea5af6358cb27c994e2cf056d4ee0872e43c3 (diff) |
fuse: add fusectl interface to max_background
Make the max_background and congestion_threshold parameters of a FUSE
mount tunable at runtime by adding the respective knobs to its directory
within the fusectl filesystem.
Signed-off-by: Csaba Henk <csaba@gluster.com>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
-rw-r--r-- | fs/fuse/control.c | 136 | ||||
-rw-r--r-- | fs/fuse/fuse_i.h | 6 | ||||
-rw-r--r-- | fs/fuse/inode.c | 4 |
3 files changed, 141 insertions, 5 deletions
diff --git a/fs/fuse/control.c b/fs/fuse/control.c index 218d514924c0..3773fd63d2f9 100644 --- a/fs/fuse/control.c +++ b/fs/fuse/control.c | |||
@@ -61,6 +61,121 @@ static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf, | |||
61 | return simple_read_from_buffer(buf, len, ppos, tmp, size); | 61 | return simple_read_from_buffer(buf, len, ppos, tmp, size); |
62 | } | 62 | } |
63 | 63 | ||
64 | static ssize_t fuse_conn_limit_read(struct file *file, char __user *buf, | ||
65 | size_t len, loff_t *ppos, unsigned val) | ||
66 | { | ||
67 | char tmp[32]; | ||
68 | size_t size = sprintf(tmp, "%u\n", val); | ||
69 | |||
70 | return simple_read_from_buffer(buf, len, ppos, tmp, size); | ||
71 | } | ||
72 | |||
73 | static ssize_t fuse_conn_limit_write(struct file *file, const char __user *buf, | ||
74 | size_t count, loff_t *ppos, unsigned *val, | ||
75 | unsigned global_limit) | ||
76 | { | ||
77 | unsigned long t; | ||
78 | char tmp[32]; | ||
79 | unsigned limit = (1 << 16) - 1; | ||
80 | int err; | ||
81 | |||
82 | if (*ppos || count >= sizeof(tmp) - 1) | ||
83 | return -EINVAL; | ||
84 | |||
85 | if (copy_from_user(tmp, buf, count)) | ||
86 | return -EINVAL; | ||
87 | |||
88 | tmp[count] = '\0'; | ||
89 | |||
90 | err = strict_strtoul(tmp, 0, &t); | ||
91 | if (err) | ||
92 | return err; | ||
93 | |||
94 | if (!capable(CAP_SYS_ADMIN)) | ||
95 | limit = min(limit, global_limit); | ||
96 | |||
97 | if (t > limit) | ||
98 | return -EINVAL; | ||
99 | |||
100 | *val = t; | ||
101 | |||
102 | return count; | ||
103 | } | ||
104 | |||
105 | static ssize_t fuse_conn_max_background_read(struct file *file, | ||
106 | char __user *buf, size_t len, | ||
107 | loff_t *ppos) | ||
108 | { | ||
109 | struct fuse_conn *fc; | ||
110 | unsigned val; | ||
111 | |||
112 | fc = fuse_ctl_file_conn_get(file); | ||
113 | if (!fc) | ||
114 | return 0; | ||
115 | |||
116 | val = fc->max_background; | ||
117 | fuse_conn_put(fc); | ||
118 | |||
119 | return fuse_conn_limit_read(file, buf, len, ppos, val); | ||
120 | } | ||
121 | |||
122 | static ssize_t fuse_conn_max_background_write(struct file *file, | ||
123 | const char __user *buf, | ||
124 | size_t count, loff_t *ppos) | ||
125 | { | ||
126 | unsigned val; | ||
127 | ssize_t ret; | ||
128 | |||
129 | ret = fuse_conn_limit_write(file, buf, count, ppos, &val, | ||
130 | max_user_bgreq); | ||
131 | if (ret > 0) { | ||
132 | struct fuse_conn *fc = fuse_ctl_file_conn_get(file); | ||
133 | if (fc) { | ||
134 | fc->max_background = val; | ||
135 | fuse_conn_put(fc); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | return ret; | ||
140 | } | ||
141 | |||
142 | static ssize_t fuse_conn_congestion_threshold_read(struct file *file, | ||
143 | char __user *buf, size_t len, | ||
144 | loff_t *ppos) | ||
145 | { | ||
146 | struct fuse_conn *fc; | ||
147 | unsigned val; | ||
148 | |||
149 | fc = fuse_ctl_file_conn_get(file); | ||
150 | if (!fc) | ||
151 | return 0; | ||
152 | |||
153 | val = fc->congestion_threshold; | ||
154 | fuse_conn_put(fc); | ||
155 | |||
156 | return fuse_conn_limit_read(file, buf, len, ppos, val); | ||
157 | } | ||
158 | |||
159 | static ssize_t fuse_conn_congestion_threshold_write(struct file *file, | ||
160 | const char __user *buf, | ||
161 | size_t count, loff_t *ppos) | ||
162 | { | ||
163 | unsigned val; | ||
164 | ssize_t ret; | ||
165 | |||
166 | ret = fuse_conn_limit_write(file, buf, count, ppos, &val, | ||
167 | max_user_congthresh); | ||
168 | if (ret > 0) { | ||
169 | struct fuse_conn *fc = fuse_ctl_file_conn_get(file); | ||
170 | if (fc) { | ||
171 | fc->congestion_threshold = val; | ||
172 | fuse_conn_put(fc); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | return ret; | ||
177 | } | ||
178 | |||
64 | static const struct file_operations fuse_ctl_abort_ops = { | 179 | static const struct file_operations fuse_ctl_abort_ops = { |
65 | .open = nonseekable_open, | 180 | .open = nonseekable_open, |
66 | .write = fuse_conn_abort_write, | 181 | .write = fuse_conn_abort_write, |
@@ -71,6 +186,18 @@ static const struct file_operations fuse_ctl_waiting_ops = { | |||
71 | .read = fuse_conn_waiting_read, | 186 | .read = fuse_conn_waiting_read, |
72 | }; | 187 | }; |
73 | 188 | ||
189 | static const struct file_operations fuse_conn_max_background_ops = { | ||
190 | .open = nonseekable_open, | ||
191 | .read = fuse_conn_max_background_read, | ||
192 | .write = fuse_conn_max_background_write, | ||
193 | }; | ||
194 | |||
195 | static const struct file_operations fuse_conn_congestion_threshold_ops = { | ||
196 | .open = nonseekable_open, | ||
197 | .read = fuse_conn_congestion_threshold_read, | ||
198 | .write = fuse_conn_congestion_threshold_write, | ||
199 | }; | ||
200 | |||
74 | static struct dentry *fuse_ctl_add_dentry(struct dentry *parent, | 201 | static struct dentry *fuse_ctl_add_dentry(struct dentry *parent, |
75 | struct fuse_conn *fc, | 202 | struct fuse_conn *fc, |
76 | const char *name, | 203 | const char *name, |
@@ -127,9 +254,14 @@ int fuse_ctl_add_conn(struct fuse_conn *fc) | |||
127 | goto err; | 254 | goto err; |
128 | 255 | ||
129 | if (!fuse_ctl_add_dentry(parent, fc, "waiting", S_IFREG | 0400, 1, | 256 | if (!fuse_ctl_add_dentry(parent, fc, "waiting", S_IFREG | 0400, 1, |
130 | NULL, &fuse_ctl_waiting_ops) || | 257 | NULL, &fuse_ctl_waiting_ops) || |
131 | !fuse_ctl_add_dentry(parent, fc, "abort", S_IFREG | 0200, 1, | 258 | !fuse_ctl_add_dentry(parent, fc, "abort", S_IFREG | 0200, 1, |
132 | NULL, &fuse_ctl_abort_ops)) | 259 | NULL, &fuse_ctl_abort_ops) || |
260 | !fuse_ctl_add_dentry(parent, fc, "max_background", S_IFREG | 0600, | ||
261 | 1, NULL, &fuse_conn_max_background_ops) || | ||
262 | !fuse_ctl_add_dentry(parent, fc, "congestion_threshold", | ||
263 | S_IFREG | 0600, 1, NULL, | ||
264 | &fuse_conn_congestion_threshold_ops)) | ||
133 | goto err; | 265 | goto err; |
134 | 266 | ||
135 | return 0; | 267 | return 0; |
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 6bcfab04396f..fc9c79feb5f7 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h | |||
@@ -32,7 +32,7 @@ | |||
32 | #define FUSE_NAME_MAX 1024 | 32 | #define FUSE_NAME_MAX 1024 |
33 | 33 | ||
34 | /** Number of dentries for each connection in the control filesystem */ | 34 | /** Number of dentries for each connection in the control filesystem */ |
35 | #define FUSE_CTL_NUM_DENTRIES 3 | 35 | #define FUSE_CTL_NUM_DENTRIES 5 |
36 | 36 | ||
37 | /** If the FUSE_DEFAULT_PERMISSIONS flag is given, the filesystem | 37 | /** If the FUSE_DEFAULT_PERMISSIONS flag is given, the filesystem |
38 | module will check permissions based on the file mode. Otherwise no | 38 | module will check permissions based on the file mode. Otherwise no |
@@ -49,6 +49,10 @@ extern struct list_head fuse_conn_list; | |||
49 | /** Global mutex protecting fuse_conn_list and the control filesystem */ | 49 | /** Global mutex protecting fuse_conn_list and the control filesystem */ |
50 | extern struct mutex fuse_mutex; | 50 | extern struct mutex fuse_mutex; |
51 | 51 | ||
52 | /** Module parameters */ | ||
53 | extern unsigned max_user_bgreq; | ||
54 | extern unsigned max_user_congthresh; | ||
55 | |||
52 | /** FUSE inode */ | 56 | /** FUSE inode */ |
53 | struct fuse_inode { | 57 | struct fuse_inode { |
54 | /** Inode data */ | 58 | /** Inode data */ |
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index e54ddbda208c..8f9aca8d4ad5 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c | |||
@@ -31,7 +31,7 @@ DEFINE_MUTEX(fuse_mutex); | |||
31 | 31 | ||
32 | static int set_global_limit(const char *val, struct kernel_param *kp); | 32 | static int set_global_limit(const char *val, struct kernel_param *kp); |
33 | 33 | ||
34 | static unsigned max_user_bgreq; | 34 | unsigned max_user_bgreq; |
35 | module_param_call(max_user_bgreq, set_global_limit, param_get_uint, | 35 | module_param_call(max_user_bgreq, set_global_limit, param_get_uint, |
36 | &max_user_bgreq, 0644); | 36 | &max_user_bgreq, 0644); |
37 | __MODULE_PARM_TYPE(max_user_bgreq, "uint"); | 37 | __MODULE_PARM_TYPE(max_user_bgreq, "uint"); |
@@ -39,7 +39,7 @@ MODULE_PARM_DESC(max_user_bgreq, | |||
39 | "Global limit for the maximum number of backgrounded requests an " | 39 | "Global limit for the maximum number of backgrounded requests an " |
40 | "unprivileged user can set"); | 40 | "unprivileged user can set"); |
41 | 41 | ||
42 | static unsigned max_user_congthresh; | 42 | unsigned max_user_congthresh; |
43 | module_param_call(max_user_congthresh, set_global_limit, param_get_uint, | 43 | module_param_call(max_user_congthresh, set_global_limit, param_get_uint, |
44 | &max_user_congthresh, 0644); | 44 | &max_user_congthresh, 0644); |
45 | __MODULE_PARM_TYPE(max_user_congthresh, "uint"); | 45 | __MODULE_PARM_TYPE(max_user_congthresh, "uint"); |