X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Flfsck%2Flfsck_engine.c;h=56052c2c73ccd3625d2d92d654f2d4fcd250b8ef;hb=743f742874bfdf845a2f64c3d65081ea23740138;hp=0ed0b35f5def05c42cc3b76b9cadc85a7e56ad16;hpb=f6d744d259fe6bc0b8750127565fb13fb2e66c06;p=fs%2Flustre-release.git diff --git a/lustre/lfsck/lfsck_engine.c b/lustre/lfsck/lfsck_engine.c index 0ed0b35..56052c2 100644 --- a/lustre/lfsck/lfsck_engine.c +++ b/lustre/lfsck/lfsck_engine.c @@ -20,7 +20,7 @@ * GPL HEADER END */ /* - * Copyright (c) 2013, 2014, Intel Corporation. + * Copyright (c) 2013, 2015, Intel Corporation. */ /* * lustre/lfsck/lfsck_engine.c @@ -93,64 +93,6 @@ static void lfsck_di_dir_put(const struct lu_env *env, struct lfsck_instance *lf iops->put(env, di); } -static int lfsck_update_lma(const struct lu_env *env, - struct lfsck_instance *lfsck, struct dt_object *obj) -{ - struct lfsck_thread_info *info = lfsck_env_info(env); - struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram; - struct dt_device *dev = lfsck_obj2dev(obj); - struct lustre_mdt_attrs *lma = &info->lti_lma; - struct lu_buf *buf; - struct thandle *th; - int fl; - int rc; - ENTRY; - - if (bk->lb_param & LPF_DRYRUN) - RETURN(0); - - buf = lfsck_buf_get(env, info->lti_lma_old, LMA_OLD_SIZE); - rc = dt_xattr_get(env, obj, buf, XATTR_NAME_LMA, BYPASS_CAPA); - if (rc < 0) { - if (rc != -ENODATA) - RETURN(rc); - - fl = LU_XATTR_CREATE; - lustre_lma_init(lma, lfsck_dto2fid(obj), LMAC_FID_ON_OST, 0); - } else { - if (rc != LMA_OLD_SIZE && rc != sizeof(struct lustre_mdt_attrs)) - RETURN(-EINVAL); - - fl = LU_XATTR_REPLACE; - lustre_lma_swab(lma); - lustre_lma_init(lma, lfsck_dto2fid(obj), - lma->lma_compat | LMAC_FID_ON_OST, - lma->lma_incompat); - } - lustre_lma_swab(lma); - - th = dt_trans_create(env, dev); - if (IS_ERR(th)) - RETURN(PTR_ERR(th)); - - buf = lfsck_buf_get(env, lma, sizeof(*lma)); - rc = dt_declare_xattr_set(env, obj, buf, XATTR_NAME_LMA, fl, th); - if (rc != 0) - GOTO(stop, rc); - - rc = dt_trans_start_local(env, dev, th); - if (rc != 0) - GOTO(stop, rc); - - rc = dt_xattr_set(env, obj, buf, XATTR_NAME_LMA, fl, th, BYPASS_CAPA); - - GOTO(stop, rc); - -stop: - dt_trans_stop(env, dev, th); - return rc; -} - static int lfsck_parent_fid(const struct lu_env *env, struct dt_object *obj, struct lu_fid *fid) { @@ -159,7 +101,7 @@ static int lfsck_parent_fid(const struct lu_env *env, struct dt_object *obj, return -ENOTDIR; return dt_lookup(env, obj, (struct dt_rec *)fid, - (const struct dt_key *)"..", BYPASS_CAPA); + (const struct dt_key *)".."); } /** @@ -253,8 +195,7 @@ static int lfsck_needs_scan_dir(const struct lu_env *env, } rc = dt_xattr_get(env, obj, - lfsck_buf_get(env, NULL, 0), XATTR_NAME_LINK, - BYPASS_CAPA); + lfsck_buf_get(env, NULL, 0), XATTR_NAME_LINK); dt_read_unlock(env, obj); if (rc >= 0) GOTO(out, rc = 1); @@ -416,7 +357,7 @@ int lfsck_open_dir(const struct lu_env *env, } iops = &obj->do_index_ops->dio_it; - di = iops->init(env, obj, lfsck->li_args_dir, BYPASS_CAPA); + di = iops->init(env, obj, lfsck->li_args_dir); if (IS_ERR(di)) GOTO(out, rc = PTR_ERR(di)); @@ -609,13 +550,14 @@ out: static int lfsck_exec_dir(const struct lu_env *env, struct lfsck_instance *lfsck, + struct lfsck_assistant_object *lso, struct lu_dirent *ent, __u16 type) { struct lfsck_component *com; int rc; list_for_each_entry(com, &lfsck->li_list_scan, lc_link) { - rc = com->lc_ops->lfsck_exec_dir(env, com, ent, type); + rc = com->lc_ops->lfsck_exec_dir(env, com, lso, ent, type); if (rc != 0) return rc; } @@ -744,6 +686,7 @@ static int lfsck_master_dir_engine(const struct lu_env *env, (struct lu_dirent *)info->lti_key; struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram; struct ptlrpc_thread *thread = &lfsck->li_thread; + struct lfsck_assistant_object *lso = NULL; int rc; __u16 type; ENTRY; @@ -756,7 +699,7 @@ static int lfsck_master_dir_engine(const struct lu_env *env, lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(dir)), lfsck->li_cookie_dir); - RETURN(0); + GOTO(out, rc = 0); } lfsck->li_new_scanned++; @@ -774,25 +717,41 @@ static int lfsck_master_dir_engine(const struct lu_env *env, lfsck->li_cookie_dir, rc); lfsck_fail(env, lfsck, true); if (bk->lb_param & LPF_FAILOUT) - RETURN(rc); + GOTO(out, rc); else goto checkpoint; } - if (ent->lde_attrs & LUDA_IGNORE && - strcmp(ent->lde_name, dotdot) != 0) + if (ent->lde_attrs & LUDA_IGNORE) + goto checkpoint; + + /* skip dot entry. */ + if (ent->lde_namelen == 1 && ent->lde_name[0] == '.') goto checkpoint; + if (lso == NULL) { + lso = lfsck_assistant_object_init(env, + lfsck_dto2fid(dir), NULL, + lfsck->li_pos_current.lp_oit_cookie, true); + if (IS_ERR(lso)) { + if (bk->lb_param & LPF_FAILOUT) + RETURN(PTR_ERR(lso)); + + lso = NULL; + goto checkpoint; + } + } + /* The type in the @ent structure may has been overwritten, * so we need to pass the @type parameter independently. */ - rc = lfsck_exec_dir(env, lfsck, ent, type); + rc = lfsck_exec_dir(env, lfsck, lso, ent, type); if (rc != 0 && bk->lb_param & LPF_FAILOUT) - RETURN(rc); + GOTO(out, rc); checkpoint: rc = lfsck_checkpoint(env, lfsck); if (rc != 0 && bk->lb_param & LPF_FAILOUT) - RETURN(rc); + GOTO(out, rc); /* Rate control. */ lfsck_control_speed(lfsck); @@ -802,14 +761,14 @@ checkpoint: lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(dir)), lfsck->li_cookie_dir); - RETURN(0); + GOTO(out, rc = 0); } if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_FATAL2)) { spin_lock(&lfsck->li_lock); thread_set_flags(thread, SVC_STOPPING); spin_unlock(&lfsck->li_lock); - RETURN(-EINVAL); + GOTO(out, rc = -EINVAL); } rc = iops->next(env, di); @@ -818,7 +777,13 @@ checkpoint: if (rc > 0 && !lfsck->li_oit_over) lfsck_close_dir(env, lfsck, rc); - RETURN(rc); + GOTO(out, rc); + +out: + if (lso != NULL) + lfsck_assistant_object_put(env, lso); + + return rc; } /** @@ -863,7 +828,6 @@ static int lfsck_master_oit_engine(const struct lu_env *env, do { struct dt_object *target; - bool update_lma = false; if (lfsck->li_di_dir != NULL) { rc = lfsck_master_dir_engine(env, lfsck); @@ -932,13 +896,23 @@ static int lfsck_master_oit_engine(const struct lu_env *env, LASSERT(!lfsck->li_master); - /* It is an old format device, update the LMA. */ if (idx != idx1) { struct ost_id *oi = &info->lti_oi; + if (unlikely(idx1 != 0)) { + CDEBUG(D_LFSCK, "%s: invalid IDIF "DFID + ", not match device index %u\n", + lfsck_lfsck2name(lfsck), + PFID(fid), idx); + + goto checkpoint; + } + + /* rebuild the IDIF with index to + * avoid double instances for the + * same object. */ fid_to_ostid(fid, oi); ostid_to_fid(fid, oi, idx); - update_lma = true; } } else if (!fid_is_norm(fid) && !fid_is_igif(fid) && !fid_is_last_id(fid) && @@ -980,18 +954,9 @@ static int lfsck_master_oit_engine(const struct lu_env *env, goto checkpoint; } - if (dt_object_exists(target)) { - if (update_lma) { - rc = lfsck_update_lma(env, lfsck, target); - if (rc != 0) - CDEBUG(D_LFSCK, "%s: fail to update " - "LMA for "DFID": rc = %d\n", - lfsck_lfsck2name(lfsck), - PFID(lfsck_dto2fid(target)), rc); - } - if (rc == 0) - rc = lfsck_exec_oit(env, lfsck, target); - } + if (dt_object_exists(target)) + rc = lfsck_exec_oit(env, lfsck, target); + lfsck_object_put(env, target); if (rc != 0 && bk->lb_param & LPF_FAILOUT) RETURN(rc); @@ -1041,6 +1006,18 @@ int lfsck_master_engine(void *args) int rc; ENTRY; + /* There will be some objects verification during the LFSCK start, + * such as the subsequent lfsck_verify_lpf(). Trigger low layer OI + * OI scrub before that to handle the potential inconsistence. */ + oit_di = oit_iops->init(env, oit_obj, lfsck->li_args_oit); + if (IS_ERR(oit_di)) { + rc = PTR_ERR(oit_di); + CDEBUG(D_LFSCK, "%s: master engine fail to init iteration: " + "rc = %d\n", lfsck_lfsck2name(lfsck), rc); + + GOTO(fini_args, rc); + } + if (lfsck->li_master && (!list_empty(&lfsck->li_list_scan) || !list_empty(&lfsck->li_list_double_scan))) { @@ -1056,15 +1033,6 @@ int lfsck_master_engine(void *args) lfsck_lfsck2name(lfsck), rc); } - oit_di = oit_iops->init(env, oit_obj, lfsck->li_args_oit, BYPASS_CAPA); - if (IS_ERR(oit_di)) { - rc = PTR_ERR(oit_di); - CDEBUG(D_LFSCK, "%s: master engine fail to init iteration: " - "rc = %d\n", lfsck_lfsck2name(lfsck), rc); - - GOTO(fini_args, rc); - } - spin_lock(&lfsck->li_lock); lfsck->li_di_oit = oit_di; spin_unlock(&lfsck->li_lock); @@ -1184,9 +1152,10 @@ static int lfsck_assistant_query_others(const struct lu_env *env, memset(lr, 0, sizeof(*lr)); lr->lr_event = LE_QUERY; lr->lr_active = com->lc_type; + + memset(laia, 0, sizeof(*laia)); laia->laia_com = com; laia->laia_lr = lr; - laia->laia_shared = 0; if (!list_empty(&lad->lad_mdt_phase1_list)) { ltds = &lfsck->li_mdt_descs; @@ -1300,9 +1269,10 @@ static int lfsck_assistant_notify_others(const struct lu_env *env, lr->lr_index = lfsck_dev_idx(lfsck); lr->lr_active = com->lc_type; + + memset(laia, 0, sizeof(*laia)); laia->laia_com = com; laia->laia_lr = lr; - laia->laia_shared = 0; switch (lr->lr_event) { case LE_START: @@ -1325,8 +1295,6 @@ static int lfsck_assistant_notify_others(const struct lu_env *env, LASSERT(ltd != NULL); laia->laia_ltd = ltd; - ltd->ltd_layout_done = 0; - ltd->ltd_synced_failures = 0; rc = lfsck_async_request(env, ltd->ltd_exp, lr, set, lfsck_async_interpret_common, laia, LFSCK_NOTIFY); @@ -1357,7 +1325,7 @@ next: spin_lock(<ds->ltd_lock); if (com->lc_type == LFSCK_TYPE_LAYOUT) { cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) { - ltd = LTD_TGT(ltds, idx); + ltd = lfsck_ltd2tgt(ltds, idx); LASSERT(ltd != NULL); if (!list_empty(<d->ltd_layout_list)) @@ -1370,7 +1338,7 @@ next: } } else { cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) { - ltd = LTD_TGT(ltds, idx); + ltd = lfsck_ltd2tgt(ltds, idx); LASSERT(ltd != NULL); if (!list_empty(<d->ltd_namespace_list)) @@ -1609,6 +1577,7 @@ int lfsck_assistant_engine(void *args) } spin_lock(&lad->lad_lock); + lad->lad_task = current; thread_set_flags(athread, SVC_RUNNING); spin_unlock(&lad->lad_lock); wake_up_all(&mthread->t_ctl_waitq); @@ -1636,10 +1605,7 @@ int lfsck_assistant_engine(void *args) /* Wake up the main engine thread only when the list * is empty or half of the prefetched items have been * handled to avoid too frequent thread schedule. */ - if (lad->lad_prefetched == 0 || - (bk->lb_async_windows != 0 && - bk->lb_async_windows / 2 == - lad->lad_prefetched)) + if (lad->lad_prefetched <= (bk->lb_async_windows / 2)) wakeup = true; spin_unlock(&lad->lad_lock); if (wakeup) @@ -1673,18 +1639,18 @@ int lfsck_assistant_engine(void *args) lad->lad_to_post = 0; LASSERT(lad->lad_post_result > 0); + /* Wakeup the master engine to go ahead. */ + wake_up_all(&mthread->t_ctl_waitq); + memset(lr, 0, sizeof(*lr)); lr->lr_event = LE_PHASE1_DONE; lr->lr_status = lad->lad_post_result; rc = lfsck_assistant_notify_others(env, com, lr); - if (rc != 0) - CDEBUG(D_LFSCK, "%s: LFSCK assistant failed to " - "notify others for %s post: rc = %d\n", - lfsck_lfsck2name(lfsck), - lad->lad_name, rc); - /* Wakeup the master engine to go ahead. */ - wake_up_all(&mthread->t_ctl_waitq); + CDEBUG(D_LFSCK, "%s: LFSCK assistant notified " + "others for %s post: rc = %d\n", + lfsck_lfsck2name(lfsck), + lad->lad_name, rc); } if (lad->lad_to_double_scan) { @@ -1855,6 +1821,7 @@ fini: lad->lad_assistant_status = (rc1 != 0 ? rc1 : rc); thread_set_flags(athread, SVC_STOPPED); wake_up_all(&mthread->t_ctl_waitq); + lad->lad_task = NULL; spin_unlock(&lad->lad_lock); CDEBUG(D_LFSCK, "%s: %s LFSCK assistant thread exit: rc = %d\n",