X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fobdclass%2Fllog_cat.c;h=4f5b0b1133a44e0bbb87d0d0b6ce0cf2f6202b18;hp=c28ca74f5848206a841a9fed6ff148cb16926544;hb=aa22a6826ee521ab14994a4533b0dbffb529aab0;hpb=cc10922919325c212ae98a69d63328c0efbd4f83 diff --git a/lustre/obdclass/llog_cat.c b/lustre/obdclass/llog_cat.c index c28ca74..4f5b0b1 100644 --- a/lustre/obdclass/llog_cat.c +++ b/lustre/obdclass/llog_cat.c @@ -27,7 +27,6 @@ */ /* * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. * * lustre/obdclass/llog_cat.c * @@ -97,13 +96,12 @@ static int llog_cat_new_log(const struct lu_env *env, if (cathandle->lgh_name == NULL) { CWARN("%s: there are no more free slots in catalog " DFID":%x\n", - loghandle->lgh_ctxt->loc_obd->obd_name, + loghandle2name(loghandle), PFID(&cathandle->lgh_id.lgl_oi.oi_fid), cathandle->lgh_id.lgl_ogen); } else { CWARN("%s: there are no more free slots in " - "catalog %s\n", - loghandle->lgh_ctxt->loc_obd->obd_name, + "catalog %s\n", loghandle2name(loghandle), cathandle->lgh_name); } RETURN(-ENOSPC); @@ -162,7 +160,7 @@ static int llog_cat_new_log(const struct lu_env *env, GOTO(out, rc = 0); } else if (rc != 0) { CERROR("%s: can't create new plain llog in catalog: rc = %d\n", - loghandle->lgh_ctxt->loc_obd->obd_name, rc); + loghandle2name(loghandle), rc); GOTO(out, rc); } @@ -248,14 +246,16 @@ static int llog_cat_refresh(const struct lu_env *env, if (!llog_exist(loghandle)) continue; + down_write(&loghandle->lgh_lock); rc = llog_read_header(env, loghandle, NULL); + up_write(&loghandle->lgh_lock); if (rc) goto unlock; } rc = llog_read_header(env, cathandle, NULL); unlock: - up_write(&loghandle->lgh_lock); + up_write(&cathandle->lgh_lock); return rc; } @@ -391,14 +391,21 @@ int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle, ostid_seq(&cgl->lgl_oi) == ostid_seq(&logid->lgl_oi)) { if (cgl->lgl_ogen != logid->lgl_ogen) { CWARN("%s: log "DFID" generation %x != %x\n", - loghandle->lgh_ctxt->loc_obd->obd_name, + loghandle2name(loghandle), PFID(&logid->lgl_oi.oi_fid), cgl->lgl_ogen, logid->lgl_ogen); continue; } + *res = llog_handle_get(loghandle); + if (!*res) { + CERROR("%s: log "DFID" refcount is zero!\n", + loghandle2name(loghandle), + PFID(&logid->lgl_oi.oi_fid)); + continue; + } loghandle->u.phd.phd_cat_handle = cathandle; up_write(&cathandle->lgh_lock); - GOTO(out, rc = 0); + RETURN(rc); } } up_write(&cathandle->lgh_lock); @@ -407,18 +414,21 @@ int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle, LLOG_OPEN_EXISTS); if (rc < 0) { CERROR("%s: error opening log id "DFID":%x: rc = %d\n", - cathandle->lgh_ctxt->loc_obd->obd_name, - PFID(&logid->lgl_oi.oi_fid), logid->lgl_ogen, rc); + loghandle2name(cathandle), PFID(&logid->lgl_oi.oi_fid), + logid->lgl_ogen, rc); RETURN(rc); } - rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN | fmt, NULL); + rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN | + LLOG_F_ZAP_WHEN_EMPTY | fmt, NULL); if (rc < 0) { llog_close(env, loghandle); - loghandle = NULL; + *res = NULL; RETURN(rc); } + *res = llog_handle_get(loghandle); + LASSERT(*res); down_write(&cathandle->lgh_lock); list_add_tail(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head); up_write(&cathandle->lgh_lock); @@ -427,11 +437,7 @@ int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle, loghandle->u.phd.phd_cookie.lgc_lgl = cathandle->lgh_id; loghandle->u.phd.phd_cookie.lgc_index = loghandle->lgh_hdr->llh_cat_idx; - EXIT; -out: - llog_handle_get(loghandle); - *res = loghandle; - return 0; + RETURN(0); } int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle) @@ -456,8 +462,7 @@ int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle) if (rc) CERROR("%s: failure destroying log during " "cleanup: rc = %d\n", - loghandle->lgh_ctxt->loc_obd->obd_name, - rc); + loghandle2name(loghandle), rc); index = loghandle->u.phd.phd_cookie.lgc_index; llog_cat_cleanup(env, cathandle, NULL, index); @@ -535,7 +540,7 @@ next: * meet this situation. */ if (IS_ERR_OR_NULL(cathandle->u.chd.chd_next_log)) { CERROR("%s: next log does not exist!\n", - cathandle->lgh_ctxt->loc_obd->obd_name); + loghandle2name(cathandle)); loghandle = ERR_PTR(-EIO); if (cathandle->u.chd.chd_next_log == NULL) { /* Store the error in chd_next_log, so @@ -612,7 +617,7 @@ retry: if (retried++ == 0) GOTO(retry, rc); CERROR("%s: error on 2nd llog: rc = %d\n", - cathandle->lgh_ctxt->loc_obd->obd_name, rc); + loghandle2name(cathandle), rc); } RETURN(rc); @@ -708,8 +713,7 @@ int llog_cat_cancel_arr_rec(const struct lu_env *env, rc = llog_cat_id2handle(env, cathandle, &loghandle, lgl); if (rc) { CDEBUG(D_HA, "%s: cannot find llog for handle "DFID":%x" - ": rc = %d\n", - cathandle->lgh_ctxt->loc_obd->obd_name, + ": rc = %d\n", loghandle2name(cathandle), PFID(&lgl->lgl_oi.oi_fid), lgl->lgl_ogen, rc); RETURN(rc); } @@ -723,11 +727,10 @@ int llog_cat_cancel_arr_rec(const struct lu_env *env, */ rc = -ENOENT; CDEBUG(D_HA, "%s: llog "DFID":%x does not exist" - ": rc = %d\n", - cathandle->lgh_ctxt->loc_obd->obd_name, + ": rc = %d\n", loghandle2name(cathandle), PFID(&lgl->lgl_oi.oi_fid), lgl->lgl_ogen, rc); - llog_handle_put(loghandle); + llog_handle_put(env, loghandle); RETURN(rc); } @@ -739,16 +742,15 @@ int llog_cat_cancel_arr_rec(const struct lu_env *env, rc = llog_cat_cleanup(env, cathandle, loghandle, cat_index); if (rc) CERROR("%s: fail to cancel catalog record: rc = %d\n", - cathandle->lgh_ctxt->loc_obd->obd_name, rc); + loghandle2name(cathandle), rc); rc = 0; } - llog_handle_put(loghandle); + llog_handle_put(env, loghandle); if (rc) CERROR("%s: fail to cancel %d llog-records: rc = %d\n", - cathandle->lgh_ctxt->loc_obd->obd_name, count, - rc); + loghandle2name(cathandle), count, rc); RETURN(rc); } @@ -784,8 +786,7 @@ int llog_cat_cancel_records(const struct lu_env *env, } if (failed) CERROR("%s: fail to cancel %d of %d llog-records: rc = %d\n", - cathandle->lgh_ctxt->loc_obd->obd_name, failed, count, - rc); + loghandle2name(cathandle), failed, count, rc); RETURN(rc); } EXPORT_SYMBOL(llog_cat_cancel_records); @@ -803,7 +804,7 @@ static int llog_cat_process_common(const struct lu_env *env, if (rec->lrh_type != le32_to_cpu(LLOG_LOGID_MAGIC)) { rc = -EINVAL; CWARN("%s: invalid record in catalog "DFID":%x: rc = %d\n", - cat_llh->lgh_ctxt->loc_obd->obd_name, + loghandle2name(cat_llh), PFID(&cat_llh->lgh_id.lgl_oi.oi_fid), cat_llh->lgh_id.lgl_ogen, rc); RETURN(rc); @@ -823,7 +824,7 @@ static int llog_cat_process_common(const struct lu_env *env, rc = LLOG_DEL_RECORD; else if (rc) CWARN("%s: can't find llog handle "DFID":%x: rc = %d\n", - cat_llh->lgh_ctxt->loc_obd->obd_name, + loghandle2name(cat_llh), PFID(&lir->lid_id.lgl_oi.oi_fid), lir->lid_id.lgl_ogen, rc); @@ -835,11 +836,12 @@ static int llog_cat_process_common(const struct lu_env *env, hdr = (*llhp)->lgh_hdr; if ((hdr->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) && hdr->llh_count == 1 && cat_llh->lgh_obj != NULL && - *llhp != cat_llh->u.chd.chd_current_log) { + *llhp != cat_llh->u.chd.chd_current_log && + *llhp != cat_llh->u.chd.chd_next_log) { rc = llog_destroy(env, *llhp); if (rc) CWARN("%s: can't destroy empty log "DFID": rc = %d\n", - (*llhp)->lgh_ctxt->loc_obd->obd_name, + loghandle2name((*llhp)), PFID(&lir->lid_id.lgl_oi.oi_fid), rc); rc = LLOG_DEL_PLAIN; } @@ -866,6 +868,7 @@ static int llog_cat_process_cb(const struct lu_env *env, } else if (d->lpd_startidx > 0) { struct llog_process_cat_data cd; + cd.lpcd_read_mode = LLOG_READ_MODE_NORMAL; cd.lpcd_first_idx = d->lpd_startidx; cd.lpcd_last_idx = 0; rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data, @@ -876,19 +879,28 @@ static int llog_cat_process_cb(const struct lu_env *env, rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data, NULL, false); } + if (rc == -ENOENT && (cat_llh->lgh_hdr->llh_flags & LLOG_F_RM_ON_ERR)) { + /* + * plain llog is reported corrupted, so better to just remove + * it if the caller is fine with that. + */ + CERROR("%s: remove corrupted/missing llog "DFID"\n", + loghandle2name(cat_llh), + PFID(&llh->lgh_id.lgl_oi.oi_fid)); + rc = LLOG_DEL_PLAIN; + } out: /* The empty plain log was destroyed while processing */ - if (rc == LLOG_DEL_PLAIN) { - rc = llog_cat_cleanup(env, cat_llh, llh, - llh->u.phd.phd_cookie.lgc_index); - } else if (rc == LLOG_DEL_RECORD) { + if (rc == LLOG_DEL_PLAIN || rc == LLOG_DEL_RECORD) /* clear wrong catalog entry */ - rc = llog_cat_cleanup(env, cat_llh, NULL, rec->lrh_index); - } + rc = llog_cat_cleanup(env, cat_llh, llh, rec->lrh_index); + else if (rc == LLOG_SKIP_PLAIN) + /* processing callback ask to skip the llog -> continue */ + rc = 0; if (llh) - llog_handle_put(llh); + llog_handle_put(env, llh); RETURN(rc); } @@ -912,10 +924,12 @@ int llog_cat_process_or_fork(const struct lu_env *env, if (llh->llh_cat_idx >= cat_llh->lgh_last_idx && llh->llh_count > 1) { - struct llog_process_cat_data cd; + struct llog_process_cat_data cd = { + .lpcd_read_mode = LLOG_READ_MODE_NORMAL + }; CWARN("%s: catlog "DFID" crosses index zero\n", - cat_llh->lgh_ctxt->loc_obd->obd_name, + loghandle2name(cat_llh), PFID(&cat_llh->lgh_id.lgl_oi.oi_fid)); /*startcat = 0 is default value for general processing */ if ((startcat != LLOG_CAT_FIRST && @@ -993,7 +1007,7 @@ static int llog_cat_size_cb(const struct lu_env *env, } if (llh != NULL) - llog_handle_put(llh); + llog_handle_put(env, llh); RETURN(0); } @@ -1049,6 +1063,9 @@ static int llog_cat_reverse_process_cb(const struct lu_env *env, } else if (rc == LLOG_DEL_RECORD) { /* clear wrong catalog entry */ rc = llog_cat_cleanup(env, cat_llh, NULL, rec->lrh_index); + } else if (rc == LLOG_SKIP_PLAIN) { + /* processing callback ask to skip the llog -> continue */ + rc = 0; } if (rc) RETURN(rc); @@ -1060,7 +1077,7 @@ static int llog_cat_reverse_process_cb(const struct lu_env *env, rc = llog_cat_cleanup(env, cat_llh, llh, llh->u.phd.phd_cookie.lgc_index); - llog_handle_put(llh); + llog_handle_put(env, llh); RETURN(rc); } @@ -1075,13 +1092,14 @@ int llog_cat_reverse_process(const struct lu_env *env, ENTRY; LASSERT(llh->llh_flags & LLOG_F_IS_CAT); + cd.lpcd_read_mode = LLOG_READ_MODE_NORMAL; d.lpd_data = data; d.lpd_cb = cb; if (llh->llh_cat_idx >= cat_llh->lgh_last_idx && llh->llh_count > 1) { CWARN("%s: catalog "DFID" crosses index zero\n", - cat_llh->lgh_ctxt->loc_obd->obd_name, + loghandle2name(cat_llh), PFID(&cat_llh->lgh_id.lgl_oi.oi_fid)); cd.lpcd_first_idx = 0; @@ -1125,7 +1143,7 @@ static int llog_cat_set_first_idx(struct llog_handle *cathandle, int idx) while (idx != cathandle->lgh_last_idx) { idx = (idx + 1) % bitmap_size; - if (!ext2_test_bit(idx, LLOG_HDR_BITMAP(llh))) { + if (!test_bit_le(idx, LLOG_HDR_BITMAP(llh))) { /* update llh_cat_idx for each unset bit, * expecting the next one is set */ llh->llh_cat_idx = idx; @@ -1139,7 +1157,7 @@ static int llog_cat_set_first_idx(struct llog_handle *cathandle, int idx) } } - CDEBUG(D_RPCTRACE, "catlog "DFID" first idx %u, last_idx %u\n", + CDEBUG(D_HA, "catlog "DFID" first idx %u, last_idx %u\n", PFID(&cathandle->lgh_id.lgl_oi.oi_fid), llh->llh_cat_idx, cathandle->lgh_last_idx); } @@ -1152,17 +1170,20 @@ int llog_cat_cleanup(const struct lu_env *env, struct llog_handle *cathandle, struct llog_handle *loghandle, int index) { int rc; + struct lu_fid fid = {.f_seq = 0, .f_oid = 0, .f_ver = 0}; LASSERT(index); if (loghandle != NULL) { /* remove destroyed llog from catalog list and * chd_current_log variable */ + fid = loghandle->lgh_id.lgl_oi.oi_fid; down_write(&cathandle->lgh_lock); if (cathandle->u.chd.chd_current_log == loghandle) cathandle->u.chd.chd_current_log = NULL; list_del_init(&loghandle->u.phd.phd_entry); up_write(&cathandle->lgh_lock); - LASSERT(index == loghandle->u.phd.phd_cookie.lgc_index); + LASSERT(index == loghandle->u.phd.phd_cookie.lgc_index || + loghandle->u.phd.phd_cookie.lgc_index == 0); /* llog was opened and keep in a list, close it now */ llog_close(env, loghandle); } @@ -1175,7 +1196,9 @@ int llog_cat_cleanup(const struct lu_env *env, struct llog_handle *cathandle, llog_cat_set_first_idx(cathandle, index); rc = llog_cancel_rec(env, cathandle, index); if (rc == 0) - CDEBUG(D_HA, "cancel plain log at index %u of catalog "DFID"\n", - index, PFID(&cathandle->lgh_id.lgl_oi.oi_fid)); + CDEBUG(D_HA, + "cancel plain log "DFID" at index %u of catalog "DFID"\n", + PFID(&fid), index, + PFID(&cathandle->lgh_id.lgl_oi.oi_fid)); return rc; }