From ed9ce86ceda2a987b34a5bc9993dcde325e8004f Mon Sep 17 00:00:00 2001 From: Hongchao Zhang Date: Fri, 21 Jul 2023 16:01:26 +0800 Subject: [PATCH] LU-17010 lfsck: don't create trans in dryrun mode In LFSCK, the LFSCK transaction should not be created in dryrun mode, which is related to the following patch, Lustre-change: https://review.whamcloud.com/51849 Lustre-commit: 441902fa3d445791a8c54026c130ab357f7469d7 Fixes: 0c1ae1cb9c19 ("LU-13124 scrub: check for multiple linked file") Change-Id: Id543bc3c0e300c1cc14b670d724ebcacac3bf71b Signed-off-by: Hongchao Zhang Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/51975 Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo --- lustre/lfsck/lfsck_layout.c | 30 +++++++++++++++++ lustre/lfsck/lfsck_lib.c | 9 +++++ lustre/lfsck/lfsck_namespace.c | 72 +++++++++++++++++++++++++--------------- lustre/lfsck/lfsck_striped_dir.c | 14 ++++---- 4 files changed, 93 insertions(+), 32 deletions(-) diff --git a/lustre/lfsck/lfsck_layout.c b/lustre/lfsck/lfsck_layout.c index 86e11c5..0886663 100644 --- a/lustre/lfsck/lfsck_layout.c +++ b/lustre/lfsck/lfsck_layout.c @@ -1555,6 +1555,9 @@ static int lfsck_layout_ins_dangling_rec(const struct lu_env *env, int rc = 0; ENTRY; + if (com->lc_lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 0); + idx = lfsck_sub_trace_file_fid2idx(pfid); obj = com->lc_sub_trace_objs[idx].lsto_obj; dev = lfsck_obj2dev(obj); @@ -1593,6 +1596,7 @@ unlock: mutex_unlock(&com->lc_sub_trace_objs[idx].lsto_mutex); +log: CDEBUG(D_LFSCK, "%s: insert the paris "DFID" => "DFID", comp_id = %u, " "ea_off = %u, ost_idx = %u, into the trace file for further " "dangling check: rc = %d\n", lfsck_lfsck2name(com->lc_lfsck), @@ -1614,6 +1618,9 @@ static int lfsck_layout_del_dangling_rec(const struct lu_env *env, int rc = 0; ENTRY; + if (com->lc_lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 0); + idx = lfsck_sub_trace_file_fid2idx(fid); obj = com->lc_sub_trace_objs[idx].lsto_obj; dev = lfsck_obj2dev(obj); @@ -1646,6 +1653,7 @@ unlock: mutex_unlock(&com->lc_sub_trace_objs[idx].lsto_mutex); +log: CDEBUG(D_LFSCK, "%s: delete the dangling record for "DFID ", comp_id = %u, ea_off = %u from the trace file: rc = %d\n", lfsck_lfsck2name(com->lc_lfsck), PFID(fid), comp_id, ea_off, rc); @@ -2178,6 +2186,9 @@ static int __lfsck_layout_update_pfid(const struct lu_env *env, struct lu_buf buf = { NULL }; int rc; + if (com->lc_lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + RETURN(0); + ff->ff_parent.f_seq = cpu_to_le64(pfid->f_seq); ff->ff_parent.f_oid = cpu_to_le32(pfid->f_oid); /* Currently, the filter_fid::ff_parent::f_ver is not the real parent @@ -2584,6 +2595,9 @@ static int lfsck_layout_slave_conditional_destroy(const struct lu_env *env, int rc = 0; ENTRY; + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + RETURN(0); + obj = lfsck_object_find_by_dev(env, dev, fid); if (IS_ERR(obj)) RETURN(PTR_ERR(obj)); @@ -3457,6 +3471,9 @@ static int __lfsck_layout_repair_dangling(const struct lu_env *env, if (!(lfsck->li_bookmark_ram.lb_param & LPF_CREATE_OSTOBJ)) GOTO(log, rc = 1); + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 1); + rc = lfsck_ibits_lock(env, lfsck, parent, &lh, MDS_INODELOCK_LAYOUT | MDS_INODELOCK_XATTR, LCK_EX); @@ -3706,6 +3723,9 @@ static int lfsck_layout_repair_unmatched_pair(const struct lu_env *env, int rc; ENTRY; + if (com->lc_lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 0); + rc = lfsck_ibits_lock(env, com->lc_lfsck, parent, &lh, MDS_INODELOCK_LAYOUT | MDS_INODELOCK_XATTR, LCK_EX); @@ -3826,6 +3846,9 @@ static int lfsck_layout_repair_multiple_references(const struct lu_env *env, int rc; ENTRY; + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + RETURN(0); + /* We use two separated transactions to repair the inconsistency. * * 1) create the child (OST-object). @@ -4019,6 +4042,9 @@ static int lfsck_layout_repair_owner(const struct lu_env *env, dt_obj_version_t version; ENTRY; + if (com->lc_lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + RETURN(0); + tla->la_uid = pla->la_uid; tla->la_gid = pla->la_gid; tla->la_valid = LA_UID | LA_GID; @@ -7163,6 +7189,9 @@ static void lfsck_layout_destroy_orphan(const struct lu_env *env, int rc; ENTRY; + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 0); + handle = lfsck_trans_create(env, dev, lfsck); if (IS_ERR(handle)) RETURN_EXIT; @@ -7190,6 +7219,7 @@ static void lfsck_layout_destroy_orphan(const struct lu_env *env, stop: dt_trans_stop(env, dev, handle); +log: CDEBUG(D_LFSCK, "destroy orphan OST-object "DFID": rc = %d\n", PFID(lfsck_dto2fid(obj)), rc); diff --git a/lustre/lfsck/lfsck_lib.c b/lustre/lfsck/lfsck_lib.c index 00e0875..43b60af 100644 --- a/lustre/lfsck/lfsck_lib.c +++ b/lustre/lfsck/lfsck_lib.c @@ -617,6 +617,9 @@ static int lfsck_lpf_remove_name_entry(const struct lu_env *env, int rc; ENTRY; + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + RETURN(0); + rc = lfsck_lock(env, lfsck, parent, name, llh, MDS_INODELOCK_UPDATE, LCK_PW); if (rc != 0) @@ -682,6 +685,9 @@ static int lfsck_create_lpf_local(const struct lu_env *env, int rc; ENTRY; + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + RETURN(0); + cname = lfsck_name_get_const(env, name, strlen(name)); rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2, cname, lfsck_dto2fid(parent)); @@ -837,6 +843,9 @@ static int lfsck_create_lpf_remote(const struct lu_env *env, int rc; ENTRY; + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + RETURN(0); + cname = lfsck_name_get_const(env, name, strlen(name)); rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2, cname, lfsck_dto2fid(parent)); diff --git a/lustre/lfsck/lfsck_namespace.c b/lustre/lfsck/lfsck_namespace.c index b622006..d3dedc0 100644 --- a/lustre/lfsck/lfsck_namespace.c +++ b/lustre/lfsck/lfsck_namespace.c @@ -531,6 +531,9 @@ int lfsck_namespace_trace_update(const struct lu_env *env, GOTO(log, rc); } + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 0); + th = lfsck_trans_create(env, dev, lfsck); if (IS_ERR(th)) GOTO(log, rc = PTR_ERR(th)); @@ -695,6 +698,9 @@ static int lfsck_namespace_links_remove(const struct lu_env *env, LASSERT(dt_object_remote(obj) == 0); + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(unlock, rc = 0); + th = lfsck_trans_create(env, dev, lfsck); if (IS_ERR(th)) GOTO(log, rc = PTR_ERR(th)); @@ -711,9 +717,6 @@ static int lfsck_namespace_links_remove(const struct lu_env *env, if (unlikely(lfsck_is_dead_obj(obj))) GOTO(unlock, rc = -ENOENT); - if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) - GOTO(unlock, rc = 0); - rc = dt_xattr_del(env, obj, XATTR_NAME_LINK, th); GOTO(unlock, rc); @@ -975,6 +978,9 @@ again: exist = false; } + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 0); + cname->ln_name = info->lti_key; cname->ln_namelen = namelen; rc = linkea_links_new(&ldata2, &info->lti_linkea_buf2, @@ -1712,6 +1718,9 @@ static int lfsck_namespace_shrink_linkea(const struct lu_env *env, int rc = 0; ENTRY; + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 0); + rc = lfsck_ibits_lock(env, lfsck, obj, &lh, MDS_INODELOCK_UPDATE | MDS_INODELOCK_XATTR, LCK_EX); @@ -2132,6 +2141,9 @@ int lfsck_namespace_rebuild_linkea(const struct lu_env *env, int rc = 0; ENTRY; + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 1); + th = lfsck_trans_create(env, dev, lfsck); if (IS_ERR(th)) GOTO(log, rc = PTR_ERR(th)); @@ -2151,9 +2163,6 @@ int lfsck_namespace_rebuild_linkea(const struct lu_env *env, if (unlikely(lfsck_is_dead_obj(obj))) GOTO(unlock, rc = 0); - if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) - GOTO(unlock, rc = 1); - rc = dt_xattr_set(env, obj, &linkea_buf, XATTR_NAME_LINK, 0, th); @@ -2238,6 +2247,9 @@ int lfsck_namespace_repair_dirent(const struct lu_env *env, if (rc != 0) GOTO(log, rc); + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(unlock1, rc = 1); + th = lfsck_trans_create(env, dev, lfsck); if (IS_ERR(th)) GOTO(unlock1, rc = PTR_ERR(th)); @@ -2282,9 +2294,6 @@ int lfsck_namespace_repair_dirent(const struct lu_env *env, if (!lu_fid_eq(&tfid, &cfid)) GOTO(unlock2, rc = 0); - if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) - GOTO(unlock2, rc = 1); - rc = dt_delete(env, parent, (const struct dt_key *)name, th); if (rc != 0) GOTO(unlock2, rc); @@ -2378,6 +2387,9 @@ static int lfsck_namespace_repair_unmatched_pairs(const struct lu_env *env, LASSERT(!dt_object_remote(obj)); LASSERT(S_ISDIR(lfsck_object_type(obj))); + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 1); + rc = linkea_links_new(&ldata, &info->lti_big_buf, cname, pfid); if (rc != 0) GOTO(log, rc); @@ -2413,9 +2425,6 @@ static int lfsck_namespace_repair_unmatched_pairs(const struct lu_env *env, if (unlikely(lfsck_is_dead_obj(obj))) GOTO(unlock, rc = 0); - if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) - GOTO(unlock, rc = 1); - /* The old ".." name entry maybe not exist. */ dt_delete(env, obj, (const struct dt_key *)dotdot, th); @@ -3103,6 +3112,19 @@ static int lfsck_namespace_repair_nlink(const struct lu_env *env, LASSERT(!dt_object_remote(obj)); + /* If the LFSCK is marked as LF_INCOMPLETE, then means some MDT has + * ever tried to verify some remote MDT-object that resides on this + * MDT, but this MDT failed to respond such request. So means there + * may be some remote name entry on other MDT that references this + * object with another name, so we cannot know whether this linkEA + * is valid or not. So keep it there and maybe resolved when next + * LFSCK run. */ + if (ns->ln_flags & LF_INCOMPLETE) + GOTO(log, rc = 0); + + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(unlock, rc = 1); + rc = lfsck_ibits_lock(env, lfsck, obj, &lh, MDS_INODELOCK_UPDATE, LCK_PW); if (rc != 0) @@ -3122,15 +3144,6 @@ static int lfsck_namespace_repair_nlink(const struct lu_env *env, GOTO(stop, rc); dt_write_lock(env, obj, 0); - /* If the LFSCK is marked as LF_INCOMPLETE, then means some MDT has - * ever tried to verify some remote MDT-object that resides on this - * MDT, but this MDT failed to respond such request. So means there - * may be some remote name entry on other MDT that references this - * object with another name, so we cannot know whether this linkEA - * is valid or not. So keep it there and maybe resolved when next - * LFSCK run. */ - if (ns->ln_flags & LF_INCOMPLETE) - GOTO(unlock, rc = 0); rc = dt_attr_get(env, obj, la); if (rc != 0) @@ -3149,8 +3162,6 @@ static int lfsck_namespace_repair_nlink(const struct lu_env *env, GOTO(unlock, rc = 0); la->la_nlink = ldata.ld_leh->leh_reccount; - if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) - GOTO(unlock, rc = 1); rc = dt_attr_set(env, obj, la, th); @@ -3463,6 +3474,9 @@ static int lfsck_namespace_linkea_clear_overflow(const struct lu_env *env, LASSERT(!dt_object_remote(obj)); + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 1); + rc = lfsck_ibits_lock(env, lfsck, obj, &lh, MDS_INODELOCK_UPDATE, LCK_PW); if (rc != 0) @@ -3491,9 +3505,6 @@ static int lfsck_namespace_linkea_clear_overflow(const struct lu_env *env, GOTO(unlock, rc = 0); ldata->ld_leh->leh_overflow_time = 0; - if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) - GOTO(unlock, rc = 1); - lfsck_buf_init(&linkea_buf, ldata->ld_buf->lb_buf, ldata->ld_leh->leh_len); rc = dt_xattr_set(env, obj, &linkea_buf, XATTR_NAME_LINK, 0, th); @@ -6128,6 +6139,9 @@ static int lfsck_namespace_scan_local_lpf_one(const struct lu_env *env, GOTO(out, rc = -ENOENT); } + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(out, rc = 1); + LASSERT(!dt_object_remote(child)); idx = lfsck_sub_trace_file_fid2idx(&ent->lde_fid); @@ -6893,6 +6907,9 @@ int lfsck_verify_linkea(const struct lu_env *env, struct lfsck_instance *lfsck, if (!S_ISDIR(lfsck_object_type(obj))) RETURN(-ENOTDIR); + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + RETURN(0); + rc = lfsck_links_read_with_rec(env, obj, &ldata); if (rc == -ENODATA) { dirty = true; @@ -7006,6 +7023,9 @@ int lfsck_update_name_entry(const struct lu_env *env, bool exists = true; ENTRY; + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + RETURN(0); + rc = lfsck_lock(env, lfsck, dir, name, llh, MDS_INODELOCK_UPDATE, LCK_PW); if (rc != 0) diff --git a/lustre/lfsck/lfsck_striped_dir.c b/lustre/lfsck/lfsck_striped_dir.c index df01fdc..dc4c662b 100644 --- a/lustre/lfsck/lfsck_striped_dir.c +++ b/lustre/lfsck/lfsck_striped_dir.c @@ -208,6 +208,9 @@ static int lfsck_disable_master_lmv(const struct lu_env *env, int rc = 0; ENTRY; + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(log, rc = 0); + th = lfsck_trans_create(env, dev, lfsck); if (IS_ERR(th)) GOTO(log, rc = PTR_ERR(th)); @@ -231,9 +234,6 @@ static int lfsck_disable_master_lmv(const struct lu_env *env, if (unlikely(lfsck_is_dead_obj(obj))) GOTO(unlock, rc = 1); - if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) - GOTO(unlock, rc = 0); - if (del_lmv) { rc = dt_xattr_del(env, obj, XATTR_NAME_LMV, th); if (rc != 0) @@ -1074,6 +1074,9 @@ int lfsck_namespace_update_lmv(const struct lu_env *env, LASSERT(lmv4 != lmv); + if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) + GOTO(out, rc = 0); + lfsck_lmv_header_cpu_to_le(lmv4, lmv); lfsck_buf_init(buf, lmv4, sizeof(*lmv4)); @@ -1106,9 +1109,6 @@ int lfsck_namespace_update_lmv(const struct lu_env *env, if (unlikely(lfsck_is_dead_obj(obj))) GOTO(unlock, rc = 1); - if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) - GOTO(unlock, rc = 0); - rc = dt_xattr_set(env, obj, buf, XATTR_NAME_LMV, 0, th); GOTO(unlock, rc); @@ -1123,6 +1123,8 @@ stop: log: lfsck_ibits_unlock(&lh, LCK_EX); + +out: CDEBUG(D_LFSCK, "%s: namespace LFSCK updated the %s LMV EA " "for the object "DFID": rc = %d\n", lfsck_lfsck2name(lfsck), -- 1.8.3.1