Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 475ee413 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Ben Myers
Browse files

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarMark Tinguely <tinguely@sgi.com>
Signed-off-by: default avatarBen Myers <bpm@sgi.com>
parent 6b7a03f0
Loading
Loading
Loading
Loading
+47 −84
Original line number Original line Diff line number Diff line
@@ -132,23 +132,28 @@ xfs_inobp_check(
#endif
#endif


/*
/*
 * Find the buffer associated with the given inode map
 * This routine is called to map an inode to the buffer containing the on-disk
 * We do basic validation checks on the buffer once it has been
 * version of the inode.  It returns a pointer to the buffer containing the
 * retrieved from disk.
 * on-disk inode in the bpp parameter, and in the dipp parameter it returns a
 * pointer to the on-disk inode within that buffer.
 *
 * If a non-zero error is returned, then the contents of bpp and dipp are
 * undefined.
 */
 */
STATIC int
int
xfs_imap_to_bp(
xfs_imap_to_bp(
	xfs_mount_t	*mp,
	struct xfs_mount	*mp,
	xfs_trans_t	*tp,
	struct xfs_trans	*tp,
	struct xfs_imap		*imap,
	struct xfs_imap		*imap,
	xfs_buf_t	**bpp,
	struct xfs_dinode	**dipp,
	struct xfs_buf		**bpp,
	uint			buf_flags,
	uint			buf_flags,
	uint			iget_flags)
	uint			iget_flags)
{
{
	struct xfs_buf		*bp;
	int			error;
	int			error;
	int			i;
	int			i;
	int			ni;
	int			ni;
	xfs_buf_t	*bp;


	buf_flags |= XBF_UNMAPPED;
	buf_flags |= XBF_UNMAPPED;
	error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, imap->im_blkno,
	error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, imap->im_blkno,
@@ -189,8 +194,8 @@ xfs_imap_to_bp(
				xfs_trans_brelse(tp, bp);
				xfs_trans_brelse(tp, bp);
				return XFS_ERROR(EINVAL);
				return XFS_ERROR(EINVAL);
			}
			}
			XFS_CORRUPTION_ERROR("xfs_imap_to_bp",
			XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_HIGH,
						XFS_ERRLEVEL_HIGH, mp, dip);
					     mp, dip);
#ifdef DEBUG
#ifdef DEBUG
			xfs_emerg(mp,
			xfs_emerg(mp,
				"bad inode magic/vsn daddr %lld #%d (magic=%x)",
				"bad inode magic/vsn daddr %lld #%d (magic=%x)",
@@ -204,7 +209,9 @@ xfs_imap_to_bp(
	}
	}


	xfs_inobp_check(mp, bp);
	xfs_inobp_check(mp, bp);

	*bpp = bp;
	*bpp = bp;
	*dipp = (struct xfs_dinode *)xfs_buf_offset(bp, imap->im_boffset);
	return 0;
	return 0;
}
}


@@ -240,63 +247,15 @@ xfs_inotobp(
	if (error)
	if (error)
		return error;
		return error;


	error = xfs_imap_to_bp(mp, tp, &imap, &bp, 0, imap_flags);
	error = xfs_imap_to_bp(mp, tp, &imap, dipp, &bp, 0, imap_flags);
	if (error)
	if (error)
		return error;
		return error;


	*dipp = (xfs_dinode_t *)xfs_buf_offset(bp, imap.im_boffset);
	*bpp = bp;
	*bpp = bp;
	*offset = imap.im_boffset;
	*offset = imap.im_boffset;
	return 0;
	return 0;
}
}



/*
 * This routine is called to map an inode to the buffer containing
 * the on-disk version of the inode.  It returns a pointer to the
 * buffer containing the on-disk inode in the bpp parameter, and in
 * the dip parameter it returns a pointer to the on-disk inode within
 * that buffer.
 *
 * If a non-zero error is returned, then the contents of bpp and
 * dipp are undefined.
 *
 * The inode is expected to already been mapped to its buffer and read
 * in once, thus we can use the mapping information stored in the inode
 * rather than calling xfs_imap().  This allows us to avoid the overhead
 * of looking at the inode btree for small block file systems
 * (see xfs_imap()).
 */
int
xfs_itobp(
	xfs_mount_t	*mp,
	xfs_trans_t	*tp,
	xfs_inode_t	*ip,
	xfs_dinode_t	**dipp,
	xfs_buf_t	**bpp,
	uint		buf_flags)
{
	xfs_buf_t	*bp;
	int		error;

	ASSERT(ip->i_imap.im_blkno != 0);

	error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &bp, buf_flags, 0);
	if (error)
		return error;

	if (!bp) {
		ASSERT(buf_flags & XBF_TRYLOCK);
		ASSERT(tp == NULL);
		*bpp = NULL;
		return EAGAIN;
	}

	*dipp = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
	*bpp = bp;
	return 0;
}

