*/
/*
* This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
*
* lustre/obdclass/llog_cat.c
*
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);
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);
}
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;
}
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",
- loghandle->lgh_ctxt->loc_obd->obd_name,
+ loghandle2name(loghandle),
PFID(&logid->lgl_oi.oi_fid));
continue;
}
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);
*res = NULL;
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);
* 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
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);
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);
}
*/
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(env, loghandle);
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;
}
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);
}
}
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);
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);
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);
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;
}
} 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,
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(env, llh);
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 &&
} 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);
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;
}
}
- 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);
}
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);
}
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;
}