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, 2014, 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 <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,
66 struct llog_thread_info *lgi = llog_info(env);
67 struct llog_logid_rec *rec = &lgi->lgi_logid;
72 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_LLOG_CREATE_FAILED))
75 rc = llog_create(env, loghandle, th);
76 /* if llog is already created, no need to initialize it */
80 CERROR("%s: can't create new plain llog in catalog: rc = %d\n",
81 loghandle->lgh_ctxt->loc_obd->obd_name, rc);
85 rc = llog_init_handle(env, loghandle,
86 LLOG_F_IS_PLAIN | LLOG_F_ZAP_WHEN_EMPTY,
87 &cathandle->lgh_hdr->llh_tgtuuid);
89 GOTO(out_destroy, rc);
91 /* build the record for this log in the catalog */
92 rec->lid_hdr.lrh_len = sizeof(*rec);
93 rec->lid_hdr.lrh_type = LLOG_LOGID_MAGIC;
94 rec->lid_id = loghandle->lgh_id;
96 /* append the new record into catalog. The new index will be
97 * assigned to the record and updated in rec header */
98 rc = llog_write_rec(env, cathandle, &rec->lid_hdr,
99 &loghandle->u.phd.phd_cookie, LLOG_NEXT_IDX, th);
101 GOTO(out_destroy, rc);
103 CDEBUG(D_OTHER, "new recovery log "DOSTID":%x for index %u of catalog"
104 DOSTID"\n", POSTID(&loghandle->lgh_id.lgl_oi),
105 loghandle->lgh_id.lgl_ogen, rec->lid_hdr.lrh_index,
106 POSTID(&cathandle->lgh_id.lgl_oi));
108 loghandle->lgh_hdr->llh_cat_idx = rec->lid_hdr.lrh_index;
111 llog_destroy(env, loghandle);
115 /* Open an existent log handle and add it to the open list.
116 * This log handle will be closed when all of the records in it are removed.
118 * Assumes caller has already pushed us into the kernel context and is locking.
119 * We return a lock on the handle to ensure nobody yanks it from us.
121 * This takes extra reference on llog_handle via llog_handle_get() and require
122 * this reference to be put by caller using llog_handle_put()
124 int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
125 struct llog_handle **res, struct llog_logid *logid)
127 struct llog_handle *loghandle;
133 if (cathandle == NULL)
136 fmt = cathandle->lgh_hdr->llh_flags & LLOG_F_EXT_MASK;
137 down_write(&cathandle->lgh_lock);
138 list_for_each_entry(loghandle, &cathandle->u.chd.chd_head,
140 struct llog_logid *cgl = &loghandle->lgh_id;
142 if (ostid_id(&cgl->lgl_oi) == ostid_id(&logid->lgl_oi) &&
143 ostid_seq(&cgl->lgl_oi) == ostid_seq(&logid->lgl_oi)) {
144 if (cgl->lgl_ogen != logid->lgl_ogen) {
145 CERROR("%s: log "DOSTID" generation %x != %x\n",
146 loghandle->lgh_ctxt->loc_obd->obd_name,
147 POSTID(&logid->lgl_oi), cgl->lgl_ogen,
151 loghandle->u.phd.phd_cat_handle = cathandle;
152 up_write(&cathandle->lgh_lock);
156 up_write(&cathandle->lgh_lock);
158 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle, logid, NULL,
161 CERROR("%s: error opening log id "DOSTID":%x: rc = %d\n",
162 cathandle->lgh_ctxt->loc_obd->obd_name,
163 POSTID(&logid->lgl_oi), logid->lgl_ogen, rc);
167 rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN | fmt, NULL);
169 llog_close(env, loghandle);
174 down_write(&cathandle->lgh_lock);
175 list_add_tail(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head);
176 up_write(&cathandle->lgh_lock);
178 loghandle->u.phd.phd_cat_handle = cathandle;
179 loghandle->u.phd.phd_cookie.lgc_lgl = cathandle->lgh_id;
180 loghandle->u.phd.phd_cookie.lgc_index =
181 loghandle->lgh_hdr->llh_cat_idx;
184 llog_handle_get(loghandle);
189 int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle)
191 struct llog_handle *loghandle, *n;
196 list_for_each_entry_safe(loghandle, n, &cathandle->u.chd.chd_head,
198 struct llog_log_hdr *llh = loghandle->lgh_hdr;
201 /* unlink open-not-created llogs */
202 list_del_init(&loghandle->u.phd.phd_entry);
203 llh = loghandle->lgh_hdr;
204 if (loghandle->lgh_obj != NULL && llh != NULL &&
205 (llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
206 (llh->llh_count == 1)) {
207 rc = llog_destroy(env, loghandle);
209 CERROR("%s: failure destroying log during "
210 "cleanup: rc = %d\n",
211 loghandle->lgh_ctxt->loc_obd->obd_name,
214 index = loghandle->u.phd.phd_cookie.lgc_index;
215 llog_cat_cleanup(env, cathandle, NULL, index);
217 llog_close(env, loghandle);
219 /* if handle was stored in ctxt, remove it too */
220 if (cathandle->lgh_ctxt->loc_handle == cathandle)
221 cathandle->lgh_ctxt->loc_handle = NULL;
222 rc = llog_close(env, cathandle);
225 EXPORT_SYMBOL(llog_cat_close);
228 * lockdep markers for nested struct llog_handle::lgh_lock locking.
235 /** Return the currently active log handle. If the current log handle doesn't
236 * have enough space left for the current record, start a new one.
238 * If reclen is 0, we only want to know what the currently active log is,
239 * otherwise we get a lock on this log so nobody can steal our space.
241 * Assumes caller has already pushed us into the kernel context and is locking.
243 * NOTE: loghandle is write-locked upon successful return
245 static struct llog_handle *llog_cat_current_log(struct llog_handle *cathandle,
248 struct llog_handle *loghandle = NULL;
251 down_read_nested(&cathandle->lgh_lock, LLOGH_CAT);
252 loghandle = cathandle->u.chd.chd_current_log;
254 struct llog_log_hdr *llh;
256 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
257 llh = loghandle->lgh_hdr;
259 loghandle->lgh_last_idx < LLOG_BITMAP_SIZE(llh) - 1) {
260 up_read(&cathandle->lgh_lock);
263 up_write(&loghandle->lgh_lock);
266 up_read(&cathandle->lgh_lock);
268 /* time to use next log */
270 /* first, we have to make sure the state hasn't changed */
271 down_write_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 if (loghandle->lgh_last_idx < LLOG_BITMAP_SIZE(llh) - 1) {
280 up_write(&cathandle->lgh_lock);
283 up_write(&loghandle->lgh_lock);
287 CDEBUG(D_INODE, "use next log\n");
289 loghandle = cathandle->u.chd.chd_next_log;
290 cathandle->u.chd.chd_current_log = loghandle;
291 cathandle->u.chd.chd_next_log = NULL;
292 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
293 up_write(&cathandle->lgh_lock);
298 /* Add a single record to the recovery log(s) using a catalog
299 * Returns as llog_write_record
301 * Assumes caller has already pushed us into the kernel context.
303 int llog_cat_add_rec(const struct lu_env *env, struct llog_handle *cathandle,
304 struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
307 struct llog_handle *loghandle;
311 LASSERT(rec->lrh_len <= LLOG_CHUNK_SIZE);
312 loghandle = llog_cat_current_log(cathandle, th);
313 LASSERT(!IS_ERR(loghandle));
315 /* loghandle is already locked by llog_cat_current_log() for us */
316 if (!llog_exist(loghandle)) {
317 rc = llog_cat_new_log(env, cathandle, loghandle, th);
319 up_write(&loghandle->lgh_lock);
323 /* now let's try to add the record */
324 rc = llog_write_rec(env, loghandle, rec, reccookie, LLOG_NEXT_IDX, th);
326 CDEBUG_LIMIT(rc == -ENOSPC ? D_HA : D_ERROR,
327 "llog_write_rec %d: lh=%p\n", rc, loghandle);
328 up_write(&loghandle->lgh_lock);
330 /* try to use next log */
331 loghandle = llog_cat_current_log(cathandle, th);
332 LASSERT(!IS_ERR(loghandle));
333 /* new llog can be created concurrently */
334 if (!llog_exist(loghandle)) {
335 rc = llog_cat_new_log(env, cathandle, loghandle, th);
337 up_write(&loghandle->lgh_lock);
341 /* now let's try to add the record */
342 rc = llog_write_rec(env, loghandle, rec, reccookie,
345 CERROR("llog_write_rec %d: lh=%p\n", rc, loghandle);
346 up_write(&loghandle->lgh_lock);
351 EXPORT_SYMBOL(llog_cat_add_rec);
353 int llog_cat_declare_add_rec(const struct lu_env *env,
354 struct llog_handle *cathandle,
355 struct llog_rec_hdr *rec, struct thandle *th)
357 struct llog_thread_info *lgi = llog_info(env);
358 struct llog_logid_rec *lirec = &lgi->lgi_logid;
359 struct llog_handle *loghandle, *next;
364 if (cathandle->u.chd.chd_current_log == NULL) {
365 /* declare new plain llog */
366 down_write(&cathandle->lgh_lock);
367 if (cathandle->u.chd.chd_current_log == NULL) {
368 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
369 NULL, NULL, LLOG_OPEN_NEW);
371 cathandle->u.chd.chd_current_log = loghandle;
372 list_add_tail(&loghandle->u.phd.phd_entry,
373 &cathandle->u.chd.chd_head);
376 up_write(&cathandle->lgh_lock);
377 } else if (cathandle->u.chd.chd_next_log == NULL) {
378 /* declare next plain llog */
379 down_write(&cathandle->lgh_lock);
380 if (cathandle->u.chd.chd_next_log == NULL) {
381 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
382 NULL, NULL, LLOG_OPEN_NEW);
384 cathandle->u.chd.chd_next_log = loghandle;
385 list_add_tail(&loghandle->u.phd.phd_entry,
386 &cathandle->u.chd.chd_head);
389 up_write(&cathandle->lgh_lock);
394 lirec->lid_hdr.lrh_len = sizeof(*lirec);
396 if (!llog_exist(cathandle->u.chd.chd_current_log)) {
397 rc = llog_declare_create(env, cathandle->u.chd.chd_current_log,
401 llog_declare_write_rec(env, cathandle, &lirec->lid_hdr, -1, th);
403 /* declare records in the llogs */
404 rc = llog_declare_write_rec(env, cathandle->u.chd.chd_current_log,
409 next = cathandle->u.chd.chd_next_log;
411 if (!llog_exist(next)) {
412 rc = llog_declare_create(env, next, th);
413 llog_declare_write_rec(env, cathandle, &lirec->lid_hdr,
416 /* XXX: we hope for declarations made for existing llog
417 * this might be not correct with some backends
418 * where declarations are expected against specific
419 * object like ZFS with full debugging enabled */
420 /*llog_declare_write_rec(env, next, rec, -1, th);*/
425 EXPORT_SYMBOL(llog_cat_declare_add_rec);
427 int llog_cat_add(const struct lu_env *env, struct llog_handle *cathandle,
428 struct llog_rec_hdr *rec, struct llog_cookie *reccookie)
430 struct llog_ctxt *ctxt;
431 struct dt_device *dt;
432 struct thandle *th = NULL;
435 ctxt = cathandle->lgh_ctxt;
437 LASSERT(ctxt->loc_exp);
439 LASSERT(cathandle->lgh_obj != NULL);
440 dt = lu2dt_dev(cathandle->lgh_obj->do_lu.lo_dev);
442 th = dt_trans_create(env, dt);
446 rc = llog_cat_declare_add_rec(env, cathandle, rec, th);
450 rc = dt_trans_start_local(env, dt, th);
453 rc = llog_cat_add_rec(env, cathandle, rec, reccookie, th);
455 dt_trans_stop(env, dt, th);
458 EXPORT_SYMBOL(llog_cat_add);
460 /* For each cookie in the cookie array, we clear the log in-use bit and either:
461 * - the log is empty, so mark it free in the catalog header and delete it
462 * - the log is not empty, just write out the log header
464 * The cookies may be in different log files, so we need to get new logs
467 * Assumes caller has already pushed us into the kernel context.
469 int llog_cat_cancel_records(const struct lu_env *env,
470 struct llog_handle *cathandle, int count,
471 struct llog_cookie *cookies)
473 int i, index, rc = 0, failed = 0;
477 for (i = 0; i < count; i++, cookies++) {
478 struct llog_handle *loghandle;
479 struct llog_logid *lgl = &cookies->lgc_lgl;
482 rc = llog_cat_id2handle(env, cathandle, &loghandle, lgl);
484 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
485 cathandle->lgh_ctxt->loc_obd->obd_name,
486 POSTID(&lgl->lgl_oi), rc);
491 lrc = llog_cancel_rec(env, loghandle, cookies->lgc_index);
492 if (lrc == LLOG_DEL_PLAIN) { /* log has been destroyed */
493 index = loghandle->u.phd.phd_cookie.lgc_index;
494 rc = llog_cat_cleanup(env, cathandle, loghandle,
496 } else if (lrc == -ENOENT) {
497 if (rc == 0) /* ENOENT shouldn't rewrite any error */
499 } else if (lrc < 0) {
503 llog_handle_put(loghandle);
506 CERROR("%s: fail to cancel %d of %d llog-records: rc = %d\n",
507 cathandle->lgh_ctxt->loc_obd->obd_name, failed, count,
512 EXPORT_SYMBOL(llog_cat_cancel_records);
514 static int llog_cat_process_cb(const struct lu_env *env,
515 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;
521 struct llog_log_hdr *hdr;
525 if (rec->lrh_type != LLOG_LOGID_MAGIC) {
526 CERROR("invalid record in catalog\n");
529 CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
530 DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
531 rec->lrh_index, POSTID(&cat_llh->lgh_id.lgl_oi));
533 rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
535 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
536 cat_llh->lgh_ctxt->loc_obd->obd_name,
537 POSTID(&lir->lid_id.lgl_oi), rc);
538 if (rc == -ENOENT || rc == -ESTALE) {
539 /* After a server crash, a stub of index
540 * record in catlog could be kept, because
541 * plain log destroy + catlog index record
542 * deletion are not atomic. So we end up with
543 * an index but no actual record. Destroy the
544 * index and move on. */
545 rc = llog_cat_cleanup(env, cat_llh, NULL,
552 /* clean old empty llogs, do not consider current llog in use */
553 /* ignore remote (lgh_obj=NULL) llogs */
555 if ((hdr->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
556 hdr->llh_count == 1 && cat_llh->lgh_obj != NULL &&
557 llh != cat_llh->u.chd.chd_current_log) {
558 rc = llog_destroy(env, llh);
560 CERROR("%s: fail to destroy empty log: rc = %d\n",
561 llh->lgh_ctxt->loc_obd->obd_name, rc);
562 GOTO(out, rc = LLOG_DEL_PLAIN);
565 if (rec->lrh_index < d->lpd_startcat) {
566 /* Skip processing of the logs until startcat */
568 } else if (d->lpd_startidx > 0) {
569 struct llog_process_cat_data cd;
571 cd.lpcd_first_idx = d->lpd_startidx;
572 cd.lpcd_last_idx = 0;
573 rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
575 /* Continue processing the next log from idx 0 */
578 rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
583 /* The empty plain log was destroyed while processing */
584 if (rc == LLOG_DEL_PLAIN)
585 rc = llog_cat_cleanup(env, cat_llh, llh,
586 llh->u.phd.phd_cookie.lgc_index);
587 llog_handle_put(llh);
592 int llog_cat_process_or_fork(const struct lu_env *env,
593 struct llog_handle *cat_llh,
594 llog_cb_t cb, void *data, int startcat,
595 int startidx, bool fork)
597 struct llog_process_data d;
598 struct llog_log_hdr *llh = cat_llh->lgh_hdr;
602 LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
605 d.lpd_startcat = startcat;
606 d.lpd_startidx = startidx;
608 if (llh->llh_cat_idx > cat_llh->lgh_last_idx) {
609 struct llog_process_cat_data cd;
611 CWARN("catlog "DOSTID" crosses index zero\n",
612 POSTID(&cat_llh->lgh_id.lgl_oi));
614 cd.lpcd_first_idx = llh->llh_cat_idx;
615 cd.lpcd_last_idx = 0;
616 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
621 cd.lpcd_first_idx = 0;
622 cd.lpcd_last_idx = cat_llh->lgh_last_idx;
623 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
626 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
633 int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
634 llog_cb_t cb, void *data, int startcat, int startidx)
636 return llog_cat_process_or_fork(env, cat_llh, cb, data, startcat,
639 EXPORT_SYMBOL(llog_cat_process);
641 static int llog_cat_reverse_process_cb(const struct lu_env *env,
642 struct llog_handle *cat_llh,
643 struct llog_rec_hdr *rec, void *data)
645 struct llog_process_data *d = data;
646 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
647 struct llog_handle *llh;
648 struct llog_log_hdr *hdr;
651 if (le32_to_cpu(rec->lrh_type) != LLOG_LOGID_MAGIC) {
652 CERROR("invalid record in catalog\n");
655 CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
656 DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
657 le32_to_cpu(rec->lrh_index), POSTID(&cat_llh->lgh_id.lgl_oi));
659 rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
661 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
662 cat_llh->lgh_ctxt->loc_obd->obd_name,
663 POSTID(&lir->lid_id.lgl_oi), rc);
664 if (rc == -ENOENT || rc == -ESTALE) {
665 /* After a server crash, a stub of index
666 * record in catlog could be kept, because
667 * plain log destroy + catlog index record
668 * deletion are not atomic. So we end up with
669 * an index but no actual record. Destroy the
670 * index and move on. */
671 rc = llog_cat_cleanup(env, cat_llh, NULL,
678 /* clean old empty llogs, do not consider current llog in use */
680 if ((hdr->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
681 hdr->llh_count == 1 &&
682 llh != cat_llh->u.chd.chd_current_log) {
683 rc = llog_destroy(env, llh);
685 CERROR("%s: fail to destroy empty log: rc = %d\n",
686 llh->lgh_ctxt->loc_obd->obd_name, rc);
687 GOTO(out, rc = LLOG_DEL_PLAIN);
690 rc = llog_reverse_process(env, llh, d->lpd_cb, d->lpd_data, NULL);
693 /* The empty plain was destroyed while processing */
694 if (rc == LLOG_DEL_PLAIN)
695 rc = llog_cat_cleanup(env, cat_llh, llh,
696 llh->u.phd.phd_cookie.lgc_index);
698 llog_handle_put(llh);
702 int llog_cat_reverse_process(const struct lu_env *env,
703 struct llog_handle *cat_llh,
704 llog_cb_t cb, void *data)
706 struct llog_process_data d;
707 struct llog_process_cat_data cd;
708 struct llog_log_hdr *llh = cat_llh->lgh_hdr;
712 LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
716 if (llh->llh_cat_idx > cat_llh->lgh_last_idx) {
717 CWARN("catalog "DOSTID" crosses index zero\n",
718 POSTID(&cat_llh->lgh_id.lgl_oi));
720 cd.lpcd_first_idx = 0;
721 cd.lpcd_last_idx = cat_llh->lgh_last_idx;
722 rc = llog_reverse_process(env, cat_llh,
723 llog_cat_reverse_process_cb,
728 cd.lpcd_first_idx = le32_to_cpu(llh->llh_cat_idx);
729 cd.lpcd_last_idx = 0;
730 rc = llog_reverse_process(env, cat_llh,
731 llog_cat_reverse_process_cb,
734 rc = llog_reverse_process(env, cat_llh,
735 llog_cat_reverse_process_cb,
741 EXPORT_SYMBOL(llog_cat_reverse_process);
743 static int llog_cat_set_first_idx(struct llog_handle *cathandle, int index)
745 struct llog_log_hdr *llh = cathandle->lgh_hdr;
746 int i, bitmap_size, idx;
749 bitmap_size = LLOG_BITMAP_SIZE(llh);
750 if (llh->llh_cat_idx == (index - 1)) {
751 idx = llh->llh_cat_idx + 1;
752 llh->llh_cat_idx = idx;
753 if (idx == cathandle->lgh_last_idx)
755 for (i = (index + 1) % bitmap_size;
756 i != cathandle->lgh_last_idx;
757 i = (i + 1) % bitmap_size) {
758 if (!ext2_test_bit(i, llh->llh_bitmap)) {
759 idx = llh->llh_cat_idx + 1;
760 llh->llh_cat_idx = idx;
762 llh->llh_cat_idx = 0;
768 CDEBUG(D_RPCTRACE, "set catlog "DOSTID" first idx %u\n",
769 POSTID(&cathandle->lgh_id.lgl_oi), llh->llh_cat_idx);
775 /* Cleanup deleted plain llog traces from catalog */
776 int llog_cat_cleanup(const struct lu_env *env, struct llog_handle *cathandle,
777 struct llog_handle *loghandle, int index)
782 if (loghandle != NULL) {
783 /* remove destroyed llog from catalog list and
784 * chd_current_log variable */
785 down_write(&cathandle->lgh_lock);
786 if (cathandle->u.chd.chd_current_log == loghandle)
787 cathandle->u.chd.chd_current_log = NULL;
788 list_del_init(&loghandle->u.phd.phd_entry);
789 up_write(&cathandle->lgh_lock);
790 LASSERT(index == loghandle->u.phd.phd_cookie.lgc_index);
791 /* llog was opened and keep in a list, close it now */
792 llog_close(env, loghandle);
795 /* do not attempt to cleanup on-disk llog if on client side */
796 if (cathandle->lgh_obj == NULL)
799 /* remove plain llog entry from catalog by index */
800 llog_cat_set_first_idx(cathandle, index);
801 rc = llog_cancel_rec(env, cathandle, index);
803 CDEBUG(D_HA, "cancel plain log at index"
804 " %u of catalog "DOSTID"\n",
805 index, POSTID(&cathandle->lgh_id.lgl_oi));
809 /* helper to initialize catalog llog and process it to cancel */
810 int llog_cat_init_and_process(const struct lu_env *env,
811 struct llog_handle *llh)
815 rc = llog_init_handle(env, llh, LLOG_F_IS_CAT, NULL);
821 EXPORT_SYMBOL(llog_cat_init_and_process);