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 fixes from Chris Mason:
"These are mostly bug fixes and a two small performance fixes. The
most important of the bunch are Josef's fix for a snapshotting
regression and Mark's update to fix compile problems on arm"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (25 commits)
Btrfs: create the uuid tree on remount rw
btrfs: change extent-same to copy entire argument struct
Btrfs: dir_inode_operations should use btrfs_update_time also
btrfs: Add btrfs: prefix to kernel log output
btrfs: refuse to remount read-write after abort
Btrfs: btrfs_ioctl_default_subvol: Revert back to toplevel subvolume when arg is 0
Btrfs: don't leak transaction in btrfs_sync_file()
Btrfs: add the missing mutex unlock in write_all_supers()
Btrfs: iput inode on allocation failure
Btrfs: remove space_info->reservation_progress
Btrfs: kill delay_iput arg to the wait_ordered functions
Btrfs: fix worst case calculator for space usage
Revert "Btrfs: rework the overcommit logic to be based on the total size"
Btrfs: improve replacing nocow extents
Btrfs: drop dir i_size when adding new names on replay
Btrfs: replay dir_index items before other items
Btrfs: check roots last log commit when checking if an inode has been logged
Btrfs: actually log directory we are fsync()'ing
Btrfs: actually limit the size of delalloc range
Btrfs: allocate the free space by the existed max extent size when ENOSPC
...

