diff options
author | Christoph Hellwig <hch@infradead.org> | 2012-07-03 12:21:22 -0400 |
---|---|---|
committer | Ben Myers <bpm@sgi.com> | 2012-07-22 11:46:56 -0400 |
commit | 475ee413f34165f8e6fcd7fbff3a4da1dce48c99 (patch) | |
tree | a32dadb75dbbddf45fdd989ad8f44dd0ed466368 /fs/xfs/xfs_inode.c | |
parent | 6b7a03f03a2f8b1629133e35729eba4727fae3cc (diff) |
xfs: merge xfs_itobp into xfs_imap_to_bp
All callers of xfs_imap_to_bp want the dinode pointer, so let's calculate it
inside xfs_imap_to_bp. Once that is done xfs_itobp becomes a fairly pointless
wrapper which can be replaced with direct calls to xfs_imap_to_bp.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_inode.c')
-rw-r--r-- | fs/xfs/xfs_inode.c | 131 |
1 files changed, 47 insertions, 84 deletions
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 257f3c463e0e..34c985de5fa0 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c | |||
@@ -132,23 +132,28 @@ xfs_inobp_check( | |||
132 | #endif | 132 | #endif |
133 | 133 | ||
134 | /* | 134 | /* |
135 | * Find the buffer associated with the given inode map | 135 | * This routine is called to map an inode to the buffer containing the on-disk |
136 | * We do basic validation checks on the buffer once it has been | 136 | * version of the inode. It returns a pointer to the buffer containing the |
137 | * retrieved from disk. | 137 | * on-disk inode in the bpp parameter, and in the dipp parameter it returns a |
138 | * pointer to the on-disk inode within that buffer. | ||
139 | * | ||
140 | * If a non-zero error is returned, then the contents of bpp and dipp are | ||
141 | * undefined. | ||
138 | */ | 142 | */ |
139 | STATIC int | 143 | int |
140 | xfs_imap_to_bp( | 144 | xfs_imap_to_bp( |
141 | xfs_mount_t *mp, | 145 | struct xfs_mount *mp, |
142 | xfs_trans_t *tp, | 146 | struct xfs_trans *tp, |
143 | struct xfs_imap *imap, | 147 | struct xfs_imap *imap, |
144 | xfs_buf_t **bpp, | 148 | struct xfs_dinode **dipp, |
145 | uint buf_flags, | 149 | struct xfs_buf **bpp, |
146 | uint iget_flags) | 150 | uint buf_flags, |
151 | uint iget_flags) | ||
147 | { | 152 | { |
148 | int error; | 153 | struct xfs_buf *bp; |
149 | int i; | 154 | int error; |
150 | int ni; | 155 | int i; |
151 | xfs_buf_t *bp; | 156 | int ni; |
152 | 157 | ||
153 | buf_flags |= XBF_UNMAPPED; | 158 | buf_flags |= XBF_UNMAPPED; |
154 | error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, imap->im_blkno, | 159 | error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, imap->im_blkno, |
@@ -189,8 +194,8 @@ xfs_imap_to_bp( | |||
189 | xfs_trans_brelse(tp, bp); | 194 | xfs_trans_brelse(tp, bp); |
190 | return XFS_ERROR(EINVAL); | 195 | return XFS_ERROR(EINVAL); |
191 | } | 196 | } |
192 | XFS_CORRUPTION_ERROR("xfs_imap_to_bp", | 197 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_HIGH, |
193 | XFS_ERRLEVEL_HIGH, mp, dip); | 198 | mp, dip); |
194 | #ifdef DEBUG | 199 | #ifdef DEBUG |
195 | xfs_emerg(mp, | 200 | xfs_emerg(mp, |
196 | "bad inode magic/vsn daddr %lld #%d (magic=%x)", | 201 | "bad inode magic/vsn daddr %lld #%d (magic=%x)", |
@@ -204,7 +209,9 @@ xfs_imap_to_bp( | |||
204 | } | 209 | } |
205 | 210 | ||
206 | xfs_inobp_check(mp, bp); | 211 | xfs_inobp_check(mp, bp); |
212 | |||
207 | *bpp = bp; | 213 | *bpp = bp; |
214 | *dipp = (struct xfs_dinode *)xfs_buf_offset(bp, imap->im_boffset); | ||
208 | return 0; | 215 | return 0; |
209 | } | 216 | } |
210 | 217 | ||
@@ -240,63 +247,15 @@ xfs_inotobp( | |||
240 | if (error) | 247 | if (error) |
241 | return error; | 248 | return error; |
242 | 249 | ||
243 | error = xfs_imap_to_bp(mp, tp, &imap, &bp, 0, imap_flags); | 250 | error = xfs_imap_to_bp(mp, tp, &imap, dipp, &bp, 0, imap_flags); |
244 | if (error) | 251 | if (error) |
245 | return error; | 252 | return error; |
246 | 253 | ||
247 | *dipp = (xfs_dinode_t *)xfs_buf_offset(bp, imap.im_boffset); | ||
248 | *bpp = bp; | 254 | *bpp = bp; |
249 | *offset = imap.im_boffset; | 255 | *offset = imap.im_boffset; |
250 | return 0; | 256 | return 0; |
251 | } | 257 | } |
252 | 258 | ||
253 | |||
254 | /* | ||
255 | * This routine is called to map an inode to the buffer containing | ||
256 | * the on-disk version of the inode. It returns a pointer to the | ||
257 | * buffer containing the on-disk inode in the bpp parameter, and in | ||
258 | * the dip parameter it returns a pointer to the on-disk inode within | ||
259 | * that buffer. | ||
260 | * | ||
261 | * If a non-zero error is returned, then the contents of bpp and | ||
262 | * dipp are undefined. | ||
263 | * | ||
264 | * The inode is expected to already been mapped to its buffer and read | ||
265 | * in once, thus we can use the mapping information stored in the inode | ||
266 | * rather than calling xfs_imap(). This allows us to avoid the overhead | ||
267 | * of looking at the inode btree for small block file systems | ||
268 | * (see xfs_imap()). | ||
269 | */ | ||
270 | int | ||
271 | xfs_itobp( | ||
272 | xfs_mount_t *mp, | ||
273 | xfs_trans_t *tp, | ||
274 | xfs_inode_t *ip, | ||
275 | xfs_dinode_t **dipp, | ||
276 | xfs_buf_t **bpp, | ||
277 | uint buf_flags) | ||
278 | { | ||
279 | xfs_buf_t *bp; | ||
280 | int error; | ||
281 | |||
282 | ASSERT(ip->i_imap.im_blkno != 0); | ||
283 | |||
284 | error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &bp, buf_flags, 0); | ||
285 | if (error) | ||
286 | return error; | ||
287 | |||
288 | if (!bp) { | ||
289 | ASSERT(buf_flags & XBF_TRYLOCK); | ||
290 | ASSERT(tp == NULL); | ||
291 | *bpp = NULL; | ||
292 | return EAGAIN; | ||
293 | } | ||
294 | |||
295 | *dipp = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset); | ||
296 | *bpp = bp; | ||
297 | return 0; | ||
298 | } | ||
299 | |||
300 | /* | 259 | /* |
301 | * Move inode type and inode format specific information from the | 260 | * Move inode type and inode format specific information from the |
302 | * on-disk inode to the in-core inode. For fifos, devs, and sockets | 261 | * on-disk inode to the in-core inode. For fifos, devs, and sockets |
@@ -796,10 +755,9 @@ xfs_iread( | |||
796 | /* | 755 | /* |
797 | * Get pointers to the on-disk inode and the buffer containing it. | 756 | * Get pointers to the on-disk inode and the buffer containing it. |
798 | */ | 757 | */ |
799 | error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &bp, 0, iget_flags); | 758 | error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &dip, &bp, 0, iget_flags); |
800 | if (error) | 759 | if (error) |
801 | return error; | 760 | return error; |
802 | dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset); | ||
803 | 761 | ||
804 | /* | 762 | /* |
805 | * If we got something that isn't an inode it means someone | 763 | * If we got something that isn't an inode it means someone |
@@ -876,7 +834,7 @@ xfs_iread( | |||
876 | /* | 834 | /* |
877 | * Use xfs_trans_brelse() to release the buffer containing the | 835 | * Use xfs_trans_brelse() to release the buffer containing the |
878 | * on-disk inode, because it was acquired with xfs_trans_read_buf() | 836 | * on-disk inode, because it was acquired with xfs_trans_read_buf() |
879 | * in xfs_itobp() above. If tp is NULL, this is just a normal | 837 | * in xfs_imap_to_bp() above. If tp is NULL, this is just a normal |
880 | * brelse(). If we're within a transaction, then xfs_trans_brelse() | 838 | * brelse(). If we're within a transaction, then xfs_trans_brelse() |
881 | * will only release the buffer if it is not dirty within the | 839 | * will only release the buffer if it is not dirty within the |
882 | * transaction. It will be OK to release the buffer in this case, | 840 | * transaction. It will be OK to release the buffer in this case, |
@@ -1355,7 +1313,8 @@ xfs_iunlink( | |||
1355 | * Here we put the head pointer into our next pointer, | 1313 | * Here we put the head pointer into our next pointer, |
1356 | * and then we fall through to point the head at us. | 1314 | * and then we fall through to point the head at us. |
1357 | */ | 1315 | */ |
1358 | error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0); | 1316 | error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &dip, &ibp, |
1317 | 0, 0); | ||
1359 | if (error) | 1318 | if (error) |
1360 | return error; | 1319 | return error; |
1361 | 1320 | ||
@@ -1429,16 +1388,16 @@ xfs_iunlink_remove( | |||
1429 | 1388 | ||
1430 | if (be32_to_cpu(agi->agi_unlinked[bucket_index]) == agino) { | 1389 | if (be32_to_cpu(agi->agi_unlinked[bucket_index]) == agino) { |
1431 | /* | 1390 | /* |
1432 | * We're at the head of the list. Get the inode's | 1391 | * We're at the head of the list. Get the inode's on-disk |
1433 | * on-disk buffer to see if there is anyone after us | 1392 | * buffer to see if there is anyone after us on the list. |
1434 | * on the list. Only modify our next pointer if it | 1393 | * Only modify our next pointer if it is not already NULLAGINO. |
1435 | * is not already NULLAGINO. This saves us the overhead | 1394 | * This saves us the overhead of dealing with the buffer when |
1436 | * of dealing with the buffer when there is no need to | 1395 | * there is no need to change it. |
1437 | * change it. | ||
1438 | */ | 1396 | */ |
1439 | error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0); | 1397 | error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &dip, &ibp, |
1398 | 0, 0); | ||
1440 | if (error) { | 1399 | if (error) { |
1441 | xfs_warn(mp, "%s: xfs_itobp() returned error %d.", | 1400 | xfs_warn(mp, "%s: xfs_imap_to_bp returned error %d.", |
1442 | __func__, error); | 1401 | __func__, error); |
1443 | return error; | 1402 | return error; |
1444 | } | 1403 | } |
@@ -1493,13 +1452,15 @@ xfs_iunlink_remove( | |||
1493 | ASSERT(next_agino != NULLAGINO); | 1452 | ASSERT(next_agino != NULLAGINO); |
1494 | ASSERT(next_agino != 0); | 1453 | ASSERT(next_agino != 0); |
1495 | } | 1454 | } |
1455 | |||
1496 | /* | 1456 | /* |
1497 | * Now last_ibp points to the buffer previous to us on | 1457 | * Now last_ibp points to the buffer previous to us on the |
1498 | * the unlinked list. Pull us from the list. | 1458 | * unlinked list. Pull us from the list. |
1499 | */ | 1459 | */ |
1500 | error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0); | 1460 | error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &dip, &ibp, |
1461 | 0, 0); | ||
1501 | if (error) { | 1462 | if (error) { |
1502 | xfs_warn(mp, "%s: xfs_itobp(2) returned error %d.", | 1463 | xfs_warn(mp, "%s: xfs_imap_to_bp(2) returned error %d.", |
1503 | __func__, error); | 1464 | __func__, error); |
1504 | return error; | 1465 | return error; |
1505 | } | 1466 | } |
@@ -1749,7 +1710,8 @@ xfs_ifree( | |||
1749 | 1710 | ||
1750 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); | 1711 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
1751 | 1712 | ||
1752 | error = xfs_itobp(ip->i_mount, tp, ip, &dip, &ibp, 0); | 1713 | error = xfs_imap_to_bp(ip->i_mount, tp, &ip->i_imap, &dip, &ibp, |
1714 | 0, 0); | ||
1753 | if (error) | 1715 | if (error) |
1754 | return error; | 1716 | return error; |
1755 | 1717 | ||
@@ -2428,7 +2390,7 @@ xfs_iflush( | |||
2428 | /* | 2390 | /* |
2429 | * For stale inodes we cannot rely on the backing buffer remaining | 2391 | * For stale inodes we cannot rely on the backing buffer remaining |
2430 | * stale in cache for the remaining life of the stale inode and so | 2392 | * stale in cache for the remaining life of the stale inode and so |
2431 | * xfs_itobp() below may give us a buffer that no longer contains | 2393 | * xfs_imap_to_bp() below may give us a buffer that no longer contains |
2432 | * inodes below. We have to check this after ensuring the inode is | 2394 | * inodes below. We have to check this after ensuring the inode is |
2433 | * unpinned so that it is safe to reclaim the stale inode after the | 2395 | * unpinned so that it is safe to reclaim the stale inode after the |
2434 | * flush call. | 2396 | * flush call. |
@@ -2454,7 +2416,8 @@ xfs_iflush( | |||
2454 | /* | 2416 | /* |
2455 | * Get the buffer containing the on-disk inode. | 2417 | * Get the buffer containing the on-disk inode. |
2456 | */ | 2418 | */ |
2457 | error = xfs_itobp(mp, NULL, ip, &dip, &bp, XBF_TRYLOCK); | 2419 | error = xfs_imap_to_bp(mp, NULL, &ip->i_imap, &dip, &bp, XBF_TRYLOCK, |
2420 | 0); | ||
2458 | if (error || !bp) { | 2421 | if (error || !bp) { |
2459 | xfs_ifunlock(ip); | 2422 | xfs_ifunlock(ip); |
2460 | return error; | 2423 | return error; |