Merge tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4

Pull ext4 fixes from Ted Ts'o:
"Miscellaneous ext4 bug fixes for 5.1"

* tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4:
ext4: prohibit fstrim in norecovery mode
ext4: cleanup bh release code in ext4_ind_remove_space()
ext4: brelse all indirect buffer in ext4_ind_remove_space()
ext4: report real fs size after failed resize
ext4: add missing brelse() in add_new_gdb_meta_bg()
ext4: remove useless ext4_pin_inode()
ext4: avoid panic during forced reboot
ext4: fix data corruption caused by unaligned direct AIO
ext4: fix NULL pointer dereference while journal is aborted

+1 -1
fs/ext4/ext4_jbd2.h
··· 384 384 { 385 385 struct ext4_inode_info *ei = EXT4_I(inode); 386 386 387 - if (ext4_handle_valid(handle)) { 387 + if (ext4_handle_valid(handle) && !is_handle_aborted(handle)) { 388 388 ei->i_sync_tid = handle->h_transaction->t_tid; 389 389 if (datasync) 390 390 ei->i_datasync_tid = handle->h_transaction->t_tid;
+1 -1
fs/ext4/file.c
··· 125 125 struct super_block *sb = inode->i_sb; 126 126 int blockmask = sb->s_blocksize - 1; 127 127 128 - if (pos >= i_size_read(inode)) 128 + if (pos >= ALIGN(i_size_read(inode), sb->s_blocksize)) 129 129 return 0; 130 130 131 131 if ((pos | iov_iter_alignment(from)) & blockmask)
+22 -21
fs/ext4/indirect.c
··· 1222 1222 ext4_lblk_t offsets[4], offsets2[4]; 1223 1223 Indirect chain[4], chain2[4]; 1224 1224 Indirect *partial, *partial2; 1225 + Indirect *p = NULL, *p2 = NULL; 1225 1226 ext4_lblk_t max_block; 1226 1227 __le32 nr = 0, nr2 = 0; 1227 1228 int n = 0, n2 = 0; ··· 1264 1263 } 1265 1264 1266 1265 1267 - partial = ext4_find_shared(inode, n, offsets, chain, &nr); 1266 + partial = p = ext4_find_shared(inode, n, offsets, chain, &nr); 1268 1267 if (nr) { 1269 1268 if (partial == chain) { 1270 1269 /* Shared branch grows from the inode */ ··· 1289 1288 partial->p + 1, 1290 1289 (__le32 *)partial->bh->b_data+addr_per_block, 1291 1290 (chain+n-1) - partial); 1292 - BUFFER_TRACE(partial->bh, "call brelse"); 1293 - brelse(partial->bh); 1294 1291 partial--; 1295 1292 } 1296 1293 1297 1294 end_range: 1298 - partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); 1295 + partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); 1299 1296 if (nr2) { 1300 1297 if (partial2 == chain2) { 1301 1298 /* ··· 1323 1324 (__le32 *)partial2->bh->b_data, 1324 1325 partial2->p, 1325 1326 (chain2+n2-1) - partial2); 1326 - BUFFER_TRACE(partial2->bh, "call brelse"); 1327 - brelse(partial2->bh); 1328 1327 partial2--; 1329 1328 } 1330 1329 goto do_indirects; 1331 1330 } 1332 1331 1333 1332 /* Punch happened within the same level (n == n2) */ 1334 - partial = ext4_find_shared(inode, n, offsets, chain, &nr); 1335 - partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); 1333 + partial = p = ext4_find_shared(inode, n, offsets, chain, &nr); 1334 + partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); 1336 1335 1337 1336 /* Free top, but only if partial2 isn't its subtree. */ 1338 1337 if (nr) { ··· 1387 1390 partial->p + 1, 1388 1391 partial2->p, 1389 1392 (chain+n-1) - partial); 1390 - BUFFER_TRACE(partial->bh, "call brelse"); 1391 - brelse(partial->bh); 1392 - BUFFER_TRACE(partial2->bh, "call brelse"); 1393 - brelse(partial2->bh); 1394 - return 0; 1393 + goto cleanup; 1395 1394 } 1396 1395 1397 1396 /* ··· 1402 1409 partial->p + 1, 1403 1410 (__le32 *)partial->bh->b_data+addr_per_block, 1404 1411 (chain+n-1) - partial); 1405 - BUFFER_TRACE(partial->bh, "call brelse"); 1406 - brelse(partial->bh); 1407 1412 partial--; 1408 1413 } 1409 1414 if (partial2 > chain2 && depth2 <= depth) { ··· 1409 1418 (__le32 *)partial2->bh->b_data, 1410 1419 partial2->p, 1411 1420 (chain2+n2-1) - partial2); 1412 - BUFFER_TRACE(partial2->bh, "call brelse"); 1413 - brelse(partial2->bh); 1414 1421 partial2--; 1415 1422 } 1423 + } 1424 + 1425 + cleanup: 1426 + while (p && p > chain) { 1427 + BUFFER_TRACE(p->bh, "call brelse"); 1428 + brelse(p->bh); 1429 + p--; 1430 + } 1431 + while (p2 && p2 > chain2) { 1432 + BUFFER_TRACE(p2->bh, "call brelse"); 1433 + brelse(p2->bh); 1434 + p2--; 1416 1435 } 1417 1436 return 0; 1418 1437 ··· 1431 1430 switch (offsets[0]) { 1432 1431 default: 1433 1432 if (++n >= n2) 1434 - return 0; 1433 + break; 1435 1434 nr = i_data[EXT4_IND_BLOCK]; 1436 1435 if (nr) { 1437 1436 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 1); ··· 1440 1439 /* fall through */ 1441 1440 case EXT4_IND_BLOCK: 1442 1441 if (++n >= n2) 1443 - return 0; 1442 + break; 1444 1443 nr = i_data[EXT4_DIND_BLOCK]; 1445 1444 if (nr) { 1446 1445 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 2); ··· 1449 1448 /* fall through */ 1450 1449 case EXT4_DIND_BLOCK: 1451 1450 if (++n >= n2) 1452 - return 0; 1451 + break; 1453 1452 nr = i_data[EXT4_TIND_BLOCK]; 1454 1453 if (nr) { 1455 1454 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 3); ··· 1459 1458 case EXT4_TIND_BLOCK: 1460 1459 ; 1461 1460 } 1462 - return 0; 1461 + goto cleanup; 1463 1462 }
-30
fs/ext4/inode.c
··· 6080 6080 return; 6081 6081 } 6082 6082 6083 - #if 0 6084 - /* 6085 - * Bind an inode's backing buffer_head into this transaction, to prevent 6086 - * it from being flushed to disk early. Unlike 6087 - * ext4_reserve_inode_write, this leaves behind no bh reference and 6088 - * returns no iloc structure, so the caller needs to repeat the iloc 6089 - * lookup to mark the inode dirty later. 6090 - */ 6091 - static int ext4_pin_inode(handle_t *handle, struct inode *inode) 6092 - { 6093 - struct ext4_iloc iloc; 6094 - 6095 - int err = 0; 6096 - if (handle) { 6097 - err = ext4_get_inode_loc(inode, &iloc); 6098 - if (!err) { 6099 - BUFFER_TRACE(iloc.bh, "get_write_access"); 6100 - err = jbd2_journal_get_write_access(handle, iloc.bh); 6101 - if (!err) 6102 - err = ext4_handle_dirty_metadata(handle, 6103 - NULL, 6104 - iloc.bh); 6105 - brelse(iloc.bh); 6106 - } 6107 - } 6108 - ext4_std_error(inode->i_sb, err); 6109 - return err; 6110 - } 6111 - #endif 6112 - 6113 6083 int ext4_change_inode_journal_flag(struct inode *inode, int val) 6114 6084 { 6115 6085 journal_t *journal;
+7
fs/ext4/ioctl.c
··· 1000 1000 if (!blk_queue_discard(q)) 1001 1001 return -EOPNOTSUPP; 1002 1002 1003 + /* 1004 + * We haven't replayed the journal, so we cannot use our 1005 + * block-bitmap-guided storage zapping commands. 1006 + */ 1007 + if (test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb)) 1008 + return -EROFS; 1009 + 1003 1010 if (copy_from_user(&range, (struct fstrim_range __user *)arg, 1004 1011 sizeof(range))) 1005 1012 return -EFAULT;
+14 -3
fs/ext4/resize.c
··· 932 932 memcpy(n_group_desc, o_group_desc, 933 933 EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *)); 934 934 n_group_desc[gdb_num] = gdb_bh; 935 + 936 + BUFFER_TRACE(gdb_bh, "get_write_access"); 937 + err = ext4_journal_get_write_access(handle, gdb_bh); 938 + if (err) { 939 + kvfree(n_group_desc); 940 + brelse(gdb_bh); 941 + return err; 942 + } 943 + 935 944 EXT4_SB(sb)->s_group_desc = n_group_desc; 936 945 EXT4_SB(sb)->s_gdb_count++; 937 946 kvfree(o_group_desc); 938 - BUFFER_TRACE(gdb_bh, "get_write_access"); 939 - err = ext4_journal_get_write_access(handle, gdb_bh); 940 947 return err; 941 948 } 942 949 ··· 2080 2073 free_flex_gd(flex_gd); 2081 2074 if (resize_inode != NULL) 2082 2075 iput(resize_inode); 2083 - ext4_msg(sb, KERN_INFO, "resized filesystem to %llu", n_blocks_count); 2076 + if (err) 2077 + ext4_warning(sb, "error (%d) occurred during " 2078 + "file system resize", err); 2079 + ext4_msg(sb, KERN_INFO, "resized filesystem to %llu", 2080 + ext4_blocks_count(es)); 2084 2081 return err; 2085 2082 }
+13 -3
fs/ext4/super.c
··· 430 430 spin_unlock(&sbi->s_md_lock); 431 431 } 432 432 433 + static bool system_going_down(void) 434 + { 435 + return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF 436 + || system_state == SYSTEM_RESTART; 437 + } 438 + 433 439 /* Deal with the reporting of failure conditions on a filesystem such as 434 440 * inconsistencies detected or read IO failures. 435 441 * ··· 466 460 if (journal) 467 461 jbd2_journal_abort(journal, -EIO); 468 462 } 469 - if (test_opt(sb, ERRORS_RO)) { 463 + /* 464 + * We force ERRORS_RO behavior when system is rebooting. Otherwise we 465 + * could panic during 'reboot -f' as the underlying device got already 466 + * disabled. 467 + */ 468 + if (test_opt(sb, ERRORS_RO) || system_going_down()) { 470 469 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); 471 470 /* 472 471 * Make sure updated value of ->s_mount_flags will be visible ··· 479 468 */ 480 469 smp_wmb(); 481 470 sb->s_flags |= SB_RDONLY; 482 - } 483 - if (test_opt(sb, ERRORS_PANIC)) { 471 + } else if (test_opt(sb, ERRORS_PANIC)) { 484 472 if (EXT4_SB(sb)->s_journal && 485 473 !(EXT4_SB(sb)->s_journal->j_flags & JBD2_REC_ERR)) 486 474 return;