From: Brian Foster <bfoster@redhat.com>
To: xfs@oss.sgi.com
Subject: [PATCH 1/4] repair: access helpers for on-disk inobt record freecount
Date: Mon, 8 Jun 2015 07:29:21 -0400 [thread overview]
Message-ID: <1433762964-11502-2-git-send-email-bfoster@redhat.com> (raw)
In-Reply-To: <1433762964-11502-1-git-send-email-bfoster@redhat.com>
The on-disk inobt record has two formats depending on whether sparse
inode support is enabled or not. If so, the freecount field is a single
byte and does not require byte-conversion. Otherwise, it is a 4-byte
field and does.
Create the inorec_[get|set]_freecount() helpers to abstract this detail
away from the core repair code.
Signed-off-by: Brian Foster <bfoster@redhat.com>
---
repair/incore.h | 28 ++++++++++++++++++++++++++++
repair/phase5.c | 12 +++++++-----
repair/scan.c | 15 +++------------
3 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/repair/incore.h b/repair/incore.h
index 5a63e1e..c92475e 100644
--- a/repair/incore.h
+++ b/repair/incore.h
@@ -591,4 +591,32 @@ typedef struct bm_cursor {
void init_bm_cursor(bmap_cursor_t *cursor, int num_level);
+/*
+ * On-disk inobt record helpers. The sparse inode record format has a single
+ * byte freecount. The older format has a 32-bit freecount and thus byte
+ * conversion is necessary.
+ */
+
+static inline int
+inorec_get_freecount(
+ struct xfs_mount *mp,
+ struct xfs_inobt_rec *rp)
+{
+ if (xfs_sb_version_hassparseinodes(&mp->m_sb))
+ return rp->ir_u.sp.ir_freecount;
+ return be32_to_cpu(rp->ir_u.f.ir_freecount);
+}
+
+static inline void
+inorec_set_freecount(
+ struct xfs_mount *mp,
+ struct xfs_inobt_rec *rp,
+ int freecount)
+{
+ if (xfs_sb_version_hassparseinodes(&mp->m_sb))
+ rp->ir_u.sp.ir_freecount = freecount;
+ else
+ rp->ir_u.f.ir_freecount = cpu_to_be32(freecount);
+}
+
#endif /* XFS_REPAIR_INCORE_H */
diff --git a/repair/phase5.c b/repair/phase5.c
index 0601810..7372734 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -1258,11 +1258,14 @@ build_ino_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
inocnt++;
}
- if (!xfs_sb_version_hassparseinodes(&mp->m_sb)) {
- bt_rec[j].ir_u.f.ir_freecount =
- cpu_to_be32(finocnt);
+ /*
+ * Set the freecount and check whether we need to update
+ * the sparse format fields. Otherwise, skip to the next
+ * record.
+ */
+ inorec_set_freecount(mp, &bt_rec[j], finocnt);
+ if (!xfs_sb_version_hassparseinodes(&mp->m_sb))
goto nextrec;
- }
/*
* Convert the 64-bit in-core sparse inode state to the
@@ -1280,7 +1283,6 @@ build_ino_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
sparse >>= XFS_INODES_PER_HOLEMASK_BIT;
}
- bt_rec[j].ir_u.sp.ir_freecount = finocnt;
bt_rec[j].ir_u.sp.ir_count = inocnt;
bt_rec[j].ir_u.sp.ir_holemask = cpu_to_be16(holemask);
diff --git a/repair/scan.c b/repair/scan.c
index e3895c2..1a6f0c5 100644
--- a/repair/scan.c
+++ b/repair/scan.c
@@ -786,10 +786,7 @@ scan_single_ino_chunk(
off = XFS_AGINO_TO_OFFSET(mp, ino);
agbno = XFS_AGINO_TO_AGBNO(mp, ino);
lino = XFS_AGINO_TO_INO(mp, agno, ino);
- if (xfs_sb_version_hassparseinodes(&mp->m_sb))
- freecount = rp->ir_u.sp.ir_freecount;
- else
- freecount = be32_to_cpu(rp->ir_u.f.ir_freecount);
+ freecount = inorec_get_freecount(mp, rp);
/*
* on multi-block block chunks, all chunks start
@@ -987,10 +984,7 @@ scan_single_finobt_chunk(
off = XFS_AGINO_TO_OFFSET(mp, ino);
agbno = XFS_AGINO_TO_AGBNO(mp, ino);
lino = XFS_AGINO_TO_INO(mp, agno, ino);
- if (xfs_sb_version_hassparseinodes(&mp->m_sb))
- freecount = rp->ir_u.sp.ir_freecount;
- else
- freecount = be32_to_cpu(rp->ir_u.f.ir_freecount);
+ freecount = inorec_get_freecount(mp, rp);
/*
* on multi-block block chunks, all chunks start at the beginning of the
@@ -1331,10 +1325,7 @@ _("inode btree block claimed (state %d), agno %d, bno %d, suspect %d\n"),
* the block. skip processing of bogus records.
*/
for (i = 0; i < numrecs; i++) {
- if (xfs_sb_version_hassparseinodes(&mp->m_sb))
- freecount = rp[i].ir_u.sp.ir_freecount;
- else
- freecount = be32_to_cpu(rp[i].ir_u.f.ir_freecount);
+ freecount = inorec_get_freecount(mp, &rp[i]);
if (magic == XFS_IBT_MAGIC ||
magic == XFS_IBT_CRC_MAGIC) {
--
1.9.3
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2015-06-08 11:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-08 11:29 [PATCH 0/4] xfsprogs/repair: sparse inode chunks cleanups Brian Foster
2015-06-08 11:29 ` Brian Foster [this message]
2015-06-08 11:29 ` [PATCH 2/4] repair: helper for inode chunk alignment and start/end ino number verification Brian Foster
2015-06-08 11:29 ` [PATCH 3/4] repair: helper to import on-disk inobt records to in-core trees Brian Foster
2015-06-08 11:29 ` [PATCH 4/4] repair: helper to transition inode blocks to inode state Brian Foster
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=1433762964-11502-2-git-send-email-bfoster@redhat.com \
--to=bfoster@redhat.com \
--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