X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Flfsck%2Flfsck_lib.c;h=891cabaaab4371b58dc36eb51d4db4fc2e8e89eb;hp=4b622a7c0c76f14a005a62c161375c65e47f47a9;hb=0c1ae1cb9c19f8a4f6c5a7ff6a1fd54807430795;hpb=dd392dfbfb1a71423f18166a56e43d9234c739d7 diff --git a/lustre/lfsck/lfsck_lib.c b/lustre/lfsck/lfsck_lib.c index 4b622a7..891caba 100644 --- a/lustre/lfsck/lfsck_lib.c +++ b/lustre/lfsck/lfsck_lib.c @@ -68,7 +68,7 @@ static LIST_HEAD(lfsck_ost_orphan_list); static LIST_HEAD(lfsck_mdt_orphan_list); static DEFINE_SPINLOCK(lfsck_instance_lock); -const char *lfsck_flags_names[] = { +const char *const lfsck_flags_names[] = { "scanned-once", "inconsistent", "upgrade", @@ -77,7 +77,7 @@ const char *lfsck_flags_names[] = { NULL }; -const char *lfsck_param_names[] = { +const char *const lfsck_param_names[] = { NULL, "failout", "dryrun", @@ -158,7 +158,7 @@ static void lfsck_tgt_descs_fini(struct lfsck_tgt_descs *ltds) LASSERTF(ltds->ltd_tgtnr == 0, "tgt count unmatched: %d\n", ltds->ltd_tgtnr); - for (idx = 0; idx < TGT_PTRS; idx++) { + for (idx = 0; idx < ARRAY_SIZE(ltds->ltd_tgts_idx); idx++) { if (ltds->ltd_tgts_idx[idx] != NULL) { OBD_FREE_PTR(ltds->ltd_tgts_idx[idx]); ltds->ltd_tgts_idx[idx] = NULL; @@ -621,7 +621,7 @@ static int lfsck_lpf_remove_name_entry(const struct lu_env *env, if (rc != 0) RETURN(rc); - th = dt_trans_create(env, dev); + th = lfsck_trans_create(env, dev, lfsck); if (IS_ERR(th)) GOTO(unlock, rc = PTR_ERR(th)); @@ -687,7 +687,7 @@ static int lfsck_create_lpf_local(const struct lu_env *env, if (rc != 0) RETURN(rc); - th = dt_trans_create(env, dev); + th = lfsck_trans_create(env, dev, lfsck); if (IS_ERR(th)) RETURN(PTR_ERR(th)); @@ -865,7 +865,7 @@ static int lfsck_create_lpf_remote(const struct lu_env *env, /* Transaction I: locally */ dev = lfsck_obj2dev(child); - th = dt_trans_create(env, dev); + th = lfsck_trans_create(env, dev, lfsck); if (IS_ERR(th)) RETURN(PTR_ERR(th)); @@ -962,7 +962,7 @@ static int lfsck_create_lpf_remote(const struct lu_env *env, /* Transaction II: remotely */ dev = lfsck_obj2dev(parent); - th = dt_trans_create(env, dev); + th = lfsck_trans_create(env, dev, lfsck); if (IS_ERR(th)) RETURN(PTR_ERR(th)); @@ -1056,8 +1056,7 @@ static int lfsck_create_lpf(const struct lu_env *env, * created the .lustre/lost+found/MDTxxxx but failed to update * the lfsck_bookmark::lb_lpf_fid successfully. So need lookup * it from MDT0 firstly. */ - rc = dt_lookup(env, parent, (struct dt_rec *)cfid, - (const struct dt_key *)name); + rc = dt_lookup_dir(env, parent, name, cfid); if (rc != 0 && rc != -ENOENT) GOTO(unlock, rc); @@ -1090,7 +1089,7 @@ static int lfsck_create_lpf(const struct lu_env *env, la->la_atime = la->la_mtime = la->la_ctime = ktime_get_real_seconds(); la->la_mode = S_IFDIR | S_IRWXU; la->la_valid = LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE | - LA_UID | LA_GID; + LA_UID | LA_GID | LA_TYPE; memset(dof, 0, sizeof(*dof)); dof->dof_type = dt_mode_to_dft(S_IFDIR); @@ -1265,8 +1264,7 @@ static int lfsck_verify_lpf_pairs(const struct lu_env *env, ENTRY; fid_zero(fid); - rc = dt_lookup(env, child, (struct dt_rec *)fid, - (const struct dt_key *)dotdot); + rc = dt_lookup_dir(env, child, dotdot, fid); if (rc != 0) GOTO(linkea, rc); @@ -1282,7 +1280,7 @@ static int lfsck_verify_lpf_pairs(const struct lu_env *env, } cname = lfsck_name_get_const(env, name, strlen(name)); - rc = lfsck_verify_linkea(env, child, cname, &LU_LPF_FID); + rc = lfsck_verify_linkea(env, lfsck, child, cname, &LU_LPF_FID); if (rc == 0) rc = lfsck_update_lpf_entry(env, lfsck, parent, child, name, type); @@ -1351,8 +1349,7 @@ linkea: GOTO(out_done, rc = 1); } - rc = dt_lookup(env, parent2, (struct dt_rec *)fid, - (const struct dt_key *)name2); + rc = dt_lookup_dir(env, parent2, name2, fid); dt_read_unlock(env, child); lfsck_ibits_unlock(&lh, LCK_PR); if (rc != 0 && rc != -ENOENT) @@ -1426,6 +1423,9 @@ int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck) LASSERT(lfsck->li_master); + if (lfsck_is_dryrun(lfsck)) + RETURN(0); + if (lfsck->li_lpf_root_obj != NULL) RETURN(0); @@ -1466,8 +1466,7 @@ int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck) /* child2 */ snprintf(name, 8, "MDT%04x", node); - rc = dt_lookup(env, parent, (struct dt_rec *)cfid, - (const struct dt_key *)name); + rc = dt_lookup_dir(env, parent, name, cfid); if (rc == -ENOENT) { rc = 0; goto find_child1; @@ -1516,7 +1515,8 @@ find_child1: } cname = lfsck_name_get_const(env, name, strlen(name)); - rc = lfsck_verify_linkea(env, child2, cname, &LU_LPF_FID); + rc = lfsck_verify_linkea(env, lfsck, child2, cname, + &LU_LPF_FID); GOTO(put, rc); } @@ -1775,7 +1775,7 @@ static inline int lfsck_instance_add(struct lfsck_instance *lfsck) return 0; } -void lfsck_bits_dump(struct seq_file *m, int bits, const char *names[], +void lfsck_bits_dump(struct seq_file *m, int bits, const char *const names[], const char *prefix) { int flag; @@ -1784,7 +1784,7 @@ void lfsck_bits_dump(struct seq_file *m, int bits, const char *names[], seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n'); - for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) { + for (i = 0, flag = 1; bits != 0; i++, flag = BIT(i)) { if (flag & bits) { bits &= ~flag; if (names[i] != NULL) { @@ -1954,7 +1954,7 @@ void lfsck_thread_args_fini(struct lfsck_thread_args *lta) } struct lfsck_assistant_data * -lfsck_assistant_data_init(struct lfsck_assistant_operations *lao, +lfsck_assistant_data_init(const struct lfsck_assistant_operations *lao, const char *name) { struct lfsck_assistant_data *lad; @@ -2389,8 +2389,8 @@ static int lfsck_async_interpret(const struct lu_env *env, struct lfsck_async_interpret_args *laia = args; struct lfsck_instance *lfsck; - lfsck = container_of0(laia->laia_ltds, struct lfsck_instance, - li_mdt_descs); + lfsck = container_of(laia->laia_ltds, struct lfsck_instance, + li_mdt_descs); lfsck_interpret(env, lfsck, req, laia, rc); lfsck_tgt_put(laia->laia_ltd); if (rc != 0 && laia->laia_result != -EALREADY) @@ -2593,7 +2593,7 @@ void lfsck_post_generic(const struct lu_env *env, CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s post, rc = %d\n", lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result); - wake_up_all(&athread->t_ctl_waitq); + wake_up(&athread->t_ctl_waitq); wait_event_idle(mthread->t_ctl_waitq, (*result > 0 && list_empty(&lad->lad_req_list)) || thread_is_stopped(athread)); @@ -2621,7 +2621,7 @@ int lfsck_double_scan_generic(const struct lu_env *env, "status %d\n", lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, status); - wake_up_all(&athread->t_ctl_waitq); + wake_up(&athread->t_ctl_waitq); wait_event_idle(mthread->t_ctl_waitq, test_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags) || thread_is_stopped(athread)); @@ -2644,7 +2644,7 @@ void lfsck_quit_generic(const struct lu_env *env, struct ptlrpc_thread *athread = &lad->lad_thread; set_bit(LAD_EXIT, &lad->lad_flags); - wake_up_all(&athread->t_ctl_waitq); + wake_up(&athread->t_ctl_waitq); wait_event_idle(mthread->t_ctl_waitq, thread_is_init(athread) || thread_is_stopped(athread)); @@ -3324,7 +3324,7 @@ trigger: thread_is_stopped(thread)); if (start == NULL || !(start->ls_flags & LPF_BROADCAST)) { lfsck->li_start_unplug = 1; - wake_up_all(&thread->t_ctl_waitq); + wake_up(&thread->t_ctl_waitq); GOTO(out, rc = 0); } @@ -3343,13 +3343,13 @@ trigger: spin_unlock(&lfsck->li_lock); lfsck->li_start_unplug = 1; - wake_up_all(&thread->t_ctl_waitq); + wake_up(&thread->t_ctl_waitq); wait_event_idle(thread->t_ctl_waitq, thread_is_stopped(thread)); } } else { lfsck->li_start_unplug = 1; - wake_up_all(&thread->t_ctl_waitq); + wake_up(&thread->t_ctl_waitq); } GOTO(put, rc); @@ -3431,7 +3431,7 @@ int lfsck_stop(const struct lu_env *env, struct dt_device *key, } } - wake_up_all(&thread->t_ctl_waitq); + wake_up(&thread->t_ctl_waitq); spin_unlock(&lfsck->li_lock); if (stop && stop->ls_flags & LPF_BROADCAST) rc1 = lfsck_stop_all(env, lfsck, stop); @@ -3567,8 +3567,8 @@ int lfsck_query(const struct lu_env *env, struct dt_device *key, GOTO(out, rc = -ENOTSUPP); } - for (i = 0, type = 1 << i; i < LFSCK_TYPE_BITS; - i++, type = 1 << i) { + for (i = 0, type = BIT(i); i < LFSCK_TYPE_BITS; + i++, type = BIT(i)) { if (!(que->lu_types & type)) continue; @@ -3592,8 +3592,8 @@ again: if (!(que->lu_flags & LPF_WAIT)) GOTO(out, rc); - for (i = 0, type = 1 << i; i < LFSCK_TYPE_BITS; - i++, type = 1 << i) { + for (i = 0, type = BIT(i); i < LFSCK_TYPE_BITS; + i++, type = BIT(i)) { if (!(que->lu_types & type)) continue; @@ -3709,9 +3709,6 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key, if (IS_ERR(root)) GOTO(out, rc = PTR_ERR(root)); - if (unlikely(!dt_try_as_dir(env, root))) - GOTO(out, rc = -ENOTDIR); - lfsck->li_local_root_fid = *fid; if (master) { lfsck->li_master = 1; @@ -3719,9 +3716,8 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key, struct lu_fid *pfid = &lfsck_env_info(env)->lti_fid2; const struct lu_name *cname; - rc = dt_lookup(env, root, - (struct dt_rec *)(&lfsck->li_global_root_fid), - (const struct dt_key *)"ROOT"); + rc = dt_lookup_dir(env, root, "ROOT", + &lfsck->li_global_root_fid); if (rc != 0) GOTO(out, rc); @@ -3729,11 +3725,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key, if (IS_ERR(obj)) GOTO(out, rc = PTR_ERR(obj)); - if (unlikely(!dt_try_as_dir(env, obj))) - GOTO(out, rc = -ENOTDIR); - - rc = dt_lookup(env, obj, (struct dt_rec *)fid, - (const struct dt_key *)dotlustre); + rc = dt_lookup_dir(env, obj, dotlustre, fid); if (rc != 0) GOTO(out, rc); @@ -3744,7 +3736,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key, cname = lfsck_name_get_const(env, dotlustre, strlen(dotlustre)); - rc = lfsck_verify_linkea(env, obj, cname, + rc = lfsck_verify_linkea(env, lfsck, obj, cname, &lfsck->li_global_root_fid); if (rc != 0) GOTO(out, rc); @@ -3753,8 +3745,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key, GOTO(out, rc = -ENOTDIR); *pfid = *fid; - rc = dt_lookup(env, obj, (struct dt_rec *)fid, - (const struct dt_key *)lostfound); + rc = dt_lookup_dir(env, obj, lostfound, fid); if (rc != 0) GOTO(out, rc); @@ -3765,7 +3756,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key, cname = lfsck_name_get_const(env, lostfound, strlen(lostfound)); - rc = lfsck_verify_linkea(env, obj, cname, pfid); + rc = lfsck_verify_linkea(env, lfsck, obj, cname, pfid); if (rc != 0) GOTO(out, rc);