diff options
author | David S. Miller <davem@davemloft.net> | 2009-11-19 01:19:03 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-11-19 01:19:03 -0500 |
commit | 3505d1a9fd65e2d3e00827857b6795d9d8983658 (patch) | |
tree | 941cfafdb57c427bb6b7ebf6354ee93b2a3693b5 /fs | |
parent | dfef948ed2ba69cf041840b5e860d6b4e16fa0b1 (diff) | |
parent | 66b00a7c93ec782d118d2c03bd599cfd041e80a1 (diff) |
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
Conflicts:
drivers/net/sfc/sfe4001.c
drivers/net/wireless/libertas/cmd.c
drivers/staging/Kconfig
drivers/staging/Makefile
drivers/staging/rtl8187se/Kconfig
drivers/staging/rtl8192e/Kconfig
Diffstat (limited to 'fs')
101 files changed, 1413 insertions, 610 deletions
diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index 873cd31baa47..15cce53bf61e 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c | |||
@@ -40,6 +40,24 @@ | |||
40 | #include "fid.h" | 40 | #include "fid.h" |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * struct p9_rdir - readdir accounting | ||
44 | * @mutex: mutex protecting readdir | ||
45 | * @head: start offset of current dirread buffer | ||
46 | * @tail: end offset of current dirread buffer | ||
47 | * @buf: dirread buffer | ||
48 | * | ||
49 | * private structure for keeping track of readdir | ||
50 | * allocated on demand | ||
51 | */ | ||
52 | |||
53 | struct p9_rdir { | ||
54 | struct mutex mutex; | ||
55 | int head; | ||
56 | int tail; | ||
57 | uint8_t *buf; | ||
58 | }; | ||
59 | |||
60 | /** | ||
43 | * dt_type - return file type | 61 | * dt_type - return file type |
44 | * @mistat: mistat structure | 62 | * @mistat: mistat structure |
45 | * | 63 | * |
@@ -70,56 +88,79 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
70 | { | 88 | { |
71 | int over; | 89 | int over; |
72 | struct p9_wstat st; | 90 | struct p9_wstat st; |
73 | int err; | 91 | int err = 0; |
74 | struct p9_fid *fid; | 92 | struct p9_fid *fid; |
75 | int buflen; | 93 | int buflen; |
76 | char *statbuf; | 94 | int reclen = 0; |
77 | int n, i = 0; | 95 | struct p9_rdir *rdir; |
78 | 96 | ||
79 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name); | 97 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name); |
80 | fid = filp->private_data; | 98 | fid = filp->private_data; |
81 | 99 | ||
82 | buflen = fid->clnt->msize - P9_IOHDRSZ; | 100 | buflen = fid->clnt->msize - P9_IOHDRSZ; |
83 | statbuf = kmalloc(buflen, GFP_KERNEL); | 101 | |
84 | if (!statbuf) | 102 | /* allocate rdir on demand */ |
85 | return -ENOMEM; | 103 | if (!fid->rdir) { |
86 | 104 | rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL); | |
87 | while (1) { | 105 | |
88 | err = v9fs_file_readn(filp, statbuf, NULL, buflen, | 106 | if (rdir == NULL) { |
89 | fid->rdir_fpos); | 107 | err = -ENOMEM; |
90 | if (err <= 0) | 108 | goto exit; |
91 | break; | 109 | } |
92 | 110 | spin_lock(&filp->f_dentry->d_lock); | |
93 | n = err; | 111 | if (!fid->rdir) { |
94 | while (i < n) { | 112 | rdir->buf = (uint8_t *)rdir + sizeof(struct p9_rdir); |
95 | err = p9stat_read(statbuf + i, buflen-i, &st, | 113 | mutex_init(&rdir->mutex); |
96 | fid->clnt->dotu); | 114 | rdir->head = rdir->tail = 0; |
115 | fid->rdir = (void *) rdir; | ||
116 | rdir = NULL; | ||
117 | } | ||
118 | spin_unlock(&filp->f_dentry->d_lock); | ||
119 | kfree(rdir); | ||
120 | } | ||
121 | rdir = (struct p9_rdir *) fid->rdir; | ||
122 | |||
123 | err = mutex_lock_interruptible(&rdir->mutex); | ||
124 | while (err == 0) { | ||
125 | if (rdir->tail == rdir->head) { | ||
126 | err = v9fs_file_readn(filp, rdir->buf, NULL, | ||
127 | buflen, filp->f_pos); | ||
128 | if (err <= 0) | ||
129 | goto unlock_and_exit; | ||
130 | |||
131 | rdir->head = 0; | ||
132 | rdir->tail = err; | ||
133 | } | ||
134 | |||
135 | while (rdir->head < rdir->tail) { | ||
136 | err = p9stat_read(rdir->buf + rdir->head, | ||
137 | buflen - rdir->head, &st, | ||
138 | fid->clnt->dotu); | ||
97 | if (err) { | 139 | if (err) { |
98 | P9_DPRINTK(P9_DEBUG_VFS, "returned %d\n", err); | 140 | P9_DPRINTK(P9_DEBUG_VFS, "returned %d\n", err); |
99 | err = -EIO; | 141 | err = -EIO; |
100 | p9stat_free(&st); | 142 | p9stat_free(&st); |
101 | goto free_and_exit; | 143 | goto unlock_and_exit; |
102 | } | 144 | } |
103 | 145 | reclen = st.size+2; | |
104 | i += st.size+2; | ||
105 | fid->rdir_fpos += st.size+2; | ||
106 | 146 | ||
107 | over = filldir(dirent, st.name, strlen(st.name), | 147 | over = filldir(dirent, st.name, strlen(st.name), |
108 | filp->f_pos, v9fs_qid2ino(&st.qid), dt_type(&st)); | 148 | filp->f_pos, v9fs_qid2ino(&st.qid), dt_type(&st)); |
109 | 149 | ||
110 | filp->f_pos += st.size+2; | ||
111 | |||
112 | p9stat_free(&st); | 150 | p9stat_free(&st); |
113 | 151 | ||
114 | if (over) { | 152 | if (over) { |
115 | err = 0; | 153 | err = 0; |
116 | goto free_and_exit; | 154 | goto unlock_and_exit; |
117 | } | 155 | } |
156 | rdir->head += reclen; | ||
157 | filp->f_pos += reclen; | ||
118 | } | 158 | } |
119 | } | 159 | } |
120 | 160 | ||
121 | free_and_exit: | 161 | unlock_and_exit: |
122 | kfree(statbuf); | 162 | mutex_unlock(&rdir->mutex); |
163 | exit: | ||
123 | return err; | 164 | return err; |
124 | } | 165 | } |
125 | 166 | ||
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 5947628aefef..18f74ec4dce9 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c | |||
@@ -994,8 +994,7 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) | |||
994 | P9_DPRINTK(P9_DEBUG_VFS, | 994 | P9_DPRINTK(P9_DEBUG_VFS, |
995 | "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer); | 995 | "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer); |
996 | 996 | ||
997 | retval = buflen; | 997 | retval = strnlen(buffer, buflen); |
998 | |||
999 | done: | 998 | done: |
1000 | kfree(st); | 999 | kfree(st); |
1001 | return retval; | 1000 | return retval; |
@@ -1062,7 +1061,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
1062 | __putname(link); | 1061 | __putname(link); |
1063 | link = ERR_PTR(len); | 1062 | link = ERR_PTR(len); |
1064 | } else | 1063 | } else |
1065 | link[len] = 0; | 1064 | link[min(len, PATH_MAX-1)] = 0; |
1066 | } | 1065 | } |
1067 | nd_set_link(nd, link); | 1066 | nd_set_link(nd, link); |
1068 | 1067 | ||
diff --git a/fs/Kconfig b/fs/Kconfig index d4bf8caad8d0..64d44efad7a5 100644 --- a/fs/Kconfig +++ b/fs/Kconfig | |||
@@ -135,8 +135,8 @@ config TMPFS_POSIX_ACL | |||
135 | 135 | ||
136 | config HUGETLBFS | 136 | config HUGETLBFS |
137 | bool "HugeTLB file system support" | 137 | bool "HugeTLB file system support" |
138 | depends on X86 || IA64 || PPC64 || SPARC64 || (SUPERH && MMU) || \ | 138 | depends on X86 || IA64 || SPARC64 || (S390 && 64BIT) || \ |
139 | (S390 && 64BIT) || SYS_SUPPORTS_HUGETLBFS || BROKEN | 139 | SYS_SUPPORTS_HUGETLBFS || BROKEN |
140 | help | 140 | help |
141 | hugetlbfs is a filesystem backing for HugeTLB pages, based on | 141 | hugetlbfs is a filesystem backing for HugeTLB pages, based on |
142 | ramfs. For architectures that support it, say Y here and read | 142 | ramfs. For architectures that support it, say Y here and read |
@@ -325,8 +325,16 @@ static void bio_fs_destructor(struct bio *bio) | |||
325 | * @gfp_mask: allocation mask to use | 325 | * @gfp_mask: allocation mask to use |
326 | * @nr_iovecs: number of iovecs | 326 | * @nr_iovecs: number of iovecs |
327 | * | 327 | * |
328 | * Allocate a new bio with @nr_iovecs bvecs. If @gfp_mask | 328 | * bio_alloc will allocate a bio and associated bio_vec array that can hold |
329 | * contains __GFP_WAIT, the allocation is guaranteed to succeed. | 329 | * at least @nr_iovecs entries. Allocations will be done from the |
330 | * fs_bio_set. Also see @bio_alloc_bioset and @bio_kmalloc. | ||
331 | * | ||
332 | * If %__GFP_WAIT is set, then bio_alloc will always be able to allocate | ||
333 | * a bio. This is due to the mempool guarantees. To make this work, callers | ||
334 | * must never allocate more than 1 bio at a time from this pool. Callers | ||
335 | * that need to allocate more than 1 bio must always submit the previously | ||
336 | * allocated bio for IO before attempting to allocate a new one. Failure to | ||
337 | * do so can cause livelocks under memory pressure. | ||
330 | * | 338 | * |
331 | * RETURNS: | 339 | * RETURNS: |
332 | * Pointer to new bio on success, NULL on failure. | 340 | * Pointer to new bio on success, NULL on failure. |
@@ -350,21 +358,13 @@ static void bio_kmalloc_destructor(struct bio *bio) | |||
350 | } | 358 | } |
351 | 359 | ||
352 | /** | 360 | /** |
353 | * bio_alloc - allocate a bio for I/O | 361 | * bio_kmalloc - allocate a bio for I/O using kmalloc() |
354 | * @gfp_mask: the GFP_ mask given to the slab allocator | 362 | * @gfp_mask: the GFP_ mask given to the slab allocator |
355 | * @nr_iovecs: number of iovecs to pre-allocate | 363 | * @nr_iovecs: number of iovecs to pre-allocate |
356 | * | 364 | * |
357 | * Description: | 365 | * Description: |
358 | * bio_alloc will allocate a bio and associated bio_vec array that can hold | 366 | * Allocate a new bio with @nr_iovecs bvecs. If @gfp_mask contains |
359 | * at least @nr_iovecs entries. Allocations will be done from the | 367 | * %__GFP_WAIT, the allocation is guaranteed to succeed. |
360 | * fs_bio_set. Also see @bio_alloc_bioset. | ||
361 | * | ||
362 | * If %__GFP_WAIT is set, then bio_alloc will always be able to allocate | ||
363 | * a bio. This is due to the mempool guarantees. To make this work, callers | ||
364 | * must never allocate more than 1 bio at a time from this pool. Callers | ||
365 | * that need to allocate more than 1 bio must always submit the previously | ||
366 | * allocated bio for IO before attempting to allocate a new one. Failure to | ||
367 | * do so can cause livelocks under memory pressure. | ||
368 | * | 368 | * |
369 | **/ | 369 | **/ |
370 | struct bio *bio_kmalloc(gfp_t gfp_mask, int nr_iovecs) | 370 | struct bio *bio_kmalloc(gfp_t gfp_mask, int nr_iovecs) |
@@ -407,7 +407,7 @@ EXPORT_SYMBOL(zero_fill_bio); | |||
407 | * | 407 | * |
408 | * Description: | 408 | * Description: |
409 | * Put a reference to a &struct bio, either one you have gotten with | 409 | * Put a reference to a &struct bio, either one you have gotten with |
410 | * bio_alloc or bio_get. The last put of a bio will free it. | 410 | * bio_alloc, bio_get or bio_clone. The last put of a bio will free it. |
411 | **/ | 411 | **/ |
412 | void bio_put(struct bio *bio) | 412 | void bio_put(struct bio *bio) |
413 | { | 413 | { |
diff --git a/fs/block_dev.c b/fs/block_dev.c index 9cf4b926f8e4..8bed0557d88c 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c | |||
@@ -1248,8 +1248,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) | |||
1248 | bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9); | 1248 | bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9); |
1249 | } | 1249 | } |
1250 | } else { | 1250 | } else { |
1251 | put_disk(disk); | ||
1252 | module_put(disk->fops->owner); | 1251 | module_put(disk->fops->owner); |
1252 | put_disk(disk); | ||
1253 | disk = NULL; | 1253 | disk = NULL; |
1254 | if (bdev->bd_contains == bdev) { | 1254 | if (bdev->bd_contains == bdev) { |
1255 | if (bdev->bd_disk->fops->open) { | 1255 | if (bdev->bd_disk->fops->open) { |
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 69b355ae7f49..361604244271 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include "btrfs_inode.h" | 27 | #include "btrfs_inode.h" |
28 | #include "xattr.h" | 28 | #include "xattr.h" |
29 | 29 | ||
30 | #ifdef CONFIG_BTRFS_POSIX_ACL | 30 | #ifdef CONFIG_BTRFS_FS_POSIX_ACL |
31 | 31 | ||
32 | static struct posix_acl *btrfs_get_acl(struct inode *inode, int type) | 32 | static struct posix_acl *btrfs_get_acl(struct inode *inode, int type) |
33 | { | 33 | { |
@@ -313,7 +313,7 @@ struct xattr_handler btrfs_xattr_acl_access_handler = { | |||
313 | .set = btrfs_xattr_acl_access_set, | 313 | .set = btrfs_xattr_acl_access_set, |
314 | }; | 314 | }; |
315 | 315 | ||
316 | #else /* CONFIG_BTRFS_POSIX_ACL */ | 316 | #else /* CONFIG_BTRFS_FS_POSIX_ACL */ |
317 | 317 | ||
318 | int btrfs_acl_chmod(struct inode *inode) | 318 | int btrfs_acl_chmod(struct inode *inode) |
319 | { | 319 | { |
@@ -325,4 +325,4 @@ int btrfs_init_acl(struct inode *inode, struct inode *dir) | |||
325 | return 0; | 325 | return 0; |
326 | } | 326 | } |
327 | 327 | ||
328 | #endif /* CONFIG_BTRFS_POSIX_ACL */ | 328 | #endif /* CONFIG_BTRFS_FS_POSIX_ACL */ |
diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c index 282ca085c2fb..c0861e781cdb 100644 --- a/fs/btrfs/async-thread.c +++ b/fs/btrfs/async-thread.c | |||
@@ -64,6 +64,51 @@ struct btrfs_worker_thread { | |||
64 | }; | 64 | }; |
65 | 65 | ||
66 | /* | 66 | /* |
67 | * btrfs_start_workers uses kthread_run, which can block waiting for memory | ||
68 | * for a very long time. It will actually throttle on page writeback, | ||
69 | * and so it may not make progress until after our btrfs worker threads | ||
70 | * process all of the pending work structs in their queue | ||
71 | * | ||
72 | * This means we can't use btrfs_start_workers from inside a btrfs worker | ||
73 | * thread that is used as part of cleaning dirty memory, which pretty much | ||
74 | * involves all of the worker threads. | ||
75 | * | ||
76 | * Instead we have a helper queue who never has more than one thread | ||
77 | * where we scheduler thread start operations. This worker_start struct | ||
78 | * is used to contain the work and hold a pointer to the queue that needs | ||
79 | * another worker. | ||
80 | */ | ||
81 | struct worker_start { | ||
82 | struct btrfs_work work; | ||
83 | struct btrfs_workers *queue; | ||
84 | }; | ||
85 | |||
86 | static void start_new_worker_func(struct btrfs_work *work) | ||
87 | { | ||
88 | struct worker_start *start; | ||
89 | start = container_of(work, struct worker_start, work); | ||
90 | btrfs_start_workers(start->queue, 1); | ||
91 | kfree(start); | ||
92 | } | ||
93 | |||
94 | static int start_new_worker(struct btrfs_workers *queue) | ||
95 | { | ||
96 | struct worker_start *start; | ||
97 | int ret; | ||
98 | |||
99 | start = kzalloc(sizeof(*start), GFP_NOFS); | ||
100 | if (!start) | ||
101 | return -ENOMEM; | ||
102 | |||
103 | start->work.func = start_new_worker_func; | ||
104 | start->queue = queue; | ||
105 | ret = btrfs_queue_worker(queue->atomic_worker_start, &start->work); | ||
106 | if (ret) | ||
107 | kfree(start); | ||
108 | return ret; | ||
109 | } | ||
110 | |||
111 | /* | ||
67 | * helper function to move a thread onto the idle list after it | 112 | * helper function to move a thread onto the idle list after it |
68 | * has finished some requests. | 113 | * has finished some requests. |
69 | */ | 114 | */ |
@@ -118,11 +163,13 @@ static void check_pending_worker_creates(struct btrfs_worker_thread *worker) | |||
118 | goto out; | 163 | goto out; |
119 | 164 | ||
120 | workers->atomic_start_pending = 0; | 165 | workers->atomic_start_pending = 0; |
121 | if (workers->num_workers >= workers->max_workers) | 166 | if (workers->num_workers + workers->num_workers_starting >= |
167 | workers->max_workers) | ||
122 | goto out; | 168 | goto out; |
123 | 169 | ||
170 | workers->num_workers_starting += 1; | ||
124 | spin_unlock_irqrestore(&workers->lock, flags); | 171 | spin_unlock_irqrestore(&workers->lock, flags); |
125 | btrfs_start_workers(workers, 1); | 172 | start_new_worker(workers); |
126 | return; | 173 | return; |
127 | 174 | ||
128 | out: | 175 | out: |
@@ -390,9 +437,11 @@ int btrfs_stop_workers(struct btrfs_workers *workers) | |||
390 | /* | 437 | /* |
391 | * simple init on struct btrfs_workers | 438 | * simple init on struct btrfs_workers |
392 | */ | 439 | */ |
393 | void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max) | 440 | void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max, |
441 | struct btrfs_workers *async_helper) | ||
394 | { | 442 | { |
395 | workers->num_workers = 0; | 443 | workers->num_workers = 0; |
444 | workers->num_workers_starting = 0; | ||
396 | INIT_LIST_HEAD(&workers->worker_list); | 445 | INIT_LIST_HEAD(&workers->worker_list); |
397 | INIT_LIST_HEAD(&workers->idle_list); | 446 | INIT_LIST_HEAD(&workers->idle_list); |
398 | INIT_LIST_HEAD(&workers->order_list); | 447 | INIT_LIST_HEAD(&workers->order_list); |
@@ -404,14 +453,15 @@ void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max) | |||
404 | workers->name = name; | 453 | workers->name = name; |
405 | workers->ordered = 0; | 454 | workers->ordered = 0; |
406 | workers->atomic_start_pending = 0; | 455 | workers->atomic_start_pending = 0; |
407 | workers->atomic_worker_start = 0; | 456 | workers->atomic_worker_start = async_helper; |
408 | } | 457 | } |
409 | 458 | ||
410 | /* | 459 | /* |
411 | * starts new worker threads. This does not enforce the max worker | 460 | * starts new worker threads. This does not enforce the max worker |
412 | * count in case you need to temporarily go past it. | 461 | * count in case you need to temporarily go past it. |
413 | */ | 462 | */ |
414 | int btrfs_start_workers(struct btrfs_workers *workers, int num_workers) | 463 | static int __btrfs_start_workers(struct btrfs_workers *workers, |
464 | int num_workers) | ||
415 | { | 465 | { |
416 | struct btrfs_worker_thread *worker; | 466 | struct btrfs_worker_thread *worker; |
417 | int ret = 0; | 467 | int ret = 0; |
@@ -444,6 +494,8 @@ int btrfs_start_workers(struct btrfs_workers *workers, int num_workers) | |||
444 | list_add_tail(&worker->worker_list, &workers->idle_list); | 494 | list_add_tail(&worker->worker_list, &workers->idle_list); |
445 | worker->idle = 1; | 495 | worker->idle = 1; |
446 | workers->num_workers++; | 496 | workers->num_workers++; |
497 | workers->num_workers_starting--; | ||
498 | WARN_ON(workers->num_workers_starting < 0); | ||
447 | spin_unlock_irq(&workers->lock); | 499 | spin_unlock_irq(&workers->lock); |
448 | } | 500 | } |
449 | return 0; | 501 | return 0; |
@@ -452,6 +504,14 @@ fail: | |||
452 | return ret; | 504 | return ret; |
453 | } | 505 | } |
454 | 506 | ||
507 | int btrfs_start_workers(struct btrfs_workers *workers, int num_workers) | ||
508 | { | ||
509 | spin_lock_irq(&workers->lock); | ||
510 | workers->num_workers_starting += num_workers; | ||
511 | spin_unlock_irq(&workers->lock); | ||
512 | return __btrfs_start_workers(workers, num_workers); | ||
513 | } | ||
514 | |||
455 | /* | 515 | /* |
456 | * run through the list and find a worker thread that doesn't have a lot | 516 | * run through the list and find a worker thread that doesn't have a lot |
457 | * to do right now. This can return null if we aren't yet at the thread | 517 | * to do right now. This can return null if we aren't yet at the thread |
@@ -461,7 +521,10 @@ static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers) | |||
461 | { | 521 | { |
462 | struct btrfs_worker_thread *worker; | 522 | struct btrfs_worker_thread *worker; |
463 | struct list_head *next; | 523 | struct list_head *next; |
464 | int enforce_min = workers->num_workers < workers->max_workers; | 524 | int enforce_min; |
525 | |||
526 | enforce_min = (workers->num_workers + workers->num_workers_starting) < | ||
527 | workers->max_workers; | ||
465 | 528 | ||
466 | /* | 529 | /* |
467 | * if we find an idle thread, don't move it to the end of the | 530 | * if we find an idle thread, don't move it to the end of the |
@@ -509,15 +572,17 @@ again: | |||
509 | worker = next_worker(workers); | 572 | worker = next_worker(workers); |
510 | 573 | ||
511 | if (!worker) { | 574 | if (!worker) { |
512 | if (workers->num_workers >= workers->max_workers) { | 575 | if (workers->num_workers + workers->num_workers_starting >= |
576 | workers->max_workers) { | ||
513 | goto fallback; | 577 | goto fallback; |
514 | } else if (workers->atomic_worker_start) { | 578 | } else if (workers->atomic_worker_start) { |
515 | workers->atomic_start_pending = 1; | 579 | workers->atomic_start_pending = 1; |
516 | goto fallback; | 580 | goto fallback; |
517 | } else { | 581 | } else { |
582 | workers->num_workers_starting++; | ||
518 | spin_unlock_irqrestore(&workers->lock, flags); | 583 | spin_unlock_irqrestore(&workers->lock, flags); |
519 | /* we're below the limit, start another worker */ | 584 | /* we're below the limit, start another worker */ |
520 | btrfs_start_workers(workers, 1); | 585 | __btrfs_start_workers(workers, 1); |
521 | goto again; | 586 | goto again; |
522 | } | 587 | } |
523 | } | 588 | } |
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h index fc089b95ec14..5077746cf85e 100644 --- a/fs/btrfs/async-thread.h +++ b/fs/btrfs/async-thread.h | |||
@@ -64,6 +64,8 @@ struct btrfs_workers { | |||
64 | /* current number of running workers */ | 64 | /* current number of running workers */ |
65 | int num_workers; | 65 | int num_workers; |
66 | 66 | ||
67 | int num_workers_starting; | ||
68 | |||
67 | /* max number of workers allowed. changed by btrfs_start_workers */ | 69 | /* max number of workers allowed. changed by btrfs_start_workers */ |
68 | int max_workers; | 70 | int max_workers; |
69 | 71 | ||
@@ -78,9 +80,10 @@ struct btrfs_workers { | |||
78 | 80 | ||
79 | /* | 81 | /* |
80 | * are we allowed to sleep while starting workers or are we required | 82 | * are we allowed to sleep while starting workers or are we required |
81 | * to start them at a later time? | 83 | * to start them at a later time? If we can't sleep, this indicates |
84 | * which queue we need to use to schedule thread creation. | ||
82 | */ | 85 | */ |
83 | int atomic_worker_start; | 86 | struct btrfs_workers *atomic_worker_start; |
84 | 87 | ||
85 | /* list with all the work threads. The workers on the idle thread | 88 | /* list with all the work threads. The workers on the idle thread |
86 | * may be actively servicing jobs, but they haven't yet hit the | 89 | * may be actively servicing jobs, but they haven't yet hit the |
@@ -109,7 +112,8 @@ struct btrfs_workers { | |||
109 | int btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work); | 112 | int btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work); |
110 | int btrfs_start_workers(struct btrfs_workers *workers, int num_workers); | 113 | int btrfs_start_workers(struct btrfs_workers *workers, int num_workers); |
111 | int btrfs_stop_workers(struct btrfs_workers *workers); | 114 | int btrfs_stop_workers(struct btrfs_workers *workers); |
112 | void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max); | 115 | void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max, |
116 | struct btrfs_workers *async_starter); | ||
113 | int btrfs_requeue_work(struct btrfs_work *work); | 117 | int btrfs_requeue_work(struct btrfs_work *work); |
114 | void btrfs_set_work_high_prio(struct btrfs_work *work); | 118 | void btrfs_set_work_high_prio(struct btrfs_work *work); |
115 | #endif | 119 | #endif |
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index a54d354cefcb..f6783a42f010 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h | |||
@@ -86,6 +86,12 @@ struct btrfs_inode { | |||
86 | * transid of the trans_handle that last modified this inode | 86 | * transid of the trans_handle that last modified this inode |
87 | */ | 87 | */ |
88 | u64 last_trans; | 88 | u64 last_trans; |
89 | |||
90 | /* | ||
91 | * log transid when this inode was last modified | ||
92 | */ | ||
93 | u64 last_sub_trans; | ||
94 | |||
89 | /* | 95 | /* |
90 | * transid that last logged this inode | 96 | * transid that last logged this inode |
91 | */ | 97 | */ |
@@ -128,12 +134,14 @@ struct btrfs_inode { | |||
128 | u64 last_unlink_trans; | 134 | u64 last_unlink_trans; |
129 | 135 | ||
130 | /* | 136 | /* |
131 | * These two counters are for delalloc metadata reservations. We keep | 137 | * Counters to keep track of the number of extent item's we may use due |
132 | * track of how many extents we've accounted for vs how many extents we | 138 | * to delalloc and such. outstanding_extents is the number of extent |
133 | * have. | 139 | * items we think we'll end up using, and reserved_extents is the number |
140 | * of extent items we've reserved metadata for. | ||
134 | */ | 141 | */ |
135 | int delalloc_reserved_extents; | 142 | spinlock_t accounting_lock; |
136 | int delalloc_extents; | 143 | int reserved_extents; |
144 | int outstanding_extents; | ||
137 | 145 | ||
138 | /* | 146 | /* |
139 | * ordered_data_close is set by truncate when a file that used | 147 | * ordered_data_close is set by truncate when a file that used |
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index dd8ced9814c4..444b3e9b92a4 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -691,14 +691,17 @@ struct btrfs_space_info { | |||
691 | 691 | ||
692 | struct list_head list; | 692 | struct list_head list; |
693 | 693 | ||
694 | /* for controlling how we free up space for allocations */ | ||
695 | wait_queue_head_t allocate_wait; | ||
696 | wait_queue_head_t flush_wait; | ||
697 | int allocating_chunk; | ||
698 | int flushing; | ||
699 | |||
694 | /* for block groups in our same type */ | 700 | /* for block groups in our same type */ |
695 | struct list_head block_groups; | 701 | struct list_head block_groups; |
696 | spinlock_t lock; | 702 | spinlock_t lock; |
697 | struct rw_semaphore groups_sem; | 703 | struct rw_semaphore groups_sem; |
698 | atomic_t caching_threads; | 704 | atomic_t caching_threads; |
699 | |||
700 | int allocating_chunk; | ||
701 | wait_queue_head_t wait; | ||
702 | }; | 705 | }; |
703 | 706 | ||
704 | /* | 707 | /* |
@@ -907,6 +910,7 @@ struct btrfs_fs_info { | |||
907 | * A third pool does submit_bio to avoid deadlocking with the other | 910 | * A third pool does submit_bio to avoid deadlocking with the other |
908 | * two | 911 | * two |
909 | */ | 912 | */ |
913 | struct btrfs_workers generic_worker; | ||
910 | struct btrfs_workers workers; | 914 | struct btrfs_workers workers; |
911 | struct btrfs_workers delalloc_workers; | 915 | struct btrfs_workers delalloc_workers; |
912 | struct btrfs_workers endio_workers; | 916 | struct btrfs_workers endio_workers; |
@@ -914,6 +918,7 @@ struct btrfs_fs_info { | |||
914 | struct btrfs_workers endio_meta_write_workers; | 918 | struct btrfs_workers endio_meta_write_workers; |
915 | struct btrfs_workers endio_write_workers; | 919 | struct btrfs_workers endio_write_workers; |
916 | struct btrfs_workers submit_workers; | 920 | struct btrfs_workers submit_workers; |
921 | struct btrfs_workers enospc_workers; | ||
917 | /* | 922 | /* |
918 | * fixup workers take dirty pages that didn't properly go through | 923 | * fixup workers take dirty pages that didn't properly go through |
919 | * the cow mechanism and make them safe to write. It happens | 924 | * the cow mechanism and make them safe to write. It happens |
@@ -1004,7 +1009,10 @@ struct btrfs_root { | |||
1004 | atomic_t log_writers; | 1009 | atomic_t log_writers; |
1005 | atomic_t log_commit[2]; | 1010 | atomic_t log_commit[2]; |
1006 | unsigned long log_transid; | 1011 | unsigned long log_transid; |
1012 | unsigned long last_log_commit; | ||
1007 | unsigned long log_batch; | 1013 | unsigned long log_batch; |
1014 | pid_t log_start_pid; | ||
1015 | bool log_multiple_pids; | ||
1008 | 1016 | ||
1009 | u64 objectid; | 1017 | u64 objectid; |
1010 | u64 last_trans; | 1018 | u64 last_trans; |
@@ -1145,6 +1153,7 @@ struct btrfs_root { | |||
1145 | #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7) | 1153 | #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7) |
1146 | #define BTRFS_MOUNT_SSD_SPREAD (1 << 8) | 1154 | #define BTRFS_MOUNT_SSD_SPREAD (1 << 8) |
1147 | #define BTRFS_MOUNT_NOSSD (1 << 9) | 1155 | #define BTRFS_MOUNT_NOSSD (1 << 9) |
1156 | #define BTRFS_MOUNT_DISCARD (1 << 10) | ||
1148 | 1157 | ||
1149 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) | 1158 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) |
1150 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) | 1159 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) |
@@ -2323,7 +2332,7 @@ int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode); | |||
2323 | void btrfs_orphan_cleanup(struct btrfs_root *root); | 2332 | void btrfs_orphan_cleanup(struct btrfs_root *root); |
2324 | int btrfs_cont_expand(struct inode *inode, loff_t size); | 2333 | int btrfs_cont_expand(struct inode *inode, loff_t size); |
2325 | int btrfs_invalidate_inodes(struct btrfs_root *root); | 2334 | int btrfs_invalidate_inodes(struct btrfs_root *root); |
2326 | extern struct dentry_operations btrfs_dentry_operations; | 2335 | extern const struct dentry_operations btrfs_dentry_operations; |
2327 | 2336 | ||
2328 | /* ioctl.c */ | 2337 | /* ioctl.c */ |
2329 | long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | 2338 | long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
@@ -2366,7 +2375,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options); | |||
2366 | int btrfs_sync_fs(struct super_block *sb, int wait); | 2375 | int btrfs_sync_fs(struct super_block *sb, int wait); |
2367 | 2376 | ||
2368 | /* acl.c */ | 2377 | /* acl.c */ |
2369 | #ifdef CONFIG_BTRFS_POSIX_ACL | 2378 | #ifdef CONFIG_BTRFS_FS_POSIX_ACL |
2370 | int btrfs_check_acl(struct inode *inode, int mask); | 2379 | int btrfs_check_acl(struct inode *inode, int mask); |
2371 | #else | 2380 | #else |
2372 | #define btrfs_check_acl NULL | 2381 | #define btrfs_check_acl NULL |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index af0435f79fa6..02b6afbd7450 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -917,6 +917,7 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
917 | atomic_set(&root->log_writers, 0); | 917 | atomic_set(&root->log_writers, 0); |
918 | root->log_batch = 0; | 918 | root->log_batch = 0; |
919 | root->log_transid = 0; | 919 | root->log_transid = 0; |
920 | root->last_log_commit = 0; | ||
920 | extent_io_tree_init(&root->dirty_log_pages, | 921 | extent_io_tree_init(&root->dirty_log_pages, |
921 | fs_info->btree_inode->i_mapping, GFP_NOFS); | 922 | fs_info->btree_inode->i_mapping, GFP_NOFS); |
922 | 923 | ||
@@ -1087,6 +1088,7 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans, | |||
1087 | WARN_ON(root->log_root); | 1088 | WARN_ON(root->log_root); |
1088 | root->log_root = log_root; | 1089 | root->log_root = log_root; |
1089 | root->log_transid = 0; | 1090 | root->log_transid = 0; |
1091 | root->last_log_commit = 0; | ||
1090 | return 0; | 1092 | return 0; |
1091 | } | 1093 | } |
1092 | 1094 | ||
@@ -1746,21 +1748,25 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1746 | err = -EINVAL; | 1748 | err = -EINVAL; |
1747 | goto fail_iput; | 1749 | goto fail_iput; |
1748 | } | 1750 | } |
1749 | printk("thread pool is %d\n", fs_info->thread_pool_size); | 1751 | |
1750 | /* | 1752 | btrfs_init_workers(&fs_info->generic_worker, |
1751 | * we need to start all the end_io workers up front because the | 1753 | "genwork", 1, NULL); |
1752 | * queue work function gets called at interrupt time, and so it | 1754 | |
1753 | * cannot dynamically grow. | ||
1754 | */ | ||
1755 | btrfs_init_workers(&fs_info->workers, "worker", | 1755 | btrfs_init_workers(&fs_info->workers, "worker", |
1756 | fs_info->thread_pool_size); | 1756 | fs_info->thread_pool_size, |
1757 | &fs_info->generic_worker); | ||
1757 | 1758 | ||
1758 | btrfs_init_workers(&fs_info->delalloc_workers, "delalloc", | 1759 | btrfs_init_workers(&fs_info->delalloc_workers, "delalloc", |
1759 | fs_info->thread_pool_size); | 1760 | fs_info->thread_pool_size, |
1761 | &fs_info->generic_worker); | ||
1760 | 1762 | ||
1761 | btrfs_init_workers(&fs_info->submit_workers, "submit", | 1763 | btrfs_init_workers(&fs_info->submit_workers, "submit", |
1762 | min_t(u64, fs_devices->num_devices, | 1764 | min_t(u64, fs_devices->num_devices, |
1763 | fs_info->thread_pool_size)); | 1765 | fs_info->thread_pool_size), |
1766 | &fs_info->generic_worker); | ||
1767 | btrfs_init_workers(&fs_info->enospc_workers, "enospc", | ||
1768 | fs_info->thread_pool_size, | ||
1769 | &fs_info->generic_worker); | ||
1764 | 1770 | ||
1765 | /* a higher idle thresh on the submit workers makes it much more | 1771 | /* a higher idle thresh on the submit workers makes it much more |
1766 | * likely that bios will be send down in a sane order to the | 1772 | * likely that bios will be send down in a sane order to the |
@@ -1774,15 +1780,20 @@ printk("thread pool is %d\n", fs_info->thread_pool_size); | |||
1774 | fs_info->delalloc_workers.idle_thresh = 2; | 1780 | fs_info->delalloc_workers.idle_thresh = 2; |
1775 | fs_info->delalloc_workers.ordered = 1; | 1781 | fs_info->delalloc_workers.ordered = 1; |
1776 | 1782 | ||
1777 | btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1); | 1783 | btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1, |
1784 | &fs_info->generic_worker); | ||
1778 | btrfs_init_workers(&fs_info->endio_workers, "endio", | 1785 | btrfs_init_workers(&fs_info->endio_workers, "endio", |
1779 | fs_info->thread_pool_size); | 1786 | fs_info->thread_pool_size, |
1787 | &fs_info->generic_worker); | ||
1780 | btrfs_init_workers(&fs_info->endio_meta_workers, "endio-meta", | 1788 | btrfs_init_workers(&fs_info->endio_meta_workers, "endio-meta", |
1781 | fs_info->thread_pool_size); | 1789 | fs_info->thread_pool_size, |
1790 | &fs_info->generic_worker); | ||
1782 | btrfs_init_workers(&fs_info->endio_meta_write_workers, | 1791 | btrfs_init_workers(&fs_info->endio_meta_write_workers, |
1783 | "endio-meta-write", fs_info->thread_pool_size); | 1792 | "endio-meta-write", fs_info->thread_pool_size, |
1793 | &fs_info->generic_worker); | ||
1784 | btrfs_init_workers(&fs_info->endio_write_workers, "endio-write", | 1794 | btrfs_init_workers(&fs_info->endio_write_workers, "endio-write", |
1785 | fs_info->thread_pool_size); | 1795 | fs_info->thread_pool_size, |
1796 | &fs_info->generic_worker); | ||
1786 | 1797 | ||
1787 | /* | 1798 | /* |
1788 | * endios are largely parallel and should have a very | 1799 | * endios are largely parallel and should have a very |
@@ -1794,12 +1805,8 @@ printk("thread pool is %d\n", fs_info->thread_pool_size); | |||
1794 | fs_info->endio_write_workers.idle_thresh = 2; | 1805 | fs_info->endio_write_workers.idle_thresh = 2; |
1795 | fs_info->endio_meta_write_workers.idle_thresh = 2; | 1806 | fs_info->endio_meta_write_workers.idle_thresh = 2; |
1796 | 1807 | ||
1797 | fs_info->endio_workers.atomic_worker_start = 1; | ||
1798 | fs_info->endio_meta_workers.atomic_worker_start = 1; | ||
1799 | fs_info->endio_write_workers.atomic_worker_start = 1; | ||
1800 | fs_info->endio_meta_write_workers.atomic_worker_start = 1; | ||
1801 | |||
1802 | btrfs_start_workers(&fs_info->workers, 1); | 1808 | btrfs_start_workers(&fs_info->workers, 1); |
1809 | btrfs_start_workers(&fs_info->generic_worker, 1); | ||
1803 | btrfs_start_workers(&fs_info->submit_workers, 1); | 1810 | btrfs_start_workers(&fs_info->submit_workers, 1); |
1804 | btrfs_start_workers(&fs_info->delalloc_workers, 1); | 1811 | btrfs_start_workers(&fs_info->delalloc_workers, 1); |
1805 | btrfs_start_workers(&fs_info->fixup_workers, 1); | 1812 | btrfs_start_workers(&fs_info->fixup_workers, 1); |
@@ -1807,6 +1814,7 @@ printk("thread pool is %d\n", fs_info->thread_pool_size); | |||
1807 | btrfs_start_workers(&fs_info->endio_meta_workers, 1); | 1814 | btrfs_start_workers(&fs_info->endio_meta_workers, 1); |
1808 | btrfs_start_workers(&fs_info->endio_meta_write_workers, 1); | 1815 | btrfs_start_workers(&fs_info->endio_meta_write_workers, 1); |
1809 | btrfs_start_workers(&fs_info->endio_write_workers, 1); | 1816 | btrfs_start_workers(&fs_info->endio_write_workers, 1); |
1817 | btrfs_start_workers(&fs_info->enospc_workers, 1); | ||
1810 | 1818 | ||
1811 | fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super); | 1819 | fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super); |
1812 | fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages, | 1820 | fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages, |
@@ -2012,6 +2020,7 @@ fail_chunk_root: | |||
2012 | free_extent_buffer(chunk_root->node); | 2020 | free_extent_buffer(chunk_root->node); |
2013 | free_extent_buffer(chunk_root->commit_root); | 2021 | free_extent_buffer(chunk_root->commit_root); |
2014 | fail_sb_buffer: | 2022 | fail_sb_buffer: |
2023 | btrfs_stop_workers(&fs_info->generic_worker); | ||
2015 | btrfs_stop_workers(&fs_info->fixup_workers); | 2024 | btrfs_stop_workers(&fs_info->fixup_workers); |
2016 | btrfs_stop_workers(&fs_info->delalloc_workers); | 2025 | btrfs_stop_workers(&fs_info->delalloc_workers); |
2017 | btrfs_stop_workers(&fs_info->workers); | 2026 | btrfs_stop_workers(&fs_info->workers); |
@@ -2020,6 +2029,7 @@ fail_sb_buffer: | |||
2020 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); | 2029 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); |
2021 | btrfs_stop_workers(&fs_info->endio_write_workers); | 2030 | btrfs_stop_workers(&fs_info->endio_write_workers); |
2022 | btrfs_stop_workers(&fs_info->submit_workers); | 2031 | btrfs_stop_workers(&fs_info->submit_workers); |
2032 | btrfs_stop_workers(&fs_info->enospc_workers); | ||
2023 | fail_iput: | 2033 | fail_iput: |
2024 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); | 2034 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); |
2025 | iput(fs_info->btree_inode); | 2035 | iput(fs_info->btree_inode); |
@@ -2437,6 +2447,7 @@ int close_ctree(struct btrfs_root *root) | |||
2437 | 2447 | ||
2438 | iput(fs_info->btree_inode); | 2448 | iput(fs_info->btree_inode); |
2439 | 2449 | ||
2450 | btrfs_stop_workers(&fs_info->generic_worker); | ||
2440 | btrfs_stop_workers(&fs_info->fixup_workers); | 2451 | btrfs_stop_workers(&fs_info->fixup_workers); |
2441 | btrfs_stop_workers(&fs_info->delalloc_workers); | 2452 | btrfs_stop_workers(&fs_info->delalloc_workers); |
2442 | btrfs_stop_workers(&fs_info->workers); | 2453 | btrfs_stop_workers(&fs_info->workers); |
@@ -2445,6 +2456,7 @@ int close_ctree(struct btrfs_root *root) | |||
2445 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); | 2456 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); |
2446 | btrfs_stop_workers(&fs_info->endio_write_workers); | 2457 | btrfs_stop_workers(&fs_info->endio_write_workers); |
2447 | btrfs_stop_workers(&fs_info->submit_workers); | 2458 | btrfs_stop_workers(&fs_info->submit_workers); |
2459 | btrfs_stop_workers(&fs_info->enospc_workers); | ||
2448 | 2460 | ||
2449 | btrfs_close_devices(fs_info->fs_devices); | 2461 | btrfs_close_devices(fs_info->fs_devices); |
2450 | btrfs_mapping_tree_free(&fs_info->mapping_tree); | 2462 | btrfs_mapping_tree_free(&fs_info->mapping_tree); |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 359a754c782c..94627c4cc193 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -1568,23 +1568,23 @@ static int remove_extent_backref(struct btrfs_trans_handle *trans, | |||
1568 | return ret; | 1568 | return ret; |
1569 | } | 1569 | } |
1570 | 1570 | ||
1571 | #ifdef BIO_RW_DISCARD | ||
1572 | static void btrfs_issue_discard(struct block_device *bdev, | 1571 | static void btrfs_issue_discard(struct block_device *bdev, |
1573 | u64 start, u64 len) | 1572 | u64 start, u64 len) |
1574 | { | 1573 | { |
1575 | blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL, | 1574 | blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL, |
1576 | DISCARD_FL_BARRIER); | 1575 | DISCARD_FL_BARRIER); |
1577 | } | 1576 | } |
1578 | #endif | ||
1579 | 1577 | ||
1580 | static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, | 1578 | static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, |
1581 | u64 num_bytes) | 1579 | u64 num_bytes) |
1582 | { | 1580 | { |
1583 | #ifdef BIO_RW_DISCARD | ||
1584 | int ret; | 1581 | int ret; |
1585 | u64 map_length = num_bytes; | 1582 | u64 map_length = num_bytes; |
1586 | struct btrfs_multi_bio *multi = NULL; | 1583 | struct btrfs_multi_bio *multi = NULL; |
1587 | 1584 | ||
1585 | if (!btrfs_test_opt(root, DISCARD)) | ||
1586 | return 0; | ||
1587 | |||
1588 | /* Tell the block device(s) that the sectors can be discarded */ | 1588 | /* Tell the block device(s) that the sectors can be discarded */ |
1589 | ret = btrfs_map_block(&root->fs_info->mapping_tree, READ, | 1589 | ret = btrfs_map_block(&root->fs_info->mapping_tree, READ, |
1590 | bytenr, &map_length, &multi, 0); | 1590 | bytenr, &map_length, &multi, 0); |
@@ -1604,9 +1604,6 @@ static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, | |||
1604 | } | 1604 | } |
1605 | 1605 | ||
1606 | return ret; | 1606 | return ret; |
1607 | #else | ||
1608 | return 0; | ||
1609 | #endif | ||
1610 | } | 1607 | } |
1611 | 1608 | ||
1612 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, | 1609 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, |
@@ -2824,14 +2821,17 @@ int btrfs_unreserve_metadata_for_delalloc(struct btrfs_root *root, | |||
2824 | num_items); | 2821 | num_items); |
2825 | 2822 | ||
2826 | spin_lock(&meta_sinfo->lock); | 2823 | spin_lock(&meta_sinfo->lock); |
2827 | if (BTRFS_I(inode)->delalloc_reserved_extents <= | 2824 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
2828 | BTRFS_I(inode)->delalloc_extents) { | 2825 | if (BTRFS_I(inode)->reserved_extents <= |
2826 | BTRFS_I(inode)->outstanding_extents) { | ||
2827 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
2829 | spin_unlock(&meta_sinfo->lock); | 2828 | spin_unlock(&meta_sinfo->lock); |
2830 | return 0; | 2829 | return 0; |
2831 | } | 2830 | } |
2831 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
2832 | 2832 | ||
2833 | BTRFS_I(inode)->delalloc_reserved_extents--; | 2833 | BTRFS_I(inode)->reserved_extents--; |
2834 | BUG_ON(BTRFS_I(inode)->delalloc_reserved_extents < 0); | 2834 | BUG_ON(BTRFS_I(inode)->reserved_extents < 0); |
2835 | 2835 | ||
2836 | if (meta_sinfo->bytes_delalloc < num_bytes) { | 2836 | if (meta_sinfo->bytes_delalloc < num_bytes) { |
2837 | bug = true; | 2837 | bug = true; |
@@ -2864,6 +2864,107 @@ static void check_force_delalloc(struct btrfs_space_info *meta_sinfo) | |||
2864 | meta_sinfo->force_delalloc = 0; | 2864 | meta_sinfo->force_delalloc = 0; |
2865 | } | 2865 | } |
2866 | 2866 | ||
2867 | struct async_flush { | ||
2868 | struct btrfs_root *root; | ||
2869 | struct btrfs_space_info *info; | ||
2870 | struct btrfs_work work; | ||
2871 | }; | ||
2872 | |||
2873 | static noinline void flush_delalloc_async(struct btrfs_work *work) | ||
2874 | { | ||
2875 | struct async_flush *async; | ||
2876 | struct btrfs_root *root; | ||
2877 | struct btrfs_space_info *info; | ||
2878 | |||
2879 | async = container_of(work, struct async_flush, work); | ||
2880 | root = async->root; | ||
2881 | info = async->info; | ||
2882 | |||
2883 | btrfs_start_delalloc_inodes(root); | ||
2884 | wake_up(&info->flush_wait); | ||
2885 | btrfs_wait_ordered_extents(root, 0); | ||
2886 | |||
2887 | spin_lock(&info->lock); | ||
2888 | info->flushing = 0; | ||
2889 | spin_unlock(&info->lock); | ||
2890 | wake_up(&info->flush_wait); | ||
2891 | |||
2892 | kfree(async); | ||
2893 | } | ||
2894 | |||
2895 | static void wait_on_flush(struct btrfs_space_info *info) | ||
2896 | { | ||
2897 | DEFINE_WAIT(wait); | ||
2898 | u64 used; | ||
2899 | |||
2900 | while (1) { | ||
2901 | prepare_to_wait(&info->flush_wait, &wait, | ||
2902 | TASK_UNINTERRUPTIBLE); | ||
2903 | spin_lock(&info->lock); | ||
2904 | if (!info->flushing) { | ||
2905 | spin_unlock(&info->lock); | ||
2906 | break; | ||
2907 | } | ||
2908 | |||
2909 | used = info->bytes_used + info->bytes_reserved + | ||
2910 | info->bytes_pinned + info->bytes_readonly + | ||
2911 | info->bytes_super + info->bytes_root + | ||
2912 | info->bytes_may_use + info->bytes_delalloc; | ||
2913 | if (used < info->total_bytes) { | ||
2914 | spin_unlock(&info->lock); | ||
2915 | break; | ||
2916 | } | ||
2917 | spin_unlock(&info->lock); | ||
2918 | schedule(); | ||
2919 | } | ||
2920 | finish_wait(&info->flush_wait, &wait); | ||
2921 | } | ||
2922 | |||
2923 | static void flush_delalloc(struct btrfs_root *root, | ||
2924 | struct btrfs_space_info *info) | ||
2925 | { | ||
2926 | struct async_flush *async; | ||
2927 | bool wait = false; | ||
2928 | |||
2929 | spin_lock(&info->lock); | ||
2930 | |||
2931 | if (!info->flushing) { | ||
2932 | info->flushing = 1; | ||
2933 | init_waitqueue_head(&info->flush_wait); | ||
2934 | } else { | ||
2935 | wait = true; | ||
2936 | } | ||
2937 | |||
2938 | spin_unlock(&info->lock); | ||
2939 | |||
2940 | if (wait) { | ||
2941 | wait_on_flush(info); | ||
2942 | return; | ||
2943 | } | ||
2944 | |||
2945 | async = kzalloc(sizeof(*async), GFP_NOFS); | ||
2946 | if (!async) | ||
2947 | goto flush; | ||
2948 | |||
2949 | async->root = root; | ||
2950 | async->info = info; | ||
2951 | async->work.func = flush_delalloc_async; | ||
2952 | |||
2953 | btrfs_queue_worker(&root->fs_info->enospc_workers, | ||
2954 | &async->work); | ||
2955 | wait_on_flush(info); | ||
2956 | return; | ||
2957 | |||
2958 | flush: | ||
2959 | btrfs_start_delalloc_inodes(root); | ||
2960 | btrfs_wait_ordered_extents(root, 0); | ||
2961 | |||
2962 | spin_lock(&info->lock); | ||
2963 | info->flushing = 0; | ||
2964 | spin_unlock(&info->lock); | ||
2965 | wake_up(&info->flush_wait); | ||
2966 | } | ||
2967 | |||
2867 | static int maybe_allocate_chunk(struct btrfs_root *root, | 2968 | static int maybe_allocate_chunk(struct btrfs_root *root, |
2868 | struct btrfs_space_info *info) | 2969 | struct btrfs_space_info *info) |
2869 | { | 2970 | { |
@@ -2876,10 +2977,10 @@ static int maybe_allocate_chunk(struct btrfs_root *root, | |||
2876 | 2977 | ||
2877 | free_space = btrfs_super_total_bytes(disk_super); | 2978 | free_space = btrfs_super_total_bytes(disk_super); |
2878 | /* | 2979 | /* |
2879 | * we allow the metadata to grow to a max of either 5gb or 5% of the | 2980 | * we allow the metadata to grow to a max of either 10gb or 5% of the |
2880 | * space in the volume. | 2981 | * space in the volume. |
2881 | */ | 2982 | */ |
2882 | min_metadata = min((u64)5 * 1024 * 1024 * 1024, | 2983 | min_metadata = min((u64)10 * 1024 * 1024 * 1024, |
2883 | div64_u64(free_space * 5, 100)); | 2984 | div64_u64(free_space * 5, 100)); |
2884 | if (info->total_bytes >= min_metadata) { | 2985 | if (info->total_bytes >= min_metadata) { |
2885 | spin_unlock(&info->lock); | 2986 | spin_unlock(&info->lock); |
@@ -2894,7 +2995,7 @@ static int maybe_allocate_chunk(struct btrfs_root *root, | |||
2894 | if (!info->allocating_chunk) { | 2995 | if (!info->allocating_chunk) { |
2895 | info->force_alloc = 1; | 2996 | info->force_alloc = 1; |
2896 | info->allocating_chunk = 1; | 2997 | info->allocating_chunk = 1; |
2897 | init_waitqueue_head(&info->wait); | 2998 | init_waitqueue_head(&info->allocate_wait); |
2898 | } else { | 2999 | } else { |
2899 | wait = true; | 3000 | wait = true; |
2900 | } | 3001 | } |
@@ -2902,7 +3003,7 @@ static int maybe_allocate_chunk(struct btrfs_root *root, | |||
2902 | spin_unlock(&info->lock); | 3003 | spin_unlock(&info->lock); |
2903 | 3004 | ||
2904 | if (wait) { | 3005 | if (wait) { |
2905 | wait_event(info->wait, | 3006 | wait_event(info->allocate_wait, |
2906 | !info->allocating_chunk); | 3007 | !info->allocating_chunk); |
2907 | return 1; | 3008 | return 1; |
2908 | } | 3009 | } |
@@ -2923,7 +3024,7 @@ out: | |||
2923 | spin_lock(&info->lock); | 3024 | spin_lock(&info->lock); |
2924 | info->allocating_chunk = 0; | 3025 | info->allocating_chunk = 0; |
2925 | spin_unlock(&info->lock); | 3026 | spin_unlock(&info->lock); |
2926 | wake_up(&info->wait); | 3027 | wake_up(&info->allocate_wait); |
2927 | 3028 | ||
2928 | if (ret) | 3029 | if (ret) |
2929 | return 0; | 3030 | return 0; |
@@ -2981,21 +3082,20 @@ again: | |||
2981 | filemap_flush(inode->i_mapping); | 3082 | filemap_flush(inode->i_mapping); |
2982 | goto again; | 3083 | goto again; |
2983 | } else if (flushed == 3) { | 3084 | } else if (flushed == 3) { |
2984 | btrfs_start_delalloc_inodes(root); | 3085 | flush_delalloc(root, meta_sinfo); |
2985 | btrfs_wait_ordered_extents(root, 0); | ||
2986 | goto again; | 3086 | goto again; |
2987 | } | 3087 | } |
2988 | spin_lock(&meta_sinfo->lock); | 3088 | spin_lock(&meta_sinfo->lock); |
2989 | meta_sinfo->bytes_delalloc -= num_bytes; | 3089 | meta_sinfo->bytes_delalloc -= num_bytes; |
2990 | spin_unlock(&meta_sinfo->lock); | 3090 | spin_unlock(&meta_sinfo->lock); |
2991 | printk(KERN_ERR "enospc, has %d, reserved %d\n", | 3091 | printk(KERN_ERR "enospc, has %d, reserved %d\n", |
2992 | BTRFS_I(inode)->delalloc_extents, | 3092 | BTRFS_I(inode)->outstanding_extents, |
2993 | BTRFS_I(inode)->delalloc_reserved_extents); | 3093 | BTRFS_I(inode)->reserved_extents); |
2994 | dump_space_info(meta_sinfo, 0, 0); | 3094 | dump_space_info(meta_sinfo, 0, 0); |
2995 | return -ENOSPC; | 3095 | return -ENOSPC; |
2996 | } | 3096 | } |
2997 | 3097 | ||
2998 | BTRFS_I(inode)->delalloc_reserved_extents++; | 3098 | BTRFS_I(inode)->reserved_extents++; |
2999 | check_force_delalloc(meta_sinfo); | 3099 | check_force_delalloc(meta_sinfo); |
3000 | spin_unlock(&meta_sinfo->lock); | 3100 | spin_unlock(&meta_sinfo->lock); |
3001 | 3101 | ||
@@ -3094,8 +3194,7 @@ again: | |||
3094 | } | 3194 | } |
3095 | 3195 | ||
3096 | if (retries == 2) { | 3196 | if (retries == 2) { |
3097 | btrfs_start_delalloc_inodes(root); | 3197 | flush_delalloc(root, meta_sinfo); |
3098 | btrfs_wait_ordered_extents(root, 0); | ||
3099 | goto again; | 3198 | goto again; |
3100 | } | 3199 | } |
3101 | spin_lock(&meta_sinfo->lock); | 3200 | spin_lock(&meta_sinfo->lock); |
@@ -3588,6 +3687,14 @@ static int pin_down_bytes(struct btrfs_trans_handle *trans, | |||
3588 | if (is_data) | 3687 | if (is_data) |
3589 | goto pinit; | 3688 | goto pinit; |
3590 | 3689 | ||
3690 | /* | ||
3691 | * discard is sloooow, and so triggering discards on | ||
3692 | * individual btree blocks isn't a good plan. Just | ||
3693 | * pin everything in discard mode. | ||
3694 | */ | ||
3695 | if (btrfs_test_opt(root, DISCARD)) | ||
3696 | goto pinit; | ||
3697 | |||
3591 | buf = btrfs_find_tree_block(root, bytenr, num_bytes); | 3698 | buf = btrfs_find_tree_block(root, bytenr, num_bytes); |
3592 | if (!buf) | 3699 | if (!buf) |
3593 | goto pinit; | 3700 | goto pinit; |
@@ -3995,7 +4102,7 @@ wait_block_group_cache_done(struct btrfs_block_group_cache *cache) | |||
3995 | } | 4102 | } |
3996 | 4103 | ||
3997 | enum btrfs_loop_type { | 4104 | enum btrfs_loop_type { |
3998 | LOOP_CACHED_ONLY = 0, | 4105 | LOOP_FIND_IDEAL = 0, |
3999 | LOOP_CACHING_NOWAIT = 1, | 4106 | LOOP_CACHING_NOWAIT = 1, |
4000 | LOOP_CACHING_WAIT = 2, | 4107 | LOOP_CACHING_WAIT = 2, |
4001 | LOOP_ALLOC_CHUNK = 3, | 4108 | LOOP_ALLOC_CHUNK = 3, |
@@ -4024,11 +4131,15 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, | |||
4024 | struct btrfs_block_group_cache *block_group = NULL; | 4131 | struct btrfs_block_group_cache *block_group = NULL; |
4025 | int empty_cluster = 2 * 1024 * 1024; | 4132 | int empty_cluster = 2 * 1024 * 1024; |
4026 | int allowed_chunk_alloc = 0; | 4133 | int allowed_chunk_alloc = 0; |
4134 | int done_chunk_alloc = 0; | ||
4027 | struct btrfs_space_info *space_info; | 4135 | struct btrfs_space_info *space_info; |
4028 | int last_ptr_loop = 0; | 4136 | int last_ptr_loop = 0; |
4029 | int loop = 0; | 4137 | int loop = 0; |
4030 | bool found_uncached_bg = false; | 4138 | bool found_uncached_bg = false; |
4031 | bool failed_cluster_refill = false; | 4139 | bool failed_cluster_refill = false; |
4140 | bool failed_alloc = false; | ||
4141 | u64 ideal_cache_percent = 0; | ||
4142 | u64 ideal_cache_offset = 0; | ||
4032 | 4143 | ||
4033 | WARN_ON(num_bytes < root->sectorsize); | 4144 | WARN_ON(num_bytes < root->sectorsize); |
4034 | btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY); | 4145 | btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY); |
@@ -4064,14 +4175,19 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, | |||
4064 | empty_cluster = 0; | 4175 | empty_cluster = 0; |
4065 | 4176 | ||
4066 | if (search_start == hint_byte) { | 4177 | if (search_start == hint_byte) { |
4178 | ideal_cache: | ||
4067 | block_group = btrfs_lookup_block_group(root->fs_info, | 4179 | block_group = btrfs_lookup_block_group(root->fs_info, |
4068 | search_start); | 4180 | search_start); |
4069 | /* | 4181 | /* |
4070 | * we don't want to use the block group if it doesn't match our | 4182 | * we don't want to use the block group if it doesn't match our |
4071 | * allocation bits, or if its not cached. | 4183 | * allocation bits, or if its not cached. |
4184 | * | ||
4185 | * However if we are re-searching with an ideal block group | ||
4186 | * picked out then we don't care that the block group is cached. | ||
4072 | */ | 4187 | */ |
4073 | if (block_group && block_group_bits(block_group, data) && | 4188 | if (block_group && block_group_bits(block_group, data) && |
4074 | block_group_cache_done(block_group)) { | 4189 | (block_group->cached != BTRFS_CACHE_NO || |
4190 | search_start == ideal_cache_offset)) { | ||
4075 | down_read(&space_info->groups_sem); | 4191 | down_read(&space_info->groups_sem); |
4076 | if (list_empty(&block_group->list) || | 4192 | if (list_empty(&block_group->list) || |
4077 | block_group->ro) { | 4193 | block_group->ro) { |
@@ -4083,13 +4199,13 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, | |||
4083 | */ | 4199 | */ |
4084 | btrfs_put_block_group(block_group); | 4200 | btrfs_put_block_group(block_group); |
4085 | up_read(&space_info->groups_sem); | 4201 | up_read(&space_info->groups_sem); |
4086 | } else | 4202 | } else { |
4087 | goto have_block_group; | 4203 | goto have_block_group; |
4204 | } | ||
4088 | } else if (block_group) { | 4205 | } else if (block_group) { |
4089 | btrfs_put_block_group(block_group); | 4206 | btrfs_put_block_group(block_group); |
4090 | } | 4207 | } |
4091 | } | 4208 | } |
4092 | |||
4093 | search: | 4209 | search: |
4094 | down_read(&space_info->groups_sem); | 4210 | down_read(&space_info->groups_sem); |
4095 | list_for_each_entry(block_group, &space_info->block_groups, list) { | 4211 | list_for_each_entry(block_group, &space_info->block_groups, list) { |
@@ -4101,28 +4217,45 @@ search: | |||
4101 | 4217 | ||
4102 | have_block_group: | 4218 | have_block_group: |
4103 | if (unlikely(block_group->cached == BTRFS_CACHE_NO)) { | 4219 | if (unlikely(block_group->cached == BTRFS_CACHE_NO)) { |
4220 | u64 free_percent; | ||
4221 | |||
4222 | free_percent = btrfs_block_group_used(&block_group->item); | ||
4223 | free_percent *= 100; | ||
4224 | free_percent = div64_u64(free_percent, | ||
4225 | block_group->key.offset); | ||
4226 | free_percent = 100 - free_percent; | ||
4227 | if (free_percent > ideal_cache_percent && | ||
4228 | likely(!block_group->ro)) { | ||
4229 | ideal_cache_offset = block_group->key.objectid; | ||
4230 | ideal_cache_percent = free_percent; | ||
4231 | } | ||
4232 | |||
4104 | /* | 4233 | /* |
4105 | * we want to start caching kthreads, but not too many | 4234 | * We only want to start kthread caching if we are at |
4106 | * right off the bat so we don't overwhelm the system, | 4235 | * the point where we will wait for caching to make |
4107 | * so only start them if there are less than 2 and we're | 4236 | * progress, or if our ideal search is over and we've |
4108 | * in the initial allocation phase. | 4237 | * found somebody to start caching. |
4109 | */ | 4238 | */ |
4110 | if (loop > LOOP_CACHING_NOWAIT || | 4239 | if (loop > LOOP_CACHING_NOWAIT || |
4111 | atomic_read(&space_info->caching_threads) < 2) { | 4240 | (loop > LOOP_FIND_IDEAL && |
4241 | atomic_read(&space_info->caching_threads) < 2)) { | ||
4112 | ret = cache_block_group(block_group); | 4242 | ret = cache_block_group(block_group); |
4113 | BUG_ON(ret); | 4243 | BUG_ON(ret); |
4114 | } | 4244 | } |
4115 | } | ||
4116 | |||
4117 | cached = block_group_cache_done(block_group); | ||
4118 | if (unlikely(!cached)) { | ||
4119 | found_uncached_bg = true; | 4245 | found_uncached_bg = true; |
4120 | 4246 | ||
4121 | /* if we only want cached bgs, loop */ | 4247 | /* |
4122 | if (loop == LOOP_CACHED_ONLY) | 4248 | * If loop is set for cached only, try the next block |
4249 | * group. | ||
4250 | */ | ||
4251 | if (loop == LOOP_FIND_IDEAL) | ||
4123 | goto loop; | 4252 | goto loop; |
4124 | } | 4253 | } |
4125 | 4254 | ||
4255 | cached = block_group_cache_done(block_group); | ||
4256 | if (unlikely(!cached)) | ||
4257 | found_uncached_bg = true; | ||
4258 | |||
4126 | if (unlikely(block_group->ro)) | 4259 | if (unlikely(block_group->ro)) |
4127 | goto loop; | 4260 | goto loop; |
4128 | 4261 | ||
@@ -4233,14 +4366,23 @@ refill_cluster: | |||
4233 | 4366 | ||
4234 | offset = btrfs_find_space_for_alloc(block_group, search_start, | 4367 | offset = btrfs_find_space_for_alloc(block_group, search_start, |
4235 | num_bytes, empty_size); | 4368 | num_bytes, empty_size); |
4236 | if (!offset && (cached || (!cached && | 4369 | /* |
4237 | loop == LOOP_CACHING_NOWAIT))) { | 4370 | * If we didn't find a chunk, and we haven't failed on this |
4238 | goto loop; | 4371 | * block group before, and this block group is in the middle of |
4239 | } else if (!offset && (!cached && | 4372 | * caching and we are ok with waiting, then go ahead and wait |
4240 | loop > LOOP_CACHING_NOWAIT)) { | 4373 | * for progress to be made, and set failed_alloc to true. |
4374 | * | ||
4375 | * If failed_alloc is true then we've already waited on this | ||
4376 | * block group once and should move on to the next block group. | ||
4377 | */ | ||
4378 | if (!offset && !failed_alloc && !cached && | ||
4379 | loop > LOOP_CACHING_NOWAIT) { | ||
4241 | wait_block_group_cache_progress(block_group, | 4380 | wait_block_group_cache_progress(block_group, |
4242 | num_bytes + empty_size); | 4381 | num_bytes + empty_size); |
4382 | failed_alloc = true; | ||
4243 | goto have_block_group; | 4383 | goto have_block_group; |
4384 | } else if (!offset) { | ||
4385 | goto loop; | ||
4244 | } | 4386 | } |
4245 | checks: | 4387 | checks: |
4246 | search_start = stripe_align(root, offset); | 4388 | search_start = stripe_align(root, offset); |
@@ -4288,13 +4430,16 @@ checks: | |||
4288 | break; | 4430 | break; |
4289 | loop: | 4431 | loop: |
4290 | failed_cluster_refill = false; | 4432 | failed_cluster_refill = false; |
4433 | failed_alloc = false; | ||
4291 | btrfs_put_block_group(block_group); | 4434 | btrfs_put_block_group(block_group); |
4292 | } | 4435 | } |
4293 | up_read(&space_info->groups_sem); | 4436 | up_read(&space_info->groups_sem); |
4294 | 4437 | ||
4295 | /* LOOP_CACHED_ONLY, only search fully cached block groups | 4438 | /* LOOP_FIND_IDEAL, only search caching/cached bg's, and don't wait for |
4296 | * LOOP_CACHING_NOWAIT, search partially cached block groups, but | 4439 | * for them to make caching progress. Also |
4297 | * dont wait foR them to finish caching | 4440 | * determine the best possible bg to cache |
4441 | * LOOP_CACHING_NOWAIT, search partially cached block groups, kicking | ||
4442 | * caching kthreads as we move along | ||
4298 | * LOOP_CACHING_WAIT, search everything, and wait if our bg is caching | 4443 | * LOOP_CACHING_WAIT, search everything, and wait if our bg is caching |
4299 | * LOOP_ALLOC_CHUNK, force a chunk allocation and try again | 4444 | * LOOP_ALLOC_CHUNK, force a chunk allocation and try again |
4300 | * LOOP_NO_EMPTY_SIZE, set empty_size and empty_cluster to 0 and try | 4445 | * LOOP_NO_EMPTY_SIZE, set empty_size and empty_cluster to 0 and try |
@@ -4303,12 +4448,47 @@ loop: | |||
4303 | if (!ins->objectid && loop < LOOP_NO_EMPTY_SIZE && | 4448 | if (!ins->objectid && loop < LOOP_NO_EMPTY_SIZE && |
4304 | (found_uncached_bg || empty_size || empty_cluster || | 4449 | (found_uncached_bg || empty_size || empty_cluster || |
4305 | allowed_chunk_alloc)) { | 4450 | allowed_chunk_alloc)) { |
4306 | if (found_uncached_bg) { | 4451 | if (loop == LOOP_FIND_IDEAL && found_uncached_bg) { |
4307 | found_uncached_bg = false; | 4452 | found_uncached_bg = false; |
4308 | if (loop < LOOP_CACHING_WAIT) { | 4453 | loop++; |
4309 | loop++; | 4454 | if (!ideal_cache_percent && |
4455 | atomic_read(&space_info->caching_threads)) | ||
4310 | goto search; | 4456 | goto search; |
4311 | } | 4457 | |
4458 | /* | ||
4459 | * 1 of the following 2 things have happened so far | ||
4460 | * | ||
4461 | * 1) We found an ideal block group for caching that | ||
4462 | * is mostly full and will cache quickly, so we might | ||
4463 | * as well wait for it. | ||
4464 | * | ||
4465 | * 2) We searched for cached only and we didn't find | ||
4466 | * anything, and we didn't start any caching kthreads | ||
4467 | * either, so chances are we will loop through and | ||
4468 | * start a couple caching kthreads, and then come back | ||
4469 | * around and just wait for them. This will be slower | ||
4470 | * because we will have 2 caching kthreads reading at | ||
4471 | * the same time when we could have just started one | ||
4472 | * and waited for it to get far enough to give us an | ||
4473 | * allocation, so go ahead and go to the wait caching | ||
4474 | * loop. | ||
4475 | */ | ||
4476 | loop = LOOP_CACHING_WAIT; | ||
4477 | search_start = ideal_cache_offset; | ||
4478 | ideal_cache_percent = 0; | ||
4479 | goto ideal_cache; | ||
4480 | } else if (loop == LOOP_FIND_IDEAL) { | ||
4481 | /* | ||
4482 | * Didn't find a uncached bg, wait on anything we find | ||
4483 | * next. | ||
4484 | */ | ||
4485 | loop = LOOP_CACHING_WAIT; | ||
4486 | goto search; | ||
4487 | } | ||
4488 | |||
4489 | if (loop < LOOP_CACHING_WAIT) { | ||
4490 | loop++; | ||
4491 | goto search; | ||
4312 | } | 4492 | } |
4313 | 4493 | ||
4314 | if (loop == LOOP_ALLOC_CHUNK) { | 4494 | if (loop == LOOP_ALLOC_CHUNK) { |
@@ -4320,7 +4500,8 @@ loop: | |||
4320 | ret = do_chunk_alloc(trans, root, num_bytes + | 4500 | ret = do_chunk_alloc(trans, root, num_bytes + |
4321 | 2 * 1024 * 1024, data, 1); | 4501 | 2 * 1024 * 1024, data, 1); |
4322 | allowed_chunk_alloc = 0; | 4502 | allowed_chunk_alloc = 0; |
4323 | } else { | 4503 | done_chunk_alloc = 1; |
4504 | } else if (!done_chunk_alloc) { | ||
4324 | space_info->force_alloc = 1; | 4505 | space_info->force_alloc = 1; |
4325 | } | 4506 | } |
4326 | 4507 | ||
@@ -4799,6 +4980,7 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, | |||
4799 | u64 bytenr; | 4980 | u64 bytenr; |
4800 | u64 generation; | 4981 | u64 generation; |
4801 | u64 refs; | 4982 | u64 refs; |
4983 | u64 flags; | ||
4802 | u64 last = 0; | 4984 | u64 last = 0; |
4803 | u32 nritems; | 4985 | u32 nritems; |
4804 | u32 blocksize; | 4986 | u32 blocksize; |
@@ -4836,15 +5018,19 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, | |||
4836 | generation <= root->root_key.offset) | 5018 | generation <= root->root_key.offset) |
4837 | continue; | 5019 | continue; |
4838 | 5020 | ||
5021 | /* We don't lock the tree block, it's OK to be racy here */ | ||
5022 | ret = btrfs_lookup_extent_info(trans, root, bytenr, blocksize, | ||
5023 | &refs, &flags); | ||
5024 | BUG_ON(ret); | ||
5025 | BUG_ON(refs == 0); | ||
5026 | |||
4839 | if (wc->stage == DROP_REFERENCE) { | 5027 | if (wc->stage == DROP_REFERENCE) { |
4840 | ret = btrfs_lookup_extent_info(trans, root, | ||
4841 | bytenr, blocksize, | ||
4842 | &refs, NULL); | ||
4843 | BUG_ON(ret); | ||
4844 | BUG_ON(refs == 0); | ||
4845 | if (refs == 1) | 5028 | if (refs == 1) |
4846 | goto reada; | 5029 | goto reada; |
4847 | 5030 | ||
5031 | if (wc->level == 1 && | ||
5032 | (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) | ||
5033 | continue; | ||
4848 | if (!wc->update_ref || | 5034 | if (!wc->update_ref || |
4849 | generation <= root->root_key.offset) | 5035 | generation <= root->root_key.offset) |
4850 | continue; | 5036 | continue; |
@@ -4853,6 +5039,10 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, | |||
4853 | &wc->update_progress); | 5039 | &wc->update_progress); |
4854 | if (ret < 0) | 5040 | if (ret < 0) |
4855 | continue; | 5041 | continue; |
5042 | } else { | ||
5043 | if (wc->level == 1 && | ||
5044 | (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) | ||
5045 | continue; | ||
4856 | } | 5046 | } |
4857 | reada: | 5047 | reada: |
4858 | ret = readahead_tree_block(root, bytenr, blocksize, | 5048 | ret = readahead_tree_block(root, bytenr, blocksize, |
@@ -4876,7 +5066,7 @@ reada: | |||
4876 | static noinline int walk_down_proc(struct btrfs_trans_handle *trans, | 5066 | static noinline int walk_down_proc(struct btrfs_trans_handle *trans, |
4877 | struct btrfs_root *root, | 5067 | struct btrfs_root *root, |
4878 | struct btrfs_path *path, | 5068 | struct btrfs_path *path, |
4879 | struct walk_control *wc) | 5069 | struct walk_control *wc, int lookup_info) |
4880 | { | 5070 | { |
4881 | int level = wc->level; | 5071 | int level = wc->level; |
4882 | struct extent_buffer *eb = path->nodes[level]; | 5072 | struct extent_buffer *eb = path->nodes[level]; |
@@ -4891,8 +5081,9 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans, | |||
4891 | * when reference count of tree block is 1, it won't increase | 5081 | * when reference count of tree block is 1, it won't increase |
4892 | * again. once full backref flag is set, we never clear it. | 5082 | * again. once full backref flag is set, we never clear it. |
4893 | */ | 5083 | */ |
4894 | if ((wc->stage == DROP_REFERENCE && wc->refs[level] != 1) || | 5084 | if (lookup_info && |
4895 | (wc->stage == UPDATE_BACKREF && !(wc->flags[level] & flag))) { | 5085 | ((wc->stage == DROP_REFERENCE && wc->refs[level] != 1) || |
5086 | (wc->stage == UPDATE_BACKREF && !(wc->flags[level] & flag)))) { | ||
4896 | BUG_ON(!path->locks[level]); | 5087 | BUG_ON(!path->locks[level]); |
4897 | ret = btrfs_lookup_extent_info(trans, root, | 5088 | ret = btrfs_lookup_extent_info(trans, root, |
4898 | eb->start, eb->len, | 5089 | eb->start, eb->len, |
@@ -4953,7 +5144,7 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans, | |||
4953 | static noinline int do_walk_down(struct btrfs_trans_handle *trans, | 5144 | static noinline int do_walk_down(struct btrfs_trans_handle *trans, |
4954 | struct btrfs_root *root, | 5145 | struct btrfs_root *root, |
4955 | struct btrfs_path *path, | 5146 | struct btrfs_path *path, |
4956 | struct walk_control *wc) | 5147 | struct walk_control *wc, int *lookup_info) |
4957 | { | 5148 | { |
4958 | u64 bytenr; | 5149 | u64 bytenr; |
4959 | u64 generation; | 5150 | u64 generation; |
@@ -4973,8 +5164,10 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, | |||
4973 | * for the subtree | 5164 | * for the subtree |
4974 | */ | 5165 | */ |
4975 | if (wc->stage == UPDATE_BACKREF && | 5166 | if (wc->stage == UPDATE_BACKREF && |
4976 | generation <= root->root_key.offset) | 5167 | generation <= root->root_key.offset) { |
5168 | *lookup_info = 1; | ||
4977 | return 1; | 5169 | return 1; |
5170 | } | ||
4978 | 5171 | ||
4979 | bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); | 5172 | bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); |
4980 | blocksize = btrfs_level_size(root, level - 1); | 5173 | blocksize = btrfs_level_size(root, level - 1); |
@@ -4987,14 +5180,19 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, | |||
4987 | btrfs_tree_lock(next); | 5180 | btrfs_tree_lock(next); |
4988 | btrfs_set_lock_blocking(next); | 5181 | btrfs_set_lock_blocking(next); |
4989 | 5182 | ||
4990 | if (wc->stage == DROP_REFERENCE) { | 5183 | ret = btrfs_lookup_extent_info(trans, root, bytenr, blocksize, |
4991 | ret = btrfs_lookup_extent_info(trans, root, bytenr, blocksize, | 5184 | &wc->refs[level - 1], |
4992 | &wc->refs[level - 1], | 5185 | &wc->flags[level - 1]); |
4993 | &wc->flags[level - 1]); | 5186 | BUG_ON(ret); |
4994 | BUG_ON(ret); | 5187 | BUG_ON(wc->refs[level - 1] == 0); |
4995 | BUG_ON(wc->refs[level - 1] == 0); | 5188 | *lookup_info = 0; |
4996 | 5189 | ||
5190 | if (wc->stage == DROP_REFERENCE) { | ||
4997 | if (wc->refs[level - 1] > 1) { | 5191 | if (wc->refs[level - 1] > 1) { |
5192 | if (level == 1 && | ||
5193 | (wc->flags[0] & BTRFS_BLOCK_FLAG_FULL_BACKREF)) | ||
5194 | goto skip; | ||
5195 | |||
4998 | if (!wc->update_ref || | 5196 | if (!wc->update_ref || |
4999 | generation <= root->root_key.offset) | 5197 | generation <= root->root_key.offset) |
5000 | goto skip; | 5198 | goto skip; |
@@ -5008,12 +5206,17 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, | |||
5008 | wc->stage = UPDATE_BACKREF; | 5206 | wc->stage = UPDATE_BACKREF; |
5009 | wc->shared_level = level - 1; | 5207 | wc->shared_level = level - 1; |
5010 | } | 5208 | } |
5209 | } else { | ||
5210 | if (level == 1 && | ||
5211 | (wc->flags[0] & BTRFS_BLOCK_FLAG_FULL_BACKREF)) | ||
5212 | goto skip; | ||
5011 | } | 5213 | } |
5012 | 5214 | ||
5013 | if (!btrfs_buffer_uptodate(next, generation)) { | 5215 | if (!btrfs_buffer_uptodate(next, generation)) { |
5014 | btrfs_tree_unlock(next); | 5216 | btrfs_tree_unlock(next); |
5015 | free_extent_buffer(next); | 5217 | free_extent_buffer(next); |
5016 | next = NULL; | 5218 | next = NULL; |
5219 | *lookup_info = 1; | ||
5017 | } | 5220 | } |
5018 | 5221 | ||
5019 | if (!next) { | 5222 | if (!next) { |
@@ -5036,21 +5239,22 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, | |||
5036 | skip: | 5239 | skip: |
5037 | wc->refs[level - 1] = 0; | 5240 | wc->refs[level - 1] = 0; |
5038 | wc->flags[level - 1] = 0; | 5241 | wc->flags[level - 1] = 0; |
5242 | if (wc->stage == DROP_REFERENCE) { | ||
5243 | if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) { | ||
5244 | parent = path->nodes[level]->start; | ||
5245 | } else { | ||
5246 | BUG_ON(root->root_key.objectid != | ||
5247 | btrfs_header_owner(path->nodes[level])); | ||
5248 | parent = 0; | ||
5249 | } | ||
5039 | 5250 | ||
5040 | if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) { | 5251 | ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent, |
5041 | parent = path->nodes[level]->start; | 5252 | root->root_key.objectid, level - 1, 0); |
5042 | } else { | 5253 | BUG_ON(ret); |
5043 | BUG_ON(root->root_key.objectid != | ||
5044 | btrfs_header_owner(path->nodes[level])); | ||
5045 | parent = 0; | ||
5046 | } | 5254 | } |
5047 | |||
5048 | ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent, | ||
5049 | root->root_key.objectid, level - 1, 0); | ||
5050 | BUG_ON(ret); | ||
5051 | |||
5052 | btrfs_tree_unlock(next); | 5255 | btrfs_tree_unlock(next); |
5053 | free_extent_buffer(next); | 5256 | free_extent_buffer(next); |
5257 | *lookup_info = 1; | ||
5054 | return 1; | 5258 | return 1; |
5055 | } | 5259 | } |
5056 | 5260 | ||
@@ -5164,6 +5368,7 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans, | |||
5164 | struct walk_control *wc) | 5368 | struct walk_control *wc) |
5165 | { | 5369 | { |
5166 | int level = wc->level; | 5370 | int level = wc->level; |
5371 | int lookup_info = 1; | ||
5167 | int ret; | 5372 | int ret; |
5168 | 5373 | ||
5169 | while (level >= 0) { | 5374 | while (level >= 0) { |
@@ -5171,14 +5376,14 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans, | |||
5171 | btrfs_header_nritems(path->nodes[level])) | 5376 | btrfs_header_nritems(path->nodes[level])) |
5172 | break; | 5377 | break; |
5173 | 5378 | ||
5174 | ret = walk_down_proc(trans, root, path, wc); | 5379 | ret = walk_down_proc(trans, root, path, wc, lookup_info); |
5175 | if (ret > 0) | 5380 | if (ret > 0) |
5176 | break; | 5381 | break; |
5177 | 5382 | ||
5178 | if (level == 0) | 5383 | if (level == 0) |
5179 | break; | 5384 | break; |
5180 | 5385 | ||
5181 | ret = do_walk_down(trans, root, path, wc); | 5386 | ret = do_walk_down(trans, root, path, wc, &lookup_info); |
5182 | if (ret > 0) { | 5387 | if (ret > 0) { |
5183 | path->slots[level]++; | 5388 | path->slots[level]++; |
5184 | continue; | 5389 | continue; |
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index de1793ba004a..96577e8bf9fd 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -460,7 +460,8 @@ static int clear_state_bit(struct extent_io_tree *tree, | |||
460 | struct extent_state *state, int bits, int wake, | 460 | struct extent_state *state, int bits, int wake, |
461 | int delete) | 461 | int delete) |
462 | { | 462 | { |
463 | int ret = state->state & bits; | 463 | int bits_to_clear = bits & ~EXTENT_DO_ACCOUNTING; |
464 | int ret = state->state & bits_to_clear; | ||
464 | 465 | ||
465 | if ((bits & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { | 466 | if ((bits & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { |
466 | u64 range = state->end - state->start + 1; | 467 | u64 range = state->end - state->start + 1; |
@@ -468,7 +469,7 @@ static int clear_state_bit(struct extent_io_tree *tree, | |||
468 | tree->dirty_bytes -= range; | 469 | tree->dirty_bytes -= range; |
469 | } | 470 | } |
470 | clear_state_cb(tree, state, bits); | 471 | clear_state_cb(tree, state, bits); |
471 | state->state &= ~bits; | 472 | state->state &= ~bits_to_clear; |
472 | if (wake) | 473 | if (wake) |
473 | wake_up(&state->wq); | 474 | wake_up(&state->wq); |
474 | if (delete || state->state == 0) { | 475 | if (delete || state->state == 0) { |
@@ -956,7 +957,8 @@ int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, | |||
956 | gfp_t mask) | 957 | gfp_t mask) |
957 | { | 958 | { |
958 | return clear_extent_bit(tree, start, end, | 959 | return clear_extent_bit(tree, start, end, |
959 | EXTENT_DIRTY | EXTENT_DELALLOC, 0, 0, | 960 | EXTENT_DIRTY | EXTENT_DELALLOC | |
961 | EXTENT_DO_ACCOUNTING, 0, 0, | ||
960 | NULL, mask); | 962 | NULL, mask); |
961 | } | 963 | } |
962 | 964 | ||
@@ -1401,12 +1403,7 @@ out_failed: | |||
1401 | int extent_clear_unlock_delalloc(struct inode *inode, | 1403 | int extent_clear_unlock_delalloc(struct inode *inode, |
1402 | struct extent_io_tree *tree, | 1404 | struct extent_io_tree *tree, |
1403 | u64 start, u64 end, struct page *locked_page, | 1405 | u64 start, u64 end, struct page *locked_page, |
1404 | int unlock_pages, | 1406 | unsigned long op) |
1405 | int clear_unlock, | ||
1406 | int clear_delalloc, int clear_dirty, | ||
1407 | int set_writeback, | ||
1408 | int end_writeback, | ||
1409 | int set_private2) | ||
1410 | { | 1407 | { |
1411 | int ret; | 1408 | int ret; |
1412 | struct page *pages[16]; | 1409 | struct page *pages[16]; |
@@ -1416,17 +1413,21 @@ int extent_clear_unlock_delalloc(struct inode *inode, | |||
1416 | int i; | 1413 | int i; |
1417 | int clear_bits = 0; | 1414 | int clear_bits = 0; |
1418 | 1415 | ||
1419 | if (clear_unlock) | 1416 | if (op & EXTENT_CLEAR_UNLOCK) |
1420 | clear_bits |= EXTENT_LOCKED; | 1417 | clear_bits |= EXTENT_LOCKED; |
1421 | if (clear_dirty) | 1418 | if (op & EXTENT_CLEAR_DIRTY) |
1422 | clear_bits |= EXTENT_DIRTY; | 1419 | clear_bits |= EXTENT_DIRTY; |
1423 | 1420 | ||
1424 | if (clear_delalloc) | 1421 | if (op & EXTENT_CLEAR_DELALLOC) |
1425 | clear_bits |= EXTENT_DELALLOC; | 1422 | clear_bits |= EXTENT_DELALLOC; |
1426 | 1423 | ||
1424 | if (op & EXTENT_CLEAR_ACCOUNTING) | ||
1425 | clear_bits |= EXTENT_DO_ACCOUNTING; | ||
1426 | |||
1427 | clear_extent_bit(tree, start, end, clear_bits, 1, 0, NULL, GFP_NOFS); | 1427 | clear_extent_bit(tree, start, end, clear_bits, 1, 0, NULL, GFP_NOFS); |
1428 | if (!(unlock_pages || clear_dirty || set_writeback || end_writeback || | 1428 | if (!(op & (EXTENT_CLEAR_UNLOCK_PAGE | EXTENT_CLEAR_DIRTY | |
1429 | set_private2)) | 1429 | EXTENT_SET_WRITEBACK | EXTENT_END_WRITEBACK | |
1430 | EXTENT_SET_PRIVATE2))) | ||
1430 | return 0; | 1431 | return 0; |
1431 | 1432 | ||
1432 | while (nr_pages > 0) { | 1433 | while (nr_pages > 0) { |
@@ -1435,20 +1436,20 @@ int extent_clear_unlock_delalloc(struct inode *inode, | |||
1435 | nr_pages, ARRAY_SIZE(pages)), pages); | 1436 | nr_pages, ARRAY_SIZE(pages)), pages); |
1436 | for (i = 0; i < ret; i++) { | 1437 | for (i = 0; i < ret; i++) { |
1437 | 1438 | ||
1438 | if (set_private2) | 1439 | if (op & EXTENT_SET_PRIVATE2) |
1439 | SetPagePrivate2(pages[i]); | 1440 | SetPagePrivate2(pages[i]); |
1440 | 1441 | ||
1441 | if (pages[i] == locked_page) { | 1442 | if (pages[i] == locked_page) { |
1442 | page_cache_release(pages[i]); | 1443 | page_cache_release(pages[i]); |
1443 | continue; | 1444 | continue; |
1444 | } | 1445 | } |
1445 | if (clear_dirty) | 1446 | if (op & EXTENT_CLEAR_DIRTY) |
1446 | clear_page_dirty_for_io(pages[i]); | 1447 | clear_page_dirty_for_io(pages[i]); |
1447 | if (set_writeback) | 1448 | if (op & EXTENT_SET_WRITEBACK) |
1448 | set_page_writeback(pages[i]); | 1449 | set_page_writeback(pages[i]); |
1449 | if (end_writeback) | 1450 | if (op & EXTENT_END_WRITEBACK) |
1450 | end_page_writeback(pages[i]); | 1451 | end_page_writeback(pages[i]); |
1451 | if (unlock_pages) | 1452 | if (op & EXTENT_CLEAR_UNLOCK_PAGE) |
1452 | unlock_page(pages[i]); | 1453 | unlock_page(pages[i]); |
1453 | page_cache_release(pages[i]); | 1454 | page_cache_release(pages[i]); |
1454 | } | 1455 | } |
@@ -2714,7 +2715,8 @@ int extent_invalidatepage(struct extent_io_tree *tree, | |||
2714 | lock_extent(tree, start, end, GFP_NOFS); | 2715 | lock_extent(tree, start, end, GFP_NOFS); |
2715 | wait_on_page_writeback(page); | 2716 | wait_on_page_writeback(page); |
2716 | clear_extent_bit(tree, start, end, | 2717 | clear_extent_bit(tree, start, end, |
2717 | EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC, | 2718 | EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC | |
2719 | EXTENT_DO_ACCOUNTING, | ||
2718 | 1, 1, NULL, GFP_NOFS); | 2720 | 1, 1, NULL, GFP_NOFS); |
2719 | return 0; | 2721 | return 0; |
2720 | } | 2722 | } |
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 4794ec891fed..36de250a7b2b 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h | |||
@@ -15,6 +15,7 @@ | |||
15 | #define EXTENT_BUFFER_FILLED (1 << 8) | 15 | #define EXTENT_BUFFER_FILLED (1 << 8) |
16 | #define EXTENT_BOUNDARY (1 << 9) | 16 | #define EXTENT_BOUNDARY (1 << 9) |
17 | #define EXTENT_NODATASUM (1 << 10) | 17 | #define EXTENT_NODATASUM (1 << 10) |
18 | #define EXTENT_DO_ACCOUNTING (1 << 11) | ||
18 | #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK) | 19 | #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK) |
19 | 20 | ||
20 | /* flags for bio submission */ | 21 | /* flags for bio submission */ |
@@ -25,6 +26,16 @@ | |||
25 | #define EXTENT_BUFFER_BLOCKING 1 | 26 | #define EXTENT_BUFFER_BLOCKING 1 |
26 | #define EXTENT_BUFFER_DIRTY 2 | 27 | #define EXTENT_BUFFER_DIRTY 2 |
27 | 28 | ||
29 | /* these are flags for extent_clear_unlock_delalloc */ | ||
30 | #define EXTENT_CLEAR_UNLOCK_PAGE 0x1 | ||
31 | #define EXTENT_CLEAR_UNLOCK 0x2 | ||
32 | #define EXTENT_CLEAR_DELALLOC 0x4 | ||
33 | #define EXTENT_CLEAR_DIRTY 0x8 | ||
34 | #define EXTENT_SET_WRITEBACK 0x10 | ||
35 | #define EXTENT_END_WRITEBACK 0x20 | ||
36 | #define EXTENT_SET_PRIVATE2 0x40 | ||
37 | #define EXTENT_CLEAR_ACCOUNTING 0x80 | ||
38 | |||
28 | /* | 39 | /* |
29 | * page->private values. Every page that is controlled by the extent | 40 | * page->private values. Every page that is controlled by the extent |
30 | * map has page->private set to one. | 41 | * map has page->private set to one. |
@@ -288,10 +299,5 @@ int extent_range_uptodate(struct extent_io_tree *tree, | |||
288 | int extent_clear_unlock_delalloc(struct inode *inode, | 299 | int extent_clear_unlock_delalloc(struct inode *inode, |
289 | struct extent_io_tree *tree, | 300 | struct extent_io_tree *tree, |
290 | u64 start, u64 end, struct page *locked_page, | 301 | u64 start, u64 end, struct page *locked_page, |
291 | int unlock_page, | 302 | unsigned long op); |
292 | int clear_unlock, | ||
293 | int clear_delalloc, int clear_dirty, | ||
294 | int set_writeback, | ||
295 | int end_writeback, | ||
296 | int set_private2); | ||
297 | #endif | 303 | #endif |
diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index 2c726b7b9faa..ccbdcb54ec5d 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c | |||
@@ -208,7 +208,7 @@ int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len) | |||
208 | write_lock(&tree->lock); | 208 | write_lock(&tree->lock); |
209 | em = lookup_extent_mapping(tree, start, len); | 209 | em = lookup_extent_mapping(tree, start, len); |
210 | 210 | ||
211 | WARN_ON(em->start != start || !em); | 211 | WARN_ON(!em || em->start != start); |
212 | 212 | ||
213 | if (!em) | 213 | if (!em) |
214 | goto out; | 214 | goto out; |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index f19e1259a971..06550affbd27 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -878,7 +878,8 @@ again: | |||
878 | btrfs_put_ordered_extent(ordered); | 878 | btrfs_put_ordered_extent(ordered); |
879 | 879 | ||
880 | clear_extent_bits(&BTRFS_I(inode)->io_tree, start_pos, | 880 | clear_extent_bits(&BTRFS_I(inode)->io_tree, start_pos, |
881 | last_pos - 1, EXTENT_DIRTY | EXTENT_DELALLOC, | 881 | last_pos - 1, EXTENT_DIRTY | EXTENT_DELALLOC | |
882 | EXTENT_DO_ACCOUNTING, | ||
882 | GFP_NOFS); | 883 | GFP_NOFS); |
883 | unlock_extent(&BTRFS_I(inode)->io_tree, | 884 | unlock_extent(&BTRFS_I(inode)->io_tree, |
884 | start_pos, last_pos - 1, GFP_NOFS); | 885 | start_pos, last_pos - 1, GFP_NOFS); |
@@ -1085,8 +1086,10 @@ out_nolock: | |||
1085 | btrfs_end_transaction(trans, root); | 1086 | btrfs_end_transaction(trans, root); |
1086 | else | 1087 | else |
1087 | btrfs_commit_transaction(trans, root); | 1088 | btrfs_commit_transaction(trans, root); |
1088 | } else { | 1089 | } else if (ret != BTRFS_NO_LOG_SYNC) { |
1089 | btrfs_commit_transaction(trans, root); | 1090 | btrfs_commit_transaction(trans, root); |
1091 | } else { | ||
1092 | btrfs_end_transaction(trans, root); | ||
1090 | } | 1093 | } |
1091 | } | 1094 | } |
1092 | if (file->f_flags & O_DIRECT) { | 1095 | if (file->f_flags & O_DIRECT) { |
@@ -1136,6 +1139,13 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
1136 | int ret = 0; | 1139 | int ret = 0; |
1137 | struct btrfs_trans_handle *trans; | 1140 | struct btrfs_trans_handle *trans; |
1138 | 1141 | ||
1142 | |||
1143 | /* we wait first, since the writeback may change the inode */ | ||
1144 | root->log_batch++; | ||
1145 | /* the VFS called filemap_fdatawrite for us */ | ||
1146 | btrfs_wait_ordered_range(inode, 0, (u64)-1); | ||
1147 | root->log_batch++; | ||
1148 | |||
1139 | /* | 1149 | /* |
1140 | * check the transaction that last modified this inode | 1150 | * check the transaction that last modified this inode |
1141 | * and see if its already been committed | 1151 | * and see if its already been committed |
@@ -1143,6 +1153,11 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
1143 | if (!BTRFS_I(inode)->last_trans) | 1153 | if (!BTRFS_I(inode)->last_trans) |
1144 | goto out; | 1154 | goto out; |
1145 | 1155 | ||
1156 | /* | ||
1157 | * if the last transaction that changed this file was before | ||
1158 | * the current transaction, we can bail out now without any | ||
1159 | * syncing | ||
1160 | */ | ||
1146 | mutex_lock(&root->fs_info->trans_mutex); | 1161 | mutex_lock(&root->fs_info->trans_mutex); |
1147 | if (BTRFS_I(inode)->last_trans <= | 1162 | if (BTRFS_I(inode)->last_trans <= |
1148 | root->fs_info->last_trans_committed) { | 1163 | root->fs_info->last_trans_committed) { |
@@ -1152,13 +1167,6 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
1152 | } | 1167 | } |
1153 | mutex_unlock(&root->fs_info->trans_mutex); | 1168 | mutex_unlock(&root->fs_info->trans_mutex); |
1154 | 1169 | ||
1155 | root->log_batch++; | ||
1156 | filemap_fdatawrite(inode->i_mapping); | ||
1157 | btrfs_wait_ordered_range(inode, 0, (u64)-1); | ||
1158 | root->log_batch++; | ||
1159 | |||
1160 | if (datasync && !(inode->i_state & I_DIRTY_PAGES)) | ||
1161 | goto out; | ||
1162 | /* | 1170 | /* |
1163 | * ok we haven't committed the transaction yet, lets do a commit | 1171 | * ok we haven't committed the transaction yet, lets do a commit |
1164 | */ | 1172 | */ |
@@ -1187,14 +1195,18 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
1187 | */ | 1195 | */ |
1188 | mutex_unlock(&dentry->d_inode->i_mutex); | 1196 | mutex_unlock(&dentry->d_inode->i_mutex); |
1189 | 1197 | ||
1190 | if (ret > 0) { | 1198 | if (ret != BTRFS_NO_LOG_SYNC) { |
1191 | ret = btrfs_commit_transaction(trans, root); | 1199 | if (ret > 0) { |
1192 | } else { | ||
1193 | ret = btrfs_sync_log(trans, root); | ||
1194 | if (ret == 0) | ||
1195 | ret = btrfs_end_transaction(trans, root); | ||
1196 | else | ||
1197 | ret = btrfs_commit_transaction(trans, root); | 1200 | ret = btrfs_commit_transaction(trans, root); |
1201 | } else { | ||
1202 | ret = btrfs_sync_log(trans, root); | ||
1203 | if (ret == 0) | ||
1204 | ret = btrfs_end_transaction(trans, root); | ||
1205 | else | ||
1206 | ret = btrfs_commit_transaction(trans, root); | ||
1207 | } | ||
1208 | } else { | ||
1209 | ret = btrfs_end_transaction(trans, root); | ||
1198 | } | 1210 | } |
1199 | mutex_lock(&dentry->d_inode->i_mutex); | 1211 | mutex_lock(&dentry->d_inode->i_mutex); |
1200 | out: | 1212 | out: |
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 5c2caad76212..cb2849f03251 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -1296,7 +1296,7 @@ again: | |||
1296 | window_start = entry->offset; | 1296 | window_start = entry->offset; |
1297 | window_free = entry->bytes; | 1297 | window_free = entry->bytes; |
1298 | last = entry; | 1298 | last = entry; |
1299 | max_extent = 0; | 1299 | max_extent = entry->bytes; |
1300 | } else { | 1300 | } else { |
1301 | last = next; | 1301 | last = next; |
1302 | window_free += next->bytes; | 1302 | window_free += next->bytes; |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 112e5aa85892..b3ad168a0bfc 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -424,9 +424,12 @@ again: | |||
424 | * and free up our temp pages. | 424 | * and free up our temp pages. |
425 | */ | 425 | */ |
426 | extent_clear_unlock_delalloc(inode, | 426 | extent_clear_unlock_delalloc(inode, |
427 | &BTRFS_I(inode)->io_tree, | 427 | &BTRFS_I(inode)->io_tree, |
428 | start, end, NULL, 1, 0, | 428 | start, end, NULL, |
429 | 0, 1, 1, 1, 0); | 429 | EXTENT_CLEAR_UNLOCK_PAGE | EXTENT_CLEAR_DIRTY | |
430 | EXTENT_CLEAR_DELALLOC | | ||
431 | EXTENT_CLEAR_ACCOUNTING | | ||
432 | EXTENT_SET_WRITEBACK | EXTENT_END_WRITEBACK); | ||
430 | ret = 0; | 433 | ret = 0; |
431 | goto free_pages_out; | 434 | goto free_pages_out; |
432 | } | 435 | } |
@@ -535,7 +538,7 @@ static noinline int submit_compressed_extents(struct inode *inode, | |||
535 | struct btrfs_root *root = BTRFS_I(inode)->root; | 538 | struct btrfs_root *root = BTRFS_I(inode)->root; |
536 | struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; | 539 | struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; |
537 | struct extent_io_tree *io_tree; | 540 | struct extent_io_tree *io_tree; |
538 | int ret; | 541 | int ret = 0; |
539 | 542 | ||
540 | if (list_empty(&async_cow->extents)) | 543 | if (list_empty(&async_cow->extents)) |
541 | return 0; | 544 | return 0; |
@@ -549,6 +552,7 @@ static noinline int submit_compressed_extents(struct inode *inode, | |||
549 | 552 | ||
550 | io_tree = &BTRFS_I(inode)->io_tree; | 553 | io_tree = &BTRFS_I(inode)->io_tree; |
551 | 554 | ||
555 | retry: | ||
552 | /* did the compression code fall back to uncompressed IO? */ | 556 | /* did the compression code fall back to uncompressed IO? */ |
553 | if (!async_extent->pages) { | 557 | if (!async_extent->pages) { |
554 | int page_started = 0; | 558 | int page_started = 0; |
@@ -559,11 +563,11 @@ static noinline int submit_compressed_extents(struct inode *inode, | |||
559 | async_extent->ram_size - 1, GFP_NOFS); | 563 | async_extent->ram_size - 1, GFP_NOFS); |
560 | 564 | ||
561 | /* allocate blocks */ | 565 | /* allocate blocks */ |
562 | cow_file_range(inode, async_cow->locked_page, | 566 | ret = cow_file_range(inode, async_cow->locked_page, |
563 | async_extent->start, | 567 | async_extent->start, |
564 | async_extent->start + | 568 | async_extent->start + |
565 | async_extent->ram_size - 1, | 569 | async_extent->ram_size - 1, |
566 | &page_started, &nr_written, 0); | 570 | &page_started, &nr_written, 0); |
567 | 571 | ||
568 | /* | 572 | /* |
569 | * if page_started, cow_file_range inserted an | 573 | * if page_started, cow_file_range inserted an |
@@ -571,7 +575,7 @@ static noinline int submit_compressed_extents(struct inode *inode, | |||
571 | * and IO for us. Otherwise, we need to submit | 575 | * and IO for us. Otherwise, we need to submit |
572 | * all those pages down to the drive. | 576 | * all those pages down to the drive. |
573 | */ | 577 | */ |
574 | if (!page_started) | 578 | if (!page_started && !ret) |
575 | extent_write_locked_range(io_tree, | 579 | extent_write_locked_range(io_tree, |
576 | inode, async_extent->start, | 580 | inode, async_extent->start, |
577 | async_extent->start + | 581 | async_extent->start + |
@@ -599,7 +603,21 @@ static noinline int submit_compressed_extents(struct inode *inode, | |||
599 | async_extent->compressed_size, | 603 | async_extent->compressed_size, |
600 | 0, alloc_hint, | 604 | 0, alloc_hint, |
601 | (u64)-1, &ins, 1); | 605 | (u64)-1, &ins, 1); |
602 | BUG_ON(ret); | 606 | if (ret) { |
607 | int i; | ||
608 | for (i = 0; i < async_extent->nr_pages; i++) { | ||
609 | WARN_ON(async_extent->pages[i]->mapping); | ||
610 | page_cache_release(async_extent->pages[i]); | ||
611 | } | ||
612 | kfree(async_extent->pages); | ||
613 | async_extent->nr_pages = 0; | ||
614 | async_extent->pages = NULL; | ||
615 | unlock_extent(io_tree, async_extent->start, | ||
616 | async_extent->start + | ||
617 | async_extent->ram_size - 1, GFP_NOFS); | ||
618 | goto retry; | ||
619 | } | ||
620 | |||
603 | em = alloc_extent_map(GFP_NOFS); | 621 | em = alloc_extent_map(GFP_NOFS); |
604 | em->start = async_extent->start; | 622 | em->start = async_extent->start; |
605 | em->len = async_extent->ram_size; | 623 | em->len = async_extent->ram_size; |
@@ -637,11 +655,14 @@ static noinline int submit_compressed_extents(struct inode *inode, | |||
637 | * clear dirty, set writeback and unlock the pages. | 655 | * clear dirty, set writeback and unlock the pages. |
638 | */ | 656 | */ |
639 | extent_clear_unlock_delalloc(inode, | 657 | extent_clear_unlock_delalloc(inode, |
640 | &BTRFS_I(inode)->io_tree, | 658 | &BTRFS_I(inode)->io_tree, |
641 | async_extent->start, | 659 | async_extent->start, |
642 | async_extent->start + | 660 | async_extent->start + |
643 | async_extent->ram_size - 1, | 661 | async_extent->ram_size - 1, |
644 | NULL, 1, 1, 0, 1, 1, 0, 0); | 662 | NULL, EXTENT_CLEAR_UNLOCK_PAGE | |
663 | EXTENT_CLEAR_UNLOCK | | ||
664 | EXTENT_CLEAR_DELALLOC | | ||
665 | EXTENT_CLEAR_DIRTY | EXTENT_SET_WRITEBACK); | ||
645 | 666 | ||
646 | ret = btrfs_submit_compressed_write(inode, | 667 | ret = btrfs_submit_compressed_write(inode, |
647 | async_extent->start, | 668 | async_extent->start, |
@@ -712,9 +733,15 @@ static noinline int cow_file_range(struct inode *inode, | |||
712 | start, end, 0, NULL); | 733 | start, end, 0, NULL); |
713 | if (ret == 0) { | 734 | if (ret == 0) { |
714 | extent_clear_unlock_delalloc(inode, | 735 | extent_clear_unlock_delalloc(inode, |
715 | &BTRFS_I(inode)->io_tree, | 736 | &BTRFS_I(inode)->io_tree, |
716 | start, end, NULL, 1, 1, | 737 | start, end, NULL, |
717 | 1, 1, 1, 1, 0); | 738 | EXTENT_CLEAR_UNLOCK_PAGE | |
739 | EXTENT_CLEAR_UNLOCK | | ||
740 | EXTENT_CLEAR_DELALLOC | | ||
741 | EXTENT_CLEAR_ACCOUNTING | | ||
742 | EXTENT_CLEAR_DIRTY | | ||
743 | EXTENT_SET_WRITEBACK | | ||
744 | EXTENT_END_WRITEBACK); | ||
718 | *nr_written = *nr_written + | 745 | *nr_written = *nr_written + |
719 | (end - start + PAGE_CACHE_SIZE) / PAGE_CACHE_SIZE; | 746 | (end - start + PAGE_CACHE_SIZE) / PAGE_CACHE_SIZE; |
720 | *page_started = 1; | 747 | *page_started = 1; |
@@ -731,13 +758,29 @@ static noinline int cow_file_range(struct inode *inode, | |||
731 | em = search_extent_mapping(&BTRFS_I(inode)->extent_tree, | 758 | em = search_extent_mapping(&BTRFS_I(inode)->extent_tree, |
732 | start, num_bytes); | 759 | start, num_bytes); |
733 | if (em) { | 760 | if (em) { |
734 | alloc_hint = em->block_start; | 761 | /* |
735 | free_extent_map(em); | 762 | * if block start isn't an actual block number then find the |
763 | * first block in this inode and use that as a hint. If that | ||
764 | * block is also bogus then just don't worry about it. | ||
765 | */ | ||
766 | if (em->block_start >= EXTENT_MAP_LAST_BYTE) { | ||
767 | free_extent_map(em); | ||
768 | em = search_extent_mapping(em_tree, 0, 0); | ||
769 | if (em && em->block_start < EXTENT_MAP_LAST_BYTE) | ||
770 | alloc_hint = em->block_start; | ||
771 | if (em) | ||
772 | free_extent_map(em); | ||
773 | } else { | ||
774 | alloc_hint = em->block_start; | ||
775 | free_extent_map(em); | ||
776 | } | ||
736 | } | 777 | } |
737 | read_unlock(&BTRFS_I(inode)->extent_tree.lock); | 778 | read_unlock(&BTRFS_I(inode)->extent_tree.lock); |
738 | btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0); | 779 | btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0); |
739 | 780 | ||
740 | while (disk_num_bytes > 0) { | 781 | while (disk_num_bytes > 0) { |
782 | unsigned long op; | ||
783 | |||
741 | cur_alloc_size = min(disk_num_bytes, root->fs_info->max_extent); | 784 | cur_alloc_size = min(disk_num_bytes, root->fs_info->max_extent); |
742 | ret = btrfs_reserve_extent(trans, root, cur_alloc_size, | 785 | ret = btrfs_reserve_extent(trans, root, cur_alloc_size, |
743 | root->sectorsize, 0, alloc_hint, | 786 | root->sectorsize, 0, alloc_hint, |
@@ -789,10 +832,13 @@ static noinline int cow_file_range(struct inode *inode, | |||
789 | * Do set the Private2 bit so we know this page was properly | 832 | * Do set the Private2 bit so we know this page was properly |
790 | * setup for writepage | 833 | * setup for writepage |
791 | */ | 834 | */ |
835 | op = unlock ? EXTENT_CLEAR_UNLOCK_PAGE : 0; | ||
836 | op |= EXTENT_CLEAR_UNLOCK | EXTENT_CLEAR_DELALLOC | | ||
837 | EXTENT_SET_PRIVATE2; | ||
838 | |||
792 | extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, | 839 | extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, |
793 | start, start + ram_size - 1, | 840 | start, start + ram_size - 1, |
794 | locked_page, unlock, 1, | 841 | locked_page, op); |
795 | 1, 0, 0, 0, 1); | ||
796 | disk_num_bytes -= cur_alloc_size; | 842 | disk_num_bytes -= cur_alloc_size; |
797 | num_bytes -= cur_alloc_size; | 843 | num_bytes -= cur_alloc_size; |
798 | alloc_hint = ins.objectid + ins.offset; | 844 | alloc_hint = ins.objectid + ins.offset; |
@@ -864,8 +910,8 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page, | |||
864 | u64 cur_end; | 910 | u64 cur_end; |
865 | int limit = 10 * 1024 * 1042; | 911 | int limit = 10 * 1024 * 1042; |
866 | 912 | ||
867 | clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED | | 913 | clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED, |
868 | EXTENT_DELALLOC, 1, 0, NULL, GFP_NOFS); | 914 | 1, 0, NULL, GFP_NOFS); |
869 | while (start < end) { | 915 | while (start < end) { |
870 | async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS); | 916 | async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS); |
871 | async_cow->inode = inode; | 917 | async_cow->inode = inode; |
@@ -1006,6 +1052,7 @@ next_slot: | |||
1006 | 1052 | ||
1007 | if (found_key.offset > cur_offset) { | 1053 | if (found_key.offset > cur_offset) { |
1008 | extent_end = found_key.offset; | 1054 | extent_end = found_key.offset; |
1055 | extent_type = 0; | ||
1009 | goto out_check; | 1056 | goto out_check; |
1010 | } | 1057 | } |
1011 | 1058 | ||
@@ -1112,8 +1159,10 @@ out_check: | |||
1112 | BUG_ON(ret); | 1159 | BUG_ON(ret); |
1113 | 1160 | ||
1114 | extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, | 1161 | extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, |
1115 | cur_offset, cur_offset + num_bytes - 1, | 1162 | cur_offset, cur_offset + num_bytes - 1, |
1116 | locked_page, 1, 1, 1, 0, 0, 0, 1); | 1163 | locked_page, EXTENT_CLEAR_UNLOCK_PAGE | |
1164 | EXTENT_CLEAR_UNLOCK | EXTENT_CLEAR_DELALLOC | | ||
1165 | EXTENT_SET_PRIVATE2); | ||
1117 | cur_offset = extent_end; | 1166 | cur_offset = extent_end; |
1118 | if (cur_offset > end) | 1167 | if (cur_offset > end) |
1119 | break; | 1168 | break; |
@@ -1178,15 +1227,17 @@ static int btrfs_split_extent_hook(struct inode *inode, | |||
1178 | root->fs_info->max_extent); | 1227 | root->fs_info->max_extent); |
1179 | 1228 | ||
1180 | /* | 1229 | /* |
1181 | * if we break a large extent up then leave delalloc_extents be, | 1230 | * if we break a large extent up then leave oustanding_extents |
1182 | * since we've already accounted for the large extent. | 1231 | * be, since we've already accounted for the large extent. |
1183 | */ | 1232 | */ |
1184 | if (div64_u64(new_size + root->fs_info->max_extent - 1, | 1233 | if (div64_u64(new_size + root->fs_info->max_extent - 1, |
1185 | root->fs_info->max_extent) < num_extents) | 1234 | root->fs_info->max_extent) < num_extents) |
1186 | return 0; | 1235 | return 0; |
1187 | } | 1236 | } |
1188 | 1237 | ||
1189 | BTRFS_I(inode)->delalloc_extents++; | 1238 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
1239 | BTRFS_I(inode)->outstanding_extents++; | ||
1240 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1190 | 1241 | ||
1191 | return 0; | 1242 | return 0; |
1192 | } | 1243 | } |
@@ -1217,7 +1268,9 @@ static int btrfs_merge_extent_hook(struct inode *inode, | |||
1217 | 1268 | ||
1218 | /* we're not bigger than the max, unreserve the space and go */ | 1269 | /* we're not bigger than the max, unreserve the space and go */ |
1219 | if (new_size <= root->fs_info->max_extent) { | 1270 | if (new_size <= root->fs_info->max_extent) { |
1220 | BTRFS_I(inode)->delalloc_extents--; | 1271 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
1272 | BTRFS_I(inode)->outstanding_extents--; | ||
1273 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1221 | return 0; | 1274 | return 0; |
1222 | } | 1275 | } |
1223 | 1276 | ||
@@ -1231,7 +1284,9 @@ static int btrfs_merge_extent_hook(struct inode *inode, | |||
1231 | root->fs_info->max_extent) > num_extents) | 1284 | root->fs_info->max_extent) > num_extents) |
1232 | return 0; | 1285 | return 0; |
1233 | 1286 | ||
1234 | BTRFS_I(inode)->delalloc_extents--; | 1287 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
1288 | BTRFS_I(inode)->outstanding_extents--; | ||
1289 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1235 | 1290 | ||
1236 | return 0; | 1291 | return 0; |
1237 | } | 1292 | } |
@@ -1253,7 +1308,9 @@ static int btrfs_set_bit_hook(struct inode *inode, u64 start, u64 end, | |||
1253 | if (!(old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { | 1308 | if (!(old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { |
1254 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1309 | struct btrfs_root *root = BTRFS_I(inode)->root; |
1255 | 1310 | ||
1256 | BTRFS_I(inode)->delalloc_extents++; | 1311 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
1312 | BTRFS_I(inode)->outstanding_extents++; | ||
1313 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1257 | btrfs_delalloc_reserve_space(root, inode, end - start + 1); | 1314 | btrfs_delalloc_reserve_space(root, inode, end - start + 1); |
1258 | spin_lock(&root->fs_info->delalloc_lock); | 1315 | spin_lock(&root->fs_info->delalloc_lock); |
1259 | BTRFS_I(inode)->delalloc_bytes += end - start + 1; | 1316 | BTRFS_I(inode)->delalloc_bytes += end - start + 1; |
@@ -1281,8 +1338,12 @@ static int btrfs_clear_bit_hook(struct inode *inode, | |||
1281 | if ((state->state & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { | 1338 | if ((state->state & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { |
1282 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1339 | struct btrfs_root *root = BTRFS_I(inode)->root; |
1283 | 1340 | ||
1284 | BTRFS_I(inode)->delalloc_extents--; | 1341 | if (bits & EXTENT_DO_ACCOUNTING) { |
1285 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | 1342 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
1343 | BTRFS_I(inode)->outstanding_extents--; | ||
1344 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1345 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
1346 | } | ||
1286 | 1347 | ||
1287 | spin_lock(&root->fs_info->delalloc_lock); | 1348 | spin_lock(&root->fs_info->delalloc_lock); |
1288 | if (state->end - state->start + 1 > | 1349 | if (state->end - state->start + 1 > |
@@ -2442,7 +2503,19 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry) | |||
2442 | 2503 | ||
2443 | root = BTRFS_I(dir)->root; | 2504 | root = BTRFS_I(dir)->root; |
2444 | 2505 | ||
2506 | /* | ||
2507 | * 5 items for unlink inode | ||
2508 | * 1 for orphan | ||
2509 | */ | ||
2510 | ret = btrfs_reserve_metadata_space(root, 6); | ||
2511 | if (ret) | ||
2512 | return ret; | ||
2513 | |||
2445 | trans = btrfs_start_transaction(root, 1); | 2514 | trans = btrfs_start_transaction(root, 1); |
2515 | if (IS_ERR(trans)) { | ||
2516 | btrfs_unreserve_metadata_space(root, 6); | ||
2517 | return PTR_ERR(trans); | ||
2518 | } | ||
2446 | 2519 | ||
2447 | btrfs_set_trans_block_group(trans, dir); | 2520 | btrfs_set_trans_block_group(trans, dir); |
2448 | 2521 | ||
@@ -2457,6 +2530,7 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry) | |||
2457 | nr = trans->blocks_used; | 2530 | nr = trans->blocks_used; |
2458 | 2531 | ||
2459 | btrfs_end_transaction_throttle(trans, root); | 2532 | btrfs_end_transaction_throttle(trans, root); |
2533 | btrfs_unreserve_metadata_space(root, 6); | ||
2460 | btrfs_btree_balance_dirty(root, nr); | 2534 | btrfs_btree_balance_dirty(root, nr); |
2461 | return ret; | 2535 | return ret; |
2462 | } | 2536 | } |
@@ -2537,7 +2611,16 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) | |||
2537 | inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) | 2611 | inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) |
2538 | return -ENOTEMPTY; | 2612 | return -ENOTEMPTY; |
2539 | 2613 | ||
2614 | ret = btrfs_reserve_metadata_space(root, 5); | ||
2615 | if (ret) | ||
2616 | return ret; | ||
2617 | |||
2540 | trans = btrfs_start_transaction(root, 1); | 2618 | trans = btrfs_start_transaction(root, 1); |
2619 | if (IS_ERR(trans)) { | ||
2620 | btrfs_unreserve_metadata_space(root, 5); | ||
2621 | return PTR_ERR(trans); | ||
2622 | } | ||
2623 | |||
2541 | btrfs_set_trans_block_group(trans, dir); | 2624 | btrfs_set_trans_block_group(trans, dir); |
2542 | 2625 | ||
2543 | if (unlikely(inode->i_ino == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { | 2626 | if (unlikely(inode->i_ino == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { |
@@ -2560,6 +2643,7 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) | |||
2560 | out: | 2643 | out: |
2561 | nr = trans->blocks_used; | 2644 | nr = trans->blocks_used; |
2562 | ret = btrfs_end_transaction_throttle(trans, root); | 2645 | ret = btrfs_end_transaction_throttle(trans, root); |
2646 | btrfs_unreserve_metadata_space(root, 5); | ||
2563 | btrfs_btree_balance_dirty(root, nr); | 2647 | btrfs_btree_balance_dirty(root, nr); |
2564 | 2648 | ||
2565 | if (ret && !err) | 2649 | if (ret && !err) |
@@ -3000,12 +3084,22 @@ static int btrfs_truncate_page(struct address_space *mapping, loff_t from) | |||
3000 | 3084 | ||
3001 | if ((offset & (blocksize - 1)) == 0) | 3085 | if ((offset & (blocksize - 1)) == 0) |
3002 | goto out; | 3086 | goto out; |
3087 | ret = btrfs_check_data_free_space(root, inode, PAGE_CACHE_SIZE); | ||
3088 | if (ret) | ||
3089 | goto out; | ||
3090 | |||
3091 | ret = btrfs_reserve_metadata_for_delalloc(root, inode, 1); | ||
3092 | if (ret) | ||
3093 | goto out; | ||
3003 | 3094 | ||
3004 | ret = -ENOMEM; | 3095 | ret = -ENOMEM; |
3005 | again: | 3096 | again: |
3006 | page = grab_cache_page(mapping, index); | 3097 | page = grab_cache_page(mapping, index); |
3007 | if (!page) | 3098 | if (!page) { |
3099 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); | ||
3100 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
3008 | goto out; | 3101 | goto out; |
3102 | } | ||
3009 | 3103 | ||
3010 | page_start = page_offset(page); | 3104 | page_start = page_offset(page); |
3011 | page_end = page_start + PAGE_CACHE_SIZE - 1; | 3105 | page_end = page_start + PAGE_CACHE_SIZE - 1; |
@@ -3038,6 +3132,10 @@ again: | |||
3038 | goto again; | 3132 | goto again; |
3039 | } | 3133 | } |
3040 | 3134 | ||
3135 | clear_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, | ||
3136 | EXTENT_DIRTY | EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING, | ||
3137 | GFP_NOFS); | ||
3138 | |||
3041 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end); | 3139 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end); |
3042 | if (ret) { | 3140 | if (ret) { |
3043 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 3141 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); |
@@ -3056,6 +3154,9 @@ again: | |||
3056 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 3154 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); |
3057 | 3155 | ||
3058 | out_unlock: | 3156 | out_unlock: |
3157 | if (ret) | ||
3158 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); | ||
3159 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
3059 | unlock_page(page); | 3160 | unlock_page(page); |
3060 | page_cache_release(page); | 3161 | page_cache_release(page); |
3061 | out: | 3162 | out: |
@@ -3079,7 +3180,9 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) | |||
3079 | if (size <= hole_start) | 3180 | if (size <= hole_start) |
3080 | return 0; | 3181 | return 0; |
3081 | 3182 | ||
3082 | btrfs_truncate_page(inode->i_mapping, inode->i_size); | 3183 | err = btrfs_truncate_page(inode->i_mapping, inode->i_size); |
3184 | if (err) | ||
3185 | return err; | ||
3083 | 3186 | ||
3084 | while (1) { | 3187 | while (1) { |
3085 | struct btrfs_ordered_extent *ordered; | 3188 | struct btrfs_ordered_extent *ordered; |
@@ -3448,6 +3551,7 @@ static noinline void init_btrfs_i(struct inode *inode) | |||
3448 | bi->generation = 0; | 3551 | bi->generation = 0; |
3449 | bi->sequence = 0; | 3552 | bi->sequence = 0; |
3450 | bi->last_trans = 0; | 3553 | bi->last_trans = 0; |
3554 | bi->last_sub_trans = 0; | ||
3451 | bi->logged_trans = 0; | 3555 | bi->logged_trans = 0; |
3452 | bi->delalloc_bytes = 0; | 3556 | bi->delalloc_bytes = 0; |
3453 | bi->reserved_bytes = 0; | 3557 | bi->reserved_bytes = 0; |
@@ -3598,12 +3702,14 @@ static int btrfs_dentry_delete(struct dentry *dentry) | |||
3598 | { | 3702 | { |
3599 | struct btrfs_root *root; | 3703 | struct btrfs_root *root; |
3600 | 3704 | ||
3601 | if (!dentry->d_inode) | 3705 | if (!dentry->d_inode && !IS_ROOT(dentry)) |
3602 | return 0; | 3706 | dentry = dentry->d_parent; |
3603 | 3707 | ||
3604 | root = BTRFS_I(dentry->d_inode)->root; | 3708 | if (dentry->d_inode) { |
3605 | if (btrfs_root_refs(&root->root_item) == 0) | 3709 | root = BTRFS_I(dentry->d_inode)->root; |
3606 | return 1; | 3710 | if (btrfs_root_refs(&root->root_item) == 0) |
3711 | return 1; | ||
3712 | } | ||
3607 | return 0; | 3713 | return 0; |
3608 | } | 3714 | } |
3609 | 3715 | ||
@@ -4808,7 +4914,8 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
4808 | */ | 4914 | */ |
4809 | clear_extent_bit(tree, page_start, page_end, | 4915 | clear_extent_bit(tree, page_start, page_end, |
4810 | EXTENT_DIRTY | EXTENT_DELALLOC | | 4916 | EXTENT_DIRTY | EXTENT_DELALLOC | |
4811 | EXTENT_LOCKED, 1, 0, NULL, GFP_NOFS); | 4917 | EXTENT_LOCKED | EXTENT_DO_ACCOUNTING, 1, 0, |
4918 | NULL, GFP_NOFS); | ||
4812 | /* | 4919 | /* |
4813 | * whoever cleared the private bit is responsible | 4920 | * whoever cleared the private bit is responsible |
4814 | * for the finish_ordered_io | 4921 | * for the finish_ordered_io |
@@ -4821,8 +4928,8 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
4821 | lock_extent(tree, page_start, page_end, GFP_NOFS); | 4928 | lock_extent(tree, page_start, page_end, GFP_NOFS); |
4822 | } | 4929 | } |
4823 | clear_extent_bit(tree, page_start, page_end, | 4930 | clear_extent_bit(tree, page_start, page_end, |
4824 | EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC, | 4931 | EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC | |
4825 | 1, 1, NULL, GFP_NOFS); | 4932 | EXTENT_DO_ACCOUNTING, 1, 1, NULL, GFP_NOFS); |
4826 | __btrfs_releasepage(page, GFP_NOFS); | 4933 | __btrfs_releasepage(page, GFP_NOFS); |
4827 | 4934 | ||
4828 | ClearPageChecked(page); | 4935 | ClearPageChecked(page); |
@@ -4917,7 +5024,8 @@ again: | |||
4917 | * prepare_pages in the normal write path. | 5024 | * prepare_pages in the normal write path. |
4918 | */ | 5025 | */ |
4919 | clear_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, | 5026 | clear_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, |
4920 | EXTENT_DIRTY | EXTENT_DELALLOC, GFP_NOFS); | 5027 | EXTENT_DIRTY | EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING, |
5028 | GFP_NOFS); | ||
4921 | 5029 | ||
4922 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end); | 5030 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end); |
4923 | if (ret) { | 5031 | if (ret) { |
@@ -4944,7 +5052,9 @@ again: | |||
4944 | set_page_dirty(page); | 5052 | set_page_dirty(page); |
4945 | SetPageUptodate(page); | 5053 | SetPageUptodate(page); |
4946 | 5054 | ||
4947 | BTRFS_I(inode)->last_trans = root->fs_info->generation + 1; | 5055 | BTRFS_I(inode)->last_trans = root->fs_info->generation; |
5056 | BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; | ||
5057 | |||
4948 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 5058 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); |
4949 | 5059 | ||
4950 | out_unlock: | 5060 | out_unlock: |
@@ -4969,7 +5079,9 @@ static void btrfs_truncate(struct inode *inode) | |||
4969 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) | 5079 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) |
4970 | return; | 5080 | return; |
4971 | 5081 | ||
4972 | btrfs_truncate_page(inode->i_mapping, inode->i_size); | 5082 | ret = btrfs_truncate_page(inode->i_mapping, inode->i_size); |
5083 | if (ret) | ||
5084 | return; | ||
4973 | btrfs_wait_ordered_range(inode, inode->i_size & (~mask), (u64)-1); | 5085 | btrfs_wait_ordered_range(inode, inode->i_size & (~mask), (u64)-1); |
4974 | 5086 | ||
4975 | trans = btrfs_start_transaction(root, 1); | 5087 | trans = btrfs_start_transaction(root, 1); |
@@ -5064,9 +5176,12 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
5064 | if (!ei) | 5176 | if (!ei) |
5065 | return NULL; | 5177 | return NULL; |
5066 | ei->last_trans = 0; | 5178 | ei->last_trans = 0; |
5179 | ei->last_sub_trans = 0; | ||
5067 | ei->logged_trans = 0; | 5180 | ei->logged_trans = 0; |
5068 | ei->delalloc_extents = 0; | 5181 | ei->outstanding_extents = 0; |
5069 | ei->delalloc_reserved_extents = 0; | 5182 | ei->reserved_extents = 0; |
5183 | ei->root = NULL; | ||
5184 | spin_lock_init(&ei->accounting_lock); | ||
5070 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); | 5185 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); |
5071 | INIT_LIST_HEAD(&ei->i_orphan); | 5186 | INIT_LIST_HEAD(&ei->i_orphan); |
5072 | INIT_LIST_HEAD(&ei->ordered_operations); | 5187 | INIT_LIST_HEAD(&ei->ordered_operations); |
@@ -5082,6 +5197,14 @@ void btrfs_destroy_inode(struct inode *inode) | |||
5082 | WARN_ON(inode->i_data.nrpages); | 5197 | WARN_ON(inode->i_data.nrpages); |
5083 | 5198 | ||
5084 | /* | 5199 | /* |
5200 | * This can happen where we create an inode, but somebody else also | ||
5201 | * created the same inode and we need to destroy the one we already | ||
5202 | * created. | ||
5203 | */ | ||
5204 | if (!root) | ||
5205 | goto free; | ||
5206 | |||
5207 | /* | ||
5085 | * Make sure we're properly removed from the ordered operation | 5208 | * Make sure we're properly removed from the ordered operation |
5086 | * lists. | 5209 | * lists. |
5087 | */ | 5210 | */ |
@@ -5116,6 +5239,7 @@ void btrfs_destroy_inode(struct inode *inode) | |||
5116 | } | 5239 | } |
5117 | inode_tree_del(inode); | 5240 | inode_tree_del(inode); |
5118 | btrfs_drop_extent_cache(inode, 0, (u64)-1, 0); | 5241 | btrfs_drop_extent_cache(inode, 0, (u64)-1, 0); |
5242 | free: | ||
5119 | kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); | 5243 | kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); |
5120 | } | 5244 | } |
5121 | 5245 | ||
@@ -5221,11 +5345,14 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
5221 | return -ENOTEMPTY; | 5345 | return -ENOTEMPTY; |
5222 | 5346 | ||
5223 | /* | 5347 | /* |
5224 | * 2 items for dir items | 5348 | * We want to reserve the absolute worst case amount of items. So if |
5225 | * 1 item for orphan entry | 5349 | * both inodes are subvols and we need to unlink them then that would |
5226 | * 1 item for ref | 5350 | * require 4 item modifications, but if they are both normal inodes it |
5351 | * would require 5 item modifications, so we'll assume their normal | ||
5352 | * inodes. So 5 * 2 is 10, plus 1 for the new link, so 11 total items | ||
5353 | * should cover the worst case number of items we'll modify. | ||
5227 | */ | 5354 | */ |
5228 | ret = btrfs_reserve_metadata_space(root, 4); | 5355 | ret = btrfs_reserve_metadata_space(root, 11); |
5229 | if (ret) | 5356 | if (ret) |
5230 | return ret; | 5357 | return ret; |
5231 | 5358 | ||
@@ -5341,7 +5468,7 @@ out_fail: | |||
5341 | if (old_inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) | 5468 | if (old_inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) |
5342 | up_read(&root->fs_info->subvol_sem); | 5469 | up_read(&root->fs_info->subvol_sem); |
5343 | 5470 | ||
5344 | btrfs_unreserve_metadata_space(root, 4); | 5471 | btrfs_unreserve_metadata_space(root, 11); |
5345 | return ret; | 5472 | return ret; |
5346 | } | 5473 | } |
5347 | 5474 | ||
@@ -5805,6 +5932,6 @@ static const struct inode_operations btrfs_symlink_inode_operations = { | |||
5805 | .removexattr = btrfs_removexattr, | 5932 | .removexattr = btrfs_removexattr, |
5806 | }; | 5933 | }; |
5807 | 5934 | ||
5808 | struct dentry_operations btrfs_dentry_operations = { | 5935 | const struct dentry_operations btrfs_dentry_operations = { |
5809 | .d_delete = btrfs_dentry_delete, | 5936 | .d_delete = btrfs_dentry_delete, |
5810 | }; | 5937 | }; |
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 9a780c8d0ac8..cdbb054102b9 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -830,6 +830,7 @@ out_up_write: | |||
830 | out_unlock: | 830 | out_unlock: |
831 | mutex_unlock(&inode->i_mutex); | 831 | mutex_unlock(&inode->i_mutex); |
832 | if (!err) { | 832 | if (!err) { |
833 | shrink_dcache_sb(root->fs_info->sb); | ||
833 | btrfs_invalidate_inodes(dest); | 834 | btrfs_invalidate_inodes(dest); |
834 | d_delete(dentry); | 835 | d_delete(dentry); |
835 | } | 836 | } |
@@ -1122,8 +1123,10 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, | |||
1122 | datao += off - key.offset; | 1123 | datao += off - key.offset; |
1123 | datal -= off - key.offset; | 1124 | datal -= off - key.offset; |
1124 | } | 1125 | } |
1125 | if (key.offset + datao + datal > off + len) | 1126 | |
1126 | datal = off + len - key.offset - datao; | 1127 | if (key.offset + datal > off + len) |
1128 | datal = off + len - key.offset; | ||
1129 | |||
1127 | /* disko == 0 means it's a hole */ | 1130 | /* disko == 0 means it's a hole */ |
1128 | if (!disko) | 1131 | if (!disko) |
1129 | datao = 0; | 1132 | datao = 0; |
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 897fba835f89..5799bc46a309 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c | |||
@@ -306,6 +306,12 @@ int btrfs_remove_ordered_extent(struct inode *inode, | |||
306 | tree->last = NULL; | 306 | tree->last = NULL; |
307 | set_bit(BTRFS_ORDERED_COMPLETE, &entry->flags); | 307 | set_bit(BTRFS_ORDERED_COMPLETE, &entry->flags); |
308 | 308 | ||
309 | spin_lock(&BTRFS_I(inode)->accounting_lock); | ||
310 | BTRFS_I(inode)->outstanding_extents--; | ||
311 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
312 | btrfs_unreserve_metadata_for_delalloc(BTRFS_I(inode)->root, | ||
313 | inode, 1); | ||
314 | |||
309 | spin_lock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock); | 315 | spin_lock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock); |
310 | list_del_init(&entry->root_extent_list); | 316 | list_del_init(&entry->root_extent_list); |
311 | 317 | ||
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 361ad323faac..cfcc93c93a7b 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c | |||
@@ -3518,7 +3518,7 @@ int btrfs_relocate_block_group(struct btrfs_root *extent_root, u64 group_start) | |||
3518 | BUG_ON(!rc->block_group); | 3518 | BUG_ON(!rc->block_group); |
3519 | 3519 | ||
3520 | btrfs_init_workers(&rc->workers, "relocate", | 3520 | btrfs_init_workers(&rc->workers, "relocate", |
3521 | fs_info->thread_pool_size); | 3521 | fs_info->thread_pool_size, NULL); |
3522 | 3522 | ||
3523 | rc->extent_root = extent_root; | 3523 | rc->extent_root = extent_root; |
3524 | btrfs_prepare_block_group_relocation(extent_root, rc->block_group); | 3524 | btrfs_prepare_block_group_relocation(extent_root, rc->block_group); |
@@ -3701,7 +3701,7 @@ int btrfs_recover_relocation(struct btrfs_root *root) | |||
3701 | mapping_tree_init(&rc->reloc_root_tree); | 3701 | mapping_tree_init(&rc->reloc_root_tree); |
3702 | INIT_LIST_HEAD(&rc->reloc_roots); | 3702 | INIT_LIST_HEAD(&rc->reloc_roots); |
3703 | btrfs_init_workers(&rc->workers, "relocate", | 3703 | btrfs_init_workers(&rc->workers, "relocate", |
3704 | root->fs_info->thread_pool_size); | 3704 | root->fs_info->thread_pool_size, NULL); |
3705 | rc->extent_root = root->fs_info->extent_root; | 3705 | rc->extent_root = root->fs_info->extent_root; |
3706 | 3706 | ||
3707 | set_reloc_control(rc); | 3707 | set_reloc_control(rc); |
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c index 9351428f30e2..67fa2d29d663 100644 --- a/fs/btrfs/root-tree.c +++ b/fs/btrfs/root-tree.c | |||
@@ -159,7 +159,6 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root | |||
159 | write_extent_buffer(l, item, ptr, sizeof(*item)); | 159 | write_extent_buffer(l, item, ptr, sizeof(*item)); |
160 | btrfs_mark_buffer_dirty(path->nodes[0]); | 160 | btrfs_mark_buffer_dirty(path->nodes[0]); |
161 | out: | 161 | out: |
162 | btrfs_release_path(root, path); | ||
163 | btrfs_free_path(path); | 162 | btrfs_free_path(path); |
164 | return ret; | 163 | return ret; |
165 | } | 164 | } |
@@ -332,7 +331,6 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
332 | BUG_ON(refs != 0); | 331 | BUG_ON(refs != 0); |
333 | ret = btrfs_del_item(trans, root, path); | 332 | ret = btrfs_del_item(trans, root, path); |
334 | out: | 333 | out: |
335 | btrfs_release_path(root, path); | ||
336 | btrfs_free_path(path); | 334 | btrfs_free_path(path); |
337 | return ret; | 335 | return ret; |
338 | } | 336 | } |
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 9de9b2236419..752a5463bf53 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -66,7 +66,8 @@ enum { | |||
66 | Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow, | 66 | Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow, |
67 | Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, | 67 | Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, |
68 | Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, | 68 | Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, |
69 | Opt_compress, Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_err, | 69 | Opt_compress, Opt_notreelog, Opt_ratio, Opt_flushoncommit, |
70 | Opt_discard, Opt_err, | ||
70 | }; | 71 | }; |
71 | 72 | ||
72 | static match_table_t tokens = { | 73 | static match_table_t tokens = { |
@@ -88,6 +89,7 @@ static match_table_t tokens = { | |||
88 | {Opt_notreelog, "notreelog"}, | 89 | {Opt_notreelog, "notreelog"}, |
89 | {Opt_flushoncommit, "flushoncommit"}, | 90 | {Opt_flushoncommit, "flushoncommit"}, |
90 | {Opt_ratio, "metadata_ratio=%d"}, | 91 | {Opt_ratio, "metadata_ratio=%d"}, |
92 | {Opt_discard, "discard"}, | ||
91 | {Opt_err, NULL}, | 93 | {Opt_err, NULL}, |
92 | }; | 94 | }; |
93 | 95 | ||
@@ -257,6 +259,9 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
257 | info->metadata_ratio); | 259 | info->metadata_ratio); |
258 | } | 260 | } |
259 | break; | 261 | break; |
262 | case Opt_discard: | ||
263 | btrfs_set_opt(info->mount_opt, DISCARD); | ||
264 | break; | ||
260 | default: | 265 | default: |
261 | break; | 266 | break; |
262 | } | 267 | } |
@@ -344,7 +349,7 @@ static int btrfs_fill_super(struct super_block *sb, | |||
344 | sb->s_export_op = &btrfs_export_ops; | 349 | sb->s_export_op = &btrfs_export_ops; |
345 | sb->s_xattr = btrfs_xattr_handlers; | 350 | sb->s_xattr = btrfs_xattr_handlers; |
346 | sb->s_time_gran = 1; | 351 | sb->s_time_gran = 1; |
347 | #ifdef CONFIG_BTRFS_POSIX_ACL | 352 | #ifdef CONFIG_BTRFS_FS_POSIX_ACL |
348 | sb->s_flags |= MS_POSIXACL; | 353 | sb->s_flags |= MS_POSIXACL; |
349 | #endif | 354 | #endif |
350 | 355 | ||
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 0b8f36d4400a..c207e8c32c9b 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -163,8 +163,14 @@ static void wait_current_trans(struct btrfs_root *root) | |||
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | enum btrfs_trans_type { | ||
167 | TRANS_START, | ||
168 | TRANS_JOIN, | ||
169 | TRANS_USERSPACE, | ||
170 | }; | ||
171 | |||
166 | static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, | 172 | static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, |
167 | int num_blocks, int wait) | 173 | int num_blocks, int type) |
168 | { | 174 | { |
169 | struct btrfs_trans_handle *h = | 175 | struct btrfs_trans_handle *h = |
170 | kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS); | 176 | kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS); |
@@ -172,7 +178,8 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, | |||
172 | 178 | ||
173 | mutex_lock(&root->fs_info->trans_mutex); | 179 | mutex_lock(&root->fs_info->trans_mutex); |
174 | if (!root->fs_info->log_root_recovering && | 180 | if (!root->fs_info->log_root_recovering && |
175 | ((wait == 1 && !root->fs_info->open_ioctl_trans) || wait == 2)) | 181 | ((type == TRANS_START && !root->fs_info->open_ioctl_trans) || |
182 | type == TRANS_USERSPACE)) | ||
176 | wait_current_trans(root); | 183 | wait_current_trans(root); |
177 | ret = join_transaction(root); | 184 | ret = join_transaction(root); |
178 | BUG_ON(ret); | 185 | BUG_ON(ret); |
@@ -186,7 +193,7 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, | |||
186 | h->alloc_exclude_start = 0; | 193 | h->alloc_exclude_start = 0; |
187 | h->delayed_ref_updates = 0; | 194 | h->delayed_ref_updates = 0; |
188 | 195 | ||
189 | if (!current->journal_info) | 196 | if (!current->journal_info && type != TRANS_USERSPACE) |
190 | current->journal_info = h; | 197 | current->journal_info = h; |
191 | 198 | ||
192 | root->fs_info->running_transaction->use_count++; | 199 | root->fs_info->running_transaction->use_count++; |
@@ -198,18 +205,18 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, | |||
198 | struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, | 205 | struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, |
199 | int num_blocks) | 206 | int num_blocks) |
200 | { | 207 | { |
201 | return start_transaction(root, num_blocks, 1); | 208 | return start_transaction(root, num_blocks, TRANS_START); |
202 | } | 209 | } |
203 | struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root, | 210 | struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root, |
204 | int num_blocks) | 211 | int num_blocks) |
205 | { | 212 | { |
206 | return start_transaction(root, num_blocks, 0); | 213 | return start_transaction(root, num_blocks, TRANS_JOIN); |
207 | } | 214 | } |
208 | 215 | ||
209 | struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *r, | 216 | struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *r, |
210 | int num_blocks) | 217 | int num_blocks) |
211 | { | 218 | { |
212 | return start_transaction(r, num_blocks, 2); | 219 | return start_transaction(r, num_blocks, TRANS_USERSPACE); |
213 | } | 220 | } |
214 | 221 | ||
215 | /* wait for a transaction commit to be fully complete */ | 222 | /* wait for a transaction commit to be fully complete */ |
@@ -344,10 +351,10 @@ int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans, | |||
344 | /* | 351 | /* |
345 | * when btree blocks are allocated, they have some corresponding bits set for | 352 | * when btree blocks are allocated, they have some corresponding bits set for |
346 | * them in one of two extent_io trees. This is used to make sure all of | 353 | * them in one of two extent_io trees. This is used to make sure all of |
347 | * those extents are on disk for transaction or log commit | 354 | * those extents are sent to disk but does not wait on them |
348 | */ | 355 | */ |
349 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | 356 | int btrfs_write_marked_extents(struct btrfs_root *root, |
350 | struct extent_io_tree *dirty_pages) | 357 | struct extent_io_tree *dirty_pages) |
351 | { | 358 | { |
352 | int ret; | 359 | int ret; |
353 | int err = 0; | 360 | int err = 0; |
@@ -394,6 +401,29 @@ int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | |||
394 | page_cache_release(page); | 401 | page_cache_release(page); |
395 | } | 402 | } |
396 | } | 403 | } |
404 | if (err) | ||
405 | werr = err; | ||
406 | return werr; | ||
407 | } | ||
408 | |||
409 | /* | ||
410 | * when btree blocks are allocated, they have some corresponding bits set for | ||
411 | * them in one of two extent_io trees. This is used to make sure all of | ||
412 | * those extents are on disk for transaction or log commit. We wait | ||
413 | * on all the pages and clear them from the dirty pages state tree | ||
414 | */ | ||
415 | int btrfs_wait_marked_extents(struct btrfs_root *root, | ||
416 | struct extent_io_tree *dirty_pages) | ||
417 | { | ||
418 | int ret; | ||
419 | int err = 0; | ||
420 | int werr = 0; | ||
421 | struct page *page; | ||
422 | struct inode *btree_inode = root->fs_info->btree_inode; | ||
423 | u64 start = 0; | ||
424 | u64 end; | ||
425 | unsigned long index; | ||
426 | |||
397 | while (1) { | 427 | while (1) { |
398 | ret = find_first_extent_bit(dirty_pages, 0, &start, &end, | 428 | ret = find_first_extent_bit(dirty_pages, 0, &start, &end, |
399 | EXTENT_DIRTY); | 429 | EXTENT_DIRTY); |
@@ -424,6 +454,22 @@ int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | |||
424 | return werr; | 454 | return werr; |
425 | } | 455 | } |
426 | 456 | ||
457 | /* | ||
458 | * when btree blocks are allocated, they have some corresponding bits set for | ||
459 | * them in one of two extent_io trees. This is used to make sure all of | ||
460 | * those extents are on disk for transaction or log commit | ||
461 | */ | ||
462 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | ||
463 | struct extent_io_tree *dirty_pages) | ||
464 | { | ||
465 | int ret; | ||
466 | int ret2; | ||
467 | |||
468 | ret = btrfs_write_marked_extents(root, dirty_pages); | ||
469 | ret2 = btrfs_wait_marked_extents(root, dirty_pages); | ||
470 | return ret || ret2; | ||
471 | } | ||
472 | |||
427 | int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, | 473 | int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, |
428 | struct btrfs_root *root) | 474 | struct btrfs_root *root) |
429 | { | 475 | { |
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index 663c67404918..d4e3e7a6938c 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h | |||
@@ -79,6 +79,7 @@ static inline void btrfs_set_inode_last_trans(struct btrfs_trans_handle *trans, | |||
79 | struct inode *inode) | 79 | struct inode *inode) |
80 | { | 80 | { |
81 | BTRFS_I(inode)->last_trans = trans->transaction->transid; | 81 | BTRFS_I(inode)->last_trans = trans->transaction->transid; |
82 | BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; | ||
82 | } | 83 | } |
83 | 84 | ||
84 | int btrfs_end_transaction(struct btrfs_trans_handle *trans, | 85 | int btrfs_end_transaction(struct btrfs_trans_handle *trans, |
@@ -107,5 +108,9 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, | |||
107 | struct btrfs_root *root); | 108 | struct btrfs_root *root); |
108 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | 109 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, |
109 | struct extent_io_tree *dirty_pages); | 110 | struct extent_io_tree *dirty_pages); |
111 | int btrfs_write_marked_extents(struct btrfs_root *root, | ||
112 | struct extent_io_tree *dirty_pages); | ||
113 | int btrfs_wait_marked_extents(struct btrfs_root *root, | ||
114 | struct extent_io_tree *dirty_pages); | ||
110 | int btrfs_transaction_in_commit(struct btrfs_fs_info *info); | 115 | int btrfs_transaction_in_commit(struct btrfs_fs_info *info); |
111 | #endif | 116 | #endif |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 7827841b55cb..741666a7676a 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -137,11 +137,20 @@ static int start_log_trans(struct btrfs_trans_handle *trans, | |||
137 | 137 | ||
138 | mutex_lock(&root->log_mutex); | 138 | mutex_lock(&root->log_mutex); |
139 | if (root->log_root) { | 139 | if (root->log_root) { |
140 | if (!root->log_start_pid) { | ||
141 | root->log_start_pid = current->pid; | ||
142 | root->log_multiple_pids = false; | ||
143 | } else if (root->log_start_pid != current->pid) { | ||
144 | root->log_multiple_pids = true; | ||
145 | } | ||
146 | |||
140 | root->log_batch++; | 147 | root->log_batch++; |
141 | atomic_inc(&root->log_writers); | 148 | atomic_inc(&root->log_writers); |
142 | mutex_unlock(&root->log_mutex); | 149 | mutex_unlock(&root->log_mutex); |
143 | return 0; | 150 | return 0; |
144 | } | 151 | } |
152 | root->log_multiple_pids = false; | ||
153 | root->log_start_pid = current->pid; | ||
145 | mutex_lock(&root->fs_info->tree_log_mutex); | 154 | mutex_lock(&root->fs_info->tree_log_mutex); |
146 | if (!root->fs_info->log_root_tree) { | 155 | if (!root->fs_info->log_root_tree) { |
147 | ret = btrfs_init_log_root_tree(trans, root->fs_info); | 156 | ret = btrfs_init_log_root_tree(trans, root->fs_info); |
@@ -1971,6 +1980,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
1971 | int ret; | 1980 | int ret; |
1972 | struct btrfs_root *log = root->log_root; | 1981 | struct btrfs_root *log = root->log_root; |
1973 | struct btrfs_root *log_root_tree = root->fs_info->log_root_tree; | 1982 | struct btrfs_root *log_root_tree = root->fs_info->log_root_tree; |
1983 | u64 log_transid = 0; | ||
1974 | 1984 | ||
1975 | mutex_lock(&root->log_mutex); | 1985 | mutex_lock(&root->log_mutex); |
1976 | index1 = root->log_transid % 2; | 1986 | index1 = root->log_transid % 2; |
@@ -1987,10 +1997,11 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
1987 | 1997 | ||
1988 | while (1) { | 1998 | while (1) { |
1989 | unsigned long batch = root->log_batch; | 1999 | unsigned long batch = root->log_batch; |
1990 | mutex_unlock(&root->log_mutex); | 2000 | if (root->log_multiple_pids) { |
1991 | schedule_timeout_uninterruptible(1); | 2001 | mutex_unlock(&root->log_mutex); |
1992 | mutex_lock(&root->log_mutex); | 2002 | schedule_timeout_uninterruptible(1); |
1993 | 2003 | mutex_lock(&root->log_mutex); | |
2004 | } | ||
1994 | wait_for_writer(trans, root); | 2005 | wait_for_writer(trans, root); |
1995 | if (batch == root->log_batch) | 2006 | if (batch == root->log_batch) |
1996 | break; | 2007 | break; |
@@ -2003,14 +2014,19 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2003 | goto out; | 2014 | goto out; |
2004 | } | 2015 | } |
2005 | 2016 | ||
2006 | ret = btrfs_write_and_wait_marked_extents(log, &log->dirty_log_pages); | 2017 | /* we start IO on all the marked extents here, but we don't actually |
2018 | * wait for them until later. | ||
2019 | */ | ||
2020 | ret = btrfs_write_marked_extents(log, &log->dirty_log_pages); | ||
2007 | BUG_ON(ret); | 2021 | BUG_ON(ret); |
2008 | 2022 | ||
2009 | btrfs_set_root_node(&log->root_item, log->node); | 2023 | btrfs_set_root_node(&log->root_item, log->node); |
2010 | 2024 | ||
2011 | root->log_batch = 0; | 2025 | root->log_batch = 0; |
2026 | log_transid = root->log_transid; | ||
2012 | root->log_transid++; | 2027 | root->log_transid++; |
2013 | log->log_transid = root->log_transid; | 2028 | log->log_transid = root->log_transid; |
2029 | root->log_start_pid = 0; | ||
2014 | smp_mb(); | 2030 | smp_mb(); |
2015 | /* | 2031 | /* |
2016 | * log tree has been flushed to disk, new modifications of | 2032 | * log tree has been flushed to disk, new modifications of |
@@ -2036,6 +2052,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2036 | 2052 | ||
2037 | index2 = log_root_tree->log_transid % 2; | 2053 | index2 = log_root_tree->log_transid % 2; |
2038 | if (atomic_read(&log_root_tree->log_commit[index2])) { | 2054 | if (atomic_read(&log_root_tree->log_commit[index2])) { |
2055 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | ||
2039 | wait_log_commit(trans, log_root_tree, | 2056 | wait_log_commit(trans, log_root_tree, |
2040 | log_root_tree->log_transid); | 2057 | log_root_tree->log_transid); |
2041 | mutex_unlock(&log_root_tree->log_mutex); | 2058 | mutex_unlock(&log_root_tree->log_mutex); |
@@ -2055,6 +2072,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2055 | * check the full commit flag again | 2072 | * check the full commit flag again |
2056 | */ | 2073 | */ |
2057 | if (root->fs_info->last_trans_log_full_commit == trans->transid) { | 2074 | if (root->fs_info->last_trans_log_full_commit == trans->transid) { |
2075 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | ||
2058 | mutex_unlock(&log_root_tree->log_mutex); | 2076 | mutex_unlock(&log_root_tree->log_mutex); |
2059 | ret = -EAGAIN; | 2077 | ret = -EAGAIN; |
2060 | goto out_wake_log_root; | 2078 | goto out_wake_log_root; |
@@ -2063,6 +2081,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2063 | ret = btrfs_write_and_wait_marked_extents(log_root_tree, | 2081 | ret = btrfs_write_and_wait_marked_extents(log_root_tree, |
2064 | &log_root_tree->dirty_log_pages); | 2082 | &log_root_tree->dirty_log_pages); |
2065 | BUG_ON(ret); | 2083 | BUG_ON(ret); |
2084 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | ||
2066 | 2085 | ||
2067 | btrfs_set_super_log_root(&root->fs_info->super_for_commit, | 2086 | btrfs_set_super_log_root(&root->fs_info->super_for_commit, |
2068 | log_root_tree->node->start); | 2087 | log_root_tree->node->start); |
@@ -2082,9 +2101,14 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2082 | * the running transaction open, so a full commit can't hop | 2101 | * the running transaction open, so a full commit can't hop |
2083 | * in and cause problems either. | 2102 | * in and cause problems either. |
2084 | */ | 2103 | */ |
2085 | write_ctree_super(trans, root->fs_info->tree_root, 2); | 2104 | write_ctree_super(trans, root->fs_info->tree_root, 1); |
2086 | ret = 0; | 2105 | ret = 0; |
2087 | 2106 | ||
2107 | mutex_lock(&root->log_mutex); | ||
2108 | if (root->last_log_commit < log_transid) | ||
2109 | root->last_log_commit = log_transid; | ||
2110 | mutex_unlock(&root->log_mutex); | ||
2111 | |||
2088 | out_wake_log_root: | 2112 | out_wake_log_root: |
2089 | atomic_set(&log_root_tree->log_commit[index2], 0); | 2113 | atomic_set(&log_root_tree->log_commit[index2], 0); |
2090 | smp_mb(); | 2114 | smp_mb(); |
@@ -2852,6 +2876,21 @@ out: | |||
2852 | return ret; | 2876 | return ret; |
2853 | } | 2877 | } |
2854 | 2878 | ||
2879 | static int inode_in_log(struct btrfs_trans_handle *trans, | ||
2880 | struct inode *inode) | ||
2881 | { | ||
2882 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
2883 | int ret = 0; | ||
2884 | |||
2885 | mutex_lock(&root->log_mutex); | ||
2886 | if (BTRFS_I(inode)->logged_trans == trans->transid && | ||
2887 | BTRFS_I(inode)->last_sub_trans <= root->last_log_commit) | ||
2888 | ret = 1; | ||
2889 | mutex_unlock(&root->log_mutex); | ||
2890 | return ret; | ||
2891 | } | ||
2892 | |||
2893 | |||
2855 | /* | 2894 | /* |
2856 | * helper function around btrfs_log_inode to make sure newly created | 2895 | * helper function around btrfs_log_inode to make sure newly created |
2857 | * parent directories also end up in the log. A minimal inode and backref | 2896 | * parent directories also end up in the log. A minimal inode and backref |
@@ -2891,6 +2930,11 @@ int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, | |||
2891 | if (ret) | 2930 | if (ret) |
2892 | goto end_no_trans; | 2931 | goto end_no_trans; |
2893 | 2932 | ||
2933 | if (inode_in_log(trans, inode)) { | ||
2934 | ret = BTRFS_NO_LOG_SYNC; | ||
2935 | goto end_no_trans; | ||
2936 | } | ||
2937 | |||
2894 | start_log_trans(trans, root); | 2938 | start_log_trans(trans, root); |
2895 | 2939 | ||
2896 | ret = btrfs_log_inode(trans, root, inode, inode_only); | 2940 | ret = btrfs_log_inode(trans, root, inode, inode_only); |
diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h index d09c7609e16b..0776eacb5083 100644 --- a/fs/btrfs/tree-log.h +++ b/fs/btrfs/tree-log.h | |||
@@ -19,6 +19,9 @@ | |||
19 | #ifndef __TREE_LOG_ | 19 | #ifndef __TREE_LOG_ |
20 | #define __TREE_LOG_ | 20 | #define __TREE_LOG_ |
21 | 21 | ||
22 | /* return value for btrfs_log_dentry_safe that means we don't need to log it at all */ | ||
23 | #define BTRFS_NO_LOG_SYNC 256 | ||
24 | |||
22 | int btrfs_sync_log(struct btrfs_trans_handle *trans, | 25 | int btrfs_sync_log(struct btrfs_trans_handle *trans, |
23 | struct btrfs_root *root); | 26 | struct btrfs_root *root); |
24 | int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root); | 27 | int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root); |
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c index b0fc93f95fd0..b6dd5967c48a 100644 --- a/fs/btrfs/xattr.c +++ b/fs/btrfs/xattr.c | |||
@@ -260,7 +260,7 @@ err: | |||
260 | * attributes are handled directly. | 260 | * attributes are handled directly. |
261 | */ | 261 | */ |
262 | struct xattr_handler *btrfs_xattr_handlers[] = { | 262 | struct xattr_handler *btrfs_xattr_handlers[] = { |
263 | #ifdef CONFIG_BTRFS_POSIX_ACL | 263 | #ifdef CONFIG_BTRFS_FS_POSIX_ACL |
264 | &btrfs_xattr_acl_access_handler, | 264 | &btrfs_xattr_acl_access_handler, |
265 | &btrfs_xattr_acl_default_handler, | 265 | &btrfs_xattr_acl_default_handler, |
266 | #endif | 266 | #endif |
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 6928c24d1d42..5646727e33f5 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h | |||
@@ -388,4 +388,5 @@ extern int CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon, | |||
388 | const struct nls_table *nls_codepage, int remap_special_chars); | 388 | const struct nls_table *nls_codepage, int remap_special_chars); |
389 | extern int CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon, | 389 | extern int CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon, |
390 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask); | 390 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask); |
391 | extern void cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb); | ||
391 | #endif /* _CIFSPROTO_H */ | 392 | #endif /* _CIFSPROTO_H */ |
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 43003e0bef18..63ea83ff687f 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -1577,7 +1577,8 @@ cifs_get_tcp_session(struct smb_vol *volume_info) | |||
1577 | 1577 | ||
1578 | out_err: | 1578 | out_err: |
1579 | if (tcp_ses) { | 1579 | if (tcp_ses) { |
1580 | kfree(tcp_ses->hostname); | 1580 | if (!IS_ERR(tcp_ses->hostname)) |
1581 | kfree(tcp_ses->hostname); | ||
1581 | if (tcp_ses->ssocket) | 1582 | if (tcp_ses->ssocket) |
1582 | sock_release(tcp_ses->ssocket); | 1583 | sock_release(tcp_ses->ssocket); |
1583 | kfree(tcp_ses); | 1584 | kfree(tcp_ses); |
@@ -2219,16 +2220,8 @@ is_path_accessible(int xid, struct cifsTconInfo *tcon, | |||
2219 | struct cifs_sb_info *cifs_sb, const char *full_path) | 2220 | struct cifs_sb_info *cifs_sb, const char *full_path) |
2220 | { | 2221 | { |
2221 | int rc; | 2222 | int rc; |
2222 | __u64 inode_num; | ||
2223 | FILE_ALL_INFO *pfile_info; | 2223 | FILE_ALL_INFO *pfile_info; |
2224 | 2224 | ||
2225 | rc = CIFSGetSrvInodeNumber(xid, tcon, full_path, &inode_num, | ||
2226 | cifs_sb->local_nls, | ||
2227 | cifs_sb->mnt_cifs_flags & | ||
2228 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
2229 | if (rc != -EOPNOTSUPP) | ||
2230 | return rc; | ||
2231 | |||
2232 | pfile_info = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); | 2225 | pfile_info = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); |
2233 | if (pfile_info == NULL) | 2226 | if (pfile_info == NULL) |
2234 | return -ENOMEM; | 2227 | return -ENOMEM; |
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 5e2492535daa..cababd8a52df 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c | |||
@@ -512,13 +512,10 @@ int cifs_get_inode_info(struct inode **pinode, | |||
512 | cifs_sb->local_nls, | 512 | cifs_sb->local_nls, |
513 | cifs_sb->mnt_cifs_flags & | 513 | cifs_sb->mnt_cifs_flags & |
514 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 514 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
515 | if (rc1) { | 515 | if (rc1 || !fattr.cf_uniqueid) { |
516 | cFYI(1, ("GetSrvInodeNum rc %d", rc1)); | 516 | cFYI(1, ("GetSrvInodeNum rc %d", rc1)); |
517 | fattr.cf_uniqueid = iunique(sb, ROOT_I); | 517 | fattr.cf_uniqueid = iunique(sb, ROOT_I); |
518 | /* disable serverino if call not supported */ | 518 | cifs_autodisable_serverino(cifs_sb); |
519 | if (rc1 == -EINVAL) | ||
520 | cifs_sb->mnt_cifs_flags &= | ||
521 | ~CIFS_MOUNT_SERVER_INUM; | ||
522 | } | 519 | } |
523 | } else { | 520 | } else { |
524 | fattr.cf_uniqueid = iunique(sb, ROOT_I); | 521 | fattr.cf_uniqueid = iunique(sb, ROOT_I); |
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index 0241b25ac33f..d27d4ec6579b 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c | |||
@@ -715,3 +715,17 @@ cifsConvertToUCS(__le16 *target, const char *source, int maxlen, | |||
715 | ctoUCS_out: | 715 | ctoUCS_out: |
716 | return i; | 716 | return i; |
717 | } | 717 | } |
718 | |||
719 | void | ||
720 | cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb) | ||
721 | { | ||
722 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { | ||
723 | cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM; | ||
724 | cERROR(1, ("Autodisabling the use of server inode numbers on " | ||
725 | "%s. This server doesn't seem to support them " | ||
726 | "properly. Hardlinks will not be recognized on this " | ||
727 | "mount. Consider mounting with the \"noserverino\" " | ||
728 | "option to silence this message.", | ||
729 | cifs_sb->tcon->treeName)); | ||
730 | } | ||
731 | } | ||
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c index 1f098ca71636..f84062f9a985 100644 --- a/fs/cifs/readdir.c +++ b/fs/cifs/readdir.c | |||
@@ -727,11 +727,12 @@ static int cifs_filldir(char *pfindEntry, struct file *file, filldir_t filldir, | |||
727 | cifs_dir_info_to_fattr(&fattr, (FILE_DIRECTORY_INFO *) | 727 | cifs_dir_info_to_fattr(&fattr, (FILE_DIRECTORY_INFO *) |
728 | pfindEntry, cifs_sb); | 728 | pfindEntry, cifs_sb); |
729 | 729 | ||
730 | /* FIXME: make _to_fattr functions fill this out */ | 730 | if (inum && (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)) { |
731 | if (pCifsF->srch_inf.info_level == SMB_FIND_FILE_ID_FULL_DIR_INFO) | ||
732 | fattr.cf_uniqueid = inum; | 731 | fattr.cf_uniqueid = inum; |
733 | else | 732 | } else { |
734 | fattr.cf_uniqueid = iunique(sb, ROOT_I); | 733 | fattr.cf_uniqueid = iunique(sb, ROOT_I); |
734 | cifs_autodisable_serverino(cifs_sb); | ||
735 | } | ||
735 | 736 | ||
736 | ino = cifs_uniqueid_to_ino_t(fattr.cf_uniqueid); | 737 | ino = cifs_uniqueid_to_ino_t(fattr.cf_uniqueid); |
737 | tmp_dentry = cifs_readdir_lookup(file->f_dentry, &qstring, &fattr); | 738 | tmp_dentry = cifs_readdir_lookup(file->f_dentry, &qstring, &fattr); |
diff --git a/fs/compat.c b/fs/compat.c index d576b552e8e2..6c19040ffeef 100644 --- a/fs/compat.c +++ b/fs/compat.c | |||
@@ -1532,6 +1532,8 @@ int compat_do_execve(char * filename, | |||
1532 | if (retval < 0) | 1532 | if (retval < 0) |
1533 | goto out; | 1533 | goto out; |
1534 | 1534 | ||
1535 | current->stack_start = current->mm->start_stack; | ||
1536 | |||
1535 | /* execve succeeded */ | 1537 | /* execve succeeded */ |
1536 | current->fs->in_exec = 0; | 1538 | current->fs->in_exec = 0; |
1537 | current->in_execve = 0; | 1539 | current->in_execve = 0; |
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c index cacf8a83e394..229e72218165 100644 --- a/fs/compat_ioctl.c +++ b/fs/compat_ioctl.c | |||
@@ -1199,7 +1199,7 @@ struct space_resv_32 { | |||
1199 | /* just account for different alignment */ | 1199 | /* just account for different alignment */ |
1200 | static int compat_ioctl_preallocate(struct file *file, unsigned long arg) | 1200 | static int compat_ioctl_preallocate(struct file *file, unsigned long arg) |
1201 | { | 1201 | { |
1202 | struct space_resv_32 __user *p32 = (void __user *)arg; | 1202 | struct space_resv_32 __user *p32 = compat_ptr(arg); |
1203 | struct space_resv __user *p = compat_alloc_user_space(sizeof(*p)); | 1203 | struct space_resv __user *p = compat_alloc_user_space(sizeof(*p)); |
1204 | 1204 | ||
1205 | if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) || | 1205 | if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) || |
@@ -2063,7 +2063,7 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, | |||
2063 | #else | 2063 | #else |
2064 | case FS_IOC_RESVSP: | 2064 | case FS_IOC_RESVSP: |
2065 | case FS_IOC_RESVSP64: | 2065 | case FS_IOC_RESVSP64: |
2066 | error = ioctl_preallocate(filp, (void __user *)arg); | 2066 | error = ioctl_preallocate(filp, compat_ptr(arg)); |
2067 | goto out_fput; | 2067 | goto out_fput; |
2068 | #endif | 2068 | #endif |
2069 | 2069 | ||
diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index 240cef14fe58..70736eb4b516 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c | |||
@@ -316,6 +316,10 @@ int dlm_lowcomms_connect_node(int nodeid) | |||
316 | { | 316 | { |
317 | struct connection *con; | 317 | struct connection *con; |
318 | 318 | ||
319 | /* with sctp there's no connecting without sending */ | ||
320 | if (dlm_config.ci_protocol != 0) | ||
321 | return 0; | ||
322 | |||
319 | if (nodeid == dlm_our_nodeid()) | 323 | if (nodeid == dlm_our_nodeid()) |
320 | return 0; | 324 | return 0; |
321 | 325 | ||
@@ -455,9 +459,9 @@ static void process_sctp_notification(struct connection *con, | |||
455 | int prim_len, ret; | 459 | int prim_len, ret; |
456 | int addr_len; | 460 | int addr_len; |
457 | struct connection *new_con; | 461 | struct connection *new_con; |
458 | struct file *file; | ||
459 | sctp_peeloff_arg_t parg; | 462 | sctp_peeloff_arg_t parg; |
460 | int parglen = sizeof(parg); | 463 | int parglen = sizeof(parg); |
464 | int err; | ||
461 | 465 | ||
462 | /* | 466 | /* |
463 | * We get this before any data for an association. | 467 | * We get this before any data for an association. |
@@ -512,19 +516,22 @@ static void process_sctp_notification(struct connection *con, | |||
512 | ret = kernel_getsockopt(con->sock, IPPROTO_SCTP, | 516 | ret = kernel_getsockopt(con->sock, IPPROTO_SCTP, |
513 | SCTP_SOCKOPT_PEELOFF, | 517 | SCTP_SOCKOPT_PEELOFF, |
514 | (void *)&parg, &parglen); | 518 | (void *)&parg, &parglen); |
515 | if (ret) { | 519 | if (ret < 0) { |
516 | log_print("Can't peel off a socket for " | 520 | log_print("Can't peel off a socket for " |
517 | "connection %d to node %d: err=%d\n", | 521 | "connection %d to node %d: err=%d", |
518 | parg.associd, nodeid, ret); | 522 | parg.associd, nodeid, ret); |
523 | return; | ||
524 | } | ||
525 | new_con->sock = sockfd_lookup(parg.sd, &err); | ||
526 | if (!new_con->sock) { | ||
527 | log_print("sockfd_lookup error %d", err); | ||
528 | return; | ||
519 | } | 529 | } |
520 | file = fget(parg.sd); | ||
521 | new_con->sock = SOCKET_I(file->f_dentry->d_inode); | ||
522 | add_sock(new_con->sock, new_con); | 530 | add_sock(new_con->sock, new_con); |
523 | fput(file); | 531 | sockfd_put(new_con->sock); |
524 | put_unused_fd(parg.sd); | ||
525 | 532 | ||
526 | log_print("got new/restarted association %d nodeid %d", | 533 | log_print("connecting to %d sctp association %d", |
527 | (int)sn->sn_assoc_change.sac_assoc_id, nodeid); | 534 | nodeid, (int)sn->sn_assoc_change.sac_assoc_id); |
528 | 535 | ||
529 | /* Send any pending writes */ | 536 | /* Send any pending writes */ |
530 | clear_bit(CF_CONNECT_PENDING, &new_con->flags); | 537 | clear_bit(CF_CONNECT_PENDING, &new_con->flags); |
@@ -837,8 +844,6 @@ static void sctp_init_assoc(struct connection *con) | |||
837 | if (con->retries++ > MAX_CONNECT_RETRIES) | 844 | if (con->retries++ > MAX_CONNECT_RETRIES) |
838 | return; | 845 | return; |
839 | 846 | ||
840 | log_print("Initiating association with node %d", con->nodeid); | ||
841 | |||
842 | if (nodeid_to_addr(con->nodeid, (struct sockaddr *)&rem_addr)) { | 847 | if (nodeid_to_addr(con->nodeid, (struct sockaddr *)&rem_addr)) { |
843 | log_print("no address for nodeid %d", con->nodeid); | 848 | log_print("no address for nodeid %d", con->nodeid); |
844 | return; | 849 | return; |
@@ -855,11 +860,14 @@ static void sctp_init_assoc(struct connection *con) | |||
855 | outmessage.msg_flags = MSG_EOR; | 860 | outmessage.msg_flags = MSG_EOR; |
856 | 861 | ||
857 | spin_lock(&con->writequeue_lock); | 862 | spin_lock(&con->writequeue_lock); |
858 | e = list_entry(con->writequeue.next, struct writequeue_entry, | ||
859 | list); | ||
860 | 863 | ||
861 | BUG_ON((struct list_head *) e == &con->writequeue); | 864 | if (list_empty(&con->writequeue)) { |
865 | spin_unlock(&con->writequeue_lock); | ||
866 | log_print("writequeue empty for nodeid %d", con->nodeid); | ||
867 | return; | ||
868 | } | ||
862 | 869 | ||
870 | e = list_first_entry(&con->writequeue, struct writequeue_entry, list); | ||
863 | len = e->len; | 871 | len = e->len; |
864 | offset = e->offset; | 872 | offset = e->offset; |
865 | spin_unlock(&con->writequeue_lock); | 873 | spin_unlock(&con->writequeue_lock); |
diff --git a/fs/ecryptfs/Kconfig b/fs/ecryptfs/Kconfig index 8aadb99b7634..1cd6d9d3e29a 100644 --- a/fs/ecryptfs/Kconfig +++ b/fs/ecryptfs/Kconfig | |||
@@ -1,8 +1,9 @@ | |||
1 | config ECRYPT_FS | 1 | config ECRYPT_FS |
2 | tristate "eCrypt filesystem layer support (EXPERIMENTAL)" | 2 | tristate "eCrypt filesystem layer support (EXPERIMENTAL)" |
3 | depends on EXPERIMENTAL && KEYS && NET | 3 | depends on EXPERIMENTAL && KEYS && CRYPTO |
4 | select CRYPTO_ECB | 4 | select CRYPTO_ECB |
5 | select CRYPTO_CBC | 5 | select CRYPTO_CBC |
6 | select CRYPTO_MD5 | ||
6 | help | 7 | help |
7 | Encrypted filesystem that operates on the VFS layer. See | 8 | Encrypted filesystem that operates on the VFS layer. See |
8 | <file:Documentation/filesystems/ecryptfs.txt> to learn more about | 9 | <file:Documentation/filesystems/ecryptfs.txt> to learn more about |
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index 101fe4c7b1ee..c6ac85d6c701 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/key.h> | 35 | #include <linux/key.h> |
36 | #include <linux/parser.h> | 36 | #include <linux/parser.h> |
37 | #include <linux/fs_stack.h> | 37 | #include <linux/fs_stack.h> |
38 | #include <linux/ima.h> | ||
38 | #include "ecryptfs_kernel.h" | 39 | #include "ecryptfs_kernel.h" |
39 | 40 | ||
40 | /** | 41 | /** |
@@ -118,6 +119,7 @@ int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry) | |||
118 | const struct cred *cred = current_cred(); | 119 | const struct cred *cred = current_cred(); |
119 | struct ecryptfs_inode_info *inode_info = | 120 | struct ecryptfs_inode_info *inode_info = |
120 | ecryptfs_inode_to_private(ecryptfs_dentry->d_inode); | 121 | ecryptfs_inode_to_private(ecryptfs_dentry->d_inode); |
122 | int opened_lower_file = 0; | ||
121 | int rc = 0; | 123 | int rc = 0; |
122 | 124 | ||
123 | mutex_lock(&inode_info->lower_file_mutex); | 125 | mutex_lock(&inode_info->lower_file_mutex); |
@@ -134,9 +136,12 @@ int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry) | |||
134 | "for lower_dentry [0x%p] and lower_mnt [0x%p]; " | 136 | "for lower_dentry [0x%p] and lower_mnt [0x%p]; " |
135 | "rc = [%d]\n", lower_dentry, lower_mnt, rc); | 137 | "rc = [%d]\n", lower_dentry, lower_mnt, rc); |
136 | inode_info->lower_file = NULL; | 138 | inode_info->lower_file = NULL; |
137 | } | 139 | } else |
140 | opened_lower_file = 1; | ||
138 | } | 141 | } |
139 | mutex_unlock(&inode_info->lower_file_mutex); | 142 | mutex_unlock(&inode_info->lower_file_mutex); |
143 | if (opened_lower_file) | ||
144 | ima_counts_get(inode_info->lower_file); | ||
140 | return rc; | 145 | return rc; |
141 | } | 146 | } |
142 | 147 | ||
@@ -624,10 +624,8 @@ int setup_arg_pages(struct linux_binprm *bprm, | |||
624 | /* Move stack pages down in memory. */ | 624 | /* Move stack pages down in memory. */ |
625 | if (stack_shift) { | 625 | if (stack_shift) { |
626 | ret = shift_arg_pages(vma, stack_shift); | 626 | ret = shift_arg_pages(vma, stack_shift); |
627 | if (ret) { | 627 | if (ret) |
628 | up_write(&mm->mmap_sem); | 628 | goto out_unlock; |
629 | return ret; | ||
630 | } | ||
631 | } | 629 | } |
632 | 630 | ||
633 | #ifdef CONFIG_STACK_GROWSUP | 631 | #ifdef CONFIG_STACK_GROWSUP |
@@ -641,7 +639,7 @@ int setup_arg_pages(struct linux_binprm *bprm, | |||
641 | 639 | ||
642 | out_unlock: | 640 | out_unlock: |
643 | up_write(&mm->mmap_sem); | 641 | up_write(&mm->mmap_sem); |
644 | return 0; | 642 | return ret; |
645 | } | 643 | } |
646 | EXPORT_SYMBOL(setup_arg_pages); | 644 | EXPORT_SYMBOL(setup_arg_pages); |
647 | 645 | ||
diff --git a/fs/ext3/fsync.c b/fs/ext3/fsync.c index 451d166bbe93..8209f266e9ad 100644 --- a/fs/ext3/fsync.c +++ b/fs/ext3/fsync.c | |||
@@ -46,19 +46,21 @@ | |||
46 | int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync) | 46 | int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync) |
47 | { | 47 | { |
48 | struct inode *inode = dentry->d_inode; | 48 | struct inode *inode = dentry->d_inode; |
49 | struct ext3_inode_info *ei = EXT3_I(inode); | ||
50 | journal_t *journal = EXT3_SB(inode->i_sb)->s_journal; | ||
49 | int ret = 0; | 51 | int ret = 0; |
52 | tid_t commit_tid; | ||
53 | |||
54 | if (inode->i_sb->s_flags & MS_RDONLY) | ||
55 | return 0; | ||
50 | 56 | ||
51 | J_ASSERT(ext3_journal_current_handle() == NULL); | 57 | J_ASSERT(ext3_journal_current_handle() == NULL); |
52 | 58 | ||
53 | /* | 59 | /* |
54 | * data=writeback: | 60 | * data=writeback,ordered: |
55 | * The caller's filemap_fdatawrite()/wait will sync the data. | 61 | * The caller's filemap_fdatawrite()/wait will sync the data. |
56 | * sync_inode() will sync the metadata | 62 | * Metadata is in the journal, we wait for a proper transaction |
57 | * | 63 | * to commit here. |
58 | * data=ordered: | ||
59 | * The caller's filemap_fdatawrite() will write the data and | ||
60 | * sync_inode() will write the inode if it is dirty. Then the caller's | ||
61 | * filemap_fdatawait() will wait on the pages. | ||
62 | * | 64 | * |
63 | * data=journal: | 65 | * data=journal: |
64 | * filemap_fdatawrite won't do anything (the buffers are clean). | 66 | * filemap_fdatawrite won't do anything (the buffers are clean). |
@@ -73,22 +75,16 @@ int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync) | |||
73 | goto out; | 75 | goto out; |
74 | } | 76 | } |
75 | 77 | ||
76 | if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) | 78 | if (datasync) |
77 | goto flush; | 79 | commit_tid = atomic_read(&ei->i_datasync_tid); |
80 | else | ||
81 | commit_tid = atomic_read(&ei->i_sync_tid); | ||
78 | 82 | ||
79 | /* | 83 | if (log_start_commit(journal, commit_tid)) { |
80 | * The VFS has written the file data. If the inode is unaltered | 84 | log_wait_commit(journal, commit_tid); |
81 | * then we need not start a commit. | ||
82 | */ | ||
83 | if (inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC)) { | ||
84 | struct writeback_control wbc = { | ||
85 | .sync_mode = WB_SYNC_ALL, | ||
86 | .nr_to_write = 0, /* sys_fsync did this */ | ||
87 | }; | ||
88 | ret = sync_inode(inode, &wbc); | ||
89 | goto out; | 85 | goto out; |
90 | } | 86 | } |
91 | flush: | 87 | |
92 | /* | 88 | /* |
93 | * In case we didn't commit a transaction, we have to flush | 89 | * In case we didn't commit a transaction, we have to flush |
94 | * disk caches manually so that data really is on persistent | 90 | * disk caches manually so that data really is on persistent |
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index acf1b1423327..354ed3b47b30 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c | |||
@@ -699,8 +699,9 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode, | |||
699 | int err = 0; | 699 | int err = 0; |
700 | struct ext3_block_alloc_info *block_i; | 700 | struct ext3_block_alloc_info *block_i; |
701 | ext3_fsblk_t current_block; | 701 | ext3_fsblk_t current_block; |
702 | struct ext3_inode_info *ei = EXT3_I(inode); | ||
702 | 703 | ||
703 | block_i = EXT3_I(inode)->i_block_alloc_info; | 704 | block_i = ei->i_block_alloc_info; |
704 | /* | 705 | /* |
705 | * If we're splicing into a [td]indirect block (as opposed to the | 706 | * If we're splicing into a [td]indirect block (as opposed to the |
706 | * inode) then we need to get write access to the [td]indirect block | 707 | * inode) then we need to get write access to the [td]indirect block |
@@ -741,6 +742,8 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode, | |||
741 | 742 | ||
742 | inode->i_ctime = CURRENT_TIME_SEC; | 743 | inode->i_ctime = CURRENT_TIME_SEC; |
743 | ext3_mark_inode_dirty(handle, inode); | 744 | ext3_mark_inode_dirty(handle, inode); |
745 | /* ext3_mark_inode_dirty already updated i_sync_tid */ | ||
746 | atomic_set(&ei->i_datasync_tid, handle->h_transaction->t_tid); | ||
744 | 747 | ||
745 | /* had we spliced it onto indirect block? */ | 748 | /* had we spliced it onto indirect block? */ |
746 | if (where->bh) { | 749 | if (where->bh) { |
@@ -1735,6 +1738,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, | |||
1735 | ssize_t ret; | 1738 | ssize_t ret; |
1736 | int orphan = 0; | 1739 | int orphan = 0; |
1737 | size_t count = iov_length(iov, nr_segs); | 1740 | size_t count = iov_length(iov, nr_segs); |
1741 | int retries = 0; | ||
1738 | 1742 | ||
1739 | if (rw == WRITE) { | 1743 | if (rw == WRITE) { |
1740 | loff_t final_size = offset + count; | 1744 | loff_t final_size = offset + count; |
@@ -1757,9 +1761,12 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, | |||
1757 | } | 1761 | } |
1758 | } | 1762 | } |
1759 | 1763 | ||
1764 | retry: | ||
1760 | ret = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, | 1765 | ret = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, |
1761 | offset, nr_segs, | 1766 | offset, nr_segs, |
1762 | ext3_get_block, NULL); | 1767 | ext3_get_block, NULL); |
1768 | if (ret == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries)) | ||
1769 | goto retry; | ||
1763 | 1770 | ||
1764 | if (orphan) { | 1771 | if (orphan) { |
1765 | int err; | 1772 | int err; |
@@ -2750,6 +2757,8 @@ struct inode *ext3_iget(struct super_block *sb, unsigned long ino) | |||
2750 | struct ext3_inode_info *ei; | 2757 | struct ext3_inode_info *ei; |
2751 | struct buffer_head *bh; | 2758 | struct buffer_head *bh; |
2752 | struct inode *inode; | 2759 | struct inode *inode; |
2760 | journal_t *journal = EXT3_SB(sb)->s_journal; | ||
2761 | transaction_t *transaction; | ||
2753 | long ret; | 2762 | long ret; |
2754 | int block; | 2763 | int block; |
2755 | 2764 | ||
@@ -2827,6 +2836,30 @@ struct inode *ext3_iget(struct super_block *sb, unsigned long ino) | |||
2827 | ei->i_data[block] = raw_inode->i_block[block]; | 2836 | ei->i_data[block] = raw_inode->i_block[block]; |
2828 | INIT_LIST_HEAD(&ei->i_orphan); | 2837 | INIT_LIST_HEAD(&ei->i_orphan); |
2829 | 2838 | ||
2839 | /* | ||
2840 | * Set transaction id's of transactions that have to be committed | ||
2841 | * to finish f[data]sync. We set them to currently running transaction | ||
2842 | * as we cannot be sure that the inode or some of its metadata isn't | ||
2843 | * part of the transaction - the inode could have been reclaimed and | ||
2844 | * now it is reread from disk. | ||
2845 | */ | ||
2846 | if (journal) { | ||
2847 | tid_t tid; | ||
2848 | |||
2849 | spin_lock(&journal->j_state_lock); | ||
2850 | if (journal->j_running_transaction) | ||
2851 | transaction = journal->j_running_transaction; | ||
2852 | else | ||
2853 | transaction = journal->j_committing_transaction; | ||
2854 | if (transaction) | ||
2855 | tid = transaction->t_tid; | ||
2856 | else | ||
2857 | tid = journal->j_commit_sequence; | ||
2858 | spin_unlock(&journal->j_state_lock); | ||
2859 | atomic_set(&ei->i_sync_tid, tid); | ||
2860 | atomic_set(&ei->i_datasync_tid, tid); | ||
2861 | } | ||
2862 | |||
2830 | if (inode->i_ino >= EXT3_FIRST_INO(inode->i_sb) + 1 && | 2863 | if (inode->i_ino >= EXT3_FIRST_INO(inode->i_sb) + 1 && |
2831 | EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) { | 2864 | EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) { |
2832 | /* | 2865 | /* |
@@ -3011,6 +3044,7 @@ again: | |||
3011 | err = rc; | 3044 | err = rc; |
3012 | ei->i_state &= ~EXT3_STATE_NEW; | 3045 | ei->i_state &= ~EXT3_STATE_NEW; |
3013 | 3046 | ||
3047 | atomic_set(&ei->i_sync_tid, handle->h_transaction->t_tid); | ||
3014 | out_brelse: | 3048 | out_brelse: |
3015 | brelse (bh); | 3049 | brelse (bh); |
3016 | ext3_std_error(inode->i_sb, err); | 3050 | ext3_std_error(inode->i_sb, err); |
diff --git a/fs/ext3/super.c b/fs/ext3/super.c index 72743d360509..427496c4767c 100644 --- a/fs/ext3/super.c +++ b/fs/ext3/super.c | |||
@@ -466,6 +466,8 @@ static struct inode *ext3_alloc_inode(struct super_block *sb) | |||
466 | return NULL; | 466 | return NULL; |
467 | ei->i_block_alloc_info = NULL; | 467 | ei->i_block_alloc_info = NULL; |
468 | ei->vfs_inode.i_version = 1; | 468 | ei->vfs_inode.i_version = 1; |
469 | atomic_set(&ei->i_datasync_tid, 0); | ||
470 | atomic_set(&ei->i_sync_tid, 0); | ||
469 | return &ei->vfs_inode; | 471 | return &ei->vfs_inode; |
470 | } | 472 | } |
471 | 473 | ||
@@ -2321,7 +2323,18 @@ static int ext3_commit_super(struct super_block *sb, | |||
2321 | 2323 | ||
2322 | if (!sbh) | 2324 | if (!sbh) |
2323 | return error; | 2325 | return error; |
2324 | es->s_wtime = cpu_to_le32(get_seconds()); | 2326 | /* |
2327 | * If the file system is mounted read-only, don't update the | ||
2328 | * superblock write time. This avoids updating the superblock | ||
2329 | * write time when we are mounting the root file system | ||
2330 | * read/only but we need to replay the journal; at that point, | ||
2331 | * for people who are east of GMT and who make their clock | ||
2332 | * tick in localtime for Windows bug-for-bug compatibility, | ||
2333 | * the clock is set in the future, and this will cause e2fsck | ||
2334 | * to complain and force a full file system check. | ||
2335 | */ | ||
2336 | if (!(sb->s_flags & MS_RDONLY)) | ||
2337 | es->s_wtime = cpu_to_le32(get_seconds()); | ||
2325 | es->s_free_blocks_count = cpu_to_le32(ext3_count_free_blocks(sb)); | 2338 | es->s_free_blocks_count = cpu_to_le32(ext3_count_free_blocks(sb)); |
2326 | es->s_free_inodes_count = cpu_to_le32(ext3_count_free_inodes(sb)); | 2339 | es->s_free_inodes_count = cpu_to_le32(ext3_count_free_inodes(sb)); |
2327 | BUFFER_TRACE(sbh, "marking dirty"); | 2340 | BUFFER_TRACE(sbh, "marking dirty"); |
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 984ca0cb38c3..8825515eeddd 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -322,6 +322,7 @@ static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags) | |||
322 | #define EXT4_STATE_NO_EXPAND 0x00000008 /* No space for expansion */ | 322 | #define EXT4_STATE_NO_EXPAND 0x00000008 /* No space for expansion */ |
323 | #define EXT4_STATE_DA_ALLOC_CLOSE 0x00000010 /* Alloc DA blks on close */ | 323 | #define EXT4_STATE_DA_ALLOC_CLOSE 0x00000010 /* Alloc DA blks on close */ |
324 | #define EXT4_STATE_EXT_MIGRATE 0x00000020 /* Inode is migrating */ | 324 | #define EXT4_STATE_EXT_MIGRATE 0x00000020 /* Inode is migrating */ |
325 | #define EXT4_STATE_DIO_UNWRITTEN 0x00000040 /* need convert on dio done*/ | ||
325 | 326 | ||
326 | /* Used to pass group descriptor data when online resize is done */ | 327 | /* Used to pass group descriptor data when online resize is done */ |
327 | struct ext4_new_group_input { | 328 | struct ext4_new_group_input { |
@@ -743,6 +744,7 @@ struct ext4_inode_info { | |||
743 | #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */ | 744 | #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */ |
744 | #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */ | 745 | #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */ |
745 | #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */ | 746 | #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */ |
747 | #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */ | ||
746 | #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */ | 748 | #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */ |
747 | #define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */ | 749 | #define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */ |
748 | #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */ | 750 | #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */ |
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 10539e364283..715264b4bae4 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -2807,6 +2807,8 @@ fix_extent_len: | |||
2807 | * into three uninitialized extent(at most). After IO complete, the part | 2807 | * into three uninitialized extent(at most). After IO complete, the part |
2808 | * being filled will be convert to initialized by the end_io callback function | 2808 | * being filled will be convert to initialized by the end_io callback function |
2809 | * via ext4_convert_unwritten_extents(). | 2809 | * via ext4_convert_unwritten_extents(). |
2810 | * | ||
2811 | * Returns the size of uninitialized extent to be written on success. | ||
2810 | */ | 2812 | */ |
2811 | static int ext4_split_unwritten_extents(handle_t *handle, | 2813 | static int ext4_split_unwritten_extents(handle_t *handle, |
2812 | struct inode *inode, | 2814 | struct inode *inode, |
@@ -2824,7 +2826,6 @@ static int ext4_split_unwritten_extents(handle_t *handle, | |||
2824 | unsigned int allocated, ee_len, depth; | 2826 | unsigned int allocated, ee_len, depth; |
2825 | ext4_fsblk_t newblock; | 2827 | ext4_fsblk_t newblock; |
2826 | int err = 0; | 2828 | int err = 0; |
2827 | int ret = 0; | ||
2828 | 2829 | ||
2829 | ext_debug("ext4_split_unwritten_extents: inode %lu," | 2830 | ext_debug("ext4_split_unwritten_extents: inode %lu," |
2830 | "iblock %llu, max_blocks %u\n", inode->i_ino, | 2831 | "iblock %llu, max_blocks %u\n", inode->i_ino, |
@@ -2842,12 +2843,12 @@ static int ext4_split_unwritten_extents(handle_t *handle, | |||
2842 | ext4_ext_store_pblock(&orig_ex, ext_pblock(ex)); | 2843 | ext4_ext_store_pblock(&orig_ex, ext_pblock(ex)); |
2843 | 2844 | ||
2844 | /* | 2845 | /* |
2845 | * if the entire unintialized extent length less than | 2846 | * If the uninitialized extent begins at the same logical |
2846 | * the size of extent to write, there is no need to split | 2847 | * block where the write begins, and the write completely |
2847 | * uninitialized extent | 2848 | * covers the extent, then we don't need to split it. |
2848 | */ | 2849 | */ |
2849 | if (allocated <= max_blocks) | 2850 | if ((iblock == ee_block) && (allocated <= max_blocks)) |
2850 | return ret; | 2851 | return allocated; |
2851 | 2852 | ||
2852 | err = ext4_ext_get_access(handle, inode, path + depth); | 2853 | err = ext4_ext_get_access(handle, inode, path + depth); |
2853 | if (err) | 2854 | if (err) |
@@ -3048,12 +3049,18 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, | |||
3048 | ret = ext4_split_unwritten_extents(handle, | 3049 | ret = ext4_split_unwritten_extents(handle, |
3049 | inode, path, iblock, | 3050 | inode, path, iblock, |
3050 | max_blocks, flags); | 3051 | max_blocks, flags); |
3051 | /* flag the io_end struct that we need convert when IO done */ | 3052 | /* |
3053 | * Flag the inode(non aio case) or end_io struct (aio case) | ||
3054 | * that this IO needs to convertion to written when IO is | ||
3055 | * completed | ||
3056 | */ | ||
3052 | if (io) | 3057 | if (io) |
3053 | io->flag = DIO_AIO_UNWRITTEN; | 3058 | io->flag = DIO_AIO_UNWRITTEN; |
3059 | else | ||
3060 | EXT4_I(inode)->i_state |= EXT4_STATE_DIO_UNWRITTEN; | ||
3054 | goto out; | 3061 | goto out; |
3055 | } | 3062 | } |
3056 | /* DIO end_io complete, convert the filled extent to written */ | 3063 | /* async DIO end_io complete, convert the filled extent to written */ |
3057 | if (flags == EXT4_GET_BLOCKS_DIO_CONVERT_EXT) { | 3064 | if (flags == EXT4_GET_BLOCKS_DIO_CONVERT_EXT) { |
3058 | ret = ext4_convert_unwritten_extents_dio(handle, inode, | 3065 | ret = ext4_convert_unwritten_extents_dio(handle, inode, |
3059 | path); | 3066 | path); |
@@ -3295,10 +3302,16 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, | |||
3295 | * To avoid unecessary convertion for every aio dio rewrite | 3302 | * To avoid unecessary convertion for every aio dio rewrite |
3296 | * to the mid of file, here we flag the IO that is really | 3303 | * to the mid of file, here we flag the IO that is really |
3297 | * need the convertion. | 3304 | * need the convertion. |
3298 | * | 3305 | * For non asycn direct IO case, flag the inode state |
3306 | * that we need to perform convertion when IO is done. | ||
3299 | */ | 3307 | */ |
3300 | if (io && flags == EXT4_GET_BLOCKS_DIO_CREATE_EXT) | 3308 | if (flags == EXT4_GET_BLOCKS_DIO_CREATE_EXT) { |
3301 | io->flag = DIO_AIO_UNWRITTEN; | 3309 | if (io) |
3310 | io->flag = DIO_AIO_UNWRITTEN; | ||
3311 | else | ||
3312 | EXT4_I(inode)->i_state |= | ||
3313 | EXT4_STATE_DIO_UNWRITTEN;; | ||
3314 | } | ||
3302 | } | 3315 | } |
3303 | err = ext4_ext_insert_extent(handle, inode, path, &newex, flags); | 3316 | err = ext4_ext_insert_extent(handle, inode, path, &newex, flags); |
3304 | if (err) { | 3317 | if (err) { |
@@ -3519,6 +3532,7 @@ retry: | |||
3519 | * | 3532 | * |
3520 | * This function is called from the direct IO end io call back | 3533 | * This function is called from the direct IO end io call back |
3521 | * function, to convert the fallocated extents after IO is completed. | 3534 | * function, to convert the fallocated extents after IO is completed. |
3535 | * Returns 0 on success. | ||
3522 | */ | 3536 | */ |
3523 | int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, | 3537 | int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, |
3524 | loff_t len) | 3538 | loff_t len) |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5c5bc5dafff8..2c8caa51addb 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -193,7 +193,7 @@ static int try_to_extend_transaction(handle_t *handle, struct inode *inode) | |||
193 | * so before we call here everything must be consistently dirtied against | 193 | * so before we call here everything must be consistently dirtied against |
194 | * this transaction. | 194 | * this transaction. |
195 | */ | 195 | */ |
196 | int ext4_truncate_restart_trans(handle_t *handle, struct inode *inode, | 196 | int ext4_truncate_restart_trans(handle_t *handle, struct inode *inode, |
197 | int nblocks) | 197 | int nblocks) |
198 | { | 198 | { |
199 | int ret; | 199 | int ret; |
@@ -209,6 +209,7 @@ static int try_to_extend_transaction(handle_t *handle, struct inode *inode) | |||
209 | up_write(&EXT4_I(inode)->i_data_sem); | 209 | up_write(&EXT4_I(inode)->i_data_sem); |
210 | ret = ext4_journal_restart(handle, blocks_for_truncate(inode)); | 210 | ret = ext4_journal_restart(handle, blocks_for_truncate(inode)); |
211 | down_write(&EXT4_I(inode)->i_data_sem); | 211 | down_write(&EXT4_I(inode)->i_data_sem); |
212 | ext4_discard_preallocations(inode); | ||
212 | 213 | ||
213 | return ret; | 214 | return ret; |
214 | } | 215 | } |
@@ -3445,8 +3446,6 @@ out: | |||
3445 | return ret; | 3446 | return ret; |
3446 | } | 3447 | } |
3447 | 3448 | ||
3448 | /* Maximum number of blocks we map for direct IO at once. */ | ||
3449 | |||
3450 | static int ext4_get_block_dio_write(struct inode *inode, sector_t iblock, | 3449 | static int ext4_get_block_dio_write(struct inode *inode, sector_t iblock, |
3451 | struct buffer_head *bh_result, int create) | 3450 | struct buffer_head *bh_result, int create) |
3452 | { | 3451 | { |
@@ -3654,13 +3653,14 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset, | |||
3654 | ext4_io_end_t *io_end = iocb->private; | 3653 | ext4_io_end_t *io_end = iocb->private; |
3655 | struct workqueue_struct *wq; | 3654 | struct workqueue_struct *wq; |
3656 | 3655 | ||
3656 | /* if not async direct IO or dio with 0 bytes write, just return */ | ||
3657 | if (!io_end || !size) | ||
3658 | return; | ||
3659 | |||
3657 | ext_debug("ext4_end_io_dio(): io_end 0x%p" | 3660 | ext_debug("ext4_end_io_dio(): io_end 0x%p" |
3658 | "for inode %lu, iocb 0x%p, offset %llu, size %llu\n", | 3661 | "for inode %lu, iocb 0x%p, offset %llu, size %llu\n", |
3659 | iocb->private, io_end->inode->i_ino, iocb, offset, | 3662 | iocb->private, io_end->inode->i_ino, iocb, offset, |
3660 | size); | 3663 | size); |
3661 | /* if not async direct IO or dio with 0 bytes write, just return */ | ||
3662 | if (!io_end || !size) | ||
3663 | return; | ||
3664 | 3664 | ||
3665 | /* if not aio dio with unwritten extents, just free io and return */ | 3665 | /* if not aio dio with unwritten extents, just free io and return */ |
3666 | if (io_end->flag != DIO_AIO_UNWRITTEN){ | 3666 | if (io_end->flag != DIO_AIO_UNWRITTEN){ |
@@ -3771,13 +3771,19 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
3771 | if (ret != -EIOCBQUEUED && ret <= 0 && iocb->private) { | 3771 | if (ret != -EIOCBQUEUED && ret <= 0 && iocb->private) { |
3772 | ext4_free_io_end(iocb->private); | 3772 | ext4_free_io_end(iocb->private); |
3773 | iocb->private = NULL; | 3773 | iocb->private = NULL; |
3774 | } else if (ret > 0) | 3774 | } else if (ret > 0 && (EXT4_I(inode)->i_state & |
3775 | EXT4_STATE_DIO_UNWRITTEN)) { | ||
3776 | int err; | ||
3775 | /* | 3777 | /* |
3776 | * for non AIO case, since the IO is already | 3778 | * for non AIO case, since the IO is already |
3777 | * completed, we could do the convertion right here | 3779 | * completed, we could do the convertion right here |
3778 | */ | 3780 | */ |
3779 | ret = ext4_convert_unwritten_extents(inode, | 3781 | err = ext4_convert_unwritten_extents(inode, |
3780 | offset, ret); | 3782 | offset, ret); |
3783 | if (err < 0) | ||
3784 | ret = err; | ||
3785 | EXT4_I(inode)->i_state &= ~EXT4_STATE_DIO_UNWRITTEN; | ||
3786 | } | ||
3781 | return ret; | 3787 | return ret; |
3782 | } | 3788 | } |
3783 | 3789 | ||
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 7c8fe80bacdd..6d2c1b897fc7 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
@@ -1518,12 +1518,8 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, | |||
1518 | return retval; | 1518 | return retval; |
1519 | 1519 | ||
1520 | if (blocks == 1 && !dx_fallback && | 1520 | if (blocks == 1 && !dx_fallback && |
1521 | EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) { | 1521 | EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) |
1522 | retval = make_indexed_dir(handle, dentry, inode, bh); | 1522 | return make_indexed_dir(handle, dentry, inode, bh); |
1523 | if (retval == -ENOSPC) | ||
1524 | brelse(bh); | ||
1525 | return retval; | ||
1526 | } | ||
1527 | brelse(bh); | 1523 | brelse(bh); |
1528 | } | 1524 | } |
1529 | bh = ext4_append(handle, dir, &block, &retval); | 1525 | bh = ext4_append(handle, dir, &block, &retval); |
@@ -1532,10 +1528,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, | |||
1532 | de = (struct ext4_dir_entry_2 *) bh->b_data; | 1528 | de = (struct ext4_dir_entry_2 *) bh->b_data; |
1533 | de->inode = 0; | 1529 | de->inode = 0; |
1534 | de->rec_len = ext4_rec_len_to_disk(blocksize, blocksize); | 1530 | de->rec_len = ext4_rec_len_to_disk(blocksize, blocksize); |
1535 | retval = add_dirent_to_buf(handle, dentry, inode, de, bh); | 1531 | return add_dirent_to_buf(handle, dentry, inode, de, bh); |
1536 | if (retval == -ENOSPC) | ||
1537 | brelse(bh); | ||
1538 | return retval; | ||
1539 | } | 1532 | } |
1540 | 1533 | ||
1541 | /* | 1534 | /* |
@@ -1664,8 +1657,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry, | |||
1664 | if (!de) | 1657 | if (!de) |
1665 | goto cleanup; | 1658 | goto cleanup; |
1666 | err = add_dirent_to_buf(handle, dentry, inode, de, bh); | 1659 | err = add_dirent_to_buf(handle, dentry, inode, de, bh); |
1667 | if (err != -ENOSPC) | 1660 | bh = NULL; |
1668 | bh = NULL; | ||
1669 | goto cleanup; | 1661 | goto cleanup; |
1670 | 1662 | ||
1671 | journal_error: | 1663 | journal_error: |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 312211ee05af..d4ca92aab514 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -1300,9 +1300,11 @@ static int parse_options(char *options, struct super_block *sb, | |||
1300 | *journal_devnum = option; | 1300 | *journal_devnum = option; |
1301 | break; | 1301 | break; |
1302 | case Opt_journal_checksum: | 1302 | case Opt_journal_checksum: |
1303 | break; /* Kept for backwards compatibility */ | 1303 | set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM); |
1304 | break; | ||
1304 | case Opt_journal_async_commit: | 1305 | case Opt_journal_async_commit: |
1305 | set_opt(sbi->s_mount_opt, JOURNAL_ASYNC_COMMIT); | 1306 | set_opt(sbi->s_mount_opt, JOURNAL_ASYNC_COMMIT); |
1307 | set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM); | ||
1306 | break; | 1308 | break; |
1307 | case Opt_noload: | 1309 | case Opt_noload: |
1308 | set_opt(sbi->s_mount_opt, NOLOAD); | 1310 | set_opt(sbi->s_mount_opt, NOLOAD); |
@@ -2759,14 +2761,20 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
2759 | goto failed_mount4; | 2761 | goto failed_mount4; |
2760 | } | 2762 | } |
2761 | 2763 | ||
2762 | jbd2_journal_set_features(sbi->s_journal, | 2764 | if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) { |
2763 | JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0); | 2765 | jbd2_journal_set_features(sbi->s_journal, |
2764 | if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) | 2766 | JBD2_FEATURE_COMPAT_CHECKSUM, 0, |
2765 | jbd2_journal_set_features(sbi->s_journal, 0, 0, | ||
2766 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); | 2767 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); |
2767 | else | 2768 | } else if (test_opt(sb, JOURNAL_CHECKSUM)) { |
2769 | jbd2_journal_set_features(sbi->s_journal, | ||
2770 | JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0); | ||
2768 | jbd2_journal_clear_features(sbi->s_journal, 0, 0, | 2771 | jbd2_journal_clear_features(sbi->s_journal, 0, 0, |
2769 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); | 2772 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); |
2773 | } else { | ||
2774 | jbd2_journal_clear_features(sbi->s_journal, | ||
2775 | JBD2_FEATURE_COMPAT_CHECKSUM, 0, | ||
2776 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); | ||
2777 | } | ||
2770 | 2778 | ||
2771 | /* We have now updated the journal if required, so we can | 2779 | /* We have now updated the journal if required, so we can |
2772 | * validate the data journaling mode. */ | 2780 | * validate the data journaling mode. */ |
diff --git a/fs/fcntl.c b/fs/fcntl.c index fc089f2f7f56..2cf93ec40a67 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c | |||
@@ -284,7 +284,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg) | |||
284 | type = PIDTYPE_PID; | 284 | type = PIDTYPE_PID; |
285 | break; | 285 | break; |
286 | 286 | ||
287 | case F_OWNER_GID: | 287 | case F_OWNER_PGRP: |
288 | type = PIDTYPE_PGID; | 288 | type = PIDTYPE_PGID; |
289 | break; | 289 | break; |
290 | 290 | ||
@@ -321,7 +321,7 @@ static int f_getown_ex(struct file *filp, unsigned long arg) | |||
321 | break; | 321 | break; |
322 | 322 | ||
323 | case PIDTYPE_PGID: | 323 | case PIDTYPE_PGID: |
324 | owner.type = F_OWNER_GID; | 324 | owner.type = F_OWNER_PGRP; |
325 | break; | 325 | break; |
326 | 326 | ||
327 | default: | 327 | default: |
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/fs.h> | 10 | #include <linux/fs.h> |
11 | #include <linux/mm.h> | 11 | #include <linux/mm.h> |
12 | #include <linux/time.h> | 12 | #include <linux/time.h> |
13 | #include <linux/sched.h> | ||
13 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
14 | #include <linux/vmalloc.h> | 15 | #include <linux/vmalloc.h> |
15 | #include <linux/file.h> | 16 | #include <linux/file.h> |
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 992f6c9410bb..8ada78aade58 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c | |||
@@ -712,8 +712,10 @@ static int fuse_rename(struct inode *olddir, struct dentry *oldent, | |||
712 | fuse_invalidate_attr(newdir); | 712 | fuse_invalidate_attr(newdir); |
713 | 713 | ||
714 | /* newent will end up negative */ | 714 | /* newent will end up negative */ |
715 | if (newent->d_inode) | 715 | if (newent->d_inode) { |
716 | fuse_invalidate_attr(newent->d_inode); | ||
716 | fuse_invalidate_entry_cache(newent); | 717 | fuse_invalidate_entry_cache(newent); |
718 | } | ||
717 | } else if (err == -EINTR) { | 719 | } else if (err == -EINTR) { |
718 | /* If request was interrupted, DEITY only knows if the | 720 | /* If request was interrupted, DEITY only knows if the |
719 | rename actually took place. If the invalidation | 721 | rename actually took place. If the invalidation |
diff --git a/fs/fuse/file.c b/fs/fuse/file.c index a3492f7d207c..c18913a777ae 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c | |||
@@ -1063,7 +1063,8 @@ ssize_t fuse_direct_io(struct file *file, const char __user *buf, | |||
1063 | break; | 1063 | break; |
1064 | } | 1064 | } |
1065 | } | 1065 | } |
1066 | fuse_put_request(fc, req); | 1066 | if (!IS_ERR(req)) |
1067 | fuse_put_request(fc, req); | ||
1067 | if (res > 0) | 1068 | if (res > 0) |
1068 | *ppos = pos; | 1069 | *ppos = pos; |
1069 | 1070 | ||
@@ -1599,7 +1600,7 @@ static int fuse_ioctl_copy_user(struct page **pages, struct iovec *iov, | |||
1599 | kaddr += copy; | 1600 | kaddr += copy; |
1600 | } | 1601 | } |
1601 | 1602 | ||
1602 | kunmap(map); | 1603 | kunmap(page); |
1603 | } | 1604 | } |
1604 | 1605 | ||
1605 | return 0; | 1606 | return 0; |
diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c index 9b9d6395bad3..052f214ea6f0 100644 --- a/fs/hfs/btree.c +++ b/fs/hfs/btree.c | |||
@@ -58,6 +58,11 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke | |||
58 | } | 58 | } |
59 | unlock_new_inode(tree->inode); | 59 | unlock_new_inode(tree->inode); |
60 | 60 | ||
61 | if (!HFS_I(tree->inode)->first_blocks) { | ||
62 | printk(KERN_ERR "hfs: invalid btree extent records (0 size).\n"); | ||
63 | goto free_inode; | ||
64 | } | ||
65 | |||
61 | mapping = tree->inode->i_mapping; | 66 | mapping = tree->inode->i_mapping; |
62 | page = read_mapping_page(mapping, 0, NULL); | 67 | page = read_mapping_page(mapping, 0, NULL); |
63 | if (IS_ERR(page)) | 68 | if (IS_ERR(page)) |
diff --git a/fs/hfsplus/wrapper.c b/fs/hfsplus/wrapper.c index 175d08eacc86..bed78ac8f6d1 100644 --- a/fs/hfsplus/wrapper.c +++ b/fs/hfsplus/wrapper.c | |||
@@ -99,6 +99,10 @@ int hfsplus_read_wrapper(struct super_block *sb) | |||
99 | 99 | ||
100 | if (hfsplus_get_last_session(sb, &part_start, &part_size)) | 100 | if (hfsplus_get_last_session(sb, &part_start, &part_size)) |
101 | return -EINVAL; | 101 | return -EINVAL; |
102 | if ((u64)part_start + part_size > 0x100000000ULL) { | ||
103 | pr_err("hfs: volumes larger than 2TB are not supported yet\n"); | ||
104 | return -EINVAL; | ||
105 | } | ||
102 | while (1) { | 106 | while (1) { |
103 | bh = sb_bread512(sb, part_start + HFSPLUS_VOLHEAD_SECTOR, vhdr); | 107 | bh = sb_bread512(sb, part_start + HFSPLUS_VOLHEAD_SECTOR, vhdr); |
104 | if (!bh) | 108 | if (!bh) |
diff --git a/fs/ioctl.c b/fs/ioctl.c index 7b17a14396ff..6c751106c2e5 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c | |||
@@ -254,7 +254,7 @@ int __generic_block_fiemap(struct inode *inode, | |||
254 | u64 len, get_block_t *get_block) | 254 | u64 len, get_block_t *get_block) |
255 | { | 255 | { |
256 | struct buffer_head tmp; | 256 | struct buffer_head tmp; |
257 | unsigned int start_blk; | 257 | unsigned long long start_blk; |
258 | long long length = 0, map_len = 0; | 258 | long long length = 0, map_len = 0; |
259 | u64 logical = 0, phys = 0, size = 0; | 259 | u64 logical = 0, phys = 0, size = 0; |
260 | u32 flags = FIEMAP_EXTENT_MERGED; | 260 | u32 flags = FIEMAP_EXTENT_MERGED; |
diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c index bd3c073b485d..4160afad6d00 100644 --- a/fs/jbd/journal.c +++ b/fs/jbd/journal.c | |||
@@ -73,6 +73,7 @@ EXPORT_SYMBOL(journal_errno); | |||
73 | EXPORT_SYMBOL(journal_ack_err); | 73 | EXPORT_SYMBOL(journal_ack_err); |
74 | EXPORT_SYMBOL(journal_clear_err); | 74 | EXPORT_SYMBOL(journal_clear_err); |
75 | EXPORT_SYMBOL(log_wait_commit); | 75 | EXPORT_SYMBOL(log_wait_commit); |
76 | EXPORT_SYMBOL(log_start_commit); | ||
76 | EXPORT_SYMBOL(journal_start_commit); | 77 | EXPORT_SYMBOL(journal_start_commit); |
77 | EXPORT_SYMBOL(journal_force_commit_nested); | 78 | EXPORT_SYMBOL(journal_force_commit_nested); |
78 | EXPORT_SYMBOL(journal_wipe); | 79 | EXPORT_SYMBOL(journal_wipe); |
@@ -756,6 +757,7 @@ journal_t * journal_init_dev(struct block_device *bdev, | |||
756 | 757 | ||
757 | return journal; | 758 | return journal; |
758 | out_err: | 759 | out_err: |
760 | kfree(journal->j_wbuf); | ||
759 | kfree(journal); | 761 | kfree(journal); |
760 | return NULL; | 762 | return NULL; |
761 | } | 763 | } |
@@ -820,6 +822,7 @@ journal_t * journal_init_inode (struct inode *inode) | |||
820 | 822 | ||
821 | return journal; | 823 | return journal; |
822 | out_err: | 824 | out_err: |
825 | kfree(journal->j_wbuf); | ||
823 | kfree(journal); | 826 | kfree(journal); |
824 | return NULL; | 827 | return NULL; |
825 | } | 828 | } |
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index b0ab5219becb..fed85388ee86 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c | |||
@@ -913,6 +913,7 @@ journal_t * jbd2_journal_init_dev(struct block_device *bdev, | |||
913 | 913 | ||
914 | return journal; | 914 | return journal; |
915 | out_err: | 915 | out_err: |
916 | kfree(journal->j_wbuf); | ||
916 | jbd2_stats_proc_exit(journal); | 917 | jbd2_stats_proc_exit(journal); |
917 | kfree(journal); | 918 | kfree(journal); |
918 | return NULL; | 919 | return NULL; |
@@ -986,6 +987,7 @@ journal_t * jbd2_journal_init_inode (struct inode *inode) | |||
986 | 987 | ||
987 | return journal; | 988 | return journal; |
988 | out_err: | 989 | out_err: |
990 | kfree(journal->j_wbuf); | ||
989 | jbd2_stats_proc_exit(journal); | 991 | jbd2_stats_proc_exit(journal); |
990 | kfree(journal); | 992 | kfree(journal); |
991 | return NULL; | 993 | return NULL; |
diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 63976c0ccc25..99ea196f071f 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c | |||
@@ -1180,7 +1180,7 @@ static int nfs4_init_client(struct nfs_client *clp, | |||
1180 | 1, flags & NFS_MOUNT_NORESVPORT); | 1180 | 1, flags & NFS_MOUNT_NORESVPORT); |
1181 | if (error < 0) | 1181 | if (error < 0) |
1182 | goto error; | 1182 | goto error; |
1183 | memcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); | 1183 | strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); |
1184 | 1184 | ||
1185 | error = nfs_idmap_new(clp); | 1185 | error = nfs_idmap_new(clp); |
1186 | if (error < 0) { | 1186 | if (error < 0) { |
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 32062c33c859..7cb298525eef 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c | |||
@@ -1536,6 +1536,8 @@ nfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) | |||
1536 | old_dentry->d_parent->d_name.name, old_dentry->d_name.name, | 1536 | old_dentry->d_parent->d_name.name, old_dentry->d_name.name, |
1537 | dentry->d_parent->d_name.name, dentry->d_name.name); | 1537 | dentry->d_parent->d_name.name, dentry->d_name.name); |
1538 | 1538 | ||
1539 | nfs_inode_return_delegation(inode); | ||
1540 | |||
1539 | d_drop(dentry); | 1541 | d_drop(dentry); |
1540 | error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name); | 1542 | error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name); |
1541 | if (error == 0) { | 1543 | if (error == 0) { |
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 6c3210099d51..e1d415e97849 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c | |||
@@ -457,6 +457,7 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq) | |||
457 | }; | 457 | }; |
458 | struct rpc_task_setup task_setup_data = { | 458 | struct rpc_task_setup task_setup_data = { |
459 | .rpc_client = NFS_CLIENT(inode), | 459 | .rpc_client = NFS_CLIENT(inode), |
460 | .rpc_message = &msg, | ||
460 | .callback_ops = &nfs_write_direct_ops, | 461 | .callback_ops = &nfs_write_direct_ops, |
461 | .workqueue = nfsiod_workqueue, | 462 | .workqueue = nfsiod_workqueue, |
462 | .flags = RPC_TASK_ASYNC, | 463 | .flags = RPC_TASK_ASYNC, |
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c index 2636c26d56fa..fa3408f20112 100644 --- a/fs/nfs/nfs4namespace.c +++ b/fs/nfs/nfs4namespace.c | |||
@@ -121,7 +121,7 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, | |||
121 | 121 | ||
122 | mnt_path = nfs4_pathname_string(&location->rootpath, page2, PAGE_SIZE); | 122 | mnt_path = nfs4_pathname_string(&location->rootpath, page2, PAGE_SIZE); |
123 | if (IS_ERR(mnt_path)) | 123 | if (IS_ERR(mnt_path)) |
124 | return mnt; | 124 | return ERR_CAST(mnt_path); |
125 | mountdata->mnt_path = mnt_path; | 125 | mountdata->mnt_path = mnt_path; |
126 | maxbuflen = mnt_path - 1 - page2; | 126 | maxbuflen = mnt_path - 1 - page2; |
127 | 127 | ||
@@ -132,15 +132,15 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, | |||
132 | if (buf->len <= 0 || buf->len >= maxbuflen) | 132 | if (buf->len <= 0 || buf->len >= maxbuflen) |
133 | continue; | 133 | continue; |
134 | 134 | ||
135 | mountdata->addr = (struct sockaddr *)&addr; | ||
136 | |||
137 | if (memchr(buf->data, IPV6_SCOPE_DELIMITER, buf->len)) | 135 | if (memchr(buf->data, IPV6_SCOPE_DELIMITER, buf->len)) |
138 | continue; | 136 | continue; |
139 | mountdata->addrlen = nfs_parse_server_name(buf->data, | 137 | |
140 | buf->len, | 138 | mountdata->addrlen = nfs_parse_server_name(buf->data, buf->len, |
141 | mountdata->addr, mountdata->addrlen); | 139 | (struct sockaddr *)&addr, sizeof(addr)); |
142 | if (mountdata->addrlen == 0) | 140 | if (mountdata->addrlen == 0) |
143 | continue; | 141 | continue; |
142 | |||
143 | mountdata->addr = (struct sockaddr *)&addr; | ||
144 | rpc_set_port(mountdata->addr, NFS_PORT); | 144 | rpc_set_port(mountdata->addr, NFS_PORT); |
145 | 145 | ||
146 | memcpy(page2, buf->data, buf->len); | 146 | memcpy(page2, buf->data, buf->len); |
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index ed7c269e2514..ff37454fa783 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
@@ -72,12 +72,17 @@ static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, | |||
72 | /* Prevent leaks of NFSv4 errors into userland */ | 72 | /* Prevent leaks of NFSv4 errors into userland */ |
73 | static int nfs4_map_errors(int err) | 73 | static int nfs4_map_errors(int err) |
74 | { | 74 | { |
75 | if (err < -1000) { | 75 | if (err >= -1000) |
76 | return err; | ||
77 | switch (err) { | ||
78 | case -NFS4ERR_RESOURCE: | ||
79 | return -EREMOTEIO; | ||
80 | default: | ||
76 | dprintk("%s could not handle NFSv4 error %d\n", | 81 | dprintk("%s could not handle NFSv4 error %d\n", |
77 | __func__, -err); | 82 | __func__, -err); |
78 | return -EIO; | 83 | break; |
79 | } | 84 | } |
80 | return err; | 85 | return -EIO; |
81 | } | 86 | } |
82 | 87 | ||
83 | /* | 88 | /* |
@@ -3060,9 +3065,6 @@ static void nfs4_renew_done(struct rpc_task *task, void *data) | |||
3060 | if (time_before(clp->cl_last_renewal,timestamp)) | 3065 | if (time_before(clp->cl_last_renewal,timestamp)) |
3061 | clp->cl_last_renewal = timestamp; | 3066 | clp->cl_last_renewal = timestamp; |
3062 | spin_unlock(&clp->cl_lock); | 3067 | spin_unlock(&clp->cl_lock); |
3063 | dprintk("%s calling put_rpccred on rpc_cred %p\n", __func__, | ||
3064 | task->tk_msg.rpc_cred); | ||
3065 | put_rpccred(task->tk_msg.rpc_cred); | ||
3066 | } | 3068 | } |
3067 | 3069 | ||
3068 | static const struct rpc_call_ops nfs4_renew_ops = { | 3070 | static const struct rpc_call_ops nfs4_renew_ops = { |
@@ -4877,7 +4879,6 @@ void nfs41_sequence_call_done(struct rpc_task *task, void *data) | |||
4877 | nfs41_sequence_free_slot(clp, task->tk_msg.rpc_resp); | 4879 | nfs41_sequence_free_slot(clp, task->tk_msg.rpc_resp); |
4878 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); | 4880 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
4879 | 4881 | ||
4880 | put_rpccred(task->tk_msg.rpc_cred); | ||
4881 | kfree(task->tk_msg.rpc_argp); | 4882 | kfree(task->tk_msg.rpc_argp); |
4882 | kfree(task->tk_msg.rpc_resp); | 4883 | kfree(task->tk_msg.rpc_resp); |
4883 | 4884 | ||
diff --git a/fs/nfs/nfs4renewd.c b/fs/nfs/nfs4renewd.c index e27c6cef18f2..0156c01c212c 100644 --- a/fs/nfs/nfs4renewd.c +++ b/fs/nfs/nfs4renewd.c | |||
@@ -127,12 +127,6 @@ nfs4_schedule_state_renewal(struct nfs_client *clp) | |||
127 | } | 127 | } |
128 | 128 | ||
129 | void | 129 | void |
130 | nfs4_renewd_prepare_shutdown(struct nfs_server *server) | ||
131 | { | ||
132 | cancel_delayed_work(&server->nfs_client->cl_renewd); | ||
133 | } | ||
134 | |||
135 | void | ||
136 | nfs4_kill_renewd(struct nfs_client *clp) | 130 | nfs4_kill_renewd(struct nfs_client *clp) |
137 | { | 131 | { |
138 | cancel_delayed_work_sync(&clp->cl_renewd); | 132 | cancel_delayed_work_sync(&clp->cl_renewd); |
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 83ad47cbdd8a..20b4e30e6c82 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c | |||
@@ -5681,7 +5681,6 @@ static struct { | |||
5681 | { NFS4ERR_SERVERFAULT, -ESERVERFAULT }, | 5681 | { NFS4ERR_SERVERFAULT, -ESERVERFAULT }, |
5682 | { NFS4ERR_BADTYPE, -EBADTYPE }, | 5682 | { NFS4ERR_BADTYPE, -EBADTYPE }, |
5683 | { NFS4ERR_LOCKED, -EAGAIN }, | 5683 | { NFS4ERR_LOCKED, -EAGAIN }, |
5684 | { NFS4ERR_RESOURCE, -EREMOTEIO }, | ||
5685 | { NFS4ERR_SYMLINK, -ELOOP }, | 5684 | { NFS4ERR_SYMLINK, -ELOOP }, |
5686 | { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, | 5685 | { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, |
5687 | { NFS4ERR_DEADLOCK, -EDEADLK }, | 5686 | { NFS4ERR_DEADLOCK, -EDEADLK }, |
diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 29786d3b9326..90be551b80c1 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c | |||
@@ -728,22 +728,24 @@ static void nfs_umount_begin(struct super_block *sb) | |||
728 | unlock_kernel(); | 728 | unlock_kernel(); |
729 | } | 729 | } |
730 | 730 | ||
731 | static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(int flags) | 731 | static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version) |
732 | { | 732 | { |
733 | struct nfs_parsed_mount_data *data; | 733 | struct nfs_parsed_mount_data *data; |
734 | 734 | ||
735 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 735 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
736 | if (data) { | 736 | if (data) { |
737 | data->flags = flags; | ||
738 | data->rsize = NFS_MAX_FILE_IO_SIZE; | 737 | data->rsize = NFS_MAX_FILE_IO_SIZE; |
739 | data->wsize = NFS_MAX_FILE_IO_SIZE; | 738 | data->wsize = NFS_MAX_FILE_IO_SIZE; |
740 | data->acregmin = NFS_DEF_ACREGMIN; | 739 | data->acregmin = NFS_DEF_ACREGMIN; |
741 | data->acregmax = NFS_DEF_ACREGMAX; | 740 | data->acregmax = NFS_DEF_ACREGMAX; |
742 | data->acdirmin = NFS_DEF_ACDIRMIN; | 741 | data->acdirmin = NFS_DEF_ACDIRMIN; |
743 | data->acdirmax = NFS_DEF_ACDIRMAX; | 742 | data->acdirmax = NFS_DEF_ACDIRMAX; |
743 | data->mount_server.port = NFS_UNSPEC_PORT; | ||
744 | data->nfs_server.port = NFS_UNSPEC_PORT; | 744 | data->nfs_server.port = NFS_UNSPEC_PORT; |
745 | data->nfs_server.protocol = XPRT_TRANSPORT_TCP; | ||
745 | data->auth_flavors[0] = RPC_AUTH_UNIX; | 746 | data->auth_flavors[0] = RPC_AUTH_UNIX; |
746 | data->auth_flavor_len = 1; | 747 | data->auth_flavor_len = 1; |
748 | data->version = version; | ||
747 | data->minorversion = 0; | 749 | data->minorversion = 0; |
748 | } | 750 | } |
749 | return data; | 751 | return data; |
@@ -776,15 +778,13 @@ static int nfs_verify_server_address(struct sockaddr *addr) | |||
776 | * Select between a default port value and a user-specified port value. | 778 | * Select between a default port value and a user-specified port value. |
777 | * If a zero value is set, then autobind will be used. | 779 | * If a zero value is set, then autobind will be used. |
778 | */ | 780 | */ |
779 | static void nfs_set_default_port(struct sockaddr *sap, const int parsed_port, | 781 | static void nfs_set_port(struct sockaddr *sap, int *port, |
780 | const unsigned short default_port) | 782 | const unsigned short default_port) |
781 | { | 783 | { |
782 | unsigned short port = default_port; | 784 | if (*port == NFS_UNSPEC_PORT) |
785 | *port = default_port; | ||
783 | 786 | ||
784 | if (parsed_port != NFS_UNSPEC_PORT) | 787 | rpc_set_port(sap, *port); |
785 | port = parsed_port; | ||
786 | |||
787 | rpc_set_port(sap, port); | ||
788 | } | 788 | } |
789 | 789 | ||
790 | /* | 790 | /* |
@@ -1253,6 +1253,7 @@ static int nfs_parse_mount_options(char *raw, | |||
1253 | default: | 1253 | default: |
1254 | dfprintk(MOUNT, "NFS: unrecognized " | 1254 | dfprintk(MOUNT, "NFS: unrecognized " |
1255 | "transport protocol\n"); | 1255 | "transport protocol\n"); |
1256 | kfree(string); | ||
1256 | return 0; | 1257 | return 0; |
1257 | } | 1258 | } |
1258 | break; | 1259 | break; |
@@ -1475,7 +1476,7 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args, | |||
1475 | args->mount_server.addrlen = args->nfs_server.addrlen; | 1476 | args->mount_server.addrlen = args->nfs_server.addrlen; |
1476 | } | 1477 | } |
1477 | request.salen = args->mount_server.addrlen; | 1478 | request.salen = args->mount_server.addrlen; |
1478 | nfs_set_default_port(request.sap, args->mount_server.port, 0); | 1479 | nfs_set_port(request.sap, &args->mount_server.port, 0); |
1479 | 1480 | ||
1480 | /* | 1481 | /* |
1481 | * Now ask the mount server to map our export path | 1482 | * Now ask the mount server to map our export path |
@@ -1711,8 +1712,6 @@ static int nfs_validate_mount_data(void *options, | |||
1711 | 1712 | ||
1712 | if (!(data->flags & NFS_MOUNT_TCP)) | 1713 | if (!(data->flags & NFS_MOUNT_TCP)) |
1713 | args->nfs_server.protocol = XPRT_TRANSPORT_UDP; | 1714 | args->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
1714 | else | ||
1715 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; | ||
1716 | /* N.B. caller will free nfs_server.hostname in all cases */ | 1715 | /* N.B. caller will free nfs_server.hostname in all cases */ |
1717 | args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); | 1716 | args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); |
1718 | args->namlen = data->namlen; | 1717 | args->namlen = data->namlen; |
@@ -1767,7 +1766,7 @@ static int nfs_validate_mount_data(void *options, | |||
1767 | goto out_v4_not_compiled; | 1766 | goto out_v4_not_compiled; |
1768 | #endif | 1767 | #endif |
1769 | 1768 | ||
1770 | nfs_set_default_port(sap, args->nfs_server.port, 0); | 1769 | nfs_set_port(sap, &args->nfs_server.port, 0); |
1771 | 1770 | ||
1772 | nfs_set_mount_transport_protocol(args); | 1771 | nfs_set_mount_transport_protocol(args); |
1773 | 1772 | ||
@@ -1848,9 +1847,10 @@ nfs_compare_remount_data(struct nfs_server *nfss, | |||
1848 | data->acdirmin != nfss->acdirmin / HZ || | 1847 | data->acdirmin != nfss->acdirmin / HZ || |
1849 | data->acdirmax != nfss->acdirmax / HZ || | 1848 | data->acdirmax != nfss->acdirmax / HZ || |
1850 | data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) || | 1849 | data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) || |
1850 | data->nfs_server.port != nfss->port || | ||
1851 | data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen || | 1851 | data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen || |
1852 | memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr, | 1852 | !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address, |
1853 | data->nfs_server.addrlen) != 0) | 1853 | (struct sockaddr *)&nfss->nfs_client->cl_addr)) |
1854 | return -EINVAL; | 1854 | return -EINVAL; |
1855 | 1855 | ||
1856 | return 0; | 1856 | return 0; |
@@ -1893,6 +1893,7 @@ nfs_remount(struct super_block *sb, int *flags, char *raw_data) | |||
1893 | data->acdirmin = nfss->acdirmin / HZ; | 1893 | data->acdirmin = nfss->acdirmin / HZ; |
1894 | data->acdirmax = nfss->acdirmax / HZ; | 1894 | data->acdirmax = nfss->acdirmax / HZ; |
1895 | data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ; | 1895 | data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ; |
1896 | data->nfs_server.port = nfss->port; | ||
1896 | data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen; | 1897 | data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen; |
1897 | memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr, | 1898 | memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr, |
1898 | data->nfs_server.addrlen); | 1899 | data->nfs_server.addrlen); |
@@ -2106,7 +2107,7 @@ static int nfs_get_sb(struct file_system_type *fs_type, | |||
2106 | }; | 2107 | }; |
2107 | int error = -ENOMEM; | 2108 | int error = -ENOMEM; |
2108 | 2109 | ||
2109 | data = nfs_alloc_parsed_mount_data(NFS_MOUNT_VER3 | NFS_MOUNT_TCP); | 2110 | data = nfs_alloc_parsed_mount_data(3); |
2110 | mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL); | 2111 | mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL); |
2111 | if (data == NULL || mntfh == NULL) | 2112 | if (data == NULL || mntfh == NULL) |
2112 | goto out_free_fh; | 2113 | goto out_free_fh; |
@@ -2331,7 +2332,7 @@ static int nfs4_validate_text_mount_data(void *options, | |||
2331 | { | 2332 | { |
2332 | struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; | 2333 | struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; |
2333 | 2334 | ||
2334 | nfs_set_default_port(sap, args->nfs_server.port, NFS_PORT); | 2335 | nfs_set_port(sap, &args->nfs_server.port, NFS_PORT); |
2335 | 2336 | ||
2336 | nfs_validate_transport_protocol(args); | 2337 | nfs_validate_transport_protocol(args); |
2337 | 2338 | ||
@@ -2376,7 +2377,6 @@ static int nfs4_validate_mount_data(void *options, | |||
2376 | if (data == NULL) | 2377 | if (data == NULL) |
2377 | goto out_no_data; | 2378 | goto out_no_data; |
2378 | 2379 | ||
2379 | args->version = 4; | ||
2380 | switch (data->version) { | 2380 | switch (data->version) { |
2381 | case 1: | 2381 | case 1: |
2382 | if (data->host_addrlen > sizeof(args->nfs_server.address)) | 2382 | if (data->host_addrlen > sizeof(args->nfs_server.address)) |
@@ -2660,7 +2660,7 @@ static int nfs4_get_sb(struct file_system_type *fs_type, | |||
2660 | struct nfs_parsed_mount_data *data; | 2660 | struct nfs_parsed_mount_data *data; |
2661 | int error = -ENOMEM; | 2661 | int error = -ENOMEM; |
2662 | 2662 | ||
2663 | data = nfs_alloc_parsed_mount_data(0); | 2663 | data = nfs_alloc_parsed_mount_data(4); |
2664 | if (data == NULL) | 2664 | if (data == NULL) |
2665 | goto out_free_data; | 2665 | goto out_free_data; |
2666 | 2666 | ||
@@ -2690,7 +2690,6 @@ static void nfs4_kill_super(struct super_block *sb) | |||
2690 | dprintk("--> %s\n", __func__); | 2690 | dprintk("--> %s\n", __func__); |
2691 | nfs_super_return_all_delegations(sb); | 2691 | nfs_super_return_all_delegations(sb); |
2692 | kill_anon_super(sb); | 2692 | kill_anon_super(sb); |
2693 | nfs4_renewd_prepare_shutdown(server); | ||
2694 | nfs_fscache_release_super_cookie(sb); | 2693 | nfs_fscache_release_super_cookie(sb); |
2695 | nfs_free_server(server); | 2694 | nfs_free_server(server); |
2696 | dprintk("<-- %s\n", __func__); | 2695 | dprintk("<-- %s\n", __func__); |
diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c index edf926e1062f..d0a2ce1b4324 100644 --- a/fs/nfsd/nfs3xdr.c +++ b/fs/nfsd/nfs3xdr.c | |||
@@ -958,7 +958,7 @@ encode_entry(struct readdir_cd *ccd, const char *name, int namlen, | |||
958 | p1 = encode_entry_baggage(cd, p1, name, namlen, ino); | 958 | p1 = encode_entry_baggage(cd, p1, name, namlen, ino); |
959 | 959 | ||
960 | if (plus) | 960 | if (plus) |
961 | p = encode_entryplus_baggage(cd, p1, name, namlen); | 961 | p1 = encode_entryplus_baggage(cd, p1, name, namlen); |
962 | 962 | ||
963 | /* determine entry word length and lengths to go in pages */ | 963 | /* determine entry word length and lengths to go in pages */ |
964 | num_entry_words = p1 - tmp; | 964 | num_entry_words = p1 - tmp; |
diff --git a/fs/nilfs2/btnode.c b/fs/nilfs2/btnode.c index 5941958f1e47..84c25382f8e3 100644 --- a/fs/nilfs2/btnode.c +++ b/fs/nilfs2/btnode.c | |||
@@ -87,6 +87,7 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr, | |||
87 | brelse(bh); | 87 | brelse(bh); |
88 | BUG(); | 88 | BUG(); |
89 | } | 89 | } |
90 | memset(bh->b_data, 0, 1 << inode->i_blkbits); | ||
90 | bh->b_bdev = NILFS_I_NILFS(inode)->ns_bdev; | 91 | bh->b_bdev = NILFS_I_NILFS(inode)->ns_bdev; |
91 | bh->b_blocknr = blocknr; | 92 | bh->b_blocknr = blocknr; |
92 | set_buffer_mapped(bh); | 93 | set_buffer_mapped(bh); |
@@ -276,8 +277,7 @@ void nilfs_btnode_commit_change_key(struct address_space *btnc, | |||
276 | "invalid oldkey %lld (newkey=%lld)", | 277 | "invalid oldkey %lld (newkey=%lld)", |
277 | (unsigned long long)oldkey, | 278 | (unsigned long long)oldkey, |
278 | (unsigned long long)newkey); | 279 | (unsigned long long)newkey); |
279 | if (!test_set_buffer_dirty(obh) && TestSetPageDirty(opage)) | 280 | nilfs_btnode_mark_dirty(obh); |
280 | BUG(); | ||
281 | 281 | ||
282 | spin_lock_irq(&btnc->tree_lock); | 282 | spin_lock_irq(&btnc->tree_lock); |
283 | radix_tree_delete(&btnc->page_tree, oldkey); | 283 | radix_tree_delete(&btnc->page_tree, oldkey); |
diff --git a/fs/nilfs2/cpfile.c b/fs/nilfs2/cpfile.c index 1c6cfb59128d..3f5d5d06f53c 100644 --- a/fs/nilfs2/cpfile.c +++ b/fs/nilfs2/cpfile.c | |||
@@ -871,7 +871,6 @@ int nilfs_cpfile_change_cpmode(struct inode *cpfile, __u64 cno, int mode) | |||
871 | * exclusive with a new mount job. Though it doesn't cover | 871 | * exclusive with a new mount job. Though it doesn't cover |
872 | * umount, it's enough for the purpose. | 872 | * umount, it's enough for the purpose. |
873 | */ | 873 | */ |
874 | mutex_lock(&nilfs->ns_mount_mutex); | ||
875 | if (nilfs_checkpoint_is_mounted(nilfs, cno, 1)) { | 874 | if (nilfs_checkpoint_is_mounted(nilfs, cno, 1)) { |
876 | /* Current implementation does not have to protect | 875 | /* Current implementation does not have to protect |
877 | plain read-only mounts since they are exclusive | 876 | plain read-only mounts since they are exclusive |
@@ -880,7 +879,6 @@ int nilfs_cpfile_change_cpmode(struct inode *cpfile, __u64 cno, int mode) | |||
880 | ret = -EBUSY; | 879 | ret = -EBUSY; |
881 | } else | 880 | } else |
882 | ret = nilfs_cpfile_clear_snapshot(cpfile, cno); | 881 | ret = nilfs_cpfile_clear_snapshot(cpfile, cno); |
883 | mutex_unlock(&nilfs->ns_mount_mutex); | ||
884 | return ret; | 882 | return ret; |
885 | case NILFS_SNAPSHOT: | 883 | case NILFS_SNAPSHOT: |
886 | return nilfs_cpfile_set_snapshot(cpfile, cno); | 884 | return nilfs_cpfile_set_snapshot(cpfile, cno); |
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index 5040220c3732..2a0a5a3ac134 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c | |||
@@ -664,7 +664,6 @@ int nilfs_load_inode_block(struct nilfs_sb_info *sbi, struct inode *inode, | |||
664 | int err; | 664 | int err; |
665 | 665 | ||
666 | spin_lock(&sbi->s_inode_lock); | 666 | spin_lock(&sbi->s_inode_lock); |
667 | /* Caller of this function MUST lock s_inode_lock */ | ||
668 | if (ii->i_bh == NULL) { | 667 | if (ii->i_bh == NULL) { |
669 | spin_unlock(&sbi->s_inode_lock); | 668 | spin_unlock(&sbi->s_inode_lock); |
670 | err = nilfs_ifile_get_inode_block(sbi->s_ifile, inode->i_ino, | 669 | err = nilfs_ifile_get_inode_block(sbi->s_ifile, inode->i_ino, |
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c index 6572ea4bc4df..f6af76042d80 100644 --- a/fs/nilfs2/ioctl.c +++ b/fs/nilfs2/ioctl.c | |||
@@ -99,7 +99,8 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs, | |||
99 | static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp, | 99 | static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp, |
100 | unsigned int cmd, void __user *argp) | 100 | unsigned int cmd, void __user *argp) |
101 | { | 101 | { |
102 | struct inode *cpfile = NILFS_SB(inode->i_sb)->s_nilfs->ns_cpfile; | 102 | struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; |
103 | struct inode *cpfile = nilfs->ns_cpfile; | ||
103 | struct nilfs_transaction_info ti; | 104 | struct nilfs_transaction_info ti; |
104 | struct nilfs_cpmode cpmode; | 105 | struct nilfs_cpmode cpmode; |
105 | int ret; | 106 | int ret; |
@@ -109,14 +110,17 @@ static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp, | |||
109 | if (copy_from_user(&cpmode, argp, sizeof(cpmode))) | 110 | if (copy_from_user(&cpmode, argp, sizeof(cpmode))) |
110 | return -EFAULT; | 111 | return -EFAULT; |
111 | 112 | ||
113 | mutex_lock(&nilfs->ns_mount_mutex); | ||
112 | nilfs_transaction_begin(inode->i_sb, &ti, 0); | 114 | nilfs_transaction_begin(inode->i_sb, &ti, 0); |
113 | ret = nilfs_cpfile_change_cpmode( | 115 | ret = nilfs_cpfile_change_cpmode( |
114 | cpfile, cpmode.cm_cno, cpmode.cm_mode); | 116 | cpfile, cpmode.cm_cno, cpmode.cm_mode); |
115 | if (unlikely(ret < 0)) { | 117 | if (unlikely(ret < 0)) { |
116 | nilfs_transaction_abort(inode->i_sb); | 118 | nilfs_transaction_abort(inode->i_sb); |
119 | mutex_unlock(&nilfs->ns_mount_mutex); | ||
117 | return ret; | 120 | return ret; |
118 | } | 121 | } |
119 | nilfs_transaction_commit(inode->i_sb); /* never fails */ | 122 | nilfs_transaction_commit(inode->i_sb); /* never fails */ |
123 | mutex_unlock(&nilfs->ns_mount_mutex); | ||
120 | return ret; | 124 | return ret; |
121 | } | 125 | } |
122 | 126 | ||
@@ -297,7 +301,18 @@ static int nilfs_ioctl_move_inode_block(struct inode *inode, | |||
297 | (unsigned long long)vdesc->vd_vblocknr); | 301 | (unsigned long long)vdesc->vd_vblocknr); |
298 | return ret; | 302 | return ret; |
299 | } | 303 | } |
300 | bh->b_private = vdesc; | 304 | if (unlikely(!list_empty(&bh->b_assoc_buffers))) { |
305 | printk(KERN_CRIT "%s: conflicting %s buffer: ino=%llu, " | ||
306 | "cno=%llu, offset=%llu, blocknr=%llu, vblocknr=%llu\n", | ||
307 | __func__, vdesc->vd_flags ? "node" : "data", | ||
308 | (unsigned long long)vdesc->vd_ino, | ||
309 | (unsigned long long)vdesc->vd_cno, | ||
310 | (unsigned long long)vdesc->vd_offset, | ||
311 | (unsigned long long)vdesc->vd_blocknr, | ||
312 | (unsigned long long)vdesc->vd_vblocknr); | ||
313 | brelse(bh); | ||
314 | return -EEXIST; | ||
315 | } | ||
301 | list_add_tail(&bh->b_assoc_buffers, buffers); | 316 | list_add_tail(&bh->b_assoc_buffers, buffers); |
302 | return 0; | 317 | return 0; |
303 | } | 318 | } |
@@ -335,24 +350,10 @@ static int nilfs_ioctl_move_blocks(struct the_nilfs *nilfs, | |||
335 | list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) { | 350 | list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) { |
336 | ret = nilfs_gccache_wait_and_mark_dirty(bh); | 351 | ret = nilfs_gccache_wait_and_mark_dirty(bh); |
337 | if (unlikely(ret < 0)) { | 352 | if (unlikely(ret < 0)) { |
338 | if (ret == -EEXIST) { | 353 | WARN_ON(ret == -EEXIST); |
339 | vdesc = bh->b_private; | ||
340 | printk(KERN_CRIT | ||
341 | "%s: conflicting %s buffer: " | ||
342 | "ino=%llu, cno=%llu, offset=%llu, " | ||
343 | "blocknr=%llu, vblocknr=%llu\n", | ||
344 | __func__, | ||
345 | vdesc->vd_flags ? "node" : "data", | ||
346 | (unsigned long long)vdesc->vd_ino, | ||
347 | (unsigned long long)vdesc->vd_cno, | ||
348 | (unsigned long long)vdesc->vd_offset, | ||
349 | (unsigned long long)vdesc->vd_blocknr, | ||
350 | (unsigned long long)vdesc->vd_vblocknr); | ||
351 | } | ||
352 | goto failed; | 354 | goto failed; |
353 | } | 355 | } |
354 | list_del_init(&bh->b_assoc_buffers); | 356 | list_del_init(&bh->b_assoc_buffers); |
355 | bh->b_private = NULL; | ||
356 | brelse(bh); | 357 | brelse(bh); |
357 | } | 358 | } |
358 | return nmembs; | 359 | return nmembs; |
@@ -360,7 +361,6 @@ static int nilfs_ioctl_move_blocks(struct the_nilfs *nilfs, | |||
360 | failed: | 361 | failed: |
361 | list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) { | 362 | list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) { |
362 | list_del_init(&bh->b_assoc_buffers); | 363 | list_del_init(&bh->b_assoc_buffers); |
363 | bh->b_private = NULL; | ||
364 | brelse(bh); | 364 | brelse(bh); |
365 | } | 365 | } |
366 | return ret; | 366 | return ret; |
@@ -471,7 +471,6 @@ int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *nilfs, | |||
471 | return 0; | 471 | return 0; |
472 | 472 | ||
473 | failed: | 473 | failed: |
474 | nilfs_remove_all_gcinode(nilfs); | ||
475 | printk(KERN_ERR "NILFS: GC failed during preparation: %s: err=%d\n", | 474 | printk(KERN_ERR "NILFS: GC failed during preparation: %s: err=%d\n", |
476 | msg, ret); | 475 | msg, ret); |
477 | return ret; | 476 | return ret; |
@@ -560,6 +559,8 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp, | |||
560 | else | 559 | else |
561 | ret = nilfs_clean_segments(inode->i_sb, argv, kbufs); | 560 | ret = nilfs_clean_segments(inode->i_sb, argv, kbufs); |
562 | 561 | ||
562 | if (ret < 0) | ||
563 | nilfs_remove_all_gcinode(nilfs); | ||
563 | clear_nilfs_gc_running(nilfs); | 564 | clear_nilfs_gc_running(nilfs); |
564 | 565 | ||
565 | out_free: | 566 | out_free: |
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index 683df89dbae5..6eff66a070d5 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c | |||
@@ -2468,17 +2468,22 @@ static void nilfs_segctor_notify(struct nilfs_sc_info *sci, | |||
2468 | /* Clear requests (even when the construction failed) */ | 2468 | /* Clear requests (even when the construction failed) */ |
2469 | spin_lock(&sci->sc_state_lock); | 2469 | spin_lock(&sci->sc_state_lock); |
2470 | 2470 | ||
2471 | sci->sc_state &= ~NILFS_SEGCTOR_COMMIT; | ||
2472 | |||
2473 | if (req->mode == SC_LSEG_SR) { | 2471 | if (req->mode == SC_LSEG_SR) { |
2472 | sci->sc_state &= ~NILFS_SEGCTOR_COMMIT; | ||
2474 | sci->sc_seq_done = req->seq_accepted; | 2473 | sci->sc_seq_done = req->seq_accepted; |
2475 | nilfs_segctor_wakeup(sci, req->sc_err ? : req->sb_err); | 2474 | nilfs_segctor_wakeup(sci, req->sc_err ? : req->sb_err); |
2476 | sci->sc_flush_request = 0; | 2475 | sci->sc_flush_request = 0; |
2477 | } else if (req->mode == SC_FLUSH_FILE) | 2476 | } else { |
2478 | sci->sc_flush_request &= ~FLUSH_FILE_BIT; | 2477 | if (req->mode == SC_FLUSH_FILE) |
2479 | else if (req->mode == SC_FLUSH_DAT) | 2478 | sci->sc_flush_request &= ~FLUSH_FILE_BIT; |
2480 | sci->sc_flush_request &= ~FLUSH_DAT_BIT; | 2479 | else if (req->mode == SC_FLUSH_DAT) |
2480 | sci->sc_flush_request &= ~FLUSH_DAT_BIT; | ||
2481 | 2481 | ||
2482 | /* re-enable timer if checkpoint creation was not done */ | ||
2483 | if (sci->sc_timer && (sci->sc_state & NILFS_SEGCTOR_COMMIT) && | ||
2484 | time_before(jiffies, sci->sc_timer->expires)) | ||
2485 | add_timer(sci->sc_timer); | ||
2486 | } | ||
2482 | spin_unlock(&sci->sc_state_lock); | 2487 | spin_unlock(&sci->sc_state_lock); |
2483 | } | 2488 | } |
2484 | 2489 | ||
diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c index 828a889be909..7e54e52964dd 100644 --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c | |||
@@ -91,6 +91,7 @@ static int dnotify_handle_event(struct fsnotify_group *group, | |||
91 | struct dnotify_struct *dn; | 91 | struct dnotify_struct *dn; |
92 | struct dnotify_struct **prev; | 92 | struct dnotify_struct **prev; |
93 | struct fown_struct *fown; | 93 | struct fown_struct *fown; |
94 | __u32 test_mask = event->mask & ~FS_EVENT_ON_CHILD; | ||
94 | 95 | ||
95 | to_tell = event->to_tell; | 96 | to_tell = event->to_tell; |
96 | 97 | ||
@@ -106,7 +107,7 @@ static int dnotify_handle_event(struct fsnotify_group *group, | |||
106 | spin_lock(&entry->lock); | 107 | spin_lock(&entry->lock); |
107 | prev = &dnentry->dn; | 108 | prev = &dnentry->dn; |
108 | while ((dn = *prev) != NULL) { | 109 | while ((dn = *prev) != NULL) { |
109 | if ((dn->dn_mask & event->mask) == 0) { | 110 | if ((dn->dn_mask & test_mask) == 0) { |
110 | prev = &dn->dn_next; | 111 | prev = &dn->dn_next; |
111 | continue; | 112 | continue; |
112 | } | 113 | } |
diff --git a/fs/notify/inode_mark.c b/fs/notify/inode_mark.c index c8a07c65482b..3165d85aada2 100644 --- a/fs/notify/inode_mark.c +++ b/fs/notify/inode_mark.c | |||
@@ -324,11 +324,11 @@ int fsnotify_add_mark(struct fsnotify_mark_entry *entry, | |||
324 | spin_lock(&group->mark_lock); | 324 | spin_lock(&group->mark_lock); |
325 | spin_lock(&inode->i_lock); | 325 | spin_lock(&inode->i_lock); |
326 | 326 | ||
327 | entry->group = group; | ||
328 | entry->inode = inode; | ||
329 | |||
330 | lentry = fsnotify_find_mark_entry(group, inode); | 327 | lentry = fsnotify_find_mark_entry(group, inode); |
331 | if (!lentry) { | 328 | if (!lentry) { |
329 | entry->group = group; | ||
330 | entry->inode = inode; | ||
331 | |||
332 | hlist_add_head(&entry->i_list, &inode->i_fsnotify_mark_entries); | 332 | hlist_add_head(&entry->i_list, &inode->i_fsnotify_mark_entries); |
333 | list_add(&entry->g_list, &group->mark_entries); | 333 | list_add(&entry->g_list, &group->mark_entries); |
334 | 334 | ||
diff --git a/fs/notify/notification.c b/fs/notify/notification.c index 3816d5750dd5..b8bf53b4c108 100644 --- a/fs/notify/notification.c +++ b/fs/notify/notification.c | |||
@@ -143,7 +143,7 @@ static bool event_compare(struct fsnotify_event *old, struct fsnotify_event *new | |||
143 | /* remember, after old was put on the wait_q we aren't | 143 | /* remember, after old was put on the wait_q we aren't |
144 | * allowed to look at the inode any more, only thing | 144 | * allowed to look at the inode any more, only thing |
145 | * left to check was if the file_name is the same */ | 145 | * left to check was if the file_name is the same */ |
146 | if (old->name_len && | 146 | if (!old->name_len || |
147 | !strcmp(old->file_name, new->file_name)) | 147 | !strcmp(old->file_name, new->file_name)) |
148 | return true; | 148 | return true; |
149 | break; | 149 | break; |
diff --git a/fs/partitions/check.c b/fs/partitions/check.c index f38fee0311a7..7b685e10cbad 100644 --- a/fs/partitions/check.c +++ b/fs/partitions/check.c | |||
@@ -248,11 +248,19 @@ ssize_t part_stat_show(struct device *dev, | |||
248 | part_stat_read(p, merges[WRITE]), | 248 | part_stat_read(p, merges[WRITE]), |
249 | (unsigned long long)part_stat_read(p, sectors[WRITE]), | 249 | (unsigned long long)part_stat_read(p, sectors[WRITE]), |
250 | jiffies_to_msecs(part_stat_read(p, ticks[WRITE])), | 250 | jiffies_to_msecs(part_stat_read(p, ticks[WRITE])), |
251 | p->in_flight, | 251 | part_in_flight(p), |
252 | jiffies_to_msecs(part_stat_read(p, io_ticks)), | 252 | jiffies_to_msecs(part_stat_read(p, io_ticks)), |
253 | jiffies_to_msecs(part_stat_read(p, time_in_queue))); | 253 | jiffies_to_msecs(part_stat_read(p, time_in_queue))); |
254 | } | 254 | } |
255 | 255 | ||
256 | ssize_t part_inflight_show(struct device *dev, | ||
257 | struct device_attribute *attr, char *buf) | ||
258 | { | ||
259 | struct hd_struct *p = dev_to_part(dev); | ||
260 | |||
261 | return sprintf(buf, "%8u %8u\n", p->in_flight[0], p->in_flight[1]); | ||
262 | } | ||
263 | |||
256 | #ifdef CONFIG_FAIL_MAKE_REQUEST | 264 | #ifdef CONFIG_FAIL_MAKE_REQUEST |
257 | ssize_t part_fail_show(struct device *dev, | 265 | ssize_t part_fail_show(struct device *dev, |
258 | struct device_attribute *attr, char *buf) | 266 | struct device_attribute *attr, char *buf) |
@@ -281,6 +289,7 @@ static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL); | |||
281 | static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL); | 289 | static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL); |
282 | static DEVICE_ATTR(alignment_offset, S_IRUGO, part_alignment_offset_show, NULL); | 290 | static DEVICE_ATTR(alignment_offset, S_IRUGO, part_alignment_offset_show, NULL); |
283 | static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL); | 291 | static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL); |
292 | static DEVICE_ATTR(inflight, S_IRUGO, part_inflight_show, NULL); | ||
284 | #ifdef CONFIG_FAIL_MAKE_REQUEST | 293 | #ifdef CONFIG_FAIL_MAKE_REQUEST |
285 | static struct device_attribute dev_attr_fail = | 294 | static struct device_attribute dev_attr_fail = |
286 | __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store); | 295 | __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store); |
@@ -292,6 +301,7 @@ static struct attribute *part_attrs[] = { | |||
292 | &dev_attr_size.attr, | 301 | &dev_attr_size.attr, |
293 | &dev_attr_alignment_offset.attr, | 302 | &dev_attr_alignment_offset.attr, |
294 | &dev_attr_stat.attr, | 303 | &dev_attr_stat.attr, |
304 | &dev_attr_inflight.attr, | ||
295 | #ifdef CONFIG_FAIL_MAKE_REQUEST | 305 | #ifdef CONFIG_FAIL_MAKE_REQUEST |
296 | &dev_attr_fail.attr, | 306 | &dev_attr_fail.attr, |
297 | #endif | 307 | #endif |
@@ -777,36 +777,55 @@ pipe_rdwr_release(struct inode *inode, struct file *filp) | |||
777 | static int | 777 | static int |
778 | pipe_read_open(struct inode *inode, struct file *filp) | 778 | pipe_read_open(struct inode *inode, struct file *filp) |
779 | { | 779 | { |
780 | /* We could have perhaps used atomic_t, but this and friends | 780 | int ret = -ENOENT; |
781 | below are the only places. So it doesn't seem worthwhile. */ | 781 | |
782 | mutex_lock(&inode->i_mutex); | 782 | mutex_lock(&inode->i_mutex); |
783 | inode->i_pipe->readers++; | 783 | |
784 | if (inode->i_pipe) { | ||
785 | ret = 0; | ||
786 | inode->i_pipe->readers++; | ||
787 | } | ||
788 | |||
784 | mutex_unlock(&inode->i_mutex); | 789 | mutex_unlock(&inode->i_mutex); |
785 | 790 | ||
786 | return 0; | 791 | return ret; |
787 | } | 792 | } |
788 | 793 | ||
789 | static int | 794 | static int |
790 | pipe_write_open(struct inode *inode, struct file *filp) | 795 | pipe_write_open(struct inode *inode, struct file *filp) |
791 | { | 796 | { |
797 | int ret = -ENOENT; | ||
798 | |||
792 | mutex_lock(&inode->i_mutex); | 799 | mutex_lock(&inode->i_mutex); |
793 | inode->i_pipe->writers++; | 800 | |
801 | if (inode->i_pipe) { | ||
802 | ret = 0; | ||
803 | inode->i_pipe->writers++; | ||
804 | } | ||
805 | |||
794 | mutex_unlock(&inode->i_mutex); | 806 | mutex_unlock(&inode->i_mutex); |
795 | 807 | ||
796 | return 0; | 808 | return ret; |
797 | } | 809 | } |
798 | 810 | ||
799 | static int | 811 | static int |
800 | pipe_rdwr_open(struct inode *inode, struct file *filp) | 812 | pipe_rdwr_open(struct inode *inode, struct file *filp) |
801 | { | 813 | { |
814 | int ret = -ENOENT; | ||
815 | |||
802 | mutex_lock(&inode->i_mutex); | 816 | mutex_lock(&inode->i_mutex); |
803 | if (filp->f_mode & FMODE_READ) | 817 | |
804 | inode->i_pipe->readers++; | 818 | if (inode->i_pipe) { |
805 | if (filp->f_mode & FMODE_WRITE) | 819 | ret = 0; |
806 | inode->i_pipe->writers++; | 820 | if (filp->f_mode & FMODE_READ) |
821 | inode->i_pipe->readers++; | ||
822 | if (filp->f_mode & FMODE_WRITE) | ||
823 | inode->i_pipe->writers++; | ||
824 | } | ||
825 | |||
807 | mutex_unlock(&inode->i_mutex); | 826 | mutex_unlock(&inode->i_mutex); |
808 | 827 | ||
809 | return 0; | 828 | return ret; |
810 | } | 829 | } |
811 | 830 | ||
812 | /* | 831 | /* |
diff --git a/fs/proc/array.c b/fs/proc/array.c index 07f77a7945c3..822c2d506518 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c | |||
@@ -571,7 +571,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, | |||
571 | rsslim, | 571 | rsslim, |
572 | mm ? mm->start_code : 0, | 572 | mm ? mm->start_code : 0, |
573 | mm ? mm->end_code : 0, | 573 | mm ? mm->end_code : 0, |
574 | (permitted) ? task->stack_start : 0, | 574 | (permitted && mm) ? task->stack_start : 0, |
575 | esp, | 575 | esp, |
576 | eip, | 576 | eip, |
577 | /* The signal information here is obsolete. | 577 | /* The signal information here is obsolete. |
diff --git a/fs/proc/base.c b/fs/proc/base.c index 837469a96598..af643b5aefe8 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -2597,8 +2597,7 @@ static void proc_flush_task_mnt(struct vfsmount *mnt, pid_t pid, pid_t tgid) | |||
2597 | name.len = snprintf(buf, sizeof(buf), "%d", pid); | 2597 | name.len = snprintf(buf, sizeof(buf), "%d", pid); |
2598 | dentry = d_hash_and_lookup(mnt->mnt_root, &name); | 2598 | dentry = d_hash_and_lookup(mnt->mnt_root, &name); |
2599 | if (dentry) { | 2599 | if (dentry) { |
2600 | if (!(current->flags & PF_EXITING)) | 2600 | shrink_dcache_parent(dentry); |
2601 | shrink_dcache_parent(dentry); | ||
2602 | d_drop(dentry); | 2601 | d_drop(dentry); |
2603 | dput(dentry); | 2602 | dput(dentry); |
2604 | } | 2603 | } |
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index 56013371f9f3..a44a7897fd4d 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include <asm/io.h> | 23 | #include <asm/io.h> |
24 | #include <linux/list.h> | 24 | #include <linux/list.h> |
25 | #include <linux/ioport.h> | 25 | #include <linux/ioport.h> |
26 | #include <linux/mm.h> | ||
27 | #include <linux/memory.h> | 26 | #include <linux/memory.h> |
28 | #include <asm/sections.h> | 27 | #include <asm/sections.h> |
29 | 28 | ||
diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index c7bff4f603ff..a65239cfd97e 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c | |||
@@ -99,7 +99,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) | |||
99 | "VmallocUsed: %8lu kB\n" | 99 | "VmallocUsed: %8lu kB\n" |
100 | "VmallocChunk: %8lu kB\n" | 100 | "VmallocChunk: %8lu kB\n" |
101 | #ifdef CONFIG_MEMORY_FAILURE | 101 | #ifdef CONFIG_MEMORY_FAILURE |
102 | "HardwareCorrupted: %8lu kB\n" | 102 | "HardwareCorrupted: %5lu kB\n" |
103 | #endif | 103 | #endif |
104 | , | 104 | , |
105 | K(i.totalram), | 105 | K(i.totalram), |
diff --git a/fs/proc/page.c b/fs/proc/page.c index 2281c2cbfe2b..5033ce0d254b 100644 --- a/fs/proc/page.c +++ b/fs/proc/page.c | |||
@@ -94,6 +94,7 @@ static const struct file_operations proc_kpagecount_operations = { | |||
94 | #define KPF_COMPOUND_TAIL 16 | 94 | #define KPF_COMPOUND_TAIL 16 |
95 | #define KPF_HUGE 17 | 95 | #define KPF_HUGE 17 |
96 | #define KPF_UNEVICTABLE 18 | 96 | #define KPF_UNEVICTABLE 18 |
97 | #define KPF_HWPOISON 19 | ||
97 | #define KPF_NOPAGE 20 | 98 | #define KPF_NOPAGE 20 |
98 | 99 | ||
99 | #define KPF_KSM 21 | 100 | #define KPF_KSM 21 |
@@ -180,6 +181,10 @@ static u64 get_uflags(struct page *page) | |||
180 | u |= kpf_copy_bit(k, KPF_UNEVICTABLE, PG_unevictable); | 181 | u |= kpf_copy_bit(k, KPF_UNEVICTABLE, PG_unevictable); |
181 | u |= kpf_copy_bit(k, KPF_MLOCKED, PG_mlocked); | 182 | u |= kpf_copy_bit(k, KPF_MLOCKED, PG_mlocked); |
182 | 183 | ||
184 | #ifdef CONFIG_MEMORY_FAILURE | ||
185 | u |= kpf_copy_bit(k, KPF_HWPOISON, PG_hwpoison); | ||
186 | #endif | ||
187 | |||
183 | #ifdef CONFIG_IA64_UNCACHED_ALLOCATOR | 188 | #ifdef CONFIG_IA64_UNCACHED_ALLOCATOR |
184 | u |= kpf_copy_bit(k, KPF_UNCACHED, PG_uncached); | 189 | u |= kpf_copy_bit(k, KPF_UNCACHED, PG_uncached); |
185 | #endif | 190 | #endif |
diff --git a/fs/romfs/storage.c b/fs/romfs/storage.c index b3208adf8e71..71e2b4d50a0a 100644 --- a/fs/romfs/storage.c +++ b/fs/romfs/storage.c | |||
@@ -253,11 +253,11 @@ ssize_t romfs_dev_strnlen(struct super_block *sb, | |||
253 | 253 | ||
254 | #ifdef CONFIG_ROMFS_ON_MTD | 254 | #ifdef CONFIG_ROMFS_ON_MTD |
255 | if (sb->s_mtd) | 255 | if (sb->s_mtd) |
256 | return romfs_mtd_strnlen(sb, pos, limit); | 256 | return romfs_mtd_strnlen(sb, pos, maxlen); |
257 | #endif | 257 | #endif |
258 | #ifdef CONFIG_ROMFS_ON_BLOCK | 258 | #ifdef CONFIG_ROMFS_ON_BLOCK |
259 | if (sb->s_bdev) | 259 | if (sb->s_bdev) |
260 | return romfs_blk_strnlen(sb, pos, limit); | 260 | return romfs_blk_strnlen(sb, pos, maxlen); |
261 | #endif | 261 | #endif |
262 | return -EIO; | 262 | return -EIO; |
263 | } | 263 | } |
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index 0050fc40e8c9..e0201837d244 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/completion.h> | 21 | #include <linux/completion.h> |
22 | #include <linux/mutex.h> | 22 | #include <linux/mutex.h> |
23 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
24 | #include <linux/security.h> | ||
24 | #include "sysfs.h" | 25 | #include "sysfs.h" |
25 | 26 | ||
26 | DEFINE_MUTEX(sysfs_mutex); | 27 | DEFINE_MUTEX(sysfs_mutex); |
@@ -285,6 +286,9 @@ void release_sysfs_dirent(struct sysfs_dirent * sd) | |||
285 | sysfs_put(sd->s_symlink.target_sd); | 286 | sysfs_put(sd->s_symlink.target_sd); |
286 | if (sysfs_type(sd) & SYSFS_COPY_NAME) | 287 | if (sysfs_type(sd) & SYSFS_COPY_NAME) |
287 | kfree(sd->s_name); | 288 | kfree(sd->s_name); |
289 | if (sd->s_iattr && sd->s_iattr->ia_secdata) | ||
290 | security_release_secctx(sd->s_iattr->ia_secdata, | ||
291 | sd->s_iattr->ia_secdata_len); | ||
288 | kfree(sd->s_iattr); | 292 | kfree(sd->s_iattr); |
289 | sysfs_free_ino(sd->s_ino); | 293 | sysfs_free_ino(sd->s_ino); |
290 | kmem_cache_free(sysfs_dir_cachep, sd); | 294 | kmem_cache_free(sysfs_dir_cachep, sd); |
@@ -894,7 +898,8 @@ int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj) | |||
894 | 898 | ||
895 | mutex_lock(&sysfs_rename_mutex); | 899 | mutex_lock(&sysfs_rename_mutex); |
896 | BUG_ON(!sd->s_parent); | 900 | BUG_ON(!sd->s_parent); |
897 | new_parent_sd = new_parent_kobj->sd ? new_parent_kobj->sd : &sysfs_root; | 901 | new_parent_sd = (new_parent_kobj && new_parent_kobj->sd) ? |
902 | new_parent_kobj->sd : &sysfs_root; | ||
898 | 903 | ||
899 | error = 0; | 904 | error = 0; |
900 | if (sd->s_parent == new_parent_sd) | 905 | if (sd->s_parent == new_parent_sd) |
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 561a9c050cef..f5ea4680f15f 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -268,7 +268,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd, | |||
268 | struct sysfs_open_dirent *od, *new_od = NULL; | 268 | struct sysfs_open_dirent *od, *new_od = NULL; |
269 | 269 | ||
270 | retry: | 270 | retry: |
271 | spin_lock(&sysfs_open_dirent_lock); | 271 | spin_lock_irq(&sysfs_open_dirent_lock); |
272 | 272 | ||
273 | if (!sd->s_attr.open && new_od) { | 273 | if (!sd->s_attr.open && new_od) { |
274 | sd->s_attr.open = new_od; | 274 | sd->s_attr.open = new_od; |
@@ -281,7 +281,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd, | |||
281 | list_add_tail(&buffer->list, &od->buffers); | 281 | list_add_tail(&buffer->list, &od->buffers); |
282 | } | 282 | } |
283 | 283 | ||
284 | spin_unlock(&sysfs_open_dirent_lock); | 284 | spin_unlock_irq(&sysfs_open_dirent_lock); |
285 | 285 | ||
286 | if (od) { | 286 | if (od) { |
287 | kfree(new_od); | 287 | kfree(new_od); |
@@ -315,8 +315,9 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd, | |||
315 | struct sysfs_buffer *buffer) | 315 | struct sysfs_buffer *buffer) |
316 | { | 316 | { |
317 | struct sysfs_open_dirent *od = sd->s_attr.open; | 317 | struct sysfs_open_dirent *od = sd->s_attr.open; |
318 | unsigned long flags; | ||
318 | 319 | ||
319 | spin_lock(&sysfs_open_dirent_lock); | 320 | spin_lock_irqsave(&sysfs_open_dirent_lock, flags); |
320 | 321 | ||
321 | list_del(&buffer->list); | 322 | list_del(&buffer->list); |
322 | if (atomic_dec_and_test(&od->refcnt)) | 323 | if (atomic_dec_and_test(&od->refcnt)) |
@@ -324,7 +325,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd, | |||
324 | else | 325 | else |
325 | od = NULL; | 326 | od = NULL; |
326 | 327 | ||
327 | spin_unlock(&sysfs_open_dirent_lock); | 328 | spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags); |
328 | 329 | ||
329 | kfree(od); | 330 | kfree(od); |
330 | } | 331 | } |
@@ -456,8 +457,9 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait) | |||
456 | void sysfs_notify_dirent(struct sysfs_dirent *sd) | 457 | void sysfs_notify_dirent(struct sysfs_dirent *sd) |
457 | { | 458 | { |
458 | struct sysfs_open_dirent *od; | 459 | struct sysfs_open_dirent *od; |
460 | unsigned long flags; | ||
459 | 461 | ||
460 | spin_lock(&sysfs_open_dirent_lock); | 462 | spin_lock_irqsave(&sysfs_open_dirent_lock, flags); |
461 | 463 | ||
462 | od = sd->s_attr.open; | 464 | od = sd->s_attr.open; |
463 | if (od) { | 465 | if (od) { |
@@ -465,7 +467,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd) | |||
465 | wake_up_interruptible(&od->poll); | 467 | wake_up_interruptible(&od->poll); |
466 | } | 468 | } |
467 | 469 | ||
468 | spin_unlock(&sysfs_open_dirent_lock); | 470 | spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags); |
469 | } | 471 | } |
470 | EXPORT_SYMBOL_GPL(sysfs_notify_dirent); | 472 | EXPORT_SYMBOL_GPL(sysfs_notify_dirent); |
471 | 473 | ||
diff --git a/fs/xfs/linux-2.6/xfs_aops.c b/fs/xfs/linux-2.6/xfs_aops.c index 381854461b28..c2e30eea74dc 100644 --- a/fs/xfs/linux-2.6/xfs_aops.c +++ b/fs/xfs/linux-2.6/xfs_aops.c | |||
@@ -186,19 +186,37 @@ xfs_destroy_ioend( | |||
186 | } | 186 | } |
187 | 187 | ||
188 | /* | 188 | /* |
189 | * If the end of the current ioend is beyond the current EOF, | ||
190 | * return the new EOF value, otherwise zero. | ||
191 | */ | ||
192 | STATIC xfs_fsize_t | ||
193 | xfs_ioend_new_eof( | ||
194 | xfs_ioend_t *ioend) | ||
195 | { | ||
196 | xfs_inode_t *ip = XFS_I(ioend->io_inode); | ||
197 | xfs_fsize_t isize; | ||
198 | xfs_fsize_t bsize; | ||
199 | |||
200 | bsize = ioend->io_offset + ioend->io_size; | ||
201 | isize = MAX(ip->i_size, ip->i_new_size); | ||
202 | isize = MIN(isize, bsize); | ||
203 | return isize > ip->i_d.di_size ? isize : 0; | ||
204 | } | ||
205 | |||
206 | /* | ||
189 | * Update on-disk file size now that data has been written to disk. | 207 | * Update on-disk file size now that data has been written to disk. |
190 | * The current in-memory file size is i_size. If a write is beyond | 208 | * The current in-memory file size is i_size. If a write is beyond |
191 | * eof i_new_size will be the intended file size until i_size is | 209 | * eof i_new_size will be the intended file size until i_size is |
192 | * updated. If this write does not extend all the way to the valid | 210 | * updated. If this write does not extend all the way to the valid |
193 | * file size then restrict this update to the end of the write. | 211 | * file size then restrict this update to the end of the write. |
194 | */ | 212 | */ |
213 | |||
195 | STATIC void | 214 | STATIC void |
196 | xfs_setfilesize( | 215 | xfs_setfilesize( |
197 | xfs_ioend_t *ioend) | 216 | xfs_ioend_t *ioend) |
198 | { | 217 | { |
199 | xfs_inode_t *ip = XFS_I(ioend->io_inode); | 218 | xfs_inode_t *ip = XFS_I(ioend->io_inode); |
200 | xfs_fsize_t isize; | 219 | xfs_fsize_t isize; |
201 | xfs_fsize_t bsize; | ||
202 | 220 | ||
203 | ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG); | 221 | ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG); |
204 | ASSERT(ioend->io_type != IOMAP_READ); | 222 | ASSERT(ioend->io_type != IOMAP_READ); |
@@ -206,16 +224,10 @@ xfs_setfilesize( | |||
206 | if (unlikely(ioend->io_error)) | 224 | if (unlikely(ioend->io_error)) |
207 | return; | 225 | return; |
208 | 226 | ||
209 | bsize = ioend->io_offset + ioend->io_size; | ||
210 | |||
211 | xfs_ilock(ip, XFS_ILOCK_EXCL); | 227 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
212 | 228 | isize = xfs_ioend_new_eof(ioend); | |
213 | isize = MAX(ip->i_size, ip->i_new_size); | 229 | if (isize) { |
214 | isize = MIN(isize, bsize); | ||
215 | |||
216 | if (ip->i_d.di_size < isize) { | ||
217 | ip->i_d.di_size = isize; | 230 | ip->i_d.di_size = isize; |
218 | ip->i_update_core = 1; | ||
219 | xfs_mark_inode_dirty_sync(ip); | 231 | xfs_mark_inode_dirty_sync(ip); |
220 | } | 232 | } |
221 | 233 | ||
@@ -404,10 +416,16 @@ xfs_submit_ioend_bio( | |||
404 | struct bio *bio) | 416 | struct bio *bio) |
405 | { | 417 | { |
406 | atomic_inc(&ioend->io_remaining); | 418 | atomic_inc(&ioend->io_remaining); |
407 | |||
408 | bio->bi_private = ioend; | 419 | bio->bi_private = ioend; |
409 | bio->bi_end_io = xfs_end_bio; | 420 | bio->bi_end_io = xfs_end_bio; |
410 | 421 | ||
422 | /* | ||
423 | * If the I/O is beyond EOF we mark the inode dirty immediately | ||
424 | * but don't update the inode size until I/O completion. | ||
425 | */ | ||
426 | if (xfs_ioend_new_eof(ioend)) | ||
427 | xfs_mark_inode_dirty_sync(XFS_I(ioend->io_inode)); | ||
428 | |||
411 | submit_bio(WRITE, bio); | 429 | submit_bio(WRITE, bio); |
412 | ASSERT(!bio_flagged(bio, BIO_EOPNOTSUPP)); | 430 | ASSERT(!bio_flagged(bio, BIO_EOPNOTSUPP)); |
413 | bio_put(bio); | 431 | bio_put(bio); |
diff --git a/fs/xfs/linux-2.6/xfs_file.c b/fs/xfs/linux-2.6/xfs_file.c index 629370974e57..eff61e2732af 100644 --- a/fs/xfs/linux-2.6/xfs_file.c +++ b/fs/xfs/linux-2.6/xfs_file.c | |||
@@ -176,14 +176,7 @@ xfs_file_fsync( | |||
176 | struct dentry *dentry, | 176 | struct dentry *dentry, |
177 | int datasync) | 177 | int datasync) |
178 | { | 178 | { |
179 | struct inode *inode = dentry->d_inode; | 179 | struct xfs_inode *ip = XFS_I(dentry->d_inode); |
180 | struct xfs_inode *ip = XFS_I(inode); | ||
181 | int error; | ||
182 | |||
183 | /* capture size updates in I/O completion before writing the inode. */ | ||
184 | error = filemap_fdatawait(inode->i_mapping); | ||
185 | if (error) | ||
186 | return error; | ||
187 | 180 | ||
188 | xfs_iflags_clear(ip, XFS_ITRUNCATED); | 181 | xfs_iflags_clear(ip, XFS_ITRUNCATED); |
189 | return -xfs_fsync(ip); | 182 | return -xfs_fsync(ip); |
diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c index da0159d99f82..cd42ef78f6b5 100644 --- a/fs/xfs/linux-2.6/xfs_iops.c +++ b/fs/xfs/linux-2.6/xfs_iops.c | |||
@@ -57,19 +57,22 @@ | |||
57 | #include <linux/fiemap.h> | 57 | #include <linux/fiemap.h> |
58 | 58 | ||
59 | /* | 59 | /* |
60 | * Bring the atime in the XFS inode uptodate. | 60 | * Bring the timestamps in the XFS inode uptodate. |
61 | * Used before logging the inode to disk or when the Linux inode goes away. | 61 | * |
62 | * Used before writing the inode to disk. | ||
62 | */ | 63 | */ |
63 | void | 64 | void |
64 | xfs_synchronize_atime( | 65 | xfs_synchronize_times( |
65 | xfs_inode_t *ip) | 66 | xfs_inode_t *ip) |
66 | { | 67 | { |
67 | struct inode *inode = VFS_I(ip); | 68 | struct inode *inode = VFS_I(ip); |
68 | 69 | ||
69 | if (!(inode->i_state & I_CLEAR)) { | 70 | ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec; |
70 | ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec; | 71 | ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec; |
71 | ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec; | 72 | ip->i_d.di_ctime.t_sec = (__int32_t)inode->i_ctime.tv_sec; |
72 | } | 73 | ip->i_d.di_ctime.t_nsec = (__int32_t)inode->i_ctime.tv_nsec; |
74 | ip->i_d.di_mtime.t_sec = (__int32_t)inode->i_mtime.tv_sec; | ||
75 | ip->i_d.di_mtime.t_nsec = (__int32_t)inode->i_mtime.tv_nsec; | ||
73 | } | 76 | } |
74 | 77 | ||
75 | /* | 78 | /* |
@@ -106,32 +109,20 @@ xfs_ichgtime( | |||
106 | if ((flags & XFS_ICHGTIME_MOD) && | 109 | if ((flags & XFS_ICHGTIME_MOD) && |
107 | !timespec_equal(&inode->i_mtime, &tv)) { | 110 | !timespec_equal(&inode->i_mtime, &tv)) { |
108 | inode->i_mtime = tv; | 111 | inode->i_mtime = tv; |
109 | ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec; | ||
110 | ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec; | ||
111 | sync_it = 1; | 112 | sync_it = 1; |
112 | } | 113 | } |
113 | if ((flags & XFS_ICHGTIME_CHG) && | 114 | if ((flags & XFS_ICHGTIME_CHG) && |
114 | !timespec_equal(&inode->i_ctime, &tv)) { | 115 | !timespec_equal(&inode->i_ctime, &tv)) { |
115 | inode->i_ctime = tv; | 116 | inode->i_ctime = tv; |
116 | ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec; | ||
117 | ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec; | ||
118 | sync_it = 1; | 117 | sync_it = 1; |
119 | } | 118 | } |
120 | 119 | ||
121 | /* | 120 | /* |
122 | * We update the i_update_core field _after_ changing | 121 | * Update complete - now make sure everyone knows that the inode |
123 | * the timestamps in order to coordinate properly with | 122 | * is dirty. |
124 | * xfs_iflush() so that we don't lose timestamp updates. | ||
125 | * This keeps us from having to hold the inode lock | ||
126 | * while doing this. We use the SYNCHRONIZE macro to | ||
127 | * ensure that the compiler does not reorder the update | ||
128 | * of i_update_core above the timestamp updates above. | ||
129 | */ | 123 | */ |
130 | if (sync_it) { | 124 | if (sync_it) |
131 | SYNCHRONIZE(); | ||
132 | ip->i_update_core = 1; | ||
133 | xfs_mark_inode_dirty_sync(ip); | 125 | xfs_mark_inode_dirty_sync(ip); |
134 | } | ||
135 | } | 126 | } |
136 | 127 | ||
137 | /* | 128 | /* |
@@ -506,10 +497,8 @@ xfs_vn_getattr( | |||
506 | stat->gid = ip->i_d.di_gid; | 497 | stat->gid = ip->i_d.di_gid; |
507 | stat->ino = ip->i_ino; | 498 | stat->ino = ip->i_ino; |
508 | stat->atime = inode->i_atime; | 499 | stat->atime = inode->i_atime; |
509 | stat->mtime.tv_sec = ip->i_d.di_mtime.t_sec; | 500 | stat->mtime = inode->i_mtime; |
510 | stat->mtime.tv_nsec = ip->i_d.di_mtime.t_nsec; | 501 | stat->ctime = inode->i_ctime; |
511 | stat->ctime.tv_sec = ip->i_d.di_ctime.t_sec; | ||
512 | stat->ctime.tv_nsec = ip->i_d.di_ctime.t_nsec; | ||
513 | stat->blocks = | 502 | stat->blocks = |
514 | XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks); | 503 | XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks); |
515 | 504 | ||
diff --git a/fs/xfs/linux-2.6/xfs_lrw.c b/fs/xfs/linux-2.6/xfs_lrw.c index 49e4a6aea73c..072050f8d346 100644 --- a/fs/xfs/linux-2.6/xfs_lrw.c +++ b/fs/xfs/linux-2.6/xfs_lrw.c | |||
@@ -667,7 +667,7 @@ start: | |||
667 | xip->i_new_size = new_size; | 667 | xip->i_new_size = new_size; |
668 | 668 | ||
669 | if (likely(!(ioflags & IO_INVIS))) | 669 | if (likely(!(ioflags & IO_INVIS))) |
670 | xfs_ichgtime(xip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); | 670 | file_update_time(file); |
671 | 671 | ||
672 | /* | 672 | /* |
673 | * If the offset is beyond the size of the file, we have a couple | 673 | * If the offset is beyond the size of the file, we have a couple |
diff --git a/fs/xfs/linux-2.6/xfs_quotaops.c b/fs/xfs/linux-2.6/xfs_quotaops.c index 9e41f91aa269..3d4a0c84d634 100644 --- a/fs/xfs/linux-2.6/xfs_quotaops.c +++ b/fs/xfs/linux-2.6/xfs_quotaops.c | |||
@@ -80,7 +80,7 @@ xfs_fs_set_xstate( | |||
80 | 80 | ||
81 | if (sb->s_flags & MS_RDONLY) | 81 | if (sb->s_flags & MS_RDONLY) |
82 | return -EROFS; | 82 | return -EROFS; |
83 | if (!XFS_IS_QUOTA_RUNNING(mp)) | 83 | if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp)) |
84 | return -ENOSYS; | 84 | return -ENOSYS; |
85 | if (!capable(CAP_SYS_ADMIN)) | 85 | if (!capable(CAP_SYS_ADMIN)) |
86 | return -EPERM; | 86 | return -EPERM; |
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c index bdd41c8c342f..18a4b8e11df2 100644 --- a/fs/xfs/linux-2.6/xfs_super.c +++ b/fs/xfs/linux-2.6/xfs_super.c | |||
@@ -977,6 +977,28 @@ xfs_fs_inode_init_once( | |||
977 | } | 977 | } |
978 | 978 | ||
979 | /* | 979 | /* |
980 | * Dirty the XFS inode when mark_inode_dirty_sync() is called so that | ||
981 | * we catch unlogged VFS level updates to the inode. Care must be taken | ||
982 | * here - the transaction code calls mark_inode_dirty_sync() to mark the | ||
983 | * VFS inode dirty in a transaction and clears the i_update_core field; | ||
984 | * it must clear the field after calling mark_inode_dirty_sync() to | ||
985 | * correctly indicate that the dirty state has been propagated into the | ||
986 | * inode log item. | ||
987 | * | ||
988 | * We need the barrier() to maintain correct ordering between unlogged | ||
989 | * updates and the transaction commit code that clears the i_update_core | ||
990 | * field. This requires all updates to be completed before marking the | ||
991 | * inode dirty. | ||
992 | */ | ||
993 | STATIC void | ||
994 | xfs_fs_dirty_inode( | ||
995 | struct inode *inode) | ||
996 | { | ||
997 | barrier(); | ||
998 | XFS_I(inode)->i_update_core = 1; | ||
999 | } | ||
1000 | |||
1001 | /* | ||
980 | * Attempt to flush the inode, this will actually fail | 1002 | * Attempt to flush the inode, this will actually fail |
981 | * if the inode is pinned, but we dirty the inode again | 1003 | * if the inode is pinned, but we dirty the inode again |
982 | * at the point when it is unpinned after a log write, | 1004 | * at the point when it is unpinned after a log write, |
@@ -1126,7 +1148,7 @@ xfs_fs_put_super( | |||
1126 | } | 1148 | } |
1127 | 1149 | ||
1128 | STATIC int | 1150 | STATIC int |
1129 | xfs_fs_sync_super( | 1151 | xfs_fs_sync_fs( |
1130 | struct super_block *sb, | 1152 | struct super_block *sb, |
1131 | int wait) | 1153 | int wait) |
1132 | { | 1154 | { |
@@ -1134,23 +1156,23 @@ xfs_fs_sync_super( | |||
1134 | int error; | 1156 | int error; |
1135 | 1157 | ||
1136 | /* | 1158 | /* |
1137 | * Treat a sync operation like a freeze. This is to work | 1159 | * Not much we can do for the first async pass. Writing out the |
1138 | * around a race in sync_inodes() which works in two phases | 1160 | * superblock would be counter-productive as we are going to redirty |
1139 | * - an asynchronous flush, which can write out an inode | 1161 | * when writing out other data and metadata (and writing out a single |
1140 | * without waiting for file size updates to complete, and a | 1162 | * block is quite fast anyway). |
1141 | * synchronous flush, which wont do anything because the | 1163 | * |
1142 | * async flush removed the inode's dirty flag. Also | 1164 | * Try to asynchronously kick off quota syncing at least. |
1143 | * sync_inodes() will not see any files that just have | ||
1144 | * outstanding transactions to be flushed because we don't | ||
1145 | * dirty the Linux inode until after the transaction I/O | ||
1146 | * completes. | ||
1147 | */ | 1165 | */ |
1148 | if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) | 1166 | if (!wait) { |
1149 | error = xfs_quiesce_data(mp); | 1167 | xfs_qm_sync(mp, SYNC_TRYLOCK); |
1150 | else | 1168 | return 0; |
1151 | error = xfs_sync_fsdata(mp, 0); | 1169 | } |
1170 | |||
1171 | error = xfs_quiesce_data(mp); | ||
1172 | if (error) | ||
1173 | return -error; | ||
1152 | 1174 | ||
1153 | if (unlikely(laptop_mode)) { | 1175 | if (laptop_mode) { |
1154 | int prev_sync_seq = mp->m_sync_seq; | 1176 | int prev_sync_seq = mp->m_sync_seq; |
1155 | 1177 | ||
1156 | /* | 1178 | /* |
@@ -1169,7 +1191,7 @@ xfs_fs_sync_super( | |||
1169 | mp->m_sync_seq != prev_sync_seq); | 1191 | mp->m_sync_seq != prev_sync_seq); |
1170 | } | 1192 | } |
1171 | 1193 | ||
1172 | return -error; | 1194 | return 0; |
1173 | } | 1195 | } |
1174 | 1196 | ||
1175 | STATIC int | 1197 | STATIC int |
@@ -1539,10 +1561,11 @@ xfs_fs_get_sb( | |||
1539 | static const struct super_operations xfs_super_operations = { | 1561 | static const struct super_operations xfs_super_operations = { |
1540 | .alloc_inode = xfs_fs_alloc_inode, | 1562 | .alloc_inode = xfs_fs_alloc_inode, |
1541 | .destroy_inode = xfs_fs_destroy_inode, | 1563 | .destroy_inode = xfs_fs_destroy_inode, |
1564 | .dirty_inode = xfs_fs_dirty_inode, | ||
1542 | .write_inode = xfs_fs_write_inode, | 1565 | .write_inode = xfs_fs_write_inode, |
1543 | .clear_inode = xfs_fs_clear_inode, | 1566 | .clear_inode = xfs_fs_clear_inode, |
1544 | .put_super = xfs_fs_put_super, | 1567 | .put_super = xfs_fs_put_super, |
1545 | .sync_fs = xfs_fs_sync_super, | 1568 | .sync_fs = xfs_fs_sync_fs, |
1546 | .freeze_fs = xfs_fs_freeze, | 1569 | .freeze_fs = xfs_fs_freeze, |
1547 | .statfs = xfs_fs_statfs, | 1570 | .statfs = xfs_fs_statfs, |
1548 | .remount_fs = xfs_fs_remount, | 1571 | .remount_fs = xfs_fs_remount, |
diff --git a/fs/xfs/linux-2.6/xfs_sync.c b/fs/xfs/linux-2.6/xfs_sync.c index 320be6aea492..961df0a22c78 100644 --- a/fs/xfs/linux-2.6/xfs_sync.c +++ b/fs/xfs/linux-2.6/xfs_sync.c | |||
@@ -309,11 +309,15 @@ xfs_sync_attr( | |||
309 | STATIC int | 309 | STATIC int |
310 | xfs_commit_dummy_trans( | 310 | xfs_commit_dummy_trans( |
311 | struct xfs_mount *mp, | 311 | struct xfs_mount *mp, |
312 | uint log_flags) | 312 | uint flags) |
313 | { | 313 | { |
314 | struct xfs_inode *ip = mp->m_rootip; | 314 | struct xfs_inode *ip = mp->m_rootip; |
315 | struct xfs_trans *tp; | 315 | struct xfs_trans *tp; |
316 | int error; | 316 | int error; |
317 | int log_flags = XFS_LOG_FORCE; | ||
318 | |||
319 | if (flags & SYNC_WAIT) | ||
320 | log_flags |= XFS_LOG_SYNC; | ||
317 | 321 | ||
318 | /* | 322 | /* |
319 | * Put a dummy transaction in the log to tell recovery | 323 | * Put a dummy transaction in the log to tell recovery |
@@ -331,13 +335,12 @@ xfs_commit_dummy_trans( | |||
331 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); | 335 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); |
332 | xfs_trans_ihold(tp, ip); | 336 | xfs_trans_ihold(tp, ip); |
333 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); | 337 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
334 | /* XXX(hch): ignoring the error here.. */ | ||
335 | error = xfs_trans_commit(tp, 0); | 338 | error = xfs_trans_commit(tp, 0); |
336 | |||
337 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | 339 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
338 | 340 | ||
341 | /* the log force ensures this transaction is pushed to disk */ | ||
339 | xfs_log_force(mp, 0, log_flags); | 342 | xfs_log_force(mp, 0, log_flags); |
340 | return 0; | 343 | return error; |
341 | } | 344 | } |
342 | 345 | ||
343 | int | 346 | int |
@@ -385,7 +388,20 @@ xfs_sync_fsdata( | |||
385 | else | 388 | else |
386 | XFS_BUF_ASYNC(bp); | 389 | XFS_BUF_ASYNC(bp); |
387 | 390 | ||
388 | return xfs_bwrite(mp, bp); | 391 | error = xfs_bwrite(mp, bp); |
392 | if (error) | ||
393 | return error; | ||
394 | |||
395 | /* | ||
396 | * If this is a data integrity sync make sure all pending buffers | ||
397 | * are flushed out for the log coverage check below. | ||
398 | */ | ||
399 | if (flags & SYNC_WAIT) | ||
400 | xfs_flush_buftarg(mp->m_ddev_targp, 1); | ||
401 | |||
402 | if (xfs_log_need_covered(mp)) | ||
403 | error = xfs_commit_dummy_trans(mp, flags); | ||
404 | return error; | ||
389 | 405 | ||
390 | out_brelse: | 406 | out_brelse: |
391 | xfs_buf_relse(bp); | 407 | xfs_buf_relse(bp); |
@@ -419,14 +435,16 @@ xfs_quiesce_data( | |||
419 | /* push non-blocking */ | 435 | /* push non-blocking */ |
420 | xfs_sync_data(mp, 0); | 436 | xfs_sync_data(mp, 0); |
421 | xfs_qm_sync(mp, SYNC_TRYLOCK); | 437 | xfs_qm_sync(mp, SYNC_TRYLOCK); |
422 | xfs_filestream_flush(mp); | ||
423 | 438 | ||
424 | /* push and block */ | 439 | /* push and block till complete */ |
425 | xfs_sync_data(mp, SYNC_WAIT); | 440 | xfs_sync_data(mp, SYNC_WAIT); |
426 | xfs_qm_sync(mp, SYNC_WAIT); | 441 | xfs_qm_sync(mp, SYNC_WAIT); |
427 | 442 | ||
443 | /* drop inode references pinned by filestreams */ | ||
444 | xfs_filestream_flush(mp); | ||
445 | |||
428 | /* write superblock and hoover up shutdown errors */ | 446 | /* write superblock and hoover up shutdown errors */ |
429 | error = xfs_sync_fsdata(mp, 0); | 447 | error = xfs_sync_fsdata(mp, SYNC_WAIT); |
430 | 448 | ||
431 | /* flush data-only devices */ | 449 | /* flush data-only devices */ |
432 | if (mp->m_rtdev_targp) | 450 | if (mp->m_rtdev_targp) |
@@ -570,8 +588,6 @@ xfs_sync_worker( | |||
570 | /* dgc: errors ignored here */ | 588 | /* dgc: errors ignored here */ |
571 | error = xfs_qm_sync(mp, SYNC_TRYLOCK); | 589 | error = xfs_qm_sync(mp, SYNC_TRYLOCK); |
572 | error = xfs_sync_fsdata(mp, SYNC_TRYLOCK); | 590 | error = xfs_sync_fsdata(mp, SYNC_TRYLOCK); |
573 | if (xfs_log_need_covered(mp)) | ||
574 | error = xfs_commit_dummy_trans(mp, XFS_LOG_FORCE); | ||
575 | } | 591 | } |
576 | mp->m_sync_seq++; | 592 | mp->m_sync_seq++; |
577 | wake_up(&mp->m_wait_single_sync_task); | 593 | wake_up(&mp->m_wait_single_sync_task); |
diff --git a/fs/xfs/quota/xfs_qm_syscalls.c b/fs/xfs/quota/xfs_qm_syscalls.c index 4e4276b956e8..5d1a3b98a6e6 100644 --- a/fs/xfs/quota/xfs_qm_syscalls.c +++ b/fs/xfs/quota/xfs_qm_syscalls.c | |||
@@ -876,7 +876,6 @@ xfs_dqrele_inode( | |||
876 | ip->i_gdquot = NULL; | 876 | ip->i_gdquot = NULL; |
877 | } | 877 | } |
878 | xfs_iput(ip, XFS_ILOCK_EXCL); | 878 | xfs_iput(ip, XFS_ILOCK_EXCL); |
879 | IRELE(ip); | ||
880 | 879 | ||
881 | return 0; | 880 | return 0; |
882 | } | 881 | } |
diff --git a/fs/xfs/xfs_dfrag.c b/fs/xfs/xfs_dfrag.c index 7465f9ee125f..ab89a7e94a0f 100644 --- a/fs/xfs/xfs_dfrag.c +++ b/fs/xfs/xfs_dfrag.c | |||
@@ -206,10 +206,10 @@ xfs_swap_extents( | |||
206 | * process that the file was not changed out from | 206 | * process that the file was not changed out from |
207 | * under it. | 207 | * under it. |
208 | */ | 208 | */ |
209 | if ((sbp->bs_ctime.tv_sec != ip->i_d.di_ctime.t_sec) || | 209 | if ((sbp->bs_ctime.tv_sec != VFS_I(ip)->i_ctime.tv_sec) || |
210 | (sbp->bs_ctime.tv_nsec != ip->i_d.di_ctime.t_nsec) || | 210 | (sbp->bs_ctime.tv_nsec != VFS_I(ip)->i_ctime.tv_nsec) || |
211 | (sbp->bs_mtime.tv_sec != ip->i_d.di_mtime.t_sec) || | 211 | (sbp->bs_mtime.tv_sec != VFS_I(ip)->i_mtime.tv_sec) || |
212 | (sbp->bs_mtime.tv_nsec != ip->i_d.di_mtime.t_nsec)) { | 212 | (sbp->bs_mtime.tv_nsec != VFS_I(ip)->i_mtime.tv_nsec)) { |
213 | error = XFS_ERROR(EBUSY); | 213 | error = XFS_ERROR(EBUSY); |
214 | goto out_unlock; | 214 | goto out_unlock; |
215 | } | 215 | } |
diff --git a/fs/xfs/xfs_dir2_leaf.c b/fs/xfs/xfs_dir2_leaf.c index fa913e459442..41ad537c49e9 100644 --- a/fs/xfs/xfs_dir2_leaf.c +++ b/fs/xfs/xfs_dir2_leaf.c | |||
@@ -854,6 +854,7 @@ xfs_dir2_leaf_getdents( | |||
854 | */ | 854 | */ |
855 | ra_want = howmany(bufsize + mp->m_dirblksize, | 855 | ra_want = howmany(bufsize + mp->m_dirblksize, |
856 | mp->m_sb.sb_blocksize) - 1; | 856 | mp->m_sb.sb_blocksize) - 1; |
857 | ASSERT(ra_want >= 0); | ||
857 | 858 | ||
858 | /* | 859 | /* |
859 | * If we don't have as many as we want, and we haven't | 860 | * If we don't have as many as we want, and we haven't |
@@ -1088,7 +1089,8 @@ xfs_dir2_leaf_getdents( | |||
1088 | */ | 1089 | */ |
1089 | ptr += length; | 1090 | ptr += length; |
1090 | curoff += length; | 1091 | curoff += length; |
1091 | bufsize -= length; | 1092 | /* bufsize may have just been a guess; don't go negative */ |
1093 | bufsize = bufsize > length ? bufsize - length : 0; | ||
1092 | } | 1094 | } |
1093 | 1095 | ||
1094 | /* | 1096 | /* |
diff --git a/fs/xfs/xfs_ialloc.c b/fs/xfs/xfs_ialloc.c index ab64f3efb43b..0785797db828 100644 --- a/fs/xfs/xfs_ialloc.c +++ b/fs/xfs/xfs_ialloc.c | |||
@@ -880,6 +880,7 @@ nextag: | |||
880 | * Not in range - save last search | 880 | * Not in range - save last search |
881 | * location and allocate a new inode | 881 | * location and allocate a new inode |
882 | */ | 882 | */ |
883 | xfs_btree_del_cursor(tcur, XFS_BTREE_NOERROR); | ||
883 | pag->pagl_leftrec = trec.ir_startino; | 884 | pag->pagl_leftrec = trec.ir_startino; |
884 | pag->pagl_rightrec = rec.ir_startino; | 885 | pag->pagl_rightrec = rec.ir_startino; |
885 | pag->pagl_pagino = pagino; | 886 | pag->pagl_pagino = pagino; |
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index c1dc7ef5a1d8..b92a4fa2a0a1 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c | |||
@@ -3068,9 +3068,9 @@ xfs_iflush_int( | |||
3068 | SYNCHRONIZE(); | 3068 | SYNCHRONIZE(); |
3069 | 3069 | ||
3070 | /* | 3070 | /* |
3071 | * Make sure to get the latest atime from the Linux inode. | 3071 | * Make sure to get the latest timestamps from the Linux inode. |
3072 | */ | 3072 | */ |
3073 | xfs_synchronize_atime(ip); | 3073 | xfs_synchronize_times(ip); |
3074 | 3074 | ||
3075 | if (XFS_TEST_ERROR(be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC, | 3075 | if (XFS_TEST_ERROR(be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC, |
3076 | mp, XFS_ERRTAG_IFLUSH_1, XFS_RANDOM_IFLUSH_1)) { | 3076 | mp, XFS_ERRTAG_IFLUSH_1, XFS_RANDOM_IFLUSH_1)) { |
diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 0b38b9a869ec..41555de1d1db 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h | |||
@@ -504,7 +504,7 @@ void xfs_ichgtime(xfs_inode_t *, int); | |||
504 | void xfs_lock_inodes(xfs_inode_t **, int, uint); | 504 | void xfs_lock_inodes(xfs_inode_t **, int, uint); |
505 | void xfs_lock_two_inodes(xfs_inode_t *, xfs_inode_t *, uint); | 505 | void xfs_lock_two_inodes(xfs_inode_t *, xfs_inode_t *, uint); |
506 | 506 | ||
507 | void xfs_synchronize_atime(xfs_inode_t *); | 507 | void xfs_synchronize_times(xfs_inode_t *); |
508 | void xfs_mark_inode_dirty_sync(xfs_inode_t *); | 508 | void xfs_mark_inode_dirty_sync(xfs_inode_t *); |
509 | 509 | ||
510 | #if defined(XFS_INODE_TRACE) | 510 | #if defined(XFS_INODE_TRACE) |
diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c index 47d5b663c37e..9794b876d6ff 100644 --- a/fs/xfs/xfs_inode_item.c +++ b/fs/xfs/xfs_inode_item.c | |||
@@ -232,6 +232,15 @@ xfs_inode_item_format( | |||
232 | nvecs = 1; | 232 | nvecs = 1; |
233 | 233 | ||
234 | /* | 234 | /* |
235 | * Make sure the linux inode is dirty. We do this before | ||
236 | * clearing i_update_core as the VFS will call back into | ||
237 | * XFS here and set i_update_core, so we need to dirty the | ||
238 | * inode first so that the ordering of i_update_core and | ||
239 | * unlogged modifications still works as described below. | ||
240 | */ | ||
241 | xfs_mark_inode_dirty_sync(ip); | ||
242 | |||
243 | /* | ||
235 | * Clear i_update_core if the timestamps (or any other | 244 | * Clear i_update_core if the timestamps (or any other |
236 | * non-transactional modification) need flushing/logging | 245 | * non-transactional modification) need flushing/logging |
237 | * and we're about to log them with the rest of the core. | 246 | * and we're about to log them with the rest of the core. |
@@ -263,14 +272,9 @@ xfs_inode_item_format( | |||
263 | } | 272 | } |
264 | 273 | ||
265 | /* | 274 | /* |
266 | * Make sure to get the latest atime from the Linux inode. | 275 | * Make sure to get the latest timestamps from the Linux inode. |
267 | */ | 276 | */ |
268 | xfs_synchronize_atime(ip); | 277 | xfs_synchronize_times(ip); |
269 | |||
270 | /* | ||
271 | * make sure the linux inode is dirty | ||
272 | */ | ||
273 | xfs_mark_inode_dirty_sync(ip); | ||
274 | 278 | ||
275 | vecp->i_addr = (xfs_caddr_t)&ip->i_d; | 279 | vecp->i_addr = (xfs_caddr_t)&ip->i_d; |
276 | vecp->i_len = sizeof(struct xfs_icdinode); | 280 | vecp->i_len = sizeof(struct xfs_icdinode); |
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c index b68f9107e26c..62efab2f3839 100644 --- a/fs/xfs/xfs_itable.c +++ b/fs/xfs/xfs_itable.c | |||
@@ -59,6 +59,7 @@ xfs_bulkstat_one_iget( | |||
59 | { | 59 | { |
60 | xfs_icdinode_t *dic; /* dinode core info pointer */ | 60 | xfs_icdinode_t *dic; /* dinode core info pointer */ |
61 | xfs_inode_t *ip; /* incore inode pointer */ | 61 | xfs_inode_t *ip; /* incore inode pointer */ |
62 | struct inode *inode; | ||
62 | int error; | 63 | int error; |
63 | 64 | ||
64 | error = xfs_iget(mp, NULL, ino, | 65 | error = xfs_iget(mp, NULL, ino, |
@@ -72,6 +73,7 @@ xfs_bulkstat_one_iget( | |||
72 | ASSERT(ip->i_imap.im_blkno != 0); | 73 | ASSERT(ip->i_imap.im_blkno != 0); |
73 | 74 | ||
74 | dic = &ip->i_d; | 75 | dic = &ip->i_d; |
76 | inode = VFS_I(ip); | ||
75 | 77 | ||
76 | /* xfs_iget returns the following without needing | 78 | /* xfs_iget returns the following without needing |
77 | * further change. | 79 | * further change. |
@@ -83,16 +85,19 @@ xfs_bulkstat_one_iget( | |||
83 | buf->bs_uid = dic->di_uid; | 85 | buf->bs_uid = dic->di_uid; |
84 | buf->bs_gid = dic->di_gid; | 86 | buf->bs_gid = dic->di_gid; |
85 | buf->bs_size = dic->di_size; | 87 | buf->bs_size = dic->di_size; |
88 | |||
86 | /* | 89 | /* |
87 | * We are reading the atime from the Linux inode because the | 90 | * We need to read the timestamps from the Linux inode because |
88 | * dinode might not be uptodate. | 91 | * the VFS keeps writing directly into the inode structure instead |
92 | * of telling us about the updates. | ||
89 | */ | 93 | */ |
90 | buf->bs_atime.tv_sec = VFS_I(ip)->i_atime.tv_sec; | 94 | buf->bs_atime.tv_sec = inode->i_atime.tv_sec; |
91 | buf->bs_atime.tv_nsec = VFS_I(ip)->i_atime.tv_nsec; | 95 | buf->bs_atime.tv_nsec = inode->i_atime.tv_nsec; |
92 | buf->bs_mtime.tv_sec = dic->di_mtime.t_sec; | 96 | buf->bs_mtime.tv_sec = inode->i_mtime.tv_sec; |
93 | buf->bs_mtime.tv_nsec = dic->di_mtime.t_nsec; | 97 | buf->bs_mtime.tv_nsec = inode->i_mtime.tv_nsec; |
94 | buf->bs_ctime.tv_sec = dic->di_ctime.t_sec; | 98 | buf->bs_ctime.tv_sec = inode->i_ctime.tv_sec; |
95 | buf->bs_ctime.tv_nsec = dic->di_ctime.t_nsec; | 99 | buf->bs_ctime.tv_nsec = inode->i_ctime.tv_nsec; |
100 | |||
96 | buf->bs_xflags = xfs_ip2xflags(ip); | 101 | buf->bs_xflags = xfs_ip2xflags(ip); |
97 | buf->bs_extsize = dic->di_extsize << mp->m_sb.sb_blocklog; | 102 | buf->bs_extsize = dic->di_extsize << mp->m_sb.sb_blocklog; |
98 | buf->bs_extents = dic->di_nextents; | 103 | buf->bs_extents = dic->di_nextents; |
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index 1099395d7d6c..fb17f8226b09 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c | |||
@@ -1980,7 +1980,7 @@ xlog_recover_do_reg_buffer( | |||
1980 | "XFS: NULL dquot in %s.", __func__); | 1980 | "XFS: NULL dquot in %s.", __func__); |
1981 | goto next; | 1981 | goto next; |
1982 | } | 1982 | } |
1983 | if (item->ri_buf[i].i_len < sizeof(xfs_dqblk_t)) { | 1983 | if (item->ri_buf[i].i_len < sizeof(xfs_disk_dquot_t)) { |
1984 | cmn_err(CE_ALERT, | 1984 | cmn_err(CE_ALERT, |
1985 | "XFS: dquot too small (%d) in %s.", | 1985 | "XFS: dquot too small (%d) in %s.", |
1986 | item->ri_buf[i].i_len, __func__); | 1986 | item->ri_buf[i].i_len, __func__); |
@@ -2635,7 +2635,7 @@ xlog_recover_do_dquot_trans( | |||
2635 | "XFS: NULL dquot in %s.", __func__); | 2635 | "XFS: NULL dquot in %s.", __func__); |
2636 | return XFS_ERROR(EIO); | 2636 | return XFS_ERROR(EIO); |
2637 | } | 2637 | } |
2638 | if (item->ri_buf[1].i_len < sizeof(xfs_dqblk_t)) { | 2638 | if (item->ri_buf[1].i_len < sizeof(xfs_disk_dquot_t)) { |
2639 | cmn_err(CE_ALERT, | 2639 | cmn_err(CE_ALERT, |
2640 | "XFS: dquot too small (%d) in %s.", | 2640 | "XFS: dquot too small (%d) in %s.", |
2641 | item->ri_buf[1].i_len, __func__); | 2641 | item->ri_buf[1].i_len, __func__); |
diff --git a/fs/xfs/xfs_trans_ail.c b/fs/xfs/xfs_trans_ail.c index f31271c30de9..2ffc570679be 100644 --- a/fs/xfs/xfs_trans_ail.c +++ b/fs/xfs/xfs_trans_ail.c | |||
@@ -467,6 +467,7 @@ xfs_trans_ail_update( | |||
467 | { | 467 | { |
468 | xfs_log_item_t *dlip = NULL; | 468 | xfs_log_item_t *dlip = NULL; |
469 | xfs_log_item_t *mlip; /* ptr to minimum lip */ | 469 | xfs_log_item_t *mlip; /* ptr to minimum lip */ |
470 | xfs_lsn_t tail_lsn; | ||
470 | 471 | ||
471 | mlip = xfs_ail_min(ailp); | 472 | mlip = xfs_ail_min(ailp); |
472 | 473 | ||
@@ -483,8 +484,16 @@ xfs_trans_ail_update( | |||
483 | 484 | ||
484 | if (mlip == dlip) { | 485 | if (mlip == dlip) { |
485 | mlip = xfs_ail_min(ailp); | 486 | mlip = xfs_ail_min(ailp); |
487 | /* | ||
488 | * It is not safe to access mlip after the AIL lock is | ||
489 | * dropped, so we must get a copy of li_lsn before we do | ||
490 | * so. This is especially important on 32-bit platforms | ||
491 | * where accessing and updating 64-bit values like li_lsn | ||
492 | * is not atomic. | ||
493 | */ | ||
494 | tail_lsn = mlip->li_lsn; | ||
486 | spin_unlock(&ailp->xa_lock); | 495 | spin_unlock(&ailp->xa_lock); |
487 | xfs_log_move_tail(ailp->xa_mount, mlip->li_lsn); | 496 | xfs_log_move_tail(ailp->xa_mount, tail_lsn); |
488 | } else { | 497 | } else { |
489 | spin_unlock(&ailp->xa_lock); | 498 | spin_unlock(&ailp->xa_lock); |
490 | } | 499 | } |
@@ -514,6 +523,7 @@ xfs_trans_ail_delete( | |||
514 | { | 523 | { |
515 | xfs_log_item_t *dlip; | 524 | xfs_log_item_t *dlip; |
516 | xfs_log_item_t *mlip; | 525 | xfs_log_item_t *mlip; |
526 | xfs_lsn_t tail_lsn; | ||
517 | 527 | ||
518 | if (lip->li_flags & XFS_LI_IN_AIL) { | 528 | if (lip->li_flags & XFS_LI_IN_AIL) { |
519 | mlip = xfs_ail_min(ailp); | 529 | mlip = xfs_ail_min(ailp); |
@@ -527,9 +537,16 @@ xfs_trans_ail_delete( | |||
527 | 537 | ||
528 | if (mlip == dlip) { | 538 | if (mlip == dlip) { |
529 | mlip = xfs_ail_min(ailp); | 539 | mlip = xfs_ail_min(ailp); |
540 | /* | ||
541 | * It is not safe to access mlip after the AIL lock | ||
542 | * is dropped, so we must get a copy of li_lsn | ||
543 | * before we do so. This is especially important | ||
544 | * on 32-bit platforms where accessing and updating | ||
545 | * 64-bit values like li_lsn is not atomic. | ||
546 | */ | ||
547 | tail_lsn = mlip ? mlip->li_lsn : 0; | ||
530 | spin_unlock(&ailp->xa_lock); | 548 | spin_unlock(&ailp->xa_lock); |
531 | xfs_log_move_tail(ailp->xa_mount, | 549 | xfs_log_move_tail(ailp->xa_mount, tail_lsn); |
532 | (mlip ? mlip->li_lsn : 0)); | ||
533 | } else { | 550 | } else { |
534 | spin_unlock(&ailp->xa_lock); | 551 | spin_unlock(&ailp->xa_lock); |
535 | } | 552 | } |
diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c index a434f287962d..b572f7e840e0 100644 --- a/fs/xfs/xfs_vnodeops.c +++ b/fs/xfs/xfs_vnodeops.c | |||
@@ -2476,12 +2476,6 @@ xfs_reclaim( | |||
2476 | ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0); | 2476 | ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0); |
2477 | 2477 | ||
2478 | /* | 2478 | /* |
2479 | * Make sure the atime in the XFS inode is correct before freeing the | ||
2480 | * Linux inode. | ||
2481 | */ | ||
2482 | xfs_synchronize_atime(ip); | ||
2483 | |||
2484 | /* | ||
2485 | * If we have nothing to flush with this inode then complete the | 2479 | * If we have nothing to flush with this inode then complete the |
2486 | * teardown now, otherwise break the link between the xfs inode and the | 2480 | * teardown now, otherwise break the link between the xfs inode and the |
2487 | * linux inode and clean up the xfs inode later. This avoids flushing | 2481 | * linux inode and clean up the xfs inode later. This avoids flushing |