/*
/*
 * Move inode type and inode format specific information from the
 * Move inode type and inode format specific information from the
 * on-disk inode to the in-core inode.  For fifos, devs, and sockets
 * on-disk inode to the in-core inode.  For fifos, devs, and sockets
@@ -796,10 +755,9 @@ xfs_iread(
	/*
	/*
	 * Get pointers to the on-disk inode and the buffer containing it.
	 * Get pointers to the on-disk inode and the buffer containing it.
	 */
	 */
	error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &bp, 0, iget_flags);
	error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &dip, &bp, 0, iget_flags);
	if (error)
	if (error)
		return error;
		return error;
	dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);


	/*
	/*
	 * If we got something that isn't an inode it means someone
	 * If we got something that isn't an inode it means someone
@@ -876,7 +834,7 @@ xfs_iread(
	/*
	/*
	 * Use xfs_trans_brelse() to release the buffer containing the
	 * Use xfs_trans_brelse() to release the buffer containing the
	 * on-disk inode, because it was acquired with xfs_trans_read_buf()
	 * on-disk inode, because it was acquired with xfs_trans_read_buf()
	 * in xfs_itobp() above.  If tp is NULL, this is just a normal
	 * in xfs_imap_to_bp() above.  If tp is NULL, this is just a normal
	 * brelse().  If we're within a transaction, then xfs_trans_brelse()
	 * brelse().  If we're within a transaction, then xfs_trans_brelse()
	 * will only release the buffer if it is not dirty within the
	 * will only release the buffer if it is not dirty within the
	 * transaction.  It will be OK to release the buffer in this case,
	 * transaction.  It will be OK to release the buffer in this case,
@@ -1355,7 +1313,8 @@ xfs_iunlink(
		 * Here we put the head pointer into our next pointer,
		 * Here we put the head pointer into our next pointer,
		 * and then we fall through to point the head at us.
		 * and then we fall through to point the head at us.
		 */
		 */
		error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0);
		error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &dip, &ibp,
				       0, 0);
		if (error)
		if (error)
			return error;
			return error;


@@ -1429,16 +1388,16 @@ xfs_iunlink_remove(


	if (be32_to_cpu(agi->agi_unlinked[bucket_index]) == agino) {
	if (be32_to_cpu(agi->agi_unlinked[bucket_index]) == agino) {
		/*
		/*
		 * We're at the head of the list.  Get the inode's
		 * We're at the head of the list.  Get the inode's on-disk
		 * on-disk buffer to see if there is anyone after us
		 * buffer to see if there is anyone after us on the list.
		 * on the list.  Only modify our next pointer if it
		 * Only modify our next pointer if it is not already NULLAGINO.
		 * is not already NULLAGINO.  This saves us the overhead
		 * This saves us the overhead of dealing with the buffer when
		 * of dealing with the buffer when there is no need to
		 * there is no need to change it.
		 * change it.
		 */
		 */
		error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0);
		error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &dip, &ibp,
				       0, 0);
		if (error) {
		if (error) {
			xfs_warn(mp, "%s: xfs_itobp() returned error %d.",
			xfs_warn(mp, "%s: xfs_imap_to_bp returned error %d.",
				__func__, error);
				__func__, error);
			return error;
			return error;
		}
		}
@@ -1493,13 +1452,15 @@ xfs_iunlink_remove(
			ASSERT(next_agino != NULLAGINO);
			ASSERT(next_agino != NULLAGINO);
			ASSERT(next_agino != 0);
			ASSERT(next_agino != 0);
		}
		}

		/*
		/*
		 * Now last_ibp points to the buffer previous to us on
		 * Now last_ibp points to the buffer previous to us on the
		 * the unlinked list.  Pull us from the list.
		 * unlinked list.  Pull us from the list.
		 */
		 */
		error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0);
		error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &dip, &ibp,
				       0, 0);
		if (error) {
		if (error) {
			xfs_warn(mp, "%s: xfs_itobp(2) returned error %d.",
			xfs_warn(mp, "%s: xfs_imap_to_bp(2) returned error %d.",
				__func__, error);
				__func__, error);
			return error;
			return error;
		}
		}
@@ -1749,7 +1710,8 @@ xfs_ifree(


	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);


	error = xfs_itobp(ip->i_mount, tp, ip, &dip, &ibp, 0);
	error = xfs_imap_to_bp(ip->i_mount, tp, &ip->i_imap, &dip, &ibp,
			       0, 0);
	if (error)
	if (error)
		return error;
		return error;


