From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: david@fromorbit.com, darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org, xfs@oss.sgi.com
Subject: [PATCH 64/71] xfs_repair: fix inode reflink flags
Date: Thu, 25 Aug 2016 16:53:29 -0700 [thread overview]
Message-ID: <147216920968.4420.261618033432866879.stgit@birch.djwong.org> (raw)
In-Reply-To: <147216879156.4420.2446767701729565218.stgit@birch.djwong.org>
While we're computing reference counts, record which inodes actually
share blocks with other files and fix the flags as necessary.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
repair/phase4.c | 20 ++++++++
repair/rmap.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
repair/rmap.h | 1
3 files changed, 154 insertions(+)
diff --git a/repair/phase4.c b/repair/phase4.c
index 86992c9..2c2d611 100644
--- a/repair/phase4.c
+++ b/repair/phase4.c
@@ -208,6 +208,21 @@ _("%s while computing reference count records.\n"),
}
static void
+process_inode_reflink_flags(
+ struct work_queue *wq,
+ xfs_agnumber_t agno,
+ void *arg)
+{
+ int error;
+
+ error = fix_inode_reflink_flags(wq->mp, agno);
+ if (error)
+ do_error(
+_("%s while fixing inode reflink flags.\n"),
+ strerror(-error));
+}
+
+static void
process_rmap_data(
struct xfs_mount *mp)
{
@@ -229,6 +244,11 @@ process_rmap_data(
for (i = 0; i < mp->m_sb.sb_agcount; i++)
queue_work(&wq, compute_ag_refcounts, i, NULL);
destroy_work_queue(&wq);
+
+ create_work_queue(&wq, mp, libxfs_nproc());
+ for (i = 0; i < mp->m_sb.sb_agcount; i++)
+ queue_work(&wq, process_inode_reflink_flags, i, NULL);
+ destroy_work_queue(&wq);
}
void
diff --git a/repair/rmap.c b/repair/rmap.c
index 4507420..5206206 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -665,6 +665,39 @@ rmap_dump(
*/
/*
+ * Mark all inodes in the reverse-mapping observation stack as requiring the
+ * reflink inode flag, if the stack depth is greater than 1.
+ */
+static void
+mark_inode_rl(
+ struct xfs_mount *mp,
+ struct xfs_bag *rmaps)
+{
+ xfs_agnumber_t iagno;
+ struct xfs_rmap_irec *rmap;
+ struct ino_tree_node *irec;
+ int off;
+ size_t idx;
+ xfs_agino_t ino;
+
+ if (bag_count(rmaps) < 2)
+ return;
+
+ /* Reflink flag accounting */
+ foreach_bag_ptr(rmaps, idx, rmap) {
+ ASSERT(!XFS_RMAP_NON_INODE_OWNER(rmap->rm_owner));
+ iagno = XFS_INO_TO_AGNO(mp, rmap->rm_owner);
+ ino = XFS_INO_TO_AGINO(mp, rmap->rm_owner);
+ pthread_mutex_lock(&ag_locks[iagno].lock);
+ irec = find_inode_rec(mp, iagno, ino);
+ off = get_inode_offset(mp, rmap->rm_owner, irec);
+ /* lock here because we might go outside this ag */
+ set_inode_is_rl(irec, off);
+ pthread_mutex_unlock(&ag_locks[iagno].lock);
+ }
+}
+
+/*
* Emit a refcount object for refcntbt reconstruction during phase 5.
*/
#define REFCOUNT_CLAMP(nr) ((nr) > MAXREFCOUNT ? MAXREFCOUNT : (nr))
@@ -745,6 +778,7 @@ compute_refcounts(
if (error)
goto err;
}
+ mark_inode_rl(mp, stack_top);
/* Set nbno to the bno of the next refcount change */
if (n < slab_count(rmaps))
@@ -781,6 +815,7 @@ compute_refcounts(
if (error)
goto err;
}
+ mark_inode_rl(mp, stack_top);
/* Emit refcount if necessary */
ASSERT(nbno > cbno);
@@ -1102,6 +1137,104 @@ record_inode_reflink_flag(
}
/*
+ * Fix an inode's reflink flag.
+ */
+static int
+fix_inode_reflink_flag(
+ struct xfs_mount *mp,
+ xfs_agnumber_t agno,
+ xfs_agino_t agino,
+ bool set)
+{
+ struct xfs_dinode *dino;
+ struct xfs_buf *buf;
+
+ if (set)
+ do_warn(
+_("setting reflink flag on inode %"PRIu64"\n"),
+ XFS_AGINO_TO_INO(mp, agno, agino));
+ else if (!no_modify) /* && !set */
+ do_warn(
+_("clearing reflink flag on inode %"PRIu64"\n"),
+ XFS_AGINO_TO_INO(mp, agno, agino));
+ if (no_modify)
+ return 0;
+
+ buf = get_agino_buf(mp, agno, agino, &dino);
+ if (!buf)
+ return 1;
+ ASSERT(XFS_AGINO_TO_INO(mp, agno, agino) == be64_to_cpu(dino->di_ino));
+ if (set)
+ dino->di_flags2 |= cpu_to_be64(XFS_DIFLAG2_REFLINK);
+ else
+ dino->di_flags2 &= cpu_to_be64(~XFS_DIFLAG2_REFLINK);
+ libxfs_dinode_calc_crc(mp, dino);
+ libxfs_writebuf(buf, 0);
+
+ return 0;
+}
+
+/*
+ * Fix discrepancies between the state of the inode reflink flag and our
+ * observations as to whether or not the inode really needs it.
+ */
+int
+fix_inode_reflink_flags(
+ struct xfs_mount *mp,
+ xfs_agnumber_t agno)
+{
+ struct ino_tree_node *irec;
+ int bit;
+ __uint64_t was;
+ __uint64_t is;
+ __uint64_t diff;
+ __uint64_t mask;
+ int error = 0;
+ xfs_agino_t agino;
+
+ /*
+ * Update the reflink flag for any inode where there's a discrepancy
+ * between the inode flag and whether or not we found any reflinked
+ * extents.
+ */
+ for (irec = findfirst_inode_rec(agno);
+ irec != NULL;
+ irec = next_ino_rec(irec)) {
+ ASSERT((irec->ino_was_rl & irec->ir_free) == 0);
+ ASSERT((irec->ino_is_rl & irec->ir_free) == 0);
+ was = irec->ino_was_rl;
+ is = irec->ino_is_rl;
+ if (was == is)
+ continue;
+ diff = was ^ is;
+ dbg_printf("mismatch ino=%llu was=0x%lx is=0x%lx dif=0x%lx\n",
+ (unsigned long long)XFS_AGINO_TO_INO(mp, agno,
+ irec->ino_startnum),
+ was, is, diff);
+
+ for (bit = 0, mask = 1; bit < 64; bit++, mask <<= 1) {
+ agino = bit + irec->ino_startnum;
+ if (!(diff & mask))
+ continue;
+ else if (was & mask)
+ error = fix_inode_reflink_flag(mp, agno, agino,
+ false);
+ else if (is & mask)
+ error = fix_inode_reflink_flag(mp, agno, agino,
+ true);
+ else
+ ASSERT(0);
+ if (error)
+ do_error(
+_("Unable to fix reflink flag on inode %"PRIu64".\n"),
+ XFS_AGINO_TO_INO(mp, agno, agino));
+ }
+ }
+
+ return error;
+}
+
+/*
* Regenerate the AGFL so that we don't run out of it while rebuilding the
* rmap btree. If skip_rmapbt is true, don't update the rmapbt (most probably
* because we're updating the rmapbt).
diff --git a/repair/rmap.h b/repair/rmap.h
index ab6f434..266448f 100644
--- a/repair/rmap.h
+++ b/repair/rmap.h
@@ -52,6 +52,7 @@ extern void rmap_high_key_from_rec(struct xfs_rmap_irec *rec,
extern int compute_refcounts(struct xfs_mount *, xfs_agnumber_t);
extern void record_inode_reflink_flag(struct xfs_mount *, struct xfs_dinode *,
xfs_agnumber_t, xfs_agino_t, xfs_ino_t);
+extern int fix_inode_reflink_flags(struct xfs_mount *, xfs_agnumber_t);
extern void fix_freelist(struct xfs_mount *, xfs_agnumber_t, bool);
extern void rmap_store_agflcount(struct xfs_mount *, xfs_agnumber_t, int);
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2016-08-25 23:53 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-25 23:46 [PATCH v8 00/71] xfsprogs: add reflink and dedupe support Darrick J. Wong
2016-08-25 23:46 ` [PATCH 01/71] xfs: remove xfs_btree_bigkey Darrick J. Wong
2016-08-25 23:46 ` [PATCH 02/71] xfs: create a standard btree size calculator code Darrick J. Wong
2016-08-25 23:46 ` [PATCH 03/71] xfs: count the blocks in a btree Darrick J. Wong
2016-08-25 23:46 ` [PATCH 04/71] xfs: defer should allow ->finish_item to request a new transaction Darrick J. Wong
2016-08-25 23:47 ` [PATCH 05/71] xfs: set up per-AG free space reservations Darrick J. Wong
2016-08-25 23:47 ` [PATCH 06/71] xfs: introduce refcount btree definitions Darrick J. Wong
2016-08-25 23:47 ` [PATCH 07/71] xfs: add refcount btree stats infrastructure Darrick J. Wong
2016-08-25 23:47 ` [PATCH 08/71] xfs: refcount btree add more reserved blocks Darrick J. Wong
2016-08-25 23:47 ` [PATCH 09/71] xfs: define the on-disk refcount btree format Darrick J. Wong
2016-08-25 23:47 ` [PATCH 10/71] xfs: account for the refcount btree in the alloc/free log reservation Darrick J. Wong
2016-08-25 23:47 ` [PATCH 11/71] xfs: add refcount btree operations Darrick J. Wong
2016-08-25 23:47 ` [PATCH 12/71] xfs: create refcount update intent log items Darrick J. Wong
2016-08-25 23:47 ` [PATCH 13/71] xfs: log refcount intent items Darrick J. Wong
2016-08-25 23:48 ` [PATCH 14/71] xfs: adjust refcount of an extent of blocks in refcount btree Darrick J. Wong
2016-08-25 23:48 ` [PATCH 15/71] xfs: connect refcount adjust functions to upper layers Darrick J. Wong
2016-08-25 23:48 ` [PATCH 16/71] xfs: adjust refcount when unmapping file blocks Darrick J. Wong
2016-08-25 23:48 ` [PATCH 17/71] xfs: refcount btree requires more reserved space Darrick J. Wong
2016-08-25 23:48 ` [PATCH 18/71] xfs: introduce reflink utility functions Darrick J. Wong
2016-08-25 23:48 ` [PATCH 19/71] xfs: create bmbt update intent log items Darrick J. Wong
2016-08-25 23:48 ` [PATCH 20/71] xfs: log bmap intent items Darrick J. Wong
2016-08-25 23:48 ` [PATCH 21/71] xfs: map an inode's offset to an exact physical block Darrick J. Wong
2016-08-25 23:48 ` [PATCH 22/71] xfs: pass bmapi flags through to bmap_del_extent Darrick J. Wong
2016-08-25 23:48 ` [PATCH 23/71] xfs: implement deferred bmbt map/unmap operations Darrick J. Wong
2016-08-25 23:49 ` [PATCH 24/71] xfs: return work remaining at the end of a bunmapi operation Darrick J. Wong
2016-08-25 23:49 ` [PATCH 25/71] xfs: add reflink feature flag to geometry Darrick J. Wong
2016-08-25 23:49 ` [PATCH 26/71] xfs: don't allow reflinked dir/dev/fifo/socket/pipe files Darrick J. Wong
2016-08-25 23:49 ` [PATCH 27/71] xfs: introduce the CoW fork Darrick J. Wong
2016-08-25 23:49 ` [PATCH 28/71] xfs: support bmapping delalloc extents in " Darrick J. Wong
2016-08-25 23:49 ` [PATCH 29/71] xfs: support allocating delayed extents in " Darrick J. Wong
2016-08-25 23:49 ` [PATCH 30/71] xfs: support removing extents from " Darrick J. Wong
2016-08-25 23:49 ` [PATCH 31/71] xfs: store in-progress CoW allocations in the refcount btree Darrick J. Wong
2016-08-25 23:49 ` [PATCH 32/71] xfs: teach get_bmapx and fiemap about shared extents and the CoW fork Darrick J. Wong
2016-08-25 23:50 ` [PATCH 33/71] xfs: support FS_XFLAG_REFLINK on reflink filesystems Darrick J. Wong
2016-08-25 23:50 ` [PATCH 34/71] xfs: create a separate cow extent size hint for the allocator Darrick J. Wong
2016-08-25 23:50 ` [PATCH 35/71] xfs: preallocate blocks for worst-case btree expansion Darrick J. Wong
2016-08-25 23:50 ` [PATCH 36/71] xfs: try other AGs to allocate a BMBT block Darrick J. Wong
2016-08-25 23:50 ` [PATCH 37/71] xfs: increase log reservations for reflink Darrick J. Wong
2016-08-25 23:50 ` [PATCH 38/71] xfs: add shared rmap map/unmap/convert log item types Darrick J. Wong
2016-08-25 23:50 ` [PATCH 39/71] xfs: use interval query for rmap map and unmap operations on shared files Darrick J. Wong
2016-08-25 23:50 ` [PATCH 40/71] xfs: convert unwritten status of shared-extent reverse mappings " Darrick J. Wong
2016-08-25 23:50 ` [PATCH 41/71] xfs: don't allow realtime and reflinked files to mix Darrick J. Wong
2016-08-25 23:51 ` [PATCH 42/71] xfs: don't mix reflink and DAX mode for now Darrick J. Wong
2016-08-25 23:51 ` [PATCH 43/71] xfs: recognize the reflink feature bit Darrick J. Wong
2016-08-25 23:51 ` [PATCH 44/71] xfs_db: dump refcount btree data Darrick J. Wong
2016-08-25 23:51 ` [PATCH 45/71] xfs_db: add support for checking the refcount btree Darrick J. Wong
2016-08-25 23:51 ` [PATCH 46/71] xfs_db: metadump should copy the refcount btree too Darrick J. Wong
2016-08-25 23:51 ` [PATCH 47/71] xfs_db: deal with the CoW extent size hint Darrick J. Wong
2016-08-25 23:51 ` [PATCH 48/71] xfs_db: print one array element per line Darrick J. Wong
2016-08-25 23:51 ` [PATCH 49/71] xfs_growfs: report the presence of the reflink feature Darrick J. Wong
2016-08-25 23:51 ` [PATCH 50/71] xfs_io: bmap should support querying CoW fork, shared blocks Darrick J. Wong
2016-08-25 23:52 ` [PATCH 51/71] libxfs: add configure option to override system header fsxattr Darrick J. Wong
2016-08-25 23:52 ` [PATCH 52/71] xfs_io: get and set the CoW extent size hint Darrick J. Wong
2016-08-25 23:52 ` [PATCH 53/71] xfs_io: add refcount+bmap error injection types Darrick J. Wong
2016-08-25 23:52 ` [PATCH 54/71] xfs_logprint: support cowextsize reporting in log contents Darrick J. Wong
2016-08-25 23:52 ` [PATCH 55/71] xfs_logprint: support refcount redo items Darrick J. Wong
2016-08-25 23:52 ` [PATCH 56/71] xfs_logprint: support bmap " Darrick J. Wong
2016-08-25 23:52 ` [PATCH 57/71] man: document the reflink inode flag in fsxattr Darrick J. Wong
2016-08-25 23:52 ` [PATCH 58/71] man: document the inode cowextsize flags & fields Darrick J. Wong
2016-08-25 23:52 ` [PATCH 59/71] xfs_repair: fix get_agino_buf to avoid corrupting inodes Darrick J. Wong
2016-08-25 23:53 ` [PATCH 60/71] xfs_repair: check the existing refcount btree Darrick J. Wong
2016-08-25 23:53 ` [PATCH 61/71] xfs_repair: handle multiple owners of data blocks Darrick J. Wong
2016-08-25 23:53 ` [PATCH 62/71] xfs_repair: process reverse-mapping data into refcount data Darrick J. Wong
2016-08-25 23:53 ` [PATCH 63/71] xfs_repair: record reflink inode state Darrick J. Wong
2016-08-25 23:53 ` Darrick J. Wong [this message]
2016-08-25 23:53 ` [PATCH 65/71] xfs_repair: check the refcount btree against our observed reference counts when -n Darrick J. Wong
2016-08-25 23:53 ` [PATCH 66/71] xfs_repair: rebuild the refcount btree Darrick J. Wong
2016-08-25 23:53 ` [PATCH 67/71] xfs_repair: complain about copy-on-write leftovers Darrick J. Wong
2016-08-25 23:53 ` [PATCH 68/71] xfs_repair: check the CoW extent size hint Darrick J. Wong
2016-08-25 23:54 ` [PATCH 69/71] xfs_repair: use range query when while checking rmaps Darrick J. Wong
2016-08-25 23:54 ` [PATCH 70/71] xfs_repair: check for mergeable refcount records Darrick J. Wong
2016-08-25 23:54 ` [PATCH 71/71] mkfs.xfs: format reflink enabled filesystems 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=147216920968.4420.261618033432866879.stgit@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=david@fromorbit.com \
--cc=linux-xfs@vger.kernel.org \
--cc=xfs@oss.sgi.com \
/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).