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 tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4

Pull ext4 bugfixes from Ted Ts'o:
"These changes contains a fix for overlayfs interacting with some
(badly behaved) dentry code in various file systems. These have been
reviewed by Al and the respective file system mtinainers and are going
through the ext4 tree for convenience.

This also has a few ext4 encryption bug fixes that were discovered in
Android testing (yes, we will need to get these sync'ed up with the
fs/crypto code; I'll take care of that). It also has some bug fixes
and a change to ignore the legacy quota options to allow for xfstests
regression testing of ext4's internal quota feature and to be more
consistent with how xfs handles this case"

* tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4:
ext4: ignore quota mount options if the quota feature is enabled
ext4 crypto: fix some error handling
ext4: avoid calling dquot_get_next_id() if quota is not enabled
ext4: retry block allocation for failed DIO and DAX writes
ext4: add lockdep annotations for i_data_sem
ext4: allow readdir()'s of large empty directories to be interrupted
btrfs: fix crash/invalid memory access on fsync when using overlayfs
ext4 crypto: use dget_parent() in ext4_d_revalidate()
ext4: use file_dentry()
ext4: use dget_parent() in ext4_file_open()
nfs: use file_dentry()
fs: add file_dentry()
ext4 crypto: don't let data integrity writebacks fail with ENOMEM
ext4: check if in-inode xattr is corrupted in ext4_expand_extra_isize_ea()

+264 -86
+1 -1
fs/btrfs/file.c
··· 1905 1905 */ 1906 1906 int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) 1907 1907 { 1908 - struct dentry *dentry = file->f_path.dentry; 1908 + struct dentry *dentry = file_dentry(file); 1909 1909 struct inode *inode = d_inode(dentry); 1910 1910 struct btrfs_root *root = BTRFS_I(inode)->root; 1911 1911 struct btrfs_trans_handle *trans;
+4 -1
fs/dcache.c
··· 1667 1667 DCACHE_OP_REVALIDATE | 1668 1668 DCACHE_OP_WEAK_REVALIDATE | 1669 1669 DCACHE_OP_DELETE | 1670 - DCACHE_OP_SELECT_INODE)); 1670 + DCACHE_OP_SELECT_INODE | 1671 + DCACHE_OP_REAL)); 1671 1672 dentry->d_op = op; 1672 1673 if (!op) 1673 1674 return; ··· 1686 1685 dentry->d_flags |= DCACHE_OP_PRUNE; 1687 1686 if (op->d_select_inode) 1688 1687 dentry->d_flags |= DCACHE_OP_SELECT_INODE; 1688 + if (op->d_real) 1689 + dentry->d_flags |= DCACHE_OP_REAL; 1689 1690 1690 1691 } 1691 1692 EXPORT_SYMBOL(d_set_d_op);
+29 -20
fs/ext4/crypto.c
··· 91 91 * Return: An allocated and initialized encryption context on success; error 92 92 * value or NULL otherwise. 93 93 */ 94 - struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode) 94 + struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode, 95 + gfp_t gfp_flags) 95 96 { 96 97 struct ext4_crypto_ctx *ctx = NULL; 97 98 int res = 0; ··· 119 118 list_del(&ctx->free_list); 120 119 spin_unlock_irqrestore(&ext4_crypto_ctx_lock, flags); 121 120 if (!ctx) { 122 - ctx = kmem_cache_zalloc(ext4_crypto_ctx_cachep, GFP_NOFS); 121 + ctx = kmem_cache_zalloc(ext4_crypto_ctx_cachep, gfp_flags); 123 122 if (!ctx) { 124 123 res = -ENOMEM; 125 124 goto out; ··· 256 255 ext4_direction_t rw, 257 256 pgoff_t index, 258 257 struct page *src_page, 259 - struct page *dest_page) 258 + struct page *dest_page, 259 + gfp_t gfp_flags) 260 260 261 261 { 262 262 u8 xts_tweak[EXT4_XTS_TWEAK_SIZE]; ··· 268 266 struct crypto_skcipher *tfm = ci->ci_ctfm; 269 267 int res = 0; 270 268 271 - req = skcipher_request_alloc(tfm, GFP_NOFS); 269 + req = skcipher_request_alloc(tfm, gfp_flags); 272 270 if (!req) { 273 271 printk_ratelimited(KERN_ERR 274 272 "%s: crypto_request_alloc() failed\n", ··· 309 307 return 0; 310 308 } 311 309 312 - static struct page *alloc_bounce_page(struct ext4_crypto_ctx *ctx) 310 + static struct page *alloc_bounce_page(struct ext4_crypto_ctx *ctx, 311 + gfp_t gfp_flags) 313 312 { 314 - ctx->w.bounce_page = mempool_alloc(ext4_bounce_page_pool, GFP_NOWAIT); 313 + ctx->w.bounce_page = mempool_alloc(ext4_bounce_page_pool, gfp_flags); 315 314 if (ctx->w.bounce_page == NULL) 316 315 return ERR_PTR(-ENOMEM); 317 316 ctx->flags |= EXT4_WRITE_PATH_FL; ··· 335 332 * error value or NULL. 336 333 */ 337 334 struct page *ext4_encrypt(struct inode *inode, 338 - struct page *plaintext_page) 335 + struct page *plaintext_page, 336 + gfp_t gfp_flags) 339 337 { 340 338 struct ext4_crypto_ctx *ctx; 341 339 struct page *ciphertext_page = NULL; ··· 344 340 345 341 BUG_ON(!PageLocked(plaintext_page)); 346 342 347 - ctx = ext4_get_crypto_ctx(inode); 343 + ctx = ext4_get_crypto_ctx(inode, gfp_flags); 348 344 if (IS_ERR(ctx)) 349 345 return (struct page *) ctx; 350 346 351 347 /* The encryption operation will require a bounce page. */ 352 - ciphertext_page = alloc_bounce_page(ctx); 348 + ciphertext_page = alloc_bounce_page(ctx, gfp_flags); 353 349 if (IS_ERR(ciphertext_page)) 354 350 goto errout; 355 351 ctx->w.control_page = plaintext_page; 356 352 err = ext4_page_crypto(inode, EXT4_ENCRYPT, plaintext_page->index, 357 - plaintext_page, ciphertext_page); 353 + plaintext_page, ciphertext_page, gfp_flags); 358 354 if (err) { 359 355 ciphertext_page = ERR_PTR(err); 360 356 errout: ··· 382 378 { 383 379 BUG_ON(!PageLocked(page)); 384 380 385 - return ext4_page_crypto(page->mapping->host, 386 - EXT4_DECRYPT, page->index, page, page); 381 + return ext4_page_crypto(page->mapping->host, EXT4_DECRYPT, 382 + page->index, page, page, GFP_NOFS); 387 383 } 388 384 389 385 int ext4_encrypted_zeroout(struct inode *inode, ext4_lblk_t lblk, ··· 402 398 403 399 BUG_ON(inode->i_sb->s_blocksize != PAGE_SIZE); 404 400 405 - ctx = ext4_get_crypto_ctx(inode); 401 + ctx = ext4_get_crypto_ctx(inode, GFP_NOFS); 406 402 if (IS_ERR(ctx)) 407 403 return PTR_ERR(ctx); 408 404 409 - ciphertext_page = alloc_bounce_page(ctx); 405 + ciphertext_page = alloc_bounce_page(ctx, GFP_NOWAIT); 410 406 if (IS_ERR(ciphertext_page)) { 411 407 err = PTR_ERR(ciphertext_page); 412 408 goto errout; ··· 414 410 415 411 while (len--) { 416 412 err = ext4_page_crypto(inode, EXT4_ENCRYPT, lblk, 417 - ZERO_PAGE(0), ciphertext_page); 413 + ZERO_PAGE(0), ciphertext_page, 414 + GFP_NOFS); 418 415 if (err) 419 416 goto errout; 420 417 421 - bio = bio_alloc(GFP_KERNEL, 1); 418 + bio = bio_alloc(GFP_NOWAIT, 1); 422 419 if (!bio) { 423 420 err = -ENOMEM; 424 421 goto errout; ··· 478 473 */ 479 474 static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags) 480 475 { 481 - struct inode *dir = d_inode(dentry->d_parent); 482 - struct ext4_crypt_info *ci = EXT4_I(dir)->i_crypt_info; 476 + struct dentry *dir; 477 + struct ext4_crypt_info *ci; 483 478 int dir_has_key, cached_with_key; 484 479 485 - if (!ext4_encrypted_inode(dir)) 480 + dir = dget_parent(dentry); 481 + if (!ext4_encrypted_inode(d_inode(dir))) { 482 + dput(dir); 486 483 return 0; 487 - 484 + } 485 + ci = EXT4_I(d_inode(dir))->i_crypt_info; 488 486 if (ci && ci->ci_keyring_key && 489 487 (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | 490 488 (1 << KEY_FLAG_REVOKED) | ··· 497 489 /* this should eventually be an flag in d_flags */ 498 490 cached_with_key = dentry->d_fsdata != NULL; 499 491 dir_has_key = (ci != NULL); 492 + dput(dir); 500 493 501 494 /* 502 495 * If the dentry was cached without the key, and it is a
+5
fs/ext4/dir.c
··· 150 150 while (ctx->pos < inode->i_size) { 151 151 struct ext4_map_blocks map; 152 152 153 + if (fatal_signal_pending(current)) { 154 + err = -ERESTARTSYS; 155 + goto errout; 156 + } 157 + cond_resched(); 153 158 map.m_lblk = ctx->pos >> EXT4_BLOCK_SIZE_BITS(sb); 154 159 map.m_len = 1; 155 160 err = ext4_map_blocks(NULL, inode, &map, 0);
+27 -2
fs/ext4/ext4.h
··· 912 912 #include "extents_status.h" 913 913 914 914 /* 915 + * Lock subclasses for i_data_sem in the ext4_inode_info structure. 916 + * 917 + * These are needed to avoid lockdep false positives when we need to 918 + * allocate blocks to the quota inode during ext4_map_blocks(), while 919 + * holding i_data_sem for a normal (non-quota) inode. Since we don't 920 + * do quota tracking for the quota inode, this avoids deadlock (as 921 + * well as infinite recursion, since it isn't turtles all the way 922 + * down...) 923 + * 924 + * I_DATA_SEM_NORMAL - Used for most inodes 925 + * I_DATA_SEM_OTHER - Used by move_inode.c for the second normal inode 926 + * where the second inode has larger inode number 927 + * than the first 928 + * I_DATA_SEM_QUOTA - Used for quota inodes only 929 + */ 930 + enum { 931 + I_DATA_SEM_NORMAL = 0, 932 + I_DATA_SEM_OTHER, 933 + I_DATA_SEM_QUOTA, 934 + }; 935 + 936 + 937 + /* 915 938 * fourth extended file system inode data in memory 916 939 */ 917 940 struct ext4_inode_info { ··· 2305 2282 bool ext4_valid_contents_enc_mode(uint32_t mode); 2306 2283 uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size); 2307 2284 extern struct workqueue_struct *ext4_read_workqueue; 2308 - struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode); 2285 + struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode, 2286 + gfp_t gfp_flags); 2309 2287 void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx); 2310 2288 void ext4_restore_control_page(struct page *data_page); 2311 2289 struct page *ext4_encrypt(struct inode *inode, 2312 - struct page *plaintext_page); 2290 + struct page *plaintext_page, 2291 + gfp_t gfp_flags); 2313 2292 int ext4_decrypt(struct page *page); 2314 2293 int ext4_encrypted_zeroout(struct inode *inode, ext4_lblk_t lblk, 2315 2294 ext4_fsblk_t pblk, ext4_lblk_t len);
+8 -4
fs/ext4/file.c
··· 329 329 struct super_block *sb = inode->i_sb; 330 330 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 331 331 struct vfsmount *mnt = filp->f_path.mnt; 332 - struct inode *dir = filp->f_path.dentry->d_parent->d_inode; 332 + struct dentry *dir; 333 333 struct path path; 334 334 char buf[64], *cp; 335 335 int ret; ··· 373 373 if (ext4_encryption_info(inode) == NULL) 374 374 return -ENOKEY; 375 375 } 376 - if (ext4_encrypted_inode(dir) && 377 - !ext4_is_child_context_consistent_with_parent(dir, inode)) { 376 + 377 + dir = dget_parent(file_dentry(filp)); 378 + if (ext4_encrypted_inode(d_inode(dir)) && 379 + !ext4_is_child_context_consistent_with_parent(d_inode(dir), inode)) { 378 380 ext4_warning(inode->i_sb, 379 381 "Inconsistent encryption contexts: %lu/%lu\n", 380 - (unsigned long) dir->i_ino, 382 + (unsigned long) d_inode(dir)->i_ino, 381 383 (unsigned long) inode->i_ino); 384 + dput(dir); 382 385 return -EPERM; 383 386 } 387 + dput(dir); 384 388 /* 385 389 * Set up the jbd2_inode if we are opening the inode for 386 390 * writing and the journal is present
+28 -30
fs/ext4/inode.c
··· 763 763 /* Maximum number of blocks we map for direct IO at once. */ 764 764 #define DIO_MAX_BLOCKS 4096 765 765 766 - static handle_t *start_dio_trans(struct inode *inode, 767 - struct buffer_head *bh_result) 766 + /* 767 + * Get blocks function for the cases that need to start a transaction - 768 + * generally difference cases of direct IO and DAX IO. It also handles retries 769 + * in case of ENOSPC. 770 + */ 771 + static int ext4_get_block_trans(struct inode *inode, sector_t iblock, 772 + struct buffer_head *bh_result, int flags) 768 773 { 769 774 int dio_credits; 775 + handle_t *handle; 776 + int retries = 0; 777 + int ret; 770 778 771 779 /* Trim mapping request to maximum we can map at once for DIO */ 772 780 if (bh_result->b_size >> inode->i_blkbits > DIO_MAX_BLOCKS) 773 781 bh_result->b_size = DIO_MAX_BLOCKS << inode->i_blkbits; 774 782 dio_credits = ext4_chunk_trans_blocks(inode, 775 783 bh_result->b_size >> inode->i_blkbits); 776 - return ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, dio_credits); 784 + retry: 785 + handle = ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, dio_credits); 786 + if (IS_ERR(handle)) 787 + return PTR_ERR(handle); 788 + 789 + ret = _ext4_get_block(inode, iblock, bh_result, flags); 790 + ext4_journal_stop(handle); 791 + 792 + if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) 793 + goto retry; 794 + return ret; 777 795 } 778 796 779 797 /* Get block function for DIO reads and writes to inodes without extents */ 780 798 int ext4_dio_get_block(struct inode *inode, sector_t iblock, 781 799 struct buffer_head *bh, int create) 782 800 { 783 - handle_t *handle; 784 - int ret; 785 - 786 801 /* We don't expect handle for direct IO */ 787 802 WARN_ON_ONCE(ext4_journal_current_handle()); 788 803 789 - if (create) { 790 - handle = start_dio_trans(inode, bh); 791 - if (IS_ERR(handle)) 792 - return PTR_ERR(handle); 793 - } 794 - ret = _ext4_get_block(inode, iblock, bh, 795 - create ? EXT4_GET_BLOCKS_CREATE : 0); 796 - if (create) 797 - ext4_journal_stop(handle); 798 - return ret; 804 + if (!create) 805 + return _ext4_get_block(inode, iblock, bh, 0); 806 + return ext4_get_block_trans(inode, iblock, bh, EXT4_GET_BLOCKS_CREATE); 799 807 } 800 808 801 809 /* ··· 814 806 static int ext4_dio_get_block_unwritten_async(struct inode *inode, 815 807 sector_t iblock, struct buffer_head *bh_result, int create) 816 808 { 817 - handle_t *handle; 818 809 int ret; 819 810 820 811 /* We don't expect handle for direct IO */ 821 812 WARN_ON_ONCE(ext4_journal_current_handle()); 822 813 823 - handle = start_dio_trans(inode, bh_result); 824 - if (IS_ERR(handle)) 825 - return PTR_ERR(handle); 826 - ret = _ext4_get_block(inode, iblock, bh_result, 827 - EXT4_GET_BLOCKS_IO_CREATE_EXT); 828 - ext4_journal_stop(handle); 814 + ret = ext4_get_block_trans(inode, iblock, bh_result, 815 + EXT4_GET_BLOCKS_IO_CREATE_EXT); 829 816 830 817 /* 831 818 * When doing DIO using unwritten extents, we need io_end to convert ··· 853 850 static int ext4_dio_get_block_unwritten_sync(struct inode *inode, 854 851 sector_t iblock, struct buffer_head *bh_result, int create) 855 852 { 856 - handle_t *handle; 857 853 int ret; 858 854 859 855 /* We don't expect handle for direct IO */ 860 856 WARN_ON_ONCE(ext4_journal_current_handle()); 861 857 862 - handle = start_dio_trans(inode, bh_result); 863 - if (IS_ERR(handle)) 864 - return PTR_ERR(handle); 865 - ret = _ext4_get_block(inode, iblock, bh_result, 866 - EXT4_GET_BLOCKS_IO_CREATE_EXT); 867 - ext4_journal_stop(handle); 858 + ret = ext4_get_block_trans(inode, iblock, bh_result, 859 + EXT4_GET_BLOCKS_IO_CREATE_EXT); 868 860 869 861 /* 870 862 * Mark inode as having pending DIO writes to unwritten extents.
+9 -2
fs/ext4/move_extent.c
··· 60 60 { 61 61 if (first < second) { 62 62 down_write(&EXT4_I(first)->i_data_sem); 63 - down_write_nested(&EXT4_I(second)->i_data_sem, SINGLE_DEPTH_NESTING); 63 + down_write_nested(&EXT4_I(second)->i_data_sem, I_DATA_SEM_OTHER); 64 64 } else { 65 65 down_write(&EXT4_I(second)->i_data_sem); 66 - down_write_nested(&EXT4_I(first)->i_data_sem, SINGLE_DEPTH_NESTING); 66 + down_write_nested(&EXT4_I(first)->i_data_sem, I_DATA_SEM_OTHER); 67 67 68 68 } 69 69 } ··· 480 480 if (IS_SWAPFILE(orig_inode) || IS_SWAPFILE(donor_inode)) { 481 481 ext4_debug("ext4 move extent: The argument files should " 482 482 "not be swapfile [ino:orig %lu, donor %lu]\n", 483 + orig_inode->i_ino, donor_inode->i_ino); 484 + return -EBUSY; 485 + } 486 + 487 + if (IS_NOQUOTA(orig_inode) || IS_NOQUOTA(donor_inode)) { 488 + ext4_debug("ext4 move extent: The argument files should " 489 + "not be quota files [ino:orig %lu, donor %lu]\n", 483 490 orig_inode->i_ino, donor_inode->i_ino); 484 491 return -EBUSY; 485 492 }
+5
fs/ext4/namei.c
··· 1107 1107 } 1108 1108 1109 1109 while (1) { 1110 + if (signal_pending(current)) { 1111 + err = -ERESTARTSYS; 1112 + goto errout; 1113 + } 1114 + cond_resched(); 1110 1115 block = dx_get_block(frame->at); 1111 1116 ret = htree_dirblock_to_tree(dir_file, dir, block, &hinfo, 1112 1117 start_hash, start_minor_hash);
+13 -1
fs/ext4/page-io.c
··· 23 23 #include <linux/kernel.h> 24 24 #include <linux/slab.h> 25 25 #include <linux/mm.h> 26 + #include <linux/backing-dev.h> 26 27 27 28 #include "ext4_jbd2.h" 28 29 #include "xattr.h" ··· 471 470 472 471 if (ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode) && 473 472 nr_to_submit) { 474 - data_page = ext4_encrypt(inode, page); 473 + gfp_t gfp_flags = GFP_NOFS; 474 + 475 + retry_encrypt: 476 + data_page = ext4_encrypt(inode, page, gfp_flags); 475 477 if (IS_ERR(data_page)) { 476 478 ret = PTR_ERR(data_page); 479 + if (ret == -ENOMEM && wbc->sync_mode == WB_SYNC_ALL) { 480 + if (io->io_bio) { 481 + ext4_io_submit(io); 482 + congestion_wait(BLK_RW_ASYNC, HZ/50); 483 + } 484 + gfp_flags |= __GFP_NOFAIL; 485 + goto retry_encrypt; 486 + } 477 487 data_page = NULL; 478 488 goto out; 479 489 }
+1 -1
fs/ext4/readpage.c
··· 279 279 280 280 if (ext4_encrypted_inode(inode) && 281 281 S_ISREG(inode->i_mode)) { 282 - ctx = ext4_get_crypto_ctx(inode); 282 + ctx = ext4_get_crypto_ctx(inode, GFP_NOFS); 283 283 if (IS_ERR(ctx)) 284 284 goto set_error_page; 285 285 }
+47 -14
fs/ext4/super.c
··· 1113 1113 static int ext4_quota_enable(struct super_block *sb, int type, int format_id, 1114 1114 unsigned int flags); 1115 1115 static int ext4_enable_quotas(struct super_block *sb); 1116 + static int ext4_get_next_id(struct super_block *sb, struct kqid *qid); 1116 1117 1117 1118 static struct dquot **ext4_get_dquots(struct inode *inode) 1118 1119 { ··· 1130 1129 .alloc_dquot = dquot_alloc, 1131 1130 .destroy_dquot = dquot_destroy, 1132 1131 .get_projid = ext4_get_projid, 1133 - .get_next_id = dquot_get_next_id, 1132 + .get_next_id = ext4_get_next_id, 1134 1133 }; 1135 1134 1136 1135 static const struct quotactl_ops ext4_qctl_operations = { ··· 1324 1323 return -1; 1325 1324 } 1326 1325 if (ext4_has_feature_quota(sb)) { 1327 - ext4_msg(sb, KERN_ERR, "Cannot set journaled quota options " 1328 - "when QUOTA feature is enabled"); 1329 - return -1; 1326 + ext4_msg(sb, KERN_INFO, "Journaled quota options " 1327 + "ignored when QUOTA feature is enabled"); 1328 + return 1; 1330 1329 } 1331 1330 qname = match_strdup(args); 1332 1331 if (!qname) { ··· 1689 1688 return -1; 1690 1689 } 1691 1690 if (ext4_has_feature_quota(sb)) { 1692 - ext4_msg(sb, KERN_ERR, 1693 - "Cannot set journaled quota options " 1691 + ext4_msg(sb, KERN_INFO, 1692 + "Quota format mount options ignored " 1694 1693 "when QUOTA feature is enabled"); 1695 - return -1; 1694 + return 1; 1696 1695 } 1697 1696 sbi->s_jquota_fmt = m->mount_opt; 1698 1697 #endif ··· 1757 1756 #ifdef CONFIG_QUOTA 1758 1757 if (ext4_has_feature_quota(sb) && 1759 1758 (test_opt(sb, USRQUOTA) || test_opt(sb, GRPQUOTA))) { 1760 - ext4_msg(sb, KERN_ERR, "Cannot set quota options when QUOTA " 1761 - "feature is enabled"); 1762 - return 0; 1763 - } 1764 - if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { 1759 + ext4_msg(sb, KERN_INFO, "Quota feature enabled, usrquota and grpquota " 1760 + "mount options ignored."); 1761 + clear_opt(sb, USRQUOTA); 1762 + clear_opt(sb, GRPQUOTA); 1763 + } else if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { 1765 1764 if (test_opt(sb, USRQUOTA) && sbi->s_qf_names[USRQUOTA]) 1766 1765 clear_opt(sb, USRQUOTA); 1767 1766 ··· 5029 5028 EXT4_SB(sb)->s_jquota_fmt, type); 5030 5029 } 5031 5030 5031 + static void lockdep_set_quota_inode(struct inode *inode, int subclass) 5032 + { 5033 + struct ext4_inode_info *ei = EXT4_I(inode); 5034 + 5035 + /* The first argument of lockdep_set_subclass has to be 5036 + * *exactly* the same as the argument to init_rwsem() --- in 5037 + * this case, in init_once() --- or lockdep gets unhappy 5038 + * because the name of the lock is set using the 5039 + * stringification of the argument to init_rwsem(). 5040 + */ 5041 + (void) ei; /* shut up clang warning if !CONFIG_LOCKDEP */ 5042 + lockdep_set_subclass(&ei->i_data_sem, subclass); 5043 + } 5044 + 5032 5045 /* 5033 5046 * Standard function to be called on quota_on 5034 5047 */ ··· 5082 5067 if (err) 5083 5068 return err; 5084 5069 } 5085 - 5086 - return dquot_quota_on(sb, type, format_id, path); 5070 + lockdep_set_quota_inode(path->dentry->d_inode, I_DATA_SEM_QUOTA); 5071 + err = dquot_quota_on(sb, type, format_id, path); 5072 + if (err) 5073 + lockdep_set_quota_inode(path->dentry->d_inode, 5074 + I_DATA_SEM_NORMAL); 5075 + return err; 5087 5076 } 5088 5077 5089 5078 static int ext4_quota_enable(struct super_block *sb, int type, int format_id, ··· 5114 5095 5115 5096 /* Don't account quota for quota files to avoid recursion */ 5116 5097 qf_inode->i_flags |= S_NOQUOTA; 5098 + lockdep_set_quota_inode(qf_inode, I_DATA_SEM_QUOTA); 5117 5099 err = dquot_enable(qf_inode, type, format_id, flags); 5118 5100 iput(qf_inode); 5101 + if (err) 5102 + lockdep_set_quota_inode(qf_inode, I_DATA_SEM_NORMAL); 5119 5103 5120 5104 return err; 5121 5105 } ··· 5275 5253 return len; 5276 5254 } 5277 5255 5256 + static int ext4_get_next_id(struct super_block *sb, struct kqid *qid) 5257 + { 5258 + const struct quota_format_ops *ops; 5259 + 5260 + if (!sb_has_quota_loaded(sb, qid->type)) 5261 + return -ESRCH; 5262 + ops = sb_dqopt(sb)->ops[qid->type]; 5263 + if (!ops || !ops->get_next_id) 5264 + return -ENOSYS; 5265 + return dquot_get_next_id(sb, qid); 5266 + } 5278 5267 #endif 5279 5268 5280 5269 static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,
+28 -4
fs/ext4/xattr.c
··· 230 230 return error; 231 231 } 232 232 233 + static int 234 + __xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header, 235 + void *end, const char *function, unsigned int line) 236 + { 237 + struct ext4_xattr_entry *entry = IFIRST(header); 238 + int error = -EFSCORRUPTED; 239 + 240 + if (((void *) header >= end) || 241 + (header->h_magic != le32_to_cpu(EXT4_XATTR_MAGIC))) 242 + goto errout; 243 + error = ext4_xattr_check_names(entry, end, entry); 244 + errout: 245 + if (error) 246 + __ext4_error_inode(inode, function, line, 0, 247 + "corrupted in-inode xattr"); 248 + return error; 249 + } 250 + 251 + #define xattr_check_inode(inode, header, end) \ 252 + __xattr_check_inode((inode), (header), (end), __func__, __LINE__) 253 + 233 254 static inline int 234 255 ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size) 235 256 { ··· 362 341 header = IHDR(inode, raw_inode); 363 342 entry = IFIRST(header); 364 343 end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; 365 - error = ext4_xattr_check_names(entry, end, entry); 344 + error = xattr_check_inode(inode, header, end); 366 345 if (error) 367 346 goto cleanup; 368 347 error = ext4_xattr_find_entry(&entry, name_index, name, ··· 498 477 raw_inode = ext4_raw_inode(&iloc); 499 478 header = IHDR(inode, raw_inode); 500 479 end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; 501 - error = ext4_xattr_check_names(IFIRST(header), end, IFIRST(header)); 480 + error = xattr_check_inode(inode, header, end); 502 481 if (error) 503 482 goto cleanup; 504 483 error = ext4_xattr_list_entries(dentry, IFIRST(header), ··· 1061 1040 is->s.here = is->s.first; 1062 1041 is->s.end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; 1063 1042 if (ext4_test_inode_state(inode, EXT4_STATE_XATTR)) { 1064 - error = ext4_xattr_check_names(IFIRST(header), is->s.end, 1065 - IFIRST(header)); 1043 + error = xattr_check_inode(inode, header, is->s.end); 1066 1044 if (error) 1067 1045 return error; 1068 1046 /* Find the named attribute. */ ··· 1375 1355 min_offs = end - base; 1376 1356 last = entry; 1377 1357 total_ino = sizeof(struct ext4_xattr_ibody_header); 1358 + 1359 + error = xattr_check_inode(inode, header, end); 1360 + if (error) 1361 + goto cleanup; 1378 1362 1379 1363 free = ext4_xattr_free_space(last, &min_offs, base, &total_ino); 1380 1364 if (free >= new_extra_isize) {
+3 -3
fs/nfs/dir.c
··· 377 377 again: 378 378 timestamp = jiffies; 379 379 gencount = nfs_inc_attr_generation_counter(); 380 - error = NFS_PROTO(inode)->readdir(file->f_path.dentry, cred, entry->cookie, pages, 380 + error = NFS_PROTO(inode)->readdir(file_dentry(file), cred, entry->cookie, pages, 381 381 NFS_SERVER(inode)->dtsize, desc->plus); 382 382 if (error < 0) { 383 383 /* We requested READDIRPLUS, but the server doesn't grok it */ ··· 560 560 count++; 561 561 562 562 if (desc->plus != 0) 563 - nfs_prime_dcache(desc->file->f_path.dentry, entry); 563 + nfs_prime_dcache(file_dentry(desc->file), entry); 564 564 565 565 status = nfs_readdir_add_to_array(entry, page); 566 566 if (status != 0) ··· 864 864 */ 865 865 static int nfs_readdir(struct file *file, struct dir_context *ctx) 866 866 { 867 - struct dentry *dentry = file->f_path.dentry; 867 + struct dentry *dentry = file_dentry(file); 868 868 struct inode *inode = d_inode(dentry); 869 869 nfs_readdir_descriptor_t my_desc, 870 870 *desc = &my_desc;
+1 -1
fs/nfs/inode.c
··· 940 940 { 941 941 struct nfs_open_context *ctx; 942 942 943 - ctx = alloc_nfs_open_context(filp->f_path.dentry, filp->f_mode); 943 + ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode); 944 944 if (IS_ERR(ctx)) 945 945 return PTR_ERR(ctx); 946 946 nfs_file_set_open_context(filp, ctx);
+2 -2
fs/nfs/nfs4file.c
··· 26 26 nfs4_file_open(struct inode *inode, struct file *filp) 27 27 { 28 28 struct nfs_open_context *ctx; 29 - struct dentry *dentry = filp->f_path.dentry; 29 + struct dentry *dentry = file_dentry(filp); 30 30 struct dentry *parent = NULL; 31 31 struct inode *dir; 32 32 unsigned openflags = filp->f_flags; ··· 57 57 parent = dget_parent(dentry); 58 58 dir = d_inode(parent); 59 59 60 - ctx = alloc_nfs_open_context(filp->f_path.dentry, filp->f_mode); 60 + ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode); 61 61 err = PTR_ERR(ctx); 62 62 if (IS_ERR(ctx)) 63 63 goto out;
+33
fs/overlayfs/super.c
··· 295 295 } 296 296 } 297 297 298 + static struct dentry *ovl_d_real(struct dentry *dentry, struct inode *inode) 299 + { 300 + struct dentry *real; 301 + 302 + if (d_is_dir(dentry)) { 303 + if (!inode || inode == d_inode(dentry)) 304 + return dentry; 305 + goto bug; 306 + } 307 + 308 + real = ovl_dentry_upper(dentry); 309 + if (real && (!inode || inode == d_inode(real))) 310 + return real; 311 + 312 + real = ovl_dentry_lower(dentry); 313 + if (!real) 314 + goto bug; 315 + 316 + if (!inode || inode == d_inode(real)) 317 + return real; 318 + 319 + /* Handle recursion */ 320 + if (real->d_flags & DCACHE_OP_REAL) 321 + return real->d_op->d_real(real, inode); 322 + 323 + bug: 324 + WARN(1, "ovl_d_real(%pd4, %s:%lu\n): real dentry not found\n", dentry, 325 + inode ? inode->i_sb->s_id : "NULL", inode ? inode->i_ino : 0); 326 + return dentry; 327 + } 328 + 298 329 static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags) 299 330 { 300 331 struct ovl_entry *oe = dentry->d_fsdata; ··· 370 339 static const struct dentry_operations ovl_dentry_operations = { 371 340 .d_release = ovl_dentry_release, 372 341 .d_select_inode = ovl_d_select_inode, 342 + .d_real = ovl_d_real, 373 343 }; 374 344 375 345 static const struct dentry_operations ovl_reval_dentry_operations = { 376 346 .d_release = ovl_dentry_release, 377 347 .d_select_inode = ovl_d_select_inode, 348 + .d_real = ovl_d_real, 378 349 .d_revalidate = ovl_dentry_revalidate, 379 350 .d_weak_revalidate = ovl_dentry_weak_revalidate, 380 351 };
+10
include/linux/dcache.h
··· 161 161 struct vfsmount *(*d_automount)(struct path *); 162 162 int (*d_manage)(struct dentry *, bool); 163 163 struct inode *(*d_select_inode)(struct dentry *, unsigned); 164 + struct dentry *(*d_real)(struct dentry *, struct inode *); 164 165 } ____cacheline_aligned; 165 166 166 167 /* ··· 230 229 #define DCACHE_OP_SELECT_INODE 0x02000000 /* Unioned entry: dcache op selects inode */ 231 230 232 231 #define DCACHE_ENCRYPTED_WITH_KEY 0x04000000 /* dir is encrypted with a valid key */ 232 + #define DCACHE_OP_REAL 0x08000000 233 233 234 234 extern seqlock_t rename_lock; 235 235 ··· 555 553 static inline struct dentry *d_backing_dentry(struct dentry *upper) 556 554 { 557 555 return upper; 556 + } 557 + 558 + static inline struct dentry *d_real(struct dentry *dentry) 559 + { 560 + if (unlikely(dentry->d_flags & DCACHE_OP_REAL)) 561 + return dentry->d_op->d_real(dentry, NULL); 562 + else 563 + return dentry; 558 564 } 559 565 560 566 #endif /* __LINUX_DCACHE_H */
+10
include/linux/fs.h
··· 1241 1241 return f->f_inode; 1242 1242 } 1243 1243 1244 + static inline struct dentry *file_dentry(const struct file *file) 1245 + { 1246 + struct dentry *dentry = file->f_path.dentry; 1247 + 1248 + if (unlikely(dentry->d_flags & DCACHE_OP_REAL)) 1249 + return dentry->d_op->d_real(dentry, file_inode(file)); 1250 + else 1251 + return dentry; 1252 + } 1253 + 1244 1254 static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl) 1245 1255 { 1246 1256 return locks_lock_inode_wait(file_inode(filp), fl);