From a209505361cf858ec91b0a89992691c5b005ab72 Mon Sep 17 00:00:00 2001 From: Alexander Zarochentsev Date: Tue, 28 Mar 2023 19:00:09 +0300 Subject: [PATCH] LU-16655 scrub: upgrade scrub_file from 2.12 format Scrub_file->sf_oi_count has different offsets in Lustre-2.10, Lustre-2.12, and Lustre-2.15 due to unintended format changes. Lustre-2.15 reads sf_oi_count from offset of sf_success_count and may initialize incorrect number of OI files, and not be able to do FID lookups for existing filesystem objects. Fixes: a114f6b8c5 ("LU-13344 servers: change request timeouts to s32") Fixes: 4c2f028a95 ("LU-9019 osd-ldiskfs: migrate to 64 bit time") Signed-off-by: Alexander Zarochentsev Change-Id: Id7c8bd555229405d604456c48447f01fd121aca9 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50480 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Patrick Farrell Reviewed-by: Andreas Dilger --- lustre/include/lustre_scrub.h | 1 + lustre/obdclass/scrub.c | 13 +++++++++---- lustre/osd-ldiskfs/osd_oi.c | 5 +++-- lustre/osd-zfs/osd_scrub.c | 5 +++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lustre/include/lustre_scrub.h b/lustre/include/lustre_scrub.h index 1911830..16249a3 100644 --- a/lustre/include/lustre_scrub.h +++ b/lustre/include/lustre_scrub.h @@ -44,6 +44,7 @@ #define PFID_STRIPE_COUNT_MASK ((1 << PFID_STRIPE_IDX_BITS) - 1) #define SCRUB_MAGIC_V1 0x4C5FD252 +#define SCRUB_MAGIC_V2 0x4C5FE253 #define SCRUB_CHECKPOINT_INTERVAL 60 #define SCRUB_WINDOW_SIZE 1024 diff --git a/lustre/obdclass/scrub.c b/lustre/obdclass/scrub.c index d3d46b8..89c3f75 100644 --- a/lustre/obdclass/scrub.c +++ b/lustre/obdclass/scrub.c @@ -119,7 +119,7 @@ void scrub_file_init(struct lustre_scrub *scrub, uuid_t uuid) memset(sf, 0, sizeof(*sf)); uuid_copy(&sf->sf_uuid, &uuid); - sf->sf_magic = SCRUB_MAGIC_V1; + sf->sf_magic = SCRUB_MAGIC_V2; sf->sf_status = SS_INIT; } EXPORT_SYMBOL(scrub_file_init); @@ -133,6 +133,7 @@ void scrub_file_reset(struct lustre_scrub *scrub, uuid_t uuid, u64 flags) scrub->os_name, sf->sf_flags, flags); uuid_copy(&sf->sf_uuid, &uuid); + sf->sf_magic = SCRUB_MAGIC_V2; sf->sf_status = SS_INIT; sf->sf_flags |= flags; sf->sf_flags &= ~SF_AUTO; @@ -183,9 +184,13 @@ int scrub_file_load(const struct lu_env *env, struct lustre_scrub *scrub) } scrub_file_to_cpu(sf, &scrub->os_file_disk); - if (sf->sf_magic != SCRUB_MAGIC_V1) { - CDEBUG(D_LFSCK, "%s: invalid scrub magic 0x%x != 0x%x\n", - scrub->os_name, sf->sf_magic, SCRUB_MAGIC_V1); + if (sf->sf_magic == SCRUB_MAGIC_V1) { + CWARN("%s: reset scrub OI count for format change (LU-16655)\n", + scrub->os_name); + sf->sf_oi_count = 0; + } else if (sf->sf_magic != SCRUB_MAGIC_V2) { + CDEBUG(D_LFSCK, "%s: invalid scrub magic %#x, should be %#x\n", + scrub->os_name, sf->sf_magic, SCRUB_MAGIC_V2); return -EFAULT; } diff --git a/lustre/osd-ldiskfs/osd_oi.c b/lustre/osd-ldiskfs/osd_oi.c index 7fb40f3..21468fe 100644 --- a/lustre/osd-ldiskfs/osd_oi.c +++ b/lustre/osd-ldiskfs/osd_oi.c @@ -397,8 +397,9 @@ int osd_oi_init(struct osd_thread_info *info, struct osd_device *osd, int rc; ENTRY; - if (unlikely(sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) { - LCONSOLE_WARN("%s: Invalid OI count in scrub file %d\n", + if (unlikely((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0 || + sf->sf_oi_count > OSD_OI_FID_NR_MAX)) { + LCONSOLE_WARN("%s: invalid OI count %u in scrub file, reset it\n", osd_dev2name(osd), sf->sf_oi_count); sf->sf_oi_count = 0; } diff --git a/lustre/osd-zfs/osd_scrub.c b/lustre/osd-zfs/osd_scrub.c index 979e377..d4dbd61 100644 --- a/lustre/osd-zfs/osd_scrub.c +++ b/lustre/osd-zfs/osd_scrub.c @@ -1380,8 +1380,9 @@ int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev, dirty = true; } - if ((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0) { - LCONSOLE_WARN("%s: invalid oi count %d, set it to %d\n", + if (unlikely((sf->sf_oi_count & (sf->sf_oi_count - 1)) != 0 || + sf->sf_oi_count > OSD_OI_FID_NR_MAX)) { + LCONSOLE_WARN("%s: invalid OI count %u, reset to %u\n", osd_name(dev), sf->sf_oi_count, osd_oi_count); sf->sf_oi_count = osd_oi_count; -- 1.8.3.1