inode.c (45f6bc5ff9c3387387f048ec85dcb4e69acf0b03) inode.c (d863dc3614e489e11808f940a612b520ce1dff91)
1/*
2 * linux/fs/ext4/inode.c
3 *
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *

--- 118 unchanged lines hidden (view full) ---

127 */
128 if (!EXT4_I(inode)->jinode)
129 return 0;
130 return jbd2_journal_begin_ordered_truncate(EXT4_JOURNAL(inode),
131 EXT4_I(inode)->jinode,
132 new_size);
133}
134
1/*
2 * linux/fs/ext4/inode.c
3 *
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *

--- 118 unchanged lines hidden (view full) ---

127 */
128 if (!EXT4_I(inode)->jinode)
129 return 0;
130 return jbd2_journal_begin_ordered_truncate(EXT4_JOURNAL(inode),
131 EXT4_I(inode)->jinode,
132 new_size);
133}
134
135static void ext4_invalidatepage(struct page *page, unsigned long offset);
135static void ext4_invalidatepage(struct page *page, unsigned int offset,
136 unsigned int length);
136static int __ext4_journalled_writepage(struct page *page, unsigned int len);
137static int ext4_bh_delay_or_unwritten(handle_t *handle, struct buffer_head *bh);
138static int ext4_discard_partial_page_buffers_no_lock(handle_t *handle,
139 struct inode *inode, struct page *page, loff_t from,
140 loff_t length, int flags);
141
142/*
143 * Test whether an inode is a fast symlink.

--- 1266 unchanged lines hidden (view full) ---

1410 percpu_counter_sub(&sbi->s_dirtyclusters_counter, to_free);
1411
1412 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
1413
1414 dquot_release_reservation_block(inode, EXT4_C2B(sbi, to_free));
1415}
1416
1417static void ext4_da_page_release_reservation(struct page *page,
137static int __ext4_journalled_writepage(struct page *page, unsigned int len);
138static int ext4_bh_delay_or_unwritten(handle_t *handle, struct buffer_head *bh);
139static int ext4_discard_partial_page_buffers_no_lock(handle_t *handle,
140 struct inode *inode, struct page *page, loff_t from,
141 loff_t length, int flags);
142
143/*
144 * Test whether an inode is a fast symlink.

--- 1266 unchanged lines hidden (view full) ---

1411 percpu_counter_sub(&sbi->s_dirtyclusters_counter, to_free);
1412
1413 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
1414
1415 dquot_release_reservation_block(inode, EXT4_C2B(sbi, to_free));
1416}
1417
1418static void ext4_da_page_release_reservation(struct page *page,
1418 unsigned long offset)
1419 unsigned int offset,
1420 unsigned int length)
1419{
1420 int to_release = 0;
1421 struct buffer_head *head, *bh;
1422 unsigned int curr_off = 0;
1423 struct inode *inode = page->mapping->host;
1424 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
1421{
1422 int to_release = 0;
1423 struct buffer_head *head, *bh;
1424 unsigned int curr_off = 0;
1425 struct inode *inode = page->mapping->host;
1426 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
1427 unsigned int stop = offset + length;
1425 int num_clusters;
1426 ext4_fsblk_t lblk;
1427
1428 int num_clusters;
1429 ext4_fsblk_t lblk;
1430
1431 BUG_ON(stop > PAGE_CACHE_SIZE || stop < length);
1432
1428 head = page_buffers(page);
1429 bh = head;
1430 do {
1431 unsigned int next_off = curr_off + bh->b_size;
1432
1433 head = page_buffers(page);
1434 bh = head;
1435 do {
1436 unsigned int next_off = curr_off + bh->b_size;
1437
1438 if (next_off > stop)
1439 break;
1440
1433 if ((offset <= curr_off) && (buffer_delay(bh))) {
1434 to_release++;
1435 clear_buffer_delay(bh);
1436 }
1437 curr_off = next_off;
1438 } while ((bh = bh->b_this_page) != head);
1439
1440 if (to_release) {

--- 160 unchanged lines hidden (view full) ---

1601 if (nr_pages == 0)
1602 break;
1603 for (i = 0; i < nr_pages; i++) {
1604 struct page *page = pvec.pages[i];
1605 if (page->index > end)
1606 break;
1607 BUG_ON(!PageLocked(page));
1608 BUG_ON(PageWriteback(page));
1441 if ((offset <= curr_off) && (buffer_delay(bh))) {
1442 to_release++;
1443 clear_buffer_delay(bh);
1444 }
1445 curr_off = next_off;
1446 } while ((bh = bh->b_this_page) != head);
1447
1448 if (to_release) {

--- 160 unchanged lines hidden (view full) ---

1609 if (nr_pages == 0)
1610 break;
1611 for (i = 0; i < nr_pages; i++) {
1612 struct page *page = pvec.pages[i];
1613 if (page->index > end)
1614 break;
1615 BUG_ON(!PageLocked(page));
1616 BUG_ON(PageWriteback(page));
1609 block_invalidatepage(page, 0);
1617 block_invalidatepage(page, 0, PAGE_CACHE_SIZE);
1610 ClearPageUptodate(page);
1611 unlock_page(page);
1612 }
1613 index = pvec.pages[nr_pages - 1]->index + 1;
1614 pagevec_release(&pvec);
1615 }
1616 return;
1617}

--- 1206 unchanged lines hidden (view full) ---

2824 ret = ret2;
2825 ret2 = ext4_journal_stop(handle);
2826 if (!ret)
2827 ret = ret2;
2828
2829 return ret ? ret : copied;
2830}
2831
1618 ClearPageUptodate(page);
1619 unlock_page(page);
1620 }
1621 index = pvec.pages[nr_pages - 1]->index + 1;
1622 pagevec_release(&pvec);
1623 }
1624 return;
1625}

--- 1206 unchanged lines hidden (view full) ---

2832 ret = ret2;
2833 ret2 = ext4_journal_stop(handle);
2834 if (!ret)
2835 ret = ret2;
2836
2837 return ret ? ret : copied;
2838}
2839
2832static void ext4_da_invalidatepage(struct page *page, unsigned long offset)
2840static void ext4_da_invalidatepage(struct page *page, unsigned int offset,
2841 unsigned int length)
2833{
2834 /*
2835 * Drop reserved blocks
2836 */
2837 BUG_ON(!PageLocked(page));
2838 if (!page_has_buffers(page))
2839 goto out;
2840
2842{
2843 /*
2844 * Drop reserved blocks
2845 */
2846 BUG_ON(!PageLocked(page));
2847 if (!page_has_buffers(page))
2848 goto out;
2849
2841 ext4_da_page_release_reservation(page, offset);
2850 ext4_da_page_release_reservation(page, offset, length);
2842
2843out:
2851
2852out:
2844 ext4_invalidatepage(page, offset);
2853 ext4_invalidatepage(page, offset, length);
2845
2846 return;
2847}
2848
2849/*
2850 * Force all delayed allocation blocks to be allocated for a given inode.
2851 */
2852int ext4_alloc_da_blocks(struct inode *inode)

