History

Merge branch 'for-chris' of http://git.kernel.org/pub/scm/linux/kernel/git/josef/btrfs-work into integration

Conflicts: fs/btrfs/inode.c

Chris Mason committed 14 years ago

Commit 567a45e2 parents e755d9a e65cbb911 files · +211 −117Browse files

Unified · Split

11 files
  1. fs/btrfs/async-thread.c +54 −61
  2. fs/btrfs/async-thread.h +2 −2
  3. fs/btrfs/ctree.h +2 −1
  4. fs/btrfs/disk-io.c +21 −13
  5. fs/btrfs/extent-tree.c +31 −14
  6. fs/btrfs/file.c +5 −1
  7. fs/btrfs/inode.c +74 −22
  8. fs/btrfs/ioctl.c +2 −0
  9. fs/btrfs/relocation.c +2 −0
  10. fs/btrfs/scrub.c +6 −2
  11. fs/btrfs/super.c +12 −1
fs/btrfs/async-thread.c+54−61
@@ -64,6 +64,8 @@ struct btrfs_worker_thread { · 63 unmodified lines
6464 int idle;
6565 };
6666
67+static int __btrfs_start_workers(struct btrfs_workers *workers);
68+
6769 /*
6870 * btrfs_start_workers uses kthread_run, which can block waiting for memory
6971 * for a very long time. It will actually throttle on page writeback,
@@ -88,27 +90,10 @@ static void start_new_worker_func(struct btrfs_work *work) · 18 unmodified lines
8890 {
8991 struct worker_start *start;
9092 start = container_of(work, struct worker_start, work);
91− btrfs_start_workers(start->queue, 1);
93+ __btrfs_start_workers(start->queue);
9294 kfree(start);
9395 }
9496
95−static int start_new_worker(struct btrfs_workers *queue)
96−{
97− struct worker_start *start;
98− int ret;
99−
100− start = kzalloc(sizeof(*start), GFP_NOFS);
101− if (!start)
102− return -ENOMEM;
103−
104− start->work.func = start_new_worker_func;
105− start->queue = queue;
106− ret = btrfs_queue_worker(queue->atomic_worker_start, &start->work);
107− if (ret)
108− kfree(start);
109− return ret;
110−}
111−
11297 /*
11398 * helper function to move a thread onto the idle list after it
11499 * has finished some requests.
@@ -153,12 +138,20 @@ static void check_busy_worker(struct btrfs_worker_thread *worker) · 38 unmodified lines
153138 static void check_pending_worker_creates(struct btrfs_worker_thread *worker)
154139 {
155140 struct btrfs_workers *workers = worker->workers;
141+ struct worker_start *start;
156142 unsigned long flags;
157143
158144 rmb();
159145 if (!workers->atomic_start_pending)
160146 return;
161147
148+ start = kzalloc(sizeof(*start), GFP_NOFS);
149+ if (!start)
150+ return;
151+
152+ start->work.func = start_new_worker_func;
153+ start->queue = workers;
154+
162155 spin_lock_irqsave(&workers->lock, flags);
163156 if (!workers->atomic_start_pending)
164157 goto out;
@@ -170,10 +163,11 @@ static void check_pending_worker_creates(struct btrfs_worker_thread *worker) · 5 unmodified lines
170163
171164 workers->num_workers_starting += 1;
172165 spin_unlock_irqrestore(&workers->lock, flags);
173− start_new_worker(workers);
166+ btrfs_queue_worker(workers->atomic_worker_start, &start->work);
174167 return;
175168
176169 out:
170+ kfree(start);
177171 spin_unlock_irqrestore(&workers->lock, flags);
178172 }
179173
@@ -462,56 +456,55 @@ void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max, · 282 unmodified lines
462456 * starts new worker threads. This does not enforce the max worker
463457 * count in case you need to temporarily go past it.
464458 */
465−static int __btrfs_start_workers(struct btrfs_workers *workers,
466− int num_workers)
459+static int __btrfs_start_workers(struct btrfs_workers *workers)
467460 {
468461 struct btrfs_worker_thread *worker;
469462 int ret = 0;
470− int i;
471463
472− for (i = 0; i < num_workers; i++) {
473− worker = kzalloc(sizeof(*worker), GFP_NOFS);
474− if (!worker) {
475− ret = -ENOMEM;
476− goto fail;
477− }
464+ worker = kzalloc(sizeof(*worker), GFP_NOFS);
465+ if (!worker) {
466+ ret = -ENOMEM;
467+ goto fail;
468+ }
478469
479− INIT_LIST_HEAD(&worker->pending);
480− INIT_LIST_HEAD(&worker->prio_pending);
481− INIT_LIST_HEAD(&worker->worker_list);
482− spin_lock_init(&worker->lock);
483−
484− atomic_set(&worker->num_pending, 0);
485− atomic_set(&worker->refs, 1);
486− worker->workers = workers;
487− worker->task = kthread_run(worker_loop, worker,
488− "btrfs-%s-%d", workers->name,
489− workers->num_workers + i);
490− if (IS_ERR(worker->task)) {
491− ret = PTR_ERR(worker->task);
492− kfree(worker);
493− goto fail;
494− }
495− spin_lock_irq(&workers->lock);
496− list_add_tail(&worker->worker_list, &workers->idle_list);
497− worker->idle = 1;
498− workers->num_workers++;
499− workers->num_workers_starting--;
500− WARN_ON(workers->num_workers_starting < 0);
501− spin_unlock_irq(&workers->lock);
470+ INIT_LIST_HEAD(&worker->pending);
471+ INIT_LIST_HEAD(&worker->prio_pending);
472+ INIT_LIST_HEAD(&worker->worker_list);
473+ spin_lock_init(&worker->lock);
474+
475+ atomic_set(&worker->num_pending, 0);
476+ atomic_set(&worker->refs, 1);
477+ worker->workers = workers;
478+ worker->task = kthread_run(worker_loop, worker,
479+ "btrfs-%s-%d", workers->name,
480+ workers->num_workers + 1);
481+ if (IS_ERR(worker->task)) {
482+ ret = PTR_ERR(worker->task);
483+ kfree(worker);
484+ goto fail;
502485 }
486+ spin_lock_irq(&workers->lock);
487+ list_add_tail(&worker->worker_list, &workers->idle_list);
488+ worker->idle = 1;
489+ workers->num_workers++;
490+ workers->num_workers_starting--;
491+ WARN_ON(workers->num_workers_starting < 0);
492+ spin_unlock_irq(&workers->lock);
493+
503494 return 0;
504495 fail:
505− btrfs_stop_workers(workers);
496+ spin_lock_irq(&workers->lock);
497+ workers->num_workers_starting--;
498+ spin_unlock_irq(&workers->lock);
506499 return ret;
507500 }
508501
509−int btrfs_start_workers(struct btrfs_workers *workers, int num_workers)
502+int btrfs_start_workers(struct btrfs_workers *workers)
510503 {
511504 spin_lock_irq(&workers->lock);
512− workers->num_workers_starting += num_workers;
505+ workers->num_workers_starting++;
513506 spin_unlock_irq(&workers->lock);
514− return __btrfs_start_workers(workers, num_workers);
507+ return __btrfs_start_workers(workers);
515508 }
516509
517510 /*
@@ -568,6 +561,7 @@ static struct btrfs_worker_thread *find_worker(struct btrfs_workers *workers) · 50 unmodified lines
568561 struct btrfs_worker_thread *worker;
569562 unsigned long flags;
570563 struct list_head *fallback;
564+ int ret;
571565
572566 again:
573567 spin_lock_irqsave(&workers->lock, flags);
@@ -584,7 +578,9 @@ again: · 10 unmodified lines
584578 workers->num_workers_starting++;
585579 spin_unlock_irqrestore(&workers->lock, flags);
586580 /* we're below the limit, start another worker */
587− __btrfs_start_workers(workers, 1);
581+ ret = __btrfs_start_workers(workers);
582+ if (ret)
583+ goto fallback;
588584 goto again;
589585 }
590586 }
@@ -665,7 +661,7 @@ void btrfs_set_work_high_prio(struct btrfs_work *work) · 74 unmodified lines
665661 /*
666662 * places a struct btrfs_work into the pending queue of one of the kthreads
667663 */
668−int btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work)
664+void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work)
669665 {
670666 struct btrfs_worker_thread *worker;
671667 unsigned long flags;
@@ -673,7 +669,7 @@ int btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work) · 1 unmodified line
673669
674670 /* don't requeue something already on a list */
675671 if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags))
676− goto out;
672+ return;
677673
678674 worker = find_worker(workers);
679675 if (workers->ordered) {
@@ -712,7 +708,4 @@ int btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work) · 32 unmodified lines
712708 if (wake)
713709 wake_up_process(worker->task);
714710 spin_unlock_irqrestore(&worker->lock, flags);
715−
716−out:
717− return 0;
718711 }
fs/btrfs/async-thread.h+2−2
@@ -109,8 +109,8 @@ struct btrfs_workers { · 108 unmodified lines
109109 char *name;
110110 };
111111
112−int btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work);
113−int btrfs_start_workers(struct btrfs_workers *workers, int num_workers);
112+void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work);
113+int btrfs_start_workers(struct btrfs_workers *workers);
114114 int btrfs_stop_workers(struct btrfs_workers *workers);
115115 void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max,
116116 struct btrfs_workers *async_starter);
fs/btrfs/ctree.h+2−1
@@ -2692,7 +2692,8 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf); · 2691 unmodified lines
26922692 int btrfs_readpage(struct file *file, struct page *page);
26932693 void btrfs_evict_inode(struct inode *inode);
26942694 int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc);
2695−void btrfs_dirty_inode(struct inode *inode, int flags);
2695+int btrfs_dirty_inode(struct inode *inode);
2696+int btrfs_update_time(struct file *file);
26962697 struct inode *btrfs_alloc_inode(struct super_block *sb);
26972698 void btrfs_destroy_inode(struct inode *inode);
26982699 int btrfs_drop_inode(struct inode *inode);
fs/btrfs/disk-io.c+21−13
@@ -2194,19 +2194,27 @@ struct btrfs_root *open_ctree(struct super_block *sb, · 2193 unmodified lines
21942194 fs_info->endio_meta_write_workers.idle_thresh = 2;
21952195 fs_info->readahead_workers.idle_thresh = 2;
21962196
2197− btrfs_start_workers(&fs_info->workers, 1);
2198− btrfs_start_workers(&fs_info->generic_worker, 1);
2199− btrfs_start_workers(&fs_info->submit_workers, 1);
2200− btrfs_start_workers(&fs_info->delalloc_workers, 1);
2201− btrfs_start_workers(&fs_info->fixup_workers, 1);
2202− btrfs_start_workers(&fs_info->endio_workers, 1);
2203− btrfs_start_workers(&fs_info->endio_meta_workers, 1);
2204− btrfs_start_workers(&fs_info->endio_meta_write_workers, 1);
2205− btrfs_start_workers(&fs_info->endio_write_workers, 1);
2206− btrfs_start_workers(&fs_info->endio_freespace_worker, 1);
2207− btrfs_start_workers(&fs_info->delayed_workers, 1);
2208− btrfs_start_workers(&fs_info->caching_workers, 1);
2209− btrfs_start_workers(&fs_info->readahead_workers, 1);
2197+ /*
2198+ * btrfs_start_workers can really only fail because of ENOMEM so just
2199+ * return -ENOMEM if any of these fail.
2200+ */
2201+ ret = btrfs_start_workers(&fs_info->workers);
2202+ ret |= btrfs_start_workers(&fs_info->generic_worker);
2203+ ret |= btrfs_start_workers(&fs_info->submit_workers);
2204+ ret |= btrfs_start_workers(&fs_info->delalloc_workers);
2205+ ret |= btrfs_start_workers(&fs_info->fixup_workers);
2206+ ret |= btrfs_start_workers(&fs_info->endio_workers);
2207+ ret |= btrfs_start_workers(&fs_info->endio_meta_workers);
2208+ ret |= btrfs_start_workers(&fs_info->endio_meta_write_workers);
2209+ ret |= btrfs_start_workers(&fs_info->endio_write_workers);
2210+ ret |= btrfs_start_workers(&fs_info->endio_freespace_worker);
2211+ ret |= btrfs_start_workers(&fs_info->delayed_workers);
2212+ ret |= btrfs_start_workers(&fs_info->caching_workers);
2213+ ret |= btrfs_start_workers(&fs_info->readahead_workers);
2214+ if (ret) {
2215+ ret = -ENOMEM;
2216+ goto fail_sb_buffer;
2217+ }
22102218
22112219 fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super);
22122220 fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages,
fs/btrfs/extent-tree.c+31−14
@@ -2822,7 +2822,7 @@ out_free: · 2821 unmodified lines
28222822 btrfs_release_path(path);
28232823 out:
28242824 spin_lock(&block_group->lock);
2825− if (!ret)
2825+ if (!ret && dcs == BTRFS_DC_SETUP)
28262826 block_group->cache_generation = trans->transid;
28272827 block_group->disk_cache_state = dcs;
28282828 spin_unlock(&block_group->lock);
@@ -4203,12 +4203,17 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) · 1374 unmodified lines
42034203 struct btrfs_root *root = BTRFS_I(inode)->root;
42044204 struct btrfs_block_rsv *block_rsv = &root->fs_info->delalloc_block_rsv;
42054205 u64 to_reserve = 0;
4206+ u64 csum_bytes;
42064207 unsigned nr_extents = 0;
4208+ int extra_reserve = 0;
42074209 int flush = 1;
42084210 int ret;
42094211
4212+ /* Need to be holding the i_mutex here if we aren't free space cache */
42104213 if (btrfs_is_free_space_inode(root, inode))
42114214 flush = 0;
4215+ else
4216+ WARN_ON(!mutex_is_locked(&inode->i_mutex));
42124217
42134218 if (flush && btrfs_transaction_in_commit(root->fs_info))
42144219 schedule_timeout(1);
@@ -4219,11 +4224,9 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) · 4 unmodified lines
42194224 BTRFS_I(inode)->outstanding_extents++;
42204225
42214226 if (BTRFS_I(inode)->outstanding_extents >
4222− BTRFS_I(inode)->reserved_extents) {
4227+ BTRFS_I(inode)->reserved_extents)
42234228 nr_extents = BTRFS_I(inode)->outstanding_extents -
42244229 BTRFS_I(inode)->reserved_extents;
4225− BTRFS_I(inode)->reserved_extents += nr_extents;
4226− }
42274230
42284231 /*
42294232 * Add an item to reserve for updating the inode when we complete the
@@ -4231,11 +4234,12 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) · 1 unmodified line
42314234 */
42324235 if (!BTRFS_I(inode)->delalloc_meta_reserved) {
42334236 nr_extents++;
4234− BTRFS_I(inode)->delalloc_meta_reserved = 1;
4237+ extra_reserve = 1;
42354238 }
42364239
42374240 to_reserve = btrfs_calc_trans_metadata_size(root, nr_extents);
42384241 to_reserve += calc_csum_metadata_size(inode, num_bytes, 1);
4242+ csum_bytes = BTRFS_I(inode)->csum_bytes;
42394243 spin_unlock(&BTRFS_I(inode)->lock);
42404244
42414245 ret = reserve_metadata_bytes(root, block_rsv, to_reserve, flush);
@@ -4245,22 +4249,35 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) · 3 unmodified lines
42454249
42464250 spin_lock(&BTRFS_I(inode)->lock);
42474251 dropped = drop_outstanding_extent(inode);
4248− to_free = calc_csum_metadata_size(inode, num_bytes, 0);
4249− spin_unlock(&BTRFS_I(inode)->lock);
4250− to_free += btrfs_calc_trans_metadata_size(root, dropped);
4251−
42524252 /*
4253− * Somebody could have come in and twiddled with the
4254− * reservation, so if we have to free more than we would have
4255− * reserved from this reservation go ahead and release those
4256− * bytes.
4253+ * If the inodes csum_bytes is the same as the original
4254+ * csum_bytes then we know we haven't raced with any free()ers
4255+ * so we can just reduce our inodes csum bytes and carry on.
4256+ * Otherwise we have to do the normal free thing to account for
4257+ * the case that the free side didn't free up its reserve
4258+ * because of this outstanding reservation.
42574259 */
4258− to_free -= to_reserve;
4260+ if (BTRFS_I(inode)->csum_bytes == csum_bytes)
4261+ calc_csum_metadata_size(inode, num_bytes, 0);
4262+ else
4263+ to_free = calc_csum_metadata_size(inode, num_bytes, 0);
4264+ spin_unlock(&BTRFS_I(inode)->lock);
4265+ if (dropped)
4266+ to_free += btrfs_calc_trans_metadata_size(root, dropped);
4267+
42594268 if (to_free)
42604269 btrfs_block_rsv_release(root, block_rsv, to_free);
42614270 return ret;
42624271 }
42634272
4273+ spin_lock(&BTRFS_I(inode)->lock);
4274+ if (extra_reserve) {
4275+ BTRFS_I(inode)->delalloc_meta_reserved = 1;
4276+ nr_extents--;
4277+ }
4278+ BTRFS_I(inode)->reserved_extents += nr_extents;
4279+ spin_unlock(&BTRFS_I(inode)->lock);
4280+
42644281 block_rsv_add_bytes(block_rsv, to_reserve, 1);
42654282
42664283 return 0;
fs/btrfs/file.c+5−1
@@ -1387,7 +1387,11 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb, · 1386 unmodified lines
13871387 goto out;
13881388 }
13891389
1390− file_update_time(file);
1390+ err = btrfs_update_time(file);
1391+ if (err) {
1392+ mutex_unlock(&inode->i_mutex);
1393+ goto out;
1394+ }
13911395 BTRFS_I(inode)->sequence++;
13921396
13931397 start_pos = round_down(pos, root->sectorsize);
fs/btrfs/inode.c+74−22
@@ -38,6 +38,7 @@ · 37 unmodified lines
3838 #include <linux/falloc.h>
3939 #include <linux/slab.h>
4040 #include <linux/ratelimit.h>
41+#include <linux/mount.h>
4142 #include "compat.h"
4243 #include "ctree.h"
4344 #include "disk-io.h"
@@ -2031,7 +2032,7 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode) · 1987 unmodified lines
20312032 /* insert an orphan item to track this unlinked/truncated file */
20322033 if (insert >= 1) {
20332034 ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode));
2034− BUG_ON(ret);
2035+ BUG_ON(ret && ret != -EEXIST);
20352036 }
20362037
20372038 /* insert an orphan item to track subvolume contains orphan files */
@@ -2223,7 +2224,14 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) · 185 unmodified lines
22232224 continue;
22242225 }
22252226 nr_truncate++;
2227+ /*
2228+ * Need to hold the imutex for reservation purposes, not
2229+ * a huge deal here but I have a WARN_ON in
2230+ * btrfs_delalloc_reserve_space to catch offenders.
2231+ */
2232+ mutex_lock(&inode->i_mutex);
22262233 ret = btrfs_truncate(inode);
2234+ mutex_unlock(&inode->i_mutex);
22272235 } else {
22282236 nr_unlink++;
22292237 }
@@ -3426,7 +3434,6 @@ static int btrfs_setsize(struct inode *inode, loff_t newsize) · 1196 unmodified lines
34263434 i_size_write(inode, newsize);
34273435 btrfs_ordered_update_i_size(inode, i_size_read(inode), NULL);
34283436 ret = btrfs_update_inode(trans, root, inode);
3429−
34303437 btrfs_end_transaction_throttle(trans, root);
34313438 } else {
34323439
@@ -3467,9 +3474,9 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) · 34 unmodified lines
34673474
34683475 if (attr->ia_valid) {
34693476 setattr_copy(inode, attr);
3470− mark_inode_dirty(inode);
3477+ err = btrfs_dirty_inode(inode);
34713478
3472− if (attr->ia_valid & ATTR_MODE)
3479+ if (!err && attr->ia_valid & ATTR_MODE)
34733480 err = btrfs_acl_chmod(inode);
34743481 }
34753482
@@ -4245,42 +4252,80 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc) · 769 unmodified lines
42454252 * FIXME, needs more benchmarking...there are no reasons other than performance
42464253 * to keep or drop this code.
42474254 */
4248−void btrfs_dirty_inode(struct inode *inode, int flags)
4255+int btrfs_dirty_inode(struct inode *inode)
42494256 {
42504257 struct btrfs_root *root = BTRFS_I(inode)->root;
42514258 struct btrfs_trans_handle *trans;
42524259 int ret;
42534260
42544261 if (BTRFS_I(inode)->dummy_inode)
4255− return;
4262+ return 0;
42564263
42574264 trans = btrfs_join_transaction(root);
4258− BUG_ON(IS_ERR(trans));
4265+ if (IS_ERR(trans))
4266+ return PTR_ERR(trans);
42594267
42604268 ret = btrfs_update_inode(trans, root, inode);
42614269 if (ret && ret == -ENOSPC) {
42624270 /* whoops, lets try again with the full transaction */
42634271 btrfs_end_transaction(trans, root);
42644272 trans = btrfs_start_transaction(root, 1);
4265− if (IS_ERR(trans)) {
4266− printk_ratelimited(KERN_ERR "btrfs: fail to "
4267− "dirty inode %llu error %ld\n",
4268− (unsigned long long)btrfs_ino(inode),
4269− PTR_ERR(trans));
4270− return;
4271− }
4273+ if (IS_ERR(trans))
4274+ return PTR_ERR(trans);
42724275
42734276 ret = btrfs_update_inode(trans, root, inode);
4274− if (ret) {
4275− printk_ratelimited(KERN_ERR "btrfs: fail to "
4276− "dirty inode %llu error %d\n",
4277− (unsigned long long)btrfs_ino(inode),
4278− ret);
4279− }
42804277 }
42814278 btrfs_end_transaction(trans, root);
42824279 if (BTRFS_I(inode)->delayed_node)
42834280 btrfs_balance_delayed_items(root);
4281+
4282+ return ret;
4283+}
4284+
4285+/*
4286+ * This is a copy of file_update_time. We need this so we can return error on
4287+ * ENOSPC for updating the inode in the case of file write and mmap writes.
4288+ */
4289+int btrfs_update_time(struct file *file)
4290+{
4291+ struct inode *inode = file->f_path.dentry->d_inode;
4292+ struct timespec now;
4293+ int ret;
4294+ enum { S_MTIME = 1, S_CTIME = 2, S_VERSION = 4 } sync_it = 0;
4295+
4296+ /* First try to exhaust all avenues to not sync */
4297+ if (IS_NOCMTIME(inode))
4298+ return 0;
4299+
4300+ now = current_fs_time(inode->i_sb);
4301+ if (!timespec_equal(&inode->i_mtime, &now))
4302+ sync_it = S_MTIME;
4303+
4304+ if (!timespec_equal(&inode->i_ctime, &now))
4305+ sync_it |= S_CTIME;
4306+
4307+ if (IS_I_VERSION(inode))
4308+ sync_it |= S_VERSION;
4309+
4310+ if (!sync_it)
4311+ return 0;
4312+
4313+ /* Finally allowed to write? Takes lock. */
4314+ if (mnt_want_write_file(file))
4315+ return 0;
4316+
4317+ /* Only change inode inside the lock region */
4318+ if (sync_it & S_VERSION)
4319+ inode_inc_iversion(inode);
4320+ if (sync_it & S_CTIME)
4321+ inode->i_ctime = now;
4322+ if (sync_it & S_MTIME)
4323+ inode->i_mtime = now;
4324+ ret = btrfs_dirty_inode(inode);
4325+ if (!ret)
4326+ mark_inode_dirty_sync(inode);
4327+ mnt_drop_write(file->f_path.mnt);
4328+ return ret;
42844329 }
42854330
42864331 /*
@@ -6358,7 +6403,12 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) · 2071 unmodified lines
63586403 u64 page_start;
63596404 u64 page_end;
63606405
6406+ /* Need this to keep space reservations serialized */
6407+ mutex_lock(&inode->i_mutex);
63616408 ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE);
6409+ mutex_unlock(&inode->i_mutex);
6410+ if (!ret)
6411+ ret = btrfs_update_time(vma->vm_file);
63626412 if (ret) {
63636413 if (ret == -ENOMEM)
63646414 ret = VM_FAULT_OOM;
@@ -6570,8 +6620,9 @@ static int btrfs_truncate(struct inode *inode) · 205 unmodified lines
65706620 /* Just need the 1 for updating the inode */
65716621 trans = btrfs_start_transaction(root, 1);
65726622 if (IS_ERR(trans)) {
6573− err = PTR_ERR(trans);
6574− goto out;
6623+ ret = err = PTR_ERR(trans);
6624+ trans = NULL;
6625+ break;
65756626 }
65766627 }
65776628
@@ -7415,6 +7466,7 @@ static const struct inode_operations btrfs_symlink_inode_operations = { · 837 unmodified lines
74157466 .follow_link = page_follow_link_light,
74167467 .put_link = page_put_link,
74177468 .getattr = btrfs_getattr,
7469+ .setattr = btrfs_setattr,
74187470 .permission = btrfs_permission,
74197471 .setxattr = btrfs_setxattr,
74207472 .getxattr = btrfs_getxattr,
fs/btrfs/ioctl.c+2−0
@@ -858,8 +858,10 @@ static int cluster_pages_for_defrag(struct inode *inode, · 857 unmodified lines
858858 return 0;
859859 file_end = (isize - 1) >> PAGE_CACHE_SHIFT;
860860
861+ mutex_lock(&inode->i_mutex);
861862 ret = btrfs_delalloc_reserve_space(inode,
862863 num_pages << PAGE_CACHE_SHIFT);
864+ mutex_unlock(&inode->i_mutex);
863865 if (ret)
864866 return ret;
865867 again:
fs/btrfs/relocation.c+2−0
@@ -2947,7 +2947,9 @@ static int relocate_file_extent_cluster(struct inode *inode, · 2946 unmodified lines
29472947 index = (cluster->start - offset) >> PAGE_CACHE_SHIFT;
29482948 last_index = (cluster->end - offset) >> PAGE_CACHE_SHIFT;
29492949 while (index <= last_index) {
2950+ mutex_lock(&inode->i_mutex);
29502951 ret = btrfs_delalloc_reserve_metadata(inode, PAGE_CACHE_SIZE);
2952+ mutex_unlock(&inode->i_mutex);
29512953 if (ret)
29522954 goto out;
29532955
fs/btrfs/scrub.c+6−2
@@ -1535,18 +1535,22 @@ static noinline_for_stack int scrub_supers(struct scrub_dev *sdev) · 1534 unmodified lines
15351535 static noinline_for_stack int scrub_workers_get(struct btrfs_root *root)
15361536 {
15371537 struct btrfs_fs_info *fs_info = root->fs_info;
1538+ int ret = 0;
15381539
15391540 mutex_lock(&fs_info->scrub_lock);
15401541 if (fs_info->scrub_workers_refcnt == 0) {
15411542 btrfs_init_workers(&fs_info->scrub_workers, "scrub",
15421543 fs_info->thread_pool_size, &fs_info->generic_worker);
15431544 fs_info->scrub_workers.idle_thresh = 4;
1544− btrfs_start_workers(&fs_info->scrub_workers, 1);
1545+ ret = btrfs_start_workers(&fs_info->scrub_workers);
1546+ if (ret)
1547+ goto out;
15451548 }
15461549 ++fs_info->scrub_workers_refcnt;
1550+out:
15471551 mutex_unlock(&fs_info->scrub_lock);
15481552
1549− return 0;
1553+ return ret;
15501554 }
15511555
15521556 static noinline_for_stack void scrub_workers_put(struct btrfs_root *root)
fs/btrfs/super.c+12−1
@@ -41,6 +41,7 @@ · 40 unmodified lines
4141 #include <linux/slab.h>
4242 #include <linux/cleancache.h>
4343 #include <linux/mnt_namespace.h>
44+#include <linux/ratelimit.h>
4445 #include "compat.h"
4546 #include "delayed-inode.h"
4647 #include "ctree.h"
@@ -1297,6 +1298,16 @@ static int btrfs_unfreeze(struct super_block *sb) · 1250 unmodified lines
12971298 return 0;
12981299 }
12991300
1301+static void btrfs_fs_dirty_inode(struct inode *inode, int flags)
1302+{
1303+ int ret;
1304+
1305+ ret = btrfs_dirty_inode(inode);
1306+ if (ret)
1307+ printk_ratelimited(KERN_ERR "btrfs: fail to dirty inode %Lu "
1308+ "error %d\n", btrfs_ino(inode), ret);
1309+}
1310+
13001311 static const struct super_operations btrfs_super_ops = {
13011312 .drop_inode = btrfs_drop_inode,
13021313 .evict_inode = btrfs_evict_inode,
@@ -1304,7 +1315,7 @@ static const struct super_operations btrfs_super_ops = { · 1 unmodified line
13041315 .sync_fs = btrfs_sync_fs,
13051316 .show_options = btrfs_show_options,
13061317 .write_inode = btrfs_write_inode,
1307− .dirty_inode = btrfs_dirty_inode,
1318+ .dirty_inode = btrfs_fs_dirty_inode,
13081319 .alloc_inode = btrfs_alloc_inode,
13091320 .destroy_inode = btrfs_destroy_inode,
13101321 .statfs = btrfs_statfs,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t