From: "Darrick J. Wong" <darrick.wong@oracle.com> To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Brian Foster <bfoster@redhat.com>, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH 7/9] xfs: have getfsmap fall back to the freesp btrees when rmap is not present Date: Thu, 30 Mar 2017 08:58:44 -0700 [thread overview] Message-ID: <149088952483.25895.7030659170344887892.stgit@birch.djwong.org> (raw) In-Reply-To: <149088947516.25895.12489128187852930801.stgit@birch.djwong.org> From: Darrick J. Wong <darrick.wong@oracle.com> If the reverse-mapping btree isn't available, fall back to the free space btrees to provide partial reverse mapping information. The online scrub tool can make use of even partial information to speed up the data block scan. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Brian Foster <bfoster@redhat.com> --- v2: various refactorings, fix array pointer passing --- fs/xfs/xfs_fsmap.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index 24b3e53..edd75c6 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -40,6 +40,7 @@ #include "xfs_fsmap.h" #include "xfs_refcount.h" #include "xfs_refcount_btree.h" +#include "xfs_alloc_btree.h" /* Convert an xfs_fsmap to an fsmap. */ void @@ -158,6 +159,9 @@ xfs_fsmap_owner_from_rmap( case XFS_RMAP_OWN_COW: dest->fmr_owner = XFS_FMR_OWN_COW; break; + case XFS_RMAP_OWN_NULL: /* "free" */ + dest->fmr_owner = XFS_FMR_OWN_FREE; + break; default: return -EFSCORRUPTED; } @@ -362,6 +366,30 @@ xfs_getfsmap_datadev_helper( return xfs_getfsmap_helper(cur->bc_tp, info, rec, rec_daddr); } +/* Transform a bnobt irec into a fsmap */ +STATIC int +xfs_getfsmap_datadev_bnobt_helper( + struct xfs_btree_cur *cur, + struct xfs_alloc_rec_incore *rec, + void *priv) +{ + struct xfs_mount *mp = cur->bc_mp; + struct xfs_getfsmap_info *info = priv; + struct xfs_rmap_irec irec; + xfs_daddr_t rec_daddr; + + rec_daddr = XFS_AGB_TO_DADDR(mp, cur->bc_private.a.agno, + rec->ar_startblock); + + irec.rm_startblock = rec->ar_startblock; + irec.rm_blockcount = rec->ar_blockcount; + irec.rm_owner = XFS_RMAP_OWN_NULL; /* "free" */ + irec.rm_offset = 0; + irec.rm_flags = 0; + + return xfs_getfsmap_helper(cur->bc_tp, info, &irec, rec_daddr); +} + /* Set rmap flags based on the getfsmap flags */ static void xfs_getfsmap_set_irec_flags( @@ -572,6 +600,43 @@ xfs_getfsmap_datadev_rmapbt( xfs_getfsmap_datadev_rmapbt_query, NULL); } +/* Actually query the bno btree. */ +STATIC int +xfs_getfsmap_datadev_bnobt_query( + struct xfs_trans *tp, + struct xfs_getfsmap_info *info, + struct xfs_btree_cur **curpp, + void *priv) +{ + struct xfs_alloc_rec_incore *key = priv; + + /* Report any gap at the end of the last AG. */ + if (info->last) + return xfs_getfsmap_datadev_bnobt_helper(*curpp, &key[1], info); + + /* Allocate cursor for this AG and query_range it. */ + *curpp = xfs_allocbt_init_cursor(tp->t_mountp, tp, info->agf_bp, + info->agno, XFS_BTNUM_BNO); + key->ar_startblock = info->low.rm_startblock; + key[1].ar_startblock = info->high.rm_startblock; + return xfs_alloc_query_range(*curpp, key, &key[1], + xfs_getfsmap_datadev_bnobt_helper, info); +} + +/* Execute a getfsmap query against the regular data device's bnobt. */ +STATIC int +xfs_getfsmap_datadev_bnobt( + struct xfs_trans *tp, + struct xfs_fsmap *keys, + struct xfs_getfsmap_info *info) +{ + struct xfs_alloc_rec_incore akeys[2]; + + info->missing_owner = XFS_FMR_OWN_UNKNOWN; + return __xfs_getfsmap_datadev(tp, keys, info, + xfs_getfsmap_datadev_bnobt_query, &akeys[0]); +} + /* Do we recognize the device? */ STATIC bool xfs_getfsmap_is_valid_device( @@ -652,8 +717,6 @@ xfs_getfsmap( int i; int error = 0; - if (!xfs_sb_version_hasrmapbt(&mp->m_sb)) - return -EOPNOTSUPP; if (head->fmh_iflags & ~FMH_IF_VALID) return -EINVAL; if (!xfs_getfsmap_is_valid_device(mp, &head->fmh_keys[0]) || @@ -665,7 +728,10 @@ xfs_getfsmap( /* Set up our device handlers. */ memset(handlers, 0, sizeof(handlers)); handlers[0].dev = new_encode_dev(mp->m_ddev_targp->bt_dev); - handlers[0].fn = xfs_getfsmap_datadev_rmapbt; + if (xfs_sb_version_hasrmapbt(&mp->m_sb)) + handlers[0].fn = xfs_getfsmap_datadev_rmapbt; + else + handlers[0].fn = xfs_getfsmap_datadev_bnobt; if (mp->m_logdev_targp != mp->m_ddev_targp) { handlers[1].dev = new_encode_dev(mp->m_logdev_targp->bt_dev); handlers[1].fn = xfs_getfsmap_logdev;
WARNING: multiple messages have this Message-ID (diff)
From: "Darrick J. Wong" <darrick.wong-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> To: darrick.wong-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org Cc: linux-xfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Brian Foster <bfoster-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>, linux-ext4-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Subject: [PATCH 7/9] xfs: have getfsmap fall back to the freesp btrees when rmap is not present Date: Thu, 30 Mar 2017 08:58:44 -0700 [thread overview] Message-ID: <149088952483.25895.7030659170344887892.stgit@birch.djwong.org> (raw) In-Reply-To: <149088947516.25895.12489128187852930801.stgit-PTl6brltDGh4DFYR7WNSRA@public.gmane.org> From: Darrick J. Wong <darrick.wong-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> If the reverse-mapping btree isn't available, fall back to the free space btrees to provide partial reverse mapping information. The online scrub tool can make use of even partial information to speed up the data block scan. Signed-off-by: Darrick J. Wong <darrick.wong-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> Reviewed-by: Brian Foster <bfoster-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> --- v2: various refactorings, fix array pointer passing --- fs/xfs/xfs_fsmap.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index 24b3e53..edd75c6 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -40,6 +40,7 @@ #include "xfs_fsmap.h" #include "xfs_refcount.h" #include "xfs_refcount_btree.h" +#include "xfs_alloc_btree.h" /* Convert an xfs_fsmap to an fsmap. */ void @@ -158,6 +159,9 @@ xfs_fsmap_owner_from_rmap( case XFS_RMAP_OWN_COW: dest->fmr_owner = XFS_FMR_OWN_COW; break; + case XFS_RMAP_OWN_NULL: /* "free" */ + dest->fmr_owner = XFS_FMR_OWN_FREE; + break; default: return -EFSCORRUPTED; } @@ -362,6 +366,30 @@ xfs_getfsmap_datadev_helper( return xfs_getfsmap_helper(cur->bc_tp, info, rec, rec_daddr); } +/* Transform a bnobt irec into a fsmap */ +STATIC int +xfs_getfsmap_datadev_bnobt_helper( + struct xfs_btree_cur *cur, + struct xfs_alloc_rec_incore *rec, + void *priv) +{ + struct xfs_mount *mp = cur->bc_mp; + struct xfs_getfsmap_info *info = priv; + struct xfs_rmap_irec irec; + xfs_daddr_t rec_daddr; + + rec_daddr = XFS_AGB_TO_DADDR(mp, cur->bc_private.a.agno, + rec->ar_startblock); + + irec.rm_startblock = rec->ar_startblock; + irec.rm_blockcount = rec->ar_blockcount; + irec.rm_owner = XFS_RMAP_OWN_NULL; /* "free" */ + irec.rm_offset = 0; + irec.rm_flags = 0; + + return xfs_getfsmap_helper(cur->bc_tp, info, &irec, rec_daddr); +} + /* Set rmap flags based on the getfsmap flags */ static void xfs_getfsmap_set_irec_flags( @@ -572,6 +600,43 @@ xfs_getfsmap_datadev_rmapbt( xfs_getfsmap_datadev_rmapbt_query, NULL); } +/* Actually query the bno btree. */ +STATIC int +xfs_getfsmap_datadev_bnobt_query( + struct xfs_trans *tp, + struct xfs_getfsmap_info *info, + struct xfs_btree_cur **curpp, + void *priv) +{ + struct xfs_alloc_rec_incore *key = priv; + + /* Report any gap at the end of the last AG. */ + if (info->last) + return xfs_getfsmap_datadev_bnobt_helper(*curpp, &key[1], info); + + /* Allocate cursor for this AG and query_range it. */ + *curpp = xfs_allocbt_init_cursor(tp->t_mountp, tp, info->agf_bp, + info->agno, XFS_BTNUM_BNO); + key->ar_startblock = info->low.rm_startblock; + key[1].ar_startblock = info->high.rm_startblock; + return xfs_alloc_query_range(*curpp, key, &key[1], + xfs_getfsmap_datadev_bnobt_helper, info); +} + +/* Execute a getfsmap query against the regular data device's bnobt. */ +STATIC int +xfs_getfsmap_datadev_bnobt( + struct xfs_trans *tp, + struct xfs_fsmap *keys, + struct xfs_getfsmap_info *info) +{ + struct xfs_alloc_rec_incore akeys[2]; + + info->missing_owner = XFS_FMR_OWN_UNKNOWN; + return __xfs_getfsmap_datadev(tp, keys, info, + xfs_getfsmap_datadev_bnobt_query, &akeys[0]); +} + /* Do we recognize the device? */ STATIC bool xfs_getfsmap_is_valid_device( @@ -652,8 +717,6 @@ xfs_getfsmap( int i; int error = 0; - if (!xfs_sb_version_hasrmapbt(&mp->m_sb)) - return -EOPNOTSUPP; if (head->fmh_iflags & ~FMH_IF_VALID) return -EINVAL; if (!xfs_getfsmap_is_valid_device(mp, &head->fmh_keys[0]) || @@ -665,7 +728,10 @@ xfs_getfsmap( /* Set up our device handlers. */ memset(handlers, 0, sizeof(handlers)); handlers[0].dev = new_encode_dev(mp->m_ddev_targp->bt_dev); - handlers[0].fn = xfs_getfsmap_datadev_rmapbt; + if (xfs_sb_version_hasrmapbt(&mp->m_sb)) + handlers[0].fn = xfs_getfsmap_datadev_rmapbt; + else + handlers[0].fn = xfs_getfsmap_datadev_bnobt; if (mp->m_logdev_targp != mp->m_ddev_targp) { handlers[1].dev = new_encode_dev(mp->m_logdev_targp->bt_dev); handlers[1].fn = xfs_getfsmap_logdev;
next prev parent reply other threads:[~2017-03-30 15:58 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-03-30 15:57 [PATCH v8 0/9] vfs/xfs/ext4: GETFSMAP support Darrick J. Wong 2017-03-30 15:58 ` [PATCH 1/9] vfs: add common GETFSMAP ioctl definitions Darrick J. Wong 2017-03-30 15:58 ` [PATCH 2/9] xfs: plumb in needed functions for range querying of the freespace btrees Darrick J. Wong 2017-03-30 15:58 ` [PATCH 3/9] xfs: provide a query_range function for " Darrick J. Wong 2017-03-30 15:58 ` [PATCH 4/9] xfs: create a function to query all records in a btree Darrick J. Wong 2017-03-30 15:58 ` [PATCH 5/9] xfs: add a couple of queries to iterate free extents in the rtbitmap Darrick J. Wong 2017-03-30 15:58 ` Darrick J. Wong 2017-03-30 15:58 ` [PATCH 6/9] xfs: implement the GETFSMAP ioctl Darrick J. Wong 2017-03-30 15:58 ` Darrick J. Wong [this message] 2017-03-30 15:58 ` [PATCH 7/9] xfs: have getfsmap fall back to the freesp btrees when rmap is not present Darrick J. Wong 2017-03-30 15:58 ` [PATCH 8/9] xfs: report realtime space information via the rtbitmap Darrick J. Wong 2017-03-30 15:58 ` [PATCH 9/9] ext4: support GETFSMAP ioctls Darrick J. Wong 2017-03-30 16:00 ` [PATCH 10/9] ioctl_getfsmap.2: document the GETFSMAP ioctl Darrick J. Wong -- strict thread matches above, loose matches on Subject: below -- 2017-02-28 18:45 [RFC PATCH v7 0/9] vfs/xfs/ext4: GETFSMAP support Darrick J. Wong 2017-02-28 18:46 ` [PATCH 7/9] xfs: have getfsmap fall back to the freesp btrees when rmap is not present Darrick J. Wong 2017-03-01 17:59 ` Brian Foster 2017-03-01 18:46 ` 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=149088952483.25895.7030659170344887892.stgit@birch.djwong.org \ --to=darrick.wong@oracle.com \ --cc=bfoster@redhat.com \ --cc=linux-api@vger.kernel.org \ --cc=linux-ext4@vger.kernel.org \ --cc=linux-fsdevel@vger.kernel.org \ --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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.