diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-29 14:52:46 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-29 14:52:46 -0400 |
commit | d4f03186c8986ffde34d06fe74a99aab08f7ee0b (patch) | |
tree | 9887bc2405a4f9e17185aa1338dec3ae68246b16 /fs/ext4/namei.c | |
parent | ef13c8afa67518e1d173a6f3b95dd02559879421 (diff) | |
parent | d80d448c6c5bdd32605b78a60fe8081d82d4da0f (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:
"Ext4 bug fixes for 3.17, to provide better handling of memory
allocation failures, and to fix some journaling bugs involving
journal checksums and FALLOC_FL_ZERO_RANGE"
* tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4:
ext4: fix same-dir rename when inline data directory overflows
jbd2: fix descriptor block size handling errors with journal_csum
jbd2: fix infinite loop when recovering corrupt journal blocks
ext4: update i_disksize coherently with block allocation on error path
ext4: fix transaction issues for ext4_fallocate and ext_zero_range
ext4: fix incorect journal credits reservation in ext4_zero_range
ext4: move i_size,i_disksize update routines to helper function
ext4: fix BUG_ON in mb_free_blocks()
ext4: propagate errors up to ext4_find_entry()'s callers
Diffstat (limited to 'fs/ext4/namei.c')
-rw-r--r-- | fs/ext4/namei.c | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index b147a67baa0d..90a3cdca3f88 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
@@ -1227,7 +1227,7 @@ static struct buffer_head * ext4_find_entry (struct inode *dir, | |||
1227 | buffer */ | 1227 | buffer */ |
1228 | int num = 0; | 1228 | int num = 0; |
1229 | ext4_lblk_t nblocks; | 1229 | ext4_lblk_t nblocks; |
1230 | int i, err; | 1230 | int i, err = 0; |
1231 | int namelen; | 1231 | int namelen; |
1232 | 1232 | ||
1233 | *res_dir = NULL; | 1233 | *res_dir = NULL; |
@@ -1264,7 +1264,11 @@ static struct buffer_head * ext4_find_entry (struct inode *dir, | |||
1264 | * return. Otherwise, fall back to doing a search the | 1264 | * return. Otherwise, fall back to doing a search the |
1265 | * old fashioned way. | 1265 | * old fashioned way. |
1266 | */ | 1266 | */ |
1267 | if (bh || (err != ERR_BAD_DX_DIR)) | 1267 | if (err == -ENOENT) |
1268 | return NULL; | ||
1269 | if (err && err != ERR_BAD_DX_DIR) | ||
1270 | return ERR_PTR(err); | ||
1271 | if (bh) | ||
1268 | return bh; | 1272 | return bh; |
1269 | dxtrace(printk(KERN_DEBUG "ext4_find_entry: dx failed, " | 1273 | dxtrace(printk(KERN_DEBUG "ext4_find_entry: dx failed, " |
1270 | "falling back\n")); | 1274 | "falling back\n")); |
@@ -1295,6 +1299,11 @@ restart: | |||
1295 | } | 1299 | } |
1296 | num++; | 1300 | num++; |
1297 | bh = ext4_getblk(NULL, dir, b++, 0, &err); | 1301 | bh = ext4_getblk(NULL, dir, b++, 0, &err); |
1302 | if (unlikely(err)) { | ||
1303 | if (ra_max == 0) | ||
1304 | return ERR_PTR(err); | ||
1305 | break; | ||
1306 | } | ||
1298 | bh_use[ra_max] = bh; | 1307 | bh_use[ra_max] = bh; |
1299 | if (bh) | 1308 | if (bh) |
1300 | ll_rw_block(READ | REQ_META | REQ_PRIO, | 1309 | ll_rw_block(READ | REQ_META | REQ_PRIO, |
@@ -1417,6 +1426,8 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi | |||
1417 | return ERR_PTR(-ENAMETOOLONG); | 1426 | return ERR_PTR(-ENAMETOOLONG); |
1418 | 1427 | ||
1419 | bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL); | 1428 | bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL); |
1429 | if (IS_ERR(bh)) | ||
1430 | return (struct dentry *) bh; | ||
1420 | inode = NULL; | 1431 | inode = NULL; |
1421 | if (bh) { | 1432 | if (bh) { |
1422 | __u32 ino = le32_to_cpu(de->inode); | 1433 | __u32 ino = le32_to_cpu(de->inode); |
@@ -1450,6 +1461,8 @@ struct dentry *ext4_get_parent(struct dentry *child) | |||
1450 | struct buffer_head *bh; | 1461 | struct buffer_head *bh; |
1451 | 1462 | ||
1452 | bh = ext4_find_entry(child->d_inode, &dotdot, &de, NULL); | 1463 | bh = ext4_find_entry(child->d_inode, &dotdot, &de, NULL); |
1464 | if (IS_ERR(bh)) | ||
1465 | return (struct dentry *) bh; | ||
1453 | if (!bh) | 1466 | if (!bh) |
1454 | return ERR_PTR(-ENOENT); | 1467 | return ERR_PTR(-ENOENT); |
1455 | ino = le32_to_cpu(de->inode); | 1468 | ino = le32_to_cpu(de->inode); |
@@ -2727,6 +2740,8 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry) | |||
2727 | 2740 | ||
2728 | retval = -ENOENT; | 2741 | retval = -ENOENT; |
2729 | bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL); | 2742 | bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL); |
2743 | if (IS_ERR(bh)) | ||
2744 | return PTR_ERR(bh); | ||
2730 | if (!bh) | 2745 | if (!bh) |
2731 | goto end_rmdir; | 2746 | goto end_rmdir; |
2732 | 2747 | ||
@@ -2794,6 +2809,8 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) | |||
2794 | 2809 | ||
2795 | retval = -ENOENT; | 2810 | retval = -ENOENT; |
2796 | bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL); | 2811 | bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL); |
2812 | if (IS_ERR(bh)) | ||
2813 | return PTR_ERR(bh); | ||
2797 | if (!bh) | 2814 | if (!bh) |
2798 | goto end_unlink; | 2815 | goto end_unlink; |
2799 | 2816 | ||
@@ -3121,6 +3138,8 @@ static int ext4_find_delete_entry(handle_t *handle, struct inode *dir, | |||
3121 | struct ext4_dir_entry_2 *de; | 3138 | struct ext4_dir_entry_2 *de; |
3122 | 3139 | ||
3123 | bh = ext4_find_entry(dir, d_name, &de, NULL); | 3140 | bh = ext4_find_entry(dir, d_name, &de, NULL); |
3141 | if (IS_ERR(bh)) | ||
3142 | return PTR_ERR(bh); | ||
3124 | if (bh) { | 3143 | if (bh) { |
3125 | retval = ext4_delete_entry(handle, dir, de, bh); | 3144 | retval = ext4_delete_entry(handle, dir, de, bh); |
3126 | brelse(bh); | 3145 | brelse(bh); |
@@ -3128,7 +3147,8 @@ static int ext4_find_delete_entry(handle_t *handle, struct inode *dir, | |||
3128 | return retval; | 3147 | return retval; |
3129 | } | 3148 | } |
3130 | 3149 | ||
3131 | static void ext4_rename_delete(handle_t *handle, struct ext4_renament *ent) | 3150 | static void ext4_rename_delete(handle_t *handle, struct ext4_renament *ent, |
3151 | int force_reread) | ||
3132 | { | 3152 | { |
3133 | int retval; | 3153 | int retval; |
3134 | /* | 3154 | /* |
@@ -3140,7 +3160,8 @@ static void ext4_rename_delete(handle_t *handle, struct ext4_renament *ent) | |||
3140 | if (le32_to_cpu(ent->de->inode) != ent->inode->i_ino || | 3160 | if (le32_to_cpu(ent->de->inode) != ent->inode->i_ino || |
3141 | ent->de->name_len != ent->dentry->d_name.len || | 3161 | ent->de->name_len != ent->dentry->d_name.len || |
3142 | strncmp(ent->de->name, ent->dentry->d_name.name, | 3162 | strncmp(ent->de->name, ent->dentry->d_name.name, |
3143 | ent->de->name_len)) { | 3163 | ent->de->name_len) || |
3164 | force_reread) { | ||
3144 | retval = ext4_find_delete_entry(handle, ent->dir, | 3165 | retval = ext4_find_delete_entry(handle, ent->dir, |
3145 | &ent->dentry->d_name); | 3166 | &ent->dentry->d_name); |
3146 | } else { | 3167 | } else { |
@@ -3191,6 +3212,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
3191 | .dentry = new_dentry, | 3212 | .dentry = new_dentry, |
3192 | .inode = new_dentry->d_inode, | 3213 | .inode = new_dentry->d_inode, |
3193 | }; | 3214 | }; |
3215 | int force_reread; | ||
3194 | int retval; | 3216 | int retval; |
3195 | 3217 | ||
3196 | dquot_initialize(old.dir); | 3218 | dquot_initialize(old.dir); |
@@ -3202,6 +3224,8 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
3202 | dquot_initialize(new.inode); | 3224 | dquot_initialize(new.inode); |
3203 | 3225 | ||
3204 | old.bh = ext4_find_entry(old.dir, &old.dentry->d_name, &old.de, NULL); | 3226 | old.bh = ext4_find_entry(old.dir, &old.dentry->d_name, &old.de, NULL); |
3227 | if (IS_ERR(old.bh)) | ||
3228 | return PTR_ERR(old.bh); | ||
3205 | /* | 3229 | /* |
3206 | * Check for inode number is _not_ due to possible IO errors. | 3230 | * Check for inode number is _not_ due to possible IO errors. |
3207 | * We might rmdir the source, keep it as pwd of some process | 3231 | * We might rmdir the source, keep it as pwd of some process |
@@ -3214,6 +3238,10 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
3214 | 3238 | ||
3215 | new.bh = ext4_find_entry(new.dir, &new.dentry->d_name, | 3239 | new.bh = ext4_find_entry(new.dir, &new.dentry->d_name, |
3216 | &new.de, &new.inlined); | 3240 | &new.de, &new.inlined); |
3241 | if (IS_ERR(new.bh)) { | ||
3242 | retval = PTR_ERR(new.bh); | ||
3243 | goto end_rename; | ||
3244 | } | ||
3217 | if (new.bh) { | 3245 | if (new.bh) { |
3218 | if (!new.inode) { | 3246 | if (!new.inode) { |
3219 | brelse(new.bh); | 3247 | brelse(new.bh); |
@@ -3246,6 +3274,15 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
3246 | if (retval) | 3274 | if (retval) |
3247 | goto end_rename; | 3275 | goto end_rename; |
3248 | } | 3276 | } |
3277 | /* | ||
3278 | * If we're renaming a file within an inline_data dir and adding or | ||
3279 | * setting the new dirent causes a conversion from inline_data to | ||
3280 | * extents/blockmap, we need to force the dirent delete code to | ||
3281 | * re-read the directory, or else we end up trying to delete a dirent | ||
3282 | * from what is now the extent tree root (or a block map). | ||
3283 | */ | ||
3284 | force_reread = (new.dir->i_ino == old.dir->i_ino && | ||
3285 | ext4_test_inode_flag(new.dir, EXT4_INODE_INLINE_DATA)); | ||
3249 | if (!new.bh) { | 3286 | if (!new.bh) { |
3250 | retval = ext4_add_entry(handle, new.dentry, old.inode); | 3287 | retval = ext4_add_entry(handle, new.dentry, old.inode); |
3251 | if (retval) | 3288 | if (retval) |
@@ -3256,6 +3293,9 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
3256 | if (retval) | 3293 | if (retval) |
3257 | goto end_rename; | 3294 | goto end_rename; |
3258 | } | 3295 | } |
3296 | if (force_reread) | ||
3297 | force_reread = !ext4_test_inode_flag(new.dir, | ||
3298 | EXT4_INODE_INLINE_DATA); | ||
3259 | 3299 | ||
3260 | /* | 3300 | /* |
3261 | * Like most other Unix systems, set the ctime for inodes on a | 3301 | * Like most other Unix systems, set the ctime for inodes on a |
@@ -3267,7 +3307,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
3267 | /* | 3307 | /* |
3268 | * ok, that's it | 3308 | * ok, that's it |
3269 | */ | 3309 | */ |
3270 | ext4_rename_delete(handle, &old); | 3310 | ext4_rename_delete(handle, &old, force_reread); |
3271 | 3311 | ||
3272 | if (new.inode) { | 3312 | if (new.inode) { |
3273 | ext4_dec_count(handle, new.inode); | 3313 | ext4_dec_count(handle, new.inode); |
@@ -3330,6 +3370,8 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
3330 | 3370 | ||
3331 | old.bh = ext4_find_entry(old.dir, &old.dentry->d_name, | 3371 | old.bh = ext4_find_entry(old.dir, &old.dentry->d_name, |
3332 | &old.de, &old.inlined); | 3372 | &old.de, &old.inlined); |
3373 | if (IS_ERR(old.bh)) | ||
3374 | return PTR_ERR(old.bh); | ||
3333 | /* | 3375 | /* |
3334 | * Check for inode number is _not_ due to possible IO errors. | 3376 | * Check for inode number is _not_ due to possible IO errors. |
3335 | * We might rmdir the source, keep it as pwd of some process | 3377 | * We might rmdir the source, keep it as pwd of some process |
@@ -3342,6 +3384,10 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
3342 | 3384 | ||
3343 | new.bh = ext4_find_entry(new.dir, &new.dentry->d_name, | 3385 | new.bh = ext4_find_entry(new.dir, &new.dentry->d_name, |
3344 | &new.de, &new.inlined); | 3386 | &new.de, &new.inlined); |
3387 | if (IS_ERR(new.bh)) { | ||
3388 | retval = PTR_ERR(new.bh); | ||
3389 | goto end_rename; | ||
3390 | } | ||
3345 | 3391 | ||
3346 | /* RENAME_EXCHANGE case: old *and* new must both exist */ | 3392 | /* RENAME_EXCHANGE case: old *and* new must both exist */ |
3347 | if (!new.bh || le32_to_cpu(new.de->inode) != new.inode->i_ino) | 3393 | if (!new.bh || le32_to_cpu(new.de->inode) != new.inode->i_ino) |