@@ -354,3 +354,50 @@ within_range(
return true;
}
+
+/*
+ * Render an inode number as both the raw inode number and as an AG number
+ * and AG inode pair. This is intended for use with status message reporting.
+ * If @format is not NULL, it should provide any desired leading whitespace.
+ *
+ * For example, "inode 287232352 (13/352) <suffix>: <status message>"
+ */
+int
+xfs_scrub_render_ino_suffix(
+ const struct scrub_ctx *ctx,
+ char *buf,
+ size_t buflen,
+ uint64_t ino,
+ uint32_t gen,
+ const char *format,
+ ...)
+{
+ va_list args;
+ uint32_t agno;
+ uint32_t agino;
+ int ret;
+
+ agno = xfrog_ino_to_agno(&ctx->mnt, ino);
+ agino = xfrog_ino_to_agino(&ctx->mnt, ino);
+ ret = snprintf(buf, buflen, _("inode %"PRIu64" (%"PRIu32"/%"PRIu32")"),
+ ino, agno, agino);
+ if (ret < 0 || ret >= buflen || format == NULL)
+ return ret;
+
+ va_start(args, format);
+ ret += vsnprintf(buf + ret, buflen - ret, format, args);
+ va_end(args);
+ return ret;
+}
+
+/* Render an inode number for message reporting with no suffix. */
+int
+xfs_scrub_render_ino(
+ const struct scrub_ctx *ctx,
+ char *buf,
+ size_t buflen,
+ uint64_t ino,
+ uint32_t gen)
+{
+ return xfs_scrub_render_ino_suffix(ctx, buf, buflen, ino, gen, NULL);
+}
@@ -86,4 +86,10 @@ bool within_range(struct scrub_ctx *ctx, unsigned long long value,
unsigned long long desired, unsigned long long abs_threshold,
unsigned int n, unsigned int d, const char *descr);
+int xfs_scrub_render_ino_suffix(const struct scrub_ctx *ctx, char *buf,
+ size_t buflen, uint64_t ino, uint32_t gen,
+ const char *format, ...);
+int xfs_scrub_render_ino(const struct scrub_ctx *ctx, char *buf,
+ size_t buflen, uint64_t ino, uint32_t gen);
+
#endif /* XFS_SCRUB_COMMON_H_ */
@@ -156,8 +156,8 @@ xfs_iterate_inodes_ag(
ireq->hdr.ino = inogrp->xi_startino;
goto igrp_retry;
}
- snprintf(idescr, DESCR_BUFSZ, "inode %"PRIu64,
- (uint64_t)bs->bs_ino);
+ xfs_scrub_render_ino(ctx, idescr, DESCR_BUFSZ,
+ bs->bs_ino, bs->bs_gen);
str_info(ctx, idescr,
_("Changed too many times during scan; giving up."));
break;
@@ -48,14 +48,10 @@ xfs_scrub_inode_vfs_error(
struct xfs_bulkstat *bstat)
{
char descr[DESCR_BUFSZ];
- xfs_agnumber_t agno;
- xfs_agino_t agino;
int old_errno = errno;
- agno = xfrog_ino_to_agno(&ctx->mnt, bstat->bs_ino);
- agino = xfrog_ino_to_agino(&ctx->mnt, bstat->bs_ino);
- snprintf(descr, DESCR_BUFSZ, _("inode %"PRIu64" (%u/%u)"),
- (uint64_t)bstat->bs_ino, agno, agino);
+ xfs_scrub_render_ino(ctx, descr, DESCR_BUFSZ, bstat->bs_ino,
+ bstat->bs_gen);
errno = old_errno;
str_errno(ctx, descr);
}
@@ -234,15 +234,11 @@ xfs_scrub_connections(
bool *pmoveon = arg;
char descr[DESCR_BUFSZ];
bool moveon = true;
- xfs_agnumber_t agno;
- xfs_agino_t agino;
int fd = -1;
int error;
- agno = xfrog_ino_to_agno(&ctx->mnt, bstat->bs_ino);
- agino = xfrog_ino_to_agino(&ctx->mnt, bstat->bs_ino);
- snprintf(descr, DESCR_BUFSZ, _("inode %"PRIu64" (%u/%u)"),
- (uint64_t)bstat->bs_ino, agno, agino);
+ xfs_scrub_render_ino(ctx, descr, DESCR_BUFSZ, bstat->bs_ino,
+ bstat->bs_gen);
background_sleep();
/* Warn about naming problems in xattrs. */
@@ -180,15 +180,15 @@ xfs_report_verify_inode(
int fd;
int error;
- snprintf(descr, DESCR_BUFSZ, _("inode %"PRIu64" (unlinked)"),
- (uint64_t)bstat->bs_ino);
-
/* Ignore linked files and things we can't open. */
if (bstat->bs_nlink != 0)
return 0;
if (!S_ISREG(bstat->bs_mode) && !S_ISDIR(bstat->bs_mode))
return 0;
+ xfs_scrub_render_ino_suffix(ctx, descr, DESCR_BUFSZ,
+ bstat->bs_ino, bstat->bs_gen, _(" (unlinked)"));
+
/* Try to open the inode. */
fd = xfs_open_handle(handle);
if (fd < 0) {
@@ -92,24 +92,26 @@ static const struct scrub_descr scrubbers[XFS_SCRUB_TYPE_NR] = {
/* Format a scrub description. */
static void
format_scrub_descr(
+ struct scrub_ctx *ctx,
char *buf,
size_t buflen,
- struct xfs_scrub_metadata *meta,
- const struct scrub_descr *sc)
+ struct xfs_scrub_metadata *meta)
{
- switch (sc->type) {
+ const struct scrub_descr *sd = &scrubbers[meta->sm_type];
+
+ switch (sd->type) {
case ST_AGHEADER:
case ST_PERAG:
snprintf(buf, buflen, _("AG %u %s"), meta->sm_agno,
- _(sc->name));
+ _(sd->name));
break;
case ST_INODE:
- snprintf(buf, buflen, _("Inode %"PRIu64" %s"),
- (uint64_t)meta->sm_ino, _(sc->name));
+ xfs_scrub_render_ino_suffix(ctx, buf, buflen,
+ meta->sm_ino, meta->sm_gen, " %s", _(sd->name));
break;
case ST_FS:
case ST_SUMMARY:
- snprintf(buf, buflen, _("%s"), _(sc->name));
+ snprintf(buf, buflen, _("%s"), _(sd->name));
break;
case ST_NONE:
assert(0);
@@ -191,7 +193,7 @@ xfs_check_metadata(
assert(!debug_tweak_on("XFS_SCRUB_NO_KERNEL"));
assert(meta->sm_type < XFS_SCRUB_TYPE_NR);
- format_scrub_descr(buf, DESCR_BUFSZ, meta, &scrubbers[meta->sm_type]);
+ format_scrub_descr(ctx, buf, DESCR_BUFSZ, meta);
dbg_printf("check %s flags %xh\n", buf, meta->sm_flags);
retry:
@@ -749,7 +751,7 @@ xfs_repair_metadata(
return CHECK_RETRY;
memcpy(&oldm, &meta, sizeof(oldm));
- format_scrub_descr(buf, DESCR_BUFSZ, &meta, &scrubbers[meta.sm_type]);
+ format_scrub_descr(ctx, buf, DESCR_BUFSZ, &meta);
if (needs_repair(&meta))
str_info(ctx, buf, _("Attempting repair."));