4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/llog_cat.c
38 * OST<->MDS recovery logging infrastructure.
40 * Invariants in implementation:
41 * - we do not share logs among different OST<->MDS connections, so that
42 * if an OST or MDS fails it need only look at log(s) relevant to itself
44 * Author: Andreas Dilger <adilger@clusterfs.com>
45 * Author: Alexey Zhuravlev <alexey.zhuravlev@intel.com>
46 * Author: Mikhail Pershin <mike.pershin@intel.com>
49 #define DEBUG_SUBSYSTEM S_LOG
52 #include <liblustre.h>
55 #include <obd_class.h>
57 #include "llog_internal.h"
59 /* Create a new log handle and add it to the open list.
60 * This log handle will be closed when all of the records in it are removed.
62 * Assumes caller has already pushed us into the kernel context and is locking.
64 static int llog_cat_new_log(const struct lu_env *env,
65 struct llog_handle *cathandle,
66 struct llog_handle *loghandle,
69 struct llog_thread_info *lgi = llog_info(env);
70 struct llog_logid_rec *rec = &lgi->lgi_logid;
75 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_LLOG_CREATE_FAILED))
78 rc = llog_create(env, loghandle, th);
79 /* if llog is already created, no need to initialize it */
83 CERROR("%s: can't create new plain llog in catalog: rc = %d\n",
84 loghandle->lgh_ctxt->loc_obd->obd_name, rc);
88 rc = llog_init_handle(env, loghandle,
89 LLOG_F_IS_PLAIN | LLOG_F_ZAP_WHEN_EMPTY,
90 &cathandle->lgh_hdr->llh_tgtuuid);
92 GOTO(out_destroy, rc);
94 /* build the record for this log in the catalog */
95 rec->lid_hdr.lrh_len = sizeof(*rec);
96 rec->lid_hdr.lrh_type = LLOG_LOGID_MAGIC;
97 rec->lid_id = loghandle->lgh_id;
99 /* append the new record into catalog. The new index will be
100 * assigned to the record and updated in rec header */
101 rc = llog_write_rec(env, cathandle, &rec->lid_hdr,
102 &loghandle->u.phd.phd_cookie, LLOG_NEXT_IDX, th);
104 GOTO(out_destroy, rc);
106 CDEBUG(D_OTHER, "new recovery log "DOSTID":%x for index %u of catalog"
107 DOSTID"\n", POSTID(&loghandle->lgh_id.lgl_oi),
108 loghandle->lgh_id.lgl_ogen, rec->lid_hdr.lrh_index,
109 POSTID(&cathandle->lgh_id.lgl_oi));
111 loghandle->lgh_hdr->llh_cat_idx = rec->lid_hdr.lrh_index;
114 llog_destroy(env, loghandle);
118 /* Open an existent log handle and add it to the open list.
119 * This log handle will be closed when all of the records in it are removed.
121 * Assumes caller has already pushed us into the kernel context and is locking.
122 * We return a lock on the handle to ensure nobody yanks it from us.
124 * This takes extra reference on llog_handle via llog_handle_get() and require
125 * this reference to be put by caller using llog_handle_put()
127 int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
128 struct llog_handle **res, struct llog_logid *logid)
130 struct llog_handle *loghandle;
135 if (cathandle == NULL)
138 down_write(&cathandle->lgh_lock);
139 cfs_list_for_each_entry(loghandle, &cathandle->u.chd.chd_head,
141 struct llog_logid *cgl = &loghandle->lgh_id;
143 if (ostid_id(&cgl->lgl_oi) == ostid_id(&logid->lgl_oi) &&
144 ostid_seq(&cgl->lgl_oi) == ostid_seq(&logid->lgl_oi)) {
145 if (cgl->lgl_ogen != logid->lgl_ogen) {
146 CERROR("%s: log "DOSTID" generation %x != %x\n",
147 loghandle->lgh_ctxt->loc_obd->obd_name,
148 POSTID(&logid->lgl_oi), cgl->lgl_ogen,
152 loghandle->u.phd.phd_cat_handle = cathandle;
153 up_write(&cathandle->lgh_lock);
157 up_write(&cathandle->lgh_lock);
159 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle, logid, NULL,
162 CERROR("%s: error opening log id "DOSTID":%x: rc = %d\n",
163 cathandle->lgh_ctxt->loc_obd->obd_name,
164 POSTID(&logid->lgl_oi), logid->lgl_ogen, rc);
168 rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN, NULL);
170 llog_close(env, loghandle);
175 down_write(&cathandle->lgh_lock);
176 cfs_list_add(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head);
177 up_write(&cathandle->lgh_lock);
179 loghandle->u.phd.phd_cat_handle = cathandle;
180 loghandle->u.phd.phd_cookie.lgc_lgl = cathandle->lgh_id;
181 loghandle->u.phd.phd_cookie.lgc_index =
182 loghandle->lgh_hdr->llh_cat_idx;
185 llog_handle_get(loghandle);
190 int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle)
192 struct llog_handle *loghandle, *n;
197 cfs_list_for_each_entry_safe(loghandle, n, &cathandle->u.chd.chd_head,
199 struct llog_log_hdr *llh = loghandle->lgh_hdr;
202 /* unlink open-not-created llogs */
203 cfs_list_del_init(&loghandle->u.phd.phd_entry);
204 llh = loghandle->lgh_hdr;
205 if (loghandle->lgh_obj != NULL && llh != NULL &&
206 (llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
207 (llh->llh_count == 1)) {
208 rc = llog_destroy(env, loghandle);
210 CERROR("%s: failure destroying log during "
211 "cleanup: rc = %d\n",
212 loghandle->lgh_ctxt->loc_obd->obd_name,
215 index = loghandle->u.phd.phd_cookie.lgc_index;
216 llog_cat_cleanup(env, cathandle, NULL, index);
218 llog_close(env, loghandle);
220 /* if handle was stored in ctxt, remove it too */
221 if (cathandle->lgh_ctxt->loc_handle == cathandle)
222 cathandle->lgh_ctxt->loc_handle = NULL;
223 rc = llog_close(env, cathandle);
226 EXPORT_SYMBOL(llog_cat_close);
229 * lockdep markers for nested struct llog_handle::lgh_lock locking.
236 /** Return the currently active log handle. If the current log handle doesn't
237 * have enough space left for the current record, start a new one.
239 * If reclen is 0, we only want to know what the currently active log is,
240 * otherwise we get a lock on this log so nobody can steal our space.
242 * Assumes caller has already pushed us into the kernel context and is locking.
244 * NOTE: loghandle is write-locked upon successful return
246 static struct llog_handle *llog_cat_current_log(struct llog_handle *cathandle,
249 struct llog_handle *loghandle = NULL;
252 down_read_nested(&cathandle->lgh_lock, LLOGH_CAT);
253 loghandle = cathandle->u.chd.chd_current_log;
255 struct llog_log_hdr *llh;
257 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
258 llh = loghandle->lgh_hdr;
260 loghandle->lgh_last_idx < LLOG_BITMAP_SIZE(llh) - 1) {
261 up_read(&cathandle->lgh_lock);
264 up_write(&loghandle->lgh_lock);
267 up_read(&cathandle->lgh_lock);
269 /* time to use next log */
271 /* first, we have to make sure the state hasn't changed */
272 down_write_nested(&cathandle->lgh_lock, LLOGH_CAT);
273 loghandle = cathandle->u.chd.chd_current_log;
275 struct llog_log_hdr *llh;
277 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
278 llh = loghandle->lgh_hdr;
280 if (loghandle->lgh_last_idx < LLOG_BITMAP_SIZE(llh) - 1) {
281 up_write(&cathandle->lgh_lock);
284 up_write(&loghandle->lgh_lock);
288 CDEBUG(D_INODE, "use next log\n");
290 loghandle = cathandle->u.chd.chd_next_log;
291 cathandle->u.chd.chd_current_log = loghandle;
292 cathandle->u.chd.chd_next_log = NULL;
293 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
294 up_write(&cathandle->lgh_lock);
299 /* Add a single record to the recovery log(s) using a catalog
300 * Returns as llog_write_record
302 * Assumes caller has already pushed us into the kernel context.
304 int llog_cat_add_rec(const struct lu_env *env, struct llog_handle *cathandle,
305 struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
308 struct llog_handle *loghandle;
312 LASSERT(rec->lrh_len <= LLOG_CHUNK_SIZE);
313 loghandle = llog_cat_current_log(cathandle, th);
314 LASSERT(!IS_ERR(loghandle));
316 /* loghandle is already locked by llog_cat_current_log() for us */
317 if (!llog_exist(loghandle)) {
318 rc = llog_cat_new_log(env, cathandle, loghandle, th);
320 up_write(&loghandle->lgh_lock);
324 /* now let's try to add the record */
325 rc = llog_write_rec(env, loghandle, rec, reccookie, LLOG_NEXT_IDX, th);
327 CDEBUG_LIMIT(rc == -ENOSPC ? D_HA : D_ERROR,
328 "llog_write_rec %d: lh=%p\n", rc, loghandle);
329 up_write(&loghandle->lgh_lock);
331 /* try to use next log */
332 loghandle = llog_cat_current_log(cathandle, th);
333 LASSERT(!IS_ERR(loghandle));
334 /* new llog can be created concurrently */
335 if (!llog_exist(loghandle)) {
336 rc = llog_cat_new_log(env, cathandle, loghandle, th);
338 up_write(&loghandle->lgh_lock);
342 /* now let's try to add the record */
343 rc = llog_write_rec(env, loghandle, rec, reccookie,
346 CERROR("llog_write_rec %d: lh=%p\n", rc, loghandle);
347 up_write(&loghandle->lgh_lock);
352 EXPORT_SYMBOL(llog_cat_add_rec);
354 int llog_cat_declare_add_rec(const struct lu_env *env,
355 struct llog_handle *cathandle,
356 struct llog_rec_hdr *rec, struct thandle *th)
358 struct llog_thread_info *lgi = llog_info(env);
359 struct llog_logid_rec *lirec = &lgi->lgi_logid;
360 struct llog_handle *loghandle, *next;
365 if (cathandle->u.chd.chd_current_log == NULL) {
366 /* declare new plain llog */
367 down_write(&cathandle->lgh_lock);
368 if (cathandle->u.chd.chd_current_log == NULL) {
369 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
370 NULL, NULL, LLOG_OPEN_NEW);
372 cathandle->u.chd.chd_current_log = loghandle;
373 cfs_list_add_tail(&loghandle->u.phd.phd_entry,
374 &cathandle->u.chd.chd_head);
377 up_write(&cathandle->lgh_lock);
378 } else if (cathandle->u.chd.chd_next_log == NULL) {
379 /* declare next plain llog */
380 down_write(&cathandle->lgh_lock);
381 if (cathandle->u.chd.chd_next_log == NULL) {
382 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
383 NULL, NULL, LLOG_OPEN_NEW);
385 cathandle->u.chd.chd_next_log = loghandle;
386 cfs_list_add_tail(&loghandle->u.phd.phd_entry,
387 &cathandle->u.chd.chd_head);
390 up_write(&cathandle->lgh_lock);
395 lirec->lid_hdr.lrh_len = sizeof(*lirec);
397 if (!llog_exist(cathandle->u.chd.chd_current_log)) {
398 rc = llog_declare_create(env, cathandle->u.chd.chd_current_log,
402 llog_declare_write_rec(env, cathandle, &lirec->lid_hdr, -1, th);
404 /* declare records in the llogs */
405 rc = llog_declare_write_rec(env, cathandle->u.chd.chd_current_log,
410 next = cathandle->u.chd.chd_next_log;
412 if (!llog_exist(next)) {
413 rc = llog_declare_create(env, next, th);
414 llog_declare_write_rec(env, cathandle, &lirec->lid_hdr,
417 /* XXX: we hope for declarations made for existing llog
418 * this might be not correct with some backends
419 * where declarations are expected against specific
420 * object like ZFS with full debugging enabled */
421 /*llog_declare_write_rec(env, next, rec, -1, th);*/
426 EXPORT_SYMBOL(llog_cat_declare_add_rec);
428 int llog_cat_add(const struct lu_env *env, struct llog_handle *cathandle,
429 struct llog_rec_hdr *rec, struct llog_cookie *reccookie)
431 struct llog_ctxt *ctxt;
432 struct dt_device *dt;
433 struct thandle *th = NULL;
436 ctxt = cathandle->lgh_ctxt;
438 LASSERT(ctxt->loc_exp);
440 LASSERT(cathandle->lgh_obj != NULL);
441 dt = lu2dt_dev(cathandle->lgh_obj->do_lu.lo_dev);
443 th = dt_trans_create(env, dt);
447 rc = llog_cat_declare_add_rec(env, cathandle, rec, th);
451 rc = dt_trans_start_local(env, dt, th);
454 rc = llog_cat_add_rec(env, cathandle, rec, reccookie, th);
456 dt_trans_stop(env, dt, th);
459 EXPORT_SYMBOL(llog_cat_add);
461 /* For each cookie in the cookie array, we clear the log in-use bit and either:
462 * - the log is empty, so mark it free in the catalog header and delete it
463 * - the log is not empty, just write out the log header
465 * The cookies may be in different log files, so we need to get new logs
468 * Assumes caller has already pushed us into the kernel context.
470 int llog_cat_cancel_records(const struct lu_env *env,
471 struct llog_handle *cathandle, int count,
472 struct llog_cookie *cookies)
474 int i, index, rc = 0, failed = 0;
478 for (i = 0; i < count; i++, cookies++) {
479 struct llog_handle *loghandle;
480 struct llog_logid *lgl = &cookies->lgc_lgl;
483 rc = llog_cat_id2handle(env, cathandle, &loghandle, lgl);
485 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
486 cathandle->lgh_ctxt->loc_obd->obd_name,
487 POSTID(&lgl->lgl_oi), rc);
492 lrc = llog_cancel_rec(env, loghandle, cookies->lgc_index);
493 if (lrc == LLOG_DEL_PLAIN) { /* log has been destroyed */
494 index = loghandle->u.phd.phd_cookie.lgc_index;
495 rc = llog_cat_cleanup(env, cathandle, loghandle,
497 } else if (lrc == -ENOENT) {
498 if (rc == 0) /* ENOENT shouldn't rewrite any error */
500 } else if (lrc < 0) {
504 llog_handle_put(loghandle);
507 CERROR("%s: fail to cancel %d of %d llog-records: rc = %d\n",
508 cathandle->lgh_ctxt->loc_obd->obd_name, failed, count,
513 EXPORT_SYMBOL(llog_cat_cancel_records);
515 int llog_cat_process_cb(const struct lu_env *env, struct llog_handle *cat_llh,
516 struct llog_rec_hdr *rec, void *data)
518 struct llog_process_data *d = data;
519 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
520 struct llog_handle *llh;
524 if (rec->lrh_type != LLOG_LOGID_MAGIC) {
525 CERROR("invalid record in catalog\n");
528 CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
529 DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
530 rec->lrh_index, POSTID(&cat_llh->lgh_id.lgl_oi));
532 rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
534 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
535 cat_llh->lgh_ctxt->loc_obd->obd_name,
536 POSTID(&lir->lid_id.lgl_oi), rc);
540 if (rec->lrh_index < d->lpd_startcat) {
541 /* Skip processing of the logs until startcat */
543 } else if (d->lpd_startidx > 0) {
544 struct llog_process_cat_data cd;
546 cd.lpcd_first_idx = d->lpd_startidx;
547 cd.lpcd_last_idx = 0;
548 rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
550 /* Continue processing the next log from idx 0 */
553 rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
557 /* The empty plain log was destroyed while processing */
558 if (rc == LLOG_DEL_PLAIN)
559 rc = llog_cat_cleanup(env, cat_llh, llh,
560 llh->u.phd.phd_cookie.lgc_index);
561 llog_handle_put(llh);
566 int llog_cat_process_or_fork(const struct lu_env *env,
567 struct llog_handle *cat_llh,
568 llog_cb_t cb, void *data, int startcat,
569 int startidx, bool fork)
571 struct llog_process_data d;
572 struct llog_log_hdr *llh = cat_llh->lgh_hdr;
576 LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
579 d.lpd_startcat = startcat;
580 d.lpd_startidx = startidx;
582 if (llh->llh_cat_idx > cat_llh->lgh_last_idx) {
583 struct llog_process_cat_data cd;
585 CWARN("catlog "DOSTID" crosses index zero\n",
586 POSTID(&cat_llh->lgh_id.lgl_oi));
588 cd.lpcd_first_idx = llh->llh_cat_idx;
589 cd.lpcd_last_idx = 0;
590 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
595 cd.lpcd_first_idx = 0;
596 cd.lpcd_last_idx = cat_llh->lgh_last_idx;
597 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
600 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
606 EXPORT_SYMBOL(llog_cat_process_or_fork);
608 int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
609 llog_cb_t cb, void *data, int startcat, int startidx)
611 return llog_cat_process_or_fork(env, cat_llh, cb, data, startcat,
614 EXPORT_SYMBOL(llog_cat_process);
616 static int llog_cat_reverse_process_cb(const struct lu_env *env,
617 struct llog_handle *cat_llh,
618 struct llog_rec_hdr *rec, void *data)
620 struct llog_process_data *d = data;
621 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
622 struct llog_handle *llh;
625 if (le32_to_cpu(rec->lrh_type) != LLOG_LOGID_MAGIC) {
626 CERROR("invalid record in catalog\n");
629 CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
630 DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
631 le32_to_cpu(rec->lrh_index), POSTID(&cat_llh->lgh_id.lgl_oi));
633 rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
635 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
636 cat_llh->lgh_ctxt->loc_obd->obd_name,
637 POSTID(&lir->lid_id.lgl_oi), rc);
641 rc = llog_reverse_process(env, llh, d->lpd_cb, d->lpd_data, NULL);
643 /* The empty plain was destroyed while processing */
644 if (rc == LLOG_DEL_PLAIN)
645 rc = llog_cat_cleanup(env, cat_llh, llh,
646 llh->u.phd.phd_cookie.lgc_index);
648 llog_handle_put(llh);
652 int llog_cat_reverse_process(const struct lu_env *env,
653 struct llog_handle *cat_llh,
654 llog_cb_t cb, void *data)
656 struct llog_process_data d;
657 struct llog_process_cat_data cd;
658 struct llog_log_hdr *llh = cat_llh->lgh_hdr;
662 LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
666 if (llh->llh_cat_idx > cat_llh->lgh_last_idx) {
667 CWARN("catalog "DOSTID" crosses index zero\n",
668 POSTID(&cat_llh->lgh_id.lgl_oi));
670 cd.lpcd_first_idx = 0;
671 cd.lpcd_last_idx = cat_llh->lgh_last_idx;
672 rc = llog_reverse_process(env, cat_llh,
673 llog_cat_reverse_process_cb,
678 cd.lpcd_first_idx = le32_to_cpu(llh->llh_cat_idx);
679 cd.lpcd_last_idx = 0;
680 rc = llog_reverse_process(env, cat_llh,
681 llog_cat_reverse_process_cb,
684 rc = llog_reverse_process(env, cat_llh,
685 llog_cat_reverse_process_cb,
691 EXPORT_SYMBOL(llog_cat_reverse_process);
693 int llog_cat_set_first_idx(struct llog_handle *cathandle, int index)
695 struct llog_log_hdr *llh = cathandle->lgh_hdr;
696 int i, bitmap_size, idx;
699 bitmap_size = LLOG_BITMAP_SIZE(llh);
700 if (llh->llh_cat_idx == (index - 1)) {
701 idx = llh->llh_cat_idx + 1;
702 llh->llh_cat_idx = idx;
703 if (idx == cathandle->lgh_last_idx)
705 for (i = (index + 1) % bitmap_size;
706 i != cathandle->lgh_last_idx;
707 i = (i + 1) % bitmap_size) {
708 if (!ext2_test_bit(i, llh->llh_bitmap)) {
709 idx = llh->llh_cat_idx + 1;
710 llh->llh_cat_idx = idx;
712 llh->llh_cat_idx = 0;
718 CDEBUG(D_RPCTRACE, "set catlog "DOSTID" first idx %u\n",
719 POSTID(&cathandle->lgh_id.lgl_oi), llh->llh_cat_idx);
725 /* Cleanup deleted plain llog traces from catalog */
726 int llog_cat_cleanup(const struct lu_env *env, struct llog_handle *cathandle,
727 struct llog_handle *loghandle, int index)
732 if (loghandle != NULL) {
733 /* remove destroyed llog from catalog list and
734 * chd_current_log variable */
735 down_write(&cathandle->lgh_lock);
736 if (cathandle->u.chd.chd_current_log == loghandle)
737 cathandle->u.chd.chd_current_log = NULL;
738 cfs_list_del_init(&loghandle->u.phd.phd_entry);
739 up_write(&cathandle->lgh_lock);
740 LASSERT(index == loghandle->u.phd.phd_cookie.lgc_index);
741 /* llog was opened and keep in a list, close it now */
742 llog_close(env, loghandle);
744 /* remove plain llog entry from catalog by index */
745 llog_cat_set_first_idx(cathandle, index);
746 rc = llog_cancel_rec(env, cathandle, index);
748 CDEBUG(D_HA, "cancel plain log at index"
749 " %u of catalog "DOSTID"\n",
750 index, POSTID(&cathandle->lgh_id.lgl_oi));
754 int cat_cancel_cb(const struct lu_env *env, struct llog_handle *cathandle,
755 struct llog_rec_hdr *rec, void *data)
757 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
758 struct llog_handle *loghandle;
759 struct llog_log_hdr *llh;
764 if (rec->lrh_type != LLOG_LOGID_MAGIC) {
765 CERROR("invalid record in catalog\n");
769 CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
770 DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
771 rec->lrh_index, POSTID(&cathandle->lgh_id.lgl_oi));
773 rc = llog_cat_id2handle(env, cathandle, &loghandle, &lir->lid_id);
775 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
776 cathandle->lgh_ctxt->loc_obd->obd_name,
777 POSTID(&lir->lid_id.lgl_oi), rc);
778 if (rc == -ENOENT || rc == -ESTALE) {
779 /* remove index from catalog */
780 llog_cat_cleanup(env, cathandle, NULL, rec->lrh_index);
785 llh = loghandle->lgh_hdr;
786 if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
787 (llh->llh_count == 1)) {
788 rc = llog_destroy(env, loghandle);
790 CERROR("%s: fail to destroy empty log: rc = %d\n",
791 loghandle->lgh_ctxt->loc_obd->obd_name, rc);
793 llog_cat_cleanup(env, cathandle, loghandle,
794 loghandle->u.phd.phd_cookie.lgc_index);
796 llog_handle_put(loghandle);
800 EXPORT_SYMBOL(cat_cancel_cb);
802 /* helper to initialize catalog llog and process it to cancel */
803 int llog_cat_init_and_process(const struct lu_env *env,
804 struct llog_handle *llh)
808 rc = llog_init_handle(env, llh, LLOG_F_IS_CAT, NULL);
812 rc = llog_process_or_fork(env, llh, cat_cancel_cb, NULL, NULL, false);
814 CERROR("%s: llog_process() with cat_cancel_cb failed: rc = "
815 "%d\n", llh->lgh_ctxt->loc_obd->obd_name, rc);
818 EXPORT_SYMBOL(llog_cat_init_and_process);