aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-04-07 20:22:20 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-04-07 20:22:20 -0400
commit93061f390f107c37bad7e3bf9eb07bda58a4a99f (patch)
tree6cd3ad605900fa7145a700c22062fabe36ccff95
parent1c915b3ac4ecf6ff67573eed24458d862e842cb6 (diff)
parentc325a67c72903e1cc30e990a15ce745bda0dbfde (diff)
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()
-rw-r--r--fs/btrfs/file.c2
-rw-r--r--fs/dcache.c5
-rw-r--r--fs/ext4/crypto.c49
-rw-r--r--fs/ext4/dir.c5
-rw-r--r--fs/ext4/ext4.h29
-rw-r--r--fs/ext4/file.c12
-rw-r--r--fs/ext4/inode.c58
-rw-r--r--fs/ext4/move_extent.c11
-rw-r--r--fs/ext4/namei.c5
-rw-r--r--fs/ext4/page-io.c14
-rw-r--r--fs/ext4/readpage.c2
-rw-r--r--fs/ext4/super.c61
-rw-r--r--fs/ext4/xattr.c32
-rw-r--r--fs/nfs/dir.c6
-rw-r--r--fs/nfs/inode.c2
-rw-r--r--fs/nfs/nfs4file.c4
-rw-r--r--fs/overlayfs/super.c33
-rw-r--r--include/linux/dcache.h10
-rw-r--r--include/linux/fs.h10
19 files changed, 264 insertions, 86 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index cf31a60c6284..fbe2589f99f0 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1905,7 +1905,7 @@ static int start_ordered_ops(struct inode *inode, loff_t start, loff_t end)
1905 */ 1905 */
1906int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) 1906int 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 struct inode *inode = d_inode(dentry); 1909 struct inode *inode = d_inode(dentry);
1910 struct btrfs_root *root = BTRFS_I(inode)->root; 1910 struct btrfs_root *root = BTRFS_I(inode)->root;
1911 struct btrfs_trans_handle *trans; 1911 struct btrfs_trans_handle *trans;
diff --git a/fs/dcache.c b/fs/dcache.c
index 32ceae3e6112..d5ecc6e477da 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1667,7 +1667,8 @@ void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op)
1667 DCACHE_OP_REVALIDATE | 1667 DCACHE_OP_REVALIDATE |
1668 DCACHE_OP_WEAK_REVALIDATE | 1668 DCACHE_OP_WEAK_REVALIDATE |
1669 DCACHE_OP_DELETE | 1669 DCACHE_OP_DELETE |
1670 DCACHE_OP_SELECT_INODE)); 1670 DCACHE_OP_SELECT_INODE |
1671 DCACHE_OP_REAL));
1671 dentry->d_op = op; 1672 dentry->d_op = op;
1672 if (!op) 1673 if (!op)
1673 return; 1674 return;
@@ -1685,6 +1686,8 @@ void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op)
1685 dentry->d_flags |= DCACHE_OP_PRUNE; 1686 dentry->d_flags |= DCACHE_OP_PRUNE;
1686 if (op->d_select_inode) 1687 if (op->d_select_inode)
1687 dentry->d_flags |= DCACHE_OP_SELECT_INODE; 1688 dentry->d_flags |= DCACHE_OP_SELECT_INODE;
1689 if (op->d_real)
1690 dentry->d_flags |= DCACHE_OP_REAL;
1688 1691
1689} 1692}
1690EXPORT_SYMBOL(d_set_d_op); 1693EXPORT_SYMBOL(d_set_d_op);
diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
index 2580ef3346ca..db9ae6e18154 100644
--- a/fs/ext4/crypto.c
+++ b/fs/ext4/crypto.c
@@ -91,7 +91,8 @@ void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx)
91 * Return: An allocated and initialized encryption context on success; error 91 * Return: An allocated and initialized encryption context on success; error
92 * value or NULL otherwise. 92 * value or NULL otherwise.
93 */ 93 */
94struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode) 94struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode,
95 gfp_t gfp_flags)
95{ 96{
96 struct ext4_crypto_ctx *ctx = NULL; 97 struct ext4_crypto_ctx *ctx = NULL;
97 int res = 0; 98 int res = 0;
@@ -118,7 +119,7 @@ struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode)
118 list_del(&ctx->free_list); 119 list_del(&ctx->free_list);
119 spin_unlock_irqrestore(&ext4_crypto_ctx_lock, flags); 120 spin_unlock_irqrestore(&ext4_crypto_ctx_lock, flags);
120 if (!ctx) { 121 if (!ctx) {
121 ctx = kmem_cache_zalloc(ext4_crypto_ctx_cachep, GFP_NOFS); 122 ctx = kmem_cache_zalloc(ext4_crypto_ctx_cachep, gfp_flags);
122 if (!ctx) { 123 if (!ctx) {
123 res = -ENOMEM; 124 res = -ENOMEM;
124 goto out; 125 goto out;
@@ -255,7 +256,8 @@ static int ext4_page_crypto(struct inode *inode,
255 ext4_direction_t rw, 256 ext4_direction_t rw,
256 pgoff_t index, 257 pgoff_t index,
257 struct page *src_page, 258 struct page *src_page,
258 struct page *dest_page) 259 struct page *dest_page,
260 gfp_t gfp_flags)
259 261
260{ 262{
261 u8 xts_tweak[EXT4_XTS_TWEAK_SIZE]; 263 u8 xts_tweak[EXT4_XTS_TWEAK_SIZE];
@@ -266,7 +268,7 @@ static int ext4_page_crypto(struct inode *inode,
266 struct crypto_skcipher *tfm = ci->ci_ctfm; 268 struct crypto_skcipher *tfm = ci->ci_ctfm;
267 int res = 0; 269 int res = 0;
268 270
269 req = skcipher_request_alloc(tfm, GFP_NOFS); 271 req = skcipher_request_alloc(tfm, gfp_flags);
270 if (!req) { 272 if (!req) {
271 printk_ratelimited(KERN_ERR 273 printk_ratelimited(KERN_ERR
272 "%s: crypto_request_alloc() failed\n", 274 "%s: crypto_request_alloc() failed\n",
@@ -307,9 +309,10 @@ static int ext4_page_crypto(struct inode *inode,
307 return 0; 309 return 0;
308} 310}
309 311
310static struct page *alloc_bounce_page(struct ext4_crypto_ctx *ctx) 312static struct page *alloc_bounce_page(struct ext4_crypto_ctx *ctx,
313 gfp_t gfp_flags)
311{ 314{
312 ctx->w.bounce_page = mempool_alloc(ext4_bounce_page_pool, GFP_NOWAIT); 315 ctx->w.bounce_page = mempool_alloc(ext4_bounce_page_pool, gfp_flags);
313 if (ctx->w.bounce_page == NULL) 316 if (ctx->w.bounce_page == NULL)
314 return ERR_PTR(-ENOMEM); 317 return ERR_PTR(-ENOMEM);
315 ctx->flags |= EXT4_WRITE_PATH_FL; 318 ctx->flags |= EXT4_WRITE_PATH_FL;
@@ -332,7 +335,8 @@ static struct page *alloc_bounce_page(struct ext4_crypto_ctx *ctx)
332 * error value or NULL. 335 * error value or NULL.
333 */ 336 */
334struct page *ext4_encrypt(struct inode *inode, 337struct page *ext4_encrypt(struct inode *inode,
335 struct page *plaintext_page) 338 struct page *plaintext_page,
339 gfp_t gfp_flags)
336{ 340{
337 struct ext4_crypto_ctx *ctx; 341 struct ext4_crypto_ctx *ctx;
338 struct page *ciphertext_page = NULL; 342 struct page *ciphertext_page = NULL;
@@ -340,17 +344,17 @@ struct page *ext4_encrypt(struct inode *inode,
340 344
341 BUG_ON(!PageLocked(plaintext_page)); 345 BUG_ON(!PageLocked(plaintext_page));
342 346
343 ctx = ext4_get_crypto_ctx(inode); 347 ctx = ext4_get_crypto_ctx(inode, gfp_flags);
344 if (IS_ERR(ctx)) 348 if (IS_ERR(ctx))
345 return (struct page *) ctx; 349 return (struct page *) ctx;
346 350
347 /* The encryption operation will require a bounce page. */ 351 /* The encryption operation will require a bounce page. */
348 ciphertext_page = alloc_bounce_page(ctx); 352 ciphertext_page = alloc_bounce_page(ctx, gfp_flags);
349 if (IS_ERR(ciphertext_page)) 353 if (IS_ERR(ciphertext_page))
350 goto errout; 354 goto errout;
351 ctx->w.control_page = plaintext_page; 355 ctx->w.control_page = plaintext_page;
352 err = ext4_page_crypto(inode, EXT4_ENCRYPT, plaintext_page->index, 356 err = ext4_page_crypto(inode, EXT4_ENCRYPT, plaintext_page->index,
353 plaintext_page, ciphertext_page); 357 plaintext_page, ciphertext_page, gfp_flags);
354 if (err) { 358 if (err) {
355 ciphertext_page = ERR_PTR(err); 359 ciphertext_page = ERR_PTR(err);
356 errout: 360 errout:
@@ -378,8 +382,8 @@ int ext4_decrypt(struct page *page)
378{ 382{
379 BUG_ON(!PageLocked(page)); 383 BUG_ON(!PageLocked(page));
380 384
381 return ext4_page_crypto(page->mapping->host, 385 return ext4_page_crypto(page->mapping->host, EXT4_DECRYPT,
382 EXT4_DECRYPT, page->index, page, page); 386 page->index, page, page, GFP_NOFS);
383} 387}
384 388
385int ext4_encrypted_zeroout(struct inode *inode, ext4_lblk_t lblk, 389int ext4_encrypted_zeroout(struct inode *inode, ext4_lblk_t lblk,
@@ -398,11 +402,11 @@ int ext4_encrypted_zeroout(struct inode *inode, ext4_lblk_t lblk,
398 402
399 BUG_ON(inode->i_sb->s_blocksize != PAGE_SIZE); 403 BUG_ON(inode->i_sb->s_blocksize != PAGE_SIZE);
400 404
401 ctx = ext4_get_crypto_ctx(inode); 405 ctx = ext4_get_crypto_ctx(inode, GFP_NOFS);
402 if (IS_ERR(ctx)) 406 if (IS_ERR(ctx))
403 return PTR_ERR(ctx); 407 return PTR_ERR(ctx);
404 408
405 ciphertext_page = alloc_bounce_page(ctx); 409 ciphertext_page = alloc_bounce_page(ctx, GFP_NOWAIT);
406 if (IS_ERR(ciphertext_page)) { 410 if (IS_ERR(ciphertext_page)) {
407 err = PTR_ERR(ciphertext_page); 411 err = PTR_ERR(ciphertext_page);
408 goto errout; 412 goto errout;
@@ -410,11 +414,12 @@ int ext4_encrypted_zeroout(struct inode *inode, ext4_lblk_t lblk,
410 414
411 while (len--) { 415 while (len--) {
412 err = ext4_page_crypto(inode, EXT4_ENCRYPT, lblk, 416 err = ext4_page_crypto(inode, EXT4_ENCRYPT, lblk,
413 ZERO_PAGE(0), ciphertext_page); 417 ZERO_PAGE(0), ciphertext_page,
418 GFP_NOFS);
414 if (err) 419 if (err)
415 goto errout; 420 goto errout;
416 421
417 bio = bio_alloc(GFP_KERNEL, 1); 422 bio = bio_alloc(GFP_NOWAIT, 1);
418 if (!bio) { 423 if (!bio) {
419 err = -ENOMEM; 424 err = -ENOMEM;
420 goto errout; 425 goto errout;
@@ -473,13 +478,16 @@ uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size)
473 */ 478 */
474static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags) 479static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags)
475{ 480{
476 struct inode *dir = d_inode(dentry->d_parent); 481 struct dentry *dir;
477 struct ext4_crypt_info *ci = EXT4_I(dir)->i_crypt_info; 482 struct ext4_crypt_info *ci;
478 int dir_has_key, cached_with_key; 483 int dir_has_key, cached_with_key;
479 484
480 if (!ext4_encrypted_inode(dir)) 485 dir = dget_parent(dentry);
486 if (!ext4_encrypted_inode(d_inode(dir))) {
487 dput(dir);
481 return 0; 488 return 0;
482 489 }
490 ci = EXT4_I(d_inode(dir))->i_crypt_info;
483 if (ci && ci->ci_keyring_key && 491 if (ci && ci->ci_keyring_key &&
484 (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | 492 (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) |
485 (1 << KEY_FLAG_REVOKED) | 493 (1 << KEY_FLAG_REVOKED) |
@@ -489,6 +497,7 @@ static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags)
489 /* this should eventually be an flag in d_flags */ 497 /* this should eventually be an flag in d_flags */
490 cached_with_key = dentry->d_fsdata != NULL; 498 cached_with_key = dentry->d_fsdata != NULL;
491 dir_has_key = (ci != NULL); 499 dir_has_key = (ci != NULL);
500 dput(dir);
492 501
493 /* 502 /*
494 * If the dentry was cached without the key, and it is a 503 * If the dentry was cached without the key, and it is a
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 561d7308b393..4173bfe21114 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -150,6 +150,11 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
150 while (ctx->pos < inode->i_size) { 150 while (ctx->pos < inode->i_size) {
151 struct ext4_map_blocks map; 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 map.m_lblk = ctx->pos >> EXT4_BLOCK_SIZE_BITS(sb); 158 map.m_lblk = ctx->pos >> EXT4_BLOCK_SIZE_BITS(sb);
154 map.m_len = 1; 159 map.m_len = 1;
155 err = ext4_map_blocks(NULL, inode, &map, 0); 160 err = ext4_map_blocks(NULL, inode, &map, 0);
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 7ccba1aa142d..349afebe21ee 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -912,6 +912,29 @@ do { \
912#include "extents_status.h" 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 */
930enum {
931 I_DATA_SEM_NORMAL = 0,
932 I_DATA_SEM_OTHER,
933 I_DATA_SEM_QUOTA,
934};
935
936
937/*
915 * fourth extended file system inode data in memory 938 * fourth extended file system inode data in memory
916 */ 939 */
917struct ext4_inode_info { 940struct ext4_inode_info {
@@ -2282,11 +2305,13 @@ extern struct kmem_cache *ext4_crypt_info_cachep;
2282bool ext4_valid_contents_enc_mode(uint32_t mode); 2305bool ext4_valid_contents_enc_mode(uint32_t mode);
2283uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size); 2306uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size);
2284extern struct workqueue_struct *ext4_read_workqueue; 2307extern struct workqueue_struct *ext4_read_workqueue;
2285struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode); 2308struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode,
2309 gfp_t gfp_flags);
2286void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx); 2310void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx);
2287void ext4_restore_control_page(struct page *data_page); 2311void ext4_restore_control_page(struct page *data_page);
2288struct page *ext4_encrypt(struct inode *inode, 2312struct page *ext4_encrypt(struct inode *inode,
2289 struct page *plaintext_page); 2313 struct page *plaintext_page,
2314 gfp_t gfp_flags);
2290int ext4_decrypt(struct page *page); 2315int ext4_decrypt(struct page *page);
2291int ext4_encrypted_zeroout(struct inode *inode, ext4_lblk_t lblk, 2316int ext4_encrypted_zeroout(struct inode *inode, ext4_lblk_t lblk,
2292 ext4_fsblk_t pblk, ext4_lblk_t len); 2317 ext4_fsblk_t pblk, ext4_lblk_t len);
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 0caece398eb8..fa2208bae2e1 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -329,7 +329,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
329 struct super_block *sb = inode->i_sb; 329 struct super_block *sb = inode->i_sb;
330 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 330 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
331 struct vfsmount *mnt = filp->f_path.mnt; 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 struct path path; 333 struct path path;
334 char buf[64], *cp; 334 char buf[64], *cp;
335 int ret; 335 int ret;
@@ -373,14 +373,18 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
373 if (ext4_encryption_info(inode) == NULL) 373 if (ext4_encryption_info(inode) == NULL)
374 return -ENOKEY; 374 return -ENOKEY;
375 } 375 }
376 if (ext4_encrypted_inode(dir) && 376
377 !ext4_is_child_context_consistent_with_parent(dir, inode)) { 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 ext4_warning(inode->i_sb, 380 ext4_warning(inode->i_sb,
379 "Inconsistent encryption contexts: %lu/%lu\n", 381 "Inconsistent encryption contexts: %lu/%lu\n",
380 (unsigned long) dir->i_ino, 382 (unsigned long) d_inode(dir)->i_ino,
381 (unsigned long) inode->i_ino); 383 (unsigned long) inode->i_ino);
384 dput(dir);
382 return -EPERM; 385 return -EPERM;
383 } 386 }
387 dput(dir);
384 /* 388 /*
385 * Set up the jbd2_inode if we are opening the inode for 389 * Set up the jbd2_inode if we are opening the inode for
386 * writing and the journal is present 390 * writing and the journal is present
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 4f7043ba4447..981a1fc30eaa 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -763,39 +763,47 @@ int ext4_get_block_unwritten(struct inode *inode, sector_t iblock,
763/* Maximum number of blocks we map for direct IO at once. */ 763/* Maximum number of blocks we map for direct IO at once. */
764#define DIO_MAX_BLOCKS 4096 764#define DIO_MAX_BLOCKS 4096
765 765
766static handle_t *start_dio_trans(struct inode *inode, 766/*
767 struct buffer_head *bh_result) 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 */
771static int ext4_get_block_trans(struct inode *inode, sector_t iblock,
772 struct buffer_head *bh_result, int flags)
768{ 773{
769 int dio_credits; 774 int dio_credits;
775 handle_t *handle;
776 int retries = 0;
777 int ret;
770 778
771 /* Trim mapping request to maximum we can map at once for DIO */ 779 /* Trim mapping request to maximum we can map at once for DIO */
772 if (bh_result->b_size >> inode->i_blkbits > DIO_MAX_BLOCKS) 780 if (bh_result->b_size >> inode->i_blkbits > DIO_MAX_BLOCKS)
773 bh_result->b_size = DIO_MAX_BLOCKS << inode->i_blkbits; 781 bh_result->b_size = DIO_MAX_BLOCKS << inode->i_blkbits;
774 dio_credits = ext4_chunk_trans_blocks(inode, 782 dio_credits = ext4_chunk_trans_blocks(inode,
775 bh_result->b_size >> inode->i_blkbits); 783 bh_result->b_size >> inode->i_blkbits);
776 return ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, dio_credits); 784retry:
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/* Get block function for DIO reads and writes to inodes without extents */ 797/* Get block function for DIO reads and writes to inodes without extents */
780int ext4_dio_get_block(struct inode *inode, sector_t iblock, 798int ext4_dio_get_block(struct inode *inode, sector_t iblock,
781 struct buffer_head *bh, int create) 799 struct buffer_head *bh, int create)
782{ 800{
783 handle_t *handle;
784 int ret;
785
786 /* We don't expect handle for direct IO */ 801 /* We don't expect handle for direct IO */
787 WARN_ON_ONCE(ext4_journal_current_handle()); 802 WARN_ON_ONCE(ext4_journal_current_handle());
788 803
789 if (create) { 804 if (!create)
790 handle = start_dio_trans(inode, bh); 805 return _ext4_get_block(inode, iblock, bh, 0);
791 if (IS_ERR(handle)) 806 return ext4_get_block_trans(inode, iblock, bh, EXT4_GET_BLOCKS_CREATE);
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;
799} 807}
800 808
801/* 809/*
@@ -806,18 +814,13 @@ int ext4_dio_get_block(struct inode *inode, sector_t iblock,
806static int ext4_dio_get_block_unwritten_async(struct inode *inode, 814static int ext4_dio_get_block_unwritten_async(struct inode *inode,
807 sector_t iblock, struct buffer_head *bh_result, int create) 815 sector_t iblock, struct buffer_head *bh_result, int create)
808{ 816{
809 handle_t *handle;
810 int ret; 817 int ret;
811 818
812 /* We don't expect handle for direct IO */ 819 /* We don't expect handle for direct IO */
813 WARN_ON_ONCE(ext4_journal_current_handle()); 820 WARN_ON_ONCE(ext4_journal_current_handle());
814 821
815 handle = start_dio_trans(inode, bh_result); 822 ret = ext4_get_block_trans(inode, iblock, bh_result,
816 if (IS_ERR(handle)) 823 EXT4_GET_BLOCKS_IO_CREATE_EXT);
817 return PTR_ERR(handle);
818 ret = _ext4_get_block(inode, iblock, bh_result,
819 EXT4_GET_BLOCKS_IO_CREATE_EXT);
820 ext4_journal_stop(handle);
821 824
822 /* 825 /*
823 * When doing DIO using unwritten extents, we need io_end to convert 826 * When doing DIO using unwritten extents, we need io_end to convert
@@ -850,18 +853,13 @@ static int ext4_dio_get_block_unwritten_async(struct inode *inode,
850static int ext4_dio_get_block_unwritten_sync(struct inode *inode, 853static int ext4_dio_get_block_unwritten_sync(struct inode *inode,
851 sector_t iblock, struct buffer_head *bh_result, int create) 854 sector_t iblock, struct buffer_head *bh_result, int create)
852{ 855{
853 handle_t *handle;
854 int ret; 856 int ret;
855 857
856 /* We don't expect handle for direct IO */ 858 /* We don't expect handle for direct IO */
857 WARN_ON_ONCE(ext4_journal_current_handle()); 859 WARN_ON_ONCE(ext4_journal_current_handle());
858 860
859 handle = start_dio_trans(inode, bh_result); 861 ret = ext4_get_block_trans(inode, iblock, bh_result,
860 if (IS_ERR(handle)) 862 EXT4_GET_BLOCKS_IO_CREATE_EXT);
861 return PTR_ERR(handle);
862 ret = _ext4_get_block(inode, iblock, bh_result,
863 EXT4_GET_BLOCKS_IO_CREATE_EXT);
864 ext4_journal_stop(handle);
865 863
866 /* 864 /*
867 * Mark inode as having pending DIO writes to unwritten extents. 865 * Mark inode as having pending DIO writes to unwritten extents.
diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index 675b67e5d5c2..325cef48b39a 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -60,10 +60,10 @@ ext4_double_down_write_data_sem(struct inode *first, struct inode *second)
60{ 60{
61 if (first < second) { 61 if (first < second) {
62 down_write(&EXT4_I(first)->i_data_sem); 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 } else { 64 } else {
65 down_write(&EXT4_I(second)->i_data_sem); 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}
@@ -484,6 +484,13 @@ mext_check_arguments(struct inode *orig_inode,
484 return -EBUSY; 484 return -EBUSY;
485 } 485 }
486 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",
490 orig_inode->i_ino, donor_inode->i_ino);
491 return -EBUSY;
492 }
493
487 /* Ext4 move extent supports only extent based file */ 494 /* Ext4 move extent supports only extent based file */
488 if (!(ext4_test_inode_flag(orig_inode, EXT4_INODE_EXTENTS))) { 495 if (!(ext4_test_inode_flag(orig_inode, EXT4_INODE_EXTENTS))) {
489 ext4_debug("ext4 move extent: orig file is not extents " 496 ext4_debug("ext4 move extent: orig file is not extents "
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 48e4b8907826..db98f89f737f 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1107,6 +1107,11 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
1107 } 1107 }
1108 1108
1109 while (1) { 1109 while (1) {
1110 if (signal_pending(current)) {
1111 err = -ERESTARTSYS;
1112 goto errout;
1113 }
1114 cond_resched();
1110 block = dx_get_block(frame->at); 1115 block = dx_get_block(frame->at);
1111 ret = htree_dirblock_to_tree(dir_file, dir, block, &hinfo, 1116 ret = htree_dirblock_to_tree(dir_file, dir, block, &hinfo,
1112 start_hash, start_minor_hash); 1117 start_hash, start_minor_hash);
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 93ad0acf704c..e4fc8ea45d78 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -23,6 +23,7 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/mm.h> 25#include <linux/mm.h>
26#include <linux/backing-dev.h>
26 27
27#include "ext4_jbd2.h" 28#include "ext4_jbd2.h"
28#include "xattr.h" 29#include "xattr.h"
@@ -470,9 +471,20 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
470 471
471 if (ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode) && 472 if (ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode) &&
472 nr_to_submit) { 473 nr_to_submit) {
473 data_page = ext4_encrypt(inode, page); 474 gfp_t gfp_flags = GFP_NOFS;
475
476 retry_encrypt:
477 data_page = ext4_encrypt(inode, page, gfp_flags);
474 if (IS_ERR(data_page)) { 478 if (IS_ERR(data_page)) {
475 ret = PTR_ERR(data_page); 479 ret = PTR_ERR(data_page);
480 if (ret == -ENOMEM && wbc->sync_mode == WB_SYNC_ALL) {
481 if (io->io_bio) {
482 ext4_io_submit(io);
483 congestion_wait(BLK_RW_ASYNC, HZ/50);
484 }
485 gfp_flags |= __GFP_NOFAIL;
486 goto retry_encrypt;
487 }
476 data_page = NULL; 488 data_page = NULL;
477 goto out; 489 goto out;
478 } 490 }
diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
index f24e7299e1c8..dc54a4b60eba 100644
--- a/fs/ext4/readpage.c
+++ b/fs/ext4/readpage.c
@@ -279,7 +279,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
279 279
280 if (ext4_encrypted_inode(inode) && 280 if (ext4_encrypted_inode(inode) &&
281 S_ISREG(inode->i_mode)) { 281 S_ISREG(inode->i_mode)) {
282 ctx = ext4_get_crypto_ctx(inode); 282 ctx = ext4_get_crypto_ctx(inode, GFP_NOFS);
283 if (IS_ERR(ctx)) 283 if (IS_ERR(ctx))
284 goto set_error_page; 284 goto set_error_page;
285 } 285 }
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 0bb74aacb8c0..304c712dbe12 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1113,6 +1113,7 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
1113static int ext4_quota_enable(struct super_block *sb, int type, int format_id, 1113static int ext4_quota_enable(struct super_block *sb, int type, int format_id,
1114 unsigned int flags); 1114 unsigned int flags);
1115static int ext4_enable_quotas(struct super_block *sb); 1115static int ext4_enable_quotas(struct super_block *sb);
1116static int ext4_get_next_id(struct super_block *sb, struct kqid *qid);
1116 1117
1117static struct dquot **ext4_get_dquots(struct inode *inode) 1118static struct dquot **ext4_get_dquots(struct inode *inode)
1118{ 1119{
@@ -1129,7 +1130,7 @@ static const struct dquot_operations ext4_quota_operations = {
1129 .alloc_dquot = dquot_alloc, 1130 .alloc_dquot = dquot_alloc,
1130 .destroy_dquot = dquot_destroy, 1131 .destroy_dquot = dquot_destroy,
1131 .get_projid = ext4_get_projid, 1132 .get_projid = ext4_get_projid,
1132 .get_next_id = dquot_get_next_id, 1133 .get_next_id = ext4_get_next_id,
1133}; 1134};
1134 1135
1135static const struct quotactl_ops ext4_qctl_operations = { 1136static const struct quotactl_ops ext4_qctl_operations = {
@@ -1323,9 +1324,9 @@ static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
1323 return -1; 1324 return -1;
1324 } 1325 }
1325 if (ext4_has_feature_quota(sb)) { 1326 if (ext4_has_feature_quota(sb)) {
1326 ext4_msg(sb, KERN_ERR, "Cannot set journaled quota options " 1327 ext4_msg(sb, KERN_INFO, "Journaled quota options "
1327 "when QUOTA feature is enabled"); 1328 "ignored when QUOTA feature is enabled");
1328 return -1; 1329 return 1;
1329 } 1330 }
1330 qname = match_strdup(args); 1331 qname = match_strdup(args);
1331 if (!qname) { 1332 if (!qname) {
@@ -1688,10 +1689,10 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
1688 return -1; 1689 return -1;
1689 } 1690 }
1690 if (ext4_has_feature_quota(sb)) { 1691 if (ext4_has_feature_quota(sb)) {
1691 ext4_msg(sb, KERN_ERR, 1692 ext4_msg(sb, KERN_INFO,
1692 "Cannot set journaled quota options " 1693 "Quota format mount options ignored "
1693 "when QUOTA feature is enabled"); 1694 "when QUOTA feature is enabled");
1694 return -1; 1695 return 1;
1695 } 1696 }
1696 sbi->s_jquota_fmt = m->mount_opt; 1697 sbi->s_jquota_fmt = m->mount_opt;
1697#endif 1698#endif
@@ -1756,11 +1757,11 @@ static int parse_options(char *options, struct super_block *sb,
1756#ifdef CONFIG_QUOTA 1757#ifdef CONFIG_QUOTA
1757 if (ext4_has_feature_quota(sb) && 1758 if (ext4_has_feature_quota(sb) &&
1758 (test_opt(sb, USRQUOTA) || test_opt(sb, GRPQUOTA))) { 1759 (test_opt(sb, USRQUOTA) || test_opt(sb, GRPQUOTA))) {
1759 ext4_msg(sb, KERN_ERR, "Cannot set quota options when QUOTA " 1760 ext4_msg(sb, KERN_INFO, "Quota feature enabled, usrquota and grpquota "
1760 "feature is enabled"); 1761 "mount options ignored.");
1761 return 0; 1762 clear_opt(sb, USRQUOTA);
1762 } 1763 clear_opt(sb, GRPQUOTA);
1763 if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { 1764 } else if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
1764 if (test_opt(sb, USRQUOTA) && sbi->s_qf_names[USRQUOTA]) 1765 if (test_opt(sb, USRQUOTA) && sbi->s_qf_names[USRQUOTA])
1765 clear_opt(sb, USRQUOTA); 1766 clear_opt(sb, USRQUOTA);
1766 1767
@@ -5028,6 +5029,20 @@ static int ext4_quota_on_mount(struct super_block *sb, int type)
5028 EXT4_SB(sb)->s_jquota_fmt, type); 5029 EXT4_SB(sb)->s_jquota_fmt, type);
5029} 5030}
5030 5031
5032static void lockdep_set_quota_inode(struct inode *inode, int subclass)
5033{
5034 struct ext4_inode_info *ei = EXT4_I(inode);
5035
5036 /* The first argument of lockdep_set_subclass has to be
5037 * *exactly* the same as the argument to init_rwsem() --- in
5038 * this case, in init_once() --- or lockdep gets unhappy
5039 * because the name of the lock is set using the
5040 * stringification of the argument to init_rwsem().
5041 */
5042 (void) ei; /* shut up clang warning if !CONFIG_LOCKDEP */
5043 lockdep_set_subclass(&ei->i_data_sem, subclass);
5044}
5045
5031/* 5046/*
5032 * Standard function to be called on quota_on 5047 * Standard function to be called on quota_on
5033 */ 5048 */
@@ -5067,8 +5082,12 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
5067 if (err) 5082 if (err)
5068 return err; 5083 return err;
5069 } 5084 }
5070 5085 lockdep_set_quota_inode(path->dentry->d_inode, I_DATA_SEM_QUOTA);
5071 return dquot_quota_on(sb, type, format_id, path); 5086 err = dquot_quota_on(sb, type, format_id, path);
5087 if (err)
5088 lockdep_set_quota_inode(path->dentry->d_inode,
5089 I_DATA_SEM_NORMAL);
5090 return err;
5072} 5091}
5073 5092
5074static int ext4_quota_enable(struct super_block *sb, int type, int format_id, 5093static int ext4_quota_enable(struct super_block *sb, int type, int format_id,
@@ -5095,8 +5114,11 @@ static int ext4_quota_enable(struct super_block *sb, int type, int format_id,
5095 5114
5096 /* Don't account quota for quota files to avoid recursion */ 5115 /* Don't account quota for quota files to avoid recursion */
5097 qf_inode->i_flags |= S_NOQUOTA; 5116 qf_inode->i_flags |= S_NOQUOTA;
5117 lockdep_set_quota_inode(qf_inode, I_DATA_SEM_QUOTA);
5098 err = dquot_enable(qf_inode, type, format_id, flags); 5118 err = dquot_enable(qf_inode, type, format_id, flags);
5099 iput(qf_inode); 5119 iput(qf_inode);
5120 if (err)
5121 lockdep_set_quota_inode(qf_inode, I_DATA_SEM_NORMAL);
5100 5122
5101 return err; 5123 return err;
5102} 5124}
@@ -5253,6 +5275,17 @@ out:
5253 return len; 5275 return len;
5254} 5276}
5255 5277
5278static int ext4_get_next_id(struct super_block *sb, struct kqid *qid)
5279{
5280 const struct quota_format_ops *ops;
5281
5282 if (!sb_has_quota_loaded(sb, qid->type))
5283 return -ESRCH;
5284 ops = sb_dqopt(sb)->ops[qid->type];
5285 if (!ops || !ops->get_next_id)
5286 return -ENOSYS;
5287 return dquot_get_next_id(sb, qid);
5288}
5256#endif 5289#endif
5257 5290
5258static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags, 5291static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 0441e055c8e8..e79bd32b9b79 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -230,6 +230,27 @@ ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh)
230 return error; 230 return error;
231} 231}
232 232
233static 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);
244errout:
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
233static inline int 254static inline int
234ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size) 255ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size)
235{ 256{
@@ -341,7 +362,7 @@ ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
341 header = IHDR(inode, raw_inode); 362 header = IHDR(inode, raw_inode);
342 entry = IFIRST(header); 363 entry = IFIRST(header);
343 end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; 364 end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
344 error = ext4_xattr_check_names(entry, end, entry); 365 error = xattr_check_inode(inode, header, end);
345 if (error) 366 if (error)
346 goto cleanup; 367 goto cleanup;
347 error = ext4_xattr_find_entry(&entry, name_index, name, 368 error = ext4_xattr_find_entry(&entry, name_index, name,
@@ -477,7 +498,7 @@ ext4_xattr_ibody_list(struct dentry *dentry, char *buffer, size_t buffer_size)
477 raw_inode = ext4_raw_inode(&iloc); 498 raw_inode = ext4_raw_inode(&iloc);
478 header = IHDR(inode, raw_inode); 499 header = IHDR(inode, raw_inode);
479 end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; 500 end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
480 error = ext4_xattr_check_names(IFIRST(header), end, IFIRST(header)); 501 error = xattr_check_inode(inode, header, end);
481 if (error) 502 if (error)
482 goto cleanup; 503 goto cleanup;
483 error = ext4_xattr_list_entries(dentry, IFIRST(header), 504 error = ext4_xattr_list_entries(dentry, IFIRST(header),
@@ -1040,8 +1061,7 @@ int ext4_xattr_ibody_find(struct inode *inode, struct ext4_xattr_info *i,
1040 is->s.here = is->s.first; 1061 is->s.here = is->s.first;
1041 is->s.end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; 1062 is->s.end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
1042 if (ext4_test_inode_state(inode, EXT4_STATE_XATTR)) { 1063 if (ext4_test_inode_state(inode, EXT4_STATE_XATTR)) {
1043 error = ext4_xattr_check_names(IFIRST(header), is->s.end, 1064 error = xattr_check_inode(inode, header, is->s.end);
1044 IFIRST(header));
1045 if (error) 1065 if (error)
1046 return error; 1066 return error;
1047 /* Find the named attribute. */ 1067 /* Find the named attribute. */
@@ -1356,6 +1376,10 @@ retry:
1356 last = entry; 1376 last = entry;
1357 total_ino = sizeof(struct ext4_xattr_ibody_header); 1377 total_ino = sizeof(struct ext4_xattr_ibody_header);
1358 1378
1379 error = xattr_check_inode(inode, header, end);
1380 if (error)
1381 goto cleanup;
1382
1359 free = ext4_xattr_free_space(last, &min_offs, base, &total_ino); 1383 free = ext4_xattr_free_space(last, &min_offs, base, &total_ino);
1360 if (free >= new_extra_isize) { 1384 if (free >= new_extra_isize) {
1361 entry = IFIRST(header); 1385 entry = IFIRST(header);
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index adef506c5786..33eb81738d03 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -377,7 +377,7 @@ int nfs_readdir_xdr_filler(struct page **pages, nfs_readdir_descriptor_t *desc,
377 again: 377 again:
378 timestamp = jiffies; 378 timestamp = jiffies;
379 gencount = nfs_inc_attr_generation_counter(); 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 NFS_SERVER(inode)->dtsize, desc->plus); 381 NFS_SERVER(inode)->dtsize, desc->plus);
382 if (error < 0) { 382 if (error < 0) {
383 /* We requested READDIRPLUS, but the server doesn't grok it */ 383 /* We requested READDIRPLUS, but the server doesn't grok it */
@@ -560,7 +560,7 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en
560 count++; 560 count++;
561 561
562 if (desc->plus != 0) 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 status = nfs_readdir_add_to_array(entry, page); 565 status = nfs_readdir_add_to_array(entry, page);
566 if (status != 0) 566 if (status != 0)
@@ -864,7 +864,7 @@ static bool nfs_dir_mapping_need_revalidate(struct inode *dir)
864 */ 864 */
865static int nfs_readdir(struct file *file, struct dir_context *ctx) 865static 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 struct inode *inode = d_inode(dentry); 868 struct inode *inode = d_inode(dentry);
869 nfs_readdir_descriptor_t my_desc, 869 nfs_readdir_descriptor_t my_desc,
870 *desc = &my_desc; 870 *desc = &my_desc;
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 33d18c411905..738c84a42eb0 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -940,7 +940,7 @@ int nfs_open(struct inode *inode, struct file *filp)
940{ 940{
941 struct nfs_open_context *ctx; 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 if (IS_ERR(ctx)) 944 if (IS_ERR(ctx))
945 return PTR_ERR(ctx); 945 return PTR_ERR(ctx);
946 nfs_file_set_open_context(filp, ctx); 946 nfs_file_set_open_context(filp, ctx);
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index 22c35abbee9d..d0390516467c 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -26,7 +26,7 @@ static int
26nfs4_file_open(struct inode *inode, struct file *filp) 26nfs4_file_open(struct inode *inode, struct file *filp)
27{ 27{
28 struct nfs_open_context *ctx; 28 struct nfs_open_context *ctx;
29 struct dentry *dentry = filp->f_path.dentry; 29 struct dentry *dentry = file_dentry(filp);
30 struct dentry *parent = NULL; 30 struct dentry *parent = NULL;
31 struct inode *dir; 31 struct inode *dir;
32 unsigned openflags = filp->f_flags; 32 unsigned openflags = filp->f_flags;
@@ -57,7 +57,7 @@ nfs4_file_open(struct inode *inode, struct file *filp)
57 parent = dget_parent(dentry); 57 parent = dget_parent(dentry);
58 dir = d_inode(parent); 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 err = PTR_ERR(ctx); 61 err = PTR_ERR(ctx);
62 if (IS_ERR(ctx)) 62 if (IS_ERR(ctx))
63 goto out; 63 goto out;
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index ef64984c9bbc..5d972e6cd3fe 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -295,6 +295,37 @@ static void ovl_dentry_release(struct dentry *dentry)
295 } 295 }
296} 296}
297 297
298static 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
323bug:
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
298static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags) 329static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags)
299{ 330{
300 struct ovl_entry *oe = dentry->d_fsdata; 331 struct ovl_entry *oe = dentry->d_fsdata;
@@ -339,11 +370,13 @@ static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
339static const struct dentry_operations ovl_dentry_operations = { 370static const struct dentry_operations ovl_dentry_operations = {
340 .d_release = ovl_dentry_release, 371 .d_release = ovl_dentry_release,
341 .d_select_inode = ovl_d_select_inode, 372 .d_select_inode = ovl_d_select_inode,
373 .d_real = ovl_d_real,
342}; 374};
343 375
344static const struct dentry_operations ovl_reval_dentry_operations = { 376static const struct dentry_operations ovl_reval_dentry_operations = {
345 .d_release = ovl_dentry_release, 377 .d_release = ovl_dentry_release,
346 .d_select_inode = ovl_d_select_inode, 378 .d_select_inode = ovl_d_select_inode,
379 .d_real = ovl_d_real,
347 .d_revalidate = ovl_dentry_revalidate, 380 .d_revalidate = ovl_dentry_revalidate,
348 .d_weak_revalidate = ovl_dentry_weak_revalidate, 381 .d_weak_revalidate = ovl_dentry_weak_revalidate,
349}; 382};
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 7cb043d8f4e8..4bb4de8d95ea 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -161,6 +161,7 @@ struct dentry_operations {
161 struct vfsmount *(*d_automount)(struct path *); 161 struct vfsmount *(*d_automount)(struct path *);
162 int (*d_manage)(struct dentry *, bool); 162 int (*d_manage)(struct dentry *, bool);
163 struct inode *(*d_select_inode)(struct dentry *, unsigned); 163 struct inode *(*d_select_inode)(struct dentry *, unsigned);
164 struct dentry *(*d_real)(struct dentry *, struct inode *);
164} ____cacheline_aligned; 165} ____cacheline_aligned;
165 166
166/* 167/*
@@ -229,6 +230,7 @@ struct dentry_operations {
229#define DCACHE_OP_SELECT_INODE 0x02000000 /* Unioned entry: dcache op selects inode */ 230#define DCACHE_OP_SELECT_INODE 0x02000000 /* Unioned entry: dcache op selects inode */
230 231
231#define DCACHE_ENCRYPTED_WITH_KEY 0x04000000 /* dir is encrypted with a valid key */ 232#define DCACHE_ENCRYPTED_WITH_KEY 0x04000000 /* dir is encrypted with a valid key */
233#define DCACHE_OP_REAL 0x08000000
232 234
233extern seqlock_t rename_lock; 235extern seqlock_t rename_lock;
234 236
@@ -555,4 +557,12 @@ static inline struct dentry *d_backing_dentry(struct dentry *upper)
555 return upper; 557 return upper;
556} 558}
557 559
560static inline struct dentry *d_real(struct dentry *dentry)
561{
562 if (unlikely(dentry->d_flags & DCACHE_OP_REAL))
563 return dentry->d_op->d_real(dentry, NULL);
564 else
565 return dentry;
566}
567
558#endif /* __LINUX_DCACHE_H */ 568#endif /* __LINUX_DCACHE_H */
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 304991a80e23..70e61b58baaf 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1241,6 +1241,16 @@ static inline struct inode *file_inode(const struct file *f)
1241 return f->f_inode; 1241 return f->f_inode;
1242} 1242}
1243 1243
1244static 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
1244static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl) 1254static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
1245{ 1255{
1246 return locks_lock_inode_wait(file_inode(filp), fl); 1256 return locks_lock_inode_wait(file_inode(filp), fl);