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/btrfs-unstable

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable:
Btrfs: set i_size properly when fallocating and we already
btrfs: unlock on error in btrfs_file_llseek()
btrfs: btrfs_permission's RO check shouldn't apply to device nodes
Btrfs: truncate pages from clone ioctl target range
Btrfs: fix uninitialized sync_pending
Btrfs: fix wrong free space information
btrfs: memory leak in btrfs_add_inode_defrag()
Btrfs: use plain page_address() in header fields setget functions
Btrfs: forced readonly when btrfs_drop_snapshot() fails
Btrfs: check if there is enough space for balancing smarter
Btrfs: fix a bug of balance on full multi-disk partitions
Btrfs: fix an oops of log replay
Btrfs: detect wether a device supports discard
Btrfs: force unplugs when switching from high to regular priority bios

+183 -43
+4 -6
fs/btrfs/ctree.h
··· 1415 1415 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ 1416 1416 static inline u##bits btrfs_##name(struct extent_buffer *eb) \ 1417 1417 { \ 1418 - type *p = kmap_atomic(eb->first_page, KM_USER0); \ 1418 + type *p = page_address(eb->first_page); \ 1419 1419 u##bits res = le##bits##_to_cpu(p->member); \ 1420 - kunmap_atomic(p, KM_USER0); \ 1421 1420 return res; \ 1422 1421 } \ 1423 1422 static inline void btrfs_set_##name(struct extent_buffer *eb, \ 1424 1423 u##bits val) \ 1425 1424 { \ 1426 - type *p = kmap_atomic(eb->first_page, KM_USER0); \ 1425 + type *p = page_address(eb->first_page); \ 1427 1426 p->member = cpu_to_le##bits(val); \ 1428 - kunmap_atomic(p, KM_USER0); \ 1429 1427 } 1430 1428 1431 1429 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ ··· 2365 2367 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); 2366 2368 int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); 2367 2369 int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf); 2368 - int btrfs_drop_snapshot(struct btrfs_root *root, 2369 - struct btrfs_block_rsv *block_rsv, int update_ref); 2370 + void btrfs_drop_snapshot(struct btrfs_root *root, 2371 + struct btrfs_block_rsv *block_rsv, int update_ref); 2370 2372 int btrfs_drop_subtree(struct btrfs_trans_handle *trans, 2371 2373 struct btrfs_root *root, 2372 2374 struct extent_buffer *node,
+59 -16
fs/btrfs/extent-tree.c
··· 1782 1782 1783 1783 1784 1784 for (i = 0; i < multi->num_stripes; i++, stripe++) { 1785 + if (!stripe->dev->can_discard) 1786 + continue; 1787 + 1785 1788 ret = btrfs_issue_discard(stripe->dev->bdev, 1786 1789 stripe->physical, 1787 1790 stripe->length); ··· 1792 1789 discarded_bytes += stripe->length; 1793 1790 else if (ret != -EOPNOTSUPP) 1794 1791 break; 1792 + 1793 + /* 1794 + * Just in case we get back EOPNOTSUPP for some reason, 1795 + * just ignore the return value so we don't screw up 1796 + * people calling discard_extent. 1797 + */ 1798 + ret = 0; 1795 1799 } 1796 1800 kfree(multi); 1797 1801 } 1798 - if (discarded_bytes && ret == -EOPNOTSUPP) 1799 - ret = 0; 1800 1802 1801 1803 if (actual_bytes) 1802 1804 *actual_bytes = discarded_bytes; ··· 6277 6269 * also make sure backrefs for the shared block and all lower level 6278 6270 * blocks are properly updated. 6279 6271 */ 6280 - int btrfs_drop_snapshot(struct btrfs_root *root, 6281 - struct btrfs_block_rsv *block_rsv, int update_ref) 6272 + void btrfs_drop_snapshot(struct btrfs_root *root, 6273 + struct btrfs_block_rsv *block_rsv, int update_ref) 6282 6274 { 6283 6275 struct btrfs_path *path; 6284 6276 struct btrfs_trans_handle *trans; ··· 6291 6283 int level; 6292 6284 6293 6285 path = btrfs_alloc_path(); 6294 - if (!path) 6295 - return -ENOMEM; 6286 + if (!path) { 6287 + err = -ENOMEM; 6288 + goto out; 6289 + } 6296 6290 6297 6291 wc = kzalloc(sizeof(*wc), GFP_NOFS); 6298 6292 if (!wc) { 6299 6293 btrfs_free_path(path); 6300 - return -ENOMEM; 6294 + err = -ENOMEM; 6295 + goto out; 6301 6296 } 6302 6297 6303 6298 trans = btrfs_start_transaction(tree_root, 0); ··· 6329 6318 path->lowest_level = 0; 6330 6319 if (ret < 0) { 6331 6320 err = ret; 6332 - goto out; 6321 + goto out_free; 6333 6322 } 6334 6323 WARN_ON(ret > 0); 6335 6324 ··· 6436 6425 free_extent_buffer(root->commit_root); 6437 6426 kfree(root); 6438 6427 } 6439 - out: 6428 + out_free: 6440 6429 btrfs_end_transaction_throttle(trans, tree_root); 6441 6430 kfree(wc); 6442 6431 btrfs_free_path(path); 6443 - return err; 6432 + out: 6433 + if (err) 6434 + btrfs_std_error(root->fs_info, err); 6435 + return; 6444 6436 } 6445 6437 6446 6438 /* ··· 6734 6720 struct btrfs_space_info *space_info; 6735 6721 struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; 6736 6722 struct btrfs_device *device; 6723 + u64 min_free; 6724 + int index; 6725 + int dev_nr = 0; 6726 + int dev_min = 1; 6737 6727 int full = 0; 6738 6728 int ret = 0; 6739 6729 ··· 6747 6729 if (!block_group) 6748 6730 return -1; 6749 6731 6732 + min_free = btrfs_block_group_used(&block_group->item); 6733 + 6750 6734 /* no bytes used, we're good */ 6751 - if (!btrfs_block_group_used(&block_group->item)) 6735 + if (!min_free) 6752 6736 goto out; 6753 6737 6754 6738 space_info = block_group->space_info; ··· 6766 6746 * all of the extents from this block group. If we can, we're good 6767 6747 */ 6768 6748 if ((space_info->total_bytes != block_group->key.offset) && 6769 - (space_info->bytes_used + space_info->bytes_reserved + 6770 - space_info->bytes_pinned + space_info->bytes_readonly + 6771 - btrfs_block_group_used(&block_group->item) < 6772 - space_info->total_bytes)) { 6749 + (space_info->bytes_used + space_info->bytes_reserved + 6750 + space_info->bytes_pinned + space_info->bytes_readonly + 6751 + min_free < space_info->total_bytes)) { 6773 6752 spin_unlock(&space_info->lock); 6774 6753 goto out; 6775 6754 } ··· 6785 6766 if (full) 6786 6767 goto out; 6787 6768 6769 + /* 6770 + * index: 6771 + * 0: raid10 6772 + * 1: raid1 6773 + * 2: dup 6774 + * 3: raid0 6775 + * 4: single 6776 + */ 6777 + index = get_block_group_index(block_group); 6778 + if (index == 0) { 6779 + dev_min = 4; 6780 + min_free /= 2; 6781 + } else if (index == 1) { 6782 + dev_min = 2; 6783 + } else if (index == 2) { 6784 + min_free *= 2; 6785 + } else if (index == 3) { 6786 + dev_min = fs_devices->rw_devices; 6787 + min_free /= dev_min; 6788 + } 6789 + 6788 6790 mutex_lock(&root->fs_info->chunk_mutex); 6789 6791 list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list) { 6790 - u64 min_free = btrfs_block_group_used(&block_group->item); 6791 6792 u64 dev_offset; 6792 6793 6793 6794 /* ··· 6818 6779 ret = find_free_dev_extent(NULL, device, min_free, 6819 6780 &dev_offset, NULL); 6820 6781 if (!ret) 6782 + dev_nr++; 6783 + 6784 + if (dev_nr >= dev_min) 6821 6785 break; 6786 + 6822 6787 ret = -1; 6823 6788 } 6824 6789 }
+24 -4
fs/btrfs/file.c
··· 150 150 spin_lock(&root->fs_info->defrag_inodes_lock); 151 151 if (!BTRFS_I(inode)->in_defrag) 152 152 __btrfs_add_inode_defrag(inode, defrag); 153 + else 154 + kfree(defrag); 153 155 spin_unlock(&root->fs_info->defrag_inodes_lock); 154 156 return 0; 155 157 } ··· 1640 1638 1641 1639 cur_offset = alloc_start; 1642 1640 while (1) { 1641 + u64 actual_end; 1642 + 1643 1643 em = btrfs_get_extent(inode, NULL, 0, cur_offset, 1644 1644 alloc_end - cur_offset, 0); 1645 1645 BUG_ON(IS_ERR_OR_NULL(em)); 1646 1646 last_byte = min(extent_map_end(em), alloc_end); 1647 + actual_end = min_t(u64, extent_map_end(em), offset + len); 1647 1648 last_byte = (last_byte + mask) & ~mask; 1649 + 1648 1650 if (em->block_start == EXTENT_MAP_HOLE || 1649 1651 (cur_offset >= inode->i_size && 1650 1652 !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { ··· 1661 1655 free_extent_map(em); 1662 1656 break; 1663 1657 } 1658 + } else if (actual_end > inode->i_size && 1659 + !(mode & FALLOC_FL_KEEP_SIZE)) { 1660 + /* 1661 + * We didn't need to allocate any more space, but we 1662 + * still extended the size of the file so we need to 1663 + * update i_size. 1664 + */ 1665 + inode->i_ctime = CURRENT_TIME; 1666 + i_size_write(inode, actual_end); 1667 + btrfs_ordered_update_i_size(inode, actual_end, NULL); 1664 1668 } 1665 1669 free_extent_map(em); 1666 1670 ··· 1820 1804 } 1821 1805 } 1822 1806 1823 - if (offset < 0 && !(file->f_mode & FMODE_UNSIGNED_OFFSET)) 1824 - return -EINVAL; 1825 - if (offset > inode->i_sb->s_maxbytes) 1826 - return -EINVAL; 1807 + if (offset < 0 && !(file->f_mode & FMODE_UNSIGNED_OFFSET)) { 1808 + ret = -EINVAL; 1809 + goto out; 1810 + } 1811 + if (offset > inode->i_sb->s_maxbytes) { 1812 + ret = -EINVAL; 1813 + goto out; 1814 + } 1827 1815 1828 1816 /* Special lock needed here? */ 1829 1817 if (offset != file->f_pos) {
+11 -5
fs/btrfs/free-space-cache.c
··· 1168 1168 div64_u64(extent_bytes, (sizeof(struct btrfs_free_space))); 1169 1169 } 1170 1170 1171 - static void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, 1172 - struct btrfs_free_space *info, u64 offset, 1173 - u64 bytes) 1171 + static inline void __bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, 1172 + struct btrfs_free_space *info, 1173 + u64 offset, u64 bytes) 1174 1174 { 1175 1175 unsigned long start, count; 1176 1176 ··· 1181 1181 bitmap_clear(info->bitmap, start, count); 1182 1182 1183 1183 info->bytes -= bytes; 1184 + } 1185 + 1186 + static void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, 1187 + struct btrfs_free_space *info, u64 offset, 1188 + u64 bytes) 1189 + { 1190 + __bitmap_clear_bits(ctl, info, offset, bytes); 1184 1191 ctl->free_space -= bytes; 1185 1192 } 1186 1193 ··· 1991 1984 return 0; 1992 1985 1993 1986 ret = search_start; 1994 - bitmap_clear_bits(ctl, entry, ret, bytes); 1987 + __bitmap_clear_bits(ctl, entry, ret, bytes); 1995 1988 1996 1989 return ret; 1997 1990 } ··· 2046 2039 continue; 2047 2040 } 2048 2041 } else { 2049 - 2050 2042 ret = entry->offset; 2051 2043 2052 2044 entry->offset += bytes;
+8 -4
fs/btrfs/inode.c
··· 7354 7354 static int btrfs_permission(struct inode *inode, int mask) 7355 7355 { 7356 7356 struct btrfs_root *root = BTRFS_I(inode)->root; 7357 + umode_t mode = inode->i_mode; 7357 7358 7358 - if (btrfs_root_readonly(root) && (mask & MAY_WRITE)) 7359 - return -EROFS; 7360 - if ((BTRFS_I(inode)->flags & BTRFS_INODE_READONLY) && (mask & MAY_WRITE)) 7361 - return -EACCES; 7359 + if (mask & MAY_WRITE && 7360 + (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))) { 7361 + if (btrfs_root_readonly(root)) 7362 + return -EROFS; 7363 + if (BTRFS_I(inode)->flags & BTRFS_INODE_READONLY) 7364 + return -EACCES; 7365 + } 7362 7366 return generic_permission(inode, mask); 7363 7367 } 7364 7368
+4
fs/btrfs/ioctl.c
··· 2236 2236 btrfs_wait_ordered_range(src, off, len); 2237 2237 } 2238 2238 2239 + /* truncate page cache pages from target inode range */ 2240 + truncate_inode_pages_range(&inode->i_data, off, 2241 + ALIGN(off + len, PAGE_CACHE_SIZE) - 1); 2242 + 2239 2243 /* clone data */ 2240 2244 key.objectid = btrfs_ino(src); 2241 2245 key.type = BTRFS_EXTENT_DATA_KEY;
+24 -4
fs/btrfs/tree-log.c
··· 799 799 struct extent_buffer *eb, int slot, 800 800 struct btrfs_key *key) 801 801 { 802 - struct inode *dir; 803 - int ret; 804 802 struct btrfs_inode_ref *ref; 803 + struct btrfs_dir_item *di; 804 + struct inode *dir; 805 805 struct inode *inode; 806 - char *name; 807 - int namelen; 808 806 unsigned long ref_ptr; 809 807 unsigned long ref_end; 808 + char *name; 809 + int namelen; 810 + int ret; 810 811 int search_done = 0; 811 812 812 813 /* ··· 907 906 * coresponding ref, it does not need to check again. 908 907 */ 909 908 search_done = 1; 909 + } 910 + btrfs_release_path(path); 911 + 912 + /* look for a conflicting sequence number */ 913 + di = btrfs_lookup_dir_index_item(trans, root, path, btrfs_ino(dir), 914 + btrfs_inode_ref_index(eb, ref), 915 + name, namelen, 0); 916 + if (di && !IS_ERR(di)) { 917 + ret = drop_one_dir_item(trans, root, path, dir, di); 918 + BUG_ON(ret); 919 + } 920 + btrfs_release_path(path); 921 + 922 + /* look for a conflicing name */ 923 + di = btrfs_lookup_dir_item(trans, root, path, btrfs_ino(dir), 924 + name, namelen, 0); 925 + if (di && !IS_ERR(di)) { 926 + ret = drop_one_dir_item(trans, root, path, dir, di); 927 + BUG_ON(ret); 910 928 } 911 929 btrfs_release_path(path); 912 930
+47 -4
fs/btrfs/volumes.c
··· 142 142 unsigned long limit; 143 143 unsigned long last_waited = 0; 144 144 int force_reg = 0; 145 + int sync_pending = 0; 145 146 struct blk_plug plug; 146 147 147 148 /* ··· 229 228 wake_up(&fs_info->async_submit_wait); 230 229 231 230 BUG_ON(atomic_read(&cur->bi_cnt) == 0); 231 + 232 + /* 233 + * if we're doing the sync list, record that our 234 + * plug has some sync requests on it 235 + * 236 + * If we're doing the regular list and there are 237 + * sync requests sitting around, unplug before 238 + * we add more 239 + */ 240 + if (pending_bios == &device->pending_sync_bios) { 241 + sync_pending = 1; 242 + } else if (sync_pending) { 243 + blk_finish_plug(&plug); 244 + blk_start_plug(&plug); 245 + sync_pending = 0; 246 + } 232 247 233 248 submit_bio(cur->bi_rw, cur); 234 249 num_run++; ··· 517 500 fs_devices->rw_devices--; 518 501 } 519 502 503 + if (device->can_discard) 504 + fs_devices->num_can_discard--; 505 + 520 506 new_device = kmalloc(sizeof(*new_device), GFP_NOFS); 521 507 BUG_ON(!new_device); 522 508 memcpy(new_device, device, sizeof(*new_device)); ··· 528 508 new_device->bdev = NULL; 529 509 new_device->writeable = 0; 530 510 new_device->in_fs_metadata = 0; 511 + new_device->can_discard = 0; 531 512 list_replace_rcu(&device->dev_list, &new_device->dev_list); 532 513 533 514 call_rcu(&device->rcu, free_device); ··· 568 547 static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices, 569 548 fmode_t flags, void *holder) 570 549 { 550 + struct request_queue *q; 571 551 struct block_device *bdev; 572 552 struct list_head *head = &fs_devices->devices; 573 553 struct btrfs_device *device; ··· 623 601 } else { 624 602 device->writeable = !bdev_read_only(bdev); 625 603 seeding = 0; 604 + } 605 + 606 + q = bdev_get_queue(bdev); 607 + if (blk_queue_discard(q)) { 608 + device->can_discard = 1; 609 + fs_devices->num_can_discard++; 626 610 } 627 611 628 612 device->bdev = bdev; ··· 863 835 864 836 max_hole_start = search_start; 865 837 max_hole_size = 0; 838 + hole_size = 0; 866 839 867 840 if (search_start >= search_end) { 868 841 ret = -ENOSPC; ··· 946 917 cond_resched(); 947 918 } 948 919 949 - hole_size = search_end- search_start; 920 + /* 921 + * At this point, search_start should be the end of 922 + * allocated dev extents, and when shrinking the device, 923 + * search_end may be smaller than search_start. 924 + */ 925 + if (search_end > search_start) 926 + hole_size = search_end - search_start; 927 + 950 928 if (hole_size > max_hole_size) { 951 929 max_hole_start = search_start; 952 930 max_hole_size = hole_size; ··· 1579 1543 1580 1544 int btrfs_init_new_device(struct btrfs_root *root, char *device_path) 1581 1545 { 1546 + struct request_queue *q; 1582 1547 struct btrfs_trans_handle *trans; 1583 1548 struct btrfs_device *device; 1584 1549 struct block_device *bdev; ··· 1649 1612 1650 1613 lock_chunks(root); 1651 1614 1615 + q = bdev_get_queue(bdev); 1616 + if (blk_queue_discard(q)) 1617 + device->can_discard = 1; 1652 1618 device->writeable = 1; 1653 1619 device->work.func = pending_bios_fn; 1654 1620 generate_random_uuid(device->uuid); ··· 1687 1647 root->fs_info->fs_devices->num_devices++; 1688 1648 root->fs_info->fs_devices->open_devices++; 1689 1649 root->fs_info->fs_devices->rw_devices++; 1650 + if (device->can_discard) 1651 + root->fs_info->fs_devices->num_can_discard++; 1690 1652 root->fs_info->fs_devices->total_rw_bytes += device->total_bytes; 1691 1653 1692 1654 if (!blk_queue_nonrot(bdev_get_queue(bdev))) ··· 2455 2413 total_avail = device->total_bytes - device->bytes_used; 2456 2414 else 2457 2415 total_avail = 0; 2458 - /* avail is off by max(alloc_start, 1MB), but that is the same 2459 - * for all devices, so it doesn't hurt the sorting later on 2460 - */ 2416 + 2417 + /* If there is no space on this device, skip it. */ 2418 + if (total_avail == 0) 2419 + continue; 2461 2420 2462 2421 ret = find_free_dev_extent(trans, device, 2463 2422 max_stripe_size * dev_stripes,
+2
fs/btrfs/volumes.h
··· 48 48 int writeable; 49 49 int in_fs_metadata; 50 50 int missing; 51 + int can_discard; 51 52 52 53 spinlock_t io_lock; 53 54 ··· 105 104 u64 rw_devices; 106 105 u64 missing_devices; 107 106 u64 total_rw_bytes; 107 + u64 num_can_discard; 108 108 struct block_device *latest_bdev; 109 109 110 110 /* all of the devices in the FS, protected by a mutex