- ENTRY;
- if (rec->lrh_type != LLOG_LOGID_MAGIC) {
- CERROR("invalid record in catalog\n");
- RETURN(-EINVAL);
- }
- CDEBUG(D_HA, "processing log "LPX64":%x at index %u of catalog "
- LPX64"\n", lir->lid_id.lgl_oid, lir->lid_id.lgl_ogen,
- rec->lrh_index, cat_llh->lgh_id.lgl_oid);
-
- rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
- if (rc) {
- CERROR("Cannot find handle for log "LPX64"\n",
- lir->lid_id.lgl_oid);
- RETURN(rc);
- }
+ ENTRY;
+ 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,
+ PFID(&cat_llh->lgh_id.lgl_oi.oi_fid),
+ cat_llh->lgh_id.lgl_ogen, rc);
+ RETURN(rc);
+ }
+ CDEBUG(D_HA, "processing log "DFID":%x at index %u of catalog "DFID"\n",
+ PFID(&lir->lid_id.lgl_oi.oi_fid), lir->lid_id.lgl_ogen,
+ le32_to_cpu(rec->lrh_index),
+ PFID(&cat_llh->lgh_id.lgl_oi.oi_fid));
+
+ rc = llog_cat_id2handle(env, cat_llh, llhp, &lir->lid_id);
+ if (rc) {
+ /* After a server crash, a stub of index record in catlog could
+ * be kept, because plain log destroy + catlog index record
+ * deletion are not atomic. So we end up with an index but no
+ * actual record. Destroy the index and move on. */
+ if (rc == -ENOENT || rc == -ESTALE)
+ 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,
+ PFID(&lir->lid_id.lgl_oi.oi_fid),
+ lir->lid_id.lgl_ogen, rc);
+
+ RETURN(rc);
+ }
+
+ /* clean old empty llogs, do not consider current llog in use */
+ /* ignore remote (lgh_obj == NULL) llogs */
+ 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) {
+ 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,
+ PFID(&lir->lid_id.lgl_oi.oi_fid), rc);
+ rc = LLOG_DEL_PLAIN;
+ }
+
+ RETURN(rc);
+}