Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branches 'for-linus' and 'for-linus-3.2' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
Btrfs: unplug every once and a while
Btrfs: deal with NULL srv_rsv in the delalloc inode reservation code
Btrfs: only set cache_generation if we setup the block group
Btrfs: don't panic if orphan item already exists
Btrfs: fix leaked space in truncate
Btrfs: fix how we do delalloc reservations and how we free reservations on error
Btrfs: deal with enospc from dirtying inodes properly
Btrfs: fix num_workers_starting bug and other bugs in async thread
BTRFS: Establish i_ops before calling d_instantiate
Btrfs: add a cond_resched() into the worker loop
Btrfs: fix ctime update of on-disk inode
btrfs: keep orphans for subvolume deletion
Btrfs: fix inaccurate available space on raid0 profile
Btrfs: fix wrong disk space information of the files
Btrfs: fix wrong i_size when truncating a file to a larger size
Btrfs: fix btrfs_end_bio to deal with write errors to a single mirror

* 'for-linus-3.2' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
btrfs: lower the dirty balance poll interval

+312 -141
+56 -63
fs/btrfs/async-thread.c
··· 64 64 int idle; 65 65 }; 66 66 67 + static int __btrfs_start_workers(struct btrfs_workers *workers); 68 + 67 69 /* 68 70 * btrfs_start_workers uses kthread_run, which can block waiting for memory 69 71 * for a very long time. It will actually throttle on page writeback, ··· 90 88 { 91 89 struct worker_start *start; 92 90 start = container_of(work, struct worker_start, work); 93 - btrfs_start_workers(start->queue, 1); 91 + __btrfs_start_workers(start->queue); 94 92 kfree(start); 95 - } 96 - 97 - static int start_new_worker(struct btrfs_workers *queue) 98 - { 99 - struct worker_start *start; 100 - int ret; 101 - 102 - start = kzalloc(sizeof(*start), GFP_NOFS); 103 - if (!start) 104 - return -ENOMEM; 105 - 106 - start->work.func = start_new_worker_func; 107 - start->queue = queue; 108 - ret = btrfs_queue_worker(queue->atomic_worker_start, &start->work); 109 - if (ret) 110 - kfree(start); 111 - return ret; 112 93 } 113 94 114 95 /* ··· 138 153 static void check_pending_worker_creates(struct btrfs_worker_thread *worker) 139 154 { 140 155 struct btrfs_workers *workers = worker->workers; 156 + struct worker_start *start; 141 157 unsigned long flags; 142 158 143 159 rmb(); 144 160 if (!workers->atomic_start_pending) 145 161 return; 162 + 163 + start = kzalloc(sizeof(*start), GFP_NOFS); 164 + if (!start) 165 + return; 166 + 167 + start->work.func = start_new_worker_func; 168 + start->queue = workers; 146 169 147 170 spin_lock_irqsave(&workers->lock, flags); 148 171 if (!workers->atomic_start_pending) ··· 163 170 164 171 workers->num_workers_starting += 1; 165 172 spin_unlock_irqrestore(&workers->lock, flags); 166 - start_new_worker(workers); 173 + btrfs_queue_worker(workers->atomic_worker_start, &start->work); 167 174 return; 168 175 169 176 out: 177 + kfree(start); 170 178 spin_unlock_irqrestore(&workers->lock, flags); 171 179 } 172 180 ··· 325 331 run_ordered_completions(worker->workers, work); 326 332 327 333 check_pending_worker_creates(worker); 328 - 334 + cond_resched(); 329 335 } 330 336 331 337 spin_lock_irq(&worker->lock); ··· 456 462 * starts new worker threads. This does not enforce the max worker 457 463 * count in case you need to temporarily go past it. 458 464 */ 459 - static int __btrfs_start_workers(struct btrfs_workers *workers, 460 - int num_workers) 465 + static int __btrfs_start_workers(struct btrfs_workers *workers) 461 466 { 462 467 struct btrfs_worker_thread *worker; 463 468 int ret = 0; 464 - int i; 465 469 466 - for (i = 0; i < num_workers; i++) { 467 - worker = kzalloc(sizeof(*worker), GFP_NOFS); 468 - if (!worker) { 469 - ret = -ENOMEM; 470 - goto fail; 471 - } 472 - 473 - INIT_LIST_HEAD(&worker->pending); 474 - INIT_LIST_HEAD(&worker->prio_pending); 475 - INIT_LIST_HEAD(&worker->worker_list); 476 - spin_lock_init(&worker->lock); 477 - 478 - atomic_set(&worker->num_pending, 0); 479 - atomic_set(&worker->refs, 1); 480 - worker->workers = workers; 481 - worker->task = kthread_run(worker_loop, worker, 482 - "btrfs-%s-%d", workers->name, 483 - workers->num_workers + i); 484 - if (IS_ERR(worker->task)) { 485 - ret = PTR_ERR(worker->task); 486 - kfree(worker); 487 - goto fail; 488 - } 489 - spin_lock_irq(&workers->lock); 490 - list_add_tail(&worker->worker_list, &workers->idle_list); 491 - worker->idle = 1; 492 - workers->num_workers++; 493 - workers->num_workers_starting--; 494 - WARN_ON(workers->num_workers_starting < 0); 495 - spin_unlock_irq(&workers->lock); 470 + worker = kzalloc(sizeof(*worker), GFP_NOFS); 471 + if (!worker) { 472 + ret = -ENOMEM; 473 + goto fail; 496 474 } 475 + 476 + INIT_LIST_HEAD(&worker->pending); 477 + INIT_LIST_HEAD(&worker->prio_pending); 478 + INIT_LIST_HEAD(&worker->worker_list); 479 + spin_lock_init(&worker->lock); 480 + 481 + atomic_set(&worker->num_pending, 0); 482 + atomic_set(&worker->refs, 1); 483 + worker->workers = workers; 484 + worker->task = kthread_run(worker_loop, worker, 485 + "btrfs-%s-%d", workers->name, 486 + workers->num_workers + 1); 487 + if (IS_ERR(worker->task)) { 488 + ret = PTR_ERR(worker->task); 489 + kfree(worker); 490 + goto fail; 491 + } 492 + spin_lock_irq(&workers->lock); 493 + list_add_tail(&worker->worker_list, &workers->idle_list); 494 + worker->idle = 1; 495 + workers->num_workers++; 496 + workers->num_workers_starting--; 497 + WARN_ON(workers->num_workers_starting < 0); 498 + spin_unlock_irq(&workers->lock); 499 + 497 500 return 0; 498 501 fail: 499 - btrfs_stop_workers(workers); 502 + spin_lock_irq(&workers->lock); 503 + workers->num_workers_starting--; 504 + spin_unlock_irq(&workers->lock); 500 505 return ret; 501 506 } 502 507 503 - int btrfs_start_workers(struct btrfs_workers *workers, int num_workers) 508 + int btrfs_start_workers(struct btrfs_workers *workers) 504 509 { 505 510 spin_lock_irq(&workers->lock); 506 - workers->num_workers_starting += num_workers; 511 + workers->num_workers_starting++; 507 512 spin_unlock_irq(&workers->lock); 508 - return __btrfs_start_workers(workers, num_workers); 513 + return __btrfs_start_workers(workers); 509 514 } 510 515 511 516 /* ··· 561 568 struct btrfs_worker_thread *worker; 562 569 unsigned long flags; 563 570 struct list_head *fallback; 571 + int ret; 564 572 565 573 again: 566 574 spin_lock_irqsave(&workers->lock, flags); ··· 578 584 workers->num_workers_starting++; 579 585 spin_unlock_irqrestore(&workers->lock, flags); 580 586 /* we're below the limit, start another worker */ 581 - __btrfs_start_workers(workers, 1); 587 + ret = __btrfs_start_workers(workers); 588 + if (ret) 589 + goto fallback; 582 590 goto again; 583 591 } 584 592 } ··· 661 665 /* 662 666 * places a struct btrfs_work into the pending queue of one of the kthreads 663 667 */ 664 - int btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work) 668 + void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work) 665 669 { 666 670 struct btrfs_worker_thread *worker; 667 671 unsigned long flags; ··· 669 673 670 674 /* don't requeue something already on a list */ 671 675 if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags)) 672 - goto out; 676 + return; 673 677 674 678 worker = find_worker(workers); 675 679 if (workers->ordered) { ··· 708 712 if (wake) 709 713 wake_up_process(worker->task); 710 714 spin_unlock_irqrestore(&worker->lock, flags); 711 - 712 - out: 713 - return 0; 714 715 }
+2 -2
fs/btrfs/async-thread.h
··· 109 109 char *name; 110 110 }; 111 111 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); 114 114 int btrfs_stop_workers(struct btrfs_workers *workers); 115 115 void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max, 116 116 struct btrfs_workers *async_starter);
+2 -1
fs/btrfs/ctree.h
··· 2692 2692 int btrfs_readpage(struct file *file, struct page *page); 2693 2693 void btrfs_evict_inode(struct inode *inode); 2694 2694 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); 2696 2697 struct inode *btrfs_alloc_inode(struct super_block *sb); 2697 2698 void btrfs_destroy_inode(struct inode *inode); 2698 2699 int btrfs_drop_inode(struct inode *inode);
+2 -2
fs/btrfs/delayed-inode.c
··· 640 640 * Now if src_rsv == delalloc_block_rsv we'll let it just steal since 641 641 * we're accounted for. 642 642 */ 643 - if (!trans->bytes_reserved && 644 - src_rsv != &root->fs_info->delalloc_block_rsv) { 643 + if (!src_rsv || (!trans->bytes_reserved && 644 + src_rsv != &root->fs_info->delalloc_block_rsv)) { 645 645 ret = btrfs_block_rsv_add_noflush(root, dst_rsv, num_bytes); 646 646 /* 647 647 * Since we're under a transaction reserve_metadata_bytes could
+21 -13
fs/btrfs/disk-io.c
··· 2194 2194 fs_info->endio_meta_write_workers.idle_thresh = 2; 2195 2195 fs_info->readahead_workers.idle_thresh = 2; 2196 2196 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 + } 2210 2218 2211 2219 fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super); 2212 2220 fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages,
+31 -14
fs/btrfs/extent-tree.c
··· 2822 2822 btrfs_release_path(path); 2823 2823 out: 2824 2824 spin_lock(&block_group->lock); 2825 - if (!ret) 2825 + if (!ret && dcs == BTRFS_DC_SETUP) 2826 2826 block_group->cache_generation = trans->transid; 2827 2827 block_group->disk_cache_state = dcs; 2828 2828 spin_unlock(&block_group->lock); ··· 4204 4204 struct btrfs_root *root = BTRFS_I(inode)->root; 4205 4205 struct btrfs_block_rsv *block_rsv = &root->fs_info->delalloc_block_rsv; 4206 4206 u64 to_reserve = 0; 4207 + u64 csum_bytes; 4207 4208 unsigned nr_extents = 0; 4209 + int extra_reserve = 0; 4208 4210 int flush = 1; 4209 4211 int ret; 4210 4212 4213 + /* Need to be holding the i_mutex here if we aren't free space cache */ 4211 4214 if (btrfs_is_free_space_inode(root, inode)) 4212 4215 flush = 0; 4216 + else 4217 + WARN_ON(!mutex_is_locked(&inode->i_mutex)); 4213 4218 4214 4219 if (flush && btrfs_transaction_in_commit(root->fs_info)) 4215 4220 schedule_timeout(1); ··· 4225 4220 BTRFS_I(inode)->outstanding_extents++; 4226 4221 4227 4222 if (BTRFS_I(inode)->outstanding_extents > 4228 - BTRFS_I(inode)->reserved_extents) { 4223 + BTRFS_I(inode)->reserved_extents) 4229 4224 nr_extents = BTRFS_I(inode)->outstanding_extents - 4230 4225 BTRFS_I(inode)->reserved_extents; 4231 - BTRFS_I(inode)->reserved_extents += nr_extents; 4232 - } 4233 4226 4234 4227 /* 4235 4228 * Add an item to reserve for updating the inode when we complete the ··· 4235 4232 */ 4236 4233 if (!BTRFS_I(inode)->delalloc_meta_reserved) { 4237 4234 nr_extents++; 4238 - BTRFS_I(inode)->delalloc_meta_reserved = 1; 4235 + extra_reserve = 1; 4239 4236 } 4240 4237 4241 4238 to_reserve = btrfs_calc_trans_metadata_size(root, nr_extents); 4242 4239 to_reserve += calc_csum_metadata_size(inode, num_bytes, 1); 4240 + csum_bytes = BTRFS_I(inode)->csum_bytes; 4243 4241 spin_unlock(&BTRFS_I(inode)->lock); 4244 4242 4245 4243 ret = reserve_metadata_bytes(root, block_rsv, to_reserve, flush); ··· 4250 4246 4251 4247 spin_lock(&BTRFS_I(inode)->lock); 4252 4248 dropped = drop_outstanding_extent(inode); 4253 - to_free = calc_csum_metadata_size(inode, num_bytes, 0); 4254 - spin_unlock(&BTRFS_I(inode)->lock); 4255 - to_free += btrfs_calc_trans_metadata_size(root, dropped); 4256 - 4257 4249 /* 4258 - * Somebody could have come in and twiddled with the 4259 - * reservation, so if we have to free more than we would have 4260 - * reserved from this reservation go ahead and release those 4261 - * bytes. 4250 + * If the inodes csum_bytes is the same as the original 4251 + * csum_bytes then we know we haven't raced with any free()ers 4252 + * so we can just reduce our inodes csum bytes and carry on. 4253 + * Otherwise we have to do the normal free thing to account for 4254 + * the case that the free side didn't free up its reserve 4255 + * because of this outstanding reservation. 4262 4256 */ 4263 - to_free -= to_reserve; 4257 + if (BTRFS_I(inode)->csum_bytes == csum_bytes) 4258 + calc_csum_metadata_size(inode, num_bytes, 0); 4259 + else 4260 + to_free = calc_csum_metadata_size(inode, num_bytes, 0); 4261 + spin_unlock(&BTRFS_I(inode)->lock); 4262 + if (dropped) 4263 + to_free += btrfs_calc_trans_metadata_size(root, dropped); 4264 + 4264 4265 if (to_free) 4265 4266 btrfs_block_rsv_release(root, block_rsv, to_free); 4266 4267 return ret; 4267 4268 } 4269 + 4270 + spin_lock(&BTRFS_I(inode)->lock); 4271 + if (extra_reserve) { 4272 + BTRFS_I(inode)->delalloc_meta_reserved = 1; 4273 + nr_extents--; 4274 + } 4275 + BTRFS_I(inode)->reserved_extents += nr_extents; 4276 + spin_unlock(&BTRFS_I(inode)->lock); 4268 4277 4269 4278 block_rsv_add_bytes(block_rsv, to_reserve, 1); 4270 4279
+7 -1
fs/btrfs/file.c
··· 1167 1167 nrptrs = min((iov_iter_count(i) + PAGE_CACHE_SIZE - 1) / 1168 1168 PAGE_CACHE_SIZE, PAGE_CACHE_SIZE / 1169 1169 (sizeof(struct page *))); 1170 + nrptrs = min(nrptrs, current->nr_dirtied_pause - current->nr_dirtied); 1171 + nrptrs = max(nrptrs, 8); 1170 1172 pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL); 1171 1173 if (!pages) 1172 1174 return -ENOMEM; ··· 1389 1387 goto out; 1390 1388 } 1391 1389 1392 - file_update_time(file); 1390 + err = btrfs_update_time(file); 1391 + if (err) { 1392 + mutex_unlock(&inode->i_mutex); 1393 + goto out; 1394 + } 1393 1395 BTRFS_I(inode)->sequence++; 1394 1396 1395 1397 start_pos = round_down(pos, root->sectorsize);
+147 -33
fs/btrfs/inode.c
··· 38 38 #include <linux/falloc.h> 39 39 #include <linux/slab.h> 40 40 #include <linux/ratelimit.h> 41 + #include <linux/mount.h> 41 42 #include "compat.h" 42 43 #include "ctree.h" 43 44 #include "disk-io.h" ··· 2032 2031 /* insert an orphan item to track this unlinked/truncated file */ 2033 2032 if (insert >= 1) { 2034 2033 ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode)); 2035 - BUG_ON(ret); 2034 + BUG_ON(ret && ret != -EEXIST); 2036 2035 } 2037 2036 2038 2037 /* insert an orphan item to track subvolume contains orphan files */ ··· 2159 2158 if (ret && ret != -ESTALE) 2160 2159 goto out; 2161 2160 2161 + if (ret == -ESTALE && root == root->fs_info->tree_root) { 2162 + struct btrfs_root *dead_root; 2163 + struct btrfs_fs_info *fs_info = root->fs_info; 2164 + int is_dead_root = 0; 2165 + 2166 + /* 2167 + * this is an orphan in the tree root. Currently these 2168 + * could come from 2 sources: 2169 + * a) a snapshot deletion in progress 2170 + * b) a free space cache inode 2171 + * We need to distinguish those two, as the snapshot 2172 + * orphan must not get deleted. 2173 + * find_dead_roots already ran before us, so if this 2174 + * is a snapshot deletion, we should find the root 2175 + * in the dead_roots list 2176 + */ 2177 + spin_lock(&fs_info->trans_lock); 2178 + list_for_each_entry(dead_root, &fs_info->dead_roots, 2179 + root_list) { 2180 + if (dead_root->root_key.objectid == 2181 + found_key.objectid) { 2182 + is_dead_root = 1; 2183 + break; 2184 + } 2185 + } 2186 + spin_unlock(&fs_info->trans_lock); 2187 + if (is_dead_root) { 2188 + /* prevent this orphan from being found again */ 2189 + key.offset = found_key.objectid - 1; 2190 + continue; 2191 + } 2192 + } 2162 2193 /* 2163 2194 * Inode is already gone but the orphan item is still there, 2164 2195 * kill the orphan item. ··· 2224 2191 continue; 2225 2192 } 2226 2193 nr_truncate++; 2194 + /* 2195 + * Need to hold the imutex for reservation purposes, not 2196 + * a huge deal here but I have a WARN_ON in 2197 + * btrfs_delalloc_reserve_space to catch offenders. 2198 + */ 2199 + mutex_lock(&inode->i_mutex); 2227 2200 ret = btrfs_truncate(inode); 2201 + mutex_unlock(&inode->i_mutex); 2228 2202 } else { 2229 2203 nr_unlink++; 2230 2204 } ··· 3367 3327 u64 hint_byte = 0; 3368 3328 hole_size = last_byte - cur_offset; 3369 3329 3370 - trans = btrfs_start_transaction(root, 2); 3330 + trans = btrfs_start_transaction(root, 3); 3371 3331 if (IS_ERR(trans)) { 3372 3332 err = PTR_ERR(trans); 3373 3333 break; ··· 3377 3337 cur_offset + hole_size, 3378 3338 &hint_byte, 1); 3379 3339 if (err) { 3340 + btrfs_update_inode(trans, root, inode); 3380 3341 btrfs_end_transaction(trans, root); 3381 3342 break; 3382 3343 } ··· 3387 3346 0, hole_size, 0, hole_size, 3388 3347 0, 0, 0); 3389 3348 if (err) { 3349 + btrfs_update_inode(trans, root, inode); 3390 3350 btrfs_end_transaction(trans, root); 3391 3351 break; 3392 3352 } ··· 3395 3353 btrfs_drop_extent_cache(inode, hole_start, 3396 3354 last_byte - 1, 0); 3397 3355 3356 + btrfs_update_inode(trans, root, inode); 3398 3357 btrfs_end_transaction(trans, root); 3399 3358 } 3400 3359 free_extent_map(em); ··· 3413 3370 3414 3371 static int btrfs_setsize(struct inode *inode, loff_t newsize) 3415 3372 { 3373 + struct btrfs_root *root = BTRFS_I(inode)->root; 3374 + struct btrfs_trans_handle *trans; 3416 3375 loff_t oldsize = i_size_read(inode); 3417 3376 int ret; 3418 3377 ··· 3422 3377 return 0; 3423 3378 3424 3379 if (newsize > oldsize) { 3425 - i_size_write(inode, newsize); 3426 - btrfs_ordered_update_i_size(inode, i_size_read(inode), NULL); 3427 3380 truncate_pagecache(inode, oldsize, newsize); 3428 3381 ret = btrfs_cont_expand(inode, oldsize, newsize); 3429 - if (ret) { 3430 - btrfs_setsize(inode, oldsize); 3382 + if (ret) 3431 3383 return ret; 3432 - } 3433 3384 3434 - mark_inode_dirty(inode); 3385 + trans = btrfs_start_transaction(root, 1); 3386 + if (IS_ERR(trans)) 3387 + return PTR_ERR(trans); 3388 + 3389 + i_size_write(inode, newsize); 3390 + btrfs_ordered_update_i_size(inode, i_size_read(inode), NULL); 3391 + ret = btrfs_update_inode(trans, root, inode); 3392 + btrfs_end_transaction_throttle(trans, root); 3435 3393 } else { 3436 3394 3437 3395 /* ··· 3474 3426 3475 3427 if (attr->ia_valid) { 3476 3428 setattr_copy(inode, attr); 3477 - mark_inode_dirty(inode); 3429 + err = btrfs_dirty_inode(inode); 3478 3430 3479 - if (attr->ia_valid & ATTR_MODE) 3431 + if (!err && attr->ia_valid & ATTR_MODE) 3480 3432 err = btrfs_acl_chmod(inode); 3481 3433 } 3482 3434 ··· 4252 4204 * FIXME, needs more benchmarking...there are no reasons other than performance 4253 4205 * to keep or drop this code. 4254 4206 */ 4255 - void btrfs_dirty_inode(struct inode *inode, int flags) 4207 + int btrfs_dirty_inode(struct inode *inode) 4256 4208 { 4257 4209 struct btrfs_root *root = BTRFS_I(inode)->root; 4258 4210 struct btrfs_trans_handle *trans; 4259 4211 int ret; 4260 4212 4261 4213 if (BTRFS_I(inode)->dummy_inode) 4262 - return; 4214 + return 0; 4263 4215 4264 4216 trans = btrfs_join_transaction(root); 4265 - BUG_ON(IS_ERR(trans)); 4217 + if (IS_ERR(trans)) 4218 + return PTR_ERR(trans); 4266 4219 4267 4220 ret = btrfs_update_inode(trans, root, inode); 4268 4221 if (ret && ret == -ENOSPC) { 4269 4222 /* whoops, lets try again with the full transaction */ 4270 4223 btrfs_end_transaction(trans, root); 4271 4224 trans = btrfs_start_transaction(root, 1); 4272 - if (IS_ERR(trans)) { 4273 - printk_ratelimited(KERN_ERR "btrfs: fail to " 4274 - "dirty inode %llu error %ld\n", 4275 - (unsigned long long)btrfs_ino(inode), 4276 - PTR_ERR(trans)); 4277 - return; 4278 - } 4225 + if (IS_ERR(trans)) 4226 + return PTR_ERR(trans); 4279 4227 4280 4228 ret = btrfs_update_inode(trans, root, inode); 4281 - if (ret) { 4282 - printk_ratelimited(KERN_ERR "btrfs: fail to " 4283 - "dirty inode %llu error %d\n", 4284 - (unsigned long long)btrfs_ino(inode), 4285 - ret); 4286 - } 4287 4229 } 4288 4230 btrfs_end_transaction(trans, root); 4289 4231 if (BTRFS_I(inode)->delayed_node) 4290 4232 btrfs_balance_delayed_items(root); 4233 + 4234 + return ret; 4235 + } 4236 + 4237 + /* 4238 + * This is a copy of file_update_time. We need this so we can return error on 4239 + * ENOSPC for updating the inode in the case of file write and mmap writes. 4240 + */ 4241 + int btrfs_update_time(struct file *file) 4242 + { 4243 + struct inode *inode = file->f_path.dentry->d_inode; 4244 + struct timespec now; 4245 + int ret; 4246 + enum { S_MTIME = 1, S_CTIME = 2, S_VERSION = 4 } sync_it = 0; 4247 + 4248 + /* First try to exhaust all avenues to not sync */ 4249 + if (IS_NOCMTIME(inode)) 4250 + return 0; 4251 + 4252 + now = current_fs_time(inode->i_sb); 4253 + if (!timespec_equal(&inode->i_mtime, &now)) 4254 + sync_it = S_MTIME; 4255 + 4256 + if (!timespec_equal(&inode->i_ctime, &now)) 4257 + sync_it |= S_CTIME; 4258 + 4259 + if (IS_I_VERSION(inode)) 4260 + sync_it |= S_VERSION; 4261 + 4262 + if (!sync_it) 4263 + return 0; 4264 + 4265 + /* Finally allowed to write? Takes lock. */ 4266 + if (mnt_want_write_file(file)) 4267 + return 0; 4268 + 4269 + /* Only change inode inside the lock region */ 4270 + if (sync_it & S_VERSION) 4271 + inode_inc_iversion(inode); 4272 + if (sync_it & S_CTIME) 4273 + inode->i_ctime = now; 4274 + if (sync_it & S_MTIME) 4275 + inode->i_mtime = now; 4276 + ret = btrfs_dirty_inode(inode); 4277 + if (!ret) 4278 + mark_inode_dirty_sync(inode); 4279 + mnt_drop_write(file->f_path.mnt); 4280 + return ret; 4291 4281 } 4292 4282 4293 4283 /* ··· 4641 4555 goto out_unlock; 4642 4556 } 4643 4557 4558 + /* 4559 + * If the active LSM wants to access the inode during 4560 + * d_instantiate it needs these. Smack checks to see 4561 + * if the filesystem supports xattrs by looking at the 4562 + * ops vector. 4563 + */ 4564 + 4565 + inode->i_op = &btrfs_special_inode_operations; 4644 4566 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); 4645 4567 if (err) 4646 4568 drop_inode = 1; 4647 4569 else { 4648 - inode->i_op = &btrfs_special_inode_operations; 4649 4570 init_special_inode(inode, inode->i_mode, rdev); 4650 4571 btrfs_update_inode(trans, root, inode); 4651 4572 } ··· 4706 4613 goto out_unlock; 4707 4614 } 4708 4615 4616 + /* 4617 + * If the active LSM wants to access the inode during 4618 + * d_instantiate it needs these. Smack checks to see 4619 + * if the filesystem supports xattrs by looking at the 4620 + * ops vector. 4621 + */ 4622 + inode->i_fop = &btrfs_file_operations; 4623 + inode->i_op = &btrfs_file_inode_operations; 4624 + 4709 4625 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); 4710 4626 if (err) 4711 4627 drop_inode = 1; 4712 4628 else { 4713 4629 inode->i_mapping->a_ops = &btrfs_aops; 4714 4630 inode->i_mapping->backing_dev_info = &root->fs_info->bdi; 4715 - inode->i_fop = &btrfs_file_operations; 4716 - inode->i_op = &btrfs_file_inode_operations; 4717 4631 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; 4718 4632 } 4719 4633 out_unlock: ··· 6403 6303 u64 page_start; 6404 6304 u64 page_end; 6405 6305 6306 + /* Need this to keep space reservations serialized */ 6307 + mutex_lock(&inode->i_mutex); 6406 6308 ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); 6309 + mutex_unlock(&inode->i_mutex); 6310 + if (!ret) 6311 + ret = btrfs_update_time(vma->vm_file); 6407 6312 if (ret) { 6408 6313 if (ret == -ENOMEM) 6409 6314 ret = VM_FAULT_OOM; ··· 6620 6515 /* Just need the 1 for updating the inode */ 6621 6516 trans = btrfs_start_transaction(root, 1); 6622 6517 if (IS_ERR(trans)) { 6623 - err = PTR_ERR(trans); 6624 - goto out; 6518 + ret = err = PTR_ERR(trans); 6519 + trans = NULL; 6520 + break; 6625 6521 } 6626 6522 } 6627 6523 ··· 7182 7076 goto out_unlock; 7183 7077 } 7184 7078 7079 + /* 7080 + * If the active LSM wants to access the inode during 7081 + * d_instantiate it needs these. Smack checks to see 7082 + * if the filesystem supports xattrs by looking at the 7083 + * ops vector. 7084 + */ 7085 + inode->i_fop = &btrfs_file_operations; 7086 + inode->i_op = &btrfs_file_inode_operations; 7087 + 7185 7088 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); 7186 7089 if (err) 7187 7090 drop_inode = 1; 7188 7091 else { 7189 7092 inode->i_mapping->a_ops = &btrfs_aops; 7190 7093 inode->i_mapping->backing_dev_info = &root->fs_info->bdi; 7191 - inode->i_fop = &btrfs_file_operations; 7192 - inode->i_op = &btrfs_file_inode_operations; 7193 7094 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; 7194 7095 } 7195 7096 if (drop_inode) ··· 7466 7353 .follow_link = page_follow_link_light, 7467 7354 .put_link = page_put_link, 7468 7355 .getattr = btrfs_getattr, 7356 + .setattr = btrfs_setattr, 7469 7357 .permission = btrfs_permission, 7470 7358 .setxattr = btrfs_setxattr, 7471 7359 .getxattr = btrfs_getxattr,
+4 -2
fs/btrfs/ioctl.c
··· 252 252 trans = btrfs_join_transaction(root); 253 253 BUG_ON(IS_ERR(trans)); 254 254 255 + btrfs_update_iflags(inode); 256 + inode->i_ctime = CURRENT_TIME; 255 257 ret = btrfs_update_inode(trans, root, inode); 256 258 BUG_ON(ret); 257 259 258 - btrfs_update_iflags(inode); 259 - inode->i_ctime = CURRENT_TIME; 260 260 btrfs_end_transaction(trans, root); 261 261 262 262 mnt_drop_write(file->f_path.mnt); ··· 858 858 return 0; 859 859 file_end = (isize - 1) >> PAGE_CACHE_SHIFT; 860 860 861 + mutex_lock(&inode->i_mutex); 861 862 ret = btrfs_delalloc_reserve_space(inode, 862 863 num_pages << PAGE_CACHE_SHIFT); 864 + mutex_unlock(&inode->i_mutex); 863 865 if (ret) 864 866 return ret; 865 867 again:
+2
fs/btrfs/relocation.c
··· 2947 2947 index = (cluster->start - offset) >> PAGE_CACHE_SHIFT; 2948 2948 last_index = (cluster->end - offset) >> PAGE_CACHE_SHIFT; 2949 2949 while (index <= last_index) { 2950 + mutex_lock(&inode->i_mutex); 2950 2951 ret = btrfs_delalloc_reserve_metadata(inode, PAGE_CACHE_SIZE); 2952 + mutex_unlock(&inode->i_mutex); 2951 2953 if (ret) 2952 2954 goto out; 2953 2955
+6 -2
fs/btrfs/scrub.c
··· 1535 1535 static noinline_for_stack int scrub_workers_get(struct btrfs_root *root) 1536 1536 { 1537 1537 struct btrfs_fs_info *fs_info = root->fs_info; 1538 + int ret = 0; 1538 1539 1539 1540 mutex_lock(&fs_info->scrub_lock); 1540 1541 if (fs_info->scrub_workers_refcnt == 0) { 1541 1542 btrfs_init_workers(&fs_info->scrub_workers, "scrub", 1542 1543 fs_info->thread_pool_size, &fs_info->generic_worker); 1543 1544 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; 1545 1548 } 1546 1549 ++fs_info->scrub_workers_refcnt; 1550 + out: 1547 1551 mutex_unlock(&fs_info->scrub_lock); 1548 1552 1549 - return 0; 1553 + return ret; 1550 1554 } 1551 1555 1552 1556 static noinline_for_stack void scrub_workers_put(struct btrfs_root *root)
+25 -7
fs/btrfs/super.c
··· 41 41 #include <linux/slab.h> 42 42 #include <linux/cleancache.h> 43 43 #include <linux/mnt_namespace.h> 44 + #include <linux/ratelimit.h> 44 45 #include "compat.h" 45 46 #include "delayed-inode.h" 46 47 #include "ctree.h" ··· 1054 1053 u64 avail_space; 1055 1054 u64 used_space; 1056 1055 u64 min_stripe_size; 1057 - int min_stripes = 1; 1056 + int min_stripes = 1, num_stripes = 1; 1058 1057 int i = 0, nr_devices; 1059 1058 int ret; 1060 1059 ··· 1068 1067 1069 1068 /* calc min stripe number for data space alloction */ 1070 1069 type = btrfs_get_alloc_profile(root, 1); 1071 - if (type & BTRFS_BLOCK_GROUP_RAID0) 1070 + if (type & BTRFS_BLOCK_GROUP_RAID0) { 1072 1071 min_stripes = 2; 1073 - else if (type & BTRFS_BLOCK_GROUP_RAID1) 1072 + num_stripes = nr_devices; 1073 + } else if (type & BTRFS_BLOCK_GROUP_RAID1) { 1074 1074 min_stripes = 2; 1075 - else if (type & BTRFS_BLOCK_GROUP_RAID10) 1075 + num_stripes = 2; 1076 + } else if (type & BTRFS_BLOCK_GROUP_RAID10) { 1076 1077 min_stripes = 4; 1078 + num_stripes = 4; 1079 + } 1077 1080 1078 1081 if (type & BTRFS_BLOCK_GROUP_DUP) 1079 1082 min_stripe_size = 2 * BTRFS_STRIPE_LEN; ··· 1146 1141 i = nr_devices - 1; 1147 1142 avail_space = 0; 1148 1143 while (nr_devices >= min_stripes) { 1144 + if (num_stripes > nr_devices) 1145 + num_stripes = nr_devices; 1146 + 1149 1147 if (devices_info[i].max_avail >= min_stripe_size) { 1150 1148 int j; 1151 1149 u64 alloc_size; 1152 1150 1153 - avail_space += devices_info[i].max_avail * min_stripes; 1151 + avail_space += devices_info[i].max_avail * num_stripes; 1154 1152 alloc_size = devices_info[i].max_avail; 1155 - for (j = i + 1 - min_stripes; j <= i; j++) 1153 + for (j = i + 1 - num_stripes; j <= i; j++) 1156 1154 devices_info[j].max_avail -= alloc_size; 1157 1155 } 1158 1156 i--; ··· 1272 1264 return 0; 1273 1265 } 1274 1266 1267 + static void btrfs_fs_dirty_inode(struct inode *inode, int flags) 1268 + { 1269 + int ret; 1270 + 1271 + ret = btrfs_dirty_inode(inode); 1272 + if (ret) 1273 + printk_ratelimited(KERN_ERR "btrfs: fail to dirty inode %Lu " 1274 + "error %d\n", btrfs_ino(inode), ret); 1275 + } 1276 + 1275 1277 static const struct super_operations btrfs_super_ops = { 1276 1278 .drop_inode = btrfs_drop_inode, 1277 1279 .evict_inode = btrfs_evict_inode, ··· 1289 1271 .sync_fs = btrfs_sync_fs, 1290 1272 .show_options = btrfs_show_options, 1291 1273 .write_inode = btrfs_write_inode, 1292 - .dirty_inode = btrfs_dirty_inode, 1274 + .dirty_inode = btrfs_fs_dirty_inode, 1293 1275 .alloc_inode = btrfs_alloc_inode, 1294 1276 .destroy_inode = btrfs_destroy_inode, 1295 1277 .statfs = btrfs_statfs,
+7 -1
fs/btrfs/volumes.c
··· 295 295 btrfs_requeue_work(&device->work); 296 296 goto done; 297 297 } 298 + /* unplug every 64 requests just for good measure */ 299 + if (batch_run % 64 == 0) { 300 + blk_finish_plug(&plug); 301 + blk_start_plug(&plug); 302 + sync_pending = 0; 303 + } 298 304 } 299 305 300 306 cond_resched(); ··· 3264 3258 */ 3265 3259 if (atomic_read(&bbio->error) > bbio->max_errors) { 3266 3260 err = -EIO; 3267 - } else if (err) { 3261 + } else { 3268 3262 /* 3269 3263 * this bio is actually up to date, we didn't 3270 3264 * go over the max number of errors