From: Christoph Hellwig <hch@lst.de>
To: linux-xfs@vger.kernel.org
Cc: Allison Collins <allison.henderson@oracle.com>
Subject: [PATCH 1/9] xfs: simplify mappedbno case from xfs_da_get_buf and xfs_da_read_buf
Date: Sat, 16 Nov 2019 19:22:06 +0100 [thread overview]
Message-ID: <20191116182214.23711-2-hch@lst.de> (raw)
In-Reply-To: <20191116182214.23711-1-hch@lst.de>
Shortcut the creation of xfs_bmbt_irec and xfs_buf_map for the case
where the callers passed an already mapped xfs_daddr_t. This is in
preparation for splitting these cases out entirely later. Also reject
the mappedbno case for xfs_da_reada_buf as no callers currently uses
it and it will be removed soon.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/xfs/libxfs/xfs_da_btree.c | 103 +++++++++++++++++------------------
1 file changed, 51 insertions(+), 52 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
index 46b1c3fb305c..681fba5731c2 100644
--- a/fs/xfs/libxfs/xfs_da_btree.c
+++ b/fs/xfs/libxfs/xfs_da_btree.c
@@ -110,6 +110,13 @@ xfs_da_state_free(xfs_da_state_t *state)
kmem_zone_free(xfs_da_state_zone, state);
}
+static inline int xfs_dabuf_nfsb(struct xfs_mount *mp, int whichfork)
+{
+ if (whichfork == XFS_DATA_FORK)
+ return mp->m_dir_geo->fsbcount;
+ return mp->m_attr_geo->fsbcount;
+}
+
void
xfs_da3_node_hdr_from_disk(
struct xfs_mount *mp,
@@ -2570,7 +2577,7 @@ xfs_dabuf_map(
int *nmaps)
{
struct xfs_mount *mp = dp->i_mount;
- int nfsb;
+ int nfsb = xfs_dabuf_nfsb(mp, whichfork);
int error = 0;
struct xfs_bmbt_irec irec;
struct xfs_bmbt_irec *irecs = &irec;
@@ -2579,35 +2586,13 @@ xfs_dabuf_map(
ASSERT(map && *map);
ASSERT(*nmaps == 1);
- if (whichfork == XFS_DATA_FORK)
- nfsb = mp->m_dir_geo->fsbcount;
- else
- nfsb = mp->m_attr_geo->fsbcount;
-
- /*
- * Caller doesn't have a mapping. -2 means don't complain
- * if we land in a hole.
- */
- if (mappedbno == -1 || mappedbno == -2) {
- /*
- * Optimize the one-block case.
- */
- if (nfsb != 1)
- irecs = kmem_zalloc(sizeof(irec) * nfsb,
- KM_NOFS);
-
- nirecs = nfsb;
- error = xfs_bmapi_read(dp, (xfs_fileoff_t)bno, nfsb, irecs,
- &nirecs, xfs_bmapi_aflag(whichfork));
- if (error)
- goto out;
- } else {
- irecs->br_startblock = XFS_DADDR_TO_FSB(mp, mappedbno);
- irecs->br_startoff = (xfs_fileoff_t)bno;
- irecs->br_blockcount = nfsb;
- irecs->br_state = 0;
- nirecs = 1;
- }
+ if (nfsb != 1)
+ irecs = kmem_zalloc(sizeof(irec) * nfsb, KM_NOFS);
+ nirecs = nfsb;
+ error = xfs_bmapi_read(dp, (xfs_fileoff_t)bno, nfsb, irecs,
+ &nirecs, xfs_bmapi_aflag(whichfork));
+ if (error)
+ goto out;
if (!xfs_da_map_covers_blocks(nirecs, irecs, bno, nfsb)) {
/* Caller ok with no mapping. */
@@ -2648,24 +2633,29 @@ xfs_dabuf_map(
*/
int
xfs_da_get_buf(
- struct xfs_trans *trans,
+ struct xfs_trans *tp,
struct xfs_inode *dp,
xfs_dablk_t bno,
xfs_daddr_t mappedbno,
struct xfs_buf **bpp,
int whichfork)
{
+ struct xfs_mount *mp = dp->i_mount;
struct xfs_buf *bp;
- struct xfs_buf_map map;
- struct xfs_buf_map *mapp;
- int nmap;
+ struct xfs_buf_map map, *mapp = ↦
+ int nmap = 1;
int error;
*bpp = NULL;
- mapp = ↦
- nmap = 1;
- error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
- &mapp, &nmap);
+
+ if (mappedbno >= 0) {
+ bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, mappedbno,
+ XFS_FSB_TO_BB(mp,
+ xfs_dabuf_nfsb(mp, whichfork)), 0);
+ goto done;
+ }
+
+ error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
if (error) {
/* mapping a hole is not an error, but we don't continue */
if (error == -1)
@@ -2673,12 +2663,12 @@ xfs_da_get_buf(
goto out_free;
}
- bp = xfs_trans_get_buf_map(trans, dp->i_mount->m_ddev_targp,
- mapp, nmap, 0);
+ bp = xfs_trans_get_buf_map(tp, mp->m_ddev_targp, mapp, nmap, 0);
+done:
error = bp ? bp->b_error : -EIO;
if (error) {
if (bp)
- xfs_trans_brelse(trans, bp);
+ xfs_trans_brelse(tp, bp);
goto out_free;
}
@@ -2696,7 +2686,7 @@ xfs_da_get_buf(
*/
int
xfs_da_read_buf(
- struct xfs_trans *trans,
+ struct xfs_trans *tp,
struct xfs_inode *dp,
xfs_dablk_t bno,
xfs_daddr_t mappedbno,
@@ -2704,17 +2694,23 @@ xfs_da_read_buf(
int whichfork,
const struct xfs_buf_ops *ops)
{
+ struct xfs_mount *mp = dp->i_mount;
struct xfs_buf *bp;
- struct xfs_buf_map map;
- struct xfs_buf_map *mapp;
- int nmap;
+ struct xfs_buf_map map, *mapp = ↦
+ int nmap = 1;
int error;
*bpp = NULL;
- mapp = ↦
- nmap = 1;
- error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
- &mapp, &nmap);
+
+ if (mappedbno >= 0) {
+ error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
+ mappedbno, XFS_FSB_TO_BB(mp,
+ xfs_dabuf_nfsb(mp, whichfork)),
+ 0, &bp, ops);
+ goto done;
+ }
+
+ error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
if (error) {
/* mapping a hole is not an error, but we don't continue */
if (error == -1)
@@ -2722,9 +2718,9 @@ xfs_da_read_buf(
goto out_free;
}
- error = xfs_trans_read_buf_map(dp->i_mount, trans,
- dp->i_mount->m_ddev_targp,
- mapp, nmap, 0, &bp, ops);
+ error = xfs_trans_read_buf_map(mp, tp, mp->m_ddev_targp, mapp, nmap, 0,
+ &bp, ops);
+done:
if (error)
goto out_free;
@@ -2756,6 +2752,9 @@ xfs_da_reada_buf(
int nmap;
int error;
+ if (mappedbno >= 0)
+ return -EINVAL;
+
mapp = ↦
nmap = 1;
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
--
2.20.1
next prev parent reply other threads:[~2019-11-16 18:22 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-16 18:22 RFC: clean up the dabuf mappedbno interface Christoph Hellwig
2019-11-16 18:22 ` Christoph Hellwig [this message]
2019-11-18 21:21 ` [PATCH 1/9] xfs: simplify mappedbno case from xfs_da_get_buf and xfs_da_read_buf Darrick J. Wong
2019-11-16 18:22 ` [PATCH 2/9] xfs: improve the xfs_dabuf_map calling conventions Christoph Hellwig
2019-11-17 18:35 ` Darrick J. Wong
2019-11-18 6:25 ` Christoph Hellwig
2019-11-19 17:12 ` Darrick J. Wong
2019-11-19 17:15 ` Christoph Hellwig
2019-11-16 18:22 ` [PATCH 3/9] xfs: remove the mappedbno argument to xfs_da_reada_buf Christoph Hellwig
2019-11-18 21:22 ` Darrick J. Wong
2019-11-16 18:22 ` [PATCH 4/9] xfs: remove the mappedbno argument to xfs_attr3_leaf_read Christoph Hellwig
2019-11-18 21:22 ` Darrick J. Wong
2019-11-16 18:22 ` [PATCH 5/9] xfs: remove the mappedbno argument to xfs_dir3_leaf_read Christoph Hellwig
2019-11-18 21:23 ` Darrick J. Wong
2019-11-18 21:23 ` Darrick J. Wong
2019-11-16 18:22 ` [PATCH 6/9] xfs: remove the mappedbno argument to xfs_dir3_leafn_read Christoph Hellwig
2019-11-18 21:23 ` Darrick J. Wong
2019-11-16 18:22 ` [PATCH 7/9] xfs: split xfs_da3_node_read Christoph Hellwig
2019-11-18 21:24 ` Darrick J. Wong
2019-11-16 18:22 ` [PATCH 8/9] xfs: remove the mappedbno argument to xfs_da_read_buf Christoph Hellwig
2019-11-18 21:29 ` Darrick J. Wong
2019-11-16 18:22 ` [PATCH 9/9] xfs: remove the mappedbno argument to xfs_da_get_buf Christoph Hellwig
2019-11-18 21:32 ` Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191116182214.23711-2-hch@lst.de \
--to=hch@lst.de \
--cc=allison.henderson@oracle.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).