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, 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 "../include/obd_class.h"
54 #include "llog_internal.h"
56 /* Create a new log handle and add it to the open list.
57 * This log handle will be closed when all of the records in it are removed.
59 * Assumes caller has already pushed us into the kernel context and is locking.
61 static int llog_cat_new_log(const struct lu_env *env,
62 struct llog_handle *cathandle,
63 struct llog_handle *loghandle,
67 struct llog_log_hdr *llh;
68 struct llog_logid_rec rec = { { 0 }, };
69 int rc, index, bitmap_size;
71 llh = cathandle->lgh_hdr;
72 bitmap_size = LLOG_BITMAP_SIZE(llh);
74 index = (cathandle->lgh_last_idx + 1) % bitmap_size;
76 /* maximum number of available slots in catlog is bitmap_size - 2 */
77 if (llh->llh_cat_idx == index) {
78 CERROR("no free catalog slots for log...\n");
82 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_LLOG_CREATE_FAILED))
85 rc = llog_create(env, loghandle, th);
86 /* if llog is already created, no need to initialize it */
90 CERROR("%s: can't create new plain llog in catalog: rc = %d\n",
91 loghandle->lgh_ctxt->loc_obd->obd_name, rc);
95 rc = llog_init_handle(env, loghandle,
96 LLOG_F_IS_PLAIN | LLOG_F_ZAP_WHEN_EMPTY,
97 &cathandle->lgh_hdr->llh_tgtuuid);
104 spin_lock(&loghandle->lgh_hdr_lock);
106 if (ext2_set_bit(index, llh->llh_bitmap)) {
107 CERROR("argh, index %u already set in log bitmap?\n",
109 spin_unlock(&loghandle->lgh_hdr_lock);
110 LBUG(); /* should never happen */
112 spin_unlock(&loghandle->lgh_hdr_lock);
114 cathandle->lgh_last_idx = index;
115 llh->llh_tail.lrt_index = index;
118 "new recovery log "DOSTID":%x for index %u of catalog"
119 DOSTID"\n", POSTID(&loghandle->lgh_id.lgl_oi),
120 loghandle->lgh_id.lgl_ogen, index,
121 POSTID(&cathandle->lgh_id.lgl_oi));
122 /* build the record for this log in the catalog */
123 rec.lid_hdr.lrh_len = sizeof(rec);
124 rec.lid_hdr.lrh_index = index;
125 rec.lid_hdr.lrh_type = LLOG_LOGID_MAGIC;
126 rec.lid_id = loghandle->lgh_id;
127 rec.lid_tail.lrt_len = sizeof(rec);
128 rec.lid_tail.lrt_index = index;
130 /* update the catalog: header and record */
131 rc = llog_write_rec(env, cathandle, &rec.lid_hdr,
132 &loghandle->u.phd.phd_cookie, 1, NULL, index, th);
136 loghandle->lgh_hdr->llh_cat_idx = index;
139 llog_destroy(env, loghandle);
143 /* Open an existent log handle and add it to the open list.
144 * This log handle will be closed when all of the records in it are removed.
146 * Assumes caller has already pushed us into the kernel context and is locking.
147 * We return a lock on the handle to ensure nobody yanks it from us.
149 * This takes extra reference on llog_handle via llog_handle_get() and require
150 * this reference to be put by caller using llog_handle_put()
152 int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
153 struct llog_handle **res, struct llog_logid *logid)
155 struct llog_handle *loghandle;
158 if (cathandle == NULL)
161 down_write(&cathandle->lgh_lock);
162 list_for_each_entry(loghandle, &cathandle->u.chd.chd_head,
164 struct llog_logid *cgl = &loghandle->lgh_id;
166 if (ostid_id(&cgl->lgl_oi) == ostid_id(&logid->lgl_oi) &&
167 ostid_seq(&cgl->lgl_oi) == ostid_seq(&logid->lgl_oi)) {
168 if (cgl->lgl_ogen != logid->lgl_ogen) {
169 CERROR("%s: log "DOSTID" generation %x != %x\n",
170 loghandle->lgh_ctxt->loc_obd->obd_name,
171 POSTID(&logid->lgl_oi), cgl->lgl_ogen,
175 loghandle->u.phd.phd_cat_handle = cathandle;
176 up_write(&cathandle->lgh_lock);
181 up_write(&cathandle->lgh_lock);
183 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle, logid, NULL,
186 CERROR("%s: error opening log id "DOSTID":%x: rc = %d\n",
187 cathandle->lgh_ctxt->loc_obd->obd_name,
188 POSTID(&logid->lgl_oi), logid->lgl_ogen, rc);
192 rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN, NULL);
194 llog_close(env, loghandle);
199 down_write(&cathandle->lgh_lock);
200 list_add(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head);
201 up_write(&cathandle->lgh_lock);
203 loghandle->u.phd.phd_cat_handle = cathandle;
204 loghandle->u.phd.phd_cookie.lgc_lgl = cathandle->lgh_id;
205 loghandle->u.phd.phd_cookie.lgc_index =
206 loghandle->lgh_hdr->llh_cat_idx;
208 llog_handle_get(loghandle);
213 int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle)
215 struct llog_handle *loghandle, *n;
218 list_for_each_entry_safe(loghandle, n, &cathandle->u.chd.chd_head,
220 struct llog_log_hdr *llh = loghandle->lgh_hdr;
223 /* unlink open-not-created llogs */
224 list_del_init(&loghandle->u.phd.phd_entry);
225 llh = loghandle->lgh_hdr;
226 if (loghandle->lgh_obj != NULL && llh != NULL &&
227 (llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
228 (llh->llh_count == 1)) {
229 rc = llog_destroy(env, loghandle);
231 CERROR("%s: failure destroying log during cleanup: rc = %d\n",
232 loghandle->lgh_ctxt->loc_obd->obd_name,
235 index = loghandle->u.phd.phd_cookie.lgc_index;
236 llog_cat_cleanup(env, cathandle, NULL, index);
238 llog_close(env, loghandle);
240 /* if handle was stored in ctxt, remove it too */
241 if (cathandle->lgh_ctxt->loc_handle == cathandle)
242 cathandle->lgh_ctxt->loc_handle = NULL;
243 rc = llog_close(env, cathandle);
246 EXPORT_SYMBOL(llog_cat_close);
249 * lockdep markers for nested struct llog_handle::lgh_lock locking.
256 /** Return the currently active log handle. If the current log handle doesn't
257 * have enough space left for the current record, start a new one.
259 * If reclen is 0, we only want to know what the currently active log is,
260 * otherwise we get a lock on this log so nobody can steal our space.
262 * Assumes caller has already pushed us into the kernel context and is locking.
264 * NOTE: loghandle is write-locked upon successful return
266 static struct llog_handle *llog_cat_current_log(struct llog_handle *cathandle,
269 struct llog_handle *loghandle = NULL;
271 down_read_nested(&cathandle->lgh_lock, LLOGH_CAT);
272 loghandle = cathandle->u.chd.chd_current_log;
274 struct llog_log_hdr *llh;
276 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
277 llh = loghandle->lgh_hdr;
279 loghandle->lgh_last_idx < LLOG_BITMAP_SIZE(llh) - 1) {
280 up_read(&cathandle->lgh_lock);
283 up_write(&loghandle->lgh_lock);
285 up_read(&cathandle->lgh_lock);
287 /* time to use next log */
289 /* first, we have to make sure the state hasn't changed */
290 down_write_nested(&cathandle->lgh_lock, LLOGH_CAT);
291 loghandle = cathandle->u.chd.chd_current_log;
293 struct llog_log_hdr *llh;
295 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
296 llh = loghandle->lgh_hdr;
298 if (loghandle->lgh_last_idx < LLOG_BITMAP_SIZE(llh) - 1) {
299 up_write(&cathandle->lgh_lock);
302 up_write(&loghandle->lgh_lock);
305 CDEBUG(D_INODE, "use next log\n");
307 loghandle = cathandle->u.chd.chd_next_log;
308 cathandle->u.chd.chd_current_log = loghandle;
309 cathandle->u.chd.chd_next_log = NULL;
310 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
311 up_write(&cathandle->lgh_lock);
316 /* Add a single record to the recovery log(s) using a catalog
317 * Returns as llog_write_record
319 * Assumes caller has already pushed us into the kernel context.
321 int llog_cat_add_rec(const struct lu_env *env, struct llog_handle *cathandle,
322 struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
323 void *buf, struct thandle *th)
325 struct llog_handle *loghandle;
328 LASSERT(rec->lrh_len <= LLOG_CHUNK_SIZE);
329 loghandle = llog_cat_current_log(cathandle, th);
330 LASSERT(!IS_ERR(loghandle));
332 /* loghandle is already locked by llog_cat_current_log() for us */
333 if (!llog_exist(loghandle)) {
334 rc = llog_cat_new_log(env, cathandle, loghandle, th);
336 up_write(&loghandle->lgh_lock);
340 /* now let's try to add the record */
341 rc = llog_write_rec(env, loghandle, rec, reccookie, 1, buf, -1, th);
343 CDEBUG_LIMIT(rc == -ENOSPC ? D_HA : D_ERROR,
344 "llog_write_rec %d: lh=%p\n", rc, loghandle);
345 up_write(&loghandle->lgh_lock);
347 /* try to use next log */
348 loghandle = llog_cat_current_log(cathandle, th);
349 LASSERT(!IS_ERR(loghandle));
350 /* new llog can be created concurrently */
351 if (!llog_exist(loghandle)) {
352 rc = llog_cat_new_log(env, cathandle, loghandle, th);
354 up_write(&loghandle->lgh_lock);
358 /* now let's try to add the record */
359 rc = llog_write_rec(env, loghandle, rec, reccookie, 1, buf,
362 CERROR("llog_write_rec %d: lh=%p\n", rc, loghandle);
363 up_write(&loghandle->lgh_lock);
368 EXPORT_SYMBOL(llog_cat_add_rec);
370 int llog_cat_declare_add_rec(const struct lu_env *env,
371 struct llog_handle *cathandle,
372 struct llog_rec_hdr *rec, struct thandle *th)
374 struct llog_handle *loghandle, *next;
377 if (cathandle->u.chd.chd_current_log == NULL) {
378 /* declare new plain llog */
379 down_write(&cathandle->lgh_lock);
380 if (cathandle->u.chd.chd_current_log == NULL) {
381 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
382 NULL, NULL, LLOG_OPEN_NEW);
384 cathandle->u.chd.chd_current_log = loghandle;
385 list_add_tail(&loghandle->u.phd.phd_entry,
386 &cathandle->u.chd.chd_head);
389 up_write(&cathandle->lgh_lock);
390 } else if (cathandle->u.chd.chd_next_log == NULL) {
391 /* declare next plain llog */
392 down_write(&cathandle->lgh_lock);
393 if (cathandle->u.chd.chd_next_log == NULL) {
394 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
395 NULL, NULL, LLOG_OPEN_NEW);
397 cathandle->u.chd.chd_next_log = loghandle;
398 list_add_tail(&loghandle->u.phd.phd_entry,
399 &cathandle->u.chd.chd_head);
402 up_write(&cathandle->lgh_lock);
407 if (!llog_exist(cathandle->u.chd.chd_current_log)) {
408 rc = llog_declare_create(env, cathandle->u.chd.chd_current_log,
412 llog_declare_write_rec(env, cathandle, NULL, -1, th);
414 /* declare records in the llogs */
415 rc = llog_declare_write_rec(env, cathandle->u.chd.chd_current_log,
420 next = cathandle->u.chd.chd_next_log;
422 if (!llog_exist(next)) {
423 rc = llog_declare_create(env, next, th);
424 llog_declare_write_rec(env, cathandle, NULL, -1, th);
426 llog_declare_write_rec(env, next, rec, -1, th);
431 EXPORT_SYMBOL(llog_cat_declare_add_rec);
433 int llog_cat_add(const struct lu_env *env, struct llog_handle *cathandle,
434 struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
437 struct llog_ctxt *ctxt;
438 struct dt_device *dt;
439 struct thandle *th = NULL;
442 ctxt = cathandle->lgh_ctxt;
444 LASSERT(ctxt->loc_exp);
446 if (cathandle->lgh_obj != NULL) {
447 dt = ctxt->loc_exp->exp_obd->obd_lvfs_ctxt.dt;
450 th = dt_trans_create(env, dt);
454 rc = llog_cat_declare_add_rec(env, cathandle, rec, th);
458 rc = dt_trans_start_local(env, dt, th);
461 rc = llog_cat_add_rec(env, cathandle, rec, reccookie, buf, th);
463 dt_trans_stop(env, dt, th);
464 } else { /* lvfs compat code */
465 LASSERT(cathandle->lgh_file != NULL);
466 rc = llog_cat_declare_add_rec(env, cathandle, rec, th);
468 rc = llog_cat_add_rec(env, cathandle, rec, reccookie,
473 EXPORT_SYMBOL(llog_cat_add);
475 /* For each cookie in the cookie array, we clear the log in-use bit and either:
476 * - the log is empty, so mark it free in the catalog header and delete it
477 * - the log is not empty, just write out the log header
479 * The cookies may be in different log files, so we need to get new logs
482 * Assumes caller has already pushed us into the kernel context.
484 int llog_cat_cancel_records(const struct lu_env *env,
485 struct llog_handle *cathandle, int count,
486 struct llog_cookie *cookies)
488 int i, index, rc = 0, failed = 0;
490 for (i = 0; i < count; i++, cookies++) {
491 struct llog_handle *loghandle;
492 struct llog_logid *lgl = &cookies->lgc_lgl;
495 rc = llog_cat_id2handle(env, cathandle, &loghandle, lgl);
497 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
498 cathandle->lgh_ctxt->loc_obd->obd_name,
499 POSTID(&lgl->lgl_oi), rc);
504 lrc = llog_cancel_rec(env, loghandle, cookies->lgc_index);
505 if (lrc == 1) { /* log has been destroyed */
506 index = loghandle->u.phd.phd_cookie.lgc_index;
507 rc = llog_cat_cleanup(env, cathandle, loghandle,
509 } else if (lrc == -ENOENT) {
510 if (rc == 0) /* ENOENT shouldn't rewrite any error */
512 } else if (lrc < 0) {
516 llog_handle_put(loghandle);
519 CERROR("%s: fail to cancel %d of %d llog-records: rc = %d\n",
520 cathandle->lgh_ctxt->loc_obd->obd_name, failed, count,
525 EXPORT_SYMBOL(llog_cat_cancel_records);
527 static int llog_cat_process_cb(const struct lu_env *env,
528 struct llog_handle *cat_llh,
529 struct llog_rec_hdr *rec, void *data)
531 struct llog_process_data *d = data;
532 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
533 struct llog_handle *llh;
536 if (rec->lrh_type != LLOG_LOGID_MAGIC) {
537 CERROR("invalid record in catalog\n");
540 CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
541 DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
542 rec->lrh_index, POSTID(&cat_llh->lgh_id.lgl_oi));
544 rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
546 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
547 cat_llh->lgh_ctxt->loc_obd->obd_name,
548 POSTID(&lir->lid_id.lgl_oi), rc);
552 if (rec->lrh_index < d->lpd_startcat)
553 /* Skip processing of the logs until startcat */
555 else if (d->lpd_startidx > 0) {
556 struct llog_process_cat_data cd;
558 cd.lpcd_first_idx = d->lpd_startidx;
559 cd.lpcd_last_idx = 0;
560 rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
562 /* Continue processing the next log from idx 0 */
565 rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
569 llog_handle_put(llh);
574 int llog_cat_process_or_fork(const struct lu_env *env,
575 struct llog_handle *cat_llh,
576 llog_cb_t cb, void *data, int startcat,
577 int startidx, bool fork)
579 struct llog_process_data d;
580 struct llog_log_hdr *llh = cat_llh->lgh_hdr;
583 LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
586 d.lpd_startcat = startcat;
587 d.lpd_startidx = startidx;
589 if (llh->llh_cat_idx > cat_llh->lgh_last_idx) {
590 struct llog_process_cat_data cd;
592 CWARN("catlog "DOSTID" crosses index zero\n",
593 POSTID(&cat_llh->lgh_id.lgl_oi));
595 cd.lpcd_first_idx = llh->llh_cat_idx;
596 cd.lpcd_last_idx = 0;
597 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
602 cd.lpcd_first_idx = 0;
603 cd.lpcd_last_idx = cat_llh->lgh_last_idx;
604 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
607 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
613 EXPORT_SYMBOL(llog_cat_process_or_fork);
615 int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
616 llog_cb_t cb, void *data, int startcat, int startidx)
618 return llog_cat_process_or_fork(env, cat_llh, cb, data, startcat,
621 EXPORT_SYMBOL(llog_cat_process);
623 static int llog_cat_reverse_process_cb(const struct lu_env *env,
624 struct llog_handle *cat_llh,
625 struct llog_rec_hdr *rec, void *data)
627 struct llog_process_data *d = data;
628 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
629 struct llog_handle *llh;
632 if (le32_to_cpu(rec->lrh_type) != LLOG_LOGID_MAGIC) {
633 CERROR("invalid record in catalog\n");
636 CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
637 DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
638 le32_to_cpu(rec->lrh_index), POSTID(&cat_llh->lgh_id.lgl_oi));
640 rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
642 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
643 cat_llh->lgh_ctxt->loc_obd->obd_name,
644 POSTID(&lir->lid_id.lgl_oi), rc);
648 rc = llog_reverse_process(env, llh, d->lpd_cb, d->lpd_data, NULL);
649 llog_handle_put(llh);
653 int llog_cat_reverse_process(const struct lu_env *env,
654 struct llog_handle *cat_llh,
655 llog_cb_t cb, void *data)
657 struct llog_process_data d;
658 struct llog_process_cat_data cd;
659 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 static 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;
698 bitmap_size = LLOG_BITMAP_SIZE(llh);
699 if (llh->llh_cat_idx == (index - 1)) {
700 idx = llh->llh_cat_idx + 1;
701 llh->llh_cat_idx = idx;
702 if (idx == cathandle->lgh_last_idx)
704 for (i = (index + 1) % bitmap_size;
705 i != cathandle->lgh_last_idx;
706 i = (i + 1) % bitmap_size) {
707 if (!ext2_test_bit(i, llh->llh_bitmap)) {
708 idx = llh->llh_cat_idx + 1;
709 llh->llh_cat_idx = idx;
711 llh->llh_cat_idx = 0;
717 CDEBUG(D_RPCTRACE, "set catlog "DOSTID" first idx %u\n",
718 POSTID(&cathandle->lgh_id.lgl_oi), llh->llh_cat_idx);
724 /* Cleanup deleted plain llog traces from catalog */
725 int llog_cat_cleanup(const struct lu_env *env, struct llog_handle *cathandle,
726 struct llog_handle *loghandle, int index)
731 if (loghandle != NULL) {
732 /* remove destroyed llog from catalog list and
733 * chd_current_log variable */
734 down_write(&cathandle->lgh_lock);
735 if (cathandle->u.chd.chd_current_log == loghandle)
736 cathandle->u.chd.chd_current_log = NULL;
737 list_del_init(&loghandle->u.phd.phd_entry);
738 up_write(&cathandle->lgh_lock);
739 LASSERT(index == loghandle->u.phd.phd_cookie.lgc_index);
740 /* llog was opened and keep in a list, close it now */
741 llog_close(env, loghandle);
743 /* remove plain llog entry from catalog by index */
744 llog_cat_set_first_idx(cathandle, index);
745 rc = llog_cancel_rec(env, cathandle, index);
747 CDEBUG(D_HA, "cancel plain log at index %u of catalog " DOSTID "\n",
748 index, POSTID(&cathandle->lgh_id.lgl_oi));
752 static int cat_cancel_cb(const struct lu_env *env, struct llog_handle *cathandle,
753 struct llog_rec_hdr *rec, void *data)
755 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
756 struct llog_handle *loghandle;
757 struct llog_log_hdr *llh;
760 if (rec->lrh_type != LLOG_LOGID_MAGIC) {
761 CERROR("invalid record in catalog\n");
765 CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
766 DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
767 rec->lrh_index, POSTID(&cathandle->lgh_id.lgl_oi));
769 rc = llog_cat_id2handle(env, cathandle, &loghandle, &lir->lid_id);
771 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
772 cathandle->lgh_ctxt->loc_obd->obd_name,
773 POSTID(&lir->lid_id.lgl_oi), rc);
774 if (rc == -ENOENT || rc == -ESTALE) {
775 /* remove index from catalog */
776 llog_cat_cleanup(env, cathandle, NULL, rec->lrh_index);
781 llh = loghandle->lgh_hdr;
782 if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
783 (llh->llh_count == 1)) {
784 rc = llog_destroy(env, loghandle);
786 CERROR("%s: fail to destroy empty log: rc = %d\n",
787 loghandle->lgh_ctxt->loc_obd->obd_name, rc);
789 llog_cat_cleanup(env, cathandle, loghandle,
790 loghandle->u.phd.phd_cookie.lgc_index);
792 llog_handle_put(loghandle);
797 /* helper to initialize catalog llog and process it to cancel */
798 int llog_cat_init_and_process(const struct lu_env *env,
799 struct llog_handle *llh)
803 rc = llog_init_handle(env, llh, LLOG_F_IS_CAT, NULL);
807 rc = llog_process_or_fork(env, llh, cat_cancel_cb, NULL, NULL, false);
809 CERROR("%s: llog_process() with cat_cancel_cb failed: rc = %d\n",
810 llh->lgh_ctxt->loc_obd->obd_name, rc);
813 EXPORT_SYMBOL(llog_cat_init_and_process);