@@ -2428,7 +2390,7 @@ xfs_iflush(
	/*
	/*
	 * For stale inodes we cannot rely on the backing buffer remaining
	 * For stale inodes we cannot rely on the backing buffer remaining
	 * stale in cache for the remaining life of the stale inode and so
	 * stale in cache for the remaining life of the stale inode and so
	 * xfs_itobp() below may give us a buffer that no longer contains
	 * xfs_imap_to_bp() below may give us a buffer that no longer contains
	 * inodes below. We have to check this after ensuring the inode is
	 * inodes below. We have to check this after ensuring the inode is
	 * unpinned so that it is safe to reclaim the stale inode after the
	 * unpinned so that it is safe to reclaim the stale inode after the
	 * flush call.
	 * flush call.
@@ -2454,7 +2416,8 @@ xfs_iflush(
	/*
	/*
	 * Get the buffer containing the on-disk inode.
	 * Get the buffer containing the on-disk inode.
	 */
	 */
	error = xfs_itobp(mp, NULL, ip, &dip, &bp, XBF_TRYLOCK);
	error = xfs_imap_to_bp(mp, NULL, &ip->i_imap, &dip, &bp, XBF_TRYLOCK,
			       0);
	if (error || !bp) {
	if (error || !bp) {
		xfs_ifunlock(ip);
		xfs_ifunlock(ip);
		return error;
		return error;
+3 −3
Original line number Original line Diff line number Diff line
@@ -560,9 +560,9 @@ do { \
int		xfs_inotobp(struct xfs_mount *, struct xfs_trans *,
int		xfs_inotobp(struct xfs_mount *, struct xfs_trans *,
			    xfs_ino_t, struct xfs_dinode **,
			    xfs_ino_t, struct xfs_dinode **,
			    struct xfs_buf **, int *, uint);
			    struct xfs_buf **, int *, uint);
int		xfs_itobp(struct xfs_mount *, struct xfs_trans *,
int		xfs_imap_to_bp(struct xfs_mount *, struct xfs_trans *,
			  struct xfs_inode *, struct xfs_dinode **,
			       struct xfs_imap *, struct xfs_dinode **,
			  struct xfs_buf **, uint);
			       struct xfs_buf **, uint, uint);
int		xfs_iread(struct xfs_mount *, struct xfs_trans *,
int		xfs_iread(struct xfs_mount *, struct xfs_trans *,
			  struct xfs_inode *, uint);
			  struct xfs_inode *, uint);
void		xfs_dinode_to_disk(struct xfs_dinode *,
void		xfs_dinode_to_disk(struct xfs_dinode *,
+1 −1
Original line number Original line Diff line number Diff line
@@ -555,7 +555,7 @@ xfs_bulkstat_single(


	/*
	/*
	 * note that requesting valid inode numbers which are not allocated
	 * note that requesting valid inode numbers which are not allocated
	 * to inodes will most likely cause xfs_itobp to generate warning
	 * to inodes will most likely cause xfs_imap_to_bp to generate warning
	 * messages about bad magic numbers. This is ok. The fact that
	 * messages about bad magic numbers. This is ok. The fact that
	 * the inode isn't actually an inode is handled by the
	 * the inode isn't actually an inode is handled by the
	 * error check below. Done this way to make the usual case faster
	 * error check below. Done this way to make the usual case faster
+1 −1
Original line number Original line Diff line number Diff line
@@ -3106,7 +3106,7 @@ xlog_recover_process_one_iunlink(
	/*
	/*
	 * Get the on disk inode to find the next inode in the bucket.
	 * Get the on disk inode to find the next inode in the bucket.
	 */
	 */
	error = xfs_itobp(mp, NULL, ip, &dip, &ibp, 0);
	error = xfs_imap_to_bp(mp, NULL, &ip->i_imap, &dip, &ibp, 0, 0);
	if (error)
	if (error)
		goto fail_iput;
		goto fail_iput;


+2 −2
Original line number Original line Diff line number Diff line
@@ -712,8 +712,8 @@ xfs_reclaim_inode(
	 * Note that xfs_iflush will never block on the inode buffer lock, as
	 * Note that xfs_iflush will never block on the inode buffer lock, as
	 * xfs_ifree_cluster() can lock the inode buffer before it locks the
	 * xfs_ifree_cluster() can lock the inode buffer before it locks the
	 * ip->i_lock, and we are doing the exact opposite here.  As a result,
	 * ip->i_lock, and we are doing the exact opposite here.  As a result,
	 * doing a blocking xfs_itobp() to get the cluster buffer would result
	 * doing a blocking xfs_imap_to_bp() to get the cluster buffer would
	 * in an ABBA deadlock with xfs_ifree_cluster().
	 * result in an ABBA deadlock with xfs_ifree_cluster().
	 *
	 *
	 * As xfs_ifree_cluser() must gather all inodes that are active in the
	 * As xfs_ifree_cluser() must gather all inodes that are active in the
	 * cache to mark them stale, if we hit this case we don't actually want
	 * cache to mark them stale, if we hit this case we don't actually want