+
+/* callback func for llog_process in llog_obd_origin_setup */
+int cat_cancel_cb(const struct lu_env *env, struct llog_handle *cathandle,
+ struct llog_rec_hdr *rec, void *data)
+{
+ struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
+ struct llog_handle *loghandle;
+ struct llog_log_hdr *llh;
+ int rc, index;
+
+ ENTRY;
+
+ if (rec->lrh_type != LLOG_LOGID_MAGIC) {
+ CERROR("%s: invalid record in catalog\n",
+ loghandle->lgh_ctxt->loc_obd->obd_name);
+ 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, cathandle->lgh_id.lgl_oid);
+
+ rc = llog_cat_id2handle(cathandle, &loghandle, &lir->lid_id);
+ if (rc) {
+ CERROR("%s: cannot find handle for llog "LPX64"\n",
+ loghandle->lgh_ctxt->loc_obd->obd_name,
+ lir->lid_id.lgl_oid);
+ if (rc == -ENOENT) {
+ index = rec->lrh_index;
+ goto cat_cleanup;
+ }
+ RETURN(rc);
+ }
+
+ llh = loghandle->lgh_hdr;
+ if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
+ (llh->llh_count == 1)) {
+ rc = llog_destroy(loghandle);
+ if (rc)
+ CERROR("%s: fail to destroy empty log: rc = %d\n",
+ loghandle->lgh_ctxt->loc_obd->obd_name, rc);
+
+ index = loghandle->u.phd.phd_cookie.lgc_index;
+ llog_free_handle(loghandle);
+
+cat_cleanup:
+ LASSERT(index);
+ llog_cat_set_first_idx(cathandle, index);
+ rc = llog_cancel_rec(cathandle, index);
+ if (rc == 0)
+ CDEBUG(D_HA,
+ "cancel log "LPX64":%x at index %u of catalog "
+ LPX64"\n", lir->lid_id.lgl_oid,
+ lir->lid_id.lgl_ogen, rec->lrh_index,
+ cathandle->lgh_id.lgl_oid);
+ }
+
+ RETURN(rc);
+}