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 git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable

* git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable: (24 commits)
Btrfs: don't use migrate page without CONFIG_MIGRATION
Btrfs: deal with DIO bios that span more than one ordered extent
Btrfs: setup blank root and fs_info for mount time
Btrfs: fix fiemap
Btrfs - fix race between btrfs_get_sb() and umount
Btrfs: update inode ctime when using links
Btrfs: make sure new inode size is ok in fallocate
Btrfs: fix typo in fallocate to make it honor actual size
Btrfs: avoid NULL pointer deref in try_release_extent_buffer
Btrfs: make btrfs_add_nondir take parent inode as an argument
Btrfs: hold i_mutex when calling btrfs_log_dentry_safe
Btrfs: use dget_parent where we can UPDATED
Btrfs: fix more ESTALE problems with NFS
Btrfs: handle NFS lookups properly
btrfs: make 1-bit signed fileds unsigned
btrfs: Show device attr correctly for symlinks
btrfs: Set file size correctly in file clone
btrfs: Check if dest_offset is block-size aligned before cloning file
Btrfs: handle the space_cache option properly
btrfs: Fix early enospc because 'unused' calculated with wrong sign.
...

+572 -114
+1 -14
fs/btrfs/compression.c
··· 91 91 static struct bio *compressed_bio_alloc(struct block_device *bdev, 92 92 u64 first_byte, gfp_t gfp_flags) 93 93 { 94 - struct bio *bio; 95 94 int nr_vecs; 96 95 97 96 nr_vecs = bio_get_nr_vecs(bdev); 98 - bio = bio_alloc(gfp_flags, nr_vecs); 99 - 100 - if (bio == NULL && (current->flags & PF_MEMALLOC)) { 101 - while (!bio && (nr_vecs /= 2)) 102 - bio = bio_alloc(gfp_flags, nr_vecs); 103 - } 104 - 105 - if (bio) { 106 - bio->bi_size = 0; 107 - bio->bi_bdev = bdev; 108 - bio->bi_sector = first_byte >> 9; 109 - } 110 - return bio; 97 + return btrfs_bio_alloc(bdev, first_byte >> 9, nr_vecs, gfp_flags); 111 98 } 112 99 113 100 static int check_compressed_csum(struct inode *inode,
+3 -3
fs/btrfs/ctree.h
··· 808 808 int extents_thresh; 809 809 int free_extents; 810 810 int total_bitmaps; 811 - int ro:1; 812 - int dirty:1; 813 - int iref:1; 811 + unsigned int ro:1; 812 + unsigned int dirty:1; 813 + unsigned int iref:1; 814 814 815 815 int disk_cache_state; 816 816
+32 -6
fs/btrfs/disk-io.c
··· 28 28 #include <linux/freezer.h> 29 29 #include <linux/crc32c.h> 30 30 #include <linux/slab.h> 31 + #include <linux/migrate.h> 31 32 #include "compat.h" 32 33 #include "ctree.h" 33 34 #include "disk-io.h" ··· 356 355 ret = btree_read_extent_buffer_pages(root, eb, start + PAGE_CACHE_SIZE, 357 356 btrfs_header_generation(eb)); 358 357 BUG_ON(ret); 358 + WARN_ON(!btrfs_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN)); 359 + 359 360 found_start = btrfs_header_bytenr(eb); 360 361 if (found_start != start) { 361 362 WARN_ON(1); ··· 696 693 __btree_submit_bio_done); 697 694 } 698 695 696 + static int btree_migratepage(struct address_space *mapping, 697 + struct page *newpage, struct page *page) 698 + { 699 + /* 700 + * we can't safely write a btree page from here, 701 + * we haven't done the locking hook 702 + */ 703 + if (PageDirty(page)) 704 + return -EAGAIN; 705 + /* 706 + * Buffers may be managed in a filesystem specific way. 707 + * We must have no buffers or drop them. 708 + */ 709 + if (page_has_private(page) && 710 + !try_to_release_page(page, GFP_KERNEL)) 711 + return -EAGAIN; 712 + #ifdef CONFIG_MIGRATION 713 + return migrate_page(mapping, newpage, page); 714 + #else 715 + return -ENOSYS; 716 + #endif 717 + } 718 + 699 719 static int btree_writepage(struct page *page, struct writeback_control *wbc) 700 720 { 701 721 struct extent_io_tree *tree; ··· 733 707 } 734 708 735 709 redirty_page_for_writepage(wbc, page); 736 - eb = btrfs_find_tree_block(root, page_offset(page), 737 - PAGE_CACHE_SIZE); 710 + eb = btrfs_find_tree_block(root, page_offset(page), PAGE_CACHE_SIZE); 738 711 WARN_ON(!eb); 739 712 740 713 was_dirty = test_and_set_bit(EXTENT_BUFFER_DIRTY, &eb->bflags); ··· 824 799 .releasepage = btree_releasepage, 825 800 .invalidatepage = btree_invalidatepage, 826 801 .sync_page = block_sync_page, 802 + #ifdef CONFIG_MIGRATION 803 + .migratepage = btree_migratepage, 804 + #endif 827 805 }; 828 806 829 807 int readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize, ··· 1566 1538 GFP_NOFS); 1567 1539 struct btrfs_root *csum_root = kzalloc(sizeof(struct btrfs_root), 1568 1540 GFP_NOFS); 1569 - struct btrfs_root *tree_root = kzalloc(sizeof(struct btrfs_root), 1570 - GFP_NOFS); 1571 - struct btrfs_fs_info *fs_info = kzalloc(sizeof(*fs_info), 1572 - GFP_NOFS); 1541 + struct btrfs_root *tree_root = btrfs_sb(sb); 1542 + struct btrfs_fs_info *fs_info = tree_root->fs_info; 1573 1543 struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root), 1574 1544 GFP_NOFS); 1575 1545 struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root),
+76
fs/btrfs/export.c
··· 232 232 return ERR_PTR(ret); 233 233 } 234 234 235 + static int btrfs_get_name(struct dentry *parent, char *name, 236 + struct dentry *child) 237 + { 238 + struct inode *inode = child->d_inode; 239 + struct inode *dir = parent->d_inode; 240 + struct btrfs_path *path; 241 + struct btrfs_root *root = BTRFS_I(dir)->root; 242 + struct btrfs_inode_ref *iref; 243 + struct btrfs_root_ref *rref; 244 + struct extent_buffer *leaf; 245 + unsigned long name_ptr; 246 + struct btrfs_key key; 247 + int name_len; 248 + int ret; 249 + 250 + if (!dir || !inode) 251 + return -EINVAL; 252 + 253 + if (!S_ISDIR(dir->i_mode)) 254 + return -EINVAL; 255 + 256 + path = btrfs_alloc_path(); 257 + if (!path) 258 + return -ENOMEM; 259 + path->leave_spinning = 1; 260 + 261 + if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) { 262 + key.objectid = BTRFS_I(inode)->root->root_key.objectid; 263 + key.type = BTRFS_ROOT_BACKREF_KEY; 264 + key.offset = (u64)-1; 265 + root = root->fs_info->tree_root; 266 + } else { 267 + key.objectid = inode->i_ino; 268 + key.offset = dir->i_ino; 269 + key.type = BTRFS_INODE_REF_KEY; 270 + } 271 + 272 + ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 273 + if (ret < 0) { 274 + btrfs_free_path(path); 275 + return ret; 276 + } else if (ret > 0) { 277 + if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) { 278 + path->slots[0]--; 279 + } else { 280 + btrfs_free_path(path); 281 + return -ENOENT; 282 + } 283 + } 284 + leaf = path->nodes[0]; 285 + 286 + if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) { 287 + rref = btrfs_item_ptr(leaf, path->slots[0], 288 + struct btrfs_root_ref); 289 + name_ptr = (unsigned long)(rref + 1); 290 + name_len = btrfs_root_ref_name_len(leaf, rref); 291 + } else { 292 + iref = btrfs_item_ptr(leaf, path->slots[0], 293 + struct btrfs_inode_ref); 294 + name_ptr = (unsigned long)(iref + 1); 295 + name_len = btrfs_inode_ref_name_len(leaf, iref); 296 + } 297 + 298 + read_extent_buffer(leaf, name, name_ptr, name_len); 299 + btrfs_free_path(path); 300 + 301 + /* 302 + * have to add the null termination to make sure that reconnect_path 303 + * gets the right len for strlen 304 + */ 305 + name[name_len] = '\0'; 306 + 307 + return 0; 308 + } 309 + 235 310 const struct export_operations btrfs_export_ops = { 236 311 .encode_fh = btrfs_encode_fh, 237 312 .fh_to_dentry = btrfs_fh_to_dentry, 238 313 .fh_to_parent = btrfs_fh_to_parent, 239 314 .get_parent = btrfs_get_parent, 315 + .get_name = btrfs_get_name, 240 316 };
+1 -1
fs/btrfs/extent-tree.c
··· 3412 3412 * our reservation. 3413 3413 */ 3414 3414 if (unused <= space_info->total_bytes) { 3415 - unused -= space_info->total_bytes; 3415 + unused = space_info->total_bytes - unused; 3416 3416 if (unused >= num_bytes) { 3417 3417 if (!reserved) 3418 3418 space_info->bytes_reserved += orig_bytes;
+62 -15
fs/btrfs/extent_io.c
··· 1828 1828 bio_put(bio); 1829 1829 } 1830 1830 1831 - static struct bio * 1832 - extent_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, 1833 - gfp_t gfp_flags) 1831 + struct bio * 1832 + btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, 1833 + gfp_t gfp_flags) 1834 1834 { 1835 1835 struct bio *bio; 1836 1836 ··· 1919 1919 else 1920 1920 nr = bio_get_nr_vecs(bdev); 1921 1921 1922 - bio = extent_bio_alloc(bdev, sector, nr, GFP_NOFS | __GFP_HIGH); 1922 + bio = btrfs_bio_alloc(bdev, sector, nr, GFP_NOFS | __GFP_HIGH); 1923 1923 1924 1924 bio_add_page(bio, page, page_size, offset); 1925 1925 bio->bi_end_io = end_io_func; ··· 2901 2901 int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2902 2902 __u64 start, __u64 len, get_extent_t *get_extent) 2903 2903 { 2904 - int ret; 2904 + int ret = 0; 2905 2905 u64 off = start; 2906 2906 u64 max = start + len; 2907 2907 u32 flags = 0; 2908 + u32 found_type; 2909 + u64 last; 2908 2910 u64 disko = 0; 2911 + struct btrfs_key found_key; 2909 2912 struct extent_map *em = NULL; 2910 2913 struct extent_state *cached_state = NULL; 2914 + struct btrfs_path *path; 2915 + struct btrfs_file_extent_item *item; 2911 2916 int end = 0; 2912 2917 u64 em_start = 0, em_len = 0; 2913 2918 unsigned long emflags; 2914 - ret = 0; 2919 + int hole = 0; 2915 2920 2916 2921 if (len == 0) 2917 2922 return -EINVAL; 2923 + 2924 + path = btrfs_alloc_path(); 2925 + if (!path) 2926 + return -ENOMEM; 2927 + path->leave_spinning = 1; 2928 + 2929 + ret = btrfs_lookup_file_extent(NULL, BTRFS_I(inode)->root, 2930 + path, inode->i_ino, -1, 0); 2931 + if (ret < 0) { 2932 + btrfs_free_path(path); 2933 + return ret; 2934 + } 2935 + WARN_ON(!ret); 2936 + path->slots[0]--; 2937 + item = btrfs_item_ptr(path->nodes[0], path->slots[0], 2938 + struct btrfs_file_extent_item); 2939 + btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]); 2940 + found_type = btrfs_key_type(&found_key); 2941 + 2942 + /* No extents, just return */ 2943 + if (found_key.objectid != inode->i_ino || 2944 + found_type != BTRFS_EXTENT_DATA_KEY) { 2945 + btrfs_free_path(path); 2946 + return 0; 2947 + } 2948 + last = found_key.offset; 2949 + btrfs_free_path(path); 2918 2950 2919 2951 lock_extent_bits(&BTRFS_I(inode)->io_tree, start, start + len, 0, 2920 2952 &cached_state, GFP_NOFS); ··· 2957 2925 ret = PTR_ERR(em); 2958 2926 goto out; 2959 2927 } 2928 + 2960 2929 while (!end) { 2930 + hole = 0; 2961 2931 off = em->start + em->len; 2962 2932 if (off >= max) 2963 2933 end = 1; 2934 + 2935 + if (em->block_start == EXTENT_MAP_HOLE) { 2936 + hole = 1; 2937 + goto next; 2938 + } 2964 2939 2965 2940 em_start = em->start; 2966 2941 em_len = em->len; ··· 2978 2939 if (em->block_start == EXTENT_MAP_LAST_BYTE) { 2979 2940 end = 1; 2980 2941 flags |= FIEMAP_EXTENT_LAST; 2981 - } else if (em->block_start == EXTENT_MAP_HOLE) { 2982 - flags |= FIEMAP_EXTENT_UNWRITTEN; 2983 2942 } else if (em->block_start == EXTENT_MAP_INLINE) { 2984 2943 flags |= (FIEMAP_EXTENT_DATA_INLINE | 2985 2944 FIEMAP_EXTENT_NOT_ALIGNED); ··· 2990 2953 if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags)) 2991 2954 flags |= FIEMAP_EXTENT_ENCODED; 2992 2955 2956 + next: 2993 2957 emflags = em->flags; 2994 2958 free_extent_map(em); 2995 2959 em = NULL; 2996 - 2997 2960 if (!end) { 2998 2961 em = get_extent(inode, NULL, 0, off, max - off, 0); 2999 2962 if (!em) ··· 3004 2967 } 3005 2968 emflags = em->flags; 3006 2969 } 2970 + 3007 2971 if (test_bit(EXTENT_FLAG_VACANCY, &emflags)) { 3008 2972 flags |= FIEMAP_EXTENT_LAST; 3009 2973 end = 1; 3010 2974 } 3011 2975 3012 - ret = fiemap_fill_next_extent(fieinfo, em_start, disko, 3013 - em_len, flags); 3014 - if (ret) 3015 - goto out_free; 2976 + if (em_start == last) { 2977 + flags |= FIEMAP_EXTENT_LAST; 2978 + end = 1; 2979 + } 2980 + 2981 + if (!hole) { 2982 + ret = fiemap_fill_next_extent(fieinfo, em_start, disko, 2983 + em_len, flags); 2984 + if (ret) 2985 + goto out_free; 2986 + } 3016 2987 } 3017 2988 out_free: 3018 2989 free_extent_map(em); ··· 3881 3836 3882 3837 spin_lock(&tree->buffer_lock); 3883 3838 eb = radix_tree_lookup(&tree->buffer, start >> PAGE_CACHE_SHIFT); 3884 - if (!eb) 3885 - goto out; 3839 + if (!eb) { 3840 + spin_unlock(&tree->buffer_lock); 3841 + return ret; 3842 + } 3886 3843 3887 3844 if (test_bit(EXTENT_BUFFER_DIRTY, &eb->bflags)) { 3888 3845 ret = 0;
+3
fs/btrfs/extent_io.h
··· 310 310 struct extent_io_tree *tree, 311 311 u64 start, u64 end, struct page *locked_page, 312 312 unsigned long op); 313 + struct bio * 314 + btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, 315 + gfp_t gfp_flags); 313 316 #endif
+7
fs/btrfs/file.c
··· 1047 1047 1048 1048 if ((file->f_flags & O_DSYNC) || IS_SYNC(inode)) { 1049 1049 trans = btrfs_start_transaction(root, 0); 1050 + if (IS_ERR(trans)) { 1051 + num_written = PTR_ERR(trans); 1052 + goto done; 1053 + } 1054 + mutex_lock(&inode->i_mutex); 1050 1055 ret = btrfs_log_dentry_safe(trans, root, 1051 1056 file->f_dentry); 1057 + mutex_unlock(&inode->i_mutex); 1052 1058 if (ret == 0) { 1053 1059 ret = btrfs_sync_log(trans, root); 1054 1060 if (ret == 0) ··· 1073 1067 (start_pos + num_written - 1) >> PAGE_CACHE_SHIFT); 1074 1068 } 1075 1069 } 1070 + done: 1076 1071 current->backing_dev_info = NULL; 1077 1072 return num_written ? num_written : err; 1078 1073 }
+237 -57
fs/btrfs/inode.c
··· 4501 4501 BTRFS_I(inode)->index_cnt = 2; 4502 4502 BTRFS_I(inode)->root = root; 4503 4503 BTRFS_I(inode)->generation = trans->transid; 4504 + inode->i_generation = BTRFS_I(inode)->generation; 4504 4505 btrfs_set_inode_space_info(root, inode); 4505 4506 4506 4507 if (mode & S_IFDIR) ··· 4623 4622 } 4624 4623 4625 4624 static int btrfs_add_nondir(struct btrfs_trans_handle *trans, 4626 - struct dentry *dentry, struct inode *inode, 4627 - int backref, u64 index) 4625 + struct inode *dir, struct dentry *dentry, 4626 + struct inode *inode, int backref, u64 index) 4628 4627 { 4629 - int err = btrfs_add_link(trans, dentry->d_parent->d_inode, 4630 - inode, dentry->d_name.name, 4631 - dentry->d_name.len, backref, index); 4628 + int err = btrfs_add_link(trans, dir, inode, 4629 + dentry->d_name.name, dentry->d_name.len, 4630 + backref, index); 4632 4631 if (!err) { 4633 4632 d_instantiate(dentry, inode); 4634 4633 return 0; ··· 4669 4668 btrfs_set_trans_block_group(trans, dir); 4670 4669 4671 4670 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 4672 - dentry->d_name.len, 4673 - dentry->d_parent->d_inode->i_ino, objectid, 4671 + dentry->d_name.len, dir->i_ino, objectid, 4674 4672 BTRFS_I(dir)->block_group, mode, &index); 4675 4673 err = PTR_ERR(inode); 4676 4674 if (IS_ERR(inode)) ··· 4682 4682 } 4683 4683 4684 4684 btrfs_set_trans_block_group(trans, inode); 4685 - err = btrfs_add_nondir(trans, dentry, inode, 0, index); 4685 + err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); 4686 4686 if (err) 4687 4687 drop_inode = 1; 4688 4688 else { ··· 4730 4730 btrfs_set_trans_block_group(trans, dir); 4731 4731 4732 4732 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 4733 - dentry->d_name.len, 4734 - dentry->d_parent->d_inode->i_ino, 4735 - objectid, BTRFS_I(dir)->block_group, mode, 4736 - &index); 4733 + dentry->d_name.len, dir->i_ino, objectid, 4734 + BTRFS_I(dir)->block_group, mode, &index); 4737 4735 err = PTR_ERR(inode); 4738 4736 if (IS_ERR(inode)) 4739 4737 goto out_unlock; ··· 4743 4745 } 4744 4746 4745 4747 btrfs_set_trans_block_group(trans, inode); 4746 - err = btrfs_add_nondir(trans, dentry, inode, 0, index); 4748 + err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); 4747 4749 if (err) 4748 4750 drop_inode = 1; 4749 4751 else { ··· 4785 4787 return -EPERM; 4786 4788 4787 4789 btrfs_inc_nlink(inode); 4790 + inode->i_ctime = CURRENT_TIME; 4788 4791 4789 4792 err = btrfs_set_inode_index(dir, &index); 4790 4793 if (err) ··· 4804 4805 btrfs_set_trans_block_group(trans, dir); 4805 4806 ihold(inode); 4806 4807 4807 - err = btrfs_add_nondir(trans, dentry, inode, 1, index); 4808 + err = btrfs_add_nondir(trans, dir, dentry, inode, 1, index); 4808 4809 4809 4810 if (err) { 4810 4811 drop_inode = 1; 4811 4812 } else { 4813 + struct dentry *parent = dget_parent(dentry); 4812 4814 btrfs_update_inode_block_group(trans, dir); 4813 4815 err = btrfs_update_inode(trans, root, inode); 4814 4816 BUG_ON(err); 4815 - btrfs_log_new_name(trans, inode, NULL, dentry->d_parent); 4817 + btrfs_log_new_name(trans, inode, NULL, parent); 4818 + dput(parent); 4816 4819 } 4817 4820 4818 4821 nr = trans->blocks_used; ··· 4854 4853 btrfs_set_trans_block_group(trans, dir); 4855 4854 4856 4855 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 4857 - dentry->d_name.len, 4858 - dentry->d_parent->d_inode->i_ino, objectid, 4856 + dentry->d_name.len, dir->i_ino, objectid, 4859 4857 BTRFS_I(dir)->block_group, S_IFDIR | mode, 4860 4858 &index); 4861 4859 if (IS_ERR(inode)) { ··· 4877 4877 if (err) 4878 4878 goto out_fail; 4879 4879 4880 - err = btrfs_add_link(trans, dentry->d_parent->d_inode, 4881 - inode, dentry->d_name.name, 4882 - dentry->d_name.len, 0, index); 4880 + err = btrfs_add_link(trans, dir, inode, dentry->d_name.name, 4881 + dentry->d_name.len, 0, index); 4883 4882 if (err) 4884 4883 goto out_fail; 4885 4884 ··· 5534 5535 u64 bytes; 5535 5536 u32 *csums; 5536 5537 void *private; 5538 + 5539 + /* number of bios pending for this dio */ 5540 + atomic_t pending_bios; 5541 + 5542 + /* IO errors */ 5543 + int errors; 5544 + 5545 + struct bio *orig_bio; 5537 5546 }; 5538 5547 5539 5548 static void btrfs_endio_direct_read(struct bio *bio, int err) 5540 5549 { 5550 + struct btrfs_dio_private *dip = bio->bi_private; 5541 5551 struct bio_vec *bvec_end = bio->bi_io_vec + bio->bi_vcnt - 1; 5542 5552 struct bio_vec *bvec = bio->bi_io_vec; 5543 - struct btrfs_dio_private *dip = bio->bi_private; 5544 5553 struct inode *inode = dip->inode; 5545 5554 struct btrfs_root *root = BTRFS_I(inode)->root; 5546 5555 u64 start; ··· 5602 5595 struct btrfs_trans_handle *trans; 5603 5596 struct btrfs_ordered_extent *ordered = NULL; 5604 5597 struct extent_state *cached_state = NULL; 5598 + u64 ordered_offset = dip->logical_offset; 5599 + u64 ordered_bytes = dip->bytes; 5605 5600 int ret; 5606 5601 5607 5602 if (err) 5608 5603 goto out_done; 5609 - 5610 - ret = btrfs_dec_test_ordered_pending(inode, &ordered, 5611 - dip->logical_offset, dip->bytes); 5604 + again: 5605 + ret = btrfs_dec_test_first_ordered_pending(inode, &ordered, 5606 + &ordered_offset, 5607 + ordered_bytes); 5612 5608 if (!ret) 5613 - goto out_done; 5609 + goto out_test; 5614 5610 5615 5611 BUG_ON(!ordered); 5616 5612 ··· 5673 5663 out: 5674 5664 btrfs_delalloc_release_metadata(inode, ordered->len); 5675 5665 btrfs_end_transaction(trans, root); 5666 + ordered_offset = ordered->file_offset + ordered->len; 5676 5667 btrfs_put_ordered_extent(ordered); 5677 5668 btrfs_put_ordered_extent(ordered); 5669 + 5670 + out_test: 5671 + /* 5672 + * our bio might span multiple ordered extents. If we haven't 5673 + * completed the accounting for the whole dio, go back and try again 5674 + */ 5675 + if (ordered_offset < dip->logical_offset + dip->bytes) { 5676 + ordered_bytes = dip->logical_offset + dip->bytes - 5677 + ordered_offset; 5678 + goto again; 5679 + } 5678 5680 out_done: 5679 5681 bio->bi_private = dip->private; 5680 5682 ··· 5703 5681 struct btrfs_root *root = BTRFS_I(inode)->root; 5704 5682 ret = btrfs_csum_one_bio(root, inode, bio, offset, 1); 5705 5683 BUG_ON(ret); 5684 + return 0; 5685 + } 5686 + 5687 + static void btrfs_end_dio_bio(struct bio *bio, int err) 5688 + { 5689 + struct btrfs_dio_private *dip = bio->bi_private; 5690 + 5691 + if (err) { 5692 + printk(KERN_ERR "btrfs direct IO failed ino %lu rw %lu " 5693 + "disk_bytenr %lu len %u err no %d\n", 5694 + dip->inode->i_ino, bio->bi_rw, bio->bi_sector, 5695 + bio->bi_size, err); 5696 + dip->errors = 1; 5697 + 5698 + /* 5699 + * before atomic variable goto zero, we must make sure 5700 + * dip->errors is perceived to be set. 5701 + */ 5702 + smp_mb__before_atomic_dec(); 5703 + } 5704 + 5705 + /* if there are more bios still pending for this dio, just exit */ 5706 + if (!atomic_dec_and_test(&dip->pending_bios)) 5707 + goto out; 5708 + 5709 + if (dip->errors) 5710 + bio_io_error(dip->orig_bio); 5711 + else { 5712 + set_bit(BIO_UPTODATE, &dip->orig_bio->bi_flags); 5713 + bio_endio(dip->orig_bio, 0); 5714 + } 5715 + out: 5716 + bio_put(bio); 5717 + } 5718 + 5719 + static struct bio *btrfs_dio_bio_alloc(struct block_device *bdev, 5720 + u64 first_sector, gfp_t gfp_flags) 5721 + { 5722 + int nr_vecs = bio_get_nr_vecs(bdev); 5723 + return btrfs_bio_alloc(bdev, first_sector, nr_vecs, gfp_flags); 5724 + } 5725 + 5726 + static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode, 5727 + int rw, u64 file_offset, int skip_sum, 5728 + u32 *csums) 5729 + { 5730 + int write = rw & REQ_WRITE; 5731 + struct btrfs_root *root = BTRFS_I(inode)->root; 5732 + int ret; 5733 + 5734 + bio_get(bio); 5735 + ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); 5736 + if (ret) 5737 + goto err; 5738 + 5739 + if (write && !skip_sum) { 5740 + ret = btrfs_wq_submit_bio(root->fs_info, 5741 + inode, rw, bio, 0, 0, 5742 + file_offset, 5743 + __btrfs_submit_bio_start_direct_io, 5744 + __btrfs_submit_bio_done); 5745 + goto err; 5746 + } else if (!skip_sum) 5747 + btrfs_lookup_bio_sums_dio(root, inode, bio, 5748 + file_offset, csums); 5749 + 5750 + ret = btrfs_map_bio(root, rw, bio, 0, 1); 5751 + err: 5752 + bio_put(bio); 5753 + return ret; 5754 + } 5755 + 5756 + static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip, 5757 + int skip_sum) 5758 + { 5759 + struct inode *inode = dip->inode; 5760 + struct btrfs_root *root = BTRFS_I(inode)->root; 5761 + struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree; 5762 + struct bio *bio; 5763 + struct bio *orig_bio = dip->orig_bio; 5764 + struct bio_vec *bvec = orig_bio->bi_io_vec; 5765 + u64 start_sector = orig_bio->bi_sector; 5766 + u64 file_offset = dip->logical_offset; 5767 + u64 submit_len = 0; 5768 + u64 map_length; 5769 + int nr_pages = 0; 5770 + u32 *csums = dip->csums; 5771 + int ret = 0; 5772 + 5773 + bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev, start_sector, GFP_NOFS); 5774 + if (!bio) 5775 + return -ENOMEM; 5776 + bio->bi_private = dip; 5777 + bio->bi_end_io = btrfs_end_dio_bio; 5778 + atomic_inc(&dip->pending_bios); 5779 + 5780 + map_length = orig_bio->bi_size; 5781 + ret = btrfs_map_block(map_tree, READ, start_sector << 9, 5782 + &map_length, NULL, 0); 5783 + if (ret) { 5784 + bio_put(bio); 5785 + return -EIO; 5786 + } 5787 + 5788 + while (bvec <= (orig_bio->bi_io_vec + orig_bio->bi_vcnt - 1)) { 5789 + if (unlikely(map_length < submit_len + bvec->bv_len || 5790 + bio_add_page(bio, bvec->bv_page, bvec->bv_len, 5791 + bvec->bv_offset) < bvec->bv_len)) { 5792 + /* 5793 + * inc the count before we submit the bio so 5794 + * we know the end IO handler won't happen before 5795 + * we inc the count. Otherwise, the dip might get freed 5796 + * before we're done setting it up 5797 + */ 5798 + atomic_inc(&dip->pending_bios); 5799 + ret = __btrfs_submit_dio_bio(bio, inode, rw, 5800 + file_offset, skip_sum, 5801 + csums); 5802 + if (ret) { 5803 + bio_put(bio); 5804 + atomic_dec(&dip->pending_bios); 5805 + goto out_err; 5806 + } 5807 + 5808 + if (!skip_sum) 5809 + csums = csums + nr_pages; 5810 + start_sector += submit_len >> 9; 5811 + file_offset += submit_len; 5812 + 5813 + submit_len = 0; 5814 + nr_pages = 0; 5815 + 5816 + bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev, 5817 + start_sector, GFP_NOFS); 5818 + if (!bio) 5819 + goto out_err; 5820 + bio->bi_private = dip; 5821 + bio->bi_end_io = btrfs_end_dio_bio; 5822 + 5823 + map_length = orig_bio->bi_size; 5824 + ret = btrfs_map_block(map_tree, READ, start_sector << 9, 5825 + &map_length, NULL, 0); 5826 + if (ret) { 5827 + bio_put(bio); 5828 + goto out_err; 5829 + } 5830 + } else { 5831 + submit_len += bvec->bv_len; 5832 + nr_pages ++; 5833 + bvec++; 5834 + } 5835 + } 5836 + 5837 + ret = __btrfs_submit_dio_bio(bio, inode, rw, file_offset, skip_sum, 5838 + csums); 5839 + if (!ret) 5840 + return 0; 5841 + 5842 + bio_put(bio); 5843 + out_err: 5844 + dip->errors = 1; 5845 + /* 5846 + * before atomic variable goto zero, we must 5847 + * make sure dip->errors is perceived to be set. 5848 + */ 5849 + smp_mb__before_atomic_dec(); 5850 + if (atomic_dec_and_test(&dip->pending_bios)) 5851 + bio_io_error(dip->orig_bio); 5852 + 5853 + /* bio_end_io() will handle error, so we needn't return it */ 5706 5854 return 0; 5707 5855 } 5708 5856 ··· 5915 5723 5916 5724 dip->disk_bytenr = (u64)bio->bi_sector << 9; 5917 5725 bio->bi_private = dip; 5726 + dip->errors = 0; 5727 + dip->orig_bio = bio; 5728 + atomic_set(&dip->pending_bios, 0); 5918 5729 5919 5730 if (write) 5920 5731 bio->bi_end_io = btrfs_endio_direct_write; 5921 5732 else 5922 5733 bio->bi_end_io = btrfs_endio_direct_read; 5923 5734 5924 - ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); 5925 - if (ret) 5926 - goto out_err; 5927 - 5928 - if (write && !skip_sum) { 5929 - ret = btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info, 5930 - inode, rw, bio, 0, 0, 5931 - dip->logical_offset, 5932 - __btrfs_submit_bio_start_direct_io, 5933 - __btrfs_submit_bio_done); 5934 - if (ret) 5935 - goto out_err; 5735 + ret = btrfs_submit_direct_hook(rw, dip, skip_sum); 5736 + if (!ret) 5936 5737 return; 5937 - } else if (!skip_sum) 5938 - btrfs_lookup_bio_sums_dio(root, inode, bio, 5939 - dip->logical_offset, dip->csums); 5940 - 5941 - ret = btrfs_map_bio(root, rw, bio, 0, 1); 5942 - if (ret) 5943 - goto out_err; 5944 - return; 5945 - out_err: 5946 - kfree(dip->csums); 5947 - kfree(dip); 5948 5738 free_ordered: 5949 5739 /* 5950 5740 * If this is a write, we need to clean up the reserved space and kill ··· 6781 6607 BUG_ON(ret); 6782 6608 6783 6609 if (old_inode->i_ino != BTRFS_FIRST_FREE_OBJECTID) { 6784 - btrfs_log_new_name(trans, old_inode, old_dir, 6785 - new_dentry->d_parent); 6610 + struct dentry *parent = dget_parent(new_dentry); 6611 + btrfs_log_new_name(trans, old_inode, old_dir, parent); 6612 + dput(parent); 6786 6613 btrfs_end_log_trans(root); 6787 6614 } 6788 6615 out_fail: ··· 6933 6758 btrfs_set_trans_block_group(trans, dir); 6934 6759 6935 6760 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 6936 - dentry->d_name.len, 6937 - dentry->d_parent->d_inode->i_ino, objectid, 6761 + dentry->d_name.len, dir->i_ino, objectid, 6938 6762 BTRFS_I(dir)->block_group, S_IFLNK|S_IRWXUGO, 6939 6763 &index); 6940 6764 err = PTR_ERR(inode); ··· 6947 6773 } 6948 6774 6949 6775 btrfs_set_trans_block_group(trans, inode); 6950 - err = btrfs_add_nondir(trans, dentry, inode, 0, index); 6776 + err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); 6951 6777 if (err) 6952 6778 drop_inode = 1; 6953 6779 else { ··· 7018 6844 struct btrfs_root *root = BTRFS_I(inode)->root; 7019 6845 struct btrfs_key ins; 7020 6846 u64 cur_offset = start; 6847 + u64 i_size; 7021 6848 int ret = 0; 7022 6849 bool own_trans = true; 7023 6850 ··· 7060 6885 (actual_len > inode->i_size) && 7061 6886 (cur_offset > inode->i_size)) { 7062 6887 if (cur_offset > actual_len) 7063 - i_size_write(inode, actual_len); 6888 + i_size = actual_len; 7064 6889 else 7065 - i_size_write(inode, cur_offset); 7066 - i_size_write(inode, cur_offset); 7067 - btrfs_ordered_update_i_size(inode, cur_offset, NULL); 6890 + i_size = cur_offset; 6891 + i_size_write(inode, i_size); 6892 + btrfs_ordered_update_i_size(inode, i_size, NULL); 7068 6893 } 7069 6894 7070 6895 ret = btrfs_update_inode(trans, root, inode); ··· 7118 6943 btrfs_wait_ordered_range(inode, alloc_start, alloc_end - alloc_start); 7119 6944 7120 6945 mutex_lock(&inode->i_mutex); 6946 + ret = inode_newsize_ok(inode, alloc_end); 6947 + if (ret) 6948 + goto out; 6949 + 7121 6950 if (alloc_start > inode->i_size) { 7122 6951 ret = btrfs_cont_expand(inode, alloc_start); 7123 6952 if (ret) ··· 7318 7139 .readlink = generic_readlink, 7319 7140 .follow_link = page_follow_link_light, 7320 7141 .put_link = page_put_link, 7142 + .getattr = btrfs_getattr, 7321 7143 .permission = btrfs_permission, 7322 7144 .setxattr = btrfs_setxattr, 7323 7145 .getxattr = btrfs_getxattr,
+21 -10
fs/btrfs/ioctl.c
··· 233 233 struct btrfs_inode_item *inode_item; 234 234 struct extent_buffer *leaf; 235 235 struct btrfs_root *new_root; 236 - struct inode *dir = dentry->d_parent->d_inode; 236 + struct dentry *parent = dget_parent(dentry); 237 + struct inode *dir; 237 238 int ret; 238 239 int err; 239 240 u64 objectid; ··· 243 242 244 243 ret = btrfs_find_free_objectid(NULL, root->fs_info->tree_root, 245 244 0, &objectid); 246 - if (ret) 245 + if (ret) { 246 + dput(parent); 247 247 return ret; 248 + } 249 + 250 + dir = parent->d_inode; 251 + 248 252 /* 249 253 * 1 - inode item 250 254 * 2 - refs ··· 257 251 * 2 - dir items 258 252 */ 259 253 trans = btrfs_start_transaction(root, 6); 260 - if (IS_ERR(trans)) 254 + if (IS_ERR(trans)) { 255 + dput(parent); 261 256 return PTR_ERR(trans); 257 + } 262 258 263 259 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 264 260 0, objectid, NULL, 0, 0, 0); ··· 347 339 348 340 d_instantiate(dentry, btrfs_lookup_dentry(dir, dentry)); 349 341 fail: 342 + dput(parent); 350 343 if (async_transid) { 351 344 *async_transid = trans->transid; 352 345 err = btrfs_commit_transaction_async(trans, root, 1); ··· 363 354 char *name, int namelen, u64 *async_transid) 364 355 { 365 356 struct inode *inode; 357 + struct dentry *parent; 366 358 struct btrfs_pending_snapshot *pending_snapshot; 367 359 struct btrfs_trans_handle *trans; 368 360 int ret; ··· 406 396 407 397 btrfs_orphan_cleanup(pending_snapshot->snap); 408 398 409 - inode = btrfs_lookup_dentry(dentry->d_parent->d_inode, dentry); 399 + parent = dget_parent(dentry); 400 + inode = btrfs_lookup_dentry(parent->d_inode, dentry); 401 + dput(parent); 410 402 if (IS_ERR(inode)) { 411 403 ret = PTR_ERR(inode); 412 404 goto fail; ··· 1681 1669 olen = len = src->i_size - off; 1682 1670 /* if we extend to eof, continue to block boundary */ 1683 1671 if (off + len == src->i_size) 1684 - len = ((src->i_size + bs-1) & ~(bs-1)) 1685 - - off; 1672 + len = ALIGN(src->i_size, bs) - off; 1686 1673 1687 1674 /* verify the end result is block aligned */ 1688 - if ((off & (bs-1)) || 1689 - ((off + len) & (bs-1))) 1675 + if (!IS_ALIGNED(off, bs) || !IS_ALIGNED(off + len, bs) || 1676 + !IS_ALIGNED(destoff, bs)) 1690 1677 goto out_unlock; 1691 1678 1692 1679 /* do any pending delalloc/csum calc on src, one way or ··· 1885 1874 * but shouldn't round up the file size 1886 1875 */ 1887 1876 endoff = new_key.offset + datal; 1888 - if (endoff > off+olen) 1889 - endoff = off+olen; 1877 + if (endoff > destoff+olen) 1878 + endoff = destoff+olen; 1890 1879 if (endoff > inode->i_size) 1891 1880 btrfs_i_size_write(inode, endoff); 1892 1881
+67
fs/btrfs/ordered-data.c
··· 250 250 251 251 /* 252 252 * this is used to account for finished IO across a given range 253 + * of the file. The IO may span ordered extents. If 254 + * a given ordered_extent is completely done, 1 is returned, otherwise 255 + * 0. 256 + * 257 + * test_and_set_bit on a flag in the struct btrfs_ordered_extent is used 258 + * to make sure this function only returns 1 once for a given ordered extent. 259 + * 260 + * file_offset is updated to one byte past the range that is recorded as 261 + * complete. This allows you to walk forward in the file. 262 + */ 263 + int btrfs_dec_test_first_ordered_pending(struct inode *inode, 264 + struct btrfs_ordered_extent **cached, 265 + u64 *file_offset, u64 io_size) 266 + { 267 + struct btrfs_ordered_inode_tree *tree; 268 + struct rb_node *node; 269 + struct btrfs_ordered_extent *entry = NULL; 270 + int ret; 271 + u64 dec_end; 272 + u64 dec_start; 273 + u64 to_dec; 274 + 275 + tree = &BTRFS_I(inode)->ordered_tree; 276 + spin_lock(&tree->lock); 277 + node = tree_search(tree, *file_offset); 278 + if (!node) { 279 + ret = 1; 280 + goto out; 281 + } 282 + 283 + entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); 284 + if (!offset_in_entry(entry, *file_offset)) { 285 + ret = 1; 286 + goto out; 287 + } 288 + 289 + dec_start = max(*file_offset, entry->file_offset); 290 + dec_end = min(*file_offset + io_size, entry->file_offset + 291 + entry->len); 292 + *file_offset = dec_end; 293 + if (dec_start > dec_end) { 294 + printk(KERN_CRIT "bad ordering dec_start %llu end %llu\n", 295 + (unsigned long long)dec_start, 296 + (unsigned long long)dec_end); 297 + } 298 + to_dec = dec_end - dec_start; 299 + if (to_dec > entry->bytes_left) { 300 + printk(KERN_CRIT "bad ordered accounting left %llu size %llu\n", 301 + (unsigned long long)entry->bytes_left, 302 + (unsigned long long)to_dec); 303 + } 304 + entry->bytes_left -= to_dec; 305 + if (entry->bytes_left == 0) 306 + ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags); 307 + else 308 + ret = 1; 309 + out: 310 + if (!ret && cached && entry) { 311 + *cached = entry; 312 + atomic_inc(&entry->refs); 313 + } 314 + spin_unlock(&tree->lock); 315 + return ret == 0; 316 + } 317 + 318 + /* 319 + * this is used to account for finished IO across a given range 253 320 * of the file. The IO should not span ordered extents. If 254 321 * a given ordered_extent is completely done, 1 is returned, otherwise 255 322 * 0.
+3
fs/btrfs/ordered-data.h
··· 141 141 int btrfs_dec_test_ordered_pending(struct inode *inode, 142 142 struct btrfs_ordered_extent **cached, 143 143 u64 file_offset, u64 io_size); 144 + int btrfs_dec_test_first_ordered_pending(struct inode *inode, 145 + struct btrfs_ordered_extent **cached, 146 + u64 *file_offset, u64 io_size); 144 147 int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, 145 148 u64 start, u64 len, u64 disk_len, int type); 146 149 int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset,
+38 -3
fs/btrfs/super.c
··· 244 244 case Opt_space_cache: 245 245 printk(KERN_INFO "btrfs: enabling disk space caching\n"); 246 246 btrfs_set_opt(info->mount_opt, SPACE_CACHE); 247 + break; 247 248 case Opt_clear_cache: 248 249 printk(KERN_INFO "btrfs: force clearing of disk cache\n"); 249 250 btrfs_set_opt(info->mount_opt, CLEAR_CACHE); ··· 563 562 564 563 static int btrfs_test_super(struct super_block *s, void *data) 565 564 { 566 - struct btrfs_fs_devices *test_fs_devices = data; 565 + struct btrfs_root *test_root = data; 567 566 struct btrfs_root *root = btrfs_sb(s); 568 567 569 - return root->fs_info->fs_devices == test_fs_devices; 568 + /* 569 + * If this super block is going away, return false as it 570 + * can't match as an existing super block. 571 + */ 572 + if (!atomic_read(&s->s_active)) 573 + return 0; 574 + return root->fs_info->fs_devices == test_root->fs_info->fs_devices; 570 575 } 576 + 577 + static int btrfs_set_super(struct super_block *s, void *data) 578 + { 579 + s->s_fs_info = data; 580 + 581 + return set_anon_super(s, data); 582 + } 583 + 571 584 572 585 /* 573 586 * Find a superblock for the given device / mount point. ··· 596 581 struct super_block *s; 597 582 struct dentry *root; 598 583 struct btrfs_fs_devices *fs_devices = NULL; 584 + struct btrfs_root *tree_root = NULL; 585 + struct btrfs_fs_info *fs_info = NULL; 599 586 fmode_t mode = FMODE_READ; 600 587 char *subvol_name = NULL; 601 588 u64 subvol_objectid = 0; ··· 625 608 goto error_close_devices; 626 609 } 627 610 611 + /* 612 + * Setup a dummy root and fs_info for test/set super. This is because 613 + * we don't actually fill this stuff out until open_ctree, but we need 614 + * it for searching for existing supers, so this lets us do that and 615 + * then open_ctree will properly initialize everything later. 616 + */ 617 + fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_NOFS); 618 + tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 619 + if (!fs_info || !tree_root) { 620 + error = -ENOMEM; 621 + goto error_close_devices; 622 + } 623 + fs_info->tree_root = tree_root; 624 + fs_info->fs_devices = fs_devices; 625 + tree_root->fs_info = fs_info; 626 + 628 627 bdev = fs_devices->latest_bdev; 629 - s = sget(fs_type, btrfs_test_super, set_anon_super, fs_devices); 628 + s = sget(fs_type, btrfs_test_super, btrfs_set_super, tree_root); 630 629 if (IS_ERR(s)) 631 630 goto error_s; 632 631 ··· 708 675 error = PTR_ERR(s); 709 676 error_close_devices: 710 677 btrfs_close_devices(fs_devices); 678 + kfree(fs_info); 679 + kfree(tree_root); 711 680 error_free_subvol_name: 712 681 kfree(subvol_name); 713 682 return ERR_PTR(error);
+4 -1
fs/btrfs/transaction.c
··· 902 902 struct btrfs_root *root = pending->root; 903 903 struct btrfs_root *parent_root; 904 904 struct inode *parent_inode; 905 + struct dentry *parent; 905 906 struct dentry *dentry; 906 907 struct extent_buffer *tmp; 907 908 struct extent_buffer *old; ··· 942 941 trans->block_rsv = &pending->block_rsv; 943 942 944 943 dentry = pending->dentry; 945 - parent_inode = dentry->d_parent->d_inode; 944 + parent = dget_parent(dentry); 945 + parent_inode = parent->d_inode; 946 946 parent_root = BTRFS_I(parent_inode)->root; 947 947 record_root_in_trans(trans, parent_root); 948 948 ··· 991 989 parent_inode->i_ino, index, 992 990 dentry->d_name.name, dentry->d_name.len); 993 991 BUG_ON(ret); 992 + dput(parent); 994 993 995 994 key.offset = (u64)-1; 996 995 pending->snap = btrfs_read_fs_root_no_name(root->fs_info, &key);
+17 -4
fs/btrfs/tree-log.c
··· 2869 2869 { 2870 2870 int ret = 0; 2871 2871 struct btrfs_root *root; 2872 + struct dentry *old_parent = NULL; 2872 2873 2873 2874 /* 2874 2875 * for regular files, if its inode is already on disk, we don't ··· 2911 2910 if (IS_ROOT(parent)) 2912 2911 break; 2913 2912 2914 - parent = parent->d_parent; 2913 + parent = dget_parent(parent); 2914 + dput(old_parent); 2915 + old_parent = parent; 2915 2916 inode = parent->d_inode; 2916 2917 2917 2918 } 2919 + dput(old_parent); 2918 2920 out: 2919 2921 return ret; 2920 2922 } ··· 2949 2945 { 2950 2946 int inode_only = exists_only ? LOG_INODE_EXISTS : LOG_INODE_ALL; 2951 2947 struct super_block *sb; 2948 + struct dentry *old_parent = NULL; 2952 2949 int ret = 0; 2953 2950 u64 last_committed = root->fs_info->last_trans_committed; 2954 2951 ··· 3021 3016 if (IS_ROOT(parent)) 3022 3017 break; 3023 3018 3024 - parent = parent->d_parent; 3019 + parent = dget_parent(parent); 3020 + dput(old_parent); 3021 + old_parent = parent; 3025 3022 } 3026 3023 ret = 0; 3027 3024 end_trans: 3025 + dput(old_parent); 3028 3026 if (ret < 0) { 3029 3027 BUG_ON(ret != -ENOSPC); 3030 3028 root->fs_info->last_trans_log_full_commit = trans->transid; ··· 3047 3039 int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans, 3048 3040 struct btrfs_root *root, struct dentry *dentry) 3049 3041 { 3050 - return btrfs_log_inode_parent(trans, root, dentry->d_inode, 3051 - dentry->d_parent, 0); 3042 + struct dentry *parent = dget_parent(dentry); 3043 + int ret; 3044 + 3045 + ret = btrfs_log_inode_parent(trans, root, dentry->d_inode, parent, 0); 3046 + dput(parent); 3047 + 3048 + return ret; 3052 3049 } 3053 3050 3054 3051 /*