diff options
author | Dave Chinner <dchinner@redhat.com> | 2011-09-18 16:40:51 -0400 |
---|---|---|
committer | Alex Elder <aelder@sgi.com> | 2011-10-11 22:15:04 -0400 |
commit | b447fe5a05cbd01c4bf7fe2fa41cb9e99ce7e58e (patch) | |
tree | 2c9a08fe5802d7164398da9f186d7389b5fafb87 /fs/xfs | |
parent | 7e47a4efde33aa3f0cb901e086a75751c2269f04 (diff) |
xfs: factor unwritten extent map manipulations out of xfs_bmapi
To further improve the readability of xfs_bmapi(), factor the
unwritten extent conversion out into a separate function. This
removes large block of logic from the xfs_bmapi() code loop and
makes it easier to see the operational logic flow for xfs_bmapi().
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
Diffstat (limited to 'fs/xfs')
-rw-r--r-- | fs/xfs/xfs_bmap.c | 107 |
1 files changed, 70 insertions, 37 deletions
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c index 311cbc1d64c5..c2e49fd18bfd 100644 --- a/fs/xfs/xfs_bmap.c +++ b/fs/xfs/xfs_bmap.c | |||
@@ -4089,7 +4089,6 @@ xfs_bmap_read_extents( | |||
4089 | xfs_extnum_t num_recs; | 4089 | xfs_extnum_t num_recs; |
4090 | xfs_extnum_t start; | 4090 | xfs_extnum_t start; |
4091 | 4091 | ||
4092 | |||
4093 | num_recs = xfs_btree_get_numrecs(block); | 4092 | num_recs = xfs_btree_get_numrecs(block); |
4094 | if (unlikely(i + num_recs > room)) { | 4093 | if (unlikely(i + num_recs > room)) { |
4095 | ASSERT(i + num_recs <= room); | 4094 | ASSERT(i + num_recs <= room); |
@@ -4746,6 +4745,69 @@ xfs_bmapi_allocate( | |||
4746 | return 0; | 4745 | return 0; |
4747 | } | 4746 | } |
4748 | 4747 | ||
4748 | STATIC int | ||
4749 | xfs_bmapi_convert_unwritten( | ||
4750 | struct xfs_bmalloca *bma, | ||
4751 | struct xfs_bmbt_irec *mval, | ||
4752 | xfs_filblks_t len, | ||
4753 | xfs_extnum_t *lastx, | ||
4754 | struct xfs_btree_cur **cur, | ||
4755 | xfs_fsblock_t *firstblock, | ||
4756 | struct xfs_bmap_free *flist, | ||
4757 | int flags, | ||
4758 | int *logflags) | ||
4759 | { | ||
4760 | int whichfork = (flags & XFS_BMAPI_ATTRFORK) ? | ||
4761 | XFS_ATTR_FORK : XFS_DATA_FORK; | ||
4762 | struct xfs_ifork *ifp = XFS_IFORK_PTR(bma->ip, whichfork); | ||
4763 | int error; | ||
4764 | |||
4765 | *logflags = 0; | ||
4766 | |||
4767 | /* check if we need to do unwritten->real conversion */ | ||
4768 | if (mval->br_state == XFS_EXT_UNWRITTEN && | ||
4769 | (flags & XFS_BMAPI_PREALLOC)) | ||
4770 | return 0; | ||
4771 | |||
4772 | /* check if we need to do real->unwritten conversion */ | ||
4773 | if (mval->br_state == XFS_EXT_NORM && | ||
4774 | (flags & (XFS_BMAPI_PREALLOC | XFS_BMAPI_CONVERT)) != | ||
4775 | (XFS_BMAPI_PREALLOC | XFS_BMAPI_CONVERT)) | ||
4776 | return 0; | ||
4777 | |||
4778 | /* | ||
4779 | * Modify (by adding) the state flag, if writing. | ||
4780 | */ | ||
4781 | ASSERT(mval->br_blockcount <= len); | ||
4782 | if ((ifp->if_flags & XFS_IFBROOT) && !*cur) { | ||
4783 | *cur = xfs_bmbt_init_cursor(bma->ip->i_mount, bma->tp, | ||
4784 | bma->ip, whichfork); | ||
4785 | (*cur)->bc_private.b.firstblock = *firstblock; | ||
4786 | (*cur)->bc_private.b.flist = flist; | ||
4787 | } | ||
4788 | mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN) | ||
4789 | ? XFS_EXT_NORM : XFS_EXT_UNWRITTEN; | ||
4790 | |||
4791 | error = xfs_bmap_add_extent(bma->tp, bma->ip, lastx, cur, mval, | ||
4792 | firstblock, flist, logflags, whichfork); | ||
4793 | if (error) | ||
4794 | return error; | ||
4795 | |||
4796 | /* | ||
4797 | * Update our extent pointer, given that xfs_bmap_add_extent might | ||
4798 | * have merged it into one of the neighbouring ones. | ||
4799 | */ | ||
4800 | xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *lastx), bma->gotp); | ||
4801 | |||
4802 | /* | ||
4803 | * We may have combined previously unwritten space with written space, | ||
4804 | * so generate another request. | ||
4805 | */ | ||
4806 | if (mval->br_blockcount < len) | ||
4807 | return EAGAIN; | ||
4808 | return 0; | ||
4809 | } | ||
4810 | |||
4749 | /* | 4811 | /* |
4750 | * Map file blocks to filesystem blocks. | 4812 | * Map file blocks to filesystem blocks. |
4751 | * File range is given by the bno/len pair. | 4813 | * File range is given by the bno/len pair. |
@@ -4932,45 +4994,16 @@ xfs_bmapi( | |||
4932 | /* Deal with the allocated space we found. */ | 4994 | /* Deal with the allocated space we found. */ |
4933 | xfs_bmapi_trim_map(mval, &got, &bno, len, obno, end, n, flags); | 4995 | xfs_bmapi_trim_map(mval, &got, &bno, len, obno, end, n, flags); |
4934 | 4996 | ||
4935 | /* | 4997 | /* Execute unwritten extent conversion if necessary */ |
4936 | * Check if writing previously allocated but | 4998 | if (wr) { |
4937 | * unwritten extents. | 4999 | error = xfs_bmapi_convert_unwritten(&bma, mval, len, |
4938 | */ | 5000 | &lastx, &cur, firstblock, flist, flags, |
4939 | if (wr && | 5001 | &tmp_logflags); |
4940 | ((mval->br_state == XFS_EXT_UNWRITTEN && | ||
4941 | ((flags & XFS_BMAPI_PREALLOC) == 0)) || | ||
4942 | (mval->br_state == XFS_EXT_NORM && | ||
4943 | ((flags & (XFS_BMAPI_PREALLOC|XFS_BMAPI_CONVERT)) == | ||
4944 | (XFS_BMAPI_PREALLOC|XFS_BMAPI_CONVERT))))) { | ||
4945 | /* | ||
4946 | * Modify (by adding) the state flag, if writing. | ||
4947 | */ | ||
4948 | ASSERT(mval->br_blockcount <= len); | ||
4949 | if ((ifp->if_flags & XFS_IFBROOT) && !cur) { | ||
4950 | cur = xfs_bmbt_init_cursor(mp, | ||
4951 | tp, ip, whichfork); | ||
4952 | cur->bc_private.b.firstblock = | ||
4953 | *firstblock; | ||
4954 | cur->bc_private.b.flist = flist; | ||
4955 | } | ||
4956 | mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN) | ||
4957 | ? XFS_EXT_NORM | ||
4958 | : XFS_EXT_UNWRITTEN; | ||
4959 | error = xfs_bmap_add_extent(tp, ip, &lastx, &cur, mval, | ||
4960 | firstblock, flist, &tmp_logflags, | ||
4961 | whichfork); | ||
4962 | logflags |= tmp_logflags; | 5002 | logflags |= tmp_logflags; |
5003 | if (error == EAGAIN) | ||
5004 | continue; | ||
4963 | if (error) | 5005 | if (error) |
4964 | goto error0; | 5006 | goto error0; |
4965 | ep = xfs_iext_get_ext(ifp, lastx); | ||
4966 | xfs_bmbt_get_all(ep, &got); | ||
4967 | /* | ||
4968 | * We may have combined previously unwritten | ||
4969 | * space with written space, so generate | ||
4970 | * another request. | ||
4971 | */ | ||
4972 | if (mval->br_blockcount < len) | ||
4973 | continue; | ||
4974 | } | 5007 | } |
4975 | 5008 | ||
4976 | /* update the extent map to return */ | 5009 | /* update the extent map to return */ |