diff options
Diffstat (limited to 'fs/ocfs2/aops.c')
-rw-r--r-- | fs/ocfs2/aops.c | 94 |
1 files changed, 70 insertions, 24 deletions
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 0de69c9a08be..1fbb0e20131b 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c | |||
@@ -165,7 +165,7 @@ int ocfs2_get_block(struct inode *inode, sector_t iblock, | |||
165 | * ocfs2 never allocates in this function - the only time we | 165 | * ocfs2 never allocates in this function - the only time we |
166 | * need to use BH_New is when we're extending i_size on a file | 166 | * need to use BH_New is when we're extending i_size on a file |
167 | * system which doesn't support holes, in which case BH_New | 167 | * system which doesn't support holes, in which case BH_New |
168 | * allows block_prepare_write() to zero. | 168 | * allows __block_write_begin() to zero. |
169 | * | 169 | * |
170 | * If we see this on a sparse file system, then a truncate has | 170 | * If we see this on a sparse file system, then a truncate has |
171 | * raced us and removed the cluster. In this case, we clear | 171 | * raced us and removed the cluster. In this case, we clear |
@@ -407,21 +407,6 @@ static int ocfs2_writepage(struct page *page, struct writeback_control *wbc) | |||
407 | return ret; | 407 | return ret; |
408 | } | 408 | } |
409 | 409 | ||
410 | /* | ||
411 | * This is called from ocfs2_write_zero_page() which has handled it's | ||
412 | * own cluster locking and has ensured allocation exists for those | ||
413 | * blocks to be written. | ||
414 | */ | ||
415 | int ocfs2_prepare_write_nolock(struct inode *inode, struct page *page, | ||
416 | unsigned from, unsigned to) | ||
417 | { | ||
418 | int ret; | ||
419 | |||
420 | ret = block_prepare_write(page, from, to, ocfs2_get_block); | ||
421 | |||
422 | return ret; | ||
423 | } | ||
424 | |||
425 | /* Taken from ext3. We don't necessarily need the full blown | 410 | /* Taken from ext3. We don't necessarily need the full blown |
426 | * functionality yet, but IMHO it's better to cut and paste the whole | 411 | * functionality yet, but IMHO it's better to cut and paste the whole |
427 | * thing so we can avoid introducing our own bugs (and easily pick up | 412 | * thing so we can avoid introducing our own bugs (and easily pick up |
@@ -588,11 +573,14 @@ static void ocfs2_dio_end_io(struct kiocb *iocb, | |||
588 | /* this io's submitter should not have unlocked this before we could */ | 573 | /* this io's submitter should not have unlocked this before we could */ |
589 | BUG_ON(!ocfs2_iocb_is_rw_locked(iocb)); | 574 | BUG_ON(!ocfs2_iocb_is_rw_locked(iocb)); |
590 | 575 | ||
576 | if (ocfs2_iocb_is_sem_locked(iocb)) { | ||
577 | up_read(&inode->i_alloc_sem); | ||
578 | ocfs2_iocb_clear_sem_locked(iocb); | ||
579 | } | ||
580 | |||
591 | ocfs2_iocb_clear_rw_locked(iocb); | 581 | ocfs2_iocb_clear_rw_locked(iocb); |
592 | 582 | ||
593 | level = ocfs2_iocb_rw_locked_level(iocb); | 583 | level = ocfs2_iocb_rw_locked_level(iocb); |
594 | if (!level) | ||
595 | up_read(&inode->i_alloc_sem); | ||
596 | ocfs2_rw_unlock(inode, level); | 584 | ocfs2_rw_unlock(inode, level); |
597 | 585 | ||
598 | if (is_async) | 586 | if (is_async) |
@@ -732,7 +720,7 @@ static int ocfs2_should_read_blk(struct inode *inode, struct page *page, | |||
732 | } | 720 | } |
733 | 721 | ||
734 | /* | 722 | /* |
735 | * Some of this taken from block_prepare_write(). We already have our | 723 | * Some of this taken from __block_write_begin(). We already have our |
736 | * mapping by now though, and the entire write will be allocating or | 724 | * mapping by now though, and the entire write will be allocating or |
737 | * it won't, so not much need to use BH_New. | 725 | * it won't, so not much need to use BH_New. |
738 | * | 726 | * |
@@ -883,8 +871,8 @@ struct ocfs2_write_ctxt { | |||
883 | * out in so that future reads from that region will get | 871 | * out in so that future reads from that region will get |
884 | * zero's. | 872 | * zero's. |
885 | */ | 873 | */ |
886 | struct page *w_pages[OCFS2_MAX_CTXT_PAGES]; | ||
887 | unsigned int w_num_pages; | 874 | unsigned int w_num_pages; |
875 | struct page *w_pages[OCFS2_MAX_CTXT_PAGES]; | ||
888 | struct page *w_target_page; | 876 | struct page *w_target_page; |
889 | 877 | ||
890 | /* | 878 | /* |
@@ -1642,13 +1630,51 @@ static int ocfs2_zero_tail(struct inode *inode, struct buffer_head *di_bh, | |||
1642 | return ret; | 1630 | return ret; |
1643 | } | 1631 | } |
1644 | 1632 | ||
1645 | int ocfs2_write_begin_nolock(struct address_space *mapping, | 1633 | /* |
1634 | * Try to flush truncate logs if we can free enough clusters from it. | ||
1635 | * As for return value, "< 0" means error, "0" no space and "1" means | ||
1636 | * we have freed enough spaces and let the caller try to allocate again. | ||
1637 | */ | ||
1638 | static int ocfs2_try_to_free_truncate_log(struct ocfs2_super *osb, | ||
1639 | unsigned int needed) | ||
1640 | { | ||
1641 | tid_t target; | ||
1642 | int ret = 0; | ||
1643 | unsigned int truncated_clusters; | ||
1644 | |||
1645 | mutex_lock(&osb->osb_tl_inode->i_mutex); | ||
1646 | truncated_clusters = osb->truncated_clusters; | ||
1647 | mutex_unlock(&osb->osb_tl_inode->i_mutex); | ||
1648 | |||
1649 | /* | ||
1650 | * Check whether we can succeed in allocating if we free | ||
1651 | * the truncate log. | ||
1652 | */ | ||
1653 | if (truncated_clusters < needed) | ||
1654 | goto out; | ||
1655 | |||
1656 | ret = ocfs2_flush_truncate_log(osb); | ||
1657 | if (ret) { | ||
1658 | mlog_errno(ret); | ||
1659 | goto out; | ||
1660 | } | ||
1661 | |||
1662 | if (jbd2_journal_start_commit(osb->journal->j_journal, &target)) { | ||
1663 | jbd2_log_wait_commit(osb->journal->j_journal, target); | ||
1664 | ret = 1; | ||
1665 | } | ||
1666 | out: | ||
1667 | return ret; | ||
1668 | } | ||
1669 | |||
1670 | int ocfs2_write_begin_nolock(struct file *filp, | ||
1671 | struct address_space *mapping, | ||
1646 | loff_t pos, unsigned len, unsigned flags, | 1672 | loff_t pos, unsigned len, unsigned flags, |
1647 | struct page **pagep, void **fsdata, | 1673 | struct page **pagep, void **fsdata, |
1648 | struct buffer_head *di_bh, struct page *mmap_page) | 1674 | struct buffer_head *di_bh, struct page *mmap_page) |
1649 | { | 1675 | { |
1650 | int ret, cluster_of_pages, credits = OCFS2_INODE_UPDATE_CREDITS; | 1676 | int ret, cluster_of_pages, credits = OCFS2_INODE_UPDATE_CREDITS; |
1651 | unsigned int clusters_to_alloc, extents_to_split; | 1677 | unsigned int clusters_to_alloc, extents_to_split, clusters_need = 0; |
1652 | struct ocfs2_write_ctxt *wc; | 1678 | struct ocfs2_write_ctxt *wc; |
1653 | struct inode *inode = mapping->host; | 1679 | struct inode *inode = mapping->host; |
1654 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 1680 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
@@ -1657,7 +1683,9 @@ int ocfs2_write_begin_nolock(struct address_space *mapping, | |||
1657 | struct ocfs2_alloc_context *meta_ac = NULL; | 1683 | struct ocfs2_alloc_context *meta_ac = NULL; |
1658 | handle_t *handle; | 1684 | handle_t *handle; |
1659 | struct ocfs2_extent_tree et; | 1685 | struct ocfs2_extent_tree et; |
1686 | int try_free = 1, ret1; | ||
1660 | 1687 | ||
1688 | try_again: | ||
1661 | ret = ocfs2_alloc_write_ctxt(&wc, osb, pos, len, di_bh); | 1689 | ret = ocfs2_alloc_write_ctxt(&wc, osb, pos, len, di_bh); |
1662 | if (ret) { | 1690 | if (ret) { |
1663 | mlog_errno(ret); | 1691 | mlog_errno(ret); |
@@ -1692,7 +1720,8 @@ int ocfs2_write_begin_nolock(struct address_space *mapping, | |||
1692 | mlog_errno(ret); | 1720 | mlog_errno(ret); |
1693 | goto out; | 1721 | goto out; |
1694 | } else if (ret == 1) { | 1722 | } else if (ret == 1) { |
1695 | ret = ocfs2_refcount_cow(inode, di_bh, | 1723 | clusters_need = wc->w_clen; |
1724 | ret = ocfs2_refcount_cow(inode, filp, di_bh, | ||
1696 | wc->w_cpos, wc->w_clen, UINT_MAX); | 1725 | wc->w_cpos, wc->w_clen, UINT_MAX); |
1697 | if (ret) { | 1726 | if (ret) { |
1698 | mlog_errno(ret); | 1727 | mlog_errno(ret); |
@@ -1706,6 +1735,7 @@ int ocfs2_write_begin_nolock(struct address_space *mapping, | |||
1706 | mlog_errno(ret); | 1735 | mlog_errno(ret); |
1707 | goto out; | 1736 | goto out; |
1708 | } | 1737 | } |
1738 | clusters_need += clusters_to_alloc; | ||
1709 | 1739 | ||
1710 | di = (struct ocfs2_dinode *)wc->w_di_bh->b_data; | 1740 | di = (struct ocfs2_dinode *)wc->w_di_bh->b_data; |
1711 | 1741 | ||
@@ -1828,6 +1858,22 @@ out: | |||
1828 | ocfs2_free_alloc_context(data_ac); | 1858 | ocfs2_free_alloc_context(data_ac); |
1829 | if (meta_ac) | 1859 | if (meta_ac) |
1830 | ocfs2_free_alloc_context(meta_ac); | 1860 | ocfs2_free_alloc_context(meta_ac); |
1861 | |||
1862 | if (ret == -ENOSPC && try_free) { | ||
1863 | /* | ||
1864 | * Try to free some truncate log so that we can have enough | ||
1865 | * clusters to allocate. | ||
1866 | */ | ||
1867 | try_free = 0; | ||
1868 | |||
1869 | ret1 = ocfs2_try_to_free_truncate_log(osb, clusters_need); | ||
1870 | if (ret1 == 1) | ||
1871 | goto try_again; | ||
1872 | |||
1873 | if (ret1 < 0) | ||
1874 | mlog_errno(ret1); | ||
1875 | } | ||
1876 | |||
1831 | return ret; | 1877 | return ret; |
1832 | } | 1878 | } |
1833 | 1879 | ||
@@ -1854,7 +1900,7 @@ static int ocfs2_write_begin(struct file *file, struct address_space *mapping, | |||
1854 | */ | 1900 | */ |
1855 | down_write(&OCFS2_I(inode)->ip_alloc_sem); | 1901 | down_write(&OCFS2_I(inode)->ip_alloc_sem); |
1856 | 1902 | ||
1857 | ret = ocfs2_write_begin_nolock(mapping, pos, len, flags, pagep, | 1903 | ret = ocfs2_write_begin_nolock(file, mapping, pos, len, flags, pagep, |
1858 | fsdata, di_bh, NULL); | 1904 | fsdata, di_bh, NULL); |
1859 | if (ret) { | 1905 | if (ret) { |
1860 | mlog_errno(ret); | 1906 | mlog_errno(ret); |