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 if (loghandle->lgh_hdr != NULL) {
76 /* If llog object is remote and creation is failed, lgh_hdr
77 * might be left over here, free it first */
78 LASSERT(!llog_exist(loghandle));
79 OBD_FREE_PTR(loghandle->lgh_hdr);
80 loghandle->lgh_hdr = NULL;
83 rc = llog_create(env, loghandle, th);
84 /* if llog is already created, no need to initialize it */
88 CERROR("%s: can't create new plain llog in catalog: rc = %d\n",
89 loghandle->lgh_ctxt->loc_obd->obd_name, rc);
93 rc = llog_init_handle(env, loghandle,
94 LLOG_F_IS_PLAIN | LLOG_F_ZAP_WHEN_EMPTY,
95 &cathandle->lgh_hdr->llh_tgtuuid);
97 GOTO(out_destroy, rc);
99 /* build the record for this log in the catalog */
100 rec->lid_hdr.lrh_len = sizeof(*rec);
101 rec->lid_hdr.lrh_type = LLOG_LOGID_MAGIC;
102 rec->lid_id = loghandle->lgh_id;
104 /* append the new record into catalog. The new index will be
105 * assigned to the record and updated in rec header */
106 rc = llog_write_rec(env, cathandle, &rec->lid_hdr,
107 &loghandle->u.phd.phd_cookie, LLOG_NEXT_IDX, th);
109 GOTO(out_destroy, rc);
111 CDEBUG(D_OTHER, "new recovery log "DOSTID":%x for index %u of catalog"
112 DOSTID"\n", POSTID(&loghandle->lgh_id.lgl_oi),
113 loghandle->lgh_id.lgl_ogen, rec->lid_hdr.lrh_index,
114 POSTID(&cathandle->lgh_id.lgl_oi));
116 loghandle->lgh_hdr->llh_cat_idx = rec->lid_hdr.lrh_index;
119 llog_destroy(env, loghandle);
123 /* Open an existent log handle and add it to the open list.
124 * This log handle will be closed when all of the records in it are removed.
126 * Assumes caller has already pushed us into the kernel context and is locking.
127 * We return a lock on the handle to ensure nobody yanks it from us.
129 * This takes extra reference on llog_handle via llog_handle_get() and require
130 * this reference to be put by caller using llog_handle_put()
132 int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
133 struct llog_handle **res, struct llog_logid *logid)
135 struct llog_handle *loghandle;
141 if (cathandle == NULL)
144 fmt = cathandle->lgh_hdr->llh_flags & LLOG_F_EXT_MASK;
145 down_write(&cathandle->lgh_lock);
146 list_for_each_entry(loghandle, &cathandle->u.chd.chd_head,
148 struct llog_logid *cgl = &loghandle->lgh_id;
150 if (ostid_id(&cgl->lgl_oi) == ostid_id(&logid->lgl_oi) &&
151 ostid_seq(&cgl->lgl_oi) == ostid_seq(&logid->lgl_oi)) {
152 if (cgl->lgl_ogen != logid->lgl_ogen) {
153 CERROR("%s: log "DOSTID" generation %x != %x\n",
154 loghandle->lgh_ctxt->loc_obd->obd_name,
155 POSTID(&logid->lgl_oi), cgl->lgl_ogen,
159 loghandle->u.phd.phd_cat_handle = cathandle;
160 up_write(&cathandle->lgh_lock);
164 up_write(&cathandle->lgh_lock);
166 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle, logid, NULL,
169 CERROR("%s: error opening log id "DOSTID":%x: rc = %d\n",
170 cathandle->lgh_ctxt->loc_obd->obd_name,
171 POSTID(&logid->lgl_oi), logid->lgl_ogen, rc);
175 rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN | fmt, NULL);
177 llog_close(env, loghandle);
182 down_write(&cathandle->lgh_lock);
183 list_add_tail(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head);
184 up_write(&cathandle->lgh_lock);
186 loghandle->u.phd.phd_cat_handle = cathandle;
187 loghandle->u.phd.phd_cookie.lgc_lgl = cathandle->lgh_id;
188 loghandle->u.phd.phd_cookie.lgc_index =
189 loghandle->lgh_hdr->llh_cat_idx;
192 llog_handle_get(loghandle);
197 int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle)
199 struct llog_handle *loghandle, *n;
204 list_for_each_entry_safe(loghandle, n, &cathandle->u.chd.chd_head,
206 struct llog_log_hdr *llh = loghandle->lgh_hdr;
209 /* unlink open-not-created llogs */
210 list_del_init(&loghandle->u.phd.phd_entry);
211 llh = loghandle->lgh_hdr;
212 if (loghandle->lgh_obj != NULL && llh != NULL &&
213 (llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
214 (llh->llh_count == 1)) {
215 rc = llog_destroy(env, loghandle);
217 CERROR("%s: failure destroying log during "
218 "cleanup: rc = %d\n",
219 loghandle->lgh_ctxt->loc_obd->obd_name,
222 index = loghandle->u.phd.phd_cookie.lgc_index;
223 llog_cat_cleanup(env, cathandle, NULL, index);
225 llog_close(env, loghandle);
227 /* if handle was stored in ctxt, remove it too */
228 if (cathandle->lgh_ctxt->loc_handle == cathandle)
229 cathandle->lgh_ctxt->loc_handle = NULL;
230 rc = llog_close(env, cathandle);
233 EXPORT_SYMBOL(llog_cat_close);
236 * lockdep markers for nested struct llog_handle::lgh_lock locking.
243 /** Return the currently active log handle. If the current log handle doesn't
244 * have enough space left for the current record, start a new one.
246 * If reclen is 0, we only want to know what the currently active log is,
247 * otherwise we get a lock on this log so nobody can steal our space.
249 * Assumes caller has already pushed us into the kernel context and is locking.
251 * NOTE: loghandle is write-locked upon successful return
253 static struct llog_handle *llog_cat_current_log(struct llog_handle *cathandle,
256 struct llog_handle *loghandle = NULL;
259 down_read_nested(&cathandle->lgh_lock, LLOGH_CAT);
260 loghandle = cathandle->u.chd.chd_current_log;
262 struct llog_log_hdr *llh;
264 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
265 llh = loghandle->lgh_hdr;
267 loghandle->lgh_last_idx < LLOG_HDR_BITMAP_SIZE(llh) - 1) {
268 up_read(&cathandle->lgh_lock);
271 up_write(&loghandle->lgh_lock);
274 up_read(&cathandle->lgh_lock);
276 /* time to use next log */
278 /* first, we have to make sure the state hasn't changed */
279 down_write_nested(&cathandle->lgh_lock, LLOGH_CAT);
280 loghandle = cathandle->u.chd.chd_current_log;
282 struct llog_log_hdr *llh;
284 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
285 llh = loghandle->lgh_hdr;
287 if (loghandle->lgh_last_idx < LLOG_HDR_BITMAP_SIZE(llh) - 1) {
288 up_write(&cathandle->lgh_lock);
291 up_write(&loghandle->lgh_lock);
295 CDEBUG(D_INODE, "use next log\n");
297 loghandle = cathandle->u.chd.chd_next_log;
298 cathandle->u.chd.chd_current_log = loghandle;
299 cathandle->u.chd.chd_next_log = NULL;
300 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
301 up_write(&cathandle->lgh_lock);
306 /* Add a single record to the recovery log(s) using a catalog
307 * Returns as llog_write_record
309 * Assumes caller has already pushed us into the kernel context.
311 int llog_cat_add_rec(const struct lu_env *env, struct llog_handle *cathandle,
312 struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
315 struct llog_handle *loghandle;
319 LASSERT(rec->lrh_len <= cathandle->lgh_ctxt->loc_chunk_size);
320 loghandle = llog_cat_current_log(cathandle, th);
321 LASSERT(!IS_ERR(loghandle));
323 /* loghandle is already locked by llog_cat_current_log() for us */
324 if (!llog_exist(loghandle)) {
325 rc = llog_cat_new_log(env, cathandle, loghandle, th);
327 up_write(&loghandle->lgh_lock);
331 /* now let's try to add the record */
332 rc = llog_write_rec(env, loghandle, rec, reccookie, LLOG_NEXT_IDX, th);
334 CDEBUG_LIMIT(rc == -ENOSPC ? D_HA : D_ERROR,
335 "llog_write_rec %d: lh=%p\n", rc, loghandle);
336 up_write(&loghandle->lgh_lock);
338 /* try to use next log */
339 loghandle = llog_cat_current_log(cathandle, th);
340 LASSERT(!IS_ERR(loghandle));
341 /* new llog can be created concurrently */
342 if (!llog_exist(loghandle)) {
343 rc = llog_cat_new_log(env, cathandle, loghandle, th);
345 up_write(&loghandle->lgh_lock);
349 /* now let's try to add the record */
350 rc = llog_write_rec(env, loghandle, rec, reccookie,
353 CERROR("llog_write_rec %d: lh=%p\n", rc, loghandle);
354 up_write(&loghandle->lgh_lock);
359 EXPORT_SYMBOL(llog_cat_add_rec);
361 int llog_cat_declare_add_rec(const struct lu_env *env,
362 struct llog_handle *cathandle,
363 struct llog_rec_hdr *rec, struct thandle *th)
365 struct llog_thread_info *lgi = llog_info(env);
366 struct llog_logid_rec *lirec = &lgi->lgi_logid;
367 struct llog_handle *loghandle, *next;
372 if (cathandle->u.chd.chd_current_log == NULL) {
373 /* declare new plain llog */
374 down_write(&cathandle->lgh_lock);
375 if (cathandle->u.chd.chd_current_log == NULL) {
376 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
377 NULL, NULL, LLOG_OPEN_NEW);
379 cathandle->u.chd.chd_current_log = loghandle;
380 list_add_tail(&loghandle->u.phd.phd_entry,
381 &cathandle->u.chd.chd_head);
384 up_write(&cathandle->lgh_lock);
385 } else if (cathandle->u.chd.chd_next_log == NULL) {
386 /* declare next plain llog */
387 down_write(&cathandle->lgh_lock);
388 if (cathandle->u.chd.chd_next_log == NULL) {
389 rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
390 NULL, NULL, LLOG_OPEN_NEW);
392 cathandle->u.chd.chd_next_log = loghandle;
393 list_add_tail(&loghandle->u.phd.phd_entry,
394 &cathandle->u.chd.chd_head);
397 up_write(&cathandle->lgh_lock);
402 lirec->lid_hdr.lrh_len = sizeof(*lirec);
404 if (!llog_exist(cathandle->u.chd.chd_current_log)) {
405 rc = llog_declare_create(env, cathandle->u.chd.chd_current_log,
409 llog_declare_write_rec(env, cathandle, &lirec->lid_hdr, -1, th);
411 /* declare records in the llogs */
412 rc = llog_declare_write_rec(env, cathandle->u.chd.chd_current_log,
417 next = cathandle->u.chd.chd_next_log;
419 if (!llog_exist(next)) {
420 rc = llog_declare_create(env, next, th);
421 llog_declare_write_rec(env, cathandle, &lirec->lid_hdr,
424 /* XXX: we hope for declarations made for existing llog
425 * this might be not correct with some backends
426 * where declarations are expected against specific
427 * object like ZFS with full debugging enabled */
428 /*llog_declare_write_rec(env, next, rec, -1, th);*/
433 EXPORT_SYMBOL(llog_cat_declare_add_rec);
435 int llog_cat_add(const struct lu_env *env, struct llog_handle *cathandle,
436 struct llog_rec_hdr *rec, struct llog_cookie *reccookie)
438 struct llog_ctxt *ctxt;
439 struct dt_device *dt;
440 struct thandle *th = NULL;
443 ctxt = cathandle->lgh_ctxt;
445 LASSERT(ctxt->loc_exp);
447 LASSERT(cathandle->lgh_obj != NULL);
448 dt = lu2dt_dev(cathandle->lgh_obj->do_lu.lo_dev);
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, th);
463 dt_trans_stop(env, dt, th);
466 EXPORT_SYMBOL(llog_cat_add);
468 /* For each cookie in the cookie array, we clear the log in-use bit and either:
469 * - the log is empty, so mark it free in the catalog header and delete it
470 * - the log is not empty, just write out the log header
472 * The cookies may be in different log files, so we need to get new logs
475 * Assumes caller has already pushed us into the kernel context.
477 int llog_cat_cancel_records(const struct lu_env *env,
478 struct llog_handle *cathandle, int count,
479 struct llog_cookie *cookies)
481 int i, index, rc = 0, failed = 0;
485 for (i = 0; i < count; i++, cookies++) {
486 struct llog_handle *loghandle;
487 struct llog_logid *lgl = &cookies->lgc_lgl;
490 rc = llog_cat_id2handle(env, cathandle, &loghandle, lgl);
492 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
493 cathandle->lgh_ctxt->loc_obd->obd_name,
494 POSTID(&lgl->lgl_oi), rc);
499 lrc = llog_cancel_rec(env, loghandle, cookies->lgc_index);
500 if (lrc == LLOG_DEL_PLAIN) { /* log has been destroyed */
501 index = loghandle->u.phd.phd_cookie.lgc_index;
502 rc = llog_cat_cleanup(env, cathandle, loghandle,
504 } else if (lrc == -ENOENT) {
505 if (rc == 0) /* ENOENT shouldn't rewrite any error */
507 } else if (lrc < 0) {
511 llog_handle_put(loghandle);
514 CERROR("%s: fail to cancel %d of %d llog-records: rc = %d\n",
515 cathandle->lgh_ctxt->loc_obd->obd_name, failed, count,
520 EXPORT_SYMBOL(llog_cat_cancel_records);
522 static int llog_cat_process_cb(const struct lu_env *env,
523 struct llog_handle *cat_llh,
524 struct llog_rec_hdr *rec, void *data)
526 struct llog_process_data *d = data;
527 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
528 struct llog_handle *llh;
529 struct llog_log_hdr *hdr;
533 if (rec->lrh_type != LLOG_LOGID_MAGIC) {
534 CERROR("invalid record in catalog\n");
537 CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
538 DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
539 rec->lrh_index, POSTID(&cat_llh->lgh_id.lgl_oi));
541 rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
543 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
544 cat_llh->lgh_ctxt->loc_obd->obd_name,
545 POSTID(&lir->lid_id.lgl_oi), rc);
546 if (rc == -ENOENT || rc == -ESTALE) {
547 /* After a server crash, a stub of index
548 * record in catlog could be kept, because
549 * plain log destroy + catlog index record
550 * deletion are not atomic. So we end up with
551 * an index but no actual record. Destroy the
552 * index and move on. */
553 rc = llog_cat_cleanup(env, cat_llh, NULL,
560 /* clean old empty llogs, do not consider current llog in use */
561 /* ignore remote (lgh_obj=NULL) llogs */
563 if ((hdr->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
564 hdr->llh_count == 1 && cat_llh->lgh_obj != NULL &&
565 llh != cat_llh->u.chd.chd_current_log) {
566 rc = llog_destroy(env, llh);
568 CERROR("%s: fail to destroy empty log: rc = %d\n",
569 llh->lgh_ctxt->loc_obd->obd_name, rc);
570 GOTO(out, rc = LLOG_DEL_PLAIN);
573 if (rec->lrh_index < d->lpd_startcat) {
574 /* Skip processing of the logs until startcat */
576 } else if (d->lpd_startidx > 0) {
577 struct llog_process_cat_data cd;
579 cd.lpcd_first_idx = d->lpd_startidx;
580 cd.lpcd_last_idx = 0;
581 rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
583 /* Continue processing the next log from idx 0 */
586 rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
591 /* The empty plain log was destroyed while processing */
592 if (rc == LLOG_DEL_PLAIN)
593 rc = llog_cat_cleanup(env, cat_llh, llh,
594 llh->u.phd.phd_cookie.lgc_index);
595 llog_handle_put(llh);
600 int llog_cat_process_or_fork(const struct lu_env *env,
601 struct llog_handle *cat_llh,
602 llog_cb_t cb, void *data, int startcat,
603 int startidx, bool fork)
605 struct llog_process_data d;
606 struct llog_log_hdr *llh = cat_llh->lgh_hdr;
610 LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
613 d.lpd_startcat = startcat;
614 d.lpd_startidx = startidx;
616 if (llh->llh_cat_idx > cat_llh->lgh_last_idx) {
617 struct llog_process_cat_data cd;
619 CWARN("catlog "DOSTID" crosses index zero\n",
620 POSTID(&cat_llh->lgh_id.lgl_oi));
622 cd.lpcd_first_idx = llh->llh_cat_idx;
623 cd.lpcd_last_idx = 0;
624 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
629 cd.lpcd_first_idx = 0;
630 cd.lpcd_last_idx = cat_llh->lgh_last_idx;
631 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
634 rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
641 int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
642 llog_cb_t cb, void *data, int startcat, int startidx)
644 return llog_cat_process_or_fork(env, cat_llh, cb, data, startcat,
647 EXPORT_SYMBOL(llog_cat_process);
649 static int llog_cat_reverse_process_cb(const struct lu_env *env,
650 struct llog_handle *cat_llh,
651 struct llog_rec_hdr *rec, void *data)
653 struct llog_process_data *d = data;
654 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
655 struct llog_handle *llh;
656 struct llog_log_hdr *hdr;
659 if (le32_to_cpu(rec->lrh_type) != LLOG_LOGID_MAGIC) {
660 CERROR("invalid record in catalog\n");
663 CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
664 DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
665 le32_to_cpu(rec->lrh_index), POSTID(&cat_llh->lgh_id.lgl_oi));
667 rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
669 CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
670 cat_llh->lgh_ctxt->loc_obd->obd_name,
671 POSTID(&lir->lid_id.lgl_oi), rc);
672 if (rc == -ENOENT || rc == -ESTALE) {
673 /* After a server crash, a stub of index
674 * record in catlog could be kept, because
675 * plain log destroy + catlog index record
676 * deletion are not atomic. So we end up with
677 * an index but no actual record. Destroy the
678 * index and move on. */
679 rc = llog_cat_cleanup(env, cat_llh, NULL,
686 /* clean old empty llogs, do not consider current llog in use */
688 if ((hdr->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
689 hdr->llh_count == 1 &&
690 llh != cat_llh->u.chd.chd_current_log) {
691 rc = llog_destroy(env, llh);
693 CERROR("%s: fail to destroy empty log: rc = %d\n",
694 llh->lgh_ctxt->loc_obd->obd_name, rc);
695 GOTO(out, rc = LLOG_DEL_PLAIN);
698 rc = llog_reverse_process(env, llh, d->lpd_cb, d->lpd_data, NULL);
701 /* The empty plain was destroyed while processing */
702 if (rc == LLOG_DEL_PLAIN)
703 rc = llog_cat_cleanup(env, cat_llh, llh,
704 llh->u.phd.phd_cookie.lgc_index);
706 llog_handle_put(llh);
710 int llog_cat_reverse_process(const struct lu_env *env,
711 struct llog_handle *cat_llh,
712 llog_cb_t cb, void *data)
714 struct llog_process_data d;
715 struct llog_process_cat_data cd;
716 struct llog_log_hdr *llh = cat_llh->lgh_hdr;
720 LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
724 if (llh->llh_cat_idx > cat_llh->lgh_last_idx) {
725 CWARN("catalog "DOSTID" crosses index zero\n",
726 POSTID(&cat_llh->lgh_id.lgl_oi));
728 cd.lpcd_first_idx = 0;
729 cd.lpcd_last_idx = cat_llh->lgh_last_idx;
730 rc = llog_reverse_process(env, cat_llh,
731 llog_cat_reverse_process_cb,
736 cd.lpcd_first_idx = le32_to_cpu(llh->llh_cat_idx);
737 cd.lpcd_last_idx = 0;
738 rc = llog_reverse_process(env, cat_llh,
739 llog_cat_reverse_process_cb,
742 rc = llog_reverse_process(env, cat_llh,
743 llog_cat_reverse_process_cb,
749 EXPORT_SYMBOL(llog_cat_reverse_process);
751 static int llog_cat_set_first_idx(struct llog_handle *cathandle, int index)
753 struct llog_log_hdr *llh = cathandle->lgh_hdr;
754 int i, bitmap_size, idx;
757 bitmap_size = LLOG_HDR_BITMAP_SIZE(llh);
758 if (llh->llh_cat_idx == (index - 1)) {
759 idx = llh->llh_cat_idx + 1;
760 llh->llh_cat_idx = idx;
761 if (idx == cathandle->lgh_last_idx)
764 for (i = (index + 1) % bitmap_size;
765 i != cathandle->lgh_last_idx;
766 i = (i + 1) % bitmap_size) {
767 if (!ext2_test_bit(i, LLOG_HDR_BITMAP(llh))) {
768 idx = llh->llh_cat_idx + 1;
769 llh->llh_cat_idx = idx;
771 llh->llh_cat_idx = 0;
777 CDEBUG(D_RPCTRACE, "set catlog "DOSTID" first idx %u\n",
778 POSTID(&cathandle->lgh_id.lgl_oi), llh->llh_cat_idx);
784 /* Cleanup deleted plain llog traces from catalog */
785 int llog_cat_cleanup(const struct lu_env *env, struct llog_handle *cathandle,
786 struct llog_handle *loghandle, int index)
791 if (loghandle != NULL) {
792 /* remove destroyed llog from catalog list and
793 * chd_current_log variable */
794 down_write(&cathandle->lgh_lock);
795 if (cathandle->u.chd.chd_current_log == loghandle)
796 cathandle->u.chd.chd_current_log = NULL;
797 list_del_init(&loghandle->u.phd.phd_entry);
798 up_write(&cathandle->lgh_lock);
799 LASSERT(index == loghandle->u.phd.phd_cookie.lgc_index);
800 /* llog was opened and keep in a list, close it now */
801 llog_close(env, loghandle);
804 /* do not attempt to cleanup on-disk llog if on client side */
805 if (cathandle->lgh_obj == NULL)
808 /* remove plain llog entry from catalog by index */
809 llog_cat_set_first_idx(cathandle, index);
810 rc = llog_cancel_rec(env, cathandle, index);
812 CDEBUG(D_HA, "cancel plain log at index"
813 " %u of catalog "DOSTID"\n",
814 index, POSTID(&cathandle->lgh_id.lgl_oi));
818 /* helper to initialize catalog llog and process it to cancel */
819 int llog_cat_init_and_process(const struct lu_env *env,
820 struct llog_handle *llh)
824 rc = llog_init_handle(env, llh, LLOG_F_IS_CAT, NULL);
830 EXPORT_SYMBOL(llog_cat_init_and_process);