diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/Kconfig | 10 | ||||
-rw-r--r-- | fs/eventfd.c | 3 | ||||
-rw-r--r-- | fs/fuse/Makefile | 1 | ||||
-rw-r--r-- | fs/fuse/cuse.c | 610 | ||||
-rw-r--r-- | fs/fuse/dev.c | 15 | ||||
-rw-r--r-- | fs/fuse/dir.c | 33 | ||||
-rw-r--r-- | fs/fuse/file.c | 346 | ||||
-rw-r--r-- | fs/fuse/fuse_i.h | 47 | ||||
-rw-r--r-- | fs/fuse/inode.c | 118 | ||||
-rw-r--r-- | fs/gfs2/Makefile | 1 | ||||
-rw-r--r-- | fs/gfs2/bmap.c | 3 | ||||
-rw-r--r-- | fs/gfs2/glock.c | 12 | ||||
-rw-r--r-- | fs/gfs2/log.c | 9 | ||||
-rw-r--r-- | fs/gfs2/lops.c | 3 | ||||
-rw-r--r-- | fs/gfs2/ops_fstype.c | 2 | ||||
-rw-r--r-- | fs/gfs2/rgrp.c | 11 | ||||
-rw-r--r-- | fs/gfs2/super.c | 4 | ||||
-rw-r--r-- | fs/gfs2/trace_gfs2.h | 407 | ||||
-rw-r--r-- | fs/partitions/check.c | 42 |
19 files changed, 1426 insertions, 251 deletions
diff --git a/fs/Kconfig b/fs/Kconfig index 9f7270f36b2a..525da2e8f73b 100644 --- a/fs/Kconfig +++ b/fs/Kconfig | |||
@@ -62,6 +62,16 @@ source "fs/autofs/Kconfig" | |||
62 | source "fs/autofs4/Kconfig" | 62 | source "fs/autofs4/Kconfig" |
63 | source "fs/fuse/Kconfig" | 63 | source "fs/fuse/Kconfig" |
64 | 64 | ||
65 | config CUSE | ||
66 | tristate "Character device in Userpace support" | ||
67 | depends on FUSE_FS | ||
68 | help | ||
69 | This FUSE extension allows character devices to be | ||
70 | implemented in userspace. | ||
71 | |||
72 | If you want to develop or use userspace character device | ||
73 | based on CUSE, answer Y or M. | ||
74 | |||
65 | config GENERIC_ACL | 75 | config GENERIC_ACL |
66 | bool | 76 | bool |
67 | select FS_POSIX_ACL | 77 | select FS_POSIX_ACL |
diff --git a/fs/eventfd.c b/fs/eventfd.c index 2a701d593d35..3f0e1974abdc 100644 --- a/fs/eventfd.c +++ b/fs/eventfd.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/anon_inodes.h> | 16 | #include <linux/anon_inodes.h> |
17 | #include <linux/eventfd.h> | 17 | #include <linux/eventfd.h> |
18 | #include <linux/syscalls.h> | 18 | #include <linux/syscalls.h> |
19 | #include <linux/module.h> | ||
19 | 20 | ||
20 | struct eventfd_ctx { | 21 | struct eventfd_ctx { |
21 | wait_queue_head_t wqh; | 22 | wait_queue_head_t wqh; |
@@ -56,6 +57,7 @@ int eventfd_signal(struct file *file, int n) | |||
56 | 57 | ||
57 | return n; | 58 | return n; |
58 | } | 59 | } |
60 | EXPORT_SYMBOL_GPL(eventfd_signal); | ||
59 | 61 | ||
60 | static int eventfd_release(struct inode *inode, struct file *file) | 62 | static int eventfd_release(struct inode *inode, struct file *file) |
61 | { | 63 | { |
@@ -197,6 +199,7 @@ struct file *eventfd_fget(int fd) | |||
197 | 199 | ||
198 | return file; | 200 | return file; |
199 | } | 201 | } |
202 | EXPORT_SYMBOL_GPL(eventfd_fget); | ||
200 | 203 | ||
201 | SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags) | 204 | SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags) |
202 | { | 205 | { |
diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile index 72437065f6ad..e95eeb445e58 100644 --- a/fs/fuse/Makefile +++ b/fs/fuse/Makefile | |||
@@ -3,5 +3,6 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | obj-$(CONFIG_FUSE_FS) += fuse.o | 5 | obj-$(CONFIG_FUSE_FS) += fuse.o |
6 | obj-$(CONFIG_CUSE) += cuse.o | ||
6 | 7 | ||
7 | fuse-objs := dev.o dir.o file.o inode.o control.o | 8 | fuse-objs := dev.o dir.o file.o inode.o control.o |
diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c new file mode 100644 index 000000000000..de792dcf3274 --- /dev/null +++ b/fs/fuse/cuse.c | |||
@@ -0,0 +1,610 @@ | |||
1 | /* | ||
2 | * CUSE: Character device in Userspace | ||
3 | * | ||
4 | * Copyright (C) 2008-2009 SUSE Linux Products GmbH | ||
5 | * Copyright (C) 2008-2009 Tejun Heo <tj@kernel.org> | ||
6 | * | ||
7 | * This file is released under the GPLv2. | ||
8 | * | ||
9 | * CUSE enables character devices to be implemented from userland much | ||
10 | * like FUSE allows filesystems. On initialization /dev/cuse is | ||
11 | * created. By opening the file and replying to the CUSE_INIT request | ||
12 | * userland CUSE server can create a character device. After that the | ||
13 | * operation is very similar to FUSE. | ||
14 | * | ||
15 | * A CUSE instance involves the following objects. | ||
16 | * | ||
17 | * cuse_conn : contains fuse_conn and serves as bonding structure | ||
18 | * channel : file handle connected to the userland CUSE server | ||
19 | * cdev : the implemented character device | ||
20 | * dev : generic device for cdev | ||
21 | * | ||
22 | * Note that 'channel' is what 'dev' is in FUSE. As CUSE deals with | ||
23 | * devices, it's called 'channel' to reduce confusion. | ||
24 | * | ||
25 | * channel determines when the character device dies. When channel is | ||
26 | * closed, everything begins to destruct. The cuse_conn is taken off | ||
27 | * the lookup table preventing further access from cdev, cdev and | ||
28 | * generic device are removed and the base reference of cuse_conn is | ||
29 | * put. | ||
30 | * | ||
31 | * On each open, the matching cuse_conn is looked up and if found an | ||
32 | * additional reference is taken which is released when the file is | ||
33 | * closed. | ||
34 | */ | ||
35 | |||
36 | #include <linux/fuse.h> | ||
37 | #include <linux/cdev.h> | ||
38 | #include <linux/device.h> | ||
39 | #include <linux/file.h> | ||
40 | #include <linux/fs.h> | ||
41 | #include <linux/kdev_t.h> | ||
42 | #include <linux/kthread.h> | ||
43 | #include <linux/list.h> | ||
44 | #include <linux/magic.h> | ||
45 | #include <linux/miscdevice.h> | ||
46 | #include <linux/mutex.h> | ||
47 | #include <linux/spinlock.h> | ||
48 | #include <linux/stat.h> | ||
49 | |||
50 | #include "fuse_i.h" | ||
51 | |||
52 | #define CUSE_CONNTBL_LEN 64 | ||
53 | |||
54 | struct cuse_conn { | ||
55 | struct list_head list; /* linked on cuse_conntbl */ | ||
56 | struct fuse_conn fc; /* fuse connection */ | ||
57 | struct cdev *cdev; /* associated character device */ | ||
58 | struct device *dev; /* device representing @cdev */ | ||
59 | |||
60 | /* init parameters, set once during initialization */ | ||
61 | bool unrestricted_ioctl; | ||
62 | }; | ||
63 | |||
64 | static DEFINE_SPINLOCK(cuse_lock); /* protects cuse_conntbl */ | ||
65 | static struct list_head cuse_conntbl[CUSE_CONNTBL_LEN]; | ||
66 | static struct class *cuse_class; | ||
67 | |||
68 | static struct cuse_conn *fc_to_cc(struct fuse_conn *fc) | ||
69 | { | ||
70 | return container_of(fc, struct cuse_conn, fc); | ||
71 | } | ||
72 | |||
73 | static struct list_head *cuse_conntbl_head(dev_t devt) | ||
74 | { | ||
75 | return &cuse_conntbl[(MAJOR(devt) + MINOR(devt)) % CUSE_CONNTBL_LEN]; | ||
76 | } | ||
77 | |||
78 | |||
79 | /************************************************************************** | ||
80 | * CUSE frontend operations | ||
81 | * | ||
82 | * These are file operations for the character device. | ||
83 | * | ||
84 | * On open, CUSE opens a file from the FUSE mnt and stores it to | ||
85 | * private_data of the open file. All other ops call FUSE ops on the | ||
86 | * FUSE file. | ||
87 | */ | ||
88 | |||
89 | static ssize_t cuse_read(struct file *file, char __user *buf, size_t count, | ||
90 | loff_t *ppos) | ||
91 | { | ||
92 | loff_t pos = 0; | ||
93 | |||
94 | return fuse_direct_io(file, buf, count, &pos, 0); | ||
95 | } | ||
96 | |||
97 | static ssize_t cuse_write(struct file *file, const char __user *buf, | ||
98 | size_t count, loff_t *ppos) | ||
99 | { | ||
100 | loff_t pos = 0; | ||
101 | /* | ||
102 | * No locking or generic_write_checks(), the server is | ||
103 | * responsible for locking and sanity checks. | ||
104 | */ | ||
105 | return fuse_direct_io(file, buf, count, &pos, 1); | ||
106 | } | ||
107 | |||
108 | static int cuse_open(struct inode *inode, struct file *file) | ||
109 | { | ||
110 | dev_t devt = inode->i_cdev->dev; | ||
111 | struct cuse_conn *cc = NULL, *pos; | ||
112 | int rc; | ||
113 | |||
114 | /* look up and get the connection */ | ||
115 | spin_lock(&cuse_lock); | ||
116 | list_for_each_entry(pos, cuse_conntbl_head(devt), list) | ||
117 | if (pos->dev->devt == devt) { | ||
118 | fuse_conn_get(&pos->fc); | ||
119 | cc = pos; | ||
120 | break; | ||
121 | } | ||
122 | spin_unlock(&cuse_lock); | ||
123 | |||
124 | /* dead? */ | ||
125 | if (!cc) | ||
126 | return -ENODEV; | ||
127 | |||
128 | /* | ||
129 | * Generic permission check is already done against the chrdev | ||
130 | * file, proceed to open. | ||
131 | */ | ||
132 | rc = fuse_do_open(&cc->fc, 0, file, 0); | ||
133 | if (rc) | ||
134 | fuse_conn_put(&cc->fc); | ||
135 | return rc; | ||
136 | } | ||
137 | |||
138 | static int cuse_release(struct inode *inode, struct file *file) | ||
139 | { | ||
140 | struct fuse_file *ff = file->private_data; | ||
141 | struct fuse_conn *fc = ff->fc; | ||
142 | |||
143 | fuse_sync_release(ff, file->f_flags); | ||
144 | fuse_conn_put(fc); | ||
145 | |||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | static long cuse_file_ioctl(struct file *file, unsigned int cmd, | ||
150 | unsigned long arg) | ||
151 | { | ||
152 | struct fuse_file *ff = file->private_data; | ||
153 | struct cuse_conn *cc = fc_to_cc(ff->fc); | ||
154 | unsigned int flags = 0; | ||
155 | |||
156 | if (cc->unrestricted_ioctl) | ||
157 | flags |= FUSE_IOCTL_UNRESTRICTED; | ||
158 | |||
159 | return fuse_do_ioctl(file, cmd, arg, flags); | ||
160 | } | ||
161 | |||
162 | static long cuse_file_compat_ioctl(struct file *file, unsigned int cmd, | ||
163 | unsigned long arg) | ||
164 | { | ||
165 | struct fuse_file *ff = file->private_data; | ||
166 | struct cuse_conn *cc = fc_to_cc(ff->fc); | ||
167 | unsigned int flags = FUSE_IOCTL_COMPAT; | ||
168 | |||
169 | if (cc->unrestricted_ioctl) | ||
170 | flags |= FUSE_IOCTL_UNRESTRICTED; | ||
171 | |||
172 | return fuse_do_ioctl(file, cmd, arg, flags); | ||
173 | } | ||
174 | |||
175 | static const struct file_operations cuse_frontend_fops = { | ||
176 | .owner = THIS_MODULE, | ||
177 | .read = cuse_read, | ||
178 | .write = cuse_write, | ||
179 | .open = cuse_open, | ||
180 | .release = cuse_release, | ||
181 | .unlocked_ioctl = cuse_file_ioctl, | ||
182 | .compat_ioctl = cuse_file_compat_ioctl, | ||
183 | .poll = fuse_file_poll, | ||
184 | }; | ||
185 | |||
186 | |||
187 | /************************************************************************** | ||
188 | * CUSE channel initialization and destruction | ||
189 | */ | ||
190 | |||
191 | struct cuse_devinfo { | ||
192 | const char *name; | ||
193 | }; | ||
194 | |||
195 | /** | ||
196 | * cuse_parse_one - parse one key=value pair | ||
197 | * @pp: i/o parameter for the current position | ||
198 | * @end: points to one past the end of the packed string | ||
199 | * @keyp: out parameter for key | ||
200 | * @valp: out parameter for value | ||
201 | * | ||
202 | * *@pp points to packed strings - "key0=val0\0key1=val1\0" which ends | ||
203 | * at @end - 1. This function parses one pair and set *@keyp to the | ||
204 | * start of the key and *@valp to the start of the value. Note that | ||
205 | * the original string is modified such that the key string is | ||
206 | * terminated with '\0'. *@pp is updated to point to the next string. | ||
207 | * | ||
208 | * RETURNS: | ||
209 | * 1 on successful parse, 0 on EOF, -errno on failure. | ||
210 | */ | ||
211 | static int cuse_parse_one(char **pp, char *end, char **keyp, char **valp) | ||
212 | { | ||
213 | char *p = *pp; | ||
214 | char *key, *val; | ||
215 | |||
216 | while (p < end && *p == '\0') | ||
217 | p++; | ||
218 | if (p == end) | ||
219 | return 0; | ||
220 | |||
221 | if (end[-1] != '\0') { | ||
222 | printk(KERN_ERR "CUSE: info not properly terminated\n"); | ||
223 | return -EINVAL; | ||
224 | } | ||
225 | |||
226 | key = val = p; | ||
227 | p += strlen(p); | ||
228 | |||
229 | if (valp) { | ||
230 | strsep(&val, "="); | ||
231 | if (!val) | ||
232 | val = key + strlen(key); | ||
233 | key = strstrip(key); | ||
234 | val = strstrip(val); | ||
235 | } else | ||
236 | key = strstrip(key); | ||
237 | |||
238 | if (!strlen(key)) { | ||
239 | printk(KERN_ERR "CUSE: zero length info key specified\n"); | ||
240 | return -EINVAL; | ||
241 | } | ||
242 | |||
243 | *pp = p; | ||
244 | *keyp = key; | ||
245 | if (valp) | ||
246 | *valp = val; | ||
247 | |||
248 | return 1; | ||
249 | } | ||
250 | |||
251 | /** | ||
252 | * cuse_parse_dev_info - parse device info | ||
253 | * @p: device info string | ||
254 | * @len: length of device info string | ||
255 | * @devinfo: out parameter for parsed device info | ||
256 | * | ||
257 | * Parse @p to extract device info and store it into @devinfo. String | ||
258 | * pointed to by @p is modified by parsing and @devinfo points into | ||
259 | * them, so @p shouldn't be freed while @devinfo is in use. | ||
260 | * | ||
261 | * RETURNS: | ||
262 | * 0 on success, -errno on failure. | ||
263 | */ | ||
264 | static int cuse_parse_devinfo(char *p, size_t len, struct cuse_devinfo *devinfo) | ||
265 | { | ||
266 | char *end = p + len; | ||
267 | char *key, *val; | ||
268 | int rc; | ||
269 | |||
270 | while (true) { | ||
271 | rc = cuse_parse_one(&p, end, &key, &val); | ||
272 | if (rc < 0) | ||
273 | return rc; | ||
274 | if (!rc) | ||
275 | break; | ||
276 | if (strcmp(key, "DEVNAME") == 0) | ||
277 | devinfo->name = val; | ||
278 | else | ||
279 | printk(KERN_WARNING "CUSE: unknown device info \"%s\"\n", | ||
280 | key); | ||
281 | } | ||
282 | |||
283 | if (!devinfo->name || !strlen(devinfo->name)) { | ||
284 | printk(KERN_ERR "CUSE: DEVNAME unspecified\n"); | ||
285 | return -EINVAL; | ||
286 | } | ||
287 | |||
288 | return 0; | ||
289 | } | ||
290 | |||
291 | static void cuse_gendev_release(struct device *dev) | ||
292 | { | ||
293 | kfree(dev); | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * cuse_process_init_reply - finish initializing CUSE channel | ||
298 | * | ||
299 | * This function creates the character device and sets up all the | ||
300 | * required data structures for it. Please read the comment at the | ||
301 | * top of this file for high level overview. | ||
302 | */ | ||
303 | static void cuse_process_init_reply(struct fuse_conn *fc, struct fuse_req *req) | ||
304 | { | ||
305 | struct cuse_conn *cc = fc_to_cc(fc); | ||
306 | struct cuse_init_out *arg = &req->misc.cuse_init_out; | ||
307 | struct page *page = req->pages[0]; | ||
308 | struct cuse_devinfo devinfo = { }; | ||
309 | struct device *dev; | ||
310 | struct cdev *cdev; | ||
311 | dev_t devt; | ||
312 | int rc; | ||
313 | |||
314 | if (req->out.h.error || | ||
315 | arg->major != FUSE_KERNEL_VERSION || arg->minor < 11) { | ||
316 | goto err; | ||
317 | } | ||
318 | |||
319 | fc->minor = arg->minor; | ||
320 | fc->max_read = max_t(unsigned, arg->max_read, 4096); | ||
321 | fc->max_write = max_t(unsigned, arg->max_write, 4096); | ||
322 | |||
323 | /* parse init reply */ | ||
324 | cc->unrestricted_ioctl = arg->flags & CUSE_UNRESTRICTED_IOCTL; | ||
325 | |||
326 | rc = cuse_parse_devinfo(page_address(page), req->out.args[1].size, | ||
327 | &devinfo); | ||
328 | if (rc) | ||
329 | goto err; | ||
330 | |||
331 | /* determine and reserve devt */ | ||
332 | devt = MKDEV(arg->dev_major, arg->dev_minor); | ||
333 | if (!MAJOR(devt)) | ||
334 | rc = alloc_chrdev_region(&devt, MINOR(devt), 1, devinfo.name); | ||
335 | else | ||
336 | rc = register_chrdev_region(devt, 1, devinfo.name); | ||
337 | if (rc) { | ||
338 | printk(KERN_ERR "CUSE: failed to register chrdev region\n"); | ||
339 | goto err; | ||
340 | } | ||
341 | |||
342 | /* devt determined, create device */ | ||
343 | rc = -ENOMEM; | ||
344 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
345 | if (!dev) | ||
346 | goto err_region; | ||
347 | |||
348 | device_initialize(dev); | ||
349 | dev_set_uevent_suppress(dev, 1); | ||
350 | dev->class = cuse_class; | ||
351 | dev->devt = devt; | ||
352 | dev->release = cuse_gendev_release; | ||
353 | dev_set_drvdata(dev, cc); | ||
354 | dev_set_name(dev, "%s", devinfo.name); | ||
355 | |||
356 | rc = device_add(dev); | ||
357 | if (rc) | ||
358 | goto err_device; | ||
359 | |||
360 | /* register cdev */ | ||
361 | rc = -ENOMEM; | ||
362 | cdev = cdev_alloc(); | ||
363 | if (!cdev) | ||
364 | goto err_device; | ||
365 | |||
366 | cdev->owner = THIS_MODULE; | ||
367 | cdev->ops = &cuse_frontend_fops; | ||
368 | |||
369 | rc = cdev_add(cdev, devt, 1); | ||
370 | if (rc) | ||
371 | goto err_cdev; | ||
372 | |||
373 | cc->dev = dev; | ||
374 | cc->cdev = cdev; | ||
375 | |||
376 | /* make the device available */ | ||
377 | spin_lock(&cuse_lock); | ||
378 | list_add(&cc->list, cuse_conntbl_head(devt)); | ||
379 | spin_unlock(&cuse_lock); | ||
380 | |||
381 | /* announce device availability */ | ||
382 | dev_set_uevent_suppress(dev, 0); | ||
383 | kobject_uevent(&dev->kobj, KOBJ_ADD); | ||
384 | out: | ||
385 | __free_page(page); | ||
386 | return; | ||
387 | |||
388 | err_cdev: | ||
389 | cdev_del(cdev); | ||
390 | err_device: | ||
391 | put_device(dev); | ||
392 | err_region: | ||
393 | unregister_chrdev_region(devt, 1); | ||
394 | err: | ||
395 | fc->conn_error = 1; | ||
396 | goto out; | ||
397 | } | ||
398 | |||
399 | static int cuse_send_init(struct cuse_conn *cc) | ||
400 | { | ||
401 | int rc; | ||
402 | struct fuse_req *req; | ||
403 | struct page *page; | ||
404 | struct fuse_conn *fc = &cc->fc; | ||
405 | struct cuse_init_in *arg; | ||
406 | |||
407 | BUILD_BUG_ON(CUSE_INIT_INFO_MAX > PAGE_SIZE); | ||
408 | |||
409 | req = fuse_get_req(fc); | ||
410 | if (IS_ERR(req)) { | ||
411 | rc = PTR_ERR(req); | ||
412 | goto err; | ||
413 | } | ||
414 | |||
415 | rc = -ENOMEM; | ||
416 | page = alloc_page(GFP_KERNEL | __GFP_ZERO); | ||
417 | if (!page) | ||
418 | goto err_put_req; | ||
419 | |||
420 | arg = &req->misc.cuse_init_in; | ||
421 | arg->major = FUSE_KERNEL_VERSION; | ||
422 | arg->minor = FUSE_KERNEL_MINOR_VERSION; | ||
423 | arg->flags |= CUSE_UNRESTRICTED_IOCTL; | ||
424 | req->in.h.opcode = CUSE_INIT; | ||
425 | req->in.numargs = 1; | ||
426 | req->in.args[0].size = sizeof(struct cuse_init_in); | ||
427 | req->in.args[0].value = arg; | ||
428 | req->out.numargs = 2; | ||
429 | req->out.args[0].size = sizeof(struct cuse_init_out); | ||
430 | req->out.args[0].value = &req->misc.cuse_init_out; | ||
431 | req->out.args[1].size = CUSE_INIT_INFO_MAX; | ||
432 | req->out.argvar = 1; | ||
433 | req->out.argpages = 1; | ||
434 | req->pages[0] = page; | ||
435 | req->num_pages = 1; | ||
436 | req->end = cuse_process_init_reply; | ||
437 | fuse_request_send_background(fc, req); | ||
438 | |||
439 | return 0; | ||
440 | |||
441 | err_put_req: | ||
442 | fuse_put_request(fc, req); | ||
443 | err: | ||
444 | return rc; | ||
445 | } | ||
446 | |||
447 | static void cuse_fc_release(struct fuse_conn *fc) | ||
448 | { | ||
449 | struct cuse_conn *cc = fc_to_cc(fc); | ||
450 | kfree(cc); | ||
451 | } | ||
452 | |||
453 | /** | ||
454 | * cuse_channel_open - open method for /dev/cuse | ||
455 | * @inode: inode for /dev/cuse | ||
456 | * @file: file struct being opened | ||
457 | * | ||
458 | * Userland CUSE server can create a CUSE device by opening /dev/cuse | ||
459 | * and replying to the initilaization request kernel sends. This | ||
460 | * function is responsible for handling CUSE device initialization. | ||
461 | * Because the fd opened by this function is used during | ||
462 | * initialization, this function only creates cuse_conn and sends | ||
463 | * init. The rest is delegated to a kthread. | ||
464 | * | ||
465 | * RETURNS: | ||
466 | * 0 on success, -errno on failure. | ||
467 | */ | ||
468 | static int cuse_channel_open(struct inode *inode, struct file *file) | ||
469 | { | ||
470 | struct cuse_conn *cc; | ||
471 | int rc; | ||
472 | |||
473 | /* set up cuse_conn */ | ||
474 | cc = kzalloc(sizeof(*cc), GFP_KERNEL); | ||
475 | if (!cc) | ||
476 | return -ENOMEM; | ||
477 | |||
478 | fuse_conn_init(&cc->fc); | ||
479 | |||
480 | INIT_LIST_HEAD(&cc->list); | ||
481 | cc->fc.release = cuse_fc_release; | ||
482 | |||
483 | cc->fc.connected = 1; | ||
484 | cc->fc.blocked = 0; | ||
485 | rc = cuse_send_init(cc); | ||
486 | if (rc) { | ||
487 | fuse_conn_put(&cc->fc); | ||
488 | return rc; | ||
489 | } | ||
490 | file->private_data = &cc->fc; /* channel owns base reference to cc */ | ||
491 | |||
492 | return 0; | ||
493 | } | ||
494 | |||
495 | /** | ||
496 | * cuse_channel_release - release method for /dev/cuse | ||
497 | * @inode: inode for /dev/cuse | ||
498 | * @file: file struct being closed | ||
499 | * | ||
500 | * Disconnect the channel, deregister CUSE device and initiate | ||
501 | * destruction by putting the default reference. | ||
502 | * | ||
503 | * RETURNS: | ||
504 | * 0 on success, -errno on failure. | ||
505 | */ | ||
506 | static int cuse_channel_release(struct inode *inode, struct file *file) | ||
507 | { | ||
508 | struct cuse_conn *cc = fc_to_cc(file->private_data); | ||
509 | int rc; | ||
510 | |||
511 | /* remove from the conntbl, no more access from this point on */ | ||
512 | spin_lock(&cuse_lock); | ||
513 | list_del_init(&cc->list); | ||
514 | spin_unlock(&cuse_lock); | ||
515 | |||
516 | /* remove device */ | ||
517 | if (cc->dev) | ||
518 | device_unregister(cc->dev); | ||
519 | if (cc->cdev) { | ||
520 | unregister_chrdev_region(cc->cdev->dev, 1); | ||
521 | cdev_del(cc->cdev); | ||
522 | } | ||
523 | |||
524 | /* kill connection and shutdown channel */ | ||
525 | fuse_conn_kill(&cc->fc); | ||
526 | rc = fuse_dev_release(inode, file); /* puts the base reference */ | ||
527 | |||
528 | return rc; | ||
529 | } | ||
530 | |||
531 | static struct file_operations cuse_channel_fops; /* initialized during init */ | ||
532 | |||
533 | |||
534 | /************************************************************************** | ||
535 | * Misc stuff and module initializatiion | ||
536 | * | ||
537 | * CUSE exports the same set of attributes to sysfs as fusectl. | ||
538 | */ | ||
539 | |||
540 | static ssize_t cuse_class_waiting_show(struct device *dev, | ||
541 | struct device_attribute *attr, char *buf) | ||
542 | { | ||
543 | struct cuse_conn *cc = dev_get_drvdata(dev); | ||
544 | |||
545 | return sprintf(buf, "%d\n", atomic_read(&cc->fc.num_waiting)); | ||
546 | } | ||
547 | |||
548 | static ssize_t cuse_class_abort_store(struct device *dev, | ||
549 | struct device_attribute *attr, | ||
550 | const char *buf, size_t count) | ||
551 | { | ||
552 | struct cuse_conn *cc = dev_get_drvdata(dev); | ||
553 | |||
554 | fuse_abort_conn(&cc->fc); | ||
555 | return count; | ||
556 | } | ||
557 | |||
558 | static struct device_attribute cuse_class_dev_attrs[] = { | ||
559 | __ATTR(waiting, S_IFREG | 0400, cuse_class_waiting_show, NULL), | ||
560 | __ATTR(abort, S_IFREG | 0200, NULL, cuse_class_abort_store), | ||
561 | { } | ||
562 | }; | ||
563 | |||
564 | static struct miscdevice cuse_miscdev = { | ||
565 | .minor = MISC_DYNAMIC_MINOR, | ||
566 | .name = "cuse", | ||
567 | .fops = &cuse_channel_fops, | ||
568 | }; | ||
569 | |||
570 | static int __init cuse_init(void) | ||
571 | { | ||
572 | int i, rc; | ||
573 | |||
574 | /* init conntbl */ | ||
575 | for (i = 0; i < CUSE_CONNTBL_LEN; i++) | ||
576 | INIT_LIST_HEAD(&cuse_conntbl[i]); | ||
577 | |||
578 | /* inherit and extend fuse_dev_operations */ | ||
579 | cuse_channel_fops = fuse_dev_operations; | ||
580 | cuse_channel_fops.owner = THIS_MODULE; | ||
581 | cuse_channel_fops.open = cuse_channel_open; | ||
582 | cuse_channel_fops.release = cuse_channel_release; | ||
583 | |||
584 | cuse_class = class_create(THIS_MODULE, "cuse"); | ||
585 | if (IS_ERR(cuse_class)) | ||
586 | return PTR_ERR(cuse_class); | ||
587 | |||
588 | cuse_class->dev_attrs = cuse_class_dev_attrs; | ||
589 | |||
590 | rc = misc_register(&cuse_miscdev); | ||
591 | if (rc) { | ||
592 | class_destroy(cuse_class); | ||
593 | return rc; | ||
594 | } | ||
595 | |||
596 | return 0; | ||
597 | } | ||
598 | |||
599 | static void __exit cuse_exit(void) | ||
600 | { | ||
601 | misc_deregister(&cuse_miscdev); | ||
602 | class_destroy(cuse_class); | ||
603 | } | ||
604 | |||
605 | module_init(cuse_init); | ||
606 | module_exit(cuse_exit); | ||
607 | |||
608 | MODULE_AUTHOR("Tejun Heo <tj@kernel.org>"); | ||
609 | MODULE_DESCRIPTION("Character device in Userspace"); | ||
610 | MODULE_LICENSE("GPL"); | ||
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index ba76b68c52ff..8fed2ed12f38 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c | |||
@@ -46,6 +46,7 @@ struct fuse_req *fuse_request_alloc(void) | |||
46 | fuse_request_init(req); | 46 | fuse_request_init(req); |
47 | return req; | 47 | return req; |
48 | } | 48 | } |
49 | EXPORT_SYMBOL_GPL(fuse_request_alloc); | ||
49 | 50 | ||
50 | struct fuse_req *fuse_request_alloc_nofs(void) | 51 | struct fuse_req *fuse_request_alloc_nofs(void) |
51 | { | 52 | { |
@@ -124,6 +125,7 @@ struct fuse_req *fuse_get_req(struct fuse_conn *fc) | |||
124 | atomic_dec(&fc->num_waiting); | 125 | atomic_dec(&fc->num_waiting); |
125 | return ERR_PTR(err); | 126 | return ERR_PTR(err); |
126 | } | 127 | } |
128 | EXPORT_SYMBOL_GPL(fuse_get_req); | ||
127 | 129 | ||
128 | /* | 130 | /* |
129 | * Return request in fuse_file->reserved_req. However that may | 131 | * Return request in fuse_file->reserved_req. However that may |
@@ -208,6 +210,7 @@ void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req) | |||
208 | fuse_request_free(req); | 210 | fuse_request_free(req); |
209 | } | 211 | } |
210 | } | 212 | } |
213 | EXPORT_SYMBOL_GPL(fuse_put_request); | ||
211 | 214 | ||
212 | static unsigned len_args(unsigned numargs, struct fuse_arg *args) | 215 | static unsigned len_args(unsigned numargs, struct fuse_arg *args) |
213 | { | 216 | { |
@@ -282,7 +285,7 @@ __releases(&fc->lock) | |||
282 | wake_up_all(&fc->blocked_waitq); | 285 | wake_up_all(&fc->blocked_waitq); |
283 | } | 286 | } |
284 | if (fc->num_background == FUSE_CONGESTION_THRESHOLD && | 287 | if (fc->num_background == FUSE_CONGESTION_THRESHOLD && |
285 | fc->connected) { | 288 | fc->connected && fc->bdi_initialized) { |
286 | clear_bdi_congested(&fc->bdi, READ); | 289 | clear_bdi_congested(&fc->bdi, READ); |
287 | clear_bdi_congested(&fc->bdi, WRITE); | 290 | clear_bdi_congested(&fc->bdi, WRITE); |
288 | } | 291 | } |
@@ -400,6 +403,7 @@ void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req) | |||
400 | } | 403 | } |
401 | spin_unlock(&fc->lock); | 404 | spin_unlock(&fc->lock); |
402 | } | 405 | } |
406 | EXPORT_SYMBOL_GPL(fuse_request_send); | ||
403 | 407 | ||
404 | static void fuse_request_send_nowait_locked(struct fuse_conn *fc, | 408 | static void fuse_request_send_nowait_locked(struct fuse_conn *fc, |
405 | struct fuse_req *req) | 409 | struct fuse_req *req) |
@@ -408,7 +412,8 @@ static void fuse_request_send_nowait_locked(struct fuse_conn *fc, | |||
408 | fc->num_background++; | 412 | fc->num_background++; |
409 | if (fc->num_background == FUSE_MAX_BACKGROUND) | 413 | if (fc->num_background == FUSE_MAX_BACKGROUND) |
410 | fc->blocked = 1; | 414 | fc->blocked = 1; |
411 | if (fc->num_background == FUSE_CONGESTION_THRESHOLD) { | 415 | if (fc->num_background == FUSE_CONGESTION_THRESHOLD && |
416 | fc->bdi_initialized) { | ||
412 | set_bdi_congested(&fc->bdi, READ); | 417 | set_bdi_congested(&fc->bdi, READ); |
413 | set_bdi_congested(&fc->bdi, WRITE); | 418 | set_bdi_congested(&fc->bdi, WRITE); |
414 | } | 419 | } |
@@ -439,6 +444,7 @@ void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req) | |||
439 | req->isreply = 1; | 444 | req->isreply = 1; |
440 | fuse_request_send_nowait(fc, req); | 445 | fuse_request_send_nowait(fc, req); |
441 | } | 446 | } |
447 | EXPORT_SYMBOL_GPL(fuse_request_send_background); | ||
442 | 448 | ||
443 | /* | 449 | /* |
444 | * Called under fc->lock | 450 | * Called under fc->lock |
@@ -1105,8 +1111,9 @@ void fuse_abort_conn(struct fuse_conn *fc) | |||
1105 | } | 1111 | } |
1106 | spin_unlock(&fc->lock); | 1112 | spin_unlock(&fc->lock); |
1107 | } | 1113 | } |
1114 | EXPORT_SYMBOL_GPL(fuse_abort_conn); | ||
1108 | 1115 | ||
1109 | static int fuse_dev_release(struct inode *inode, struct file *file) | 1116 | int fuse_dev_release(struct inode *inode, struct file *file) |
1110 | { | 1117 | { |
1111 | struct fuse_conn *fc = fuse_get_conn(file); | 1118 | struct fuse_conn *fc = fuse_get_conn(file); |
1112 | if (fc) { | 1119 | if (fc) { |
@@ -1120,6 +1127,7 @@ static int fuse_dev_release(struct inode *inode, struct file *file) | |||
1120 | 1127 | ||
1121 | return 0; | 1128 | return 0; |
1122 | } | 1129 | } |
1130 | EXPORT_SYMBOL_GPL(fuse_dev_release); | ||
1123 | 1131 | ||
1124 | static int fuse_dev_fasync(int fd, struct file *file, int on) | 1132 | static int fuse_dev_fasync(int fd, struct file *file, int on) |
1125 | { | 1133 | { |
@@ -1142,6 +1150,7 @@ const struct file_operations fuse_dev_operations = { | |||
1142 | .release = fuse_dev_release, | 1150 | .release = fuse_dev_release, |
1143 | .fasync = fuse_dev_fasync, | 1151 | .fasync = fuse_dev_fasync, |
1144 | }; | 1152 | }; |
1153 | EXPORT_SYMBOL_GPL(fuse_dev_operations); | ||
1145 | 1154 | ||
1146 | static struct miscdevice fuse_miscdevice = { | 1155 | static struct miscdevice fuse_miscdevice = { |
1147 | .minor = FUSE_MINOR, | 1156 | .minor = FUSE_MINOR, |
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 8b8eebc5614b..b3089a083d30 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c | |||
@@ -362,19 +362,6 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, | |||
362 | } | 362 | } |
363 | 363 | ||
364 | /* | 364 | /* |
365 | * Synchronous release for the case when something goes wrong in CREATE_OPEN | ||
366 | */ | ||
367 | static void fuse_sync_release(struct fuse_conn *fc, struct fuse_file *ff, | ||
368 | u64 nodeid, int flags) | ||
369 | { | ||
370 | fuse_release_fill(ff, nodeid, flags, FUSE_RELEASE); | ||
371 | ff->reserved_req->force = 1; | ||
372 | fuse_request_send(fc, ff->reserved_req); | ||
373 | fuse_put_request(fc, ff->reserved_req); | ||
374 | kfree(ff); | ||
375 | } | ||
376 | |||
377 | /* | ||
378 | * Atomic create+open operation | 365 | * Atomic create+open operation |
379 | * | 366 | * |
380 | * If the filesystem doesn't support this, then fall back to separate | 367 | * If the filesystem doesn't support this, then fall back to separate |
@@ -445,12 +432,14 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode, | |||
445 | goto out_free_ff; | 432 | goto out_free_ff; |
446 | 433 | ||
447 | fuse_put_request(fc, req); | 434 | fuse_put_request(fc, req); |
435 | ff->fh = outopen.fh; | ||
436 | ff->nodeid = outentry.nodeid; | ||
437 | ff->open_flags = outopen.open_flags; | ||
448 | inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation, | 438 | inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation, |
449 | &outentry.attr, entry_attr_timeout(&outentry), 0); | 439 | &outentry.attr, entry_attr_timeout(&outentry), 0); |
450 | if (!inode) { | 440 | if (!inode) { |
451 | flags &= ~(O_CREAT | O_EXCL | O_TRUNC); | 441 | flags &= ~(O_CREAT | O_EXCL | O_TRUNC); |
452 | ff->fh = outopen.fh; | 442 | fuse_sync_release(ff, flags); |
453 | fuse_sync_release(fc, ff, outentry.nodeid, flags); | ||
454 | fuse_send_forget(fc, forget_req, outentry.nodeid, 1); | 443 | fuse_send_forget(fc, forget_req, outentry.nodeid, 1); |
455 | return -ENOMEM; | 444 | return -ENOMEM; |
456 | } | 445 | } |
@@ -460,11 +449,11 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode, | |||
460 | fuse_invalidate_attr(dir); | 449 | fuse_invalidate_attr(dir); |
461 | file = lookup_instantiate_filp(nd, entry, generic_file_open); | 450 | file = lookup_instantiate_filp(nd, entry, generic_file_open); |
462 | if (IS_ERR(file)) { | 451 | if (IS_ERR(file)) { |
463 | ff->fh = outopen.fh; | 452 | fuse_sync_release(ff, flags); |
464 | fuse_sync_release(fc, ff, outentry.nodeid, flags); | ||
465 | return PTR_ERR(file); | 453 | return PTR_ERR(file); |
466 | } | 454 | } |
467 | fuse_finish_open(inode, file, ff, &outopen); | 455 | file->private_data = fuse_file_get(ff); |
456 | fuse_finish_open(inode, file); | ||
468 | return 0; | 457 | return 0; |
469 | 458 | ||
470 | out_free_ff: | 459 | out_free_ff: |
@@ -1035,7 +1024,7 @@ static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir) | |||
1035 | req->out.argpages = 1; | 1024 | req->out.argpages = 1; |
1036 | req->num_pages = 1; | 1025 | req->num_pages = 1; |
1037 | req->pages[0] = page; | 1026 | req->pages[0] = page; |
1038 | fuse_read_fill(req, file, inode, file->f_pos, PAGE_SIZE, FUSE_READDIR); | 1027 | fuse_read_fill(req, file, file->f_pos, PAGE_SIZE, FUSE_READDIR); |
1039 | fuse_request_send(fc, req); | 1028 | fuse_request_send(fc, req); |
1040 | nbytes = req->out.args[0].size; | 1029 | nbytes = req->out.args[0].size; |
1041 | err = req->out.h.error; | 1030 | err = req->out.h.error; |
@@ -1101,12 +1090,14 @@ static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c) | |||
1101 | 1090 | ||
1102 | static int fuse_dir_open(struct inode *inode, struct file *file) | 1091 | static int fuse_dir_open(struct inode *inode, struct file *file) |
1103 | { | 1092 | { |
1104 | return fuse_open_common(inode, file, 1); | 1093 | return fuse_open_common(inode, file, true); |
1105 | } | 1094 | } |
1106 | 1095 | ||
1107 | static int fuse_dir_release(struct inode *inode, struct file *file) | 1096 | static int fuse_dir_release(struct inode *inode, struct file *file) |
1108 | { | 1097 | { |
1109 | return fuse_release_common(inode, file, 1); | 1098 | fuse_release_common(file, FUSE_RELEASEDIR); |
1099 | |||
1100 | return 0; | ||
1110 | } | 1101 | } |
1111 | 1102 | ||
1112 | static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync) | 1103 | static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync) |
diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 06f30e965676..fce6ce694fde 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c | |||
@@ -12,13 +12,13 @@ | |||
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/sched.h> | 14 | #include <linux/sched.h> |
15 | #include <linux/module.h> | ||
15 | 16 | ||
16 | static const struct file_operations fuse_direct_io_file_operations; | 17 | static const struct file_operations fuse_direct_io_file_operations; |
17 | 18 | ||
18 | static int fuse_send_open(struct inode *inode, struct file *file, int isdir, | 19 | static int fuse_send_open(struct fuse_conn *fc, u64 nodeid, struct file *file, |
19 | struct fuse_open_out *outargp) | 20 | int opcode, struct fuse_open_out *outargp) |
20 | { | 21 | { |
21 | struct fuse_conn *fc = get_fuse_conn(inode); | ||
22 | struct fuse_open_in inarg; | 22 | struct fuse_open_in inarg; |
23 | struct fuse_req *req; | 23 | struct fuse_req *req; |
24 | int err; | 24 | int err; |
@@ -31,8 +31,8 @@ static int fuse_send_open(struct inode *inode, struct file *file, int isdir, | |||
31 | inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY); | 31 | inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY); |
32 | if (!fc->atomic_o_trunc) | 32 | if (!fc->atomic_o_trunc) |
33 | inarg.flags &= ~O_TRUNC; | 33 | inarg.flags &= ~O_TRUNC; |
34 | req->in.h.opcode = isdir ? FUSE_OPENDIR : FUSE_OPEN; | 34 | req->in.h.opcode = opcode; |
35 | req->in.h.nodeid = get_node_id(inode); | 35 | req->in.h.nodeid = nodeid; |
36 | req->in.numargs = 1; | 36 | req->in.numargs = 1; |
37 | req->in.args[0].size = sizeof(inarg); | 37 | req->in.args[0].size = sizeof(inarg); |
38 | req->in.args[0].value = &inarg; | 38 | req->in.args[0].value = &inarg; |
@@ -49,22 +49,27 @@ static int fuse_send_open(struct inode *inode, struct file *file, int isdir, | |||
49 | struct fuse_file *fuse_file_alloc(struct fuse_conn *fc) | 49 | struct fuse_file *fuse_file_alloc(struct fuse_conn *fc) |
50 | { | 50 | { |
51 | struct fuse_file *ff; | 51 | struct fuse_file *ff; |
52 | |||
52 | ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL); | 53 | ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL); |
53 | if (ff) { | 54 | if (unlikely(!ff)) |
54 | ff->reserved_req = fuse_request_alloc(); | 55 | return NULL; |
55 | if (!ff->reserved_req) { | 56 | |
56 | kfree(ff); | 57 | ff->fc = fc; |
57 | return NULL; | 58 | ff->reserved_req = fuse_request_alloc(); |
58 | } else { | 59 | if (unlikely(!ff->reserved_req)) { |
59 | INIT_LIST_HEAD(&ff->write_entry); | 60 | kfree(ff); |
60 | atomic_set(&ff->count, 0); | 61 | return NULL; |
61 | spin_lock(&fc->lock); | ||
62 | ff->kh = ++fc->khctr; | ||
63 | spin_unlock(&fc->lock); | ||
64 | } | ||
65 | RB_CLEAR_NODE(&ff->polled_node); | ||
66 | init_waitqueue_head(&ff->poll_wait); | ||
67 | } | 62 | } |
63 | |||
64 | INIT_LIST_HEAD(&ff->write_entry); | ||
65 | atomic_set(&ff->count, 0); | ||
66 | RB_CLEAR_NODE(&ff->polled_node); | ||
67 | init_waitqueue_head(&ff->poll_wait); | ||
68 | |||
69 | spin_lock(&fc->lock); | ||
70 | ff->kh = ++fc->khctr; | ||
71 | spin_unlock(&fc->lock); | ||
72 | |||
68 | return ff; | 73 | return ff; |
69 | } | 74 | } |
70 | 75 | ||
@@ -74,7 +79,7 @@ void fuse_file_free(struct fuse_file *ff) | |||
74 | kfree(ff); | 79 | kfree(ff); |
75 | } | 80 | } |
76 | 81 | ||
77 | static struct fuse_file *fuse_file_get(struct fuse_file *ff) | 82 | struct fuse_file *fuse_file_get(struct fuse_file *ff) |
78 | { | 83 | { |
79 | atomic_inc(&ff->count); | 84 | atomic_inc(&ff->count); |
80 | return ff; | 85 | return ff; |
@@ -82,40 +87,65 @@ static struct fuse_file *fuse_file_get(struct fuse_file *ff) | |||
82 | 87 | ||
83 | static void fuse_release_end(struct fuse_conn *fc, struct fuse_req *req) | 88 | static void fuse_release_end(struct fuse_conn *fc, struct fuse_req *req) |
84 | { | 89 | { |
85 | dput(req->misc.release.dentry); | 90 | path_put(&req->misc.release.path); |
86 | mntput(req->misc.release.vfsmount); | ||
87 | } | 91 | } |
88 | 92 | ||
89 | static void fuse_file_put(struct fuse_file *ff) | 93 | static void fuse_file_put(struct fuse_file *ff) |
90 | { | 94 | { |
91 | if (atomic_dec_and_test(&ff->count)) { | 95 | if (atomic_dec_and_test(&ff->count)) { |
92 | struct fuse_req *req = ff->reserved_req; | 96 | struct fuse_req *req = ff->reserved_req; |
93 | struct inode *inode = req->misc.release.dentry->d_inode; | 97 | |
94 | struct fuse_conn *fc = get_fuse_conn(inode); | ||
95 | req->end = fuse_release_end; | 98 | req->end = fuse_release_end; |
96 | fuse_request_send_background(fc, req); | 99 | fuse_request_send_background(ff->fc, req); |
97 | kfree(ff); | 100 | kfree(ff); |
98 | } | 101 | } |
99 | } | 102 | } |
100 | 103 | ||
101 | void fuse_finish_open(struct inode *inode, struct file *file, | 104 | int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, |
102 | struct fuse_file *ff, struct fuse_open_out *outarg) | 105 | bool isdir) |
103 | { | 106 | { |
104 | if (outarg->open_flags & FOPEN_DIRECT_IO) | 107 | struct fuse_open_out outarg; |
108 | struct fuse_file *ff; | ||
109 | int err; | ||
110 | int opcode = isdir ? FUSE_OPENDIR : FUSE_OPEN; | ||
111 | |||
112 | ff = fuse_file_alloc(fc); | ||
113 | if (!ff) | ||
114 | return -ENOMEM; | ||
115 | |||
116 | err = fuse_send_open(fc, nodeid, file, opcode, &outarg); | ||
117 | if (err) { | ||
118 | fuse_file_free(ff); | ||
119 | return err; | ||
120 | } | ||
121 | |||
122 | if (isdir) | ||
123 | outarg.open_flags &= ~FOPEN_DIRECT_IO; | ||
124 | |||
125 | ff->fh = outarg.fh; | ||
126 | ff->nodeid = nodeid; | ||
127 | ff->open_flags = outarg.open_flags; | ||
128 | file->private_data = fuse_file_get(ff); | ||
129 | |||
130 | return 0; | ||
131 | } | ||
132 | EXPORT_SYMBOL_GPL(fuse_do_open); | ||
133 | |||
134 | void fuse_finish_open(struct inode *inode, struct file *file) | ||
135 | { | ||
136 | struct fuse_file *ff = file->private_data; | ||
137 | |||
138 | if (ff->open_flags & FOPEN_DIRECT_IO) | ||
105 | file->f_op = &fuse_direct_io_file_operations; | 139 | file->f_op = &fuse_direct_io_file_operations; |
106 | if (!(outarg->open_flags & FOPEN_KEEP_CACHE)) | 140 | if (!(ff->open_flags & FOPEN_KEEP_CACHE)) |
107 | invalidate_inode_pages2(inode->i_mapping); | 141 | invalidate_inode_pages2(inode->i_mapping); |
108 | if (outarg->open_flags & FOPEN_NONSEEKABLE) | 142 | if (ff->open_flags & FOPEN_NONSEEKABLE) |
109 | nonseekable_open(inode, file); | 143 | nonseekable_open(inode, file); |
110 | ff->fh = outarg->fh; | ||
111 | file->private_data = fuse_file_get(ff); | ||
112 | } | 144 | } |
113 | 145 | ||
114 | int fuse_open_common(struct inode *inode, struct file *file, int isdir) | 146 | int fuse_open_common(struct inode *inode, struct file *file, bool isdir) |
115 | { | 147 | { |
116 | struct fuse_conn *fc = get_fuse_conn(inode); | 148 | struct fuse_conn *fc = get_fuse_conn(inode); |
117 | struct fuse_open_out outarg; | ||
118 | struct fuse_file *ff; | ||
119 | int err; | 149 | int err; |
120 | 150 | ||
121 | /* VFS checks this, but only _after_ ->open() */ | 151 | /* VFS checks this, but only _after_ ->open() */ |
@@ -126,78 +156,85 @@ int fuse_open_common(struct inode *inode, struct file *file, int isdir) | |||
126 | if (err) | 156 | if (err) |
127 | return err; | 157 | return err; |
128 | 158 | ||
129 | ff = fuse_file_alloc(fc); | 159 | err = fuse_do_open(fc, get_node_id(inode), file, isdir); |
130 | if (!ff) | ||
131 | return -ENOMEM; | ||
132 | |||
133 | err = fuse_send_open(inode, file, isdir, &outarg); | ||
134 | if (err) | 160 | if (err) |
135 | fuse_file_free(ff); | 161 | return err; |
136 | else { | ||
137 | if (isdir) | ||
138 | outarg.open_flags &= ~FOPEN_DIRECT_IO; | ||
139 | fuse_finish_open(inode, file, ff, &outarg); | ||
140 | } | ||
141 | 162 | ||
142 | return err; | 163 | fuse_finish_open(inode, file); |
164 | |||
165 | return 0; | ||
143 | } | 166 | } |
144 | 167 | ||
145 | void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode) | 168 | static void fuse_prepare_release(struct fuse_file *ff, int flags, int opcode) |
146 | { | 169 | { |
170 | struct fuse_conn *fc = ff->fc; | ||
147 | struct fuse_req *req = ff->reserved_req; | 171 | struct fuse_req *req = ff->reserved_req; |
148 | struct fuse_release_in *inarg = &req->misc.release.in; | 172 | struct fuse_release_in *inarg = &req->misc.release.in; |
149 | 173 | ||
174 | spin_lock(&fc->lock); | ||
175 | list_del(&ff->write_entry); | ||
176 | if (!RB_EMPTY_NODE(&ff->polled_node)) | ||
177 | rb_erase(&ff->polled_node, &fc->polled_files); | ||
178 | spin_unlock(&fc->lock); | ||
179 | |||
180 | wake_up_interruptible_sync(&ff->poll_wait); | ||
181 | |||
150 | inarg->fh = ff->fh; | 182 | inarg->fh = ff->fh; |
151 | inarg->flags = flags; | 183 | inarg->flags = flags; |
152 | req->in.h.opcode = opcode; | 184 | req->in.h.opcode = opcode; |
153 | req->in.h.nodeid = nodeid; | 185 | req->in.h.nodeid = ff->nodeid; |
154 | req->in.numargs = 1; | 186 | req->in.numargs = 1; |
155 | req->in.args[0].size = sizeof(struct fuse_release_in); | 187 | req->in.args[0].size = sizeof(struct fuse_release_in); |
156 | req->in.args[0].value = inarg; | 188 | req->in.args[0].value = inarg; |
157 | } | 189 | } |
158 | 190 | ||
159 | int fuse_release_common(struct inode *inode, struct file *file, int isdir) | 191 | void fuse_release_common(struct file *file, int opcode) |
160 | { | 192 | { |
161 | struct fuse_file *ff = file->private_data; | 193 | struct fuse_file *ff; |
162 | if (ff) { | 194 | struct fuse_req *req; |
163 | struct fuse_conn *fc = get_fuse_conn(inode); | ||
164 | struct fuse_req *req = ff->reserved_req; | ||
165 | |||
166 | fuse_release_fill(ff, get_node_id(inode), file->f_flags, | ||
167 | isdir ? FUSE_RELEASEDIR : FUSE_RELEASE); | ||
168 | 195 | ||
169 | /* Hold vfsmount and dentry until release is finished */ | 196 | ff = file->private_data; |
170 | req->misc.release.vfsmount = mntget(file->f_path.mnt); | 197 | if (unlikely(!ff)) |
171 | req->misc.release.dentry = dget(file->f_path.dentry); | 198 | return; |
172 | 199 | ||
173 | spin_lock(&fc->lock); | 200 | req = ff->reserved_req; |
174 | list_del(&ff->write_entry); | 201 | fuse_prepare_release(ff, file->f_flags, opcode); |
175 | if (!RB_EMPTY_NODE(&ff->polled_node)) | ||
176 | rb_erase(&ff->polled_node, &fc->polled_files); | ||
177 | spin_unlock(&fc->lock); | ||
178 | 202 | ||
179 | wake_up_interruptible_sync(&ff->poll_wait); | 203 | /* Hold vfsmount and dentry until release is finished */ |
180 | /* | 204 | path_get(&file->f_path); |
181 | * Normally this will send the RELEASE request, | 205 | req->misc.release.path = file->f_path; |
182 | * however if some asynchronous READ or WRITE requests | ||
183 | * are outstanding, the sending will be delayed | ||
184 | */ | ||
185 | fuse_file_put(ff); | ||
186 | } | ||
187 | 206 | ||
188 | /* Return value is ignored by VFS */ | 207 | /* |
189 | return 0; | 208 | * Normally this will send the RELEASE request, however if |
209 | * some asynchronous READ or WRITE requests are outstanding, | ||
210 | * the sending will be delayed. | ||
211 | */ | ||
212 | fuse_file_put(ff); | ||
190 | } | 213 | } |
191 | 214 | ||
192 | static int fuse_open(struct inode *inode, struct file *file) | 215 | static int fuse_open(struct inode *inode, struct file *file) |
193 | { | 216 | { |
194 | return fuse_open_common(inode, file, 0); | 217 | return fuse_open_common(inode, file, false); |
195 | } | 218 | } |
196 | 219 | ||
197 | static int fuse_release(struct inode *inode, struct file *file) | 220 | static int fuse_release(struct inode *inode, struct file *file) |
198 | { | 221 | { |
199 | return fuse_release_common(inode, file, 0); | 222 | fuse_release_common(file, FUSE_RELEASE); |
223 | |||
224 | /* return value is ignored by VFS */ | ||
225 | return 0; | ||
226 | } | ||
227 | |||
228 | void fuse_sync_release(struct fuse_file *ff, int flags) | ||
229 | { | ||
230 | WARN_ON(atomic_read(&ff->count) > 1); | ||
231 | fuse_prepare_release(ff, flags, FUSE_RELEASE); | ||
232 | ff->reserved_req->force = 1; | ||
233 | fuse_request_send(ff->fc, ff->reserved_req); | ||
234 | fuse_put_request(ff->fc, ff->reserved_req); | ||
235 | kfree(ff); | ||
200 | } | 236 | } |
237 | EXPORT_SYMBOL_GPL(fuse_sync_release); | ||
201 | 238 | ||
202 | /* | 239 | /* |
203 | * Scramble the ID space with XTEA, so that the value of the files_struct | 240 | * Scramble the ID space with XTEA, so that the value of the files_struct |
@@ -371,8 +408,8 @@ static int fuse_fsync(struct file *file, struct dentry *de, int datasync) | |||
371 | return fuse_fsync_common(file, de, datasync, 0); | 408 | return fuse_fsync_common(file, de, datasync, 0); |
372 | } | 409 | } |
373 | 410 | ||
374 | void fuse_read_fill(struct fuse_req *req, struct file *file, | 411 | void fuse_read_fill(struct fuse_req *req, struct file *file, loff_t pos, |
375 | struct inode *inode, loff_t pos, size_t count, int opcode) | 412 | size_t count, int opcode) |
376 | { | 413 | { |
377 | struct fuse_read_in *inarg = &req->misc.read.in; | 414 | struct fuse_read_in *inarg = &req->misc.read.in; |
378 | struct fuse_file *ff = file->private_data; | 415 | struct fuse_file *ff = file->private_data; |
@@ -382,7 +419,7 @@ void fuse_read_fill(struct fuse_req *req, struct file *file, | |||
382 | inarg->size = count; | 419 | inarg->size = count; |
383 | inarg->flags = file->f_flags; | 420 | inarg->flags = file->f_flags; |
384 | req->in.h.opcode = opcode; | 421 | req->in.h.opcode = opcode; |
385 | req->in.h.nodeid = get_node_id(inode); | 422 | req->in.h.nodeid = ff->nodeid; |
386 | req->in.numargs = 1; | 423 | req->in.numargs = 1; |
387 | req->in.args[0].size = sizeof(struct fuse_read_in); | 424 | req->in.args[0].size = sizeof(struct fuse_read_in); |
388 | req->in.args[0].value = inarg; | 425 | req->in.args[0].value = inarg; |
@@ -392,12 +429,12 @@ void fuse_read_fill(struct fuse_req *req, struct file *file, | |||
392 | } | 429 | } |
393 | 430 | ||
394 | static size_t fuse_send_read(struct fuse_req *req, struct file *file, | 431 | static size_t fuse_send_read(struct fuse_req *req, struct file *file, |
395 | struct inode *inode, loff_t pos, size_t count, | 432 | loff_t pos, size_t count, fl_owner_t owner) |
396 | fl_owner_t owner) | ||
397 | { | 433 | { |
398 | struct fuse_conn *fc = get_fuse_conn(inode); | 434 | struct fuse_file *ff = file->private_data; |
435 | struct fuse_conn *fc = ff->fc; | ||
399 | 436 | ||
400 | fuse_read_fill(req, file, inode, pos, count, FUSE_READ); | 437 | fuse_read_fill(req, file, pos, count, FUSE_READ); |
401 | if (owner != NULL) { | 438 | if (owner != NULL) { |
402 | struct fuse_read_in *inarg = &req->misc.read.in; | 439 | struct fuse_read_in *inarg = &req->misc.read.in; |
403 | 440 | ||
@@ -455,7 +492,7 @@ static int fuse_readpage(struct file *file, struct page *page) | |||
455 | req->out.argpages = 1; | 492 | req->out.argpages = 1; |
456 | req->num_pages = 1; | 493 | req->num_pages = 1; |
457 | req->pages[0] = page; | 494 | req->pages[0] = page; |
458 | num_read = fuse_send_read(req, file, inode, pos, count, NULL); | 495 | num_read = fuse_send_read(req, file, pos, count, NULL); |
459 | err = req->out.h.error; | 496 | err = req->out.h.error; |
460 | fuse_put_request(fc, req); | 497 | fuse_put_request(fc, req); |
461 | 498 | ||
@@ -504,19 +541,18 @@ static void fuse_readpages_end(struct fuse_conn *fc, struct fuse_req *req) | |||
504 | fuse_file_put(req->ff); | 541 | fuse_file_put(req->ff); |
505 | } | 542 | } |
506 | 543 | ||
507 | static void fuse_send_readpages(struct fuse_req *req, struct file *file, | 544 | static void fuse_send_readpages(struct fuse_req *req, struct file *file) |
508 | struct inode *inode) | ||
509 | { | 545 | { |
510 | struct fuse_conn *fc = get_fuse_conn(inode); | 546 | struct fuse_file *ff = file->private_data; |
547 | struct fuse_conn *fc = ff->fc; | ||
511 | loff_t pos = page_offset(req->pages[0]); | 548 | loff_t pos = page_offset(req->pages[0]); |
512 | size_t count = req->num_pages << PAGE_CACHE_SHIFT; | 549 | size_t count = req->num_pages << PAGE_CACHE_SHIFT; |
513 | 550 | ||
514 | req->out.argpages = 1; | 551 | req->out.argpages = 1; |
515 | req->out.page_zeroing = 1; | 552 | req->out.page_zeroing = 1; |
516 | fuse_read_fill(req, file, inode, pos, count, FUSE_READ); | 553 | fuse_read_fill(req, file, pos, count, FUSE_READ); |
517 | req->misc.read.attr_ver = fuse_get_attr_version(fc); | 554 | req->misc.read.attr_ver = fuse_get_attr_version(fc); |
518 | if (fc->async_read) { | 555 | if (fc->async_read) { |
519 | struct fuse_file *ff = file->private_data; | ||
520 | req->ff = fuse_file_get(ff); | 556 | req->ff = fuse_file_get(ff); |
521 | req->end = fuse_readpages_end; | 557 | req->end = fuse_readpages_end; |
522 | fuse_request_send_background(fc, req); | 558 | fuse_request_send_background(fc, req); |
@@ -546,7 +582,7 @@ static int fuse_readpages_fill(void *_data, struct page *page) | |||
546 | (req->num_pages == FUSE_MAX_PAGES_PER_REQ || | 582 | (req->num_pages == FUSE_MAX_PAGES_PER_REQ || |
547 | (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read || | 583 | (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read || |
548 | req->pages[req->num_pages - 1]->index + 1 != page->index)) { | 584 | req->pages[req->num_pages - 1]->index + 1 != page->index)) { |
549 | fuse_send_readpages(req, data->file, inode); | 585 | fuse_send_readpages(req, data->file); |
550 | data->req = req = fuse_get_req(fc); | 586 | data->req = req = fuse_get_req(fc); |
551 | if (IS_ERR(req)) { | 587 | if (IS_ERR(req)) { |
552 | unlock_page(page); | 588 | unlock_page(page); |
@@ -580,7 +616,7 @@ static int fuse_readpages(struct file *file, struct address_space *mapping, | |||
580 | err = read_cache_pages(mapping, pages, fuse_readpages_fill, &data); | 616 | err = read_cache_pages(mapping, pages, fuse_readpages_fill, &data); |
581 | if (!err) { | 617 | if (!err) { |
582 | if (data.req->num_pages) | 618 | if (data.req->num_pages) |
583 | fuse_send_readpages(data.req, file, inode); | 619 | fuse_send_readpages(data.req, file); |
584 | else | 620 | else |
585 | fuse_put_request(fc, data.req); | 621 | fuse_put_request(fc, data.req); |
586 | } | 622 | } |
@@ -607,24 +643,19 @@ static ssize_t fuse_file_aio_read(struct kiocb *iocb, const struct iovec *iov, | |||
607 | return generic_file_aio_read(iocb, iov, nr_segs, pos); | 643 | return generic_file_aio_read(iocb, iov, nr_segs, pos); |
608 | } | 644 | } |
609 | 645 | ||
610 | static void fuse_write_fill(struct fuse_req *req, struct file *file, | 646 | static void fuse_write_fill(struct fuse_req *req, struct fuse_file *ff, |
611 | struct fuse_file *ff, struct inode *inode, | 647 | loff_t pos, size_t count) |
612 | loff_t pos, size_t count, int writepage) | ||
613 | { | 648 | { |
614 | struct fuse_conn *fc = get_fuse_conn(inode); | ||
615 | struct fuse_write_in *inarg = &req->misc.write.in; | 649 | struct fuse_write_in *inarg = &req->misc.write.in; |
616 | struct fuse_write_out *outarg = &req->misc.write.out; | 650 | struct fuse_write_out *outarg = &req->misc.write.out; |
617 | 651 | ||
618 | memset(inarg, 0, sizeof(struct fuse_write_in)); | ||
619 | inarg->fh = ff->fh; | 652 | inarg->fh = ff->fh; |
620 | inarg->offset = pos; | 653 | inarg->offset = pos; |
621 | inarg->size = count; | 654 | inarg->size = count; |
622 | inarg->write_flags = writepage ? FUSE_WRITE_CACHE : 0; | ||
623 | inarg->flags = file ? file->f_flags : 0; | ||
624 | req->in.h.opcode = FUSE_WRITE; | 655 | req->in.h.opcode = FUSE_WRITE; |
625 | req->in.h.nodeid = get_node_id(inode); | 656 | req->in.h.nodeid = ff->nodeid; |
626 | req->in.numargs = 2; | 657 | req->in.numargs = 2; |
627 | if (fc->minor < 9) | 658 | if (ff->fc->minor < 9) |
628 | req->in.args[0].size = FUSE_COMPAT_WRITE_IN_SIZE; | 659 | req->in.args[0].size = FUSE_COMPAT_WRITE_IN_SIZE; |
629 | else | 660 | else |
630 | req->in.args[0].size = sizeof(struct fuse_write_in); | 661 | req->in.args[0].size = sizeof(struct fuse_write_in); |
@@ -636,13 +667,15 @@ static void fuse_write_fill(struct fuse_req *req, struct file *file, | |||
636 | } | 667 | } |
637 | 668 | ||
638 | static size_t fuse_send_write(struct fuse_req *req, struct file *file, | 669 | static size_t fuse_send_write(struct fuse_req *req, struct file *file, |
639 | struct inode *inode, loff_t pos, size_t count, | 670 | loff_t pos, size_t count, fl_owner_t owner) |
640 | fl_owner_t owner) | ||
641 | { | 671 | { |
642 | struct fuse_conn *fc = get_fuse_conn(inode); | 672 | struct fuse_file *ff = file->private_data; |
643 | fuse_write_fill(req, file, file->private_data, inode, pos, count, 0); | 673 | struct fuse_conn *fc = ff->fc; |
674 | struct fuse_write_in *inarg = &req->misc.write.in; | ||
675 | |||
676 | fuse_write_fill(req, ff, pos, count); | ||
677 | inarg->flags = file->f_flags; | ||
644 | if (owner != NULL) { | 678 | if (owner != NULL) { |
645 | struct fuse_write_in *inarg = &req->misc.write.in; | ||
646 | inarg->write_flags |= FUSE_WRITE_LOCKOWNER; | 679 | inarg->write_flags |= FUSE_WRITE_LOCKOWNER; |
647 | inarg->lock_owner = fuse_lock_owner_id(fc, owner); | 680 | inarg->lock_owner = fuse_lock_owner_id(fc, owner); |
648 | } | 681 | } |
@@ -700,7 +733,7 @@ static int fuse_buffered_write(struct file *file, struct inode *inode, | |||
700 | req->num_pages = 1; | 733 | req->num_pages = 1; |
701 | req->pages[0] = page; | 734 | req->pages[0] = page; |
702 | req->page_offset = offset; | 735 | req->page_offset = offset; |
703 | nres = fuse_send_write(req, file, inode, pos, count, NULL); | 736 | nres = fuse_send_write(req, file, pos, count, NULL); |
704 | err = req->out.h.error; | 737 | err = req->out.h.error; |
705 | fuse_put_request(fc, req); | 738 | fuse_put_request(fc, req); |
706 | if (!err && !nres) | 739 | if (!err && !nres) |
@@ -741,7 +774,7 @@ static size_t fuse_send_write_pages(struct fuse_req *req, struct file *file, | |||
741 | for (i = 0; i < req->num_pages; i++) | 774 | for (i = 0; i < req->num_pages; i++) |
742 | fuse_wait_on_page_writeback(inode, req->pages[i]->index); | 775 | fuse_wait_on_page_writeback(inode, req->pages[i]->index); |
743 | 776 | ||
744 | res = fuse_send_write(req, file, inode, pos, count, NULL); | 777 | res = fuse_send_write(req, file, pos, count, NULL); |
745 | 778 | ||
746 | offset = req->page_offset; | 779 | offset = req->page_offset; |
747 | count = res; | 780 | count = res; |
@@ -979,25 +1012,23 @@ static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf, | |||
979 | return 0; | 1012 | return 0; |
980 | } | 1013 | } |
981 | 1014 | ||
982 | static ssize_t fuse_direct_io(struct file *file, const char __user *buf, | 1015 | ssize_t fuse_direct_io(struct file *file, const char __user *buf, |
983 | size_t count, loff_t *ppos, int write) | 1016 | size_t count, loff_t *ppos, int write) |
984 | { | 1017 | { |
985 | struct inode *inode = file->f_path.dentry->d_inode; | 1018 | struct fuse_file *ff = file->private_data; |
986 | struct fuse_conn *fc = get_fuse_conn(inode); | 1019 | struct fuse_conn *fc = ff->fc; |
987 | size_t nmax = write ? fc->max_write : fc->max_read; | 1020 | size_t nmax = write ? fc->max_write : fc->max_read; |
988 | loff_t pos = *ppos; | 1021 | loff_t pos = *ppos; |
989 | ssize_t res = 0; | 1022 | ssize_t res = 0; |
990 | struct fuse_req *req; | 1023 | struct fuse_req *req; |
991 | 1024 | ||
992 | if (is_bad_inode(inode)) | ||
993 | return -EIO; | ||
994 | |||
995 | req = fuse_get_req(fc); | 1025 | req = fuse_get_req(fc); |
996 | if (IS_ERR(req)) | 1026 | if (IS_ERR(req)) |
997 | return PTR_ERR(req); | 1027 | return PTR_ERR(req); |
998 | 1028 | ||
999 | while (count) { | 1029 | while (count) { |
1000 | size_t nres; | 1030 | size_t nres; |
1031 | fl_owner_t owner = current->files; | ||
1001 | size_t nbytes = min(count, nmax); | 1032 | size_t nbytes = min(count, nmax); |
1002 | int err = fuse_get_user_pages(req, buf, &nbytes, write); | 1033 | int err = fuse_get_user_pages(req, buf, &nbytes, write); |
1003 | if (err) { | 1034 | if (err) { |
@@ -1006,11 +1037,10 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf, | |||
1006 | } | 1037 | } |
1007 | 1038 | ||
1008 | if (write) | 1039 | if (write) |
1009 | nres = fuse_send_write(req, file, inode, pos, nbytes, | 1040 | nres = fuse_send_write(req, file, pos, nbytes, owner); |
1010 | current->files); | ||
1011 | else | 1041 | else |
1012 | nres = fuse_send_read(req, file, inode, pos, nbytes, | 1042 | nres = fuse_send_read(req, file, pos, nbytes, owner); |
1013 | current->files); | 1043 | |
1014 | fuse_release_user_pages(req, !write); | 1044 | fuse_release_user_pages(req, !write); |
1015 | if (req->out.h.error) { | 1045 | if (req->out.h.error) { |
1016 | if (!res) | 1046 | if (!res) |
@@ -1034,20 +1064,27 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf, | |||
1034 | } | 1064 | } |
1035 | } | 1065 | } |
1036 | fuse_put_request(fc, req); | 1066 | fuse_put_request(fc, req); |
1037 | if (res > 0) { | 1067 | if (res > 0) |
1038 | if (write) | ||
1039 | fuse_write_update_size(inode, pos); | ||
1040 | *ppos = pos; | 1068 | *ppos = pos; |
1041 | } | ||
1042 | fuse_invalidate_attr(inode); | ||
1043 | 1069 | ||
1044 | return res; | 1070 | return res; |
1045 | } | 1071 | } |
1072 | EXPORT_SYMBOL_GPL(fuse_direct_io); | ||
1046 | 1073 | ||
1047 | static ssize_t fuse_direct_read(struct file *file, char __user *buf, | 1074 | static ssize_t fuse_direct_read(struct file *file, char __user *buf, |
1048 | size_t count, loff_t *ppos) | 1075 | size_t count, loff_t *ppos) |
1049 | { | 1076 | { |
1050 | return fuse_direct_io(file, buf, count, ppos, 0); | 1077 | ssize_t res; |
1078 | struct inode *inode = file->f_path.dentry->d_inode; | ||
1079 | |||
1080 | if (is_bad_inode(inode)) | ||
1081 | return -EIO; | ||
1082 | |||
1083 | res = fuse_direct_io(file, buf, count, ppos, 0); | ||
1084 | |||
1085 | fuse_invalidate_attr(inode); | ||
1086 | |||
1087 | return res; | ||
1051 | } | 1088 | } |
1052 | 1089 | ||
1053 | static ssize_t fuse_direct_write(struct file *file, const char __user *buf, | 1090 | static ssize_t fuse_direct_write(struct file *file, const char __user *buf, |
@@ -1055,12 +1092,22 @@ static ssize_t fuse_direct_write(struct file *file, const char __user *buf, | |||
1055 | { | 1092 | { |
1056 | struct inode *inode = file->f_path.dentry->d_inode; | 1093 | struct inode *inode = file->f_path.dentry->d_inode; |
1057 | ssize_t res; | 1094 | ssize_t res; |
1095 | |||
1096 | if (is_bad_inode(inode)) | ||
1097 | return -EIO; | ||
1098 | |||
1058 | /* Don't allow parallel writes to the same file */ | 1099 | /* Don't allow parallel writes to the same file */ |
1059 | mutex_lock(&inode->i_mutex); | 1100 | mutex_lock(&inode->i_mutex); |
1060 | res = generic_write_checks(file, ppos, &count, 0); | 1101 | res = generic_write_checks(file, ppos, &count, 0); |
1061 | if (!res) | 1102 | if (!res) { |
1062 | res = fuse_direct_io(file, buf, count, ppos, 1); | 1103 | res = fuse_direct_io(file, buf, count, ppos, 1); |
1104 | if (res > 0) | ||
1105 | fuse_write_update_size(inode, *ppos); | ||
1106 | } | ||
1063 | mutex_unlock(&inode->i_mutex); | 1107 | mutex_unlock(&inode->i_mutex); |
1108 | |||
1109 | fuse_invalidate_attr(inode); | ||
1110 | |||
1064 | return res; | 1111 | return res; |
1065 | } | 1112 | } |
1066 | 1113 | ||
@@ -1177,9 +1224,10 @@ static int fuse_writepage_locked(struct page *page) | |||
1177 | req->ff = fuse_file_get(ff); | 1224 | req->ff = fuse_file_get(ff); |
1178 | spin_unlock(&fc->lock); | 1225 | spin_unlock(&fc->lock); |
1179 | 1226 | ||
1180 | fuse_write_fill(req, NULL, ff, inode, page_offset(page), 0, 1); | 1227 | fuse_write_fill(req, ff, page_offset(page), 0); |
1181 | 1228 | ||
1182 | copy_highpage(tmp_page, page); | 1229 | copy_highpage(tmp_page, page); |
1230 | req->misc.write.in.write_flags |= FUSE_WRITE_CACHE; | ||
1183 | req->in.argpages = 1; | 1231 | req->in.argpages = 1; |
1184 | req->num_pages = 1; | 1232 | req->num_pages = 1; |
1185 | req->pages[0] = tmp_page; | 1233 | req->pages[0] = tmp_page; |
@@ -1603,12 +1651,11 @@ static int fuse_ioctl_copy_user(struct page **pages, struct iovec *iov, | |||
1603 | * limits ioctl data transfers to well-formed ioctls and is the forced | 1651 | * limits ioctl data transfers to well-formed ioctls and is the forced |
1604 | * behavior for all FUSE servers. | 1652 | * behavior for all FUSE servers. |
1605 | */ | 1653 | */ |
1606 | static long fuse_file_do_ioctl(struct file *file, unsigned int cmd, | 1654 | long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, |
1607 | unsigned long arg, unsigned int flags) | 1655 | unsigned int flags) |
1608 | { | 1656 | { |
1609 | struct inode *inode = file->f_dentry->d_inode; | ||
1610 | struct fuse_file *ff = file->private_data; | 1657 | struct fuse_file *ff = file->private_data; |
1611 | struct fuse_conn *fc = get_fuse_conn(inode); | 1658 | struct fuse_conn *fc = ff->fc; |
1612 | struct fuse_ioctl_in inarg = { | 1659 | struct fuse_ioctl_in inarg = { |
1613 | .fh = ff->fh, | 1660 | .fh = ff->fh, |
1614 | .cmd = cmd, | 1661 | .cmd = cmd, |
@@ -1627,13 +1674,6 @@ static long fuse_file_do_ioctl(struct file *file, unsigned int cmd, | |||
1627 | /* assume all the iovs returned by client always fits in a page */ | 1674 | /* assume all the iovs returned by client always fits in a page */ |
1628 | BUILD_BUG_ON(sizeof(struct iovec) * FUSE_IOCTL_MAX_IOV > PAGE_SIZE); | 1675 | BUILD_BUG_ON(sizeof(struct iovec) * FUSE_IOCTL_MAX_IOV > PAGE_SIZE); |
1629 | 1676 | ||
1630 | if (!fuse_allow_task(fc, current)) | ||
1631 | return -EACCES; | ||
1632 | |||
1633 | err = -EIO; | ||
1634 | if (is_bad_inode(inode)) | ||
1635 | goto out; | ||
1636 | |||
1637 | err = -ENOMEM; | 1677 | err = -ENOMEM; |
1638 | pages = kzalloc(sizeof(pages[0]) * FUSE_MAX_PAGES_PER_REQ, GFP_KERNEL); | 1678 | pages = kzalloc(sizeof(pages[0]) * FUSE_MAX_PAGES_PER_REQ, GFP_KERNEL); |
1639 | iov_page = alloc_page(GFP_KERNEL); | 1679 | iov_page = alloc_page(GFP_KERNEL); |
@@ -1694,7 +1734,7 @@ static long fuse_file_do_ioctl(struct file *file, unsigned int cmd, | |||
1694 | 1734 | ||
1695 | /* okay, let's send it to the client */ | 1735 | /* okay, let's send it to the client */ |
1696 | req->in.h.opcode = FUSE_IOCTL; | 1736 | req->in.h.opcode = FUSE_IOCTL; |
1697 | req->in.h.nodeid = get_node_id(inode); | 1737 | req->in.h.nodeid = ff->nodeid; |
1698 | req->in.numargs = 1; | 1738 | req->in.numargs = 1; |
1699 | req->in.args[0].size = sizeof(inarg); | 1739 | req->in.args[0].size = sizeof(inarg); |
1700 | req->in.args[0].value = &inarg; | 1740 | req->in.args[0].value = &inarg; |
@@ -1777,17 +1817,33 @@ static long fuse_file_do_ioctl(struct file *file, unsigned int cmd, | |||
1777 | 1817 | ||
1778 | return err ? err : outarg.result; | 1818 | return err ? err : outarg.result; |
1779 | } | 1819 | } |
1820 | EXPORT_SYMBOL_GPL(fuse_do_ioctl); | ||
1821 | |||
1822 | static long fuse_file_ioctl_common(struct file *file, unsigned int cmd, | ||
1823 | unsigned long arg, unsigned int flags) | ||
1824 | { | ||
1825 | struct inode *inode = file->f_dentry->d_inode; | ||
1826 | struct fuse_conn *fc = get_fuse_conn(inode); | ||
1827 | |||
1828 | if (!fuse_allow_task(fc, current)) | ||
1829 | return -EACCES; | ||
1830 | |||
1831 | if (is_bad_inode(inode)) | ||
1832 | return -EIO; | ||
1833 | |||
1834 | return fuse_do_ioctl(file, cmd, arg, flags); | ||
1835 | } | ||
1780 | 1836 | ||
1781 | static long fuse_file_ioctl(struct file *file, unsigned int cmd, | 1837 | static long fuse_file_ioctl(struct file *file, unsigned int cmd, |
1782 | unsigned long arg) | 1838 | unsigned long arg) |
1783 | { | 1839 | { |
1784 | return fuse_file_do_ioctl(file, cmd, arg, 0); | 1840 | return fuse_file_ioctl_common(file, cmd, arg, 0); |
1785 | } | 1841 | } |
1786 | 1842 | ||
1787 | static long fuse_file_compat_ioctl(struct file *file, unsigned int cmd, | 1843 | static long fuse_file_compat_ioctl(struct file *file, unsigned int cmd, |
1788 | unsigned long arg) | 1844 | unsigned long arg) |
1789 | { | 1845 | { |
1790 | return fuse_file_do_ioctl(file, cmd, arg, FUSE_IOCTL_COMPAT); | 1846 | return fuse_file_ioctl_common(file, cmd, arg, FUSE_IOCTL_COMPAT); |
1791 | } | 1847 | } |
1792 | 1848 | ||
1793 | /* | 1849 | /* |
@@ -1841,11 +1897,10 @@ static void fuse_register_polled_file(struct fuse_conn *fc, | |||
1841 | spin_unlock(&fc->lock); | 1897 | spin_unlock(&fc->lock); |
1842 | } | 1898 | } |
1843 | 1899 | ||
1844 | static unsigned fuse_file_poll(struct file *file, poll_table *wait) | 1900 | unsigned fuse_file_poll(struct file *file, poll_table *wait) |
1845 | { | 1901 | { |
1846 | struct inode *inode = file->f_dentry->d_inode; | ||
1847 | struct fuse_file *ff = file->private_data; | 1902 | struct fuse_file *ff = file->private_data; |
1848 | struct fuse_conn *fc = get_fuse_conn(inode); | 1903 | struct fuse_conn *fc = ff->fc; |
1849 | struct fuse_poll_in inarg = { .fh = ff->fh, .kh = ff->kh }; | 1904 | struct fuse_poll_in inarg = { .fh = ff->fh, .kh = ff->kh }; |
1850 | struct fuse_poll_out outarg; | 1905 | struct fuse_poll_out outarg; |
1851 | struct fuse_req *req; | 1906 | struct fuse_req *req; |
@@ -1870,7 +1925,7 @@ static unsigned fuse_file_poll(struct file *file, poll_table *wait) | |||
1870 | return PTR_ERR(req); | 1925 | return PTR_ERR(req); |
1871 | 1926 | ||
1872 | req->in.h.opcode = FUSE_POLL; | 1927 | req->in.h.opcode = FUSE_POLL; |
1873 | req->in.h.nodeid = get_node_id(inode); | 1928 | req->in.h.nodeid = ff->nodeid; |
1874 | req->in.numargs = 1; | 1929 | req->in.numargs = 1; |
1875 | req->in.args[0].size = sizeof(inarg); | 1930 | req->in.args[0].size = sizeof(inarg); |
1876 | req->in.args[0].value = &inarg; | 1931 | req->in.args[0].value = &inarg; |
@@ -1889,6 +1944,7 @@ static unsigned fuse_file_poll(struct file *file, poll_table *wait) | |||
1889 | } | 1944 | } |
1890 | return POLLERR; | 1945 | return POLLERR; |
1891 | } | 1946 | } |
1947 | EXPORT_SYMBOL_GPL(fuse_file_poll); | ||
1892 | 1948 | ||
1893 | /* | 1949 | /* |
1894 | * This is called from fuse_handle_notify() on FUSE_NOTIFY_POLL and | 1950 | * This is called from fuse_handle_notify() on FUSE_NOTIFY_POLL and |
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 6fc5aedaa0d5..aaf2f9ff970e 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h | |||
@@ -97,8 +97,13 @@ struct fuse_inode { | |||
97 | struct list_head writepages; | 97 | struct list_head writepages; |
98 | }; | 98 | }; |
99 | 99 | ||
100 | struct fuse_conn; | ||
101 | |||
100 | /** FUSE specific file data */ | 102 | /** FUSE specific file data */ |
101 | struct fuse_file { | 103 | struct fuse_file { |
104 | /** Fuse connection for this file */ | ||
105 | struct fuse_conn *fc; | ||
106 | |||
102 | /** Request reserved for flush and release */ | 107 | /** Request reserved for flush and release */ |
103 | struct fuse_req *reserved_req; | 108 | struct fuse_req *reserved_req; |
104 | 109 | ||
@@ -108,9 +113,15 @@ struct fuse_file { | |||
108 | /** File handle used by userspace */ | 113 | /** File handle used by userspace */ |
109 | u64 fh; | 114 | u64 fh; |
110 | 115 | ||
116 | /** Node id of this file */ | ||
117 | u64 nodeid; | ||
118 | |||
111 | /** Refcount */ | 119 | /** Refcount */ |
112 | atomic_t count; | 120 | atomic_t count; |
113 | 121 | ||
122 | /** FOPEN_* flags returned by open */ | ||
123 | u32 open_flags; | ||
124 | |||
114 | /** Entry on inode's write_files list */ | 125 | /** Entry on inode's write_files list */ |
115 | struct list_head write_entry; | 126 | struct list_head write_entry; |
116 | 127 | ||
@@ -185,8 +196,6 @@ enum fuse_req_state { | |||
185 | FUSE_REQ_FINISHED | 196 | FUSE_REQ_FINISHED |
186 | }; | 197 | }; |
187 | 198 | ||
188 | struct fuse_conn; | ||
189 | |||
190 | /** | 199 | /** |
191 | * A request to the client | 200 | * A request to the client |
192 | */ | 201 | */ |
@@ -248,11 +257,12 @@ struct fuse_req { | |||
248 | struct fuse_forget_in forget_in; | 257 | struct fuse_forget_in forget_in; |
249 | struct { | 258 | struct { |
250 | struct fuse_release_in in; | 259 | struct fuse_release_in in; |
251 | struct vfsmount *vfsmount; | 260 | struct path path; |
252 | struct dentry *dentry; | ||
253 | } release; | 261 | } release; |
254 | struct fuse_init_in init_in; | 262 | struct fuse_init_in init_in; |
255 | struct fuse_init_out init_out; | 263 | struct fuse_init_out init_out; |
264 | struct cuse_init_in cuse_init_in; | ||
265 | struct cuse_init_out cuse_init_out; | ||
256 | struct { | 266 | struct { |
257 | struct fuse_read_in in; | 267 | struct fuse_read_in in; |
258 | u64 attr_ver; | 268 | u64 attr_ver; |
@@ -386,6 +396,9 @@ struct fuse_conn { | |||
386 | /** Filesystem supports NFS exporting. Only set in INIT */ | 396 | /** Filesystem supports NFS exporting. Only set in INIT */ |
387 | unsigned export_support:1; | 397 | unsigned export_support:1; |
388 | 398 | ||
399 | /** Set if bdi is valid */ | ||
400 | unsigned bdi_initialized:1; | ||
401 | |||
389 | /* | 402 | /* |
390 | * The following bitfields are only for optimization purposes | 403 | * The following bitfields are only for optimization purposes |
391 | * and hence races in setting them will not cause malfunction | 404 | * and hence races in setting them will not cause malfunction |
@@ -515,25 +528,24 @@ void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, | |||
515 | * Initialize READ or READDIR request | 528 | * Initialize READ or READDIR request |
516 | */ | 529 | */ |
517 | void fuse_read_fill(struct fuse_req *req, struct file *file, | 530 | void fuse_read_fill(struct fuse_req *req, struct file *file, |
518 | struct inode *inode, loff_t pos, size_t count, int opcode); | 531 | loff_t pos, size_t count, int opcode); |
519 | 532 | ||
520 | /** | 533 | /** |
521 | * Send OPEN or OPENDIR request | 534 | * Send OPEN or OPENDIR request |
522 | */ | 535 | */ |
523 | int fuse_open_common(struct inode *inode, struct file *file, int isdir); | 536 | int fuse_open_common(struct inode *inode, struct file *file, bool isdir); |
524 | 537 | ||
525 | struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); | 538 | struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); |
539 | struct fuse_file *fuse_file_get(struct fuse_file *ff); | ||
526 | void fuse_file_free(struct fuse_file *ff); | 540 | void fuse_file_free(struct fuse_file *ff); |
527 | void fuse_finish_open(struct inode *inode, struct file *file, | 541 | void fuse_finish_open(struct inode *inode, struct file *file); |
528 | struct fuse_file *ff, struct fuse_open_out *outarg); | ||
529 | 542 | ||
530 | /** Fill in ff->reserved_req with a RELEASE request */ | 543 | void fuse_sync_release(struct fuse_file *ff, int flags); |
531 | void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode); | ||
532 | 544 | ||
533 | /** | 545 | /** |
534 | * Send RELEASE or RELEASEDIR request | 546 | * Send RELEASE or RELEASEDIR request |
535 | */ | 547 | */ |
536 | int fuse_release_common(struct inode *inode, struct file *file, int isdir); | 548 | void fuse_release_common(struct file *file, int opcode); |
537 | 549 | ||
538 | /** | 550 | /** |
539 | * Send FSYNC or FSYNCDIR request | 551 | * Send FSYNC or FSYNCDIR request |
@@ -652,10 +664,12 @@ void fuse_invalidate_entry_cache(struct dentry *entry); | |||
652 | */ | 664 | */ |
653 | struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); | 665 | struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); |
654 | 666 | ||
667 | void fuse_conn_kill(struct fuse_conn *fc); | ||
668 | |||
655 | /** | 669 | /** |
656 | * Initialize fuse_conn | 670 | * Initialize fuse_conn |
657 | */ | 671 | */ |
658 | int fuse_conn_init(struct fuse_conn *fc, struct super_block *sb); | 672 | void fuse_conn_init(struct fuse_conn *fc); |
659 | 673 | ||
660 | /** | 674 | /** |
661 | * Release reference to fuse_conn | 675 | * Release reference to fuse_conn |
@@ -694,4 +708,13 @@ void fuse_release_nowrite(struct inode *inode); | |||
694 | 708 | ||
695 | u64 fuse_get_attr_version(struct fuse_conn *fc); | 709 | u64 fuse_get_attr_version(struct fuse_conn *fc); |
696 | 710 | ||
711 | int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, | ||
712 | bool isdir); | ||
713 | ssize_t fuse_direct_io(struct file *file, const char __user *buf, | ||
714 | size_t count, loff_t *ppos, int write); | ||
715 | long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, | ||
716 | unsigned int flags); | ||
717 | unsigned fuse_file_poll(struct file *file, poll_table *wait); | ||
718 | int fuse_dev_release(struct inode *inode, struct file *file); | ||
719 | |||
697 | #endif /* _FS_FUSE_I_H */ | 720 | #endif /* _FS_FUSE_I_H */ |
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 91f7c85f1ffd..f0df55a52929 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c | |||
@@ -277,11 +277,14 @@ static void fuse_send_destroy(struct fuse_conn *fc) | |||
277 | } | 277 | } |
278 | } | 278 | } |
279 | 279 | ||
280 | static void fuse_put_super(struct super_block *sb) | 280 | static void fuse_bdi_destroy(struct fuse_conn *fc) |
281 | { | 281 | { |
282 | struct fuse_conn *fc = get_fuse_conn_super(sb); | 282 | if (fc->bdi_initialized) |
283 | bdi_destroy(&fc->bdi); | ||
284 | } | ||
283 | 285 | ||
284 | fuse_send_destroy(fc); | 286 | void fuse_conn_kill(struct fuse_conn *fc) |
287 | { | ||
285 | spin_lock(&fc->lock); | 288 | spin_lock(&fc->lock); |
286 | fc->connected = 0; | 289 | fc->connected = 0; |
287 | fc->blocked = 0; | 290 | fc->blocked = 0; |
@@ -295,7 +298,16 @@ static void fuse_put_super(struct super_block *sb) | |||
295 | list_del(&fc->entry); | 298 | list_del(&fc->entry); |
296 | fuse_ctl_remove_conn(fc); | 299 | fuse_ctl_remove_conn(fc); |
297 | mutex_unlock(&fuse_mutex); | 300 | mutex_unlock(&fuse_mutex); |
298 | bdi_destroy(&fc->bdi); | 301 | fuse_bdi_destroy(fc); |
302 | } | ||
303 | EXPORT_SYMBOL_GPL(fuse_conn_kill); | ||
304 | |||
305 | static void fuse_put_super(struct super_block *sb) | ||
306 | { | ||
307 | struct fuse_conn *fc = get_fuse_conn_super(sb); | ||
308 | |||
309 | fuse_send_destroy(fc); | ||
310 | fuse_conn_kill(fc); | ||
299 | fuse_conn_put(fc); | 311 | fuse_conn_put(fc); |
300 | } | 312 | } |
301 | 313 | ||
@@ -466,10 +478,8 @@ static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt) | |||
466 | return 0; | 478 | return 0; |
467 | } | 479 | } |
468 | 480 | ||
469 | int fuse_conn_init(struct fuse_conn *fc, struct super_block *sb) | 481 | void fuse_conn_init(struct fuse_conn *fc) |
470 | { | 482 | { |
471 | int err; | ||
472 | |||
473 | memset(fc, 0, sizeof(*fc)); | 483 | memset(fc, 0, sizeof(*fc)); |
474 | spin_lock_init(&fc->lock); | 484 | spin_lock_init(&fc->lock); |
475 | mutex_init(&fc->inst_mutex); | 485 | mutex_init(&fc->inst_mutex); |
@@ -484,49 +494,12 @@ int fuse_conn_init(struct fuse_conn *fc, struct super_block *sb) | |||
484 | INIT_LIST_HEAD(&fc->bg_queue); | 494 | INIT_LIST_HEAD(&fc->bg_queue); |
485 | INIT_LIST_HEAD(&fc->entry); | 495 | INIT_LIST_HEAD(&fc->entry); |
486 | atomic_set(&fc->num_waiting, 0); | 496 | atomic_set(&fc->num_waiting, 0); |
487 | fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; | ||
488 | fc->bdi.unplug_io_fn = default_unplug_io_fn; | ||
489 | /* fuse does it's own writeback accounting */ | ||
490 | fc->bdi.capabilities = BDI_CAP_NO_ACCT_WB; | ||
491 | fc->khctr = 0; | 497 | fc->khctr = 0; |
492 | fc->polled_files = RB_ROOT; | 498 | fc->polled_files = RB_ROOT; |
493 | fc->dev = sb->s_dev; | ||
494 | err = bdi_init(&fc->bdi); | ||
495 | if (err) | ||
496 | goto error_mutex_destroy; | ||
497 | if (sb->s_bdev) { | ||
498 | err = bdi_register(&fc->bdi, NULL, "%u:%u-fuseblk", | ||
499 | MAJOR(fc->dev), MINOR(fc->dev)); | ||
500 | } else { | ||
501 | err = bdi_register_dev(&fc->bdi, fc->dev); | ||
502 | } | ||
503 | if (err) | ||
504 | goto error_bdi_destroy; | ||
505 | /* | ||
506 | * For a single fuse filesystem use max 1% of dirty + | ||
507 | * writeback threshold. | ||
508 | * | ||
509 | * This gives about 1M of write buffer for memory maps on a | ||
510 | * machine with 1G and 10% dirty_ratio, which should be more | ||
511 | * than enough. | ||
512 | * | ||
513 | * Privileged users can raise it by writing to | ||
514 | * | ||
515 | * /sys/class/bdi/<bdi>/max_ratio | ||
516 | */ | ||
517 | bdi_set_max_ratio(&fc->bdi, 1); | ||
518 | fc->reqctr = 0; | 499 | fc->reqctr = 0; |
519 | fc->blocked = 1; | 500 | fc->blocked = 1; |
520 | fc->attr_version = 1; | 501 | fc->attr_version = 1; |
521 | get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key)); | 502 | get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key)); |
522 | |||
523 | return 0; | ||
524 | |||
525 | error_bdi_destroy: | ||
526 | bdi_destroy(&fc->bdi); | ||
527 | error_mutex_destroy: | ||
528 | mutex_destroy(&fc->inst_mutex); | ||
529 | return err; | ||
530 | } | 503 | } |
531 | EXPORT_SYMBOL_GPL(fuse_conn_init); | 504 | EXPORT_SYMBOL_GPL(fuse_conn_init); |
532 | 505 | ||
@@ -539,12 +512,14 @@ void fuse_conn_put(struct fuse_conn *fc) | |||
539 | fc->release(fc); | 512 | fc->release(fc); |
540 | } | 513 | } |
541 | } | 514 | } |
515 | EXPORT_SYMBOL_GPL(fuse_conn_put); | ||
542 | 516 | ||
543 | struct fuse_conn *fuse_conn_get(struct fuse_conn *fc) | 517 | struct fuse_conn *fuse_conn_get(struct fuse_conn *fc) |
544 | { | 518 | { |
545 | atomic_inc(&fc->count); | 519 | atomic_inc(&fc->count); |
546 | return fc; | 520 | return fc; |
547 | } | 521 | } |
522 | EXPORT_SYMBOL_GPL(fuse_conn_get); | ||
548 | 523 | ||
549 | static struct inode *fuse_get_root_inode(struct super_block *sb, unsigned mode) | 524 | static struct inode *fuse_get_root_inode(struct super_block *sb, unsigned mode) |
550 | { | 525 | { |
@@ -797,6 +772,48 @@ static void fuse_free_conn(struct fuse_conn *fc) | |||
797 | kfree(fc); | 772 | kfree(fc); |
798 | } | 773 | } |
799 | 774 | ||
775 | static int fuse_bdi_init(struct fuse_conn *fc, struct super_block *sb) | ||
776 | { | ||
777 | int err; | ||
778 | |||
779 | fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; | ||
780 | fc->bdi.unplug_io_fn = default_unplug_io_fn; | ||
781 | /* fuse does it's own writeback accounting */ | ||
782 | fc->bdi.capabilities = BDI_CAP_NO_ACCT_WB; | ||
783 | |||
784 | err = bdi_init(&fc->bdi); | ||
785 | if (err) | ||
786 | return err; | ||
787 | |||
788 | fc->bdi_initialized = 1; | ||
789 | |||
790 | if (sb->s_bdev) { | ||
791 | err = bdi_register(&fc->bdi, NULL, "%u:%u-fuseblk", | ||
792 | MAJOR(fc->dev), MINOR(fc->dev)); | ||
793 | } else { | ||
794 | err = bdi_register_dev(&fc->bdi, fc->dev); | ||
795 | } | ||
796 | |||
797 | if (err) | ||
798 | return err; | ||
799 | |||
800 | /* | ||
801 | * For a single fuse filesystem use max 1% of dirty + | ||
802 | * writeback threshold. | ||
803 | * | ||
804 | * This gives about 1M of write buffer for memory maps on a | ||
805 | * machine with 1G and 10% dirty_ratio, which should be more | ||
806 | * than enough. | ||
807 | * | ||
808 | * Privileged users can raise it by writing to | ||
809 | * | ||
810 | * /sys/class/bdi/<bdi>/max_ratio | ||
811 | */ | ||
812 | bdi_set_max_ratio(&fc->bdi, 1); | ||
813 | |||
814 | return 0; | ||
815 | } | ||
816 | |||
800 | static int fuse_fill_super(struct super_block *sb, void *data, int silent) | 817 | static int fuse_fill_super(struct super_block *sb, void *data, int silent) |
801 | { | 818 | { |
802 | struct fuse_conn *fc; | 819 | struct fuse_conn *fc; |
@@ -843,11 +860,12 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent) | |||
843 | if (!fc) | 860 | if (!fc) |
844 | goto err_fput; | 861 | goto err_fput; |
845 | 862 | ||
846 | err = fuse_conn_init(fc, sb); | 863 | fuse_conn_init(fc); |
847 | if (err) { | 864 | |
848 | kfree(fc); | 865 | fc->dev = sb->s_dev; |
849 | goto err_fput; | 866 | err = fuse_bdi_init(fc, sb); |
850 | } | 867 | if (err) |
868 | goto err_put_conn; | ||
851 | 869 | ||
852 | fc->release = fuse_free_conn; | 870 | fc->release = fuse_free_conn; |
853 | fc->flags = d.flags; | 871 | fc->flags = d.flags; |
@@ -911,7 +929,7 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent) | |||
911 | err_put_root: | 929 | err_put_root: |
912 | dput(root_dentry); | 930 | dput(root_dentry); |
913 | err_put_conn: | 931 | err_put_conn: |
914 | bdi_destroy(&fc->bdi); | 932 | fuse_bdi_destroy(fc); |
915 | fuse_conn_put(fc); | 933 | fuse_conn_put(fc); |
916 | err_fput: | 934 | err_fput: |
917 | fput(file); | 935 | fput(file); |
diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile index d53a9bea1c2f..3da2f1f4f738 100644 --- a/fs/gfs2/Makefile +++ b/fs/gfs2/Makefile | |||
@@ -1,3 +1,4 @@ | |||
1 | EXTRA_CFLAGS := -I$(src) | ||
1 | obj-$(CONFIG_GFS2_FS) += gfs2.o | 2 | obj-$(CONFIG_GFS2_FS) += gfs2.o |
2 | gfs2-y := acl.o bmap.o dir.o eaops.o eattr.o glock.o \ | 3 | gfs2-y := acl.o bmap.o dir.o eaops.o eattr.o glock.o \ |
3 | glops.o inode.o log.o lops.o main.o meta_io.o \ | 4 | glops.o inode.o log.o lops.o main.o meta_io.o \ |
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 329763530dc0..6d47379e794b 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "trans.h" | 25 | #include "trans.h" |
26 | #include "dir.h" | 26 | #include "dir.h" |
27 | #include "util.h" | 27 | #include "util.h" |
28 | #include "trace_gfs2.h" | ||
28 | 29 | ||
29 | /* This doesn't need to be that large as max 64 bit pointers in a 4k | 30 | /* This doesn't need to be that large as max 64 bit pointers in a 4k |
30 | * block is 512, so __u16 is fine for that. It saves stack space to | 31 | * block is 512, so __u16 is fine for that. It saves stack space to |
@@ -589,6 +590,7 @@ int gfs2_block_map(struct inode *inode, sector_t lblock, | |||
589 | clear_buffer_mapped(bh_map); | 590 | clear_buffer_mapped(bh_map); |
590 | clear_buffer_new(bh_map); | 591 | clear_buffer_new(bh_map); |
591 | clear_buffer_boundary(bh_map); | 592 | clear_buffer_boundary(bh_map); |
593 | trace_gfs2_bmap(ip, bh_map, lblock, create, 1); | ||
592 | if (gfs2_is_dir(ip)) { | 594 | if (gfs2_is_dir(ip)) { |
593 | bsize = sdp->sd_jbsize; | 595 | bsize = sdp->sd_jbsize; |
594 | arr = sdp->sd_jheightsize; | 596 | arr = sdp->sd_jheightsize; |
@@ -623,6 +625,7 @@ int gfs2_block_map(struct inode *inode, sector_t lblock, | |||
623 | ret = 0; | 625 | ret = 0; |
624 | out: | 626 | out: |
625 | release_metapath(&mp); | 627 | release_metapath(&mp); |
628 | trace_gfs2_bmap(ip, bh_map, lblock, create, ret); | ||
626 | bmap_unlock(ip, create); | 629 | bmap_unlock(ip, create); |
627 | return ret; | 630 | return ret; |
628 | 631 | ||
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 2bf62bcc5181..297421c0427a 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c | |||
@@ -39,6 +39,8 @@ | |||
39 | #include "super.h" | 39 | #include "super.h" |
40 | #include "util.h" | 40 | #include "util.h" |
41 | #include "bmap.h" | 41 | #include "bmap.h" |
42 | #define CREATE_TRACE_POINTS | ||
43 | #include "trace_gfs2.h" | ||
42 | 44 | ||
43 | struct gfs2_gl_hash_bucket { | 45 | struct gfs2_gl_hash_bucket { |
44 | struct hlist_head hb_list; | 46 | struct hlist_head hb_list; |
@@ -155,7 +157,7 @@ static void glock_free(struct gfs2_glock *gl) | |||
155 | 157 | ||
156 | if (aspace) | 158 | if (aspace) |
157 | gfs2_aspace_put(aspace); | 159 | gfs2_aspace_put(aspace); |
158 | 160 | trace_gfs2_glock_put(gl); | |
159 | sdp->sd_lockstruct.ls_ops->lm_put_lock(gfs2_glock_cachep, gl); | 161 | sdp->sd_lockstruct.ls_ops->lm_put_lock(gfs2_glock_cachep, gl); |
160 | } | 162 | } |
161 | 163 | ||
@@ -317,14 +319,17 @@ restart: | |||
317 | return 2; | 319 | return 2; |
318 | gh->gh_error = ret; | 320 | gh->gh_error = ret; |
319 | list_del_init(&gh->gh_list); | 321 | list_del_init(&gh->gh_list); |
322 | trace_gfs2_glock_queue(gh, 0); | ||
320 | gfs2_holder_wake(gh); | 323 | gfs2_holder_wake(gh); |
321 | goto restart; | 324 | goto restart; |
322 | } | 325 | } |
323 | set_bit(HIF_HOLDER, &gh->gh_iflags); | 326 | set_bit(HIF_HOLDER, &gh->gh_iflags); |
327 | trace_gfs2_promote(gh, 1); | ||
324 | gfs2_holder_wake(gh); | 328 | gfs2_holder_wake(gh); |
325 | goto restart; | 329 | goto restart; |
326 | } | 330 | } |
327 | set_bit(HIF_HOLDER, &gh->gh_iflags); | 331 | set_bit(HIF_HOLDER, &gh->gh_iflags); |
332 | trace_gfs2_promote(gh, 0); | ||
328 | gfs2_holder_wake(gh); | 333 | gfs2_holder_wake(gh); |
329 | continue; | 334 | continue; |
330 | } | 335 | } |
@@ -354,6 +359,7 @@ static inline void do_error(struct gfs2_glock *gl, const int ret) | |||
354 | else | 359 | else |
355 | continue; | 360 | continue; |
356 | list_del_init(&gh->gh_list); | 361 | list_del_init(&gh->gh_list); |
362 | trace_gfs2_glock_queue(gh, 0); | ||
357 | gfs2_holder_wake(gh); | 363 | gfs2_holder_wake(gh); |
358 | } | 364 | } |
359 | } | 365 | } |
@@ -422,6 +428,7 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret) | |||
422 | int rv; | 428 | int rv; |
423 | 429 | ||
424 | spin_lock(&gl->gl_spin); | 430 | spin_lock(&gl->gl_spin); |
431 | trace_gfs2_glock_state_change(gl, state); | ||
425 | state_change(gl, state); | 432 | state_change(gl, state); |
426 | gh = find_first_waiter(gl); | 433 | gh = find_first_waiter(gl); |
427 | 434 | ||
@@ -851,6 +858,7 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state, | |||
851 | gl->gl_demote_state != state) { | 858 | gl->gl_demote_state != state) { |
852 | gl->gl_demote_state = LM_ST_UNLOCKED; | 859 | gl->gl_demote_state = LM_ST_UNLOCKED; |
853 | } | 860 | } |
861 | trace_gfs2_demote_rq(gl); | ||
854 | } | 862 | } |
855 | 863 | ||
856 | /** | 864 | /** |
@@ -936,6 +944,7 @@ fail: | |||
936 | goto do_cancel; | 944 | goto do_cancel; |
937 | return; | 945 | return; |
938 | } | 946 | } |
947 | trace_gfs2_glock_queue(gh, 1); | ||
939 | list_add_tail(&gh->gh_list, insert_pt); | 948 | list_add_tail(&gh->gh_list, insert_pt); |
940 | do_cancel: | 949 | do_cancel: |
941 | gh = list_entry(gl->gl_holders.next, struct gfs2_holder, gh_list); | 950 | gh = list_entry(gl->gl_holders.next, struct gfs2_holder, gh_list); |
@@ -1032,6 +1041,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh) | |||
1032 | !test_bit(GLF_DEMOTE, &gl->gl_flags)) | 1041 | !test_bit(GLF_DEMOTE, &gl->gl_flags)) |
1033 | fast_path = 1; | 1042 | fast_path = 1; |
1034 | } | 1043 | } |
1044 | trace_gfs2_glock_queue(gh, 0); | ||
1035 | spin_unlock(&gl->gl_spin); | 1045 | spin_unlock(&gl->gl_spin); |
1036 | if (likely(fast_path)) | 1046 | if (likely(fast_path)) |
1037 | return; | 1047 | return; |
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index f2e449c595b4..13c6237c5f67 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "meta_io.h" | 28 | #include "meta_io.h" |
29 | #include "util.h" | 29 | #include "util.h" |
30 | #include "dir.h" | 30 | #include "dir.h" |
31 | #include "trace_gfs2.h" | ||
31 | 32 | ||
32 | #define PULL 1 | 33 | #define PULL 1 |
33 | 34 | ||
@@ -313,6 +314,7 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) | |||
313 | gfs2_log_lock(sdp); | 314 | gfs2_log_lock(sdp); |
314 | } | 315 | } |
315 | atomic_sub(blks, &sdp->sd_log_blks_free); | 316 | atomic_sub(blks, &sdp->sd_log_blks_free); |
317 | trace_gfs2_log_blocks(sdp, -blks); | ||
316 | gfs2_log_unlock(sdp); | 318 | gfs2_log_unlock(sdp); |
317 | mutex_unlock(&sdp->sd_log_reserve_mutex); | 319 | mutex_unlock(&sdp->sd_log_reserve_mutex); |
318 | 320 | ||
@@ -333,6 +335,7 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) | |||
333 | 335 | ||
334 | gfs2_log_lock(sdp); | 336 | gfs2_log_lock(sdp); |
335 | atomic_add(blks, &sdp->sd_log_blks_free); | 337 | atomic_add(blks, &sdp->sd_log_blks_free); |
338 | trace_gfs2_log_blocks(sdp, blks); | ||
336 | gfs2_assert_withdraw(sdp, | 339 | gfs2_assert_withdraw(sdp, |
337 | atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks); | 340 | atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks); |
338 | gfs2_log_unlock(sdp); | 341 | gfs2_log_unlock(sdp); |
@@ -558,6 +561,7 @@ static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail) | |||
558 | 561 | ||
559 | gfs2_log_lock(sdp); | 562 | gfs2_log_lock(sdp); |
560 | atomic_add(dist, &sdp->sd_log_blks_free); | 563 | atomic_add(dist, &sdp->sd_log_blks_free); |
564 | trace_gfs2_log_blocks(sdp, dist); | ||
561 | gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks); | 565 | gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks); |
562 | gfs2_log_unlock(sdp); | 566 | gfs2_log_unlock(sdp); |
563 | 567 | ||
@@ -715,6 +719,7 @@ void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) | |||
715 | up_write(&sdp->sd_log_flush_lock); | 719 | up_write(&sdp->sd_log_flush_lock); |
716 | return; | 720 | return; |
717 | } | 721 | } |
722 | trace_gfs2_log_flush(sdp, 1); | ||
718 | 723 | ||
719 | ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); | 724 | ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); |
720 | INIT_LIST_HEAD(&ai->ai_ail1_list); | 725 | INIT_LIST_HEAD(&ai->ai_ail1_list); |
@@ -746,6 +751,7 @@ void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) | |||
746 | else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){ | 751 | else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){ |
747 | gfs2_log_lock(sdp); | 752 | gfs2_log_lock(sdp); |
748 | atomic_dec(&sdp->sd_log_blks_free); /* Adjust for unreserved buffer */ | 753 | atomic_dec(&sdp->sd_log_blks_free); /* Adjust for unreserved buffer */ |
754 | trace_gfs2_log_blocks(sdp, -1); | ||
749 | gfs2_log_unlock(sdp); | 755 | gfs2_log_unlock(sdp); |
750 | log_write_header(sdp, 0, PULL); | 756 | log_write_header(sdp, 0, PULL); |
751 | } | 757 | } |
@@ -763,7 +769,7 @@ void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) | |||
763 | ai = NULL; | 769 | ai = NULL; |
764 | } | 770 | } |
765 | gfs2_log_unlock(sdp); | 771 | gfs2_log_unlock(sdp); |
766 | 772 | trace_gfs2_log_flush(sdp, 0); | |
767 | up_write(&sdp->sd_log_flush_lock); | 773 | up_write(&sdp->sd_log_flush_lock); |
768 | 774 | ||
769 | kfree(ai); | 775 | kfree(ai); |
@@ -787,6 +793,7 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) | |||
787 | gfs2_assert_withdraw(sdp, sdp->sd_log_blks_reserved + tr->tr_reserved >= reserved); | 793 | gfs2_assert_withdraw(sdp, sdp->sd_log_blks_reserved + tr->tr_reserved >= reserved); |
788 | unused = sdp->sd_log_blks_reserved - reserved + tr->tr_reserved; | 794 | unused = sdp->sd_log_blks_reserved - reserved + tr->tr_reserved; |
789 | atomic_add(unused, &sdp->sd_log_blks_free); | 795 | atomic_add(unused, &sdp->sd_log_blks_free); |
796 | trace_gfs2_log_blocks(sdp, unused); | ||
790 | gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= | 797 | gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= |
791 | sdp->sd_jdesc->jd_blocks); | 798 | sdp->sd_jdesc->jd_blocks); |
792 | sdp->sd_log_blks_reserved = reserved; | 799 | sdp->sd_log_blks_reserved = reserved; |
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 00315f50fa46..9969ff062c5b 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "rgrp.h" | 27 | #include "rgrp.h" |
28 | #include "trans.h" | 28 | #include "trans.h" |
29 | #include "util.h" | 29 | #include "util.h" |
30 | #include "trace_gfs2.h" | ||
30 | 31 | ||
31 | /** | 32 | /** |
32 | * gfs2_pin - Pin a buffer in memory | 33 | * gfs2_pin - Pin a buffer in memory |
@@ -53,6 +54,7 @@ static void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh) | |||
53 | if (bd->bd_ail) | 54 | if (bd->bd_ail) |
54 | list_move(&bd->bd_ail_st_list, &bd->bd_ail->ai_ail2_list); | 55 | list_move(&bd->bd_ail_st_list, &bd->bd_ail->ai_ail2_list); |
55 | get_bh(bh); | 56 | get_bh(bh); |
57 | trace_gfs2_pin(bd, 1); | ||
56 | } | 58 | } |
57 | 59 | ||
58 | /** | 60 | /** |
@@ -89,6 +91,7 @@ static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, | |||
89 | bd->bd_ail = ai; | 91 | bd->bd_ail = ai; |
90 | list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list); | 92 | list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list); |
91 | clear_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags); | 93 | clear_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags); |
94 | trace_gfs2_pin(bd, 0); | ||
92 | gfs2_log_unlock(sdp); | 95 | gfs2_log_unlock(sdp); |
93 | unlock_buffer(bh); | 96 | unlock_buffer(bh); |
94 | } | 97 | } |
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index cc34f271b3e7..7bc3c45cd676 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include "log.h" | 33 | #include "log.h" |
34 | #include "quota.h" | 34 | #include "quota.h" |
35 | #include "dir.h" | 35 | #include "dir.h" |
36 | #include "trace_gfs2.h" | ||
36 | 37 | ||
37 | #define DO 0 | 38 | #define DO 0 |
38 | #define UNDO 1 | 39 | #define UNDO 1 |
@@ -775,6 +776,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) | |||
775 | /* Map the extents for this journal's blocks */ | 776 | /* Map the extents for this journal's blocks */ |
776 | map_journal_extents(sdp); | 777 | map_journal_extents(sdp); |
777 | } | 778 | } |
779 | trace_gfs2_log_blocks(sdp, atomic_read(&sdp->sd_log_blks_free)); | ||
778 | 780 | ||
779 | if (sdp->sd_lockstruct.ls_first) { | 781 | if (sdp->sd_lockstruct.ls_first) { |
780 | unsigned int x; | 782 | unsigned int x; |
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index de3239731db8..daa4ae341a29 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "util.h" | 29 | #include "util.h" |
30 | #include "log.h" | 30 | #include "log.h" |
31 | #include "inode.h" | 31 | #include "inode.h" |
32 | #include "trace_gfs2.h" | ||
32 | 33 | ||
33 | #define BFITNOENT ((u32)~0) | 34 | #define BFITNOENT ((u32)~0) |
34 | #define NO_BLOCK ((u64)~0) | 35 | #define NO_BLOCK ((u64)~0) |
@@ -1519,7 +1520,7 @@ int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n) | |||
1519 | spin_lock(&sdp->sd_rindex_spin); | 1520 | spin_lock(&sdp->sd_rindex_spin); |
1520 | rgd->rd_free_clone -= *n; | 1521 | rgd->rd_free_clone -= *n; |
1521 | spin_unlock(&sdp->sd_rindex_spin); | 1522 | spin_unlock(&sdp->sd_rindex_spin); |
1522 | 1523 | trace_gfs2_block_alloc(ip, block, *n, GFS2_BLKST_USED); | |
1523 | *bn = block; | 1524 | *bn = block; |
1524 | return 0; | 1525 | return 0; |
1525 | 1526 | ||
@@ -1571,7 +1572,7 @@ u64 gfs2_alloc_di(struct gfs2_inode *dip, u64 *generation) | |||
1571 | spin_lock(&sdp->sd_rindex_spin); | 1572 | spin_lock(&sdp->sd_rindex_spin); |
1572 | rgd->rd_free_clone--; | 1573 | rgd->rd_free_clone--; |
1573 | spin_unlock(&sdp->sd_rindex_spin); | 1574 | spin_unlock(&sdp->sd_rindex_spin); |
1574 | 1575 | trace_gfs2_block_alloc(dip, block, 1, GFS2_BLKST_DINODE); | |
1575 | return block; | 1576 | return block; |
1576 | } | 1577 | } |
1577 | 1578 | ||
@@ -1591,7 +1592,7 @@ void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen) | |||
1591 | rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE); | 1592 | rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE); |
1592 | if (!rgd) | 1593 | if (!rgd) |
1593 | return; | 1594 | return; |
1594 | 1595 | trace_gfs2_block_alloc(ip, bstart, blen, GFS2_BLKST_FREE); | |
1595 | rgd->rd_free += blen; | 1596 | rgd->rd_free += blen; |
1596 | 1597 | ||
1597 | gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); | 1598 | gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); |
@@ -1619,7 +1620,7 @@ void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen) | |||
1619 | rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE); | 1620 | rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE); |
1620 | if (!rgd) | 1621 | if (!rgd) |
1621 | return; | 1622 | return; |
1622 | 1623 | trace_gfs2_block_alloc(ip, bstart, blen, GFS2_BLKST_FREE); | |
1623 | rgd->rd_free += blen; | 1624 | rgd->rd_free += blen; |
1624 | 1625 | ||
1625 | gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); | 1626 | gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); |
@@ -1642,6 +1643,7 @@ void gfs2_unlink_di(struct inode *inode) | |||
1642 | rgd = rgblk_free(sdp, blkno, 1, GFS2_BLKST_UNLINKED); | 1643 | rgd = rgblk_free(sdp, blkno, 1, GFS2_BLKST_UNLINKED); |
1643 | if (!rgd) | 1644 | if (!rgd) |
1644 | return; | 1645 | return; |
1646 | trace_gfs2_block_alloc(ip, blkno, 1, GFS2_BLKST_UNLINKED); | ||
1645 | gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); | 1647 | gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); |
1646 | gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); | 1648 | gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); |
1647 | gfs2_trans_add_rg(rgd); | 1649 | gfs2_trans_add_rg(rgd); |
@@ -1673,6 +1675,7 @@ static void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, u64 blkno) | |||
1673 | void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) | 1675 | void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) |
1674 | { | 1676 | { |
1675 | gfs2_free_uninit_di(rgd, ip->i_no_addr); | 1677 | gfs2_free_uninit_di(rgd, ip->i_no_addr); |
1678 | trace_gfs2_block_alloc(ip, ip->i_no_addr, 1, GFS2_BLKST_FREE); | ||
1676 | gfs2_quota_change(ip, -1, ip->i_inode.i_uid, ip->i_inode.i_gid); | 1679 | gfs2_quota_change(ip, -1, ip->i_inode.i_uid, ip->i_inode.i_gid); |
1677 | gfs2_meta_wipe(ip, ip->i_no_addr, 1); | 1680 | gfs2_meta_wipe(ip, ip->i_no_addr, 1); |
1678 | } | 1681 | } |
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index c8930b31cdf0..0a6801336470 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c | |||
@@ -719,8 +719,6 @@ static void gfs2_put_super(struct super_block *sb) | |||
719 | int error; | 719 | int error; |
720 | struct gfs2_jdesc *jd; | 720 | struct gfs2_jdesc *jd; |
721 | 721 | ||
722 | lock_kernel(); | ||
723 | |||
724 | /* Unfreeze the filesystem, if we need to */ | 722 | /* Unfreeze the filesystem, if we need to */ |
725 | 723 | ||
726 | mutex_lock(&sdp->sd_freeze_lock); | 724 | mutex_lock(&sdp->sd_freeze_lock); |
@@ -787,8 +785,6 @@ restart: | |||
787 | 785 | ||
788 | /* At this point, we're through participating in the lockspace */ | 786 | /* At this point, we're through participating in the lockspace */ |
789 | gfs2_sys_fs_del(sdp); | 787 | gfs2_sys_fs_del(sdp); |
790 | |||
791 | unlock_kernel(); | ||
792 | } | 788 | } |
793 | 789 | ||
794 | /** | 790 | /** |
diff --git a/fs/gfs2/trace_gfs2.h b/fs/gfs2/trace_gfs2.h new file mode 100644 index 000000000000..98d6ef1c1dc0 --- /dev/null +++ b/fs/gfs2/trace_gfs2.h | |||
@@ -0,0 +1,407 @@ | |||
1 | #if !defined(_TRACE_GFS2_H) || defined(TRACE_HEADER_MULTI_READ) | ||
2 | #define _TRACE_GFS2_H | ||
3 | |||
4 | #include <linux/tracepoint.h> | ||
5 | |||
6 | #undef TRACE_SYSTEM | ||
7 | #define TRACE_SYSTEM gfs2 | ||
8 | #define TRACE_INCLUDE_FILE trace_gfs2 | ||
9 | |||
10 | #include <linux/fs.h> | ||
11 | #include <linux/buffer_head.h> | ||
12 | #include <linux/dlmconstants.h> | ||
13 | #include <linux/gfs2_ondisk.h> | ||
14 | #include "incore.h" | ||
15 | #include "glock.h" | ||
16 | |||
17 | #define dlm_state_name(nn) { DLM_LOCK_##nn, #nn } | ||
18 | #define glock_trace_name(x) __print_symbolic(x, \ | ||
19 | dlm_state_name(IV), \ | ||
20 | dlm_state_name(NL), \ | ||
21 | dlm_state_name(CR), \ | ||
22 | dlm_state_name(CW), \ | ||
23 | dlm_state_name(PR), \ | ||
24 | dlm_state_name(PW), \ | ||
25 | dlm_state_name(EX)) | ||
26 | |||
27 | #define block_state_name(x) __print_symbolic(x, \ | ||
28 | { GFS2_BLKST_FREE, "free" }, \ | ||
29 | { GFS2_BLKST_USED, "used" }, \ | ||
30 | { GFS2_BLKST_DINODE, "dinode" }, \ | ||
31 | { GFS2_BLKST_UNLINKED, "unlinked" }) | ||
32 | |||
33 | #define show_glock_flags(flags) __print_flags(flags, "", \ | ||
34 | {(1UL << GLF_LOCK), "l" }, \ | ||
35 | {(1UL << GLF_DEMOTE), "D" }, \ | ||
36 | {(1UL << GLF_PENDING_DEMOTE), "d" }, \ | ||
37 | {(1UL << GLF_DEMOTE_IN_PROGRESS), "p" }, \ | ||
38 | {(1UL << GLF_DIRTY), "y" }, \ | ||
39 | {(1UL << GLF_LFLUSH), "f" }, \ | ||
40 | {(1UL << GLF_INVALIDATE_IN_PROGRESS), "i" }, \ | ||
41 | {(1UL << GLF_REPLY_PENDING), "r" }, \ | ||
42 | {(1UL << GLF_INITIAL), "I" }, \ | ||
43 | {(1UL << GLF_FROZEN), "F" }) | ||
44 | |||
45 | #ifndef NUMPTY | ||
46 | #define NUMPTY | ||
47 | static inline u8 glock_trace_state(unsigned int state) | ||
48 | { | ||
49 | switch(state) { | ||
50 | case LM_ST_SHARED: | ||
51 | return DLM_LOCK_PR; | ||
52 | case LM_ST_DEFERRED: | ||
53 | return DLM_LOCK_CW; | ||
54 | case LM_ST_EXCLUSIVE: | ||
55 | return DLM_LOCK_EX; | ||
56 | } | ||
57 | return DLM_LOCK_NL; | ||
58 | } | ||
59 | #endif | ||
60 | |||
61 | /* Section 1 - Locking | ||
62 | * | ||
63 | * Objectives: | ||
64 | * Latency: Remote demote request to state change | ||
65 | * Latency: Local lock request to state change | ||
66 | * Latency: State change to lock grant | ||
67 | * Correctness: Ordering of local lock state vs. I/O requests | ||
68 | * Correctness: Responses to remote demote requests | ||
69 | */ | ||
70 | |||
71 | /* General glock state change (DLM lock request completes) */ | ||
72 | TRACE_EVENT(gfs2_glock_state_change, | ||
73 | |||
74 | TP_PROTO(const struct gfs2_glock *gl, unsigned int new_state), | ||
75 | |||
76 | TP_ARGS(gl, new_state), | ||
77 | |||
78 | TP_STRUCT__entry( | ||
79 | __field( dev_t, dev ) | ||
80 | __field( u64, glnum ) | ||
81 | __field( u32, gltype ) | ||
82 | __field( u8, cur_state ) | ||
83 | __field( u8, new_state ) | ||
84 | __field( u8, dmt_state ) | ||
85 | __field( u8, tgt_state ) | ||
86 | __field( unsigned long, flags ) | ||
87 | ), | ||
88 | |||
89 | TP_fast_assign( | ||
90 | __entry->dev = gl->gl_sbd->sd_vfs->s_dev; | ||
91 | __entry->glnum = gl->gl_name.ln_number; | ||
92 | __entry->gltype = gl->gl_name.ln_type; | ||
93 | __entry->cur_state = glock_trace_state(gl->gl_state); | ||
94 | __entry->new_state = glock_trace_state(new_state); | ||
95 | __entry->tgt_state = glock_trace_state(gl->gl_target); | ||
96 | __entry->dmt_state = glock_trace_state(gl->gl_demote_state); | ||
97 | __entry->flags = gl->gl_flags; | ||
98 | ), | ||
99 | |||
100 | TP_printk("%u,%u glock %d:%lld state %s to %s tgt:%s dmt:%s flags:%s", | ||
101 | MAJOR(__entry->dev), MINOR(__entry->dev), __entry->gltype, | ||
102 | (unsigned long long)__entry->glnum, | ||
103 | glock_trace_name(__entry->cur_state), | ||
104 | glock_trace_name(__entry->new_state), | ||
105 | glock_trace_name(__entry->tgt_state), | ||
106 | glock_trace_name(__entry->dmt_state), | ||
107 | show_glock_flags(__entry->flags)) | ||
108 | ); | ||
109 | |||
110 | /* State change -> unlocked, glock is being deallocated */ | ||
111 | TRACE_EVENT(gfs2_glock_put, | ||
112 | |||
113 | TP_PROTO(const struct gfs2_glock *gl), | ||
114 | |||
115 | TP_ARGS(gl), | ||
116 | |||
117 | TP_STRUCT__entry( | ||
118 | __field( dev_t, dev ) | ||
119 | __field( u64, glnum ) | ||
120 | __field( u32, gltype ) | ||
121 | __field( u8, cur_state ) | ||
122 | __field( unsigned long, flags ) | ||
123 | ), | ||
124 | |||
125 | TP_fast_assign( | ||
126 | __entry->dev = gl->gl_sbd->sd_vfs->s_dev; | ||
127 | __entry->gltype = gl->gl_name.ln_type; | ||
128 | __entry->glnum = gl->gl_name.ln_number; | ||
129 | __entry->cur_state = glock_trace_state(gl->gl_state); | ||
130 | __entry->flags = gl->gl_flags; | ||
131 | ), | ||
132 | |||
133 | TP_printk("%u,%u glock %d:%lld state %s => %s flags:%s", | ||
134 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
135 | __entry->gltype, (unsigned long long)__entry->glnum, | ||
136 | glock_trace_name(__entry->cur_state), | ||
137 | glock_trace_name(DLM_LOCK_IV), | ||
138 | show_glock_flags(__entry->flags)) | ||
139 | |||
140 | ); | ||
141 | |||
142 | /* Callback (local or remote) requesting lock demotion */ | ||
143 | TRACE_EVENT(gfs2_demote_rq, | ||
144 | |||
145 | TP_PROTO(const struct gfs2_glock *gl), | ||
146 | |||
147 | TP_ARGS(gl), | ||
148 | |||
149 | TP_STRUCT__entry( | ||
150 | __field( dev_t, dev ) | ||
151 | __field( u64, glnum ) | ||
152 | __field( u32, gltype ) | ||
153 | __field( u8, cur_state ) | ||
154 | __field( u8, dmt_state ) | ||
155 | __field( unsigned long, flags ) | ||
156 | ), | ||
157 | |||
158 | TP_fast_assign( | ||
159 | __entry->dev = gl->gl_sbd->sd_vfs->s_dev; | ||
160 | __entry->gltype = gl->gl_name.ln_type; | ||
161 | __entry->glnum = gl->gl_name.ln_number; | ||
162 | __entry->cur_state = glock_trace_state(gl->gl_state); | ||
163 | __entry->dmt_state = glock_trace_state(gl->gl_demote_state); | ||
164 | __entry->flags = gl->gl_flags; | ||
165 | ), | ||
166 | |||
167 | TP_printk("%u,%u glock %d:%lld demote %s to %s flags:%s", | ||
168 | MAJOR(__entry->dev), MINOR(__entry->dev), __entry->gltype, | ||
169 | (unsigned long long)__entry->glnum, | ||
170 | glock_trace_name(__entry->cur_state), | ||
171 | glock_trace_name(__entry->dmt_state), | ||
172 | show_glock_flags(__entry->flags)) | ||
173 | |||
174 | ); | ||
175 | |||
176 | /* Promotion/grant of a glock */ | ||
177 | TRACE_EVENT(gfs2_promote, | ||
178 | |||
179 | TP_PROTO(const struct gfs2_holder *gh, int first), | ||
180 | |||
181 | TP_ARGS(gh, first), | ||
182 | |||
183 | TP_STRUCT__entry( | ||
184 | __field( dev_t, dev ) | ||
185 | __field( u64, glnum ) | ||
186 | __field( u32, gltype ) | ||
187 | __field( int, first ) | ||
188 | __field( u8, state ) | ||
189 | ), | ||
190 | |||
191 | TP_fast_assign( | ||
192 | __entry->dev = gh->gh_gl->gl_sbd->sd_vfs->s_dev; | ||
193 | __entry->glnum = gh->gh_gl->gl_name.ln_number; | ||
194 | __entry->gltype = gh->gh_gl->gl_name.ln_type; | ||
195 | __entry->first = first; | ||
196 | __entry->state = glock_trace_state(gh->gh_state); | ||
197 | ), | ||
198 | |||
199 | TP_printk("%u,%u glock %u:%llu promote %s %s", | ||
200 | MAJOR(__entry->dev), MINOR(__entry->dev), __entry->gltype, | ||
201 | (unsigned long long)__entry->glnum, | ||
202 | __entry->first ? "first": "other", | ||
203 | glock_trace_name(__entry->state)) | ||
204 | ); | ||
205 | |||
206 | /* Queue/dequeue a lock request */ | ||
207 | TRACE_EVENT(gfs2_glock_queue, | ||
208 | |||
209 | TP_PROTO(const struct gfs2_holder *gh, int queue), | ||
210 | |||
211 | TP_ARGS(gh, queue), | ||
212 | |||
213 | TP_STRUCT__entry( | ||
214 | __field( dev_t, dev ) | ||
215 | __field( u64, glnum ) | ||
216 | __field( u32, gltype ) | ||
217 | __field( int, queue ) | ||
218 | __field( u8, state ) | ||
219 | ), | ||
220 | |||
221 | TP_fast_assign( | ||
222 | __entry->dev = gh->gh_gl->gl_sbd->sd_vfs->s_dev; | ||
223 | __entry->glnum = gh->gh_gl->gl_name.ln_number; | ||
224 | __entry->gltype = gh->gh_gl->gl_name.ln_type; | ||
225 | __entry->queue = queue; | ||
226 | __entry->state = glock_trace_state(gh->gh_state); | ||
227 | ), | ||
228 | |||
229 | TP_printk("%u,%u glock %u:%llu %squeue %s", | ||
230 | MAJOR(__entry->dev), MINOR(__entry->dev), __entry->gltype, | ||
231 | (unsigned long long)__entry->glnum, | ||
232 | __entry->queue ? "" : "de", | ||
233 | glock_trace_name(__entry->state)) | ||
234 | ); | ||
235 | |||
236 | /* Section 2 - Log/journal | ||
237 | * | ||
238 | * Objectives: | ||
239 | * Latency: Log flush time | ||
240 | * Correctness: pin/unpin vs. disk I/O ordering | ||
241 | * Performance: Log usage stats | ||
242 | */ | ||
243 | |||
244 | /* Pin/unpin a block in the log */ | ||
245 | TRACE_EVENT(gfs2_pin, | ||
246 | |||
247 | TP_PROTO(const struct gfs2_bufdata *bd, int pin), | ||
248 | |||
249 | TP_ARGS(bd, pin), | ||
250 | |||
251 | TP_STRUCT__entry( | ||
252 | __field( dev_t, dev ) | ||
253 | __field( int, pin ) | ||
254 | __field( u32, len ) | ||
255 | __field( sector_t, block ) | ||
256 | __field( u64, ino ) | ||
257 | ), | ||
258 | |||
259 | TP_fast_assign( | ||
260 | __entry->dev = bd->bd_gl->gl_sbd->sd_vfs->s_dev; | ||
261 | __entry->pin = pin; | ||
262 | __entry->len = bd->bd_bh->b_size; | ||
263 | __entry->block = bd->bd_bh->b_blocknr; | ||
264 | __entry->ino = bd->bd_gl->gl_name.ln_number; | ||
265 | ), | ||
266 | |||
267 | TP_printk("%u,%u log %s %llu/%lu inode %llu", | ||
268 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
269 | __entry->pin ? "pin" : "unpin", | ||
270 | (unsigned long long)__entry->block, | ||
271 | (unsigned long)__entry->len, | ||
272 | (unsigned long long)__entry->ino) | ||
273 | ); | ||
274 | |||
275 | /* Flushing the log */ | ||
276 | TRACE_EVENT(gfs2_log_flush, | ||
277 | |||
278 | TP_PROTO(const struct gfs2_sbd *sdp, int start), | ||
279 | |||
280 | TP_ARGS(sdp, start), | ||
281 | |||
282 | TP_STRUCT__entry( | ||
283 | __field( dev_t, dev ) | ||
284 | __field( int, start ) | ||
285 | __field( u64, log_seq ) | ||
286 | ), | ||
287 | |||
288 | TP_fast_assign( | ||
289 | __entry->dev = sdp->sd_vfs->s_dev; | ||
290 | __entry->start = start; | ||
291 | __entry->log_seq = sdp->sd_log_sequence; | ||
292 | ), | ||
293 | |||
294 | TP_printk("%u,%u log flush %s %llu", | ||
295 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
296 | __entry->start ? "start" : "end", | ||
297 | (unsigned long long)__entry->log_seq) | ||
298 | ); | ||
299 | |||
300 | /* Reserving/releasing blocks in the log */ | ||
301 | TRACE_EVENT(gfs2_log_blocks, | ||
302 | |||
303 | TP_PROTO(const struct gfs2_sbd *sdp, int blocks), | ||
304 | |||
305 | TP_ARGS(sdp, blocks), | ||
306 | |||
307 | TP_STRUCT__entry( | ||
308 | __field( dev_t, dev ) | ||
309 | __field( int, blocks ) | ||
310 | ), | ||
311 | |||
312 | TP_fast_assign( | ||
313 | __entry->dev = sdp->sd_vfs->s_dev; | ||
314 | __entry->blocks = blocks; | ||
315 | ), | ||
316 | |||
317 | TP_printk("%u,%u log reserve %d", MAJOR(__entry->dev), | ||
318 | MINOR(__entry->dev), __entry->blocks) | ||
319 | ); | ||
320 | |||
321 | /* Section 3 - bmap | ||
322 | * | ||
323 | * Objectives: | ||
324 | * Latency: Bmap request time | ||
325 | * Performance: Block allocator tracing | ||
326 | * Correctness: Test of disard generation vs. blocks allocated | ||
327 | */ | ||
328 | |||
329 | /* Map an extent of blocks, possibly a new allocation */ | ||
330 | TRACE_EVENT(gfs2_bmap, | ||
331 | |||
332 | TP_PROTO(const struct gfs2_inode *ip, const struct buffer_head *bh, | ||
333 | sector_t lblock, int create, int errno), | ||
334 | |||
335 | TP_ARGS(ip, bh, lblock, create, errno), | ||
336 | |||
337 | TP_STRUCT__entry( | ||
338 | __field( dev_t, dev ) | ||
339 | __field( sector_t, lblock ) | ||
340 | __field( sector_t, pblock ) | ||
341 | __field( u64, inum ) | ||
342 | __field( unsigned long, state ) | ||
343 | __field( u32, len ) | ||
344 | __field( int, create ) | ||
345 | __field( int, errno ) | ||
346 | ), | ||
347 | |||
348 | TP_fast_assign( | ||
349 | __entry->dev = ip->i_gl->gl_sbd->sd_vfs->s_dev; | ||
350 | __entry->lblock = lblock; | ||
351 | __entry->pblock = buffer_mapped(bh) ? bh->b_blocknr : 0; | ||
352 | __entry->inum = ip->i_no_addr; | ||
353 | __entry->state = bh->b_state; | ||
354 | __entry->len = bh->b_size; | ||
355 | __entry->create = create; | ||
356 | __entry->errno = errno; | ||
357 | ), | ||
358 | |||
359 | TP_printk("%u,%u bmap %llu map %llu/%lu to %llu flags:%08lx %s %d", | ||
360 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
361 | (unsigned long long)__entry->inum, | ||
362 | (unsigned long long)__entry->lblock, | ||
363 | (unsigned long)__entry->len, | ||
364 | (unsigned long long)__entry->pblock, | ||
365 | __entry->state, __entry->create ? "create " : "nocreate", | ||
366 | __entry->errno) | ||
367 | ); | ||
368 | |||
369 | /* Keep track of blocks as they are allocated/freed */ | ||
370 | TRACE_EVENT(gfs2_block_alloc, | ||
371 | |||
372 | TP_PROTO(const struct gfs2_inode *ip, u64 block, unsigned len, | ||
373 | u8 block_state), | ||
374 | |||
375 | TP_ARGS(ip, block, len, block_state), | ||
376 | |||
377 | TP_STRUCT__entry( | ||
378 | __field( dev_t, dev ) | ||
379 | __field( u64, start ) | ||
380 | __field( u64, inum ) | ||
381 | __field( u32, len ) | ||
382 | __field( u8, block_state ) | ||
383 | ), | ||
384 | |||
385 | TP_fast_assign( | ||
386 | __entry->dev = ip->i_gl->gl_sbd->sd_vfs->s_dev; | ||
387 | __entry->start = block; | ||
388 | __entry->inum = ip->i_no_addr; | ||
389 | __entry->len = len; | ||
390 | __entry->block_state = block_state; | ||
391 | ), | ||
392 | |||
393 | TP_printk("%u,%u bmap %llu alloc %llu/%lu %s", | ||
394 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
395 | (unsigned long long)__entry->inum, | ||
396 | (unsigned long long)__entry->start, | ||
397 | (unsigned long)__entry->len, | ||
398 | block_state_name(__entry->block_state)) | ||
399 | ); | ||
400 | |||
401 | #endif /* _TRACE_GFS2_H */ | ||
402 | |||
403 | /* This part must be outside protection */ | ||
404 | #undef TRACE_INCLUDE_PATH | ||
405 | #define TRACE_INCLUDE_PATH . | ||
406 | #include <trace/define_trace.h> | ||
407 | |||
diff --git a/fs/partitions/check.c b/fs/partitions/check.c index 0af36085eb28..1a9c7878f864 100644 --- a/fs/partitions/check.c +++ b/fs/partitions/check.c | |||
@@ -556,27 +556,49 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) | |||
556 | 556 | ||
557 | /* add partitions */ | 557 | /* add partitions */ |
558 | for (p = 1; p < state->limit; p++) { | 558 | for (p = 1; p < state->limit; p++) { |
559 | sector_t size = state->parts[p].size; | 559 | sector_t size, from; |
560 | sector_t from = state->parts[p].from; | 560 | try_scan: |
561 | size = state->parts[p].size; | ||
561 | if (!size) | 562 | if (!size) |
562 | continue; | 563 | continue; |
564 | |||
565 | from = state->parts[p].from; | ||
563 | if (from >= get_capacity(disk)) { | 566 | if (from >= get_capacity(disk)) { |
564 | printk(KERN_WARNING | 567 | printk(KERN_WARNING |
565 | "%s: p%d ignored, start %llu is behind the end of the disk\n", | 568 | "%s: p%d ignored, start %llu is behind the end of the disk\n", |
566 | disk->disk_name, p, (unsigned long long) from); | 569 | disk->disk_name, p, (unsigned long long) from); |
567 | continue; | 570 | continue; |
568 | } | 571 | } |
572 | |||
569 | if (from + size > get_capacity(disk)) { | 573 | if (from + size > get_capacity(disk)) { |
570 | /* | 574 | struct block_device_operations *bdops = disk->fops; |
571 | * we can not ignore partitions of broken tables | 575 | unsigned long long capacity; |
572 | * created by for example camera firmware, but we | 576 | |
573 | * limit them to the end of the disk to avoid | ||
574 | * creating invalid block devices | ||
575 | */ | ||
576 | printk(KERN_WARNING | 577 | printk(KERN_WARNING |
577 | "%s: p%d size %llu limited to end of disk\n", | 578 | "%s: p%d size %llu exceeds device capacity, ", |
578 | disk->disk_name, p, (unsigned long long) size); | 579 | disk->disk_name, p, (unsigned long long) size); |
579 | size = get_capacity(disk) - from; | 580 | |
581 | if (bdops->set_capacity && | ||
582 | (disk->flags & GENHD_FL_NATIVE_CAPACITY) == 0) { | ||
583 | printk(KERN_CONT "enabling native capacity\n"); | ||
584 | capacity = bdops->set_capacity(disk, ~0ULL); | ||
585 | disk->flags |= GENHD_FL_NATIVE_CAPACITY; | ||
586 | if (capacity > get_capacity(disk)) { | ||
587 | set_capacity(disk, capacity); | ||
588 | check_disk_size_change(disk, bdev); | ||
589 | bdev->bd_invalidated = 0; | ||
590 | } | ||
591 | goto try_scan; | ||
592 | } else { | ||
593 | /* | ||
594 | * we can not ignore partitions of broken tables | ||
595 | * created by for example camera firmware, but | ||
596 | * we limit them to the end of the disk to avoid | ||
597 | * creating invalid block devices | ||
598 | */ | ||
599 | printk(KERN_CONT "limited to end of disk\n"); | ||
600 | size = get_capacity(disk) - from; | ||
601 | } | ||
580 | } | 602 | } |
581 | part = add_partition(disk, p, from, size, | 603 | part = add_partition(disk, p, from, size, |
582 | state->parts[p].flags); | 604 | state->parts[p].flags); |