aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2011-09-18 16:40:57 -0400
committerAlex Elder <aelder@sgi.com>2011-10-11 22:15:05 -0400
commit0937e0fd8be6f9c26844127d39d677bb752e8741 (patch)
treef05f9c8a7cb6459726a9f207025b495853b913e8
parentbaf41a52b9c62f9a825371806129ed12e2c1e2d8 (diff)
xfs: move firstblock and bmap freelist cursor into bmalloca structure
Rather than passing the firstblock and freelist structure around, embed it into the bmalloca structure and remove it from the function parameters. This also enables the minleft parameter to be set only once in xfs_bmapi_write(), and the freelist cursor directly queried in xfs_bmapi_allocate to clear it when the lowspace algorithm is activated. Signed-off-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Alex Elder <aelder@sgi.com>
-rw-r--r--fs/xfs/xfs_bmap.c92
-rw-r--r--fs/xfs/xfs_bmap.h4
-rw-r--r--fs/xfs/xfs_filestream.c2
3 files changed, 48 insertions, 50 deletions
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
index 68edf99bfad6..608a0013791b 100644
--- a/fs/xfs/xfs_bmap.c
+++ b/fs/xfs/xfs_bmap.c
@@ -2006,9 +2006,9 @@ xfs_bmap_adjacent(
2006 XFS_FSB_TO_AGBNO(mp, x) < mp->m_sb.sb_agblocks) 2006 XFS_FSB_TO_AGBNO(mp, x) < mp->m_sb.sb_agblocks)
2007 2007
2008 mp = ap->ip->i_mount; 2008 mp = ap->ip->i_mount;
2009 nullfb = ap->firstblock == NULLFSBLOCK; 2009 nullfb = *ap->firstblock == NULLFSBLOCK;
2010 rt = XFS_IS_REALTIME_INODE(ap->ip) && ap->userdata; 2010 rt = XFS_IS_REALTIME_INODE(ap->ip) && ap->userdata;
2011 fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, ap->firstblock); 2011 fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, *ap->firstblock);
2012 /* 2012 /*
2013 * If allocating at eof, and there's a previous real block, 2013 * If allocating at eof, and there's a previous real block,
2014 * try to use its last block as our starting point. 2014 * try to use its last block as our starting point.
@@ -2380,8 +2380,8 @@ xfs_bmap_btalloc(
2380 ASSERT(!error); 2380 ASSERT(!error);
2381 ASSERT(ap->alen); 2381 ASSERT(ap->alen);
2382 } 2382 }
2383 nullfb = ap->firstblock == NULLFSBLOCK; 2383 nullfb = *ap->firstblock == NULLFSBLOCK;
2384 fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, ap->firstblock); 2384 fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, *ap->firstblock);
2385 if (nullfb) { 2385 if (nullfb) {
2386 if (ap->userdata && xfs_inode_is_filestream(ap->ip)) { 2386 if (ap->userdata && xfs_inode_is_filestream(ap->ip)) {
2387 ag = xfs_filestream_lookup_ag(ap->ip); 2387 ag = xfs_filestream_lookup_ag(ap->ip);
@@ -2391,7 +2391,7 @@ xfs_bmap_btalloc(
2391 ap->rval = XFS_INO_TO_FSB(mp, ap->ip->i_ino); 2391 ap->rval = XFS_INO_TO_FSB(mp, ap->ip->i_ino);
2392 } 2392 }
2393 } else 2393 } else
2394 ap->rval = ap->firstblock; 2394 ap->rval = *ap->firstblock;
2395 2395
2396 xfs_bmap_adjacent(ap); 2396 xfs_bmap_adjacent(ap);
2397 2397
@@ -2402,7 +2402,7 @@ xfs_bmap_btalloc(
2402 if (nullfb || XFS_FSB_TO_AGNO(mp, ap->rval) == fb_agno) 2402 if (nullfb || XFS_FSB_TO_AGNO(mp, ap->rval) == fb_agno)
2403 ; 2403 ;
2404 else 2404 else
2405 ap->rval = ap->firstblock; 2405 ap->rval = *ap->firstblock;
2406 /* 2406 /*
2407 * Normal allocation, done through xfs_alloc_vextent. 2407 * Normal allocation, done through xfs_alloc_vextent.
2408 */ 2408 */
@@ -2413,13 +2413,13 @@ xfs_bmap_btalloc(
2413 2413
2414 /* Trim the allocation back to the maximum an AG can fit. */ 2414 /* Trim the allocation back to the maximum an AG can fit. */
2415 args.maxlen = MIN(ap->alen, XFS_ALLOC_AG_MAX_USABLE(mp)); 2415 args.maxlen = MIN(ap->alen, XFS_ALLOC_AG_MAX_USABLE(mp));
2416 args.firstblock = ap->firstblock; 2416 args.firstblock = *ap->firstblock;
2417 blen = 0; 2417 blen = 0;
2418 if (nullfb) { 2418 if (nullfb) {
2419 error = xfs_bmap_btalloc_nullfb(ap, &args, &blen); 2419 error = xfs_bmap_btalloc_nullfb(ap, &args, &blen);
2420 if (error) 2420 if (error)
2421 return error; 2421 return error;
2422 } else if (ap->low) { 2422 } else if (ap->flist->xbf_low) {
2423 if (xfs_inode_is_filestream(ap->ip)) 2423 if (xfs_inode_is_filestream(ap->ip))
2424 args.type = XFS_ALLOCTYPE_FIRST_AG; 2424 args.type = XFS_ALLOCTYPE_FIRST_AG;
2425 else 2425 else
@@ -2452,7 +2452,7 @@ xfs_bmap_btalloc(
2452 * is >= the stripe unit and the allocation offset is 2452 * is >= the stripe unit and the allocation offset is
2453 * at the end of file. 2453 * at the end of file.
2454 */ 2454 */
2455 if (!ap->low && ap->aeof) { 2455 if (!ap->flist->xbf_low && ap->aeof) {
2456 if (!ap->off) { 2456 if (!ap->off) {
2457 args.alignment = mp->m_dalign; 2457 args.alignment = mp->m_dalign;
2458 atype = args.type; 2458 atype = args.type;
@@ -2540,12 +2540,25 @@ xfs_bmap_btalloc(
2540 args.minleft = 0; 2540 args.minleft = 0;
2541 if ((error = xfs_alloc_vextent(&args))) 2541 if ((error = xfs_alloc_vextent(&args)))
2542 return error; 2542 return error;
2543 ap->low = 1; 2543 ap->flist->xbf_low = 1;
2544 } 2544 }
2545 if (args.fsbno != NULLFSBLOCK) { 2545 if (args.fsbno != NULLFSBLOCK) {
2546 ap->firstblock = ap->rval = args.fsbno; 2546 /*
2547 * check the allocation happened at the same or higher AG than
2548 * the first block that was allocated.
2549 */
2550 ASSERT(*ap->firstblock == NULLFSBLOCK ||
2551 XFS_FSB_TO_AGNO(mp, *ap->firstblock) ==
2552 XFS_FSB_TO_AGNO(mp, args.fsbno) ||
2553 (ap->flist->xbf_low &&
2554 XFS_FSB_TO_AGNO(mp, *ap->firstblock) <
2555 XFS_FSB_TO_AGNO(mp, args.fsbno)));
2556
2557 ap->rval = args.fsbno;
2558 if (*ap->firstblock == NULLFSBLOCK)
2559 *ap->firstblock = args.fsbno;
2547 ASSERT(nullfb || fb_agno == args.agno || 2560 ASSERT(nullfb || fb_agno == args.agno ||
2548 (ap->low && fb_agno < args.agno)); 2561 (ap->flist->xbf_low && fb_agno < args.agno));
2549 ap->alen = args.len; 2562 ap->alen = args.len;
2550 ap->ip->i_d.di_nblocks += args.len; 2563 ap->ip->i_d.di_nblocks += args.len;
2551 xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE); 2564 xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE);
@@ -4596,8 +4609,6 @@ xfs_bmapi_allocate(
4596 struct xfs_bmalloca *bma, 4609 struct xfs_bmalloca *bma,
4597 xfs_extnum_t *lastx, 4610 xfs_extnum_t *lastx,
4598 struct xfs_btree_cur **cur, 4611 struct xfs_btree_cur **cur,
4599 xfs_fsblock_t *firstblock,
4600 struct xfs_bmap_free *flist,
4601 int flags, 4612 int flags,
4602 int *nallocs, 4613 int *nallocs,
4603 int *logflags) 4614 int *logflags)
@@ -4647,9 +4658,7 @@ xfs_bmapi_allocate(
4647 */ 4658 */
4648 bma->alen = alen; 4659 bma->alen = alen;
4649 bma->off = aoff; 4660 bma->off = aoff;
4650 bma->firstblock = *firstblock;
4651 bma->minlen = (flags & XFS_BMAPI_CONTIG) ? alen : 1; 4661 bma->minlen = (flags & XFS_BMAPI_CONTIG) ? alen : 1;
4652 bma->low = flist->xbf_low;
4653 bma->aeof = 0; 4662 bma->aeof = 0;
4654 4663
4655 /* 4664 /*
@@ -4671,24 +4680,18 @@ xfs_bmapi_allocate(
4671 * Copy out result fields. 4680 * Copy out result fields.
4672 */ 4681 */
4673 abno = bma->rval; 4682 abno = bma->rval;
4674 flist->xbf_low = bma->low;
4675 alen = bma->alen; 4683 alen = bma->alen;
4676 aoff = bma->off; 4684 aoff = bma->off;
4677 ASSERT(*firstblock == NULLFSBLOCK || 4685 if (bma->flist->xbf_low)
4678 XFS_FSB_TO_AGNO(mp, *firstblock) == 4686 bma->minleft = 0;
4679 XFS_FSB_TO_AGNO(mp, bma->firstblock) ||
4680 (flist->xbf_low &&
4681 XFS_FSB_TO_AGNO(mp, *firstblock) <
4682 XFS_FSB_TO_AGNO(mp, bma->firstblock)));
4683 *firstblock = bma->firstblock;
4684 if (*cur) 4687 if (*cur)
4685 (*cur)->bc_private.b.firstblock = *firstblock; 4688 (*cur)->bc_private.b.firstblock = *bma->firstblock;
4686 if (abno == NULLFSBLOCK) 4689 if (abno == NULLFSBLOCK)
4687 return 0; 4690 return 0;
4688 if ((ifp->if_flags & XFS_IFBROOT) && !*cur) { 4691 if ((ifp->if_flags & XFS_IFBROOT) && !*cur) {
4689 (*cur) = xfs_bmbt_init_cursor(mp, bma->tp, bma->ip, whichfork); 4692 (*cur) = xfs_bmbt_init_cursor(mp, bma->tp, bma->ip, whichfork);
4690 (*cur)->bc_private.b.firstblock = *firstblock; 4693 (*cur)->bc_private.b.firstblock = *bma->firstblock;
4691 (*cur)->bc_private.b.flist = flist; 4694 (*cur)->bc_private.b.flist = bma->flist;
4692 } 4695 }
4693 /* 4696 /*
4694 * Bump the number of extents we've allocated 4697 * Bump the number of extents we've allocated
@@ -4715,11 +4718,12 @@ xfs_bmapi_allocate(
4715 4718
4716 if (bma->wasdel) { 4719 if (bma->wasdel) {
4717 error = xfs_bmap_add_extent_delay_real(bma->tp, bma->ip, lastx, 4720 error = xfs_bmap_add_extent_delay_real(bma->tp, bma->ip, lastx,
4718 cur, &bma->got, firstblock, flist, logflags); 4721 cur, &bma->got, bma->firstblock, bma->flist,
4722 logflags);
4719 } else { 4723 } else {
4720 error = xfs_bmap_add_extent_hole_real(bma->tp, bma->ip, lastx, 4724 error = xfs_bmap_add_extent_hole_real(bma->tp, bma->ip, lastx,
4721 cur, &bma->got, firstblock, flist, logflags, 4725 cur, &bma->got, bma->firstblock, bma->flist,
4722 whichfork); 4726 logflags, whichfork);
4723 } 4727 }
4724 4728
4725 if (error) 4729 if (error)
@@ -4746,8 +4750,6 @@ xfs_bmapi_convert_unwritten(
4746 xfs_filblks_t len, 4750 xfs_filblks_t len,
4747 xfs_extnum_t *lastx, 4751 xfs_extnum_t *lastx,
4748 struct xfs_btree_cur **cur, 4752 struct xfs_btree_cur **cur,
4749 xfs_fsblock_t *firstblock,
4750 struct xfs_bmap_free *flist,
4751 int flags, 4753 int flags,
4752 int *logflags) 4754 int *logflags)
4753{ 4755{
@@ -4776,14 +4778,14 @@ xfs_bmapi_convert_unwritten(
4776 if ((ifp->if_flags & XFS_IFBROOT) && !*cur) { 4778 if ((ifp->if_flags & XFS_IFBROOT) && !*cur) {
4777 *cur = xfs_bmbt_init_cursor(bma->ip->i_mount, bma->tp, 4779 *cur = xfs_bmbt_init_cursor(bma->ip->i_mount, bma->tp,
4778 bma->ip, whichfork); 4780 bma->ip, whichfork);
4779 (*cur)->bc_private.b.firstblock = *firstblock; 4781 (*cur)->bc_private.b.firstblock = *bma->firstblock;
4780 (*cur)->bc_private.b.flist = flist; 4782 (*cur)->bc_private.b.flist = bma->flist;
4781 } 4783 }
4782 mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN) 4784 mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN)
4783 ? XFS_EXT_NORM : XFS_EXT_UNWRITTEN; 4785 ? XFS_EXT_NORM : XFS_EXT_UNWRITTEN;
4784 4786
4785 error = xfs_bmap_add_extent_unwritten_real(bma->tp, bma->ip, lastx, 4787 error = xfs_bmap_add_extent_unwritten_real(bma->tp, bma->ip, lastx,
4786 cur, mval, firstblock, flist, logflags); 4788 cur, mval, bma->firstblock, bma->flist, logflags);
4787 if (error) 4789 if (error)
4788 return error; 4790 return error;
4789 4791
@@ -4838,7 +4840,6 @@ xfs_bmapi_write(
4838 int error; /* error return */ 4840 int error; /* error return */
4839 xfs_extnum_t lastx; /* last useful extent number */ 4841 xfs_extnum_t lastx; /* last useful extent number */
4840 int logflags; /* flags for transaction logging */ 4842 int logflags; /* flags for transaction logging */
4841 xfs_extlen_t minleft; /* min blocks left after allocation */
4842 int n; /* current extent index */ 4843 int n; /* current extent index */
4843 int nallocs; /* number of extents alloc'd */ 4844 int nallocs; /* number of extents alloc'd */
4844 xfs_fileoff_t obno; /* old block number (offset) */ 4845 xfs_fileoff_t obno; /* old block number (offset) */
@@ -4900,11 +4901,11 @@ xfs_bmapi_write(
4900 4901
4901 if (*firstblock == NULLFSBLOCK) { 4902 if (*firstblock == NULLFSBLOCK) {
4902 if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE) 4903 if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE)
4903 minleft = be16_to_cpu(ifp->if_broot->bb_level) + 1; 4904 bma.minleft = be16_to_cpu(ifp->if_broot->bb_level) + 1;
4904 else 4905 else
4905 minleft = 1; 4906 bma.minleft = 1;
4906 } else { 4907 } else {
4907 minleft = 0; 4908 bma.minleft = 0;
4908 } 4909 }
4909 4910
4910 if (!(ifp->if_flags & XFS_IFEXTENTS)) { 4911 if (!(ifp->if_flags & XFS_IFEXTENTS)) {
@@ -4923,6 +4924,8 @@ xfs_bmapi_write(
4923 bma.ip = ip; 4924 bma.ip = ip;
4924 bma.total = total; 4925 bma.total = total;
4925 bma.userdata = 0; 4926 bma.userdata = 0;
4927 bma.flist = flist;
4928 bma.firstblock = firstblock;
4926 4929
4927 while (bno < end && n < *nmap) { 4930 while (bno < end && n < *nmap) {
4928 inhole = eof || bma.got.br_startoff > bno; 4931 inhole = eof || bma.got.br_startoff > bno;
@@ -4938,16 +4941,12 @@ xfs_bmapi_write(
4938 bma.wasdel = wasdelay; 4941 bma.wasdel = wasdelay;
4939 bma.alen = len; 4942 bma.alen = len;
4940 bma.off = bno; 4943 bma.off = bno;
4941 bma.minleft = minleft;
4942 4944
4943 error = xfs_bmapi_allocate(&bma, &lastx, &cur, 4945 error = xfs_bmapi_allocate(&bma, &lastx, &cur, flags,
4944 firstblock, flist, flags, &nallocs, 4946 &nallocs, &tmp_logflags);
4945 &tmp_logflags);
4946 logflags |= tmp_logflags; 4947 logflags |= tmp_logflags;
4947 if (error) 4948 if (error)
4948 goto error0; 4949 goto error0;
4949 if (flist && flist->xbf_low)
4950 minleft = 0;
4951 if (bma.rval == NULLFSBLOCK) 4950 if (bma.rval == NULLFSBLOCK)
4952 break; 4951 break;
4953 } 4952 }
@@ -4958,8 +4957,7 @@ xfs_bmapi_write(
4958 4957
4959 /* Execute unwritten extent conversion if necessary */ 4958 /* Execute unwritten extent conversion if necessary */
4960 error = xfs_bmapi_convert_unwritten(&bma, mval, len, &lastx, 4959 error = xfs_bmapi_convert_unwritten(&bma, mval, len, &lastx,
4961 &cur, firstblock, flist, 4960 &cur, flags, &tmp_logflags);
4962 flags, &tmp_logflags);
4963 logflags |= tmp_logflags; 4961 logflags |= tmp_logflags;
4964 if (error == EAGAIN) 4962 if (error == EAGAIN)
4965 continue; 4963 continue;
diff --git a/fs/xfs/xfs_bmap.h b/fs/xfs/xfs_bmap.h
index 6e8f8aee7cdb..6e7c7a50d248 100644
--- a/fs/xfs/xfs_bmap.h
+++ b/fs/xfs/xfs_bmap.h
@@ -109,7 +109,8 @@ static inline void xfs_bmap_init(xfs_bmap_free_t *flp, xfs_fsblock_t *fbp)
109 * Argument structure for xfs_bmap_alloc. 109 * Argument structure for xfs_bmap_alloc.
110 */ 110 */
111typedef struct xfs_bmalloca { 111typedef struct xfs_bmalloca {
112 xfs_fsblock_t firstblock; /* i/o first block allocated */ 112 xfs_fsblock_t *firstblock; /* i/o first block allocated */
113 struct xfs_bmap_free *flist; /* bmap freelist */
113 xfs_fsblock_t rval; /* starting block of new extent */ 114 xfs_fsblock_t rval; /* starting block of new extent */
114 xfs_fileoff_t off; /* offset in file filling in */ 115 xfs_fileoff_t off; /* offset in file filling in */
115 struct xfs_trans *tp; /* transaction pointer */ 116 struct xfs_trans *tp; /* transaction pointer */
@@ -123,7 +124,6 @@ typedef struct xfs_bmalloca {
123 char eof; /* set if allocating past last extent */ 124 char eof; /* set if allocating past last extent */
124 char wasdel; /* replacing a delayed allocation */ 125 char wasdel; /* replacing a delayed allocation */
125 char userdata;/* set if is user data */ 126 char userdata;/* set if is user data */
126 char low; /* low on space, using seq'l ags */
127 char aeof; /* allocated space at eof */ 127 char aeof; /* allocated space at eof */
128 char conv; /* overwriting unwritten extents */ 128 char conv; /* overwriting unwritten extents */
129} xfs_bmalloca_t; 129} xfs_bmalloca_t;
diff --git a/fs/xfs/xfs_filestream.c b/fs/xfs/xfs_filestream.c
index 3ff3d9e23ded..137f957b8c7e 100644
--- a/fs/xfs/xfs_filestream.c
+++ b/fs/xfs/xfs_filestream.c
@@ -761,7 +761,7 @@ xfs_filestream_new_ag(
761 */ 761 */
762 ag = (ag == NULLAGNUMBER) ? 0 : (ag + 1) % mp->m_sb.sb_agcount; 762 ag = (ag == NULLAGNUMBER) ? 0 : (ag + 1) % mp->m_sb.sb_agcount;
763 flags = (ap->userdata ? XFS_PICK_USERDATA : 0) | 763 flags = (ap->userdata ? XFS_PICK_USERDATA : 0) |
764 (ap->low ? XFS_PICK_LOWSPACE : 0); 764 (ap->flist->xbf_low ? XFS_PICK_LOWSPACE : 0);
765 765
766 err = _xfs_filestream_pick_ag(mp, ag, agp, flags, minlen); 766 err = _xfs_filestream_pick_ag(mp, ag, agp, flags, minlen);
767 if (err || *agp == NULLAGNUMBER) 767 if (err || *agp == NULLAGNUMBER)