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 branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs

Pull btrfs update from Chris Mason:
"The dates look like I had to rebase this morning because there was a
compiler warning for a printk arg that I had missed earlier.

These are all fixes, including one to prevent using stale pointers for
device names, and lots of fixes around transaction abort cleanups
(Josef, Liu Bo).

Jan Schmidt also sent in a number of fixes for the new reference
number tracking code.

Liu Bo beat me to updating the MAINTAINERS file. Since he thought to
also fix the git url, I kept his commit."

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (24 commits)
Btrfs: update MAINTAINERS info for BTRFS FILE SYSTEM
Btrfs: destroy the items of the delayed inodes in error handling routine
Btrfs: make sure that we've made everything in pinned tree clean
Btrfs: avoid memory leak of extent state in error handling routine
Btrfs: do not resize a seeding device
Btrfs: fix missing inherited flag in rename
Btrfs: fix incompat flags setting
Btrfs: fix defrag regression
Btrfs: call filemap_fdatawrite twice for compression
Btrfs: keep inode pinned when compressing writes
Btrfs: implement ->show_devname
Btrfs: use rcu to protect device->name
Btrfs: unlock everything properly in the error case for nocow
Btrfs: fix btrfs_destroy_marked_extents
Btrfs: abort the transaction if the commit fails
Btrfs: wake up transaction waiters when aborting a transaction
Btrfs: fix locking in btrfs_destroy_delayed_refs
Btrfs: pass locked_page into extent_clear_unlock_delalloc if theres an error
Btrfs: fix race in tree mod log addition
Btrfs: add btrfs_next_old_leaf
...

