diff options
Diffstat (limited to 'fs/xfs/xfs_rtalloc.c')
-rw-r--r-- | fs/xfs/xfs_rtalloc.c | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index ca83ddf72af4..a0dc6e5bc5b9 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c | |||
@@ -44,6 +44,7 @@ | |||
44 | #include "xfs_rw.h" | 44 | #include "xfs_rw.h" |
45 | #include "xfs_inode_item.h" | 45 | #include "xfs_inode_item.h" |
46 | #include "xfs_trans_space.h" | 46 | #include "xfs_trans_space.h" |
47 | #include "xfs_utils.h" | ||
47 | 48 | ||
48 | 49 | ||
49 | /* | 50 | /* |
@@ -73,6 +74,18 @@ STATIC int xfs_rtmodify_summary(xfs_mount_t *, xfs_trans_t *, int, | |||
73 | */ | 74 | */ |
74 | 75 | ||
75 | /* | 76 | /* |
77 | * xfs_lowbit32: get low bit set out of 32-bit argument, -1 if none set. | ||
78 | */ | ||
79 | STATIC int | ||
80 | xfs_lowbit32( | ||
81 | __uint32_t v) | ||
82 | { | ||
83 | if (v) | ||
84 | return ffs(v) - 1; | ||
85 | return -1; | ||
86 | } | ||
87 | |||
88 | /* | ||
76 | * Allocate space to the bitmap or summary file, and zero it, for growfs. | 89 | * Allocate space to the bitmap or summary file, and zero it, for growfs. |
77 | */ | 90 | */ |
78 | STATIC int /* error */ | 91 | STATIC int /* error */ |
@@ -111,14 +124,14 @@ xfs_growfs_rt_alloc( | |||
111 | XFS_GROWRTALLOC_LOG_RES(mp), 0, | 124 | XFS_GROWRTALLOC_LOG_RES(mp), 0, |
112 | XFS_TRANS_PERM_LOG_RES, | 125 | XFS_TRANS_PERM_LOG_RES, |
113 | XFS_DEFAULT_PERM_LOG_COUNT))) | 126 | XFS_DEFAULT_PERM_LOG_COUNT))) |
114 | goto error_exit; | 127 | goto error_cancel; |
115 | cancelflags = XFS_TRANS_RELEASE_LOG_RES; | 128 | cancelflags = XFS_TRANS_RELEASE_LOG_RES; |
116 | /* | 129 | /* |
117 | * Lock the inode. | 130 | * Lock the inode. |
118 | */ | 131 | */ |
119 | if ((error = xfs_trans_iget(mp, tp, ino, 0, | 132 | if ((error = xfs_trans_iget(mp, tp, ino, 0, |
120 | XFS_ILOCK_EXCL, &ip))) | 133 | XFS_ILOCK_EXCL, &ip))) |
121 | goto error_exit; | 134 | goto error_cancel; |
122 | XFS_BMAP_INIT(&flist, &firstblock); | 135 | XFS_BMAP_INIT(&flist, &firstblock); |
123 | /* | 136 | /* |
124 | * Allocate blocks to the bitmap file. | 137 | * Allocate blocks to the bitmap file. |
@@ -131,14 +144,16 @@ xfs_growfs_rt_alloc( | |||
131 | if (!error && nmap < 1) | 144 | if (!error && nmap < 1) |
132 | error = XFS_ERROR(ENOSPC); | 145 | error = XFS_ERROR(ENOSPC); |
133 | if (error) | 146 | if (error) |
134 | goto error_exit; | 147 | goto error_cancel; |
135 | /* | 148 | /* |
136 | * Free any blocks freed up in the transaction, then commit. | 149 | * Free any blocks freed up in the transaction, then commit. |
137 | */ | 150 | */ |
138 | error = xfs_bmap_finish(&tp, &flist, &committed); | 151 | error = xfs_bmap_finish(&tp, &flist, &committed); |
139 | if (error) | 152 | if (error) |
140 | goto error_exit; | 153 | goto error_cancel; |
141 | xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); | 154 | error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); |
155 | if (error) | ||
156 | goto error; | ||
142 | /* | 157 | /* |
143 | * Now we need to clear the allocated blocks. | 158 | * Now we need to clear the allocated blocks. |
144 | * Do this one block per transaction, to keep it simple. | 159 | * Do this one block per transaction, to keep it simple. |
@@ -153,13 +168,13 @@ xfs_growfs_rt_alloc( | |||
153 | */ | 168 | */ |
154 | if ((error = xfs_trans_reserve(tp, 0, | 169 | if ((error = xfs_trans_reserve(tp, 0, |
155 | XFS_GROWRTZERO_LOG_RES(mp), 0, 0, 0))) | 170 | XFS_GROWRTZERO_LOG_RES(mp), 0, 0, 0))) |
156 | goto error_exit; | 171 | goto error_cancel; |
157 | /* | 172 | /* |
158 | * Lock the bitmap inode. | 173 | * Lock the bitmap inode. |
159 | */ | 174 | */ |
160 | if ((error = xfs_trans_iget(mp, tp, ino, 0, | 175 | if ((error = xfs_trans_iget(mp, tp, ino, 0, |
161 | XFS_ILOCK_EXCL, &ip))) | 176 | XFS_ILOCK_EXCL, &ip))) |
162 | goto error_exit; | 177 | goto error_cancel; |
163 | /* | 178 | /* |
164 | * Get a buffer for the block. | 179 | * Get a buffer for the block. |
165 | */ | 180 | */ |
@@ -168,14 +183,16 @@ xfs_growfs_rt_alloc( | |||
168 | mp->m_bsize, 0); | 183 | mp->m_bsize, 0); |
169 | if (bp == NULL) { | 184 | if (bp == NULL) { |
170 | error = XFS_ERROR(EIO); | 185 | error = XFS_ERROR(EIO); |
171 | goto error_exit; | 186 | goto error_cancel; |
172 | } | 187 | } |
173 | memset(XFS_BUF_PTR(bp), 0, mp->m_sb.sb_blocksize); | 188 | memset(XFS_BUF_PTR(bp), 0, mp->m_sb.sb_blocksize); |
174 | xfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1); | 189 | xfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1); |
175 | /* | 190 | /* |
176 | * Commit the transaction. | 191 | * Commit the transaction. |
177 | */ | 192 | */ |
178 | xfs_trans_commit(tp, 0); | 193 | error = xfs_trans_commit(tp, 0); |
194 | if (error) | ||
195 | goto error; | ||
179 | } | 196 | } |
180 | /* | 197 | /* |
181 | * Go on to the next extent, if any. | 198 | * Go on to the next extent, if any. |
@@ -183,8 +200,9 @@ xfs_growfs_rt_alloc( | |||
183 | oblocks = map.br_startoff + map.br_blockcount; | 200 | oblocks = map.br_startoff + map.br_blockcount; |
184 | } | 201 | } |
185 | return 0; | 202 | return 0; |
186 | error_exit: | 203 | error_cancel: |
187 | xfs_trans_cancel(tp, cancelflags); | 204 | xfs_trans_cancel(tp, cancelflags); |
205 | error: | ||
188 | return error; | 206 | return error; |
189 | } | 207 | } |
190 | 208 | ||
@@ -432,7 +450,6 @@ xfs_rtallocate_extent_near( | |||
432 | } | 450 | } |
433 | bbno = XFS_BITTOBLOCK(mp, bno); | 451 | bbno = XFS_BITTOBLOCK(mp, bno); |
434 | i = 0; | 452 | i = 0; |
435 | ASSERT(minlen != 0); | ||
436 | log2len = xfs_highbit32(minlen); | 453 | log2len = xfs_highbit32(minlen); |
437 | /* | 454 | /* |
438 | * Loop over all bitmap blocks (bbno + i is current block). | 455 | * Loop over all bitmap blocks (bbno + i is current block). |
@@ -601,8 +618,6 @@ xfs_rtallocate_extent_size( | |||
601 | xfs_suminfo_t sum; /* summary information for extents */ | 618 | xfs_suminfo_t sum; /* summary information for extents */ |
602 | 619 | ||
603 | ASSERT(minlen % prod == 0 && maxlen % prod == 0); | 620 | ASSERT(minlen % prod == 0 && maxlen % prod == 0); |
604 | ASSERT(maxlen != 0); | ||
605 | |||
606 | /* | 621 | /* |
607 | * Loop over all the levels starting with maxlen. | 622 | * Loop over all the levels starting with maxlen. |
608 | * At each level, look at all the bitmap blocks, to see if there | 623 | * At each level, look at all the bitmap blocks, to see if there |
@@ -660,9 +675,6 @@ xfs_rtallocate_extent_size( | |||
660 | *rtblock = NULLRTBLOCK; | 675 | *rtblock = NULLRTBLOCK; |
661 | return 0; | 676 | return 0; |
662 | } | 677 | } |
663 | ASSERT(minlen != 0); | ||
664 | ASSERT(maxlen != 0); | ||
665 | |||
666 | /* | 678 | /* |
667 | * Loop over sizes, from maxlen down to minlen. | 679 | * Loop over sizes, from maxlen down to minlen. |
668 | * This time, when we do the allocations, allow smaller ones | 680 | * This time, when we do the allocations, allow smaller ones |
@@ -1869,6 +1881,7 @@ xfs_growfs_rt( | |||
1869 | xfs_trans_t *tp; /* transaction pointer */ | 1881 | xfs_trans_t *tp; /* transaction pointer */ |
1870 | 1882 | ||
1871 | sbp = &mp->m_sb; | 1883 | sbp = &mp->m_sb; |
1884 | cancelflags = 0; | ||
1872 | /* | 1885 | /* |
1873 | * Initial error checking. | 1886 | * Initial error checking. |
1874 | */ | 1887 | */ |
@@ -1948,7 +1961,6 @@ xfs_growfs_rt( | |||
1948 | nsbp->sb_blocksize * nsbp->sb_rextsize); | 1961 | nsbp->sb_blocksize * nsbp->sb_rextsize); |
1949 | nsbp->sb_rextents = nsbp->sb_rblocks; | 1962 | nsbp->sb_rextents = nsbp->sb_rblocks; |
1950 | do_div(nsbp->sb_rextents, nsbp->sb_rextsize); | 1963 | do_div(nsbp->sb_rextents, nsbp->sb_rextsize); |
1951 | ASSERT(nsbp->sb_rextents != 0); | ||
1952 | nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents); | 1964 | nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents); |
1953 | nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1; | 1965 | nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1; |
1954 | nrsumsize = | 1966 | nrsumsize = |
@@ -2036,13 +2048,15 @@ xfs_growfs_rt( | |||
2036 | */ | 2048 | */ |
2037 | mp->m_rsumlevels = nrsumlevels; | 2049 | mp->m_rsumlevels = nrsumlevels; |
2038 | mp->m_rsumsize = nrsumsize; | 2050 | mp->m_rsumsize = nrsumsize; |
2039 | /* | 2051 | |
2040 | * Commit the transaction. | 2052 | error = xfs_trans_commit(tp, 0); |
2041 | */ | 2053 | if (error) { |
2042 | xfs_trans_commit(tp, 0); | 2054 | tp = NULL; |
2055 | break; | ||
2056 | } | ||
2043 | } | 2057 | } |
2044 | 2058 | ||
2045 | if (error) | 2059 | if (error && tp) |
2046 | xfs_trans_cancel(tp, cancelflags); | 2060 | xfs_trans_cancel(tp, cancelflags); |
2047 | 2061 | ||
2048 | /* | 2062 | /* |
@@ -2273,7 +2287,7 @@ xfs_rtmount_inodes( | |||
2273 | ASSERT(sbp->sb_rsumino != NULLFSINO); | 2287 | ASSERT(sbp->sb_rsumino != NULLFSINO); |
2274 | error = xfs_iget(mp, NULL, sbp->sb_rsumino, 0, 0, &mp->m_rsumip, 0); | 2288 | error = xfs_iget(mp, NULL, sbp->sb_rsumino, 0, 0, &mp->m_rsumip, 0); |
2275 | if (error) { | 2289 | if (error) { |
2276 | VN_RELE(XFS_ITOV(mp->m_rbmip)); | 2290 | IRELE(mp->m_rbmip); |
2277 | return error; | 2291 | return error; |
2278 | } | 2292 | } |
2279 | ASSERT(mp->m_rsumip != NULL); | 2293 | ASSERT(mp->m_rsumip != NULL); |