+364 -175
+4 -1
fs/btrfs/btrfs_inode.h
··· 213 213 static inline int btrfs_inode_in_log(struct inode *inode, u64 generation) 214 214 { 215 215 if (BTRFS_I(inode)->logged_trans == generation && 216 - BTRFS_I(inode)->last_sub_trans <= BTRFS_I(inode)->last_log_commit) 216 + BTRFS_I(inode)->last_sub_trans <= 217 + BTRFS_I(inode)->last_log_commit && 218 + BTRFS_I(inode)->last_sub_trans <= 219 + BTRFS_I(inode)->root->last_log_commit) 217 220 return 1; 218 221 return 0; 219 222 }
+5 -2
fs/btrfs/ctree.c
··· 1005 1005 return ret; 1006 1006 } 1007 1007 1008 - if (root->ref_cows) 1009 - btrfs_reloc_cow_block(trans, root, buf, cow); 1008 + if (root->ref_cows) { 1009 + ret = btrfs_reloc_cow_block(trans, root, buf, cow); 1010 + if (ret) 1011 + return ret; 1012 + } 1010 1013 1011 1014 if (buf == root->node) { 1012 1015 WARN_ON(parent && parent != buf);
+4 -13
fs/btrfs/ctree.h
··· 1118 1118 */ 1119 1119 struct percpu_counter total_bytes_pinned; 1120 1120 1121 - /* 1122 - * we bump reservation progress every time we decrement 1123 - * bytes_reserved. This way people waiting for reservations 1124 - * know something good has happened and they can check 1125 - * for progress. The number here isn't to be trusted, it 1126 - * just shows reclaim activity 1127 - */ 1128 - unsigned long reservation_progress; 1129 - 1130 1121 unsigned int full:1; /* indicates that we cannot allocate any more 1131 1122 chunks for this space */ 1132 1123 unsigned int chunk_alloc:1; /* set if we are allocating a chunk */ ··· 3126 3135 unsigned num_items) 3127 3136 { 3128 3137 return (root->leafsize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) * 3129 - 3 * num_items; 3138 + 2 * num_items; 3130 3139 } 3131 3140 3132 3141 /* ··· 3930 3939 struct btrfs_root *root); 3931 3940 int btrfs_recover_relocation(struct btrfs_root *root); 3932 3941 int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len); 3933 - void btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, 3934 - struct btrfs_root *root, struct extent_buffer *buf, 3935 - struct extent_buffer *cow); 3942 + int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, 3943 + struct btrfs_root *root, struct extent_buffer *buf, 3944 + struct extent_buffer *cow); 3936 3945 void btrfs_reloc_pre_snapshot(struct btrfs_trans_handle *trans, 3937 3946 struct btrfs_pending_snapshot *pending, 3938 3947 u64 *bytes_to_reserve);
+2 -2
fs/btrfs/dev-replace.c
··· 400 400 args->result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR; 401 401 btrfs_dev_replace_unlock(dev_replace); 402 402 403 - btrfs_wait_all_ordered_extents(root->fs_info, 0); 403 + btrfs_wait_all_ordered_extents(root->fs_info); 404 404 405 405 /* force writing the updated state information to disk */ 406 406 trans = btrfs_start_transaction(root, 0); ··· 475 475 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); 476 476 return ret; 477 477 } 478 - btrfs_wait_all_ordered_extents(root->fs_info, 0); 478 + btrfs_wait_all_ordered_extents(root->fs_info); 479 479 480 480 trans = btrfs_start_transaction(root, 0); 481 481 if (IS_ERR(trans)) {
+2
fs/btrfs/disk-io.c
··· 157 157 { .id = BTRFS_TREE_LOG_OBJECTID, .name_stem = "log" }, 158 158 { .id = BTRFS_TREE_RELOC_OBJECTID, .name_stem = "treloc" }, 159 159 { .id = BTRFS_DATA_RELOC_TREE_OBJECTID, .name_stem = "dreloc" }, 160 + { .id = BTRFS_UUID_TREE_OBJECTID, .name_stem = "uuid" }, 160 161 { .id = 0, .name_stem = "tree" }, 161 162 }; 162 163 ··· 3416 3415 if (total_errors > max_errors) { 3417 3416 printk(KERN_ERR "btrfs: %d errors while writing supers\n", 3418 3417 total_errors); 3418 + mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); 3419 3419 3420 3420 /* FUA is masked off if unsupported and can't be the reason */ 3421 3421 btrfs_error(root->fs_info, -EIO,
+30 -27
fs/btrfs/extent-tree.c
··· 3925 3925 u64 space_size; 3926 3926 u64 avail; 3927 3927 u64 used; 3928 - u64 to_add; 3929 3928 3930 3929 used = space_info->bytes_used + space_info->bytes_reserved + 3931 3930 space_info->bytes_pinned + space_info->bytes_readonly; ··· 3958 3959 BTRFS_BLOCK_GROUP_RAID10)) 3959 3960 avail >>= 1; 3960 3961 3961 - to_add = space_info->total_bytes; 3962 - 3963 3962 /* 3964 3963 * If we aren't flushing all things, let us overcommit up to 3965 3964 * 1/2th of the space. If we can flush, don't let us overcommit 3966 3965 * too much, let it overcommit up to 1/8 of the space. 3967 3966 */ 3968 3967 if (flush == BTRFS_RESERVE_FLUSH_ALL) 3969 - to_add >>= 3; 3968 + avail >>= 3; 3970 3969 else 3971 - to_add >>= 1; 3970 + avail >>= 1; 3972 3971 3973 - /* 3974 - * Limit the overcommit to the amount of free space we could possibly 3975 - * allocate for chunks. 3976 - */ 3977 - to_add = min(avail, to_add); 3978 - 3979 - if (used + bytes < space_info->total_bytes + to_add) 3972 + if (used + bytes < space_info->total_bytes + avail) 3980 3973 return 1; 3981 3974 return 0; 3982 3975 } ··· 3991 4000 */ 3992 4001 btrfs_start_all_delalloc_inodes(root->fs_info, 0); 3993 4002 if (!current->journal_info) 3994 - btrfs_wait_all_ordered_extents(root->fs_info, 0); 4003 + btrfs_wait_all_ordered_extents(root->fs_info); 3995 4004 } 3996 4005 } 3997 4006 ··· 4021 4030 if (delalloc_bytes == 0) { 4022 4031 if (trans) 4023 4032 return; 4024 - btrfs_wait_all_ordered_extents(root->fs_info, 0); 4033 + btrfs_wait_all_ordered_extents(root->fs_info); 4025 4034 return; 4026 4035 } 4027 4036 ··· 4049 4058 4050 4059 loops++; 4051 4060 if (wait_ordered && !trans) { 4052 - btrfs_wait_all_ordered_extents(root->fs_info, 0); 4061 + btrfs_wait_all_ordered_extents(root->fs_info); 4053 4062 } else { 4054 4063 time_left = schedule_timeout_killable(1); 4055 4064 if (time_left) ··· 4456 4465 space_info->bytes_may_use -= num_bytes; 4457 4466 trace_btrfs_space_reservation(fs_info, "space_info", 4458 4467 space_info->flags, num_bytes, 0); 4459 - space_info->reservation_progress++; 4460 4468 spin_unlock(&space_info->lock); 4461 4469 } 4462 4470 } ··· 4656 4666 sinfo->bytes_may_use -= num_bytes; 4657 4667 trace_btrfs_space_reservation(fs_info, "space_info", 4658 4668 sinfo->flags, num_bytes, 0); 4659 - sinfo->reservation_progress++; 4660 4669 block_rsv->reserved = block_rsv->size; 4661 4670 block_rsv->full = 1; 4662 4671 } ··· 5435 5446 space_info->bytes_readonly += num_bytes; 5436 5447 cache->reserved -= num_bytes; 5437 5448 space_info->bytes_reserved -= num_bytes; 5438 - space_info->reservation_progress++; 5439 5449 } 5440 5450 spin_unlock(&cache->lock); 5441 5451 spin_unlock(&space_info->lock); ··· 6105 6117 /* 6106 6118 * walks the btree of allocated extents and find a hole of a given size. 6107 6119 * The key ins is changed to record the hole: 6108 - * ins->objectid == block start 6120 + * ins->objectid == start position 6109 6121 * ins->flags = BTRFS_EXTENT_ITEM_KEY 6110 - * ins->offset == number of blocks 6122 + * ins->offset == the size of the hole. 6111 6123 * Any available blocks before search_start are skipped. 6124 + * 6125 + * If there is no suitable free space, we will record the max size of 6126 + * the free space extent currently. 6112 6127 */ 6113 6128 static noinline int find_free_extent(struct btrfs_root *orig_root, 6114 6129 u64 num_bytes, u64 empty_size, ··· 6124 6133 struct btrfs_block_group_cache *block_group = NULL; 6125 6134 struct btrfs_block_group_cache *used_block_group; 6126 6135 u64 search_start = 0; 6136 + u64 max_extent_size = 0; 6127 6137 int empty_cluster = 2 * 1024 * 1024; 6128 6138 struct btrfs_space_info *space_info; 6129 6139 int loop = 0; ··· 6284 6292 btrfs_get_block_group(used_block_group); 6285 6293 6286 6294 offset = btrfs_alloc_from_cluster(used_block_group, 6287 - last_ptr, num_bytes, used_block_group->key.objectid); 6295 + last_ptr, 6296 + num_bytes, 6297 + used_block_group->key.objectid, 6298 + &max_extent_size); 6288 6299 if (offset) { 6289 6300 /* we have a block, we're done */ 6290 6301 spin_unlock(&last_ptr->refill_lock); ··· 6350 6355 * cluster 6351 6356 */ 6352 6357 offset = btrfs_alloc_from_cluster(block_group, 6353 - last_ptr, num_bytes, 6354 - search_start); 6358 + last_ptr, 6359 + num_bytes, 6360 + search_start, 6361 + &max_extent_size); 6355 6362 if (offset) { 6356 6363 /* we found one, proceed */ 6357 6364 spin_unlock(&last_ptr->refill_lock); ··· 6388 6391 if (cached && 6389 6392 block_group->free_space_ctl->free_space < 6390 6393 num_bytes + empty_cluster + empty_size) { 6394 + if (block_group->free_space_ctl->free_space > 6395 + max_extent_size) 6396 + max_extent_size = 6397 + block_group->free_space_ctl->free_space; 6391 6398 spin_unlock(&block_group->free_space_ctl->tree_lock); 6392 6399 goto loop; 6393 6400 } 6394 6401 spin_unlock(&block_group->free_space_ctl->tree_lock); 6395 6402 6396 6403 offset = btrfs_find_space_for_alloc(block_group, search_start, 6397 - num_bytes, empty_size); 6404 + num_bytes, empty_size, 6405 + &max_extent_size); 6398 6406 /* 6399 6407 * If we didn't find a chunk, and we haven't failed on this 6400 6408 * block group before, and this block group is in the middle of ··· 6517 6515 ret = 0; 6518 6516 } 6519 6517 out: 6520 - 6518 + if (ret == -ENOSPC) 6519 + ins->offset = max_extent_size; 6521 6520 return ret; 6522 6521 } 6523 6522 ··· 6576 6573 flags); 6577 6574 6578 6575 if (ret == -ENOSPC) { 6579 - if (!final_tried) { 6580 - num_bytes = num_bytes >> 1; 6576 + if (!final_tried && ins->offset) { 6577 + num_bytes = min(num_bytes >> 1, ins->offset); 6581 6578 num_bytes = round_down(num_bytes, root->sectorsize); 6582 6579 num_bytes = max(num_bytes, min_alloc_size); 6583 6580 if (num_bytes == min_alloc_size)
+5 -3
fs/btrfs/extent_io.c
··· 1481 1481 *end = state->end; 1482 1482 cur_start = state->end + 1; 1483 1483 node = rb_next(node); 1484 - if (!node) 1485 - break; 1486 1484 total_bytes += state->end - state->start + 1; 1487 - if (total_bytes >= max_bytes) 1485 + if (total_bytes >= max_bytes) { 1486 + *end = *start + max_bytes - 1; 1487 + break; 1488 + } 1489 + if (!node) 1488 1490 break; 1489 1491 } 1490 1492 out:
+2 -2
fs/btrfs/file.c
··· 1859 1859 1860 1860 ret = btrfs_log_dentry_safe(trans, root, dentry); 1861 1861 if (ret < 0) { 1862 - mutex_unlock(&inode->i_mutex); 1863 - goto out; 1862 + /* Fallthrough and commit/free transaction. */ 1863 + ret = 1; 1864 1864 } 1865 1865 1866 1866 /* we've logged all the items and now have a consistent
+47 -20
fs/btrfs/free-space-cache.c
··· 1431 1431 ctl->free_space += bytes; 1432 1432 } 1433 1433 1434 + /* 1435 + * If we can not find suitable extent, we will use bytes to record 1436 + * the size of the max extent. 1437 + */ 1434 1438 static int search_bitmap(struct btrfs_free_space_ctl *ctl, 1435 1439 struct btrfs_free_space *bitmap_info, u64 *offset, 1436 1440 u64 *bytes) 1437 1441 { 1438 1442 unsigned long found_bits = 0; 1443 + unsigned long max_bits = 0; 1439 1444 unsigned long bits, i; 1440 1445 unsigned long next_zero; 1446 + unsigned long extent_bits; 1441 1447 1442 1448 i = offset_to_bit(bitmap_info->offset, ctl->unit, 1443 1449 max_t(u64, *offset, bitmap_info->offset)); ··· 1452 1446 for_each_set_bit_from(i, bitmap_info->bitmap, BITS_PER_BITMAP) { 1453 1447 next_zero = find_next_zero_bit(bitmap_info->bitmap, 1454 1448 BITS_PER_BITMAP, i); 1455 - if ((next_zero - i) >= bits) { 1456 - found_bits = next_zero - i; 1449 + extent_bits = next_zero - i; 1450 + if (extent_bits >= bits) { 1451 + found_bits = extent_bits; 1457 1452 break; 1453 + } else if (extent_bits > max_bits) { 1454 + max_bits = extent_bits; 1458 1455 } 1459 1456 i = next_zero; 1460 1457 } ··· 1468 1459 return 0; 1469 1460 } 1470 1461 1462 + *bytes = (u64)(max_bits) * ctl->unit; 1471 1463 return -1; 1472 1464 } 1473 1465 1466 + /* Cache the size of the max extent in bytes */ 1474 1467 static struct btrfs_free_space * 1475 1468 find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, 1476 - unsigned long align) 1469 + unsigned long align, u64 *max_extent_size) 1477 1470 { 1478 1471 struct btrfs_free_space *entry; 1479 1472 struct rb_node *node; 1480 - u64 ctl_off; 1481 1473 u64 tmp; 1482 1474 u64 align_off; 1483 1475 int ret; 1484 1476 1485 1477 if (!ctl->free_space_offset.rb_node) 1486 - return NULL; 1478 + goto out; 1487 1479 1488 1480 entry = tree_search_offset(ctl, offset_to_bitmap(ctl, *offset), 0, 1); 1489 1481 if (!entry) 1490 - return NULL; 1482 + goto out; 1491 1483 1492 1484 for (node = &entry->offset_index; node; node = rb_next(node)) { 1493 1485 entry = rb_entry(node, struct btrfs_free_space, offset_index); 1494 - if (entry->bytes < *bytes) 1486 + if (entry->bytes < *bytes) { 1487 + if (entry->bytes > *max_extent_size) 1488 + *max_extent_size = entry->bytes; 1495 1489 continue; 1490 + } 1496 1491 1497 1492 /* make sure the space returned is big enough 1498 1493 * to match our requested alignment 1499 1494 */ 1500 1495 if (*bytes >= align) { 1501 - ctl_off = entry->offset - ctl->start; 1502 - tmp = ctl_off + align - 1;; 1496 + tmp = entry->offset - ctl->start + align - 1; 1503 1497 do_div(tmp, align); 1504 1498 tmp = tmp * align + ctl->start; 1505 1499 align_off = tmp - entry->offset; ··· 1511 1499 tmp = entry->offset; 1512 1500 } 1513 1501 1514 - if (entry->bytes < *bytes + align_off) 1502 + if (entry->bytes < *bytes + align_off) { 1503 + if (entry->bytes > *max_extent_size) 1504 + *max_extent_size = entry->bytes; 1515 1505 continue; 1506 + } 1516 1507 1517 1508 if (entry->bitmap) { 1518 - ret = search_bitmap(ctl, entry, &tmp, bytes); 1509 + u64 size = *bytes; 1510 + 1511 + ret = search_bitmap(ctl, entry, &tmp, &size); 1519 1512 if (!ret) { 1520 1513 *offset = tmp; 1514 + *bytes = size; 1521 1515 return entry; 1516 + } else if (size > *max_extent_size) { 1517 + *max_extent_size = size; 1522 1518 } 1523 1519 continue; 1524 1520 } ··· 1535 1515 *bytes = entry->bytes - align_off; 1536 1516 return entry; 1537 1517 } 1538 - 1518 + out: 1539 1519 return NULL; 1540 1520 } 1541 1521 ··· 2136 2116 } 2137 2117 2138 2118 u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group, 2139 - u64 offset, u64 bytes, u64 empty_size) 2119 + u64 offset, u64 bytes, u64 empty_size, 2120 + u64 *max_extent_size) 2140 2121 { 2141 2122 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; 2142 2123 struct btrfs_free_space *entry = NULL; ··· 2148 2127 2149 2128 spin_lock(&ctl->tree_lock); 2150 2129 entry = find_free_space(ctl, &offset, &bytes_search, 2151 - block_group->full_stripe_len); 2130 + block_group->full_stripe_len, max_extent_size); 2152 2131 if (!entry) 2153 2132 goto out; 2154 2133 ··· 2158 2137 if (!entry->bytes) 2159 2138 free_bitmap(ctl, entry); 2160 2139 } else { 2161 - 2162 2140 unlink_free_space(ctl, entry); 2163 2141 align_gap_len = offset - entry->offset; 2164 2142 align_gap = entry->offset; ··· 2171 2151 else 2172 2152 link_free_space(ctl, entry); 2173 2153 } 2174 - 2175 2154 out: 2176 2155 spin_unlock(&ctl->tree_lock); 2177 2156 ··· 2225 2206 static u64 btrfs_alloc_from_bitmap(struct btrfs_block_group_cache *block_group, 2226 2207 struct btrfs_free_cluster *cluster, 2227 2208 struct btrfs_free_space *entry, 2228 - u64 bytes, u64 min_start) 2209 + u64 bytes, u64 min_start, 2210 + u64 *max_extent_size) 2229 2211 { 2230 2212 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; 2231 2213 int err; ··· 2238 2218 search_bytes = bytes; 2239 2219 2240 2220 err = search_bitmap(ctl, entry, &search_start, &search_bytes); 2241 - if (err) 2221 + if (err) { 2222 + if (search_bytes > *max_extent_size) 2223 + *max_extent_size = search_bytes; 2242 2224 return 0; 2225 + } 2243 2226 2244 2227 ret = search_start; 2245 2228 __bitmap_clear_bits(ctl, entry, ret, bytes); ··· 2257 2234 */ 2258 2235 u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group, 2259 2236 struct btrfs_free_cluster *cluster, u64 bytes, 2260 - u64 min_start) 2237 + u64 min_start, u64 *max_extent_size) 2261 2238 { 2262 2239 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; 2263 2240 struct btrfs_free_space *entry = NULL; ··· 2277 2254 2278 2255 entry = rb_entry(node, struct btrfs_free_space, offset_index); 2279 2256 while(1) { 2257 + if (entry->bytes < bytes && entry->bytes > *max_extent_size) 2258 + *max_extent_size = entry->bytes; 2259 + 2280 2260 if (entry->bytes < bytes || 2281 2261 (!entry->bitmap && entry->offset < min_start)) { 2282 2262 node = rb_next(&entry->offset_index); ··· 2293 2267 if (entry->bitmap) { 2294 2268 ret = btrfs_alloc_from_bitmap(block_group, 2295 2269 cluster, entry, bytes, 2296 - cluster->window_start); 2270 + cluster->window_start, 2271 + max_extent_size); 2297 2272 if (ret == 0) { 2298 2273 node = rb_next(&entry->offset_index); 2299 2274 if (!node)
+3 -2
fs/btrfs/free-space-cache.h
··· 94 94 void btrfs_remove_free_space_cache(struct btrfs_block_group_cache 95 95 *block_group); 96 96 u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group, 97 - u64 offset, u64 bytes, u64 empty_size); 97 + u64 offset, u64 bytes, u64 empty_size, 98 + u64 *max_extent_size); 98 99 u64 btrfs_find_ino_for_alloc(struct btrfs_root *fs_root); 99 100 void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group, 100 101 u64 bytes); ··· 106 105 void btrfs_init_free_cluster(struct btrfs_free_cluster *cluster); 107 106 u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group, 108 107 struct btrfs_free_cluster *cluster, u64 bytes, 109 - u64 min_start); 108 + u64 min_start, u64 *max_extent_size); 110 109 int btrfs_return_cluster_to_free_space( 111 110 struct btrfs_block_group_cache *block_group, 112 111 struct btrfs_free_cluster *cluster);
+11 -5
fs/btrfs/inode.c
··· 4688 4688 struct btrfs_inode *entry; 4689 4689 struct rb_node **p; 4690 4690 struct rb_node *parent; 4691 + struct rb_node *new = &BTRFS_I(inode)->rb_node; 4691 4692 u64 ino = btrfs_ino(inode); 4692 4693 4693 4694 if (inode_unhashed(inode)) 4694 4695 return; 4695 - again: 4696 4696 parent = NULL; 4697 4697 spin_lock(&root->inode_lock); 4698 4698 p = &root->inode_tree.rb_node; ··· 4707 4707 else { 4708 4708 WARN_ON(!(entry->vfs_inode.i_state & 4709 4709 (I_WILL_FREE | I_FREEING))); 4710 - rb_erase(parent, &root->inode_tree); 4710 + rb_replace_node(parent, new, &root->inode_tree); 4711 4711 RB_CLEAR_NODE(parent); 4712 4712 spin_unlock(&root->inode_lock); 4713 - goto again; 4713 + return; 4714 4714 } 4715 4715 } 4716 - rb_link_node(&BTRFS_I(inode)->rb_node, parent, p); 4717 - rb_insert_color(&BTRFS_I(inode)->rb_node, &root->inode_tree); 4716 + rb_link_node(new, parent, p); 4717 + rb_insert_color(new, &root->inode_tree); 4718 4718 spin_unlock(&root->inode_lock); 4719 4719 } 4720 4720 ··· 8216 8216 8217 8217 work = btrfs_alloc_delalloc_work(inode, 0, delay_iput); 8218 8218 if (unlikely(!work)) { 8219 + if (delay_iput) 8220 + btrfs_add_delayed_iput(inode); 8221 + else 8222 + iput(inode); 8219 8223 ret = -ENOMEM; 8220 8224 goto out; 8221 8225 } ··· 8617 8613 .removexattr = btrfs_removexattr, 8618 8614 .permission = btrfs_permission, 8619 8615 .get_acl = btrfs_get_acl, 8616 + .update_time = btrfs_update_time, 8620 8617 }; 8621 8618 static const struct inode_operations btrfs_dir_ro_inode_operations = { 8622 8619 .lookup = btrfs_lookup, 8623 8620 .permission = btrfs_permission, 8624 8621 .get_acl = btrfs_get_acl, 8622 + .update_time = btrfs_update_time, 8625 8623 }; 8626 8624 8627 8625 static const struct file_operations btrfs_dir_file_operations = {
+47 -33
fs/btrfs/ioctl.c
··· 574 574 if (ret) 575 575 return ret; 576 576 577 - btrfs_wait_ordered_extents(root, 0); 577 + btrfs_wait_ordered_extents(root); 578 578 579 579 pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS); 580 580 if (!pending_snapshot) ··· 2696 2696 static long btrfs_ioctl_file_extent_same(struct file *file, 2697 2697 void __user *argp) 2698 2698 { 2699 - struct btrfs_ioctl_same_args *args = argp; 2700 - struct btrfs_ioctl_same_args same; 2701 - struct btrfs_ioctl_same_extent_info info; 2699 + struct btrfs_ioctl_same_args tmp; 2700 + struct btrfs_ioctl_same_args *same; 2701 + struct btrfs_ioctl_same_extent_info *info; 2702 2702 struct inode *src = file->f_dentry->d_inode; 2703 2703 struct file *dst_file = NULL; 2704 2704 struct inode *dst; ··· 2706 2706 u64 len; 2707 2707 int i; 2708 2708 int ret; 2709 + unsigned long size; 2709 2710 u64 bs = BTRFS_I(src)->root->fs_info->sb->s_blocksize; 2710 2711 bool is_admin = capable(CAP_SYS_ADMIN); 2711 2712 ··· 2717 2716 if (ret) 2718 2717 return ret; 2719 2718 2720 - if (copy_from_user(&same, 2719 + if (copy_from_user(&tmp, 2721 2720 (struct btrfs_ioctl_same_args __user *)argp, 2722 - sizeof(same))) { 2721 + sizeof(tmp))) { 2723 2722 ret = -EFAULT; 2724 2723 goto out; 2725 2724 } 2726 2725 2727 - off = same.logical_offset; 2728 - len = same.length; 2726 + size = sizeof(tmp) + 2727 + tmp.dest_count * sizeof(struct btrfs_ioctl_same_extent_info); 2728 + 2729 + same = kmalloc(size, GFP_NOFS); 2730 + if (!same) { 2731 + ret = -EFAULT; 2732 + goto out; 2733 + } 2734 + 2735 + if (copy_from_user(same, 2736 + (struct btrfs_ioctl_same_args __user *)argp, size)) { 2737 + ret = -EFAULT; 2738 + goto out; 2739 + } 2740 + 2741 + off = same->logical_offset; 2742 + len = same->length; 2729 2743 2730 2744 /* 2731 2745 * Limit the total length we will dedupe for each operation. ··· 2768 2752 if (!S_ISREG(src->i_mode)) 2769 2753 goto out; 2770 2754 2755 + /* pre-format output fields to sane values */ 2756 + for (i = 0; i < same->dest_count; i++) { 2757 + same->info[i].bytes_deduped = 0ULL; 2758 + same->info[i].status = 0; 2759 + } 2760 + 2771 2761 ret = 0; 2772 - for (i = 0; i < same.dest_count; i++) { 2773 - if (copy_from_user(&info, &args->info[i], sizeof(info))) { 2774 - ret = -EFAULT; 2775 - goto out; 2776 - } 2762 + for (i = 0; i < same->dest_count; i++) { 2763 + info = &same->info[i]; 2777 2764 2778 - info.bytes_deduped = 0; 2779 - 2780 - dst_file = fget(info.fd); 2765 + dst_file = fget(info->fd); 2781 2766 if (!dst_file) { 2782 - info.status = -EBADF; 2767 + info->status = -EBADF; 2783 2768 goto next; 2784 2769 } 2785 2770 2786 2771 if (!(is_admin || (dst_file->f_mode & FMODE_WRITE))) { 2787 - info.status = -EINVAL; 2772 + info->status = -EINVAL; 2788 2773 goto next; 2789 2774 } 2790 2775 2791 - info.status = -EXDEV; 2776 + info->status = -EXDEV; 2792 2777 if (file->f_path.mnt != dst_file->f_path.mnt) 2793 2778 goto next; 2794 2779 ··· 2798 2781 goto next; 2799 2782 2800 2783 if (S_ISDIR(dst->i_mode)) { 2801 - info.status = -EISDIR; 2784 + info->status = -EISDIR; 2802 2785 goto next; 2803 2786 } 2804 2787 2805 2788 if (!S_ISREG(dst->i_mode)) { 2806 - info.status = -EACCES; 2789 + info->status = -EACCES; 2807 2790 goto next; 2808 2791 } 2809 2792 2810 - info.status = btrfs_extent_same(src, off, len, dst, 2811 - info.logical_offset); 2812 - if (info.status == 0) 2813 - info.bytes_deduped += len; 2793 + info->status = btrfs_extent_same(src, off, len, dst, 2794 + info->logical_offset); 2795 + if (info->status == 0) 2796 + info->bytes_deduped += len; 2814 2797 2815 2798 next: 2816 2799 if (dst_file) 2817 2800 fput(dst_file); 2818 - 2819 - if (__put_user_unaligned(info.status, &args->info[i].status) || 2820 - __put_user_unaligned(info.bytes_deduped, 2821 - &args->info[i].bytes_deduped)) { 2822 - ret = -EFAULT; 2823 - goto out; 2824 - } 2825 2801 } 2802 + 2803 + ret = copy_to_user(argp, same, size); 2804 + if (ret) 2805 + ret = -EFAULT; 2826 2806 2827 2807 out: 2828 2808 mnt_drop_write_file(file); ··· 3324 3310 } 3325 3311 3326 3312 if (!objectid) 3327 - objectid = root->root_key.objectid; 3313 + objectid = BTRFS_FS_TREE_OBJECTID; 3328 3314 3329 3315 location.objectid = objectid; 3330 3316 location.type = BTRFS_ROOT_ITEM_KEY;
+3 -21
fs/btrfs/ordered-data.c
··· 563 563 * wait for all the ordered extents in a root. This is done when balancing 564 564 * space between drives. 565 565 */ 566 - void btrfs_wait_ordered_extents(struct btrfs_root *root, int delay_iput) 566 + void btrfs_wait_ordered_extents(struct btrfs_root *root) 567 567 { 568 568 struct list_head splice, works; 569 569 struct btrfs_ordered_extent *ordered, *next; 570 - struct inode *inode; 571 570 572 571 INIT_LIST_HEAD(&splice); 573 572 INIT_LIST_HEAD(&works); ··· 579 580 root_extent_list); 580 581 list_move_tail(&ordered->root_extent_list, 581 582 &root->ordered_extents); 582 - /* 583 - * the inode may be getting freed (in sys_unlink path). 584 - */ 585 - inode = igrab(ordered->inode); 586 - if (!inode) { 587 - cond_resched_lock(&root->ordered_extent_lock); 588 - continue; 589 - } 590 - 591 583 atomic_inc(&ordered->refs); 592 584 spin_unlock(&root->ordered_extent_lock); 593 585 ··· 595 605 list_for_each_entry_safe(ordered, next, &works, work_list) { 596 606 list_del_init(&ordered->work_list); 597 607 wait_for_completion(&ordered->completion); 598 - 599 - inode = ordered->inode; 600 608 btrfs_put_ordered_extent(ordered); 601 - if (delay_iput) 602 - btrfs_add_delayed_iput(inode); 603 - else 604 - iput(inode); 605 - 606 609 cond_resched(); 607 610 } 608 611 mutex_unlock(&root->fs_info->ordered_operations_mutex); 609 612 } 610 613 611 - void btrfs_wait_all_ordered_extents(struct btrfs_fs_info *fs_info, 612 - int delay_iput) 614 + void btrfs_wait_all_ordered_extents(struct btrfs_fs_info *fs_info) 613 615 { 614 616 struct btrfs_root *root; 615 617 struct list_head splice; ··· 619 637 &fs_info->ordered_roots); 620 638 spin_unlock(&fs_info->ordered_root_lock); 621 639 622 - btrfs_wait_ordered_extents(root, delay_iput); 640 + btrfs_wait_ordered_extents(root); 623 641 btrfs_put_fs_root(root); 624 642 625 643 spin_lock(&fs_info->ordered_root_lock);
+2 -3
fs/btrfs/ordered-data.h
··· 195 195 void btrfs_add_ordered_operation(struct btrfs_trans_handle *trans, 196 196 struct btrfs_root *root, 197 197 struct inode *inode); 198 - void btrfs_wait_ordered_extents(struct btrfs_root *root, int delay_iput); 199 - void btrfs_wait_all_ordered_extents(struct btrfs_fs_info *fs_info, 200 - int delay_iput); 198 + void btrfs_wait_ordered_extents(struct btrfs_root *root); 199 + void btrfs_wait_all_ordered_extents(struct btrfs_fs_info *fs_info); 201 200 void btrfs_get_logged_extents(struct btrfs_root *log, struct inode *inode); 202 201 void btrfs_wait_logged_extents(struct btrfs_root *log, u64 transid); 203 202 void btrfs_free_logged_extents(struct btrfs_root *log, u64 transid);
+25 -18
fs/btrfs/relocation.c
··· 1548 1548 btrfs_file_extent_other_encoding(leaf, fi)); 1549 1549 1550 1550 if (num_bytes != btrfs_file_extent_disk_num_bytes(leaf, fi)) { 1551 - ret = 1; 1551 + ret = -EINVAL; 1552 1552 goto out; 1553 1553 } 1554 1554 ··· 1579 1579 u64 end; 1580 1580 u32 nritems; 1581 1581 u32 i; 1582 - int ret; 1582 + int ret = 0; 1583 1583 int first = 1; 1584 1584 int dirty = 0; 1585 1585 ··· 1642 1642 1643 1643 ret = get_new_location(rc->data_inode, &new_bytenr, 1644 1644 bytenr, num_bytes); 1645 - if (ret > 0) { 1646 - WARN_ON(1); 1647 - continue; 1645 + if (ret) { 1646 + /* 1647 + * Don't have to abort since we've not changed anything 1648 + * in the file extent yet. 1649 + */ 1650 + break; 1648 1651 } 1649 - BUG_ON(ret < 0); 1650 1652 1651 1653 btrfs_set_file_extent_disk_bytenr(leaf, fi, new_bytenr); 1652 1654 dirty = 1; ··· 1658 1656 num_bytes, parent, 1659 1657 btrfs_header_owner(leaf), 1660 1658 key.objectid, key.offset, 1); 1661 - BUG_ON(ret); 1659 + if (ret) { 1660 + btrfs_abort_transaction(trans, root, ret); 1661 + break; 1662 + } 1662 1663 1663 1664 ret = btrfs_free_extent(trans, root, bytenr, num_bytes, 1664 1665 parent, btrfs_header_owner(leaf), 1665 1666 key.objectid, key.offset, 1); 1666 - BUG_ON(ret); 1667 + if (ret) { 1668 + btrfs_abort_transaction(trans, root, ret); 1669 + break; 1670 + } 1667 1671 } 1668 1672 if (dirty) 1669 1673 btrfs_mark_buffer_dirty(leaf); 1670 1674 if (inode) 1671 1675 btrfs_add_delayed_iput(inode); 1672 - return 0; 1676 + return ret; 1673 1677 } 1674 1678 1675 1679 static noinline_for_stack ··· 4246 4238 err = ret; 4247 4239 goto out; 4248 4240 } 4249 - btrfs_wait_all_ordered_extents(fs_info, 0); 4241 + btrfs_wait_all_ordered_extents(fs_info); 4250 4242 4251 4243 while (1) { 4252 4244 mutex_lock(&fs_info->cleaner_mutex); ··· 4507 4499 return ret; 4508 4500 } 4509 4501 4510 - void btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, 4511 - struct btrfs_root *root, struct extent_buffer *buf, 4512 - struct extent_buffer *cow) 4502 + int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, 4503 + struct btrfs_root *root, struct extent_buffer *buf, 4504 + struct extent_buffer *cow) 4513 4505 { 4514 4506 struct reloc_control *rc; 4515 4507 struct backref_node *node; 4516 4508 int first_cow = 0; 4517 4509 int level; 4518 - int ret; 4510 + int ret = 0; 4519 4511 4520 4512 rc = root->fs_info->reloc_ctl; 4521 4513 if (!rc) 4522 - return; 4514 + return 0; 4523 4515 4524 4516 BUG_ON(rc->stage == UPDATE_DATA_PTRS && 4525 4517 root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID); ··· 4555 4547 rc->nodes_relocated += buf->len; 4556 4548 } 4557 4549 4558 - if (level == 0 && first_cow && rc->stage == UPDATE_DATA_PTRS) { 4550 + if (level == 0 && first_cow && rc->stage == UPDATE_DATA_PTRS) 4559 4551 ret = replace_file_extents(trans, rc, root, cow); 4560 - BUG_ON(ret); 4561 - } 4552 + return ret; 4562 4553 } 4563 4554 4564 4555 /*
+98 -14
fs/btrfs/scrub.c
··· 158 158 int mirror_num; 159 159 }; 160 160 161 + struct scrub_nocow_inode { 162 + u64 inum; 163 + u64 offset; 164 + u64 root; 165 + struct list_head list; 166 + }; 167 + 161 168 struct scrub_copy_nocow_ctx { 162 169 struct scrub_ctx *sctx; 163 170 u64 logical; 164 171 u64 len; 165 172 int mirror_num; 166 173 u64 physical_for_dev_replace; 174 + struct list_head inodes; 167 175 struct btrfs_work work; 168 176 }; 169 177 ··· 253 245 static int write_page_nocow(struct scrub_ctx *sctx, 254 246 u64 physical_for_dev_replace, struct page *page); 255 247 static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, 256 - void *ctx); 248 + struct scrub_copy_nocow_ctx *ctx); 257 249 static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len, 258 250 int mirror_num, u64 physical_for_dev_replace); 259 251 static void copy_nocow_pages_worker(struct btrfs_work *work); ··· 3134 3126 nocow_ctx->mirror_num = mirror_num; 3135 3127 nocow_ctx->physical_for_dev_replace = physical_for_dev_replace; 3136 3128 nocow_ctx->work.func = copy_nocow_pages_worker; 3129 + INIT_LIST_HEAD(&nocow_ctx->inodes); 3137 3130 btrfs_queue_worker(&fs_info->scrub_nocow_workers, 3138 3131 &nocow_ctx->work); 3139 3132 3140 3133 return 0; 3141 3134 } 3135 + 3136 + static int record_inode_for_nocow(u64 inum, u64 offset, u64 root, void *ctx) 3137 + { 3138 + struct scrub_copy_nocow_ctx *nocow_ctx = ctx; 3139 + struct scrub_nocow_inode *nocow_inode; 3140 + 3141 + nocow_inode = kzalloc(sizeof(*nocow_inode), GFP_NOFS); 3142 + if (!nocow_inode) 3143 + return -ENOMEM; 3144 + nocow_inode->inum = inum; 3145 + nocow_inode->offset = offset; 3146 + nocow_inode->root = root; 3147 + list_add_tail(&nocow_inode->list, &nocow_ctx->inodes); 3148 + return 0; 3149 + } 3150 + 3151 + #define COPY_COMPLETE 1 3142 3152 3143 3153 static void copy_nocow_pages_worker(struct btrfs_work *work) 3144 3154 { ··· 3193 3167 } 3194 3168 3195 3169 ret = iterate_inodes_from_logical(logical, fs_info, path, 3196 - copy_nocow_pages_for_inode, 3197 - nocow_ctx); 3170 + record_inode_for_nocow, nocow_ctx); 3198 3171 if (ret != 0 && ret != -ENOENT) { 3199 3172 pr_warn("iterate_inodes_from_logical() failed: log %llu, phys %llu, len %llu, mir %u, ret %d\n", 3200 3173 logical, physical_for_dev_replace, len, mirror_num, ··· 3202 3177 goto out; 3203 3178 } 3204 3179 3180 + btrfs_end_transaction(trans, root); 3181 + trans = NULL; 3182 + while (!list_empty(&nocow_ctx->inodes)) { 3183 + struct scrub_nocow_inode *entry; 3184 + entry = list_first_entry(&nocow_ctx->inodes, 3185 + struct scrub_nocow_inode, 3186 + list); 3187 + list_del_init(&entry->list); 3188 + ret = copy_nocow_pages_for_inode(entry->inum, entry->offset, 3189 + entry->root, nocow_ctx); 3190 + kfree(entry); 3191 + if (ret == COPY_COMPLETE) { 3192 + ret = 0; 3193 + break; 3194 + } else if (ret) { 3195 + break; 3196 + } 3197 + } 3205 3198 out: 3199 + while (!list_empty(&nocow_ctx->inodes)) { 3200 + struct scrub_nocow_inode *entry; 3201 + entry = list_first_entry(&nocow_ctx->inodes, 3202 + struct scrub_nocow_inode, 3203 + list); 3204 + list_del_init(&entry->list); 3205 + kfree(entry); 3206 + } 3206 3207 if (trans && !IS_ERR(trans)) 3207 3208 btrfs_end_transaction(trans, root); 3208 3209 if (not_written) ··· 3241 3190 scrub_pending_trans_workers_dec(sctx); 3242 3191 } 3243 3192 3244 - static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, void *ctx) 3193 + static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, 3194 + struct scrub_copy_nocow_ctx *nocow_ctx) 3245 3195 { 3246 - struct scrub_copy_nocow_ctx *nocow_ctx = ctx; 3247 3196 struct btrfs_fs_info *fs_info = nocow_ctx->sctx->dev_root->fs_info; 3248 3197 struct btrfs_key key; 3249 3198 struct inode *inode; 3250 3199 struct page *page; 3251 3200 struct btrfs_root *local_root; 3201 + struct btrfs_ordered_extent *ordered; 3202 + struct extent_map *em; 3203 + struct extent_state *cached_state = NULL; 3204 + struct extent_io_tree *io_tree; 3252 3205 u64 physical_for_dev_replace; 3253 - u64 len; 3206 + u64 len = nocow_ctx->len; 3207 + u64 lockstart = offset, lockend = offset + len - 1; 3254 3208 unsigned long index; 3255 3209 int srcu_index; 3256 - int ret; 3257 - int err; 3210 + int ret = 0; 3211 + int err = 0; 3258 3212 3259 3213 key.objectid = root; 3260 3214 key.type = BTRFS_ROOT_ITEM_KEY; ··· 3285 3229 mutex_lock(&inode->i_mutex); 3286 3230 inode_dio_wait(inode); 3287 3231 3288 - ret = 0; 3289 3232 physical_for_dev_replace = nocow_ctx->physical_for_dev_replace; 3290 - len = nocow_ctx->len; 3233 + io_tree = &BTRFS_I(inode)->io_tree; 3234 + 3235 + lock_extent_bits(io_tree, lockstart, lockend, 0, &cached_state); 3236 + ordered = btrfs_lookup_ordered_range(inode, lockstart, len); 3237 + if (ordered) { 3238 + btrfs_put_ordered_extent(ordered); 3239 + goto out_unlock; 3240 + } 3241 + 3242 + em = btrfs_get_extent(inode, NULL, 0, lockstart, len, 0); 3243 + if (IS_ERR(em)) { 3244 + ret = PTR_ERR(em); 3245 + goto out_unlock; 3246 + } 3247 + 3248 + /* 3249 + * This extent does not actually cover the logical extent anymore, 3250 + * move on to the next inode. 3251 + */ 3252 + if (em->block_start > nocow_ctx->logical || 3253 + em->block_start + em->block_len < nocow_ctx->logical + len) { 3254 + free_extent_map(em); 3255 + goto out_unlock; 3256 + } 3257 + free_extent_map(em); 3258 + 3291 3259 while (len >= PAGE_CACHE_SIZE) { 3292 3260 index = offset >> PAGE_CACHE_SHIFT; 3293 3261 again: ··· 3327 3247 goto next_page; 3328 3248 } else { 3329 3249 ClearPageError(page); 3330 - err = extent_read_full_page(&BTRFS_I(inode)-> 3331 - io_tree, 3332 - page, btrfs_get_extent, 3333 - nocow_ctx->mirror_num); 3250 + err = extent_read_full_page_nolock(io_tree, page, 3251 + btrfs_get_extent, 3252 + nocow_ctx->mirror_num); 3334 3253 if (err) { 3335 3254 ret = err; 3336 3255 goto next_page; ··· 3343 3264 * page in the page cache. 3344 3265 */ 3345 3266 if (page->mapping != inode->i_mapping) { 3267 + unlock_page(page); 3346 3268 page_cache_release(page); 3347 3269 goto again; 3348 3270 } ··· 3367 3287 physical_for_dev_replace += PAGE_CACHE_SIZE; 3368 3288 len -= PAGE_CACHE_SIZE; 3369 3289 } 3290 + ret = COPY_COMPLETE; 3291 + out_unlock: 3292 + unlock_extent_cached(io_tree, lockstart, lockend, &cached_state, 3293 + GFP_NOFS); 3370 3294 out: 3371 3295 mutex_unlock(&inode->i_mutex); 3372 3296 iput(inode);
+20 -1
fs/btrfs/super.c
··· 921 921 return 0; 922 922 } 923 923 924 - btrfs_wait_all_ordered_extents(fs_info, 1); 924 + btrfs_wait_all_ordered_extents(fs_info); 925 925 926 926 trans = btrfs_attach_transaction_barrier(root); 927 927 if (IS_ERR(trans)) { ··· 1340 1340 if (ret) 1341 1341 goto restore; 1342 1342 } else { 1343 + if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) { 1344 + btrfs_err(fs_info, 1345 + "Remounting read-write after error is not allowed\n"); 1346 + ret = -EINVAL; 1347 + goto restore; 1348 + } 1343 1349 if (fs_info->fs_devices->rw_devices == 0) { 1344 1350 ret = -EACCES; 1345 1351 goto restore; ··· 1382 1376 if (ret) { 1383 1377 pr_warn("btrfs: failed to resume dev_replace\n"); 1384 1378 goto restore; 1379 + } 1380 + 1381 + if (!fs_info->uuid_root) { 1382 + pr_info("btrfs: creating UUID tree\n"); 1383 + ret = btrfs_create_uuid_tree(fs_info); 1384 + if (ret) { 1385 + pr_warn("btrfs: failed to create the uuid tree" 1386 + "%d\n", ret); 1387 + goto restore; 1388 + } 1385 1389 } 1386 1390 sb->s_flags &= ~MS_RDONLY; 1387 1391 } ··· 1777 1761 printk(KERN_INFO "Btrfs loaded" 1778 1762 #ifdef CONFIG_BTRFS_DEBUG 1779 1763 ", debug=on" 1764 + #endif 1765 + #ifdef CONFIG_BTRFS_ASSERT 1766 + ", assert=on" 1780 1767 #endif 1781 1768 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY 1782 1769 ", integrity-checker=on"
+1 -1
fs/btrfs/transaction.c
··· 1603 1603 static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info) 1604 1604 { 1605 1605 if (btrfs_test_opt(fs_info->tree_root, FLUSHONCOMMIT)) 1606 - btrfs_wait_all_ordered_extents(fs_info, 1); 1606 + btrfs_wait_all_ordered_extents(fs_info); 1607 1607 } 1608 1608 1609 1609 int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
+48 -4
fs/btrfs/tree-log.c
··· 93 93 */ 94 94 #define LOG_WALK_PIN_ONLY 0 95 95 #define LOG_WALK_REPLAY_INODES 1 96 - #define LOG_WALK_REPLAY_ALL 2 96 + #define LOG_WALK_REPLAY_DIR_INDEX 2 97 + #define LOG_WALK_REPLAY_ALL 3 97 98 98 99 static int btrfs_log_inode(struct btrfs_trans_handle *trans, 99 100 struct btrfs_root *root, struct inode *inode, ··· 394 393 if (inode_item) { 395 394 struct btrfs_inode_item *item; 396 395 u64 nbytes; 396 + u32 mode; 397 397 398 398 item = btrfs_item_ptr(path->nodes[0], path->slots[0], 399 399 struct btrfs_inode_item); ··· 402 400 item = btrfs_item_ptr(eb, slot, 403 401 struct btrfs_inode_item); 404 402 btrfs_set_inode_nbytes(eb, item, nbytes); 403 + 404 + /* 405 + * If this is a directory we need to reset the i_size to 406 + * 0 so that we can set it up properly when replaying 407 + * the rest of the items in this log. 408 + */ 409 + mode = btrfs_inode_mode(eb, item); 410 + if (S_ISDIR(mode)) 411 + btrfs_set_inode_size(eb, item, 0); 405 412 } 406 413 } else if (inode_item) { 407 414 struct btrfs_inode_item *item; 415 + u32 mode; 408 416 409 417 /* 410 418 * New inode, set nbytes to 0 so that the nbytes comes out ··· 422 410 */ 423 411 item = btrfs_item_ptr(eb, slot, struct btrfs_inode_item); 424 412 btrfs_set_inode_nbytes(eb, item, 0); 413 + 414 + /* 415 + * If this is a directory we need to reset the i_size to 0 so 416 + * that we can set it up properly when replaying the rest of 417 + * the items in this log. 418 + */ 419 + mode = btrfs_inode_mode(eb, item); 420 + if (S_ISDIR(mode)) 421 + btrfs_set_inode_size(eb, item, 0); 425 422 } 426 423 insert: 427 424 btrfs_release_path(path); ··· 1517 1496 iput(inode); 1518 1497 return -EIO; 1519 1498 } 1499 + 1520 1500 ret = btrfs_add_link(trans, dir, inode, name, name_len, 1, index); 1521 1501 1522 1502 /* FIXME, put inode into FIXUP list */ ··· 1556 1534 u8 log_type; 1557 1535 int exists; 1558 1536 int ret = 0; 1537 + bool update_size = (key->type == BTRFS_DIR_INDEX_KEY); 1559 1538 1560 1539 dir = read_one_inode(root, key->objectid); 1561 1540 if (!dir) ··· 1627 1604 goto insert; 1628 1605 out: 1629 1606 btrfs_release_path(path); 1607 + if (!ret && update_size) { 1608 + btrfs_i_size_write(dir, dir->i_size + name_len * 2); 1609 + ret = btrfs_update_inode(trans, root, dir); 1610 + } 1630 1611 kfree(name); 1631 1612 iput(dir); 1632 1613 return ret; ··· 1641 1614 name, name_len, log_type, &log_key); 1642 1615 if (ret && ret != -ENOENT) 1643 1616 goto out; 1617 + update_size = false; 1644 1618 ret = 0; 1645 1619 goto out; 1646 1620 } ··· 2055 2027 if (ret) 2056 2028 break; 2057 2029 } 2030 + 2031 + if (key.type == BTRFS_DIR_INDEX_KEY && 2032 + wc->stage == LOG_WALK_REPLAY_DIR_INDEX) { 2033 + ret = replay_one_dir_item(wc->trans, root, path, 2034 + eb, i, &key); 2035 + if (ret) 2036 + break; 2037 + } 2038 + 2058 2039 if (wc->stage < LOG_WALK_REPLAY_ALL) 2059 2040 continue; 2060 2041 ··· 2085 2048 eb, i, &key); 2086 2049 if (ret) 2087 2050 break; 2088 - } else if (key.type == BTRFS_DIR_ITEM_KEY || 2089 - key.type == BTRFS_DIR_INDEX_KEY) { 2051 + } else if (key.type == BTRFS_DIR_ITEM_KEY) { 2090 2052 ret = replay_one_dir_item(wc->trans, root, path, 2091 2053 eb, i, &key); 2092 2054 if (ret) ··· 3841 3805 int ret = 0; 3842 3806 struct btrfs_root *root; 3843 3807 struct dentry *old_parent = NULL; 3808 + struct inode *orig_inode = inode; 3844 3809 3845 3810 /* 3846 3811 * for regular files, if its inode is already on disk, we don't ··· 3861 3824 } 3862 3825 3863 3826 while (1) { 3864 - BTRFS_I(inode)->logged_trans = trans->transid; 3827 + /* 3828 + * If we are logging a directory then we start with our inode, 3829 + * not our parents inode, so we need to skipp setting the 3830 + * logged_trans so that further down in the log code we don't 3831 + * think this inode has already been logged. 3832 + */ 3833 + if (inode != orig_inode) 3834 + BTRFS_I(inode)->logged_trans = trans->transid; 3865 3835 smp_mb(); 3866 3836 3867 3837 if (BTRFS_I(inode)->last_unlink_trans > last_committed) {
+4 -3
fs/btrfs/volumes.c
··· 796 796 fs_devices->rotating = 1; 797 797 798 798 fs_devices->open_devices++; 799 - if (device->writeable && !device->is_tgtdev_for_dev_replace) { 799 + if (device->writeable && 800 + device->devid != BTRFS_DEV_REPLACE_DEVID) { 800 801 fs_devices->rw_devices++; 801 802 list_add(&device->dev_alloc_list, 802 803 &fs_devices->alloc_list); ··· 912 911 if (disk_super->label[0]) { 913 912 if (disk_super->label[BTRFS_LABEL_SIZE - 1]) 914 913 disk_super->label[BTRFS_LABEL_SIZE - 1] = '\0'; 915 - printk(KERN_INFO "device label %s ", disk_super->label); 914 + printk(KERN_INFO "btrfs: device label %s ", disk_super->label); 916 915 } else { 917 - printk(KERN_INFO "device fsid %pU ", disk_super->fsid); 916 + printk(KERN_INFO "btrfs: device fsid %pU ", disk_super->fsid); 918 917 } 919 918 920 919 printk(KERN_CONT "devid %llu transid %llu %s\n", devid, transid, path);
+1
include/trace/events/btrfs.h
··· 42 42 { BTRFS_TREE_LOG_OBJECTID, "TREE_LOG" }, \ 43 43 { BTRFS_QUOTA_TREE_OBJECTID, "QUOTA_TREE" }, \ 44 44 { BTRFS_TREE_RELOC_OBJECTID, "TREE_RELOC" }, \ 45 + { BTRFS_UUID_TREE_OBJECTID, "UUID_RELOC" }, \ 45 46 { BTRFS_DATA_RELOC_TREE_OBJECTID, "DATA_RELOC_TREE" }) 46 47 47 48 #define show_root_type(obj) \