diff options
Diffstat (limited to 'fs')
38 files changed, 645 insertions, 297 deletions
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..c71abec0ab90 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h | |||
@@ -128,12 +128,14 @@ struct btrfs_inode { | |||
128 | u64 last_unlink_trans; | 128 | u64 last_unlink_trans; |
129 | 129 | ||
130 | /* | 130 | /* |
131 | * These two counters are for delalloc metadata reservations. We keep | 131 | * 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 | 132 | * to delalloc and such. outstanding_extents is the number of extent |
133 | * have. | 133 | * items we think we'll end up using, and reserved_extents is the number |
134 | * of extent items we've reserved metadata for. | ||
134 | */ | 135 | */ |
135 | int delalloc_reserved_extents; | 136 | spinlock_t accounting_lock; |
136 | int delalloc_extents; | 137 | int reserved_extents; |
138 | int outstanding_extents; | ||
137 | 139 | ||
138 | /* | 140 | /* |
139 | * ordered_data_close is set by truncate when a file that used | 141 | * 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..1bb897ecdeeb 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 |
@@ -1005,6 +1010,8 @@ struct btrfs_root { | |||
1005 | atomic_t log_commit[2]; | 1010 | atomic_t log_commit[2]; |
1006 | unsigned long log_transid; | 1011 | unsigned long log_transid; |
1007 | unsigned long log_batch; | 1012 | unsigned long log_batch; |
1013 | pid_t log_start_pid; | ||
1014 | bool log_multiple_pids; | ||
1008 | 1015 | ||
1009 | u64 objectid; | 1016 | u64 objectid; |
1010 | u64 last_trans; | 1017 | u64 last_trans; |
@@ -2323,7 +2330,7 @@ int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode); | |||
2323 | void btrfs_orphan_cleanup(struct btrfs_root *root); | 2330 | void btrfs_orphan_cleanup(struct btrfs_root *root); |
2324 | int btrfs_cont_expand(struct inode *inode, loff_t size); | 2331 | int btrfs_cont_expand(struct inode *inode, loff_t size); |
2325 | int btrfs_invalidate_inodes(struct btrfs_root *root); | 2332 | int btrfs_invalidate_inodes(struct btrfs_root *root); |
2326 | extern struct dentry_operations btrfs_dentry_operations; | 2333 | extern const struct dentry_operations btrfs_dentry_operations; |
2327 | 2334 | ||
2328 | /* ioctl.c */ | 2335 | /* ioctl.c */ |
2329 | long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | 2336 | long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index af0435f79fa6..100551a66c46 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -1746,21 +1746,25 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1746 | err = -EINVAL; | 1746 | err = -EINVAL; |
1747 | goto fail_iput; | 1747 | goto fail_iput; |
1748 | } | 1748 | } |
1749 | printk("thread pool is %d\n", fs_info->thread_pool_size); | 1749 | |
1750 | /* | 1750 | btrfs_init_workers(&fs_info->generic_worker, |
1751 | * we need to start all the end_io workers up front because the | 1751 | "genwork", 1, NULL); |
1752 | * queue work function gets called at interrupt time, and so it | 1752 | |
1753 | * cannot dynamically grow. | ||
1754 | */ | ||
1755 | btrfs_init_workers(&fs_info->workers, "worker", | 1753 | btrfs_init_workers(&fs_info->workers, "worker", |
1756 | fs_info->thread_pool_size); | 1754 | fs_info->thread_pool_size, |
1755 | &fs_info->generic_worker); | ||
1757 | 1756 | ||
1758 | btrfs_init_workers(&fs_info->delalloc_workers, "delalloc", | 1757 | btrfs_init_workers(&fs_info->delalloc_workers, "delalloc", |
1759 | fs_info->thread_pool_size); | 1758 | fs_info->thread_pool_size, |
1759 | &fs_info->generic_worker); | ||
1760 | 1760 | ||
1761 | btrfs_init_workers(&fs_info->submit_workers, "submit", | 1761 | btrfs_init_workers(&fs_info->submit_workers, "submit", |
1762 | min_t(u64, fs_devices->num_devices, | 1762 | min_t(u64, fs_devices->num_devices, |
1763 | fs_info->thread_pool_size)); | 1763 | fs_info->thread_pool_size), |
1764 | &fs_info->generic_worker); | ||
1765 | btrfs_init_workers(&fs_info->enospc_workers, "enospc", | ||
1766 | fs_info->thread_pool_size, | ||
1767 | &fs_info->generic_worker); | ||
1764 | 1768 | ||
1765 | /* a higher idle thresh on the submit workers makes it much more | 1769 | /* 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 | 1770 | * likely that bios will be send down in a sane order to the |
@@ -1774,15 +1778,20 @@ printk("thread pool is %d\n", fs_info->thread_pool_size); | |||
1774 | fs_info->delalloc_workers.idle_thresh = 2; | 1778 | fs_info->delalloc_workers.idle_thresh = 2; |
1775 | fs_info->delalloc_workers.ordered = 1; | 1779 | fs_info->delalloc_workers.ordered = 1; |
1776 | 1780 | ||
1777 | btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1); | 1781 | btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1, |
1782 | &fs_info->generic_worker); | ||
1778 | btrfs_init_workers(&fs_info->endio_workers, "endio", | 1783 | btrfs_init_workers(&fs_info->endio_workers, "endio", |
1779 | fs_info->thread_pool_size); | 1784 | fs_info->thread_pool_size, |
1785 | &fs_info->generic_worker); | ||
1780 | btrfs_init_workers(&fs_info->endio_meta_workers, "endio-meta", | 1786 | btrfs_init_workers(&fs_info->endio_meta_workers, "endio-meta", |
1781 | fs_info->thread_pool_size); | 1787 | fs_info->thread_pool_size, |
1788 | &fs_info->generic_worker); | ||
1782 | btrfs_init_workers(&fs_info->endio_meta_write_workers, | 1789 | btrfs_init_workers(&fs_info->endio_meta_write_workers, |
1783 | "endio-meta-write", fs_info->thread_pool_size); | 1790 | "endio-meta-write", fs_info->thread_pool_size, |
1791 | &fs_info->generic_worker); | ||
1784 | btrfs_init_workers(&fs_info->endio_write_workers, "endio-write", | 1792 | btrfs_init_workers(&fs_info->endio_write_workers, "endio-write", |
1785 | fs_info->thread_pool_size); | 1793 | fs_info->thread_pool_size, |
1794 | &fs_info->generic_worker); | ||
1786 | 1795 | ||
1787 | /* | 1796 | /* |
1788 | * endios are largely parallel and should have a very | 1797 | * endios are largely parallel and should have a very |
@@ -1794,12 +1803,8 @@ printk("thread pool is %d\n", fs_info->thread_pool_size); | |||
1794 | fs_info->endio_write_workers.idle_thresh = 2; | 1803 | fs_info->endio_write_workers.idle_thresh = 2; |
1795 | fs_info->endio_meta_write_workers.idle_thresh = 2; | 1804 | fs_info->endio_meta_write_workers.idle_thresh = 2; |
1796 | 1805 | ||
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); | 1806 | btrfs_start_workers(&fs_info->workers, 1); |
1807 | btrfs_start_workers(&fs_info->generic_worker, 1); | ||
1803 | btrfs_start_workers(&fs_info->submit_workers, 1); | 1808 | btrfs_start_workers(&fs_info->submit_workers, 1); |
1804 | btrfs_start_workers(&fs_info->delalloc_workers, 1); | 1809 | btrfs_start_workers(&fs_info->delalloc_workers, 1); |
1805 | btrfs_start_workers(&fs_info->fixup_workers, 1); | 1810 | btrfs_start_workers(&fs_info->fixup_workers, 1); |
@@ -1807,6 +1812,7 @@ printk("thread pool is %d\n", fs_info->thread_pool_size); | |||
1807 | btrfs_start_workers(&fs_info->endio_meta_workers, 1); | 1812 | btrfs_start_workers(&fs_info->endio_meta_workers, 1); |
1808 | btrfs_start_workers(&fs_info->endio_meta_write_workers, 1); | 1813 | btrfs_start_workers(&fs_info->endio_meta_write_workers, 1); |
1809 | btrfs_start_workers(&fs_info->endio_write_workers, 1); | 1814 | btrfs_start_workers(&fs_info->endio_write_workers, 1); |
1815 | btrfs_start_workers(&fs_info->enospc_workers, 1); | ||
1810 | 1816 | ||
1811 | fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super); | 1817 | fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super); |
1812 | fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages, | 1818 | fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages, |
@@ -2012,6 +2018,7 @@ fail_chunk_root: | |||
2012 | free_extent_buffer(chunk_root->node); | 2018 | free_extent_buffer(chunk_root->node); |
2013 | free_extent_buffer(chunk_root->commit_root); | 2019 | free_extent_buffer(chunk_root->commit_root); |
2014 | fail_sb_buffer: | 2020 | fail_sb_buffer: |
2021 | btrfs_stop_workers(&fs_info->generic_worker); | ||
2015 | btrfs_stop_workers(&fs_info->fixup_workers); | 2022 | btrfs_stop_workers(&fs_info->fixup_workers); |
2016 | btrfs_stop_workers(&fs_info->delalloc_workers); | 2023 | btrfs_stop_workers(&fs_info->delalloc_workers); |
2017 | btrfs_stop_workers(&fs_info->workers); | 2024 | btrfs_stop_workers(&fs_info->workers); |
@@ -2020,6 +2027,7 @@ fail_sb_buffer: | |||
2020 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); | 2027 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); |
2021 | btrfs_stop_workers(&fs_info->endio_write_workers); | 2028 | btrfs_stop_workers(&fs_info->endio_write_workers); |
2022 | btrfs_stop_workers(&fs_info->submit_workers); | 2029 | btrfs_stop_workers(&fs_info->submit_workers); |
2030 | btrfs_stop_workers(&fs_info->enospc_workers); | ||
2023 | fail_iput: | 2031 | fail_iput: |
2024 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); | 2032 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); |
2025 | iput(fs_info->btree_inode); | 2033 | iput(fs_info->btree_inode); |
@@ -2437,6 +2445,7 @@ int close_ctree(struct btrfs_root *root) | |||
2437 | 2445 | ||
2438 | iput(fs_info->btree_inode); | 2446 | iput(fs_info->btree_inode); |
2439 | 2447 | ||
2448 | btrfs_stop_workers(&fs_info->generic_worker); | ||
2440 | btrfs_stop_workers(&fs_info->fixup_workers); | 2449 | btrfs_stop_workers(&fs_info->fixup_workers); |
2441 | btrfs_stop_workers(&fs_info->delalloc_workers); | 2450 | btrfs_stop_workers(&fs_info->delalloc_workers); |
2442 | btrfs_stop_workers(&fs_info->workers); | 2451 | btrfs_stop_workers(&fs_info->workers); |
@@ -2445,6 +2454,7 @@ int close_ctree(struct btrfs_root *root) | |||
2445 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); | 2454 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); |
2446 | btrfs_stop_workers(&fs_info->endio_write_workers); | 2455 | btrfs_stop_workers(&fs_info->endio_write_workers); |
2447 | btrfs_stop_workers(&fs_info->submit_workers); | 2456 | btrfs_stop_workers(&fs_info->submit_workers); |
2457 | btrfs_stop_workers(&fs_info->enospc_workers); | ||
2448 | 2458 | ||
2449 | btrfs_close_devices(fs_info->fs_devices); | 2459 | btrfs_close_devices(fs_info->fs_devices); |
2450 | btrfs_mapping_tree_free(&fs_info->mapping_tree); | 2460 | btrfs_mapping_tree_free(&fs_info->mapping_tree); |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 359a754c782c..d0c4d584efad 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -2824,14 +2824,17 @@ int btrfs_unreserve_metadata_for_delalloc(struct btrfs_root *root, | |||
2824 | num_items); | 2824 | num_items); |
2825 | 2825 | ||
2826 | spin_lock(&meta_sinfo->lock); | 2826 | spin_lock(&meta_sinfo->lock); |
2827 | if (BTRFS_I(inode)->delalloc_reserved_extents <= | 2827 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
2828 | BTRFS_I(inode)->delalloc_extents) { | 2828 | if (BTRFS_I(inode)->reserved_extents <= |
2829 | BTRFS_I(inode)->outstanding_extents) { | ||
2830 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
2829 | spin_unlock(&meta_sinfo->lock); | 2831 | spin_unlock(&meta_sinfo->lock); |
2830 | return 0; | 2832 | return 0; |
2831 | } | 2833 | } |
2834 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
2832 | 2835 | ||
2833 | BTRFS_I(inode)->delalloc_reserved_extents--; | 2836 | BTRFS_I(inode)->reserved_extents--; |
2834 | BUG_ON(BTRFS_I(inode)->delalloc_reserved_extents < 0); | 2837 | BUG_ON(BTRFS_I(inode)->reserved_extents < 0); |
2835 | 2838 | ||
2836 | if (meta_sinfo->bytes_delalloc < num_bytes) { | 2839 | if (meta_sinfo->bytes_delalloc < num_bytes) { |
2837 | bug = true; | 2840 | bug = true; |
@@ -2864,6 +2867,107 @@ static void check_force_delalloc(struct btrfs_space_info *meta_sinfo) | |||
2864 | meta_sinfo->force_delalloc = 0; | 2867 | meta_sinfo->force_delalloc = 0; |
2865 | } | 2868 | } |
2866 | 2869 | ||
2870 | struct async_flush { | ||
2871 | struct btrfs_root *root; | ||
2872 | struct btrfs_space_info *info; | ||
2873 | struct btrfs_work work; | ||
2874 | }; | ||
2875 | |||
2876 | static noinline void flush_delalloc_async(struct btrfs_work *work) | ||
2877 | { | ||
2878 | struct async_flush *async; | ||
2879 | struct btrfs_root *root; | ||
2880 | struct btrfs_space_info *info; | ||
2881 | |||
2882 | async = container_of(work, struct async_flush, work); | ||
2883 | root = async->root; | ||
2884 | info = async->info; | ||
2885 | |||
2886 | btrfs_start_delalloc_inodes(root); | ||
2887 | wake_up(&info->flush_wait); | ||
2888 | btrfs_wait_ordered_extents(root, 0); | ||
2889 | |||
2890 | spin_lock(&info->lock); | ||
2891 | info->flushing = 0; | ||
2892 | spin_unlock(&info->lock); | ||
2893 | wake_up(&info->flush_wait); | ||
2894 | |||
2895 | kfree(async); | ||
2896 | } | ||
2897 | |||
2898 | static void wait_on_flush(struct btrfs_space_info *info) | ||
2899 | { | ||
2900 | DEFINE_WAIT(wait); | ||
2901 | u64 used; | ||
2902 | |||
2903 | while (1) { | ||
2904 | prepare_to_wait(&info->flush_wait, &wait, | ||
2905 | TASK_UNINTERRUPTIBLE); | ||
2906 | spin_lock(&info->lock); | ||
2907 | if (!info->flushing) { | ||
2908 | spin_unlock(&info->lock); | ||
2909 | break; | ||
2910 | } | ||
2911 | |||
2912 | used = info->bytes_used + info->bytes_reserved + | ||
2913 | info->bytes_pinned + info->bytes_readonly + | ||
2914 | info->bytes_super + info->bytes_root + | ||
2915 | info->bytes_may_use + info->bytes_delalloc; | ||
2916 | if (used < info->total_bytes) { | ||
2917 | spin_unlock(&info->lock); | ||
2918 | break; | ||
2919 | } | ||
2920 | spin_unlock(&info->lock); | ||
2921 | schedule(); | ||
2922 | } | ||
2923 | finish_wait(&info->flush_wait, &wait); | ||
2924 | } | ||
2925 | |||
2926 | static void flush_delalloc(struct btrfs_root *root, | ||
2927 | struct btrfs_space_info *info) | ||
2928 | { | ||
2929 | struct async_flush *async; | ||
2930 | bool wait = false; | ||
2931 | |||
2932 | spin_lock(&info->lock); | ||
2933 | |||
2934 | if (!info->flushing) { | ||
2935 | info->flushing = 1; | ||
2936 | init_waitqueue_head(&info->flush_wait); | ||
2937 | } else { | ||
2938 | wait = true; | ||
2939 | } | ||
2940 | |||
2941 | spin_unlock(&info->lock); | ||
2942 | |||
2943 | if (wait) { | ||
2944 | wait_on_flush(info); | ||
2945 | return; | ||
2946 | } | ||
2947 | |||
2948 | async = kzalloc(sizeof(*async), GFP_NOFS); | ||
2949 | if (!async) | ||
2950 | goto flush; | ||
2951 | |||
2952 | async->root = root; | ||
2953 | async->info = info; | ||
2954 | async->work.func = flush_delalloc_async; | ||
2955 | |||
2956 | btrfs_queue_worker(&root->fs_info->enospc_workers, | ||
2957 | &async->work); | ||
2958 | wait_on_flush(info); | ||
2959 | return; | ||
2960 | |||
2961 | flush: | ||
2962 | btrfs_start_delalloc_inodes(root); | ||
2963 | btrfs_wait_ordered_extents(root, 0); | ||
2964 | |||
2965 | spin_lock(&info->lock); | ||
2966 | info->flushing = 0; | ||
2967 | spin_unlock(&info->lock); | ||
2968 | wake_up(&info->flush_wait); | ||
2969 | } | ||
2970 | |||
2867 | static int maybe_allocate_chunk(struct btrfs_root *root, | 2971 | static int maybe_allocate_chunk(struct btrfs_root *root, |
2868 | struct btrfs_space_info *info) | 2972 | struct btrfs_space_info *info) |
2869 | { | 2973 | { |
@@ -2894,7 +2998,7 @@ static int maybe_allocate_chunk(struct btrfs_root *root, | |||
2894 | if (!info->allocating_chunk) { | 2998 | if (!info->allocating_chunk) { |
2895 | info->force_alloc = 1; | 2999 | info->force_alloc = 1; |
2896 | info->allocating_chunk = 1; | 3000 | info->allocating_chunk = 1; |
2897 | init_waitqueue_head(&info->wait); | 3001 | init_waitqueue_head(&info->allocate_wait); |
2898 | } else { | 3002 | } else { |
2899 | wait = true; | 3003 | wait = true; |
2900 | } | 3004 | } |
@@ -2902,7 +3006,7 @@ static int maybe_allocate_chunk(struct btrfs_root *root, | |||
2902 | spin_unlock(&info->lock); | 3006 | spin_unlock(&info->lock); |
2903 | 3007 | ||
2904 | if (wait) { | 3008 | if (wait) { |
2905 | wait_event(info->wait, | 3009 | wait_event(info->allocate_wait, |
2906 | !info->allocating_chunk); | 3010 | !info->allocating_chunk); |
2907 | return 1; | 3011 | return 1; |
2908 | } | 3012 | } |
@@ -2923,7 +3027,7 @@ out: | |||
2923 | spin_lock(&info->lock); | 3027 | spin_lock(&info->lock); |
2924 | info->allocating_chunk = 0; | 3028 | info->allocating_chunk = 0; |
2925 | spin_unlock(&info->lock); | 3029 | spin_unlock(&info->lock); |
2926 | wake_up(&info->wait); | 3030 | wake_up(&info->allocate_wait); |
2927 | 3031 | ||
2928 | if (ret) | 3032 | if (ret) |
2929 | return 0; | 3033 | return 0; |
@@ -2981,21 +3085,20 @@ again: | |||
2981 | filemap_flush(inode->i_mapping); | 3085 | filemap_flush(inode->i_mapping); |
2982 | goto again; | 3086 | goto again; |
2983 | } else if (flushed == 3) { | 3087 | } else if (flushed == 3) { |
2984 | btrfs_start_delalloc_inodes(root); | 3088 | flush_delalloc(root, meta_sinfo); |
2985 | btrfs_wait_ordered_extents(root, 0); | ||
2986 | goto again; | 3089 | goto again; |
2987 | } | 3090 | } |
2988 | spin_lock(&meta_sinfo->lock); | 3091 | spin_lock(&meta_sinfo->lock); |
2989 | meta_sinfo->bytes_delalloc -= num_bytes; | 3092 | meta_sinfo->bytes_delalloc -= num_bytes; |
2990 | spin_unlock(&meta_sinfo->lock); | 3093 | spin_unlock(&meta_sinfo->lock); |
2991 | printk(KERN_ERR "enospc, has %d, reserved %d\n", | 3094 | printk(KERN_ERR "enospc, has %d, reserved %d\n", |
2992 | BTRFS_I(inode)->delalloc_extents, | 3095 | BTRFS_I(inode)->outstanding_extents, |
2993 | BTRFS_I(inode)->delalloc_reserved_extents); | 3096 | BTRFS_I(inode)->reserved_extents); |
2994 | dump_space_info(meta_sinfo, 0, 0); | 3097 | dump_space_info(meta_sinfo, 0, 0); |
2995 | return -ENOSPC; | 3098 | return -ENOSPC; |
2996 | } | 3099 | } |
2997 | 3100 | ||
2998 | BTRFS_I(inode)->delalloc_reserved_extents++; | 3101 | BTRFS_I(inode)->reserved_extents++; |
2999 | check_force_delalloc(meta_sinfo); | 3102 | check_force_delalloc(meta_sinfo); |
3000 | spin_unlock(&meta_sinfo->lock); | 3103 | spin_unlock(&meta_sinfo->lock); |
3001 | 3104 | ||
@@ -3094,8 +3197,7 @@ again: | |||
3094 | } | 3197 | } |
3095 | 3198 | ||
3096 | if (retries == 2) { | 3199 | if (retries == 2) { |
3097 | btrfs_start_delalloc_inodes(root); | 3200 | flush_delalloc(root, meta_sinfo); |
3098 | btrfs_wait_ordered_extents(root, 0); | ||
3099 | goto again; | 3201 | goto again; |
3100 | } | 3202 | } |
3101 | spin_lock(&meta_sinfo->lock); | 3203 | spin_lock(&meta_sinfo->lock); |
@@ -4029,6 +4131,7 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, | |||
4029 | int loop = 0; | 4131 | int loop = 0; |
4030 | bool found_uncached_bg = false; | 4132 | bool found_uncached_bg = false; |
4031 | bool failed_cluster_refill = false; | 4133 | bool failed_cluster_refill = false; |
4134 | bool failed_alloc = false; | ||
4032 | 4135 | ||
4033 | WARN_ON(num_bytes < root->sectorsize); | 4136 | WARN_ON(num_bytes < root->sectorsize); |
4034 | btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY); | 4137 | btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY); |
@@ -4233,14 +4336,23 @@ refill_cluster: | |||
4233 | 4336 | ||
4234 | offset = btrfs_find_space_for_alloc(block_group, search_start, | 4337 | offset = btrfs_find_space_for_alloc(block_group, search_start, |
4235 | num_bytes, empty_size); | 4338 | num_bytes, empty_size); |
4236 | if (!offset && (cached || (!cached && | 4339 | /* |
4237 | loop == LOOP_CACHING_NOWAIT))) { | 4340 | * If we didn't find a chunk, and we haven't failed on this |
4238 | goto loop; | 4341 | * block group before, and this block group is in the middle of |
4239 | } else if (!offset && (!cached && | 4342 | * caching and we are ok with waiting, then go ahead and wait |
4240 | loop > LOOP_CACHING_NOWAIT)) { | 4343 | * for progress to be made, and set failed_alloc to true. |
4344 | * | ||
4345 | * If failed_alloc is true then we've already waited on this | ||
4346 | * block group once and should move on to the next block group. | ||
4347 | */ | ||
4348 | if (!offset && !failed_alloc && !cached && | ||
4349 | loop > LOOP_CACHING_NOWAIT) { | ||
4241 | wait_block_group_cache_progress(block_group, | 4350 | wait_block_group_cache_progress(block_group, |
4242 | num_bytes + empty_size); | 4351 | num_bytes + empty_size); |
4352 | failed_alloc = true; | ||
4243 | goto have_block_group; | 4353 | goto have_block_group; |
4354 | } else if (!offset) { | ||
4355 | goto loop; | ||
4244 | } | 4356 | } |
4245 | checks: | 4357 | checks: |
4246 | search_start = stripe_align(root, offset); | 4358 | search_start = stripe_align(root, offset); |
@@ -4288,6 +4400,7 @@ checks: | |||
4288 | break; | 4400 | break; |
4289 | loop: | 4401 | loop: |
4290 | failed_cluster_refill = false; | 4402 | failed_cluster_refill = false; |
4403 | failed_alloc = false; | ||
4291 | btrfs_put_block_group(block_group); | 4404 | btrfs_put_block_group(block_group); |
4292 | } | 4405 | } |
4293 | up_read(&space_info->groups_sem); | 4406 | up_read(&space_info->groups_sem); |
@@ -4799,6 +4912,7 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, | |||
4799 | u64 bytenr; | 4912 | u64 bytenr; |
4800 | u64 generation; | 4913 | u64 generation; |
4801 | u64 refs; | 4914 | u64 refs; |
4915 | u64 flags; | ||
4802 | u64 last = 0; | 4916 | u64 last = 0; |
4803 | u32 nritems; | 4917 | u32 nritems; |
4804 | u32 blocksize; | 4918 | u32 blocksize; |
@@ -4836,15 +4950,19 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, | |||
4836 | generation <= root->root_key.offset) | 4950 | generation <= root->root_key.offset) |
4837 | continue; | 4951 | continue; |
4838 | 4952 | ||
4953 | /* We don't lock the tree block, it's OK to be racy here */ | ||
4954 | ret = btrfs_lookup_extent_info(trans, root, bytenr, blocksize, | ||
4955 | &refs, &flags); | ||
4956 | BUG_ON(ret); | ||
4957 | BUG_ON(refs == 0); | ||
4958 | |||
4839 | if (wc->stage == DROP_REFERENCE) { | 4959 | 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) | 4960 | if (refs == 1) |
4846 | goto reada; | 4961 | goto reada; |
4847 | 4962 | ||
4963 | if (wc->level == 1 && | ||
4964 | (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) | ||
4965 | continue; | ||
4848 | if (!wc->update_ref || | 4966 | if (!wc->update_ref || |
4849 | generation <= root->root_key.offset) | 4967 | generation <= root->root_key.offset) |
4850 | continue; | 4968 | continue; |
@@ -4853,6 +4971,10 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, | |||
4853 | &wc->update_progress); | 4971 | &wc->update_progress); |
4854 | if (ret < 0) | 4972 | if (ret < 0) |
4855 | continue; | 4973 | continue; |
4974 | } else { | ||
4975 | if (wc->level == 1 && | ||
4976 | (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) | ||
4977 | continue; | ||
4856 | } | 4978 | } |
4857 | reada: | 4979 | reada: |
4858 | ret = readahead_tree_block(root, bytenr, blocksize, | 4980 | ret = readahead_tree_block(root, bytenr, blocksize, |
@@ -4876,7 +4998,7 @@ reada: | |||
4876 | static noinline int walk_down_proc(struct btrfs_trans_handle *trans, | 4998 | static noinline int walk_down_proc(struct btrfs_trans_handle *trans, |
4877 | struct btrfs_root *root, | 4999 | struct btrfs_root *root, |
4878 | struct btrfs_path *path, | 5000 | struct btrfs_path *path, |
4879 | struct walk_control *wc) | 5001 | struct walk_control *wc, int lookup_info) |
4880 | { | 5002 | { |
4881 | int level = wc->level; | 5003 | int level = wc->level; |
4882 | struct extent_buffer *eb = path->nodes[level]; | 5004 | struct extent_buffer *eb = path->nodes[level]; |
@@ -4891,8 +5013,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 | 5013 | * when reference count of tree block is 1, it won't increase |
4892 | * again. once full backref flag is set, we never clear it. | 5014 | * again. once full backref flag is set, we never clear it. |
4893 | */ | 5015 | */ |
4894 | if ((wc->stage == DROP_REFERENCE && wc->refs[level] != 1) || | 5016 | if (lookup_info && |
4895 | (wc->stage == UPDATE_BACKREF && !(wc->flags[level] & flag))) { | 5017 | ((wc->stage == DROP_REFERENCE && wc->refs[level] != 1) || |
5018 | (wc->stage == UPDATE_BACKREF && !(wc->flags[level] & flag)))) { | ||
4896 | BUG_ON(!path->locks[level]); | 5019 | BUG_ON(!path->locks[level]); |
4897 | ret = btrfs_lookup_extent_info(trans, root, | 5020 | ret = btrfs_lookup_extent_info(trans, root, |
4898 | eb->start, eb->len, | 5021 | eb->start, eb->len, |
@@ -4953,7 +5076,7 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans, | |||
4953 | static noinline int do_walk_down(struct btrfs_trans_handle *trans, | 5076 | static noinline int do_walk_down(struct btrfs_trans_handle *trans, |
4954 | struct btrfs_root *root, | 5077 | struct btrfs_root *root, |
4955 | struct btrfs_path *path, | 5078 | struct btrfs_path *path, |
4956 | struct walk_control *wc) | 5079 | struct walk_control *wc, int *lookup_info) |
4957 | { | 5080 | { |
4958 | u64 bytenr; | 5081 | u64 bytenr; |
4959 | u64 generation; | 5082 | u64 generation; |
@@ -4973,8 +5096,10 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, | |||
4973 | * for the subtree | 5096 | * for the subtree |
4974 | */ | 5097 | */ |
4975 | if (wc->stage == UPDATE_BACKREF && | 5098 | if (wc->stage == UPDATE_BACKREF && |
4976 | generation <= root->root_key.offset) | 5099 | generation <= root->root_key.offset) { |
5100 | *lookup_info = 1; | ||
4977 | return 1; | 5101 | return 1; |
5102 | } | ||
4978 | 5103 | ||
4979 | bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); | 5104 | bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); |
4980 | blocksize = btrfs_level_size(root, level - 1); | 5105 | blocksize = btrfs_level_size(root, level - 1); |
@@ -4987,14 +5112,19 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, | |||
4987 | btrfs_tree_lock(next); | 5112 | btrfs_tree_lock(next); |
4988 | btrfs_set_lock_blocking(next); | 5113 | btrfs_set_lock_blocking(next); |
4989 | 5114 | ||
4990 | if (wc->stage == DROP_REFERENCE) { | 5115 | ret = btrfs_lookup_extent_info(trans, root, bytenr, blocksize, |
4991 | ret = btrfs_lookup_extent_info(trans, root, bytenr, blocksize, | 5116 | &wc->refs[level - 1], |
4992 | &wc->refs[level - 1], | 5117 | &wc->flags[level - 1]); |
4993 | &wc->flags[level - 1]); | 5118 | BUG_ON(ret); |
4994 | BUG_ON(ret); | 5119 | BUG_ON(wc->refs[level - 1] == 0); |
4995 | BUG_ON(wc->refs[level - 1] == 0); | 5120 | *lookup_info = 0; |
4996 | 5121 | ||
5122 | if (wc->stage == DROP_REFERENCE) { | ||
4997 | if (wc->refs[level - 1] > 1) { | 5123 | if (wc->refs[level - 1] > 1) { |
5124 | if (level == 1 && | ||
5125 | (wc->flags[0] & BTRFS_BLOCK_FLAG_FULL_BACKREF)) | ||
5126 | goto skip; | ||
5127 | |||
4998 | if (!wc->update_ref || | 5128 | if (!wc->update_ref || |
4999 | generation <= root->root_key.offset) | 5129 | generation <= root->root_key.offset) |
5000 | goto skip; | 5130 | goto skip; |
@@ -5008,12 +5138,17 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, | |||
5008 | wc->stage = UPDATE_BACKREF; | 5138 | wc->stage = UPDATE_BACKREF; |
5009 | wc->shared_level = level - 1; | 5139 | wc->shared_level = level - 1; |
5010 | } | 5140 | } |
5141 | } else { | ||
5142 | if (level == 1 && | ||
5143 | (wc->flags[0] & BTRFS_BLOCK_FLAG_FULL_BACKREF)) | ||
5144 | goto skip; | ||
5011 | } | 5145 | } |
5012 | 5146 | ||
5013 | if (!btrfs_buffer_uptodate(next, generation)) { | 5147 | if (!btrfs_buffer_uptodate(next, generation)) { |
5014 | btrfs_tree_unlock(next); | 5148 | btrfs_tree_unlock(next); |
5015 | free_extent_buffer(next); | 5149 | free_extent_buffer(next); |
5016 | next = NULL; | 5150 | next = NULL; |
5151 | *lookup_info = 1; | ||
5017 | } | 5152 | } |
5018 | 5153 | ||
5019 | if (!next) { | 5154 | if (!next) { |
@@ -5036,21 +5171,22 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, | |||
5036 | skip: | 5171 | skip: |
5037 | wc->refs[level - 1] = 0; | 5172 | wc->refs[level - 1] = 0; |
5038 | wc->flags[level - 1] = 0; | 5173 | wc->flags[level - 1] = 0; |
5174 | if (wc->stage == DROP_REFERENCE) { | ||
5175 | if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) { | ||
5176 | parent = path->nodes[level]->start; | ||
5177 | } else { | ||
5178 | BUG_ON(root->root_key.objectid != | ||
5179 | btrfs_header_owner(path->nodes[level])); | ||
5180 | parent = 0; | ||
5181 | } | ||
5039 | 5182 | ||
5040 | if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) { | 5183 | ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent, |
5041 | parent = path->nodes[level]->start; | 5184 | root->root_key.objectid, level - 1, 0); |
5042 | } else { | 5185 | BUG_ON(ret); |
5043 | BUG_ON(root->root_key.objectid != | ||
5044 | btrfs_header_owner(path->nodes[level])); | ||
5045 | parent = 0; | ||
5046 | } | 5186 | } |
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); | 5187 | btrfs_tree_unlock(next); |
5053 | free_extent_buffer(next); | 5188 | free_extent_buffer(next); |
5189 | *lookup_info = 1; | ||
5054 | return 1; | 5190 | return 1; |
5055 | } | 5191 | } |
5056 | 5192 | ||
@@ -5164,6 +5300,7 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans, | |||
5164 | struct walk_control *wc) | 5300 | struct walk_control *wc) |
5165 | { | 5301 | { |
5166 | int level = wc->level; | 5302 | int level = wc->level; |
5303 | int lookup_info = 1; | ||
5167 | int ret; | 5304 | int ret; |
5168 | 5305 | ||
5169 | while (level >= 0) { | 5306 | while (level >= 0) { |
@@ -5171,14 +5308,14 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans, | |||
5171 | btrfs_header_nritems(path->nodes[level])) | 5308 | btrfs_header_nritems(path->nodes[level])) |
5172 | break; | 5309 | break; |
5173 | 5310 | ||
5174 | ret = walk_down_proc(trans, root, path, wc); | 5311 | ret = walk_down_proc(trans, root, path, wc, lookup_info); |
5175 | if (ret > 0) | 5312 | if (ret > 0) |
5176 | break; | 5313 | break; |
5177 | 5314 | ||
5178 | if (level == 0) | 5315 | if (level == 0) |
5179 | break; | 5316 | break; |
5180 | 5317 | ||
5181 | ret = do_walk_down(trans, root, path, wc); | 5318 | ret = do_walk_down(trans, root, path, wc, &lookup_info); |
5182 | if (ret > 0) { | 5319 | if (ret > 0) { |
5183 | path->slots[level]++; | 5320 | path->slots[level]++; |
5184 | continue; | 5321 | 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/file.c b/fs/btrfs/file.c index f19e1259a971..2d623aa0625f 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); |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 112e5aa85892..9e138b793dc7 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 | } |
@@ -637,11 +640,14 @@ static noinline int submit_compressed_extents(struct inode *inode, | |||
637 | * clear dirty, set writeback and unlock the pages. | 640 | * clear dirty, set writeback and unlock the pages. |
638 | */ | 641 | */ |
639 | extent_clear_unlock_delalloc(inode, | 642 | extent_clear_unlock_delalloc(inode, |
640 | &BTRFS_I(inode)->io_tree, | 643 | &BTRFS_I(inode)->io_tree, |
641 | async_extent->start, | 644 | async_extent->start, |
642 | async_extent->start + | 645 | async_extent->start + |
643 | async_extent->ram_size - 1, | 646 | async_extent->ram_size - 1, |
644 | NULL, 1, 1, 0, 1, 1, 0, 0); | 647 | NULL, EXTENT_CLEAR_UNLOCK_PAGE | |
648 | EXTENT_CLEAR_UNLOCK | | ||
649 | EXTENT_CLEAR_DELALLOC | | ||
650 | EXTENT_CLEAR_DIRTY | EXTENT_SET_WRITEBACK); | ||
645 | 651 | ||
646 | ret = btrfs_submit_compressed_write(inode, | 652 | ret = btrfs_submit_compressed_write(inode, |
647 | async_extent->start, | 653 | async_extent->start, |
@@ -712,9 +718,15 @@ static noinline int cow_file_range(struct inode *inode, | |||
712 | start, end, 0, NULL); | 718 | start, end, 0, NULL); |
713 | if (ret == 0) { | 719 | if (ret == 0) { |
714 | extent_clear_unlock_delalloc(inode, | 720 | extent_clear_unlock_delalloc(inode, |
715 | &BTRFS_I(inode)->io_tree, | 721 | &BTRFS_I(inode)->io_tree, |
716 | start, end, NULL, 1, 1, | 722 | start, end, NULL, |
717 | 1, 1, 1, 1, 0); | 723 | EXTENT_CLEAR_UNLOCK_PAGE | |
724 | EXTENT_CLEAR_UNLOCK | | ||
725 | EXTENT_CLEAR_DELALLOC | | ||
726 | EXTENT_CLEAR_ACCOUNTING | | ||
727 | EXTENT_CLEAR_DIRTY | | ||
728 | EXTENT_SET_WRITEBACK | | ||
729 | EXTENT_END_WRITEBACK); | ||
718 | *nr_written = *nr_written + | 730 | *nr_written = *nr_written + |
719 | (end - start + PAGE_CACHE_SIZE) / PAGE_CACHE_SIZE; | 731 | (end - start + PAGE_CACHE_SIZE) / PAGE_CACHE_SIZE; |
720 | *page_started = 1; | 732 | *page_started = 1; |
@@ -738,6 +750,8 @@ static noinline int cow_file_range(struct inode *inode, | |||
738 | btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0); | 750 | btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0); |
739 | 751 | ||
740 | while (disk_num_bytes > 0) { | 752 | while (disk_num_bytes > 0) { |
753 | unsigned long op; | ||
754 | |||
741 | cur_alloc_size = min(disk_num_bytes, root->fs_info->max_extent); | 755 | cur_alloc_size = min(disk_num_bytes, root->fs_info->max_extent); |
742 | ret = btrfs_reserve_extent(trans, root, cur_alloc_size, | 756 | ret = btrfs_reserve_extent(trans, root, cur_alloc_size, |
743 | root->sectorsize, 0, alloc_hint, | 757 | root->sectorsize, 0, alloc_hint, |
@@ -789,10 +803,13 @@ static noinline int cow_file_range(struct inode *inode, | |||
789 | * Do set the Private2 bit so we know this page was properly | 803 | * Do set the Private2 bit so we know this page was properly |
790 | * setup for writepage | 804 | * setup for writepage |
791 | */ | 805 | */ |
806 | op = unlock ? EXTENT_CLEAR_UNLOCK_PAGE : 0; | ||
807 | op |= EXTENT_CLEAR_UNLOCK | EXTENT_CLEAR_DELALLOC | | ||
808 | EXTENT_SET_PRIVATE2; | ||
809 | |||
792 | extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, | 810 | extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, |
793 | start, start + ram_size - 1, | 811 | start, start + ram_size - 1, |
794 | locked_page, unlock, 1, | 812 | locked_page, op); |
795 | 1, 0, 0, 0, 1); | ||
796 | disk_num_bytes -= cur_alloc_size; | 813 | disk_num_bytes -= cur_alloc_size; |
797 | num_bytes -= cur_alloc_size; | 814 | num_bytes -= cur_alloc_size; |
798 | alloc_hint = ins.objectid + ins.offset; | 815 | alloc_hint = ins.objectid + ins.offset; |
@@ -864,8 +881,8 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page, | |||
864 | u64 cur_end; | 881 | u64 cur_end; |
865 | int limit = 10 * 1024 * 1042; | 882 | int limit = 10 * 1024 * 1042; |
866 | 883 | ||
867 | clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED | | 884 | clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED, |
868 | EXTENT_DELALLOC, 1, 0, NULL, GFP_NOFS); | 885 | 1, 0, NULL, GFP_NOFS); |
869 | while (start < end) { | 886 | while (start < end) { |
870 | async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS); | 887 | async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS); |
871 | async_cow->inode = inode; | 888 | async_cow->inode = inode; |
@@ -1006,6 +1023,7 @@ next_slot: | |||
1006 | 1023 | ||
1007 | if (found_key.offset > cur_offset) { | 1024 | if (found_key.offset > cur_offset) { |
1008 | extent_end = found_key.offset; | 1025 | extent_end = found_key.offset; |
1026 | extent_type = 0; | ||
1009 | goto out_check; | 1027 | goto out_check; |
1010 | } | 1028 | } |
1011 | 1029 | ||
@@ -1112,8 +1130,10 @@ out_check: | |||
1112 | BUG_ON(ret); | 1130 | BUG_ON(ret); |
1113 | 1131 | ||
1114 | extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, | 1132 | extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, |
1115 | cur_offset, cur_offset + num_bytes - 1, | 1133 | cur_offset, cur_offset + num_bytes - 1, |
1116 | locked_page, 1, 1, 1, 0, 0, 0, 1); | 1134 | locked_page, EXTENT_CLEAR_UNLOCK_PAGE | |
1135 | EXTENT_CLEAR_UNLOCK | EXTENT_CLEAR_DELALLOC | | ||
1136 | EXTENT_SET_PRIVATE2); | ||
1117 | cur_offset = extent_end; | 1137 | cur_offset = extent_end; |
1118 | if (cur_offset > end) | 1138 | if (cur_offset > end) |
1119 | break; | 1139 | break; |
@@ -1178,15 +1198,17 @@ static int btrfs_split_extent_hook(struct inode *inode, | |||
1178 | root->fs_info->max_extent); | 1198 | root->fs_info->max_extent); |
1179 | 1199 | ||
1180 | /* | 1200 | /* |
1181 | * if we break a large extent up then leave delalloc_extents be, | 1201 | * if we break a large extent up then leave oustanding_extents |
1182 | * since we've already accounted for the large extent. | 1202 | * be, since we've already accounted for the large extent. |
1183 | */ | 1203 | */ |
1184 | if (div64_u64(new_size + root->fs_info->max_extent - 1, | 1204 | if (div64_u64(new_size + root->fs_info->max_extent - 1, |
1185 | root->fs_info->max_extent) < num_extents) | 1205 | root->fs_info->max_extent) < num_extents) |
1186 | return 0; | 1206 | return 0; |
1187 | } | 1207 | } |
1188 | 1208 | ||
1189 | BTRFS_I(inode)->delalloc_extents++; | 1209 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
1210 | BTRFS_I(inode)->outstanding_extents++; | ||
1211 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1190 | 1212 | ||
1191 | return 0; | 1213 | return 0; |
1192 | } | 1214 | } |
@@ -1217,7 +1239,9 @@ static int btrfs_merge_extent_hook(struct inode *inode, | |||
1217 | 1239 | ||
1218 | /* we're not bigger than the max, unreserve the space and go */ | 1240 | /* we're not bigger than the max, unreserve the space and go */ |
1219 | if (new_size <= root->fs_info->max_extent) { | 1241 | if (new_size <= root->fs_info->max_extent) { |
1220 | BTRFS_I(inode)->delalloc_extents--; | 1242 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
1243 | BTRFS_I(inode)->outstanding_extents--; | ||
1244 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1221 | return 0; | 1245 | return 0; |
1222 | } | 1246 | } |
1223 | 1247 | ||
@@ -1231,7 +1255,9 @@ static int btrfs_merge_extent_hook(struct inode *inode, | |||
1231 | root->fs_info->max_extent) > num_extents) | 1255 | root->fs_info->max_extent) > num_extents) |
1232 | return 0; | 1256 | return 0; |
1233 | 1257 | ||
1234 | BTRFS_I(inode)->delalloc_extents--; | 1258 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
1259 | BTRFS_I(inode)->outstanding_extents--; | ||
1260 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1235 | 1261 | ||
1236 | return 0; | 1262 | return 0; |
1237 | } | 1263 | } |
@@ -1253,7 +1279,9 @@ static int btrfs_set_bit_hook(struct inode *inode, u64 start, u64 end, | |||
1253 | if (!(old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { | 1279 | if (!(old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { |
1254 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1280 | struct btrfs_root *root = BTRFS_I(inode)->root; |
1255 | 1281 | ||
1256 | BTRFS_I(inode)->delalloc_extents++; | 1282 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
1283 | BTRFS_I(inode)->outstanding_extents++; | ||
1284 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1257 | btrfs_delalloc_reserve_space(root, inode, end - start + 1); | 1285 | btrfs_delalloc_reserve_space(root, inode, end - start + 1); |
1258 | spin_lock(&root->fs_info->delalloc_lock); | 1286 | spin_lock(&root->fs_info->delalloc_lock); |
1259 | BTRFS_I(inode)->delalloc_bytes += end - start + 1; | 1287 | BTRFS_I(inode)->delalloc_bytes += end - start + 1; |
@@ -1281,8 +1309,12 @@ static int btrfs_clear_bit_hook(struct inode *inode, | |||
1281 | if ((state->state & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { | 1309 | if ((state->state & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { |
1282 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1310 | struct btrfs_root *root = BTRFS_I(inode)->root; |
1283 | 1311 | ||
1284 | BTRFS_I(inode)->delalloc_extents--; | 1312 | if (bits & EXTENT_DO_ACCOUNTING) { |
1285 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | 1313 | spin_lock(&BTRFS_I(inode)->accounting_lock); |
1314 | BTRFS_I(inode)->outstanding_extents--; | ||
1315 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1316 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
1317 | } | ||
1286 | 1318 | ||
1287 | spin_lock(&root->fs_info->delalloc_lock); | 1319 | spin_lock(&root->fs_info->delalloc_lock); |
1288 | if (state->end - state->start + 1 > | 1320 | if (state->end - state->start + 1 > |
@@ -3598,12 +3630,14 @@ static int btrfs_dentry_delete(struct dentry *dentry) | |||
3598 | { | 3630 | { |
3599 | struct btrfs_root *root; | 3631 | struct btrfs_root *root; |
3600 | 3632 | ||
3601 | if (!dentry->d_inode) | 3633 | if (!dentry->d_inode && !IS_ROOT(dentry)) |
3602 | return 0; | 3634 | dentry = dentry->d_parent; |
3603 | 3635 | ||
3604 | root = BTRFS_I(dentry->d_inode)->root; | 3636 | if (dentry->d_inode) { |
3605 | if (btrfs_root_refs(&root->root_item) == 0) | 3637 | root = BTRFS_I(dentry->d_inode)->root; |
3606 | return 1; | 3638 | if (btrfs_root_refs(&root->root_item) == 0) |
3639 | return 1; | ||
3640 | } | ||
3607 | return 0; | 3641 | return 0; |
3608 | } | 3642 | } |
3609 | 3643 | ||
@@ -4808,7 +4842,8 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
4808 | */ | 4842 | */ |
4809 | clear_extent_bit(tree, page_start, page_end, | 4843 | clear_extent_bit(tree, page_start, page_end, |
4810 | EXTENT_DIRTY | EXTENT_DELALLOC | | 4844 | EXTENT_DIRTY | EXTENT_DELALLOC | |
4811 | EXTENT_LOCKED, 1, 0, NULL, GFP_NOFS); | 4845 | EXTENT_LOCKED | EXTENT_DO_ACCOUNTING, 1, 0, |
4846 | NULL, GFP_NOFS); | ||
4812 | /* | 4847 | /* |
4813 | * whoever cleared the private bit is responsible | 4848 | * whoever cleared the private bit is responsible |
4814 | * for the finish_ordered_io | 4849 | * for the finish_ordered_io |
@@ -4821,8 +4856,8 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
4821 | lock_extent(tree, page_start, page_end, GFP_NOFS); | 4856 | lock_extent(tree, page_start, page_end, GFP_NOFS); |
4822 | } | 4857 | } |
4823 | clear_extent_bit(tree, page_start, page_end, | 4858 | clear_extent_bit(tree, page_start, page_end, |
4824 | EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC, | 4859 | EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC | |
4825 | 1, 1, NULL, GFP_NOFS); | 4860 | EXTENT_DO_ACCOUNTING, 1, 1, NULL, GFP_NOFS); |
4826 | __btrfs_releasepage(page, GFP_NOFS); | 4861 | __btrfs_releasepage(page, GFP_NOFS); |
4827 | 4862 | ||
4828 | ClearPageChecked(page); | 4863 | ClearPageChecked(page); |
@@ -4917,7 +4952,8 @@ again: | |||
4917 | * prepare_pages in the normal write path. | 4952 | * prepare_pages in the normal write path. |
4918 | */ | 4953 | */ |
4919 | clear_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, | 4954 | clear_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, |
4920 | EXTENT_DIRTY | EXTENT_DELALLOC, GFP_NOFS); | 4955 | EXTENT_DIRTY | EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING, |
4956 | GFP_NOFS); | ||
4921 | 4957 | ||
4922 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end); | 4958 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end); |
4923 | if (ret) { | 4959 | if (ret) { |
@@ -5065,8 +5101,9 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
5065 | return NULL; | 5101 | return NULL; |
5066 | ei->last_trans = 0; | 5102 | ei->last_trans = 0; |
5067 | ei->logged_trans = 0; | 5103 | ei->logged_trans = 0; |
5068 | ei->delalloc_extents = 0; | 5104 | ei->outstanding_extents = 0; |
5069 | ei->delalloc_reserved_extents = 0; | 5105 | ei->reserved_extents = 0; |
5106 | spin_lock_init(&ei->accounting_lock); | ||
5070 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); | 5107 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); |
5071 | INIT_LIST_HEAD(&ei->i_orphan); | 5108 | INIT_LIST_HEAD(&ei->i_orphan); |
5072 | INIT_LIST_HEAD(&ei->ordered_operations); | 5109 | INIT_LIST_HEAD(&ei->ordered_operations); |
@@ -5805,6 +5842,6 @@ static const struct inode_operations btrfs_symlink_inode_operations = { | |||
5805 | .removexattr = btrfs_removexattr, | 5842 | .removexattr = btrfs_removexattr, |
5806 | }; | 5843 | }; |
5807 | 5844 | ||
5808 | struct dentry_operations btrfs_dentry_operations = { | 5845 | const struct dentry_operations btrfs_dentry_operations = { |
5809 | .d_delete = btrfs_dentry_delete, | 5846 | .d_delete = btrfs_dentry_delete, |
5810 | }; | 5847 | }; |
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/tree-log.c b/fs/btrfs/tree-log.c index 7827841b55cb..4edfdc2acc5f 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); |
@@ -1985,7 +1994,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
1985 | if (atomic_read(&root->log_commit[(index1 + 1) % 2])) | 1994 | if (atomic_read(&root->log_commit[(index1 + 1) % 2])) |
1986 | wait_log_commit(trans, root, root->log_transid - 1); | 1995 | wait_log_commit(trans, root, root->log_transid - 1); |
1987 | 1996 | ||
1988 | while (1) { | 1997 | while (root->log_multiple_pids) { |
1989 | unsigned long batch = root->log_batch; | 1998 | unsigned long batch = root->log_batch; |
1990 | mutex_unlock(&root->log_mutex); | 1999 | mutex_unlock(&root->log_mutex); |
1991 | schedule_timeout_uninterruptible(1); | 2000 | schedule_timeout_uninterruptible(1); |
@@ -2011,6 +2020,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2011 | root->log_batch = 0; | 2020 | root->log_batch = 0; |
2012 | root->log_transid++; | 2021 | root->log_transid++; |
2013 | log->log_transid = root->log_transid; | 2022 | log->log_transid = root->log_transid; |
2023 | root->log_start_pid = 0; | ||
2014 | smp_mb(); | 2024 | smp_mb(); |
2015 | /* | 2025 | /* |
2016 | * log tree has been flushed to disk, new modifications of | 2026 | * log tree has been flushed to disk, new modifications of |
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 | ||
diff --git a/fs/ext3/super.c b/fs/ext3/super.c index 72743d360509..7a520a862f49 100644 --- a/fs/ext3/super.c +++ b/fs/ext3/super.c | |||
@@ -2321,7 +2321,18 @@ static int ext3_commit_super(struct super_block *sb, | |||
2321 | 2321 | ||
2322 | if (!sbh) | 2322 | if (!sbh) |
2323 | return error; | 2323 | return error; |
2324 | es->s_wtime = cpu_to_le32(get_seconds()); | 2324 | /* |
2325 | * If the file system is mounted read-only, don't update the | ||
2326 | * superblock write time. This avoids updating the superblock | ||
2327 | * write time when we are mounting the root file system | ||
2328 | * read/only but we need to replay the journal; at that point, | ||
2329 | * for people who are east of GMT and who make their clock | ||
2330 | * tick in localtime for Windows bug-for-bug compatibility, | ||
2331 | * the clock is set in the future, and this will cause e2fsck | ||
2332 | * to complain and force a full file system check. | ||
2333 | */ | ||
2334 | if (!(sb->s_flags & MS_RDONLY)) | ||
2335 | es->s_wtime = cpu_to_le32(get_seconds()); | ||
2325 | es->s_free_blocks_count = cpu_to_le32(ext3_count_free_blocks(sb)); | 2336 | 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)); | 2337 | es->s_free_inodes_count = cpu_to_le32(ext3_count_free_inodes(sb)); |
2327 | BUFFER_TRACE(sbh, "marking dirty"); | 2338 | BUFFER_TRACE(sbh, "marking dirty"); |
@@ -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/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/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/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/super.c b/fs/nfs/super.c index 29786d3b9326..a2c18acb8568 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 | /* |
@@ -1475,7 +1475,7 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args, | |||
1475 | args->mount_server.addrlen = args->nfs_server.addrlen; | 1475 | args->mount_server.addrlen = args->nfs_server.addrlen; |
1476 | } | 1476 | } |
1477 | request.salen = args->mount_server.addrlen; | 1477 | request.salen = args->mount_server.addrlen; |
1478 | nfs_set_default_port(request.sap, args->mount_server.port, 0); | 1478 | nfs_set_port(request.sap, &args->mount_server.port, 0); |
1479 | 1479 | ||
1480 | /* | 1480 | /* |
1481 | * Now ask the mount server to map our export path | 1481 | * Now ask the mount server to map our export path |
@@ -1711,8 +1711,6 @@ static int nfs_validate_mount_data(void *options, | |||
1711 | 1711 | ||
1712 | if (!(data->flags & NFS_MOUNT_TCP)) | 1712 | if (!(data->flags & NFS_MOUNT_TCP)) |
1713 | args->nfs_server.protocol = XPRT_TRANSPORT_UDP; | 1713 | 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 */ | 1714 | /* N.B. caller will free nfs_server.hostname in all cases */ |
1717 | args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); | 1715 | args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); |
1718 | args->namlen = data->namlen; | 1716 | args->namlen = data->namlen; |
@@ -1767,7 +1765,7 @@ static int nfs_validate_mount_data(void *options, | |||
1767 | goto out_v4_not_compiled; | 1765 | goto out_v4_not_compiled; |
1768 | #endif | 1766 | #endif |
1769 | 1767 | ||
1770 | nfs_set_default_port(sap, args->nfs_server.port, 0); | 1768 | nfs_set_port(sap, &args->nfs_server.port, 0); |
1771 | 1769 | ||
1772 | nfs_set_mount_transport_protocol(args); | 1770 | nfs_set_mount_transport_protocol(args); |
1773 | 1771 | ||
@@ -1848,9 +1846,10 @@ nfs_compare_remount_data(struct nfs_server *nfss, | |||
1848 | data->acdirmin != nfss->acdirmin / HZ || | 1846 | data->acdirmin != nfss->acdirmin / HZ || |
1849 | data->acdirmax != nfss->acdirmax / HZ || | 1847 | data->acdirmax != nfss->acdirmax / HZ || |
1850 | data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) || | 1848 | data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) || |
1849 | data->nfs_server.port != nfss->port || | ||
1851 | data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen || | 1850 | data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen || |
1852 | memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr, | 1851 | !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address, |
1853 | data->nfs_server.addrlen) != 0) | 1852 | (struct sockaddr *)&nfss->nfs_client->cl_addr)) |
1854 | return -EINVAL; | 1853 | return -EINVAL; |
1855 | 1854 | ||
1856 | return 0; | 1855 | return 0; |
@@ -1893,6 +1892,7 @@ nfs_remount(struct super_block *sb, int *flags, char *raw_data) | |||
1893 | data->acdirmin = nfss->acdirmin / HZ; | 1892 | data->acdirmin = nfss->acdirmin / HZ; |
1894 | data->acdirmax = nfss->acdirmax / HZ; | 1893 | data->acdirmax = nfss->acdirmax / HZ; |
1895 | data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ; | 1894 | data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ; |
1895 | data->nfs_server.port = nfss->port; | ||
1896 | data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen; | 1896 | data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen; |
1897 | memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr, | 1897 | memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr, |
1898 | data->nfs_server.addrlen); | 1898 | data->nfs_server.addrlen); |
@@ -2106,7 +2106,7 @@ static int nfs_get_sb(struct file_system_type *fs_type, | |||
2106 | }; | 2106 | }; |
2107 | int error = -ENOMEM; | 2107 | int error = -ENOMEM; |
2108 | 2108 | ||
2109 | data = nfs_alloc_parsed_mount_data(NFS_MOUNT_VER3 | NFS_MOUNT_TCP); | 2109 | data = nfs_alloc_parsed_mount_data(3); |
2110 | mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL); | 2110 | mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL); |
2111 | if (data == NULL || mntfh == NULL) | 2111 | if (data == NULL || mntfh == NULL) |
2112 | goto out_free_fh; | 2112 | goto out_free_fh; |
@@ -2331,7 +2331,7 @@ static int nfs4_validate_text_mount_data(void *options, | |||
2331 | { | 2331 | { |
2332 | struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; | 2332 | struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; |
2333 | 2333 | ||
2334 | nfs_set_default_port(sap, args->nfs_server.port, NFS_PORT); | 2334 | nfs_set_port(sap, &args->nfs_server.port, NFS_PORT); |
2335 | 2335 | ||
2336 | nfs_validate_transport_protocol(args); | 2336 | nfs_validate_transport_protocol(args); |
2337 | 2337 | ||
@@ -2376,7 +2376,6 @@ static int nfs4_validate_mount_data(void *options, | |||
2376 | if (data == NULL) | 2376 | if (data == NULL) |
2377 | goto out_no_data; | 2377 | goto out_no_data; |
2378 | 2378 | ||
2379 | args->version = 4; | ||
2380 | switch (data->version) { | 2379 | switch (data->version) { |
2381 | case 1: | 2380 | case 1: |
2382 | if (data->host_addrlen > sizeof(args->nfs_server.address)) | 2381 | if (data->host_addrlen > sizeof(args->nfs_server.address)) |
@@ -2660,7 +2659,7 @@ static int nfs4_get_sb(struct file_system_type *fs_type, | |||
2660 | struct nfs_parsed_mount_data *data; | 2659 | struct nfs_parsed_mount_data *data; |
2661 | int error = -ENOMEM; | 2660 | int error = -ENOMEM; |
2662 | 2661 | ||
2663 | data = nfs_alloc_parsed_mount_data(0); | 2662 | data = nfs_alloc_parsed_mount_data(4); |
2664 | if (data == NULL) | 2663 | if (data == NULL) |
2665 | goto out_free_data; | 2664 | goto out_free_data; |
2666 | 2665 | ||
@@ -2690,7 +2689,6 @@ static void nfs4_kill_super(struct super_block *sb) | |||
2690 | dprintk("--> %s\n", __func__); | 2689 | dprintk("--> %s\n", __func__); |
2691 | nfs_super_return_all_delegations(sb); | 2690 | nfs_super_return_all_delegations(sb); |
2692 | kill_anon_super(sb); | 2691 | kill_anon_super(sb); |
2693 | nfs4_renewd_prepare_shutdown(server); | ||
2694 | nfs_fscache_release_super_cookie(sb); | 2692 | nfs_fscache_release_super_cookie(sb); |
2695 | nfs_free_server(server); | 2693 | nfs_free_server(server); |
2696 | dprintk("<-- %s\n", __func__); | 2694 | dprintk("<-- %s\n", __func__); |
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/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/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_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/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_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_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 |