--- 131 unchanged lines hidden (view full) ---

2984
2985 /* If the file has inline data, no need to do readpages. */
2986 if (ext4_has_inline_data(inode))
2987 return 0;
2988
2989 return mpage_readpages(mapping, pages, nr_pages, ext4_get_block);
2990}
2991
2854
2855 return;
2856}
2857
2858/*
2859 * Force all delayed allocation blocks to be allocated for a given inode.
2860 */
2861int ext4_alloc_da_blocks(struct inode *inode)

--- 131 unchanged lines hidden (view full) ---

2993
2994 /* If the file has inline data, no need to do readpages. */
2995 if (ext4_has_inline_data(inode))
2996 return 0;
2997
2998 return mpage_readpages(mapping, pages, nr_pages, ext4_get_block);
2999}
3000
2992static void ext4_invalidatepage(struct page *page, unsigned long offset)
3001static void ext4_invalidatepage(struct page *page, unsigned int offset,
3002 unsigned int length)
2993{
3003{
2994 trace_ext4_invalidatepage(page, offset);
3004 trace_ext4_invalidatepage(page, offset, length);
2995
2996 /* No journalling happens on data buffers when this function is used */
2997 WARN_ON(page_has_buffers(page) && buffer_jbd(page_buffers(page)));
2998
3005
3006 /* No journalling happens on data buffers when this function is used */
3007 WARN_ON(page_has_buffers(page) && buffer_jbd(page_buffers(page)));
3008
2999 block_invalidatepage(page, offset);
3009 block_invalidatepage(page, offset, length);
3000}
3001
3002static int __ext4_journalled_invalidatepage(struct page *page,
3010}
3011
3012static int __ext4_journalled_invalidatepage(struct page *page,
3003 unsigned long offset)
3013 unsigned int offset,
3014 unsigned int length)
3004{
3005 journal_t *journal = EXT4_JOURNAL(page->mapping->host);
3006
3015{
3016 journal_t *journal = EXT4_JOURNAL(page->mapping->host);
3017
3007 trace_ext4_journalled_invalidatepage(page, offset);
3018 trace_ext4_journalled_invalidatepage(page, offset, length);
3008
3009 /*
3010 * If it's a full truncate we just forget about the pending dirtying
3011 */
3019
3020 /*
3021 * If it's a full truncate we just forget about the pending dirtying
3022 */
3012 if (offset == 0)
3023 if (offset == 0 && length == PAGE_CACHE_SIZE)
3013 ClearPageChecked(page);
3014
3024 ClearPageChecked(page);
3025
3015 return jbd2_journal_invalidatepage(journal, page, offset);
3026 return jbd2_journal_invalidatepage(journal, page, offset, length);
3016}
3017
3018/* Wrapper for aops... */
3019static void ext4_journalled_invalidatepage(struct page *page,
3027}
3028
3029/* Wrapper for aops... */
3030static void ext4_journalled_invalidatepage(struct page *page,
3020 unsigned long offset)
3031 unsigned int offset,
3032 unsigned int length)
3021{
3033{
3022 WARN_ON(__ext4_journalled_invalidatepage(page, offset) < 0);
3034 WARN_ON(__ext4_journalled_invalidatepage(page, offset, length) < 0);
3023}
3024
3025static int ext4_releasepage(struct page *page, gfp_t wait)
3026{
3027 journal_t *journal = EXT4_JOURNAL(page->mapping->host);
3028
3029 trace_ext4_releasepage(page);
3030

--- 522 unchanged lines hidden (view full) ---

3553 bh = bh->b_this_page;
3554 iblock++;
3555 pos += range_to_discard;
3556 }
3557
3558 return err;
3559}
3560
3035}
3036
3037static int ext4_releasepage(struct page *page, gfp_t wait)
3038{
3039 journal_t *journal = EXT4_JOURNAL(page->mapping->host);
3040
3041 trace_ext4_releasepage(page);
3042

--- 522 unchanged lines hidden (view full) ---

3565 bh = bh->b_this_page;
3566 iblock++;
3567 pos += range_to_discard;
3568 }
3569
3570 return err;
3571}
3572
3573/*
3574 * ext4_block_truncate_page() zeroes out a mapping from file offset `from'
3575 * up to the end of the block which corresponds to `from'.
3576 * This required during truncate. We need to physically zero the tail end
3577 * of that block so it doesn't yield old data if the file is later grown.
3578 */
3579int ext4_block_truncate_page(handle_t *handle,
3580 struct address_space *mapping, loff_t from)
3581{
3582 unsigned offset = from & (PAGE_CACHE_SIZE-1);
3583 unsigned length;
3584 unsigned blocksize;
3585 struct inode *inode = mapping->host;
3586
3587 blocksize = inode->i_sb->s_blocksize;
3588 length = blocksize - (offset & (blocksize - 1));
3589
3590 return ext4_block_zero_page_range(handle, mapping, from, length);
3591}
3592
3593/*
3594 * ext4_block_zero_page_range() zeros out a mapping of length 'length'
3595 * starting from file offset 'from'. The range to be zero'd must
3596 * be contained with in one block. If the specified range exceeds
3597 * the end of the block it will be shortened to end of the block
3598 * that cooresponds to 'from'
3599 */
3600int ext4_block_zero_page_range(handle_t *handle,
3601 struct address_space *mapping, loff_t from, loff_t length)
3602{
3603 ext4_fsblk_t index = from >> PAGE_CACHE_SHIFT;
3604 unsigned offset = from & (PAGE_CACHE_SIZE-1);
3605 unsigned blocksize, max, pos;
3606 ext4_lblk_t iblock;
3607 struct inode *inode = mapping->host;
3608 struct buffer_head *bh;
3609 struct page *page;
3610 int err = 0;
3611
3612 page = find_or_create_page(mapping, from >> PAGE_CACHE_SHIFT,
3613 mapping_gfp_mask(mapping) & ~__GFP_FS);
3614 if (!page)
3615 return -ENOMEM;
3616
3617 blocksize = inode->i_sb->s_blocksize;
3618 max = blocksize - (offset & (blocksize - 1));
3619
3620 /*
3621 * correct length if it does not fall between
3622 * 'from' and the end of the block
3623 */
3624 if (length > max || length < 0)
3625 length = max;
3626
3627 iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits);
3628
3629 if (!page_has_buffers(page))
3630 create_empty_buffers(page, blocksize, 0);
3631
3632 /* Find the buffer that contains "offset" */
3633 bh = page_buffers(page);
3634 pos = blocksize;
3635 while (offset >= pos) {
3636 bh = bh->b_this_page;
3637 iblock++;
3638 pos += blocksize;
3639 }
3640
3641 err = 0;
3642 if (buffer_freed(bh)) {
3643 BUFFER_TRACE(bh, "freed: skip");
3644 goto unlock;
3645 }
3646
3647 if (!buffer_mapped(bh)) {
3648 BUFFER_TRACE(bh, "unmapped");
3649 ext4_get_block(inode, iblock, bh, 0);
3650 /* unmapped? It's a hole - nothing to do */
3651 if (!buffer_mapped(bh)) {
3652 BUFFER_TRACE(bh, "still unmapped");
3653 goto unlock;
3654 }
3655 }
3656
3657 /* Ok, it's mapped. Make sure it's up-to-date */
3658 if (PageUptodate(page))
3659 set_buffer_uptodate(bh);
3660
3661 if (!buffer_uptodate(bh)) {
3662 err = -EIO;
3663 ll_rw_block(READ, 1, &bh);
3664 wait_on_buffer(bh);
3665 /* Uhhuh. Read error. Complain and punt. */
3666 if (!buffer_uptodate(bh))
3667 goto unlock;
3668 }
3669
3670 if (ext4_should_journal_data(inode)) {
3671 BUFFER_TRACE(bh, "get write access");
3672 err = ext4_journal_get_write_access(handle, bh);
3673 if (err)
3674 goto unlock;
3675 }
3676
3677 zero_user(page, offset, length);
3678
3679 BUFFER_TRACE(bh, "zeroed end of block");
3680
3681 err = 0;
3682 if (ext4_should_journal_data(inode)) {
3683 err = ext4_handle_dirty_metadata(handle, inode, bh);
3684 } else
3685 mark_buffer_dirty(bh);
3686
3687unlock:
3688 unlock_page(page);
3689 page_cache_release(page);
3690 return err;
3691}
3692
3561int ext4_can_truncate(struct inode *inode)
3562{
3563 if (S_ISREG(inode->i_mode))
3564 return 1;
3565 if (S_ISDIR(inode->i_mode))
3566 return 1;
3567 if (S_ISLNK(inode->i_mode))
3568 return !ext4_inode_is_fast_symlink(inode);

--- 1049 unchanged lines hidden (view full) ---

4618 */
4619 if (offset > PAGE_CACHE_SIZE - (1 << inode->i_blkbits))
4620 return;
4621 while (1) {
4622 page = find_lock_page(inode->i_mapping,
4623 inode->i_size >> PAGE_CACHE_SHIFT);
4624 if (!page)
4625 return;
3693int ext4_can_truncate(struct inode *inode)
3694{
3695 if (S_ISREG(inode->i_mode))
3696 return 1;
3697 if (S_ISDIR(inode->i_mode))
3698 return 1;
3699 if (S_ISLNK(inode->i_mode))
3700 return !ext4_inode_is_fast_symlink(inode);

--- 1049 unchanged lines hidden (view full) ---

4750 */
4751 if (offset > PAGE_CACHE_SIZE - (1 << inode->i_blkbits))
4752 return;
4753 while (1) {
4754 page = find_lock_page(inode->i_mapping,
4755 inode->i_size >> PAGE_CACHE_SHIFT);
4756 if (!page)
4757 return;
4626 ret = __ext4_journalled_invalidatepage(page, offset);
4758 ret = __ext4_journalled_invalidatepage(page, offset,
4759 PAGE_CACHE_SIZE - offset);
4627 unlock_page(page);
4628 page_cache_release(page);
4629 if (ret != -EBUSY)
4630 return;
4631 commit_tid = 0;
4632 read_lock(&journal->j_state_lock);
4633 if (journal->j_committing_transaction)
4634 commit_tid = journal->j_committing_transaction->t_tid;

--- 653 unchanged lines hidden ---
4760 unlock_page(page);
4761 page_cache_release(page);
4762 if (ret != -EBUSY)
4763 return;
4764 commit_tid = 0;
4765 read_lock(&journal->j_state_lock);
4766 if (journal->j_committing_transaction)
4767 commit_tid = journal->j_committing_transaction->t_tid;

--- 653 unchanged lines hidden ---