diff options
Diffstat (limited to 'fs/ext4/inode.c')
| -rw-r--r-- | fs/ext4/inode.c | 322 |
1 files changed, 235 insertions, 87 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index be21a5ae33cb..a6444cee0c7e 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
| @@ -34,6 +34,7 @@ | |||
| 34 | #include <linux/writeback.h> | 34 | #include <linux/writeback.h> |
| 35 | #include <linux/pagevec.h> | 35 | #include <linux/pagevec.h> |
| 36 | #include <linux/mpage.h> | 36 | #include <linux/mpage.h> |
| 37 | #include <linux/namei.h> | ||
| 37 | #include <linux/uio.h> | 38 | #include <linux/uio.h> |
| 38 | #include <linux/bio.h> | 39 | #include <linux/bio.h> |
| 39 | #include "ext4_jbd2.h" | 40 | #include "ext4_jbd2.h" |
| @@ -71,12 +72,17 @@ static int ext4_inode_is_fast_symlink(struct inode *inode) | |||
| 71 | * "bh" may be NULL: a metadata block may have been freed from memory | 72 | * "bh" may be NULL: a metadata block may have been freed from memory |
| 72 | * but there may still be a record of it in the journal, and that record | 73 | * but there may still be a record of it in the journal, and that record |
| 73 | * still needs to be revoked. | 74 | * still needs to be revoked. |
| 75 | * | ||
| 76 | * If the handle isn't valid we're not journaling so there's nothing to do. | ||
| 74 | */ | 77 | */ |
| 75 | int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode, | 78 | int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode, |
| 76 | struct buffer_head *bh, ext4_fsblk_t blocknr) | 79 | struct buffer_head *bh, ext4_fsblk_t blocknr) |
| 77 | { | 80 | { |
| 78 | int err; | 81 | int err; |
| 79 | 82 | ||
| 83 | if (!ext4_handle_valid(handle)) | ||
| 84 | return 0; | ||
| 85 | |||
| 80 | might_sleep(); | 86 | might_sleep(); |
| 81 | 87 | ||
| 82 | BUFFER_TRACE(bh, "enter"); | 88 | BUFFER_TRACE(bh, "enter"); |
| @@ -169,7 +175,9 @@ static handle_t *start_transaction(struct inode *inode) | |||
| 169 | */ | 175 | */ |
| 170 | static int try_to_extend_transaction(handle_t *handle, struct inode *inode) | 176 | static int try_to_extend_transaction(handle_t *handle, struct inode *inode) |
| 171 | { | 177 | { |
| 172 | if (handle->h_buffer_credits > EXT4_RESERVE_TRANS_BLOCKS) | 178 | if (!ext4_handle_valid(handle)) |
| 179 | return 0; | ||
| 180 | if (ext4_handle_has_enough_credits(handle, EXT4_RESERVE_TRANS_BLOCKS+1)) | ||
| 173 | return 0; | 181 | return 0; |
| 174 | if (!ext4_journal_extend(handle, blocks_for_truncate(inode))) | 182 | if (!ext4_journal_extend(handle, blocks_for_truncate(inode))) |
| 175 | return 0; | 183 | return 0; |
| @@ -183,6 +191,7 @@ static int try_to_extend_transaction(handle_t *handle, struct inode *inode) | |||
| 183 | */ | 191 | */ |
| 184 | static int ext4_journal_test_restart(handle_t *handle, struct inode *inode) | 192 | static int ext4_journal_test_restart(handle_t *handle, struct inode *inode) |
| 185 | { | 193 | { |
| 194 | BUG_ON(EXT4_JOURNAL(inode) == NULL); | ||
| 186 | jbd_debug(2, "restarting handle %p\n", handle); | 195 | jbd_debug(2, "restarting handle %p\n", handle); |
| 187 | return ext4_journal_restart(handle, blocks_for_truncate(inode)); | 196 | return ext4_journal_restart(handle, blocks_for_truncate(inode)); |
| 188 | } | 197 | } |
| @@ -215,7 +224,7 @@ void ext4_delete_inode(struct inode *inode) | |||
| 215 | } | 224 | } |
| 216 | 225 | ||
| 217 | if (IS_SYNC(inode)) | 226 | if (IS_SYNC(inode)) |
| 218 | handle->h_sync = 1; | 227 | ext4_handle_sync(handle); |
| 219 | inode->i_size = 0; | 228 | inode->i_size = 0; |
| 220 | err = ext4_mark_inode_dirty(handle, inode); | 229 | err = ext4_mark_inode_dirty(handle, inode); |
| 221 | if (err) { | 230 | if (err) { |
| @@ -232,7 +241,7 @@ void ext4_delete_inode(struct inode *inode) | |||
| 232 | * enough credits left in the handle to remove the inode from | 241 | * enough credits left in the handle to remove the inode from |
| 233 | * the orphan list and set the dtime field. | 242 | * the orphan list and set the dtime field. |
| 234 | */ | 243 | */ |
| 235 | if (handle->h_buffer_credits < 3) { | 244 | if (!ext4_handle_has_enough_credits(handle, 3)) { |
| 236 | err = ext4_journal_extend(handle, 3); | 245 | err = ext4_journal_extend(handle, 3); |
| 237 | if (err > 0) | 246 | if (err > 0) |
| 238 | err = ext4_journal_restart(handle, 3); | 247 | err = ext4_journal_restart(handle, 3); |
| @@ -505,10 +514,10 @@ static ext4_fsblk_t ext4_find_goal(struct inode *inode, ext4_lblk_t block, | |||
| 505 | * return the total number of blocks to be allocate, including the | 514 | * return the total number of blocks to be allocate, including the |
| 506 | * direct and indirect blocks. | 515 | * direct and indirect blocks. |
| 507 | */ | 516 | */ |
| 508 | static int ext4_blks_to_allocate(Indirect *branch, int k, unsigned long blks, | 517 | static int ext4_blks_to_allocate(Indirect *branch, int k, unsigned int blks, |
| 509 | int blocks_to_boundary) | 518 | int blocks_to_boundary) |
| 510 | { | 519 | { |
| 511 | unsigned long count = 0; | 520 | unsigned int count = 0; |
| 512 | 521 | ||
| 513 | /* | 522 | /* |
| 514 | * Simple case, [t,d]Indirect block(s) has not allocated yet | 523 | * Simple case, [t,d]Indirect block(s) has not allocated yet |
| @@ -546,6 +555,7 @@ static int ext4_alloc_blocks(handle_t *handle, struct inode *inode, | |||
| 546 | int indirect_blks, int blks, | 555 | int indirect_blks, int blks, |
| 547 | ext4_fsblk_t new_blocks[4], int *err) | 556 | ext4_fsblk_t new_blocks[4], int *err) |
| 548 | { | 557 | { |
| 558 | struct ext4_allocation_request ar; | ||
| 549 | int target, i; | 559 | int target, i; |
| 550 | unsigned long count = 0, blk_allocated = 0; | 560 | unsigned long count = 0, blk_allocated = 0; |
| 551 | int index = 0; | 561 | int index = 0; |
| @@ -594,10 +604,17 @@ static int ext4_alloc_blocks(handle_t *handle, struct inode *inode, | |||
| 594 | if (!target) | 604 | if (!target) |
| 595 | goto allocated; | 605 | goto allocated; |
| 596 | /* Now allocate data blocks */ | 606 | /* Now allocate data blocks */ |
| 597 | count = target; | 607 | memset(&ar, 0, sizeof(ar)); |
| 598 | /* allocating blocks for data blocks */ | 608 | ar.inode = inode; |
| 599 | current_block = ext4_new_blocks(handle, inode, iblock, | 609 | ar.goal = goal; |
| 600 | goal, &count, err); | 610 | ar.len = target; |
| 611 | ar.logical = iblock; | ||
| 612 | if (S_ISREG(inode->i_mode)) | ||
| 613 | /* enable in-core preallocation only for regular files */ | ||
| 614 | ar.flags = EXT4_MB_HINT_DATA; | ||
| 615 | |||
| 616 | current_block = ext4_mb_new_blocks(handle, &ar, err); | ||
| 617 | |||
| 601 | if (*err && (target == blks)) { | 618 | if (*err && (target == blks)) { |
| 602 | /* | 619 | /* |
| 603 | * if the allocation failed and we didn't allocate | 620 | * if the allocation failed and we didn't allocate |
| @@ -613,7 +630,7 @@ static int ext4_alloc_blocks(handle_t *handle, struct inode *inode, | |||
| 613 | */ | 630 | */ |
| 614 | new_blocks[index] = current_block; | 631 | new_blocks[index] = current_block; |
| 615 | } | 632 | } |
| 616 | blk_allocated += count; | 633 | blk_allocated += ar.len; |
| 617 | } | 634 | } |
| 618 | allocated: | 635 | allocated: |
| 619 | /* total number of blocks allocated for direct blocks */ | 636 | /* total number of blocks allocated for direct blocks */ |
| @@ -708,8 +725,8 @@ static int ext4_alloc_branch(handle_t *handle, struct inode *inode, | |||
| 708 | set_buffer_uptodate(bh); | 725 | set_buffer_uptodate(bh); |
| 709 | unlock_buffer(bh); | 726 | unlock_buffer(bh); |
| 710 | 727 | ||
| 711 | BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata"); | 728 | BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); |
| 712 | err = ext4_journal_dirty_metadata(handle, bh); | 729 | err = ext4_handle_dirty_metadata(handle, inode, bh); |
| 713 | if (err) | 730 | if (err) |
| 714 | goto failed; | 731 | goto failed; |
| 715 | } | 732 | } |
| @@ -791,8 +808,8 @@ static int ext4_splice_branch(handle_t *handle, struct inode *inode, | |||
| 791 | * generic_commit_write->__mark_inode_dirty->ext4_dirty_inode. | 808 | * generic_commit_write->__mark_inode_dirty->ext4_dirty_inode. |
| 792 | */ | 809 | */ |
| 793 | jbd_debug(5, "splicing indirect only\n"); | 810 | jbd_debug(5, "splicing indirect only\n"); |
| 794 | BUFFER_TRACE(where->bh, "call ext4_journal_dirty_metadata"); | 811 | BUFFER_TRACE(where->bh, "call ext4_handle_dirty_metadata"); |
| 795 | err = ext4_journal_dirty_metadata(handle, where->bh); | 812 | err = ext4_handle_dirty_metadata(handle, inode, where->bh); |
| 796 | if (err) | 813 | if (err) |
| 797 | goto err_out; | 814 | goto err_out; |
| 798 | } else { | 815 | } else { |
| @@ -839,10 +856,10 @@ err_out: | |||
| 839 | * down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system block | 856 | * down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system block |
| 840 | * (ie, create is zero). Otherwise down_write(&EXT4_I(inode)->i_data_sem) | 857 | * (ie, create is zero). Otherwise down_write(&EXT4_I(inode)->i_data_sem) |
| 841 | */ | 858 | */ |
| 842 | int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, | 859 | static int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, |
| 843 | ext4_lblk_t iblock, unsigned long maxblocks, | 860 | ext4_lblk_t iblock, unsigned int maxblocks, |
| 844 | struct buffer_head *bh_result, | 861 | struct buffer_head *bh_result, |
| 845 | int create, int extend_disksize) | 862 | int create, int extend_disksize) |
| 846 | { | 863 | { |
| 847 | int err = -EIO; | 864 | int err = -EIO; |
| 848 | ext4_lblk_t offsets[4]; | 865 | ext4_lblk_t offsets[4]; |
| @@ -1044,7 +1061,7 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used) | |||
| 1044 | * It returns the error in case of allocation failure. | 1061 | * It returns the error in case of allocation failure. |
| 1045 | */ | 1062 | */ |
| 1046 | int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, | 1063 | int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, |
| 1047 | unsigned long max_blocks, struct buffer_head *bh, | 1064 | unsigned int max_blocks, struct buffer_head *bh, |
| 1048 | int create, int extend_disksize, int flag) | 1065 | int create, int extend_disksize, int flag) |
| 1049 | { | 1066 | { |
| 1050 | int retval; | 1067 | int retval; |
| @@ -1220,8 +1237,8 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, | |||
| 1220 | set_buffer_uptodate(bh); | 1237 | set_buffer_uptodate(bh); |
| 1221 | } | 1238 | } |
| 1222 | unlock_buffer(bh); | 1239 | unlock_buffer(bh); |
| 1223 | BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata"); | 1240 | BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); |
| 1224 | err = ext4_journal_dirty_metadata(handle, bh); | 1241 | err = ext4_handle_dirty_metadata(handle, inode, bh); |
| 1225 | if (!fatal) | 1242 | if (!fatal) |
| 1226 | fatal = err; | 1243 | fatal = err; |
| 1227 | } else { | 1244 | } else { |
| @@ -1334,6 +1351,10 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, | |||
| 1334 | pgoff_t index; | 1351 | pgoff_t index; |
| 1335 | unsigned from, to; | 1352 | unsigned from, to; |
| 1336 | 1353 | ||
| 1354 | trace_mark(ext4_write_begin, | ||
| 1355 | "dev %s ino %lu pos %llu len %u flags %u", | ||
| 1356 | inode->i_sb->s_id, inode->i_ino, | ||
| 1357 | (unsigned long long) pos, len, flags); | ||
| 1337 | index = pos >> PAGE_CACHE_SHIFT; | 1358 | index = pos >> PAGE_CACHE_SHIFT; |
| 1338 | from = pos & (PAGE_CACHE_SIZE - 1); | 1359 | from = pos & (PAGE_CACHE_SIZE - 1); |
| 1339 | to = from + len; | 1360 | to = from + len; |
| @@ -1345,7 +1366,7 @@ retry: | |||
| 1345 | goto out; | 1366 | goto out; |
| 1346 | } | 1367 | } |
| 1347 | 1368 | ||
| 1348 | page = __grab_cache_page(mapping, index); | 1369 | page = grab_cache_page_write_begin(mapping, index, flags); |
| 1349 | if (!page) { | 1370 | if (!page) { |
| 1350 | ext4_journal_stop(handle); | 1371 | ext4_journal_stop(handle); |
| 1351 | ret = -ENOMEM; | 1372 | ret = -ENOMEM; |
| @@ -1386,7 +1407,7 @@ static int write_end_fn(handle_t *handle, struct buffer_head *bh) | |||
| 1386 | if (!buffer_mapped(bh) || buffer_freed(bh)) | 1407 | if (!buffer_mapped(bh) || buffer_freed(bh)) |
| 1387 | return 0; | 1408 | return 0; |
| 1388 | set_buffer_uptodate(bh); | 1409 | set_buffer_uptodate(bh); |
| 1389 | return ext4_journal_dirty_metadata(handle, bh); | 1410 | return ext4_handle_dirty_metadata(handle, NULL, bh); |
| 1390 | } | 1411 | } |
| 1391 | 1412 | ||
| 1392 | /* | 1413 | /* |
| @@ -1405,6 +1426,10 @@ static int ext4_ordered_write_end(struct file *file, | |||
| 1405 | struct inode *inode = mapping->host; | 1426 | struct inode *inode = mapping->host; |
| 1406 | int ret = 0, ret2; | 1427 | int ret = 0, ret2; |
| 1407 | 1428 | ||
| 1429 | trace_mark(ext4_ordered_write_end, | ||
| 1430 | "dev %s ino %lu pos %llu len %u copied %u", | ||
| 1431 | inode->i_sb->s_id, inode->i_ino, | ||
| 1432 | (unsigned long long) pos, len, copied); | ||
| 1408 | ret = ext4_jbd2_file_inode(handle, inode); | 1433 | ret = ext4_jbd2_file_inode(handle, inode); |
| 1409 | 1434 | ||
| 1410 | if (ret == 0) { | 1435 | if (ret == 0) { |
| @@ -1443,6 +1468,10 @@ static int ext4_writeback_write_end(struct file *file, | |||
| 1443 | int ret = 0, ret2; | 1468 | int ret = 0, ret2; |
| 1444 | loff_t new_i_size; | 1469 | loff_t new_i_size; |
| 1445 | 1470 | ||
| 1471 | trace_mark(ext4_writeback_write_end, | ||
| 1472 | "dev %s ino %lu pos %llu len %u copied %u", | ||
| 1473 | inode->i_sb->s_id, inode->i_ino, | ||
| 1474 | (unsigned long long) pos, len, copied); | ||
| 1446 | new_i_size = pos + copied; | 1475 | new_i_size = pos + copied; |
| 1447 | if (new_i_size > EXT4_I(inode)->i_disksize) { | 1476 | if (new_i_size > EXT4_I(inode)->i_disksize) { |
| 1448 | ext4_update_i_disksize(inode, new_i_size); | 1477 | ext4_update_i_disksize(inode, new_i_size); |
| @@ -1478,6 +1507,10 @@ static int ext4_journalled_write_end(struct file *file, | |||
| 1478 | unsigned from, to; | 1507 | unsigned from, to; |
| 1479 | loff_t new_i_size; | 1508 | loff_t new_i_size; |
| 1480 | 1509 | ||
| 1510 | trace_mark(ext4_journalled_write_end, | ||
| 1511 | "dev %s ino %lu pos %llu len %u copied %u", | ||
| 1512 | inode->i_sb->s_id, inode->i_ino, | ||
| 1513 | (unsigned long long) pos, len, copied); | ||
| 1481 | from = pos & (PAGE_CACHE_SIZE - 1); | 1514 | from = pos & (PAGE_CACHE_SIZE - 1); |
| 1482 | to = from + len; | 1515 | to = from + len; |
| 1483 | 1516 | ||
| @@ -1624,7 +1657,7 @@ struct mpage_da_data { | |||
| 1624 | get_block_t *get_block; | 1657 | get_block_t *get_block; |
| 1625 | struct writeback_control *wbc; | 1658 | struct writeback_control *wbc; |
| 1626 | int io_done; | 1659 | int io_done; |
| 1627 | long pages_written; | 1660 | int pages_written; |
| 1628 | int retval; | 1661 | int retval; |
| 1629 | }; | 1662 | }; |
| 1630 | 1663 | ||
| @@ -1644,35 +1677,39 @@ struct mpage_da_data { | |||
| 1644 | */ | 1677 | */ |
| 1645 | static int mpage_da_submit_io(struct mpage_da_data *mpd) | 1678 | static int mpage_da_submit_io(struct mpage_da_data *mpd) |
| 1646 | { | 1679 | { |
| 1647 | struct address_space *mapping = mpd->inode->i_mapping; | ||
| 1648 | int ret = 0, err, nr_pages, i; | ||
| 1649 | unsigned long index, end; | ||
| 1650 | struct pagevec pvec; | ||
| 1651 | long pages_skipped; | 1680 | long pages_skipped; |
| 1681 | struct pagevec pvec; | ||
| 1682 | unsigned long index, end; | ||
| 1683 | int ret = 0, err, nr_pages, i; | ||
| 1684 | struct inode *inode = mpd->inode; | ||
| 1685 | struct address_space *mapping = inode->i_mapping; | ||
| 1652 | 1686 | ||
| 1653 | BUG_ON(mpd->next_page <= mpd->first_page); | 1687 | BUG_ON(mpd->next_page <= mpd->first_page); |
| 1654 | pagevec_init(&pvec, 0); | 1688 | /* |
| 1689 | * We need to start from the first_page to the next_page - 1 | ||
| 1690 | * to make sure we also write the mapped dirty buffer_heads. | ||
| 1691 | * If we look at mpd->lbh.b_blocknr we would only be looking | ||
| 1692 | * at the currently mapped buffer_heads. | ||
| 1693 | */ | ||
| 1655 | index = mpd->first_page; | 1694 | index = mpd->first_page; |
| 1656 | end = mpd->next_page - 1; | 1695 | end = mpd->next_page - 1; |
| 1657 | 1696 | ||
| 1697 | pagevec_init(&pvec, 0); | ||
| 1658 | while (index <= end) { | 1698 | while (index <= end) { |
| 1659 | /* | 1699 | nr_pages = pagevec_lookup(&pvec, mapping, index, PAGEVEC_SIZE); |
| 1660 | * We can use PAGECACHE_TAG_DIRTY lookup here because | ||
| 1661 | * even though we have cleared the dirty flag on the page | ||
| 1662 | * We still keep the page in the radix tree with tag | ||
| 1663 | * PAGECACHE_TAG_DIRTY. See clear_page_dirty_for_io. | ||
| 1664 | * The PAGECACHE_TAG_DIRTY is cleared in set_page_writeback | ||
| 1665 | * which is called via the below writepage callback. | ||
| 1666 | */ | ||
| 1667 | nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, | ||
| 1668 | PAGECACHE_TAG_DIRTY, | ||
| 1669 | min(end - index, | ||
| 1670 | (pgoff_t)PAGEVEC_SIZE-1) + 1); | ||
| 1671 | if (nr_pages == 0) | 1700 | if (nr_pages == 0) |
| 1672 | break; | 1701 | break; |
| 1673 | for (i = 0; i < nr_pages; i++) { | 1702 | for (i = 0; i < nr_pages; i++) { |
| 1674 | struct page *page = pvec.pages[i]; | 1703 | struct page *page = pvec.pages[i]; |
| 1675 | 1704 | ||
| 1705 | index = page->index; | ||
| 1706 | if (index > end) | ||
| 1707 | break; | ||
| 1708 | index++; | ||
| 1709 | |||
| 1710 | BUG_ON(!PageLocked(page)); | ||
| 1711 | BUG_ON(PageWriteback(page)); | ||
| 1712 | |||
| 1676 | pages_skipped = mpd->wbc->pages_skipped; | 1713 | pages_skipped = mpd->wbc->pages_skipped; |
| 1677 | err = mapping->a_ops->writepage(page, mpd->wbc); | 1714 | err = mapping->a_ops->writepage(page, mpd->wbc); |
| 1678 | if (!err && (pages_skipped == mpd->wbc->pages_skipped)) | 1715 | if (!err && (pages_skipped == mpd->wbc->pages_skipped)) |
| @@ -1830,13 +1867,13 @@ static void ext4_print_free_blocks(struct inode *inode) | |||
| 1830 | ext4_count_free_blocks(inode->i_sb)); | 1867 | ext4_count_free_blocks(inode->i_sb)); |
| 1831 | printk(KERN_EMERG "Free/Dirty block details\n"); | 1868 | printk(KERN_EMERG "Free/Dirty block details\n"); |
| 1832 | printk(KERN_EMERG "free_blocks=%lld\n", | 1869 | printk(KERN_EMERG "free_blocks=%lld\n", |
| 1833 | percpu_counter_sum(&sbi->s_freeblocks_counter)); | 1870 | (long long)percpu_counter_sum(&sbi->s_freeblocks_counter)); |
| 1834 | printk(KERN_EMERG "dirty_blocks=%lld\n", | 1871 | printk(KERN_EMERG "dirty_blocks=%lld\n", |
| 1835 | percpu_counter_sum(&sbi->s_dirtyblocks_counter)); | 1872 | (long long)percpu_counter_sum(&sbi->s_dirtyblocks_counter)); |
| 1836 | printk(KERN_EMERG "Block reservation details\n"); | 1873 | printk(KERN_EMERG "Block reservation details\n"); |
| 1837 | printk(KERN_EMERG "i_reserved_data_blocks=%lu\n", | 1874 | printk(KERN_EMERG "i_reserved_data_blocks=%u\n", |
| 1838 | EXT4_I(inode)->i_reserved_data_blocks); | 1875 | EXT4_I(inode)->i_reserved_data_blocks); |
| 1839 | printk(KERN_EMERG "i_reserved_meta_blocks=%lu\n", | 1876 | printk(KERN_EMERG "i_reserved_meta_blocks=%u\n", |
| 1840 | EXT4_I(inode)->i_reserved_meta_blocks); | 1877 | EXT4_I(inode)->i_reserved_meta_blocks); |
| 1841 | return; | 1878 | return; |
| 1842 | } | 1879 | } |
| @@ -2086,11 +2123,29 @@ static int __mpage_da_writepage(struct page *page, | |||
| 2086 | bh = head; | 2123 | bh = head; |
| 2087 | do { | 2124 | do { |
| 2088 | BUG_ON(buffer_locked(bh)); | 2125 | BUG_ON(buffer_locked(bh)); |
| 2126 | /* | ||
| 2127 | * We need to try to allocate | ||
| 2128 | * unmapped blocks in the same page. | ||
| 2129 | * Otherwise we won't make progress | ||
| 2130 | * with the page in ext4_da_writepage | ||
| 2131 | */ | ||
| 2089 | if (buffer_dirty(bh) && | 2132 | if (buffer_dirty(bh) && |
| 2090 | (!buffer_mapped(bh) || buffer_delay(bh))) { | 2133 | (!buffer_mapped(bh) || buffer_delay(bh))) { |
| 2091 | mpage_add_bh_to_extent(mpd, logical, bh); | 2134 | mpage_add_bh_to_extent(mpd, logical, bh); |
| 2092 | if (mpd->io_done) | 2135 | if (mpd->io_done) |
| 2093 | return MPAGE_DA_EXTENT_TAIL; | 2136 | return MPAGE_DA_EXTENT_TAIL; |
| 2137 | } else if (buffer_dirty(bh) && (buffer_mapped(bh))) { | ||
| 2138 | /* | ||
| 2139 | * mapped dirty buffer. We need to update | ||
| 2140 | * the b_state because we look at | ||
| 2141 | * b_state in mpage_da_map_blocks. We don't | ||
| 2142 | * update b_size because if we find an | ||
| 2143 | * unmapped buffer_head later we need to | ||
| 2144 | * use the b_state flag of that buffer_head. | ||
| 2145 | */ | ||
| 2146 | if (mpd->lbh.b_size == 0) | ||
| 2147 | mpd->lbh.b_state = | ||
| 2148 | bh->b_state & BH_FLAGS; | ||
| 2094 | } | 2149 | } |
| 2095 | logical++; | 2150 | logical++; |
| 2096 | } while ((bh = bh->b_this_page) != head); | 2151 | } while ((bh = bh->b_this_page) != head); |
| @@ -2268,10 +2323,13 @@ static int ext4_da_writepage(struct page *page, | |||
| 2268 | { | 2323 | { |
| 2269 | int ret = 0; | 2324 | int ret = 0; |
| 2270 | loff_t size; | 2325 | loff_t size; |
| 2271 | unsigned long len; | 2326 | unsigned int len; |
| 2272 | struct buffer_head *page_bufs; | 2327 | struct buffer_head *page_bufs; |
| 2273 | struct inode *inode = page->mapping->host; | 2328 | struct inode *inode = page->mapping->host; |
| 2274 | 2329 | ||
| 2330 | trace_mark(ext4_da_writepage, | ||
| 2331 | "dev %s ino %lu page_index %lu", | ||
| 2332 | inode->i_sb->s_id, inode->i_ino, page->index); | ||
| 2275 | size = i_size_read(inode); | 2333 | size = i_size_read(inode); |
| 2276 | if (page->index == size >> PAGE_CACHE_SHIFT) | 2334 | if (page->index == size >> PAGE_CACHE_SHIFT) |
| 2277 | len = size & ~PAGE_CACHE_MASK; | 2335 | len = size & ~PAGE_CACHE_MASK; |
| @@ -2377,10 +2435,25 @@ static int ext4_da_writepages(struct address_space *mapping, | |||
| 2377 | struct mpage_da_data mpd; | 2435 | struct mpage_da_data mpd; |
| 2378 | struct inode *inode = mapping->host; | 2436 | struct inode *inode = mapping->host; |
| 2379 | int no_nrwrite_index_update; | 2437 | int no_nrwrite_index_update; |
| 2380 | long pages_written = 0, pages_skipped; | 2438 | int pages_written = 0; |
| 2439 | long pages_skipped; | ||
| 2381 | int needed_blocks, ret = 0, nr_to_writebump = 0; | 2440 | int needed_blocks, ret = 0, nr_to_writebump = 0; |
| 2382 | struct ext4_sb_info *sbi = EXT4_SB(mapping->host->i_sb); | 2441 | struct ext4_sb_info *sbi = EXT4_SB(mapping->host->i_sb); |
| 2383 | 2442 | ||
| 2443 | trace_mark(ext4_da_writepages, | ||
| 2444 | "dev %s ino %lu nr_t_write %ld " | ||
| 2445 | "pages_skipped %ld range_start %llu " | ||
| 2446 | "range_end %llu nonblocking %d " | ||
| 2447 | "for_kupdate %d for_reclaim %d " | ||
| 2448 | "for_writepages %d range_cyclic %d", | ||
| 2449 | inode->i_sb->s_id, inode->i_ino, | ||
| 2450 | wbc->nr_to_write, wbc->pages_skipped, | ||
| 2451 | (unsigned long long) wbc->range_start, | ||
| 2452 | (unsigned long long) wbc->range_end, | ||
| 2453 | wbc->nonblocking, wbc->for_kupdate, | ||
| 2454 | wbc->for_reclaim, wbc->for_writepages, | ||
| 2455 | wbc->range_cyclic); | ||
| 2456 | |||
| 2384 | /* | 2457 | /* |
| 2385 | * No pages to write? This is mainly a kludge to avoid starting | 2458 | * No pages to write? This is mainly a kludge to avoid starting |
| 2386 | * a transaction for special inodes like journal inode on last iput() | 2459 | * a transaction for special inodes like journal inode on last iput() |
| @@ -2388,6 +2461,20 @@ static int ext4_da_writepages(struct address_space *mapping, | |||
| 2388 | */ | 2461 | */ |
| 2389 | if (!mapping->nrpages || !mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) | 2462 | if (!mapping->nrpages || !mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) |
| 2390 | return 0; | 2463 | return 0; |
| 2464 | |||
| 2465 | /* | ||
| 2466 | * If the filesystem has aborted, it is read-only, so return | ||
| 2467 | * right away instead of dumping stack traces later on that | ||
| 2468 | * will obscure the real source of the problem. We test | ||
| 2469 | * EXT4_MOUNT_ABORT instead of sb->s_flag's MS_RDONLY because | ||
| 2470 | * the latter could be true if the filesystem is mounted | ||
| 2471 | * read-only, and in that case, ext4_da_writepages should | ||
| 2472 | * *never* be called, so if that ever happens, we would want | ||
| 2473 | * the stack trace. | ||
| 2474 | */ | ||
| 2475 | if (unlikely(sbi->s_mount_opt & EXT4_MOUNT_ABORT)) | ||
| 2476 | return -EROFS; | ||
| 2477 | |||
| 2391 | /* | 2478 | /* |
| 2392 | * Make sure nr_to_write is >= sbi->s_mb_stream_request | 2479 | * Make sure nr_to_write is >= sbi->s_mb_stream_request |
| 2393 | * This make sure small files blocks are allocated in | 2480 | * This make sure small files blocks are allocated in |
| @@ -2432,7 +2519,7 @@ static int ext4_da_writepages(struct address_space *mapping, | |||
| 2432 | handle = ext4_journal_start(inode, needed_blocks); | 2519 | handle = ext4_journal_start(inode, needed_blocks); |
| 2433 | if (IS_ERR(handle)) { | 2520 | if (IS_ERR(handle)) { |
| 2434 | ret = PTR_ERR(handle); | 2521 | ret = PTR_ERR(handle); |
| 2435 | printk(KERN_EMERG "%s: jbd2_start: " | 2522 | printk(KERN_CRIT "%s: jbd2_start: " |
| 2436 | "%ld pages, ino %lu; err %d\n", __func__, | 2523 | "%ld pages, ino %lu; err %d\n", __func__, |
| 2437 | wbc->nr_to_write, inode->i_ino, ret); | 2524 | wbc->nr_to_write, inode->i_ino, ret); |
| 2438 | dump_stack(); | 2525 | dump_stack(); |
| @@ -2485,6 +2572,14 @@ out_writepages: | |||
| 2485 | if (!no_nrwrite_index_update) | 2572 | if (!no_nrwrite_index_update) |
| 2486 | wbc->no_nrwrite_index_update = 0; | 2573 | wbc->no_nrwrite_index_update = 0; |
| 2487 | wbc->nr_to_write -= nr_to_writebump; | 2574 | wbc->nr_to_write -= nr_to_writebump; |
| 2575 | trace_mark(ext4_da_writepage_result, | ||
| 2576 | "dev %s ino %lu ret %d pages_written %d " | ||
| 2577 | "pages_skipped %ld congestion %d " | ||
| 2578 | "more_io %d no_nrwrite_index_update %d", | ||
| 2579 | inode->i_sb->s_id, inode->i_ino, ret, | ||
| 2580 | pages_written, wbc->pages_skipped, | ||
| 2581 | wbc->encountered_congestion, wbc->more_io, | ||
| 2582 | wbc->no_nrwrite_index_update); | ||
| 2488 | return ret; | 2583 | return ret; |
| 2489 | } | 2584 | } |
| 2490 | 2585 | ||
| @@ -2497,7 +2592,7 @@ static int ext4_nonda_switch(struct super_block *sb) | |||
| 2497 | /* | 2592 | /* |
| 2498 | * switch to non delalloc mode if we are running low | 2593 | * switch to non delalloc mode if we are running low |
| 2499 | * on free block. The free block accounting via percpu | 2594 | * on free block. The free block accounting via percpu |
| 2500 | * counters can get slightly wrong with FBC_BATCH getting | 2595 | * counters can get slightly wrong with percpu_counter_batch getting |
| 2501 | * accumulated on each CPU without updating global counters | 2596 | * accumulated on each CPU without updating global counters |
| 2502 | * Delalloc need an accurate free block accounting. So switch | 2597 | * Delalloc need an accurate free block accounting. So switch |
| 2503 | * to non delalloc when we are near to error range. | 2598 | * to non delalloc when we are near to error range. |
| @@ -2536,6 +2631,11 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping, | |||
| 2536 | len, flags, pagep, fsdata); | 2631 | len, flags, pagep, fsdata); |
| 2537 | } | 2632 | } |
| 2538 | *fsdata = (void *)0; | 2633 | *fsdata = (void *)0; |
| 2634 | |||
| 2635 | trace_mark(ext4_da_write_begin, | ||
| 2636 | "dev %s ino %lu pos %llu len %u flags %u", | ||
| 2637 | inode->i_sb->s_id, inode->i_ino, | ||
| 2638 | (unsigned long long) pos, len, flags); | ||
| 2539 | retry: | 2639 | retry: |
| 2540 | /* | 2640 | /* |
| 2541 | * With delayed allocation, we don't log the i_disksize update | 2641 | * With delayed allocation, we don't log the i_disksize update |
| @@ -2549,7 +2649,7 @@ retry: | |||
| 2549 | goto out; | 2649 | goto out; |
| 2550 | } | 2650 | } |
| 2551 | 2651 | ||
| 2552 | page = __grab_cache_page(mapping, index); | 2652 | page = grab_cache_page_write_begin(mapping, index, flags); |
| 2553 | if (!page) { | 2653 | if (!page) { |
| 2554 | ext4_journal_stop(handle); | 2654 | ext4_journal_stop(handle); |
| 2555 | ret = -ENOMEM; | 2655 | ret = -ENOMEM; |
| @@ -2625,6 +2725,10 @@ static int ext4_da_write_end(struct file *file, | |||
| 2625 | } | 2725 | } |
| 2626 | } | 2726 | } |
| 2627 | 2727 | ||
| 2728 | trace_mark(ext4_da_write_end, | ||
| 2729 | "dev %s ino %lu pos %llu len %u copied %u", | ||
| 2730 | inode->i_sb->s_id, inode->i_ino, | ||
| 2731 | (unsigned long long) pos, len, copied); | ||
| 2628 | start = pos & (PAGE_CACHE_SIZE - 1); | 2732 | start = pos & (PAGE_CACHE_SIZE - 1); |
| 2629 | end = start + copied - 1; | 2733 | end = start + copied - 1; |
| 2630 | 2734 | ||
| @@ -2717,7 +2821,10 @@ static sector_t ext4_bmap(struct address_space *mapping, sector_t block) | |||
| 2717 | filemap_write_and_wait(mapping); | 2821 | filemap_write_and_wait(mapping); |
| 2718 | } | 2822 | } |
| 2719 | 2823 | ||
| 2720 | if (EXT4_I(inode)->i_state & EXT4_STATE_JDATA) { | 2824 | BUG_ON(!EXT4_JOURNAL(inode) && |
| 2825 | EXT4_I(inode)->i_state & EXT4_STATE_JDATA); | ||
| 2826 | |||
| 2827 | if (EXT4_JOURNAL(inode) && EXT4_I(inode)->i_state & EXT4_STATE_JDATA) { | ||
| 2721 | /* | 2828 | /* |
| 2722 | * This is a REALLY heavyweight approach, but the use of | 2829 | * This is a REALLY heavyweight approach, but the use of |
| 2723 | * bmap on dirty files is expected to be extremely rare: | 2830 | * bmap on dirty files is expected to be extremely rare: |
| @@ -2835,6 +2942,9 @@ static int ext4_normal_writepage(struct page *page, | |||
| 2835 | loff_t size = i_size_read(inode); | 2942 | loff_t size = i_size_read(inode); |
| 2836 | loff_t len; | 2943 | loff_t len; |
| 2837 | 2944 | ||
| 2945 | trace_mark(ext4_normal_writepage, | ||
| 2946 | "dev %s ino %lu page_index %lu", | ||
| 2947 | inode->i_sb->s_id, inode->i_ino, page->index); | ||
| 2838 | J_ASSERT(PageLocked(page)); | 2948 | J_ASSERT(PageLocked(page)); |
| 2839 | if (page->index == size >> PAGE_CACHE_SHIFT) | 2949 | if (page->index == size >> PAGE_CACHE_SHIFT) |
| 2840 | len = size & ~PAGE_CACHE_MASK; | 2950 | len = size & ~PAGE_CACHE_MASK; |
| @@ -2920,6 +3030,9 @@ static int ext4_journalled_writepage(struct page *page, | |||
| 2920 | loff_t size = i_size_read(inode); | 3030 | loff_t size = i_size_read(inode); |
| 2921 | loff_t len; | 3031 | loff_t len; |
| 2922 | 3032 | ||
| 3033 | trace_mark(ext4_journalled_writepage, | ||
| 3034 | "dev %s ino %lu page_index %lu", | ||
| 3035 | inode->i_sb->s_id, inode->i_ino, page->index); | ||
| 2923 | J_ASSERT(PageLocked(page)); | 3036 | J_ASSERT(PageLocked(page)); |
| 2924 | if (page->index == size >> PAGE_CACHE_SHIFT) | 3037 | if (page->index == size >> PAGE_CACHE_SHIFT) |
| 2925 | len = size & ~PAGE_CACHE_MASK; | 3038 | len = size & ~PAGE_CACHE_MASK; |
| @@ -2988,7 +3101,10 @@ static void ext4_invalidatepage(struct page *page, unsigned long offset) | |||
| 2988 | if (offset == 0) | 3101 | if (offset == 0) |
| 2989 | ClearPageChecked(page); | 3102 | ClearPageChecked(page); |
| 2990 | 3103 | ||
| 2991 | jbd2_journal_invalidatepage(journal, page, offset); | 3104 | if (journal) |
| 3105 | jbd2_journal_invalidatepage(journal, page, offset); | ||
| 3106 | else | ||
| 3107 | block_invalidatepage(page, offset); | ||
| 2992 | } | 3108 | } |
| 2993 | 3109 | ||
| 2994 | static int ext4_releasepage(struct page *page, gfp_t wait) | 3110 | static int ext4_releasepage(struct page *page, gfp_t wait) |
| @@ -2998,7 +3114,10 @@ static int ext4_releasepage(struct page *page, gfp_t wait) | |||
| 2998 | WARN_ON(PageChecked(page)); | 3114 | WARN_ON(PageChecked(page)); |
| 2999 | if (!page_has_buffers(page)) | 3115 | if (!page_has_buffers(page)) |
| 3000 | return 0; | 3116 | return 0; |
| 3001 | return jbd2_journal_try_to_free_buffers(journal, page, wait); | 3117 | if (journal) |
| 3118 | return jbd2_journal_try_to_free_buffers(journal, page, wait); | ||
| 3119 | else | ||
| 3120 | return try_to_free_buffers(page); | ||
| 3002 | } | 3121 | } |
| 3003 | 3122 | ||
| 3004 | /* | 3123 | /* |
| @@ -3270,7 +3389,7 @@ int ext4_block_truncate_page(handle_t *handle, | |||
| 3270 | 3389 | ||
| 3271 | err = 0; | 3390 | err = 0; |
| 3272 | if (ext4_should_journal_data(inode)) { | 3391 | if (ext4_should_journal_data(inode)) { |
| 3273 | err = ext4_journal_dirty_metadata(handle, bh); | 3392 | err = ext4_handle_dirty_metadata(handle, inode, bh); |
| 3274 | } else { | 3393 | } else { |
| 3275 | if (ext4_should_order_data(inode)) | 3394 | if (ext4_should_order_data(inode)) |
| 3276 | err = ext4_jbd2_file_inode(handle, inode); | 3395 | err = ext4_jbd2_file_inode(handle, inode); |
| @@ -3394,8 +3513,8 @@ static void ext4_clear_blocks(handle_t *handle, struct inode *inode, | |||
| 3394 | __le32 *p; | 3513 | __le32 *p; |
| 3395 | if (try_to_extend_transaction(handle, inode)) { | 3514 | if (try_to_extend_transaction(handle, inode)) { |
| 3396 | if (bh) { | 3515 | if (bh) { |
| 3397 | BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata"); | 3516 | BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); |
| 3398 | ext4_journal_dirty_metadata(handle, bh); | 3517 | ext4_handle_dirty_metadata(handle, inode, bh); |
| 3399 | } | 3518 | } |
| 3400 | ext4_mark_inode_dirty(handle, inode); | 3519 | ext4_mark_inode_dirty(handle, inode); |
| 3401 | ext4_journal_test_restart(handle, inode); | 3520 | ext4_journal_test_restart(handle, inode); |
| @@ -3495,7 +3614,7 @@ static void ext4_free_data(handle_t *handle, struct inode *inode, | |||
| 3495 | count, block_to_free_p, p); | 3614 | count, block_to_free_p, p); |
| 3496 | 3615 | ||
| 3497 | if (this_bh) { | 3616 | if (this_bh) { |
| 3498 | BUFFER_TRACE(this_bh, "call ext4_journal_dirty_metadata"); | 3617 | BUFFER_TRACE(this_bh, "call ext4_handle_dirty_metadata"); |
| 3499 | 3618 | ||
| 3500 | /* | 3619 | /* |
| 3501 | * The buffer head should have an attached journal head at this | 3620 | * The buffer head should have an attached journal head at this |
| @@ -3504,7 +3623,7 @@ static void ext4_free_data(handle_t *handle, struct inode *inode, | |||
| 3504 | * the block was cleared. Check for this instead of OOPSing. | 3623 | * the block was cleared. Check for this instead of OOPSing. |
| 3505 | */ | 3624 | */ |
| 3506 | if (bh2jh(this_bh)) | 3625 | if (bh2jh(this_bh)) |
| 3507 | ext4_journal_dirty_metadata(handle, this_bh); | 3626 | ext4_handle_dirty_metadata(handle, inode, this_bh); |
| 3508 | else | 3627 | else |
| 3509 | ext4_error(inode->i_sb, __func__, | 3628 | ext4_error(inode->i_sb, __func__, |
| 3510 | "circular indirect block detected, " | 3629 | "circular indirect block detected, " |
| @@ -3534,7 +3653,7 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode, | |||
| 3534 | ext4_fsblk_t nr; | 3653 | ext4_fsblk_t nr; |
| 3535 | __le32 *p; | 3654 | __le32 *p; |
| 3536 | 3655 | ||
| 3537 | if (is_handle_aborted(handle)) | 3656 | if (ext4_handle_is_aborted(handle)) |
| 3538 | return; | 3657 | return; |
| 3539 | 3658 | ||
| 3540 | if (depth--) { | 3659 | if (depth--) { |
| @@ -3604,7 +3723,7 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode, | |||
| 3604 | * will merely complain about releasing a free block, | 3723 | * will merely complain about releasing a free block, |
| 3605 | * rather than leaking blocks. | 3724 | * rather than leaking blocks. |
| 3606 | */ | 3725 | */ |
| 3607 | if (is_handle_aborted(handle)) | 3726 | if (ext4_handle_is_aborted(handle)) |
| 3608 | return; | 3727 | return; |
| 3609 | if (try_to_extend_transaction(handle, inode)) { | 3728 | if (try_to_extend_transaction(handle, inode)) { |
| 3610 | ext4_mark_inode_dirty(handle, inode); | 3729 | ext4_mark_inode_dirty(handle, inode); |
| @@ -3623,9 +3742,10 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode, | |||
| 3623 | parent_bh)){ | 3742 | parent_bh)){ |
| 3624 | *p = 0; | 3743 | *p = 0; |
| 3625 | BUFFER_TRACE(parent_bh, | 3744 | BUFFER_TRACE(parent_bh, |
| 3626 | "call ext4_journal_dirty_metadata"); | 3745 | "call ext4_handle_dirty_metadata"); |
| 3627 | ext4_journal_dirty_metadata(handle, | 3746 | ext4_handle_dirty_metadata(handle, |
| 3628 | parent_bh); | 3747 | inode, |
| 3748 | parent_bh); | ||
| 3629 | } | 3749 | } |
| 3630 | } | 3750 | } |
| 3631 | } | 3751 | } |
| @@ -3813,7 +3933,7 @@ do_indirects: | |||
| 3813 | * synchronous | 3933 | * synchronous |
| 3814 | */ | 3934 | */ |
| 3815 | if (IS_SYNC(inode)) | 3935 | if (IS_SYNC(inode)) |
| 3816 | handle->h_sync = 1; | 3936 | ext4_handle_sync(handle); |
| 3817 | out_stop: | 3937 | out_stop: |
| 3818 | /* | 3938 | /* |
| 3819 | * If this was a simple ftruncate(), and the file will remain alive | 3939 | * If this was a simple ftruncate(), and the file will remain alive |
| @@ -3843,7 +3963,7 @@ static int __ext4_get_inode_loc(struct inode *inode, | |||
| 3843 | ext4_fsblk_t block; | 3963 | ext4_fsblk_t block; |
| 3844 | int inodes_per_block, inode_offset; | 3964 | int inodes_per_block, inode_offset; |
| 3845 | 3965 | ||
| 3846 | iloc->bh = 0; | 3966 | iloc->bh = NULL; |
| 3847 | if (!ext4_valid_inum(sb, inode->i_ino)) | 3967 | if (!ext4_valid_inum(sb, inode->i_ino)) |
| 3848 | return -EIO; | 3968 | return -EIO; |
| 3849 | 3969 | ||
| @@ -3950,7 +4070,7 @@ make_io: | |||
| 3950 | num = EXT4_INODES_PER_GROUP(sb); | 4070 | num = EXT4_INODES_PER_GROUP(sb); |
| 3951 | if (EXT4_HAS_RO_COMPAT_FEATURE(sb, | 4071 | if (EXT4_HAS_RO_COMPAT_FEATURE(sb, |
| 3952 | EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) | 4072 | EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) |
| 3953 | num -= le16_to_cpu(gdp->bg_itable_unused); | 4073 | num -= ext4_itable_unused_count(sb, gdp); |
| 3954 | table += num / inodes_per_block; | 4074 | table += num / inodes_per_block; |
| 3955 | if (end > table) | 4075 | if (end > table) |
| 3956 | end = table; | 4076 | end = table; |
| @@ -4164,9 +4284,11 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
| 4164 | inode->i_op = &ext4_dir_inode_operations; | 4284 | inode->i_op = &ext4_dir_inode_operations; |
| 4165 | inode->i_fop = &ext4_dir_operations; | 4285 | inode->i_fop = &ext4_dir_operations; |
| 4166 | } else if (S_ISLNK(inode->i_mode)) { | 4286 | } else if (S_ISLNK(inode->i_mode)) { |
| 4167 | if (ext4_inode_is_fast_symlink(inode)) | 4287 | if (ext4_inode_is_fast_symlink(inode)) { |
| 4168 | inode->i_op = &ext4_fast_symlink_inode_operations; | 4288 | inode->i_op = &ext4_fast_symlink_inode_operations; |
| 4169 | else { | 4289 | nd_terminate_link(ei->i_data, inode->i_size, |
| 4290 | sizeof(ei->i_data) - 1); | ||
| 4291 | } else { | ||
| 4170 | inode->i_op = &ext4_symlink_inode_operations; | 4292 | inode->i_op = &ext4_symlink_inode_operations; |
| 4171 | ext4_set_aops(inode); | 4293 | ext4_set_aops(inode); |
| 4172 | } | 4294 | } |
| @@ -4310,8 +4432,8 @@ static int ext4_do_update_inode(handle_t *handle, | |||
| 4310 | EXT4_SET_RO_COMPAT_FEATURE(sb, | 4432 | EXT4_SET_RO_COMPAT_FEATURE(sb, |
| 4311 | EXT4_FEATURE_RO_COMPAT_LARGE_FILE); | 4433 | EXT4_FEATURE_RO_COMPAT_LARGE_FILE); |
| 4312 | sb->s_dirt = 1; | 4434 | sb->s_dirt = 1; |
| 4313 | handle->h_sync = 1; | 4435 | ext4_handle_sync(handle); |
| 4314 | err = ext4_journal_dirty_metadata(handle, | 4436 | err = ext4_handle_dirty_metadata(handle, inode, |
| 4315 | EXT4_SB(sb)->s_sbh); | 4437 | EXT4_SB(sb)->s_sbh); |
| 4316 | } | 4438 | } |
| 4317 | } | 4439 | } |
| @@ -4338,9 +4460,8 @@ static int ext4_do_update_inode(handle_t *handle, | |||
| 4338 | raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize); | 4460 | raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize); |
| 4339 | } | 4461 | } |
| 4340 | 4462 | ||
| 4341 | 4463 | BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); | |
| 4342 | BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata"); | 4464 | rc = ext4_handle_dirty_metadata(handle, inode, bh); |
| 4343 | rc = ext4_journal_dirty_metadata(handle, bh); | ||
| 4344 | if (!err) | 4465 | if (!err) |
| 4345 | err = rc; | 4466 | err = rc; |
| 4346 | ei->i_state &= ~EXT4_STATE_NEW; | 4467 | ei->i_state &= ~EXT4_STATE_NEW; |
| @@ -4403,6 +4524,25 @@ int ext4_write_inode(struct inode *inode, int wait) | |||
| 4403 | return ext4_force_commit(inode->i_sb); | 4524 | return ext4_force_commit(inode->i_sb); |
| 4404 | } | 4525 | } |
| 4405 | 4526 | ||
| 4527 | int __ext4_write_dirty_metadata(struct inode *inode, struct buffer_head *bh) | ||
| 4528 | { | ||
| 4529 | int err = 0; | ||
| 4530 | |||
| 4531 | mark_buffer_dirty(bh); | ||
| 4532 | if (inode && inode_needs_sync(inode)) { | ||
| 4533 | sync_dirty_buffer(bh); | ||
| 4534 | if (buffer_req(bh) && !buffer_uptodate(bh)) { | ||
| 4535 | ext4_error(inode->i_sb, __func__, | ||
| 4536 | "IO error syncing inode, " | ||
| 4537 | "inode=%lu, block=%llu", | ||
| 4538 | inode->i_ino, | ||
| 4539 | (unsigned long long)bh->b_blocknr); | ||
| 4540 | err = -EIO; | ||
| 4541 | } | ||
| 4542 | } | ||
| 4543 | return err; | ||
| 4544 | } | ||
| 4545 | |||
| 4406 | /* | 4546 | /* |
| 4407 | * ext4_setattr() | 4547 | * ext4_setattr() |
| 4408 | * | 4548 | * |
| @@ -4707,16 +4847,15 @@ int | |||
| 4707 | ext4_reserve_inode_write(handle_t *handle, struct inode *inode, | 4847 | ext4_reserve_inode_write(handle_t *handle, struct inode *inode, |
| 4708 | struct ext4_iloc *iloc) | 4848 | struct ext4_iloc *iloc) |
| 4709 | { | 4849 | { |
| 4710 | int err = 0; | 4850 | int err; |
| 4711 | if (handle) { | 4851 | |
| 4712 | err = ext4_get_inode_loc(inode, iloc); | 4852 | err = ext4_get_inode_loc(inode, iloc); |
| 4713 | if (!err) { | 4853 | if (!err) { |
| 4714 | BUFFER_TRACE(iloc->bh, "get_write_access"); | 4854 | BUFFER_TRACE(iloc->bh, "get_write_access"); |
| 4715 | err = ext4_journal_get_write_access(handle, iloc->bh); | 4855 | err = ext4_journal_get_write_access(handle, iloc->bh); |
| 4716 | if (err) { | 4856 | if (err) { |
| 4717 | brelse(iloc->bh); | 4857 | brelse(iloc->bh); |
| 4718 | iloc->bh = NULL; | 4858 | iloc->bh = NULL; |
| 4719 | } | ||
| 4720 | } | 4859 | } |
| 4721 | } | 4860 | } |
| 4722 | ext4_std_error(inode->i_sb, err); | 4861 | ext4_std_error(inode->i_sb, err); |
| @@ -4788,7 +4927,8 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode) | |||
| 4788 | 4927 | ||
| 4789 | might_sleep(); | 4928 | might_sleep(); |
| 4790 | err = ext4_reserve_inode_write(handle, inode, &iloc); | 4929 | err = ext4_reserve_inode_write(handle, inode, &iloc); |
| 4791 | if (EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize && | 4930 | if (ext4_handle_valid(handle) && |
| 4931 | EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize && | ||
| 4792 | !(EXT4_I(inode)->i_state & EXT4_STATE_NO_EXPAND)) { | 4932 | !(EXT4_I(inode)->i_state & EXT4_STATE_NO_EXPAND)) { |
| 4793 | /* | 4933 | /* |
| 4794 | * We need extra buffer credits since we may write into EA block | 4934 | * We need extra buffer credits since we may write into EA block |
| @@ -4840,6 +4980,11 @@ void ext4_dirty_inode(struct inode *inode) | |||
| 4840 | handle_t *current_handle = ext4_journal_current_handle(); | 4980 | handle_t *current_handle = ext4_journal_current_handle(); |
| 4841 | handle_t *handle; | 4981 | handle_t *handle; |
| 4842 | 4982 | ||
| 4983 | if (!ext4_handle_valid(current_handle)) { | ||
| 4984 | ext4_mark_inode_dirty(current_handle, inode); | ||
| 4985 | return; | ||
| 4986 | } | ||
| 4987 | |||
| 4843 | handle = ext4_journal_start(inode, 2); | 4988 | handle = ext4_journal_start(inode, 2); |
| 4844 | if (IS_ERR(handle)) | 4989 | if (IS_ERR(handle)) |
| 4845 | goto out; | 4990 | goto out; |
| @@ -4877,8 +5022,9 @@ static int ext4_pin_inode(handle_t *handle, struct inode *inode) | |||
| 4877 | BUFFER_TRACE(iloc.bh, "get_write_access"); | 5022 | BUFFER_TRACE(iloc.bh, "get_write_access"); |
| 4878 | err = jbd2_journal_get_write_access(handle, iloc.bh); | 5023 | err = jbd2_journal_get_write_access(handle, iloc.bh); |
| 4879 | if (!err) | 5024 | if (!err) |
| 4880 | err = ext4_journal_dirty_metadata(handle, | 5025 | err = ext4_handle_dirty_metadata(handle, |
| 4881 | iloc.bh); | 5026 | inode, |
| 5027 | iloc.bh); | ||
| 4882 | brelse(iloc.bh); | 5028 | brelse(iloc.bh); |
| 4883 | } | 5029 | } |
| 4884 | } | 5030 | } |
| @@ -4904,6 +5050,8 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) | |||
| 4904 | */ | 5050 | */ |
| 4905 | 5051 | ||
| 4906 | journal = EXT4_JOURNAL(inode); | 5052 | journal = EXT4_JOURNAL(inode); |
| 5053 | if (!journal) | ||
| 5054 | return 0; | ||
| 4907 | if (is_journal_aborted(journal)) | 5055 | if (is_journal_aborted(journal)) |
| 4908 | return -EROFS; | 5056 | return -EROFS; |
| 4909 | 5057 | ||
| @@ -4933,7 +5081,7 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) | |||
| 4933 | return PTR_ERR(handle); | 5081 | return PTR_ERR(handle); |
| 4934 | 5082 | ||
| 4935 | err = ext4_mark_inode_dirty(handle, inode); | 5083 | err = ext4_mark_inode_dirty(handle, inode); |
| 4936 | handle->h_sync = 1; | 5084 | ext4_handle_sync(handle); |
| 4937 | ext4_journal_stop(handle); | 5085 | ext4_journal_stop(handle); |
| 4938 | ext4_std_error(inode->i_sb, err); | 5086 | ext4_std_error(inode->i_sb, err); |
| 4939 | 5087 | ||