+480 -193
+2 -2
MAINTAINERS
··· 1646 1646 F: drivers/gpio/gpio-bt8xx.c 1647 1647 1648 1648 BTRFS FILE SYSTEM 1649 - M: Chris Mason <chris.mason@oracle.com> 1649 + M: Chris Mason <chris.mason@fusionio.com> 1650 1650 L: linux-btrfs@vger.kernel.org 1651 1651 W: http://btrfs.wiki.kernel.org/ 1652 1652 Q: http://patchwork.kernel.org/project/linux-btrfs/list/ 1653 - T: git git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable.git 1653 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git 1654 1654 S: Maintained 1655 1655 F: Documentation/filesystems/btrfs.txt 1656 1656 F: fs/btrfs/
+5 -12
fs/btrfs/backref.c
··· 179 179 180 180 static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path, 181 181 struct ulist *parents, int level, 182 - struct btrfs_key *key, u64 wanted_disk_byte, 182 + struct btrfs_key *key, u64 time_seq, 183 + u64 wanted_disk_byte, 183 184 const u64 *extent_item_pos) 184 185 { 185 186 int ret; ··· 213 212 */ 214 213 while (1) { 215 214 eie = NULL; 216 - ret = btrfs_next_leaf(root, path); 215 + ret = btrfs_next_old_leaf(root, path, time_seq); 217 216 if (ret < 0) 218 217 return ret; 219 218 if (ret) ··· 295 294 goto out; 296 295 } 297 296 298 - if (level == 0) { 299 - if (ret == 1 && path->slots[0] >= btrfs_header_nritems(eb)) { 300 - ret = btrfs_next_leaf(root, path); 301 - if (ret) 302 - goto out; 303 - eb = path->nodes[0]; 304 - } 305 - 297 + if (level == 0) 306 298 btrfs_item_key_to_cpu(eb, &key, path->slots[0]); 307 - } 308 299 309 - ret = add_all_parents(root, path, parents, level, &key, 300 + ret = add_all_parents(root, path, parents, level, &key, time_seq, 310 301 ref->wanted_disk_byte, extent_item_pos); 311 302 out: 312 303 btrfs_free_path(path);
+1
fs/btrfs/btrfs_inode.h
··· 37 37 #define BTRFS_INODE_IN_DEFRAG 3 38 38 #define BTRFS_INODE_DELALLOC_META_RESERVED 4 39 39 #define BTRFS_INODE_HAS_ORPHAN_ITEM 5 40 + #define BTRFS_INODE_HAS_ASYNC_EXTENT 6 40 41 41 42 /* in memory btrfs inode */ 42 43 struct btrfs_inode {
+9 -7
fs/btrfs/check-integrity.c
··· 93 93 #include "print-tree.h" 94 94 #include "locking.h" 95 95 #include "check-integrity.h" 96 + #include "rcu-string.h" 96 97 97 98 #define BTRFSIC_BLOCK_HASHTABLE_SIZE 0x10000 98 99 #define BTRFSIC_BLOCK_LINK_HASHTABLE_SIZE 0x10000 ··· 844 843 superblock_tmp->never_written = 0; 845 844 superblock_tmp->mirror_num = 1 + superblock_mirror_num; 846 845 if (state->print_mask & BTRFSIC_PRINT_MASK_SUPERBLOCK_WRITE) 847 - printk(KERN_INFO "New initial S-block (bdev %p, %s)" 848 - " @%llu (%s/%llu/%d)\n", 849 - superblock_bdev, device->name, 850 - (unsigned long long)dev_bytenr, 851 - dev_state->name, 852 - (unsigned long long)dev_bytenr, 853 - superblock_mirror_num); 846 + printk_in_rcu(KERN_INFO "New initial S-block (bdev %p, %s)" 847 + " @%llu (%s/%llu/%d)\n", 848 + superblock_bdev, 849 + rcu_str_deref(device->name), 850 + (unsigned long long)dev_bytenr, 851 + dev_state->name, 852 + (unsigned long long)dev_bytenr, 853 + superblock_mirror_num); 854 854 list_add(&superblock_tmp->all_blocks_node, 855 855 &state->all_blocks_list); 856 856 btrfsic_block_hashtable_add(superblock_tmp,
+63 -23
fs/btrfs/ctree.c
··· 467 467 return 0; 468 468 } 469 469 470 + /* 471 + * This allocates memory and gets a tree modification sequence number when 472 + * needed. 473 + * 474 + * Returns 0 when no sequence number is needed, < 0 on error. 475 + * Returns 1 when a sequence number was added. In this case, 476 + * fs_info->tree_mod_seq_lock was acquired and must be released by the caller 477 + * after inserting into the rb tree. 478 + */ 470 479 static inline int tree_mod_alloc(struct btrfs_fs_info *fs_info, gfp_t flags, 471 480 struct tree_mod_elem **tm_ret) 472 481 { ··· 500 491 */ 501 492 kfree(tm); 502 493 seq = 0; 494 + spin_unlock(&fs_info->tree_mod_seq_lock); 503 495 } else { 504 496 __get_tree_mod_seq(fs_info, &tm->elem); 505 497 seq = tm->elem.seq; 506 498 } 507 - spin_unlock(&fs_info->tree_mod_seq_lock); 508 499 509 500 return seq; 510 501 } ··· 530 521 tm->slot = slot; 531 522 tm->generation = btrfs_node_ptr_generation(eb, slot); 532 523 533 - return __tree_mod_log_insert(fs_info, tm); 524 + ret = __tree_mod_log_insert(fs_info, tm); 525 + spin_unlock(&fs_info->tree_mod_seq_lock); 526 + return ret; 534 527 } 535 528 536 529 static noinline int ··· 570 559 tm->move.nr_items = nr_items; 571 560 tm->op = MOD_LOG_MOVE_KEYS; 572 561 573 - return __tree_mod_log_insert(fs_info, tm); 562 + ret = __tree_mod_log_insert(fs_info, tm); 563 + spin_unlock(&fs_info->tree_mod_seq_lock); 564 + return ret; 574 565 } 575 566 576 567 static noinline int ··· 593 580 tm->generation = btrfs_header_generation(old_root); 594 581 tm->op = MOD_LOG_ROOT_REPLACE; 595 582 596 - return __tree_mod_log_insert(fs_info, tm); 583 + ret = __tree_mod_log_insert(fs_info, tm); 584 + spin_unlock(&fs_info->tree_mod_seq_lock); 585 + return ret; 597 586 } 598 587 599 588 static struct tree_mod_elem * ··· 1038 1023 looped = 1; 1039 1024 } 1040 1025 1026 + /* if there's no old root to return, return what we found instead */ 1027 + if (!found) 1028 + found = tm; 1029 + 1041 1030 return found; 1042 1031 } 1043 1032 ··· 1162 1143 return eb_rewin; 1163 1144 } 1164 1145 1146 + /* 1147 + * get_old_root() rewinds the state of @root's root node to the given @time_seq 1148 + * value. If there are no changes, the current root->root_node is returned. If 1149 + * anything changed in between, there's a fresh buffer allocated on which the 1150 + * rewind operations are done. In any case, the returned buffer is read locked. 1151 + * Returns NULL on error (with no locks held). 1152 + */ 1165 1153 static inline struct extent_buffer * 1166 1154 get_old_root(struct btrfs_root *root, u64 time_seq) 1167 1155 { 1168 1156 struct tree_mod_elem *tm; 1169 1157 struct extent_buffer *eb; 1170 - struct tree_mod_root *old_root; 1158 + struct tree_mod_root *old_root = NULL; 1171 1159 u64 old_generation; 1160 + u64 logical; 1172 1161 1162 + eb = btrfs_read_lock_root_node(root); 1173 1163 tm = __tree_mod_log_oldest_root(root->fs_info, root, time_seq); 1174 1164 if (!tm) 1175 1165 return root->node; 1176 1166 1177 - old_root = &tm->old_root; 1178 - old_generation = tm->generation; 1167 + if (tm->op == MOD_LOG_ROOT_REPLACE) { 1168 + old_root = &tm->old_root; 1169 + old_generation = tm->generation; 1170 + logical = old_root->logical; 1171 + } else { 1172 + logical = root->node->start; 1173 + } 1179 1174 1180 - tm = tree_mod_log_search(root->fs_info, old_root->logical, time_seq); 1175 + tm = tree_mod_log_search(root->fs_info, logical, time_seq); 1181 1176 /* 1182 1177 * there was an item in the log when __tree_mod_log_oldest_root 1183 1178 * returned. this one must not go away, because the time_seq passed to ··· 1199 1166 */ 1200 1167 BUG_ON(!tm); 1201 1168 1202 - if (old_root->logical == root->node->start) { 1203 - /* there are logged operations for the current root */ 1204 - eb = btrfs_clone_extent_buffer(root->node); 1205 - } else { 1206 - /* there's a root replace operation for the current root */ 1169 + if (old_root) 1207 1170 eb = alloc_dummy_extent_buffer(tm->index << PAGE_CACHE_SHIFT, 1208 1171 root->nodesize); 1172 + else 1173 + eb = btrfs_clone_extent_buffer(root->node); 1174 + btrfs_tree_read_unlock(root->node); 1175 + free_extent_buffer(root->node); 1176 + if (!eb) 1177 + return NULL; 1178 + btrfs_tree_read_lock(eb); 1179 + if (old_root) { 1209 1180 btrfs_set_header_bytenr(eb, eb->start); 1210 1181 btrfs_set_header_backref_rev(eb, BTRFS_MIXED_BACKREF_REV); 1211 1182 btrfs_set_header_owner(eb, root->root_key.objectid); 1183 + btrfs_set_header_level(eb, old_root->level); 1184 + btrfs_set_header_generation(eb, old_generation); 1212 1185 } 1213 - if (!eb) 1214 - return NULL; 1215 - btrfs_set_header_level(eb, old_root->level); 1216 - btrfs_set_header_generation(eb, old_generation); 1217 1186 __tree_mod_log_rewind(eb, time_seq, tm); 1187 + extent_buffer_get(eb); 1218 1188 1219 1189 return eb; 1220 1190 } ··· 1686 1650 BTRFS_NODEPTRS_PER_BLOCK(root) / 4) 1687 1651 return 0; 1688 1652 1689 - btrfs_header_nritems(mid); 1690 - 1691 1653 left = read_node_slot(root, parent, pslot - 1); 1692 1654 if (left) { 1693 1655 btrfs_tree_lock(left); ··· 1715 1681 wret = push_node_left(trans, root, left, mid, 1); 1716 1682 if (wret < 0) 1717 1683 ret = wret; 1718 - btrfs_header_nritems(mid); 1719 1684 } 1720 1685 1721 1686 /* ··· 2648 2615 2649 2616 again: 2650 2617 b = get_old_root(root, time_seq); 2651 - extent_buffer_get(b); 2652 2618 level = btrfs_header_level(b); 2653 - btrfs_tree_read_lock(b); 2654 2619 p->locks[level] = BTRFS_READ_LOCK; 2655 2620 2656 2621 while (b) { ··· 5032 5001 */ 5033 5002 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path) 5034 5003 { 5004 + return btrfs_next_old_leaf(root, path, 0); 5005 + } 5006 + 5007 + int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path, 5008 + u64 time_seq) 5009 + { 5035 5010 int slot; 5036 5011 int level; 5037 5012 struct extent_buffer *c; ··· 5062 5025 path->keep_locks = 1; 5063 5026 path->leave_spinning = 1; 5064 5027 5065 - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 5028 + if (time_seq) 5029 + ret = btrfs_search_old_slot(root, &key, path, time_seq); 5030 + else 5031 + ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 5066 5032 path->keep_locks = 0; 5067 5033 5068 5034 if (ret < 0)
+2
fs/btrfs/ctree.h
··· 2753 2753 } 2754 2754 2755 2755 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); 2756 + int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path, 2757 + u64 time_seq); 2756 2758 static inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p) 2757 2759 { 2758 2760 ++p->slots[0];
+18
fs/btrfs/delayed-inode.c
··· 1879 1879 } 1880 1880 } 1881 1881 } 1882 + 1883 + void btrfs_destroy_delayed_inodes(struct btrfs_root *root) 1884 + { 1885 + struct btrfs_delayed_root *delayed_root; 1886 + struct btrfs_delayed_node *curr_node, *prev_node; 1887 + 1888 + delayed_root = btrfs_get_delayed_root(root); 1889 + 1890 + curr_node = btrfs_first_delayed_node(delayed_root); 1891 + while (curr_node) { 1892 + __btrfs_kill_delayed_node(curr_node); 1893 + 1894 + prev_node = curr_node; 1895 + curr_node = btrfs_next_delayed_node(curr_node); 1896 + btrfs_release_delayed_node(prev_node); 1897 + } 1898 + } 1899 +
+3
fs/btrfs/delayed-inode.h
··· 124 124 /* Used for drop dead root */ 125 125 void btrfs_kill_all_delayed_nodes(struct btrfs_root *root); 126 126 127 + /* Used for clean the transaction */ 128 + void btrfs_destroy_delayed_inodes(struct btrfs_root *root); 129 + 127 130 /* Used for readdir() */ 128 131 void btrfs_get_delayed_items(struct inode *inode, struct list_head *ins_list, 129 132 struct list_head *del_list);
+48 -28
fs/btrfs/disk-io.c
··· 44 44 #include "free-space-cache.h" 45 45 #include "inode-map.h" 46 46 #include "check-integrity.h" 47 + #include "rcu-string.h" 47 48 48 49 static struct extent_io_ops btree_extent_io_ops; 49 50 static void end_workqueue_fn(struct btrfs_work *work); ··· 2119 2118 2120 2119 features = btrfs_super_incompat_flags(disk_super); 2121 2120 features |= BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF; 2122 - if (tree_root->fs_info->compress_type & BTRFS_COMPRESS_LZO) 2121 + if (tree_root->fs_info->compress_type == BTRFS_COMPRESS_LZO) 2123 2122 features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO; 2124 2123 2125 2124 /* ··· 2576 2575 struct btrfs_device *device = (struct btrfs_device *) 2577 2576 bh->b_private; 2578 2577 2579 - printk_ratelimited(KERN_WARNING "lost page write due to " 2580 - "I/O error on %s\n", device->name); 2578 + printk_ratelimited_in_rcu(KERN_WARNING "lost page write due to " 2579 + "I/O error on %s\n", 2580 + rcu_str_deref(device->name)); 2581 2581 /* note, we dont' set_buffer_write_io_error because we have 2582 2582 * our own ways of dealing with the IO errors 2583 2583 */ ··· 2751 2749 wait_for_completion(&device->flush_wait); 2752 2750 2753 2751 if (bio_flagged(bio, BIO_EOPNOTSUPP)) { 2754 - printk("btrfs: disabling barriers on dev %s\n", 2755 - device->name); 2752 + printk_in_rcu("btrfs: disabling barriers on dev %s\n", 2753 + rcu_str_deref(device->name)); 2756 2754 device->nobarriers = 1; 2757 2755 } 2758 2756 if (!bio_flagged(bio, BIO_UPTODATE)) { ··· 3402 3400 3403 3401 delayed_refs = &trans->delayed_refs; 3404 3402 3405 - again: 3406 3403 spin_lock(&delayed_refs->lock); 3407 3404 if (delayed_refs->num_entries == 0) { 3408 3405 spin_unlock(&delayed_refs->lock); ··· 3409 3408 return ret; 3410 3409 } 3411 3410 3412 - node = rb_first(&delayed_refs->root); 3413 - while (node) { 3411 + while ((node = rb_first(&delayed_refs->root)) != NULL) { 3414 3412 ref = rb_entry(node, struct btrfs_delayed_ref_node, rb_node); 3415 - node = rb_next(node); 3416 - 3417 - ref->in_tree = 0; 3418 - rb_erase(&ref->rb_node, &delayed_refs->root); 3419 - delayed_refs->num_entries--; 3420 3413 3421 3414 atomic_set(&ref->refs, 1); 3422 3415 if (btrfs_delayed_ref_is_head(ref)) { 3423 3416 struct btrfs_delayed_ref_head *head; 3424 3417 3425 3418 head = btrfs_delayed_node_to_head(ref); 3426 - spin_unlock(&delayed_refs->lock); 3427 - mutex_lock(&head->mutex); 3419 + if (!mutex_trylock(&head->mutex)) { 3420 + atomic_inc(&ref->refs); 3421 + spin_unlock(&delayed_refs->lock); 3422 + 3423 + /* Need to wait for the delayed ref to run */ 3424 + mutex_lock(&head->mutex); 3425 + mutex_unlock(&head->mutex); 3426 + btrfs_put_delayed_ref(ref); 3427 + 3428 + continue; 3429 + } 3430 + 3428 3431 kfree(head->extent_op); 3429 3432 delayed_refs->num_heads--; 3430 3433 if (list_empty(&head->cluster)) 3431 3434 delayed_refs->num_heads_ready--; 3432 3435 list_del_init(&head->cluster); 3433 - mutex_unlock(&head->mutex); 3434 - btrfs_put_delayed_ref(ref); 3435 - goto again; 3436 3436 } 3437 + ref->in_tree = 0; 3438 + rb_erase(&ref->rb_node, &delayed_refs->root); 3439 + delayed_refs->num_entries--; 3440 + 3437 3441 spin_unlock(&delayed_refs->lock); 3438 3442 btrfs_put_delayed_ref(ref); 3439 3443 ··· 3526 3520 &(&BTRFS_I(page->mapping->host)->io_tree)->buffer, 3527 3521 offset >> PAGE_CACHE_SHIFT); 3528 3522 spin_unlock(&dirty_pages->buffer_lock); 3529 - if (eb) { 3523 + if (eb) 3530 3524 ret = test_and_clear_bit(EXTENT_BUFFER_DIRTY, 3531 3525 &eb->bflags); 3532 - atomic_set(&eb->refs, 1); 3533 - } 3534 3526 if (PageWriteback(page)) 3535 3527 end_page_writeback(page); 3536 3528 ··· 3542 3538 spin_unlock_irq(&page->mapping->tree_lock); 3543 3539 } 3544 3540 3545 - page->mapping->a_ops->invalidatepage(page, 0); 3546 3541 unlock_page(page); 3542 + page_cache_release(page); 3547 3543 } 3548 3544 } 3549 3545 ··· 3557 3553 u64 start; 3558 3554 u64 end; 3559 3555 int ret; 3556 + bool loop = true; 3560 3557 3561 3558 unpin = pinned_extents; 3559 + again: 3562 3560 while (1) { 3563 3561 ret = find_first_extent_bit(unpin, 0, &start, &end, 3564 3562 EXTENT_DIRTY); ··· 3578 3572 cond_resched(); 3579 3573 } 3580 3574 3575 + if (loop) { 3576 + if (unpin == &root->fs_info->freed_extents[0]) 3577 + unpin = &root->fs_info->freed_extents[1]; 3578 + else 3579 + unpin = &root->fs_info->freed_extents[0]; 3580 + loop = false; 3581 + goto again; 3582 + } 3583 + 3581 3584 return 0; 3582 3585 } 3583 3586 ··· 3600 3585 /* FIXME: cleanup wait for commit */ 3601 3586 cur_trans->in_commit = 1; 3602 3587 cur_trans->blocked = 1; 3603 - if (waitqueue_active(&root->fs_info->transaction_blocked_wait)) 3604 - wake_up(&root->fs_info->transaction_blocked_wait); 3588 + wake_up(&root->fs_info->transaction_blocked_wait); 3605 3589 3606 3590 cur_trans->blocked = 0; 3607 - if (waitqueue_active(&root->fs_info->transaction_wait)) 3608 - wake_up(&root->fs_info->transaction_wait); 3591 + wake_up(&root->fs_info->transaction_wait); 3609 3592 3610 3593 cur_trans->commit_done = 1; 3611 - if (waitqueue_active(&cur_trans->commit_wait)) 3612 - wake_up(&cur_trans->commit_wait); 3594 + wake_up(&cur_trans->commit_wait); 3595 + 3596 + btrfs_destroy_delayed_inodes(root); 3597 + btrfs_assert_delayed_root_empty(root); 3613 3598 3614 3599 btrfs_destroy_pending_snapshots(cur_trans); 3615 3600 3616 3601 btrfs_destroy_marked_extents(root, &cur_trans->dirty_pages, 3617 3602 EXTENT_DIRTY); 3603 + btrfs_destroy_pinned_extent(root, 3604 + root->fs_info->pinned_extents); 3618 3605 3619 3606 /* 3620 3607 memset(cur_trans, 0, sizeof(*cur_trans)); ··· 3664 3647 t->commit_done = 1; 3665 3648 if (waitqueue_active(&t->commit_wait)) 3666 3649 wake_up(&t->commit_wait); 3650 + 3651 + btrfs_destroy_delayed_inodes(root); 3652 + btrfs_assert_delayed_root_empty(root); 3667 3653 3668 3654 btrfs_destroy_pending_snapshots(t); 3669 3655
+4 -3
fs/btrfs/extent_io.c
··· 20 20 #include "volumes.h" 21 21 #include "check-integrity.h" 22 22 #include "locking.h" 23 + #include "rcu-string.h" 23 24 24 25 static struct kmem_cache *extent_state_cache; 25 26 static struct kmem_cache *extent_buffer_cache; ··· 1918 1917 return -EIO; 1919 1918 } 1920 1919 1921 - printk(KERN_INFO "btrfs read error corrected: ino %lu off %llu (dev %s " 1922 - "sector %llu)\n", page->mapping->host->i_ino, start, 1923 - dev->name, sector); 1920 + printk_in_rcu(KERN_INFO "btrfs read error corrected: ino %lu off %llu " 1921 + "(dev %s sector %llu)\n", page->mapping->host->i_ino, 1922 + start, rcu_str_deref(dev->name), sector); 1924 1923 1925 1924 bio_put(bio); 1926 1925 return 0;
+58 -15
fs/btrfs/inode.c
··· 830 830 if (IS_ERR(trans)) { 831 831 extent_clear_unlock_delalloc(inode, 832 832 &BTRFS_I(inode)->io_tree, 833 - start, end, NULL, 833 + start, end, locked_page, 834 834 EXTENT_CLEAR_UNLOCK_PAGE | 835 835 EXTENT_CLEAR_UNLOCK | 836 836 EXTENT_CLEAR_DELALLOC | ··· 963 963 out_unlock: 964 964 extent_clear_unlock_delalloc(inode, 965 965 &BTRFS_I(inode)->io_tree, 966 - start, end, NULL, 966 + start, end, locked_page, 967 967 EXTENT_CLEAR_UNLOCK_PAGE | 968 968 EXTENT_CLEAR_UNLOCK | 969 969 EXTENT_CLEAR_DELALLOC | ··· 986 986 compress_file_range(async_cow->inode, async_cow->locked_page, 987 987 async_cow->start, async_cow->end, async_cow, 988 988 &num_added); 989 - if (num_added == 0) 989 + if (num_added == 0) { 990 + iput(async_cow->inode); 990 991 async_cow->inode = NULL; 992 + } 991 993 } 992 994 993 995 /* ··· 1022 1020 { 1023 1021 struct async_cow *async_cow; 1024 1022 async_cow = container_of(work, struct async_cow, work); 1023 + if (async_cow->inode) 1024 + iput(async_cow->inode); 1025 1025 kfree(async_cow); 1026 1026 } 1027 1027 ··· 1042 1038 while (start < end) { 1043 1039 async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS); 1044 1040 BUG_ON(!async_cow); /* -ENOMEM */ 1045 - async_cow->inode = inode; 1041 + async_cow->inode = igrab(inode); 1046 1042 async_cow->root = root; 1047 1043 async_cow->locked_page = locked_page; 1048 1044 async_cow->start = start; ··· 1140 1136 u64 ino = btrfs_ino(inode); 1141 1137 1142 1138 path = btrfs_alloc_path(); 1143 - if (!path) 1139 + if (!path) { 1140 + extent_clear_unlock_delalloc(inode, 1141 + &BTRFS_I(inode)->io_tree, 1142 + start, end, locked_page, 1143 + EXTENT_CLEAR_UNLOCK_PAGE | 1144 + EXTENT_CLEAR_UNLOCK | 1145 + EXTENT_CLEAR_DELALLOC | 1146 + EXTENT_CLEAR_DIRTY | 1147 + EXTENT_SET_WRITEBACK | 1148 + EXTENT_END_WRITEBACK); 1144 1149 return -ENOMEM; 1150 + } 1145 1151 1146 1152 nolock = btrfs_is_free_space_inode(root, inode); 1147 1153 ··· 1161 1147 trans = btrfs_join_transaction(root); 1162 1148 1163 1149 if (IS_ERR(trans)) { 1150 + extent_clear_unlock_delalloc(inode, 1151 + &BTRFS_I(inode)->io_tree, 1152 + start, end, locked_page, 1153 + EXTENT_CLEAR_UNLOCK_PAGE | 1154 + EXTENT_CLEAR_UNLOCK | 1155 + EXTENT_CLEAR_DELALLOC | 1156 + EXTENT_CLEAR_DIRTY | 1157 + EXTENT_SET_WRITEBACK | 1158 + EXTENT_END_WRITEBACK); 1164 1159 btrfs_free_path(path); 1165 1160 return PTR_ERR(trans); 1166 1161 } ··· 1350 1327 } 1351 1328 btrfs_release_path(path); 1352 1329 1353 - if (cur_offset <= end && cow_start == (u64)-1) 1330 + if (cur_offset <= end && cow_start == (u64)-1) { 1354 1331 cow_start = cur_offset; 1332 + cur_offset = end; 1333 + } 1334 + 1355 1335 if (cow_start != (u64)-1) { 1356 1336 ret = cow_file_range(inode, locked_page, cow_start, end, 1357 1337 page_started, nr_written, 1); ··· 1373 1347 if (!ret) 1374 1348 ret = err; 1375 1349 1350 + if (ret && cur_offset < end) 1351 + extent_clear_unlock_delalloc(inode, 1352 + &BTRFS_I(inode)->io_tree, 1353 + cur_offset, end, locked_page, 1354 + EXTENT_CLEAR_UNLOCK_PAGE | 1355 + EXTENT_CLEAR_UNLOCK | 1356 + EXTENT_CLEAR_DELALLOC | 1357 + EXTENT_CLEAR_DIRTY | 1358 + EXTENT_SET_WRITEBACK | 1359 + EXTENT_END_WRITEBACK); 1360 + 1376 1361 btrfs_free_path(path); 1377 1362 return ret; 1378 1363 } ··· 1398 1361 int ret; 1399 1362 struct btrfs_root *root = BTRFS_I(inode)->root; 1400 1363 1401 - if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW) 1364 + if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW) { 1402 1365 ret = run_delalloc_nocow(inode, locked_page, start, end, 1403 1366 page_started, 1, nr_written); 1404 - else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC) 1367 + } else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC) { 1405 1368 ret = run_delalloc_nocow(inode, locked_page, start, end, 1406 1369 page_started, 0, nr_written); 1407 - else if (!btrfs_test_opt(root, COMPRESS) && 1408 - !(BTRFS_I(inode)->force_compress) && 1409 - !(BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS)) 1370 + } else if (!btrfs_test_opt(root, COMPRESS) && 1371 + !(BTRFS_I(inode)->force_compress) && 1372 + !(BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS)) { 1410 1373 ret = cow_file_range(inode, locked_page, start, end, 1411 1374 page_started, nr_written, 1); 1412 - else 1375 + } else { 1376 + set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, 1377 + &BTRFS_I(inode)->runtime_flags); 1413 1378 ret = cow_file_range_async(inode, locked_page, start, end, 1414 1379 page_started, nr_written); 1380 + } 1415 1381 return ret; 1416 1382 } 1417 1383 ··· 7094 7054 else 7095 7055 b_inode->flags &= ~BTRFS_INODE_NODATACOW; 7096 7056 7097 - if (b_dir->flags & BTRFS_INODE_COMPRESS) 7057 + if (b_dir->flags & BTRFS_INODE_COMPRESS) { 7098 7058 b_inode->flags |= BTRFS_INODE_COMPRESS; 7099 - else 7100 - b_inode->flags &= ~BTRFS_INODE_COMPRESS; 7059 + b_inode->flags &= ~BTRFS_INODE_NOCOMPRESS; 7060 + } else { 7061 + b_inode->flags &= ~(BTRFS_INODE_COMPRESS | 7062 + BTRFS_INODE_NOCOMPRESS); 7063 + } 7101 7064 } 7102 7065 7103 7066 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
+68 -53
fs/btrfs/ioctl.c
··· 52 52 #include "locking.h" 53 53 #include "inode-map.h" 54 54 #include "backref.h" 55 + #include "rcu-string.h" 55 56 56 57 /* Mask out flags that are inappropriate for the given type of inode. */ 57 58 static inline __u32 btrfs_mask_flags(umode_t mode, __u32 flags) ··· 786 785 return -ENOENT; 787 786 } 788 787 789 - /* 790 - * Validaty check of prev em and next em: 791 - * 1) no prev/next em 792 - * 2) prev/next em is an hole/inline extent 793 - */ 794 - static int check_adjacent_extents(struct inode *inode, struct extent_map *em) 788 + static struct extent_map *defrag_lookup_extent(struct inode *inode, u64 start) 795 789 { 796 790 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 797 - struct extent_map *prev = NULL, *next = NULL; 798 - int ret = 0; 799 - 800 - read_lock(&em_tree->lock); 801 - prev = lookup_extent_mapping(em_tree, em->start - 1, (u64)-1); 802 - next = lookup_extent_mapping(em_tree, em->start + em->len, (u64)-1); 803 - read_unlock(&em_tree->lock); 804 - 805 - if ((!prev || prev->block_start >= EXTENT_MAP_LAST_BYTE) && 806 - (!next || next->block_start >= EXTENT_MAP_LAST_BYTE)) 807 - ret = 1; 808 - free_extent_map(prev); 809 - free_extent_map(next); 810 - 811 - return ret; 812 - } 813 - 814 - static int should_defrag_range(struct inode *inode, u64 start, u64 len, 815 - int thresh, u64 *last_len, u64 *skip, 816 - u64 *defrag_end) 817 - { 818 791 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; 819 - struct extent_map *em = NULL; 820 - struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 821 - int ret = 1; 822 - 823 - /* 824 - * make sure that once we start defragging an extent, we keep on 825 - * defragging it 826 - */ 827 - if (start < *defrag_end) 828 - return 1; 829 - 830 - *skip = 0; 792 + struct extent_map *em; 793 + u64 len = PAGE_CACHE_SIZE; 831 794 832 795 /* 833 796 * hopefully we have this extent in the tree already, try without ··· 808 843 unlock_extent(io_tree, start, start + len - 1); 809 844 810 845 if (IS_ERR(em)) 811 - return 0; 846 + return NULL; 812 847 } 848 + 849 + return em; 850 + } 851 + 852 + static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em) 853 + { 854 + struct extent_map *next; 855 + bool ret = true; 856 + 857 + /* this is the last extent */ 858 + if (em->start + em->len >= i_size_read(inode)) 859 + return false; 860 + 861 + next = defrag_lookup_extent(inode, em->start + em->len); 862 + if (!next || next->block_start >= EXTENT_MAP_LAST_BYTE) 863 + ret = false; 864 + 865 + free_extent_map(next); 866 + return ret; 867 + } 868 + 869 + static int should_defrag_range(struct inode *inode, u64 start, int thresh, 870 + u64 *last_len, u64 *skip, u64 *defrag_end) 871 + { 872 + struct extent_map *em; 873 + int ret = 1; 874 + bool next_mergeable = true; 875 + 876 + /* 877 + * make sure that once we start defragging an extent, we keep on 878 + * defragging it 879 + */ 880 + if (start < *defrag_end) 881 + return 1; 882 + 883 + *skip = 0; 884 + 885 + em = defrag_lookup_extent(inode, start); 886 + if (!em) 887 + return 0; 813 888 814 889 /* this will cover holes, and inline extents */ 815 890 if (em->block_start >= EXTENT_MAP_LAST_BYTE) { ··· 857 852 goto out; 858 853 } 859 854 860 - /* If we have nothing to merge with us, just skip. */ 861 - if (check_adjacent_extents(inode, em)) { 862 - ret = 0; 863 - goto out; 864 - } 855 + next_mergeable = defrag_check_next_extent(inode, em); 865 856 866 857 /* 867 - * we hit a real extent, if it is big don't bother defragging it again 858 + * we hit a real extent, if it is big or the next extent is not a 859 + * real extent, don't bother defragging it 868 860 */ 869 - if ((*last_len == 0 || *last_len >= thresh) && em->len >= thresh) 861 + if ((*last_len == 0 || *last_len >= thresh) && 862 + (em->len >= thresh || !next_mergeable)) 870 863 ret = 0; 871 - 872 864 out: 873 865 /* 874 866 * last_len ends up being a counter of how many bytes we've defragged. ··· 1144 1142 break; 1145 1143 1146 1144 if (!should_defrag_range(inode, (u64)i << PAGE_CACHE_SHIFT, 1147 - PAGE_CACHE_SIZE, extent_thresh, 1148 - &last_len, &skip, &defrag_end)) { 1145 + extent_thresh, &last_len, &skip, 1146 + &defrag_end)) { 1149 1147 unsigned long next; 1150 1148 /* 1151 1149 * the should_defrag function tells us how much to skip ··· 1306 1304 ret = -EINVAL; 1307 1305 goto out_free; 1308 1306 } 1307 + if (device->fs_devices && device->fs_devices->seeding) { 1308 + printk(KERN_INFO "btrfs: resizer unable to apply on " 1309 + "seeding device %llu\n", devid); 1310 + ret = -EINVAL; 1311 + goto out_free; 1312 + } 1313 + 1309 1314 if (!strcmp(sizestr, "max")) 1310 1315 new_size = device->bdev->bd_inode->i_size; 1311 1316 else { ··· 1354 1345 do_div(new_size, root->sectorsize); 1355 1346 new_size *= root->sectorsize; 1356 1347 1357 - printk(KERN_INFO "btrfs: new size for %s is %llu\n", 1358 - device->name, (unsigned long long)new_size); 1348 + printk_in_rcu(KERN_INFO "btrfs: new size for %s is %llu\n", 1349 + rcu_str_deref(device->name), 1350 + (unsigned long long)new_size); 1359 1351 1360 1352 if (new_size > old_size) { 1361 1353 trans = btrfs_start_transaction(root, 0); ··· 2274 2264 di_args->total_bytes = dev->total_bytes; 2275 2265 memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid)); 2276 2266 if (dev->name) { 2277 - strncpy(di_args->path, dev->name, sizeof(di_args->path)); 2267 + struct rcu_string *name; 2268 + 2269 + rcu_read_lock(); 2270 + name = rcu_dereference(dev->name); 2271 + strncpy(di_args->path, name->str, sizeof(di_args->path)); 2272 + rcu_read_unlock(); 2278 2273 di_args->path[sizeof(di_args->path) - 1] = 0; 2279 2274 } else { 2280 2275 di_args->path[0] = '\0';
+21 -1
fs/btrfs/ordered-data.c
··· 627 627 /* start IO across the range first to instantiate any delalloc 628 628 * extents 629 629 */ 630 - filemap_write_and_wait_range(inode->i_mapping, start, orig_end); 630 + filemap_fdatawrite_range(inode->i_mapping, start, orig_end); 631 + 632 + /* 633 + * So with compression we will find and lock a dirty page and clear the 634 + * first one as dirty, setup an async extent, and immediately return 635 + * with the entire range locked but with nobody actually marked with 636 + * writeback. So we can't just filemap_write_and_wait_range() and 637 + * expect it to work since it will just kick off a thread to do the 638 + * actual work. So we need to call filemap_fdatawrite_range _again_ 639 + * since it will wait on the page lock, which won't be unlocked until 640 + * after the pages have been marked as writeback and so we're good to go 641 + * from there. We have to do this otherwise we'll miss the ordered 642 + * extents and that results in badness. Please Josef, do not think you 643 + * know better and pull this out at some point in the future, it is 644 + * right and you are wrong. 645 + */ 646 + if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, 647 + &BTRFS_I(inode)->runtime_flags)) 648 + filemap_fdatawrite_range(inode->i_mapping, start, orig_end); 649 + 650 + filemap_fdatawait_range(inode->i_mapping, start, orig_end); 631 651 632 652 end = orig_end; 633 653 found = 0;
+56
fs/btrfs/rcu-string.h
··· 1 + /* 2 + * Copyright (C) 2012 Red Hat. All rights reserved. 3 + * 4 + * This program is free software; you can redistribute it and/or 5 + * modify it under the terms of the GNU General Public 6 + * License v2 as published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 + * General Public License for more details. 12 + * 13 + * You should have received a copy of the GNU General Public 14 + * License along with this program; if not, write to the 15 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 + * Boston, MA 021110-1307, USA. 17 + */ 18 + 19 + struct rcu_string { 20 + struct rcu_head rcu; 21 + char str[0]; 22 + }; 23 + 24 + static inline struct rcu_string *rcu_string_strdup(const char *src, gfp_t mask) 25 + { 26 + size_t len = strlen(src) + 1; 27 + struct rcu_string *ret = kzalloc(sizeof(struct rcu_string) + 28 + (len * sizeof(char)), mask); 29 + if (!ret) 30 + return ret; 31 + strncpy(ret->str, src, len); 32 + return ret; 33 + } 34 + 35 + static inline void rcu_string_free(struct rcu_string *str) 36 + { 37 + if (str) 38 + kfree_rcu(str, rcu); 39 + } 40 + 41 + #define printk_in_rcu(fmt, ...) do { \ 42 + rcu_read_lock(); \ 43 + printk(fmt, __VA_ARGS__); \ 44 + rcu_read_unlock(); \ 45 + } while (0) 46 + 47 + #define printk_ratelimited_in_rcu(fmt, ...) do { \ 48 + rcu_read_lock(); \ 49 + printk_ratelimited(fmt, __VA_ARGS__); \ 50 + rcu_read_unlock(); \ 51 + } while (0) 52 + 53 + #define rcu_str_deref(rcu_str) ({ \ 54 + struct rcu_string *__str = rcu_dereference(rcu_str); \ 55 + __str->str; \ 56 + })
+18 -12
fs/btrfs/scrub.c
··· 26 26 #include "backref.h" 27 27 #include "extent_io.h" 28 28 #include "check-integrity.h" 29 + #include "rcu-string.h" 29 30 30 31 /* 31 32 * This is only the first step towards a full-features scrub. It reads all ··· 321 320 * hold all of the paths here 322 321 */ 323 322 for (i = 0; i < ipath->fspath->elem_cnt; ++i) 324 - printk(KERN_WARNING "btrfs: %s at logical %llu on dev " 323 + printk_in_rcu(KERN_WARNING "btrfs: %s at logical %llu on dev " 325 324 "%s, sector %llu, root %llu, inode %llu, offset %llu, " 326 325 "length %llu, links %u (path: %s)\n", swarn->errstr, 327 - swarn->logical, swarn->dev->name, 326 + swarn->logical, rcu_str_deref(swarn->dev->name), 328 327 (unsigned long long)swarn->sector, root, inum, offset, 329 328 min(isize - offset, (u64)PAGE_SIZE), nlink, 330 329 (char *)(unsigned long)ipath->fspath->val[i]); ··· 333 332 return 0; 334 333 335 334 err: 336 - printk(KERN_WARNING "btrfs: %s at logical %llu on dev " 335 + printk_in_rcu(KERN_WARNING "btrfs: %s at logical %llu on dev " 337 336 "%s, sector %llu, root %llu, inode %llu, offset %llu: path " 338 337 "resolving failed with ret=%d\n", swarn->errstr, 339 - swarn->logical, swarn->dev->name, 338 + swarn->logical, rcu_str_deref(swarn->dev->name), 340 339 (unsigned long long)swarn->sector, root, inum, offset, ret); 341 340 342 341 free_ipath(ipath); ··· 391 390 do { 392 391 ret = tree_backref_for_extent(&ptr, eb, ei, item_size, 393 392 &ref_root, &ref_level); 394 - printk(KERN_WARNING 393 + printk_in_rcu(KERN_WARNING 395 394 "btrfs: %s at logical %llu on dev %s, " 396 395 "sector %llu: metadata %s (level %d) in tree " 397 - "%llu\n", errstr, swarn.logical, dev->name, 396 + "%llu\n", errstr, swarn.logical, 397 + rcu_str_deref(dev->name), 398 398 (unsigned long long)swarn.sector, 399 399 ref_level ? "node" : "leaf", 400 400 ret < 0 ? -1 : ref_level, ··· 582 580 spin_lock(&sdev->stat_lock); 583 581 ++sdev->stat.uncorrectable_errors; 584 582 spin_unlock(&sdev->stat_lock); 585 - printk_ratelimited(KERN_ERR 583 + 584 + printk_ratelimited_in_rcu(KERN_ERR 586 585 "btrfs: unable to fixup (nodatasum) error at logical %llu on dev %s\n", 587 - (unsigned long long)fixup->logical, sdev->dev->name); 586 + (unsigned long long)fixup->logical, 587 + rcu_str_deref(sdev->dev->name)); 588 588 } 589 589 590 590 btrfs_free_path(path); ··· 940 936 spin_lock(&sdev->stat_lock); 941 937 sdev->stat.corrected_errors++; 942 938 spin_unlock(&sdev->stat_lock); 943 - printk_ratelimited(KERN_ERR 939 + printk_ratelimited_in_rcu(KERN_ERR 944 940 "btrfs: fixed up error at logical %llu on dev %s\n", 945 - (unsigned long long)logical, sdev->dev->name); 941 + (unsigned long long)logical, 942 + rcu_str_deref(sdev->dev->name)); 946 943 } 947 944 } else { 948 945 did_not_correct_error: 949 946 spin_lock(&sdev->stat_lock); 950 947 sdev->stat.uncorrectable_errors++; 951 948 spin_unlock(&sdev->stat_lock); 952 - printk_ratelimited(KERN_ERR 949 + printk_ratelimited_in_rcu(KERN_ERR 953 950 "btrfs: unable to fixup (regular) error at logical %llu on dev %s\n", 954 - (unsigned long long)logical, sdev->dev->name); 951 + (unsigned long long)logical, 952 + rcu_str_deref(sdev->dev->name)); 955 953 } 956 954 957 955 out:
+33
fs/btrfs/super.c
··· 54 54 #include "version.h" 55 55 #include "export.h" 56 56 #include "compression.h" 57 + #include "rcu-string.h" 57 58 58 59 #define CREATE_TRACE_POINTS 59 60 #include <trace/events/btrfs.h> ··· 1483 1482 "error %d\n", btrfs_ino(inode), ret); 1484 1483 } 1485 1484 1485 + static int btrfs_show_devname(struct seq_file *m, struct dentry *root) 1486 + { 1487 + struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb); 1488 + struct btrfs_fs_devices *cur_devices; 1489 + struct btrfs_device *dev, *first_dev = NULL; 1490 + struct list_head *head; 1491 + struct rcu_string *name; 1492 + 1493 + mutex_lock(&fs_info->fs_devices->device_list_mutex); 1494 + cur_devices = fs_info->fs_devices; 1495 + while (cur_devices) { 1496 + head = &cur_devices->devices; 1497 + list_for_each_entry(dev, head, dev_list) { 1498 + if (!first_dev || dev->devid < first_dev->devid) 1499 + first_dev = dev; 1500 + } 1501 + cur_devices = cur_devices->seed; 1502 + } 1503 + 1504 + if (first_dev) { 1505 + rcu_read_lock(); 1506 + name = rcu_dereference(first_dev->name); 1507 + seq_escape(m, name->str, " \t\n\\"); 1508 + rcu_read_unlock(); 1509 + } else { 1510 + WARN_ON(1); 1511 + } 1512 + mutex_unlock(&fs_info->fs_devices->device_list_mutex); 1513 + return 0; 1514 + } 1515 + 1486 1516 static const struct super_operations btrfs_super_ops = { 1487 1517 .drop_inode = btrfs_drop_inode, 1488 1518 .evict_inode = btrfs_evict_inode, 1489 1519 .put_super = btrfs_put_super, 1490 1520 .sync_fs = btrfs_sync_fs, 1491 1521 .show_options = btrfs_show_options, 1522 + .show_devname = btrfs_show_devname, 1492 1523 .write_inode = btrfs_write_inode, 1493 1524 .dirty_inode = btrfs_fs_dirty_inode, 1494 1525 .alloc_inode = btrfs_alloc_inode,
+12 -2
fs/btrfs/transaction.c
··· 100 100 kmem_cache_free(btrfs_transaction_cachep, cur_trans); 101 101 cur_trans = fs_info->running_transaction; 102 102 goto loop; 103 + } else if (root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) { 104 + spin_unlock(&root->fs_info->trans_lock); 105 + kmem_cache_free(btrfs_transaction_cachep, cur_trans); 106 + return -EROFS; 103 107 } 104 108 105 109 atomic_set(&cur_trans->num_writers, 1); ··· 1217 1213 1218 1214 1219 1215 static void cleanup_transaction(struct btrfs_trans_handle *trans, 1220 - struct btrfs_root *root) 1216 + struct btrfs_root *root, int err) 1221 1217 { 1222 1218 struct btrfs_transaction *cur_trans = trans->transaction; 1223 1219 1224 1220 WARN_ON(trans->use_count > 1); 1225 1221 1222 + btrfs_abort_transaction(trans, root, err); 1223 + 1226 1224 spin_lock(&root->fs_info->trans_lock); 1227 1225 list_del_init(&cur_trans->list); 1226 + if (cur_trans == root->fs_info->running_transaction) { 1227 + root->fs_info->running_transaction = NULL; 1228 + root->fs_info->trans_no_join = 0; 1229 + } 1228 1230 spin_unlock(&root->fs_info->trans_lock); 1229 1231 1230 1232 btrfs_cleanup_one_transaction(trans->transaction, root); ··· 1536 1526 // WARN_ON(1); 1537 1527 if (current->journal_info == trans) 1538 1528 current->journal_info = NULL; 1539 - cleanup_transaction(trans, root); 1529 + cleanup_transaction(trans, root, ret); 1540 1530 1541 1531 return ret; 1542 1532 }
+58 -34
fs/btrfs/volumes.c
··· 35 35 #include "volumes.h" 36 36 #include "async-thread.h" 37 37 #include "check-integrity.h" 38 + #include "rcu-string.h" 38 39 39 40 static int init_first_rw_device(struct btrfs_trans_handle *trans, 40 41 struct btrfs_root *root, ··· 65 64 device = list_entry(fs_devices->devices.next, 66 65 struct btrfs_device, dev_list); 67 66 list_del(&device->dev_list); 68 - kfree(device->name); 67 + rcu_string_free(device->name); 69 68 kfree(device); 70 69 } 71 70 kfree(fs_devices); ··· 335 334 { 336 335 struct btrfs_device *device; 337 336 struct btrfs_fs_devices *fs_devices; 337 + struct rcu_string *name; 338 338 u64 found_transid = btrfs_super_generation(disk_super); 339 - char *name; 340 339 341 340 fs_devices = find_fsid(disk_super->fsid); 342 341 if (!fs_devices) { ··· 370 369 memcpy(device->uuid, disk_super->dev_item.uuid, 371 370 BTRFS_UUID_SIZE); 372 371 spin_lock_init(&device->io_lock); 373 - device->name = kstrdup(path, GFP_NOFS); 374 - if (!device->name) { 372 + 373 + name = rcu_string_strdup(path, GFP_NOFS); 374 + if (!name) { 375 375 kfree(device); 376 376 return -ENOMEM; 377 377 } 378 + rcu_assign_pointer(device->name, name); 378 379 INIT_LIST_HEAD(&device->dev_alloc_list); 379 380 380 381 /* init readahead state */ ··· 393 390 394 391 device->fs_devices = fs_devices; 395 392 fs_devices->num_devices++; 396 - } else if (!device->name || strcmp(device->name, path)) { 397 - name = kstrdup(path, GFP_NOFS); 393 + } else if (!device->name || strcmp(device->name->str, path)) { 394 + name = rcu_string_strdup(path, GFP_NOFS); 398 395 if (!name) 399 396 return -ENOMEM; 400 - kfree(device->name); 401 - device->name = name; 397 + rcu_string_free(device->name); 398 + rcu_assign_pointer(device->name, name); 402 399 if (device->missing) { 403 400 fs_devices->missing_devices--; 404 401 device->missing = 0; ··· 433 430 434 431 /* We have held the volume lock, it is safe to get the devices. */ 435 432 list_for_each_entry(orig_dev, &orig->devices, dev_list) { 433 + struct rcu_string *name; 434 + 436 435 device = kzalloc(sizeof(*device), GFP_NOFS); 437 436 if (!device) 438 437 goto error; 439 438 440 - device->name = kstrdup(orig_dev->name, GFP_NOFS); 441 - if (!device->name) { 439 + /* 440 + * This is ok to do without rcu read locked because we hold the 441 + * uuid mutex so nothing we touch in here is going to disappear. 442 + */ 443 + name = rcu_string_strdup(orig_dev->name->str, GFP_NOFS); 444 + if (!name) { 442 445 kfree(device); 443 446 goto error; 444 447 } 448 + rcu_assign_pointer(device->name, name); 445 449 446 450 device->devid = orig_dev->devid; 447 451 device->work.func = pending_bios_fn; ··· 501 491 } 502 492 list_del_init(&device->dev_list); 503 493 fs_devices->num_devices--; 504 - kfree(device->name); 494 + rcu_string_free(device->name); 505 495 kfree(device); 506 496 } 507 497 ··· 526 516 if (device->bdev) 527 517 blkdev_put(device->bdev, device->mode); 528 518 529 - kfree(device->name); 519 + rcu_string_free(device->name); 530 520 kfree(device); 531 521 } 532 522 ··· 550 540 mutex_lock(&fs_devices->device_list_mutex); 551 541 list_for_each_entry(device, &fs_devices->devices, dev_list) { 552 542 struct btrfs_device *new_device; 543 + struct rcu_string *name; 553 544 554 545 if (device->bdev) 555 546 fs_devices->open_devices--; ··· 566 555 new_device = kmalloc(sizeof(*new_device), GFP_NOFS); 567 556 BUG_ON(!new_device); /* -ENOMEM */ 568 557 memcpy(new_device, device, sizeof(*new_device)); 569 - new_device->name = kstrdup(device->name, GFP_NOFS); 570 - BUG_ON(device->name && !new_device->name); /* -ENOMEM */ 558 + 559 + /* Safe because we are under uuid_mutex */ 560 + name = rcu_string_strdup(device->name->str, GFP_NOFS); 561 + BUG_ON(device->name && !name); /* -ENOMEM */ 562 + rcu_assign_pointer(new_device->name, name); 571 563 new_device->bdev = NULL; 572 564 new_device->writeable = 0; 573 565 new_device->in_fs_metadata = 0; ··· 635 621 if (!device->name) 636 622 continue; 637 623 638 - bdev = blkdev_get_by_path(device->name, flags, holder); 624 + bdev = blkdev_get_by_path(device->name->str, flags, holder); 639 625 if (IS_ERR(bdev)) { 640 - printk(KERN_INFO "open %s failed\n", device->name); 626 + printk(KERN_INFO "open %s failed\n", device->name->str); 641 627 goto error; 642 628 } 643 629 filemap_write_and_wait(bdev->bd_inode->i_mapping); ··· 1646 1632 struct block_device *bdev; 1647 1633 struct list_head *devices; 1648 1634 struct super_block *sb = root->fs_info->sb; 1635 + struct rcu_string *name; 1649 1636 u64 total_bytes; 1650 1637 int seeding_dev = 0; 1651 1638 int ret = 0; ··· 1686 1671 goto error; 1687 1672 } 1688 1673 1689 - device->name = kstrdup(device_path, GFP_NOFS); 1690 - if (!device->name) { 1674 + name = rcu_string_strdup(device_path, GFP_NOFS); 1675 + if (!name) { 1691 1676 kfree(device); 1692 1677 ret = -ENOMEM; 1693 1678 goto error; 1694 1679 } 1680 + rcu_assign_pointer(device->name, name); 1695 1681 1696 1682 ret = find_next_devid(root, &device->devid); 1697 1683 if (ret) { 1698 - kfree(device->name); 1684 + rcu_string_free(device->name); 1699 1685 kfree(device); 1700 1686 goto error; 1701 1687 } 1702 1688 1703 1689 trans = btrfs_start_transaction(root, 0); 1704 1690 if (IS_ERR(trans)) { 1705 - kfree(device->name); 1691 + rcu_string_free(device->name); 1706 1692 kfree(device); 1707 1693 ret = PTR_ERR(trans); 1708 1694 goto error; ··· 1812 1796 unlock_chunks(root); 1813 1797 btrfs_abort_transaction(trans, root, ret); 1814 1798 btrfs_end_transaction(trans, root); 1815 - kfree(device->name); 1799 + rcu_string_free(device->name); 1816 1800 kfree(device); 1817 1801 error: 1818 1802 blkdev_put(bdev, FMODE_EXCL); ··· 4220 4204 bio->bi_sector = bbio->stripes[dev_nr].physical >> 9; 4221 4205 dev = bbio->stripes[dev_nr].dev; 4222 4206 if (dev && dev->bdev && (rw != WRITE || dev->writeable)) { 4207 + #ifdef DEBUG 4208 + struct rcu_string *name; 4209 + 4210 + rcu_read_lock(); 4211 + name = rcu_dereference(dev->name); 4223 4212 pr_debug("btrfs_map_bio: rw %d, secor=%llu, dev=%lu " 4224 4213 "(%s id %llu), size=%u\n", rw, 4225 4214 (u64)bio->bi_sector, (u_long)dev->bdev->bd_dev, 4226 - dev->name, dev->devid, bio->bi_size); 4215 + name->str, dev->devid, bio->bi_size); 4216 + rcu_read_unlock(); 4217 + #endif 4227 4218 bio->bi_bdev = dev->bdev; 4228 4219 if (async_submit) 4229 4220 schedule_bio(root, dev, rw, bio); ··· 4717 4694 key.offset = device->devid; 4718 4695 ret = btrfs_search_slot(NULL, dev_root, &key, path, 0, 0); 4719 4696 if (ret) { 4720 - printk(KERN_WARNING "btrfs: no dev_stats entry found for device %s (devid %llu) (OK on first mount after mkfs)\n", 4721 - device->name, (unsigned long long)device->devid); 4697 + printk_in_rcu(KERN_WARNING "btrfs: no dev_stats entry found for device %s (devid %llu) (OK on first mount after mkfs)\n", 4698 + rcu_str_deref(device->name), 4699 + (unsigned long long)device->devid); 4722 4700 __btrfs_reset_dev_stats(device); 4723 4701 device->dev_stats_valid = 1; 4724 4702 btrfs_release_path(path); ··· 4771 4747 BUG_ON(!path); 4772 4748 ret = btrfs_search_slot(trans, dev_root, &key, path, -1, 1); 4773 4749 if (ret < 0) { 4774 - printk(KERN_WARNING "btrfs: error %d while searching for dev_stats item for device %s!\n", 4775 - ret, device->name); 4750 + printk_in_rcu(KERN_WARNING "btrfs: error %d while searching for dev_stats item for device %s!\n", 4751 + ret, rcu_str_deref(device->name)); 4776 4752 goto out; 4777 4753 } 4778 4754 ··· 4781 4757 /* need to delete old one and insert a new one */ 4782 4758 ret = btrfs_del_item(trans, dev_root, path); 4783 4759 if (ret != 0) { 4784 - printk(KERN_WARNING "btrfs: delete too small dev_stats item for device %s failed %d!\n", 4785 - device->name, ret); 4760 + printk_in_rcu(KERN_WARNING "btrfs: delete too small dev_stats item for device %s failed %d!\n", 4761 + rcu_str_deref(device->name), ret); 4786 4762 goto out; 4787 4763 } 4788 4764 ret = 1; ··· 4794 4770 ret = btrfs_insert_empty_item(trans, dev_root, path, 4795 4771 &key, sizeof(*ptr)); 4796 4772 if (ret < 0) { 4797 - printk(KERN_WARNING "btrfs: insert dev_stats item for device %s failed %d!\n", 4798 - device->name, ret); 4773 + printk_in_rcu(KERN_WARNING "btrfs: insert dev_stats item for device %s failed %d!\n", 4774 + rcu_str_deref(device->name), ret); 4799 4775 goto out; 4800 4776 } 4801 4777 } ··· 4847 4823 { 4848 4824 if (!dev->dev_stats_valid) 4849 4825 return; 4850 - printk_ratelimited(KERN_ERR 4826 + printk_ratelimited_in_rcu(KERN_ERR 4851 4827 "btrfs: bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u\n", 4852 - dev->name, 4828 + rcu_str_deref(dev->name), 4853 4829 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS), 4854 4830 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_READ_ERRS), 4855 4831 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_FLUSH_ERRS), ··· 4861 4837 4862 4838 static void btrfs_dev_stat_print_on_load(struct btrfs_device *dev) 4863 4839 { 4864 - printk(KERN_INFO "btrfs: bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u\n", 4865 - dev->name, 4840 + printk_in_rcu(KERN_INFO "btrfs: bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u\n", 4841 + rcu_str_deref(dev->name), 4866 4842 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS), 4867 4843 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_READ_ERRS), 4868 4844 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_FLUSH_ERRS),
+1 -1
fs/btrfs/volumes.h
··· 58 58 /* the mode sent to blkdev_get */ 59 59 fmode_t mode; 60 60 61 - char *name; 61 + struct rcu_string *name; 62 62 63 63 /* the internal btrfs device id */ 64 64 u64 devid;