Whamcloud - gitweb
LU-4134 obdclass: obd_device improvement
[fs/lustre-release.git] / lustre / obdclass / llog_cat.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/obdclass/llog_cat.c
33  *
34  * OST<->MDS recovery logging infrastructure.
35  *
36  * Invariants in implementation:
37  * - we do not share logs among different OST<->MDS connections, so that
38  *   if an OST or MDS fails it need only look at log(s) relevant to itself
39  *
40  * Author: Andreas Dilger <adilger@clusterfs.com>
41  * Author: Alexey Zhuravlev <alexey.zhuravlev@intel.com>
42  * Author: Mikhail Pershin <mike.pershin@intel.com>
43  */
44
45 #define DEBUG_SUBSYSTEM S_LOG
46
47
48 #include <obd_class.h>
49
50 #include "llog_internal.h"
51
52 /* Create a new log handle and add it to the open list.
53  * This log handle will be closed when all of the records in it are removed.
54  *
55  * Assumes caller has already pushed us into the kernel context and is locking.
56  */
57 static int llog_cat_new_log(const struct lu_env *env,
58                             struct llog_handle *cathandle,
59                             struct llog_handle *loghandle,
60                             struct thandle *th)
61 {
62         struct llog_thread_info *lgi = llog_info(env);
63         struct llog_logid_rec   *rec = &lgi->lgi_logid;
64         struct thandle *handle = NULL;
65         struct dt_device *dt = NULL;
66         struct llog_log_hdr     *llh = cathandle->lgh_hdr;
67         int                      rc, index;
68
69         ENTRY;
70
71         index = (cathandle->lgh_last_idx + 1) %
72                 (OBD_FAIL_PRECHECK(OBD_FAIL_CAT_RECORDS) ? (cfs_fail_val + 1) :
73                                                 LLOG_HDR_BITMAP_SIZE(llh));
74
75         /* check that new llog index will not overlap with the first one.
76          * - llh_cat_idx is the index just before the first/oldest still in-use
77          *      index in catalog
78          * - lgh_last_idx is the last/newest used index in catalog
79          *
80          * When catalog is not wrapped yet then lgh_last_idx is always larger
81          * than llh_cat_idx. After the wrap around lgh_last_idx re-starts
82          * from 0 and llh_cat_idx becomes the upper limit for it
83          *
84          * Check if catalog has already wrapped around or not by comparing
85          * last_idx and cat_idx */
86         if ((index == llh->llh_cat_idx + 1 && llh->llh_count > 1) ||
87             (index == 0 && llh->llh_cat_idx == 0)) {
88                 if (cathandle->lgh_name == NULL) {
89                         CWARN("%s: there are no more free slots in catalog "
90                               DFID":%x\n",
91                               loghandle->lgh_ctxt->loc_obd->obd_name,
92                               PFID(&cathandle->lgh_id.lgl_oi.oi_fid),
93                               cathandle->lgh_id.lgl_ogen);
94                 } else {
95                         CWARN("%s: there are no more free slots in "
96                               "catalog %s\n",
97                               loghandle->lgh_ctxt->loc_obd->obd_name,
98                               cathandle->lgh_name);
99                 }
100                 RETURN(-ENOSPC);
101         }
102
103         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_LLOG_CREATE_FAILED))
104                 RETURN(-ENOSPC);
105
106         if (loghandle->lgh_hdr != NULL) {
107                 /* If llog object is remote and creation is failed, lgh_hdr
108                  * might be left over here, free it first */
109                 LASSERT(!llog_exist(loghandle));
110                 OBD_FREE_LARGE(loghandle->lgh_hdr, loghandle->lgh_hdr_size);
111                 loghandle->lgh_hdr = NULL;
112         }
113
114         if (th == NULL) {
115                 dt = lu2dt_dev(cathandle->lgh_obj->do_lu.lo_dev);
116
117                 handle = dt_trans_create(env, dt);
118                 if (IS_ERR(handle))
119                         RETURN(PTR_ERR(handle));
120
121                 /* Create update llog object synchronously, which
122                  * happens during inialization process see
123                  * lod_sub_prep_llog(), to make sure the update
124                  * llog object is created before corss-MDT writing
125                  * updates into the llog object */
126                 if (cathandle->lgh_ctxt->loc_flags & LLOG_CTXT_FLAG_NORMAL_FID)
127                         handle->th_sync = 1;
128
129                 handle->th_wait_submit = 1;
130
131                 rc = llog_declare_create(env, loghandle, handle);
132                 if (rc != 0)
133                         GOTO(out, rc);
134
135                 rec->lid_hdr.lrh_len = sizeof(*rec);
136                 rec->lid_hdr.lrh_type = LLOG_LOGID_MAGIC;
137                 rec->lid_id = loghandle->lgh_id;
138                 rc = llog_declare_write_rec(env, cathandle, &rec->lid_hdr, -1,
139                                             handle);
140                 if (rc != 0)
141                         GOTO(out, rc);
142
143                 rc = dt_trans_start_local(env, dt, handle);
144                 if (rc != 0)
145                         GOTO(out, rc);
146
147                 th = handle;
148         }
149
150         rc = llog_create(env, loghandle, th);
151         /* if llog is already created, no need to initialize it */
152         if (rc == -EEXIST) {
153                 GOTO(out, rc = 0);
154         } else if (rc != 0) {
155                 CERROR("%s: can't create new plain llog in catalog: rc = %d\n",
156                        loghandle->lgh_ctxt->loc_obd->obd_name, rc);
157                 GOTO(out, rc);
158         }
159
160         rc = llog_init_handle(env, loghandle,
161                               LLOG_F_IS_PLAIN | LLOG_F_ZAP_WHEN_EMPTY,
162                               &cathandle->lgh_hdr->llh_tgtuuid);
163         if (rc < 0)
164                 GOTO(out, rc);
165
166         /* build the record for this log in the catalog */
167         rec->lid_hdr.lrh_len = sizeof(*rec);
168         rec->lid_hdr.lrh_type = LLOG_LOGID_MAGIC;
169         rec->lid_id = loghandle->lgh_id;
170
171         /* append the new record into catalog. The new index will be
172          * assigned to the record and updated in rec header */
173         rc = llog_write_rec(env, cathandle, &rec->lid_hdr,
174                             &loghandle->u.phd.phd_cookie, LLOG_NEXT_IDX, th);
175         if (rc < 0)
176                 GOTO(out_destroy, rc);
177
178         CDEBUG(D_OTHER, "new plain log "DFID".%u of catalog "DFID"\n",
179                PFID(&loghandle->lgh_id.lgl_oi.oi_fid), rec->lid_hdr.lrh_index,
180                PFID(&cathandle->lgh_id.lgl_oi.oi_fid));
181
182         loghandle->lgh_hdr->llh_cat_idx = rec->lid_hdr.lrh_index;
183
184         /* limit max size of plain llog so that space can be
185          * released sooner, especially on small filesystems */
186         /* 2MB for the cases when free space hasn't been learned yet */
187         loghandle->lgh_max_size = 2 << 20;
188         dt = lu2dt_dev(cathandle->lgh_obj->do_lu.lo_dev);
189         rc = dt_statfs(env, dt, &lgi->lgi_statfs);
190         if (rc == 0 && lgi->lgi_statfs.os_bfree > 0) {
191                 __u64 freespace = (lgi->lgi_statfs.os_bfree *
192                                   lgi->lgi_statfs.os_bsize) >> 6;
193                 if (freespace < loghandle->lgh_max_size)
194                         loghandle->lgh_max_size = freespace;
195                 /* shouldn't be > 128MB in any case?
196                  * it's 256K records of 512 bytes each */
197                 if (freespace > (128 << 20))
198                         loghandle->lgh_max_size = 128 << 20;
199         }
200         rc = 0;
201
202 out:
203         if (handle != NULL) {
204                 handle->th_result = rc >= 0 ? 0 : rc;
205                 dt_trans_stop(env, dt, handle);
206         }
207         RETURN(rc);
208
209 out_destroy:
210         /* to signal llog_cat_close() it shouldn't try to destroy the llog,
211          * we want to destroy it in this transaction, otherwise the object
212          * becomes an orphan */
213         loghandle->lgh_hdr->llh_flags &= ~LLOG_F_ZAP_WHEN_EMPTY;
214         /* this is to mimic full log, so another llog_cat_current_log()
215          * can skip it and ask for another onet */
216         loghandle->lgh_last_idx = LLOG_HDR_BITMAP_SIZE(llh) + 1;
217         llog_trans_destroy(env, loghandle, th);
218         RETURN(rc);
219 }
220
221 /* Open an existent log handle and add it to the open list.
222  * This log handle will be closed when all of the records in it are removed.
223  *
224  * Assumes caller has already pushed us into the kernel context and is locking.
225  * We return a lock on the handle to ensure nobody yanks it from us.
226  *
227  * This takes extra reference on llog_handle via llog_handle_get() and require
228  * this reference to be put by caller using llog_handle_put()
229  */
230 int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
231                        struct llog_handle **res, struct llog_logid *logid)
232 {
233         struct llog_handle      *loghandle;
234         enum llog_flag           fmt;
235         int                      rc = 0;
236
237         ENTRY;
238
239         if (cathandle == NULL)
240                 RETURN(-EBADF);
241
242         fmt = cathandle->lgh_hdr->llh_flags & LLOG_F_EXT_MASK;
243         down_write(&cathandle->lgh_lock);
244         list_for_each_entry(loghandle, &cathandle->u.chd.chd_head,
245                             u.phd.phd_entry) {
246                 struct llog_logid *cgl = &loghandle->lgh_id;
247
248                 if (ostid_id(&cgl->lgl_oi) == ostid_id(&logid->lgl_oi) &&
249                     ostid_seq(&cgl->lgl_oi) == ostid_seq(&logid->lgl_oi)) {
250                         if (cgl->lgl_ogen != logid->lgl_ogen) {
251                                 CWARN("%s: log "DFID" generation %x != %x\n",
252                                       loghandle->lgh_ctxt->loc_obd->obd_name,
253                                       PFID(&logid->lgl_oi.oi_fid),
254                                       cgl->lgl_ogen, logid->lgl_ogen);
255                                 continue;
256                         }
257                         loghandle->u.phd.phd_cat_handle = cathandle;
258                         up_write(&cathandle->lgh_lock);
259                         GOTO(out, rc = 0);
260                 }
261         }
262         up_write(&cathandle->lgh_lock);
263
264         rc = llog_open(env, cathandle->lgh_ctxt, &loghandle, logid, NULL,
265                        LLOG_OPEN_EXISTS);
266         if (rc < 0) {
267                 CERROR("%s: error opening log id "DFID":%x: rc = %d\n",
268                        cathandle->lgh_ctxt->loc_obd->obd_name,
269                        PFID(&logid->lgl_oi.oi_fid), logid->lgl_ogen, rc);
270                 RETURN(rc);
271         }
272
273         rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN | fmt, NULL);
274         if (rc < 0) {
275                 llog_close(env, loghandle);
276                 loghandle = NULL;
277                 RETURN(rc);
278         }
279
280         down_write(&cathandle->lgh_lock);
281         list_add_tail(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head);
282         up_write(&cathandle->lgh_lock);
283
284         loghandle->u.phd.phd_cat_handle = cathandle;
285         loghandle->u.phd.phd_cookie.lgc_lgl = cathandle->lgh_id;
286         loghandle->u.phd.phd_cookie.lgc_index =
287                                 loghandle->lgh_hdr->llh_cat_idx;
288         EXIT;
289 out:
290         llog_handle_get(loghandle);
291         *res = loghandle;
292         return 0;
293 }
294
295 int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle)
296 {
297         struct llog_handle      *loghandle, *n;
298         int                      rc;
299
300         ENTRY;
301
302         list_for_each_entry_safe(loghandle, n, &cathandle->u.chd.chd_head,
303                                  u.phd.phd_entry) {
304                 struct llog_log_hdr     *llh = loghandle->lgh_hdr;
305                 int                      index;
306
307                 /* unlink open-not-created llogs */
308                 list_del_init(&loghandle->u.phd.phd_entry);
309                 llh = loghandle->lgh_hdr;
310                 if (loghandle->lgh_obj != NULL && llh != NULL &&
311                     (llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
312                     (llh->llh_count == 1)) {
313                         rc = llog_destroy(env, loghandle);
314                         if (rc)
315                                 CERROR("%s: failure destroying log during "
316                                        "cleanup: rc = %d\n",
317                                        loghandle->lgh_ctxt->loc_obd->obd_name,
318                                        rc);
319
320                         index = loghandle->u.phd.phd_cookie.lgc_index;
321                         llog_cat_cleanup(env, cathandle, NULL, index);
322                 }
323                 llog_close(env, loghandle);
324         }
325         /* if handle was stored in ctxt, remove it too */
326         if (cathandle->lgh_ctxt->loc_handle == cathandle)
327                 cathandle->lgh_ctxt->loc_handle = NULL;
328         rc = llog_close(env, cathandle);
329         RETURN(rc);
330 }
331 EXPORT_SYMBOL(llog_cat_close);
332
333 /**
334  * lockdep markers for nested struct llog_handle::lgh_lock locking.
335  */
336 enum {
337         LLOGH_CAT,
338         LLOGH_LOG
339 };
340
341 /** Return the currently active log handle.  If the current log handle doesn't
342  * have enough space left for the current record, start a new one.
343  *
344  * If reclen is 0, we only want to know what the currently active log is,
345  * otherwise we get a lock on this log so nobody can steal our space.
346  *
347  * Assumes caller has already pushed us into the kernel context and is locking.
348  *
349  * NOTE: loghandle is write-locked upon successful return
350  */
351 static struct llog_handle *llog_cat_current_log(struct llog_handle *cathandle,
352                                                 struct thandle *th)
353 {
354         struct llog_handle *loghandle = NULL;
355         ENTRY;
356
357
358         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_LLOG_CREATE_FAILED2)) {
359                 down_write_nested(&cathandle->lgh_lock, LLOGH_CAT);
360                 GOTO(next, loghandle);
361         }
362
363         down_read_nested(&cathandle->lgh_lock, LLOGH_CAT);
364         loghandle = cathandle->u.chd.chd_current_log;
365         if (loghandle) {
366                 struct llog_log_hdr *llh;
367
368                 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
369                 llh = loghandle->lgh_hdr;
370                 if (llh == NULL || !llog_is_full(loghandle)) {
371                         up_read(&cathandle->lgh_lock);
372                         RETURN(loghandle);
373                 } else {
374                         up_write(&loghandle->lgh_lock);
375                 }
376         }
377         up_read(&cathandle->lgh_lock);
378
379         /* time to use next log */
380
381         /* first, we have to make sure the state hasn't changed */
382         down_write_nested(&cathandle->lgh_lock, LLOGH_CAT);
383         loghandle = cathandle->u.chd.chd_current_log;
384         if (loghandle) {
385                 struct llog_log_hdr *llh;
386
387                 down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
388                 llh = loghandle->lgh_hdr;
389                 LASSERT(llh);
390                 if (!llog_is_full(loghandle))
391                         GOTO(out_unlock, loghandle);
392                 else
393                         up_write(&loghandle->lgh_lock);
394         }
395
396 next:
397         /* Sigh, the chd_next_log and chd_current_log is initialized
398          * in declare phase, and we do not serialize the catlog
399          * accessing, so it might be possible the llog creation
400          * thread (see llog_cat_declare_add_rec()) did not create
401          * llog successfully, then the following thread might
402          * meet this situation. */
403         if (IS_ERR_OR_NULL(cathandle->u.chd.chd_next_log)) {
404                 CERROR("%s: next log does not exist!\n",
405                        cathandle->lgh_ctxt->loc_obd->obd_name);
406                 loghandle = ERR_PTR(-EIO);
407                 if (cathandle->u.chd.chd_next_log == NULL) {
408                         /* Store the error in chd_next_log, so
409                          * the following process can get correct
410                          * failure value */
411                         cathandle->u.chd.chd_next_log = loghandle;
412                 }
413                 GOTO(out_unlock, loghandle);
414         }
415
416         CDEBUG(D_INODE, "use next log\n");
417
418         loghandle = cathandle->u.chd.chd_next_log;
419         cathandle->u.chd.chd_current_log = loghandle;
420         cathandle->u.chd.chd_next_log = NULL;
421         down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
422
423 out_unlock:
424         up_write(&cathandle->lgh_lock);
425         LASSERT(loghandle);
426         RETURN(loghandle);
427 }
428
429 static int llog_cat_update_header(const struct lu_env *env,
430                            struct llog_handle *cathandle)
431 {
432         struct llog_handle *loghandle;
433         int rc;
434         ENTRY;
435
436         /* refresh llog */
437         down_write(&cathandle->lgh_lock);
438         if (!cathandle->lgh_stale) {
439                 up_write(&cathandle->lgh_lock);
440                 RETURN(0);
441         }
442         list_for_each_entry(loghandle, &cathandle->u.chd.chd_head,
443                             u.phd.phd_entry) {
444                 if (!llog_exist(loghandle))
445                         continue;
446
447                 rc = llog_read_header(env, loghandle, NULL);
448                 if (rc != 0) {
449                         up_write(&cathandle->lgh_lock);
450                         GOTO(out, rc);
451                 }
452         }
453         rc = llog_read_header(env, cathandle, NULL);
454         if (rc == 0)
455                 cathandle->lgh_stale = 0;
456         up_write(&cathandle->lgh_lock);
457         if (rc != 0)
458                 GOTO(out, rc);
459 out:
460         RETURN(rc);
461 }
462
463 /* Add a single record to the recovery log(s) using a catalog
464  * Returns as llog_write_record
465  *
466  * Assumes caller has already pushed us into the kernel context.
467  */
468 int llog_cat_add_rec(const struct lu_env *env, struct llog_handle *cathandle,
469                      struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
470                      struct thandle *th)
471 {
472         struct llog_handle *loghandle;
473         int rc, retried = 0;
474         ENTRY;
475
476         LASSERT(rec->lrh_len <= cathandle->lgh_ctxt->loc_chunk_size);
477
478 retry:
479         loghandle = llog_cat_current_log(cathandle, th);
480         if (IS_ERR(loghandle))
481                 RETURN(PTR_ERR(loghandle));
482
483         /* loghandle is already locked by llog_cat_current_log() for us */
484         if (!llog_exist(loghandle)) {
485                 rc = llog_cat_new_log(env, cathandle, loghandle, th);
486                 if (rc < 0) {
487                         up_write(&loghandle->lgh_lock);
488                         /* nobody should be trying to use this llog */
489                         down_write(&cathandle->lgh_lock);
490                         if (cathandle->u.chd.chd_current_log == loghandle)
491                                 cathandle->u.chd.chd_current_log = NULL;
492                         up_write(&cathandle->lgh_lock);
493                         RETURN(rc);
494                 }
495         }
496         /* now let's try to add the record */
497         rc = llog_write_rec(env, loghandle, rec, reccookie, LLOG_NEXT_IDX, th);
498         if (rc < 0) {
499                 CDEBUG_LIMIT(rc == -ENOSPC ? D_HA : D_ERROR,
500                              "llog_write_rec %d: lh=%p\n", rc, loghandle);
501                 /* -ENOSPC is returned if no empty records left
502                  * and when it's lack of space on the stogage.
503                  * there is no point to try again if it's the second
504                  * case. many callers (like llog test) expect ENOSPC,
505                  * so we preserve this error code, but look for the
506                  * actual cause here */
507                 if (rc == -ENOSPC && llog_is_full(loghandle))
508                         rc = -ENOBUFS;
509         }
510         up_write(&loghandle->lgh_lock);
511
512         if (rc == -ENOBUFS) {
513                 if (retried++ == 0)
514                         GOTO(retry, rc);
515                 CERROR("%s: error on 2nd llog: rc = %d\n",
516                        cathandle->lgh_ctxt->loc_obd->obd_name, rc);
517         }
518
519         RETURN(rc);
520 }
521 EXPORT_SYMBOL(llog_cat_add_rec);
522
523 int llog_cat_declare_add_rec(const struct lu_env *env,
524                              struct llog_handle *cathandle,
525                              struct llog_rec_hdr *rec, struct thandle *th)
526 {
527         struct llog_thread_info *lgi = llog_info(env);
528         struct llog_logid_rec   *lirec = &lgi->lgi_logid;
529         struct llog_handle      *loghandle, *next;
530         int                      rc = 0;
531
532         ENTRY;
533
534         if (cathandle->u.chd.chd_current_log == NULL) {
535                 /* declare new plain llog */
536                 down_write(&cathandle->lgh_lock);
537                 if (cathandle->u.chd.chd_current_log == NULL) {
538                         rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
539                                        NULL, NULL, LLOG_OPEN_NEW);
540                         if (rc == 0) {
541                                 cathandle->u.chd.chd_current_log = loghandle;
542                                 list_add_tail(&loghandle->u.phd.phd_entry,
543                                               &cathandle->u.chd.chd_head);
544                         }
545                 }
546                 up_write(&cathandle->lgh_lock);
547         } else if (cathandle->u.chd.chd_next_log == NULL ||
548                    IS_ERR(cathandle->u.chd.chd_next_log)) {
549                 /* declare next plain llog */
550                 down_write(&cathandle->lgh_lock);
551                 if (cathandle->u.chd.chd_next_log == NULL ||
552                     IS_ERR(cathandle->u.chd.chd_next_log)) {
553                         rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
554                                        NULL, NULL, LLOG_OPEN_NEW);
555                         if (rc == 0) {
556                                 cathandle->u.chd.chd_next_log = loghandle;
557                                 list_add_tail(&loghandle->u.phd.phd_entry,
558                                               &cathandle->u.chd.chd_head);
559                         }
560                 }
561                 up_write(&cathandle->lgh_lock);
562         }
563         if (rc)
564                 GOTO(out, rc);
565
566         lirec->lid_hdr.lrh_len = sizeof(*lirec);
567
568         if (!llog_exist(cathandle->u.chd.chd_current_log)) {
569                 if (dt_object_remote(cathandle->lgh_obj)) {
570                         /* For remote operation, if we put the llog object
571                          * creation in the current transaction, then the
572                          * llog object will not be created on the remote
573                          * target until the transaction stop, if other
574                          * operations start before the transaction stop,
575                          * and use the same llog object, will be dependent
576                          * on the success of this transaction. So let's
577                          * create the llog object synchronously here to
578                          * remove the dependency. */
579 create_again:
580                         down_read_nested(&cathandle->lgh_lock, LLOGH_CAT);
581                         loghandle = cathandle->u.chd.chd_current_log;
582                         down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
583                         if (cathandle->lgh_stale) {
584                                 up_write(&loghandle->lgh_lock);
585                                 up_read(&cathandle->lgh_lock);
586                                 GOTO(out, rc = -EIO);
587                         }
588                         if (!llog_exist(loghandle)) {
589                                 rc = llog_cat_new_log(env, cathandle, loghandle,
590                                                       NULL);
591                                 if (rc == -ESTALE)
592                                         cathandle->lgh_stale = 1;
593                         }
594                         up_write(&loghandle->lgh_lock);
595                         up_read(&cathandle->lgh_lock);
596                         if (rc == -ESTALE) {
597                                 rc = llog_cat_update_header(env, cathandle);
598                                 if (rc != 0)
599                                         GOTO(out, rc);
600                                 goto create_again;
601                         } else if (rc < 0) {
602                                 GOTO(out, rc);
603                         }
604                 } else {
605                         rc = llog_declare_create(env,
606                                         cathandle->u.chd.chd_current_log, th);
607                         if (rc)
608                                 GOTO(out, rc);
609                         llog_declare_write_rec(env, cathandle,
610                                                &lirec->lid_hdr, -1, th);
611                 }
612         }
613
614 write_again:
615         /* declare records in the llogs */
616         rc = llog_declare_write_rec(env, cathandle->u.chd.chd_current_log,
617                                     rec, -1, th);
618         if (rc == -ESTALE) {
619                 down_write(&cathandle->lgh_lock);
620                 if (cathandle->lgh_stale) {
621                         up_write(&cathandle->lgh_lock);
622                         GOTO(out, rc = -EIO);
623                 }
624
625                 cathandle->lgh_stale = 1;
626                 up_write(&cathandle->lgh_lock);
627                 rc = llog_cat_update_header(env, cathandle);
628                 if (rc != 0)
629                         GOTO(out, rc);
630                 goto write_again;
631         } else if (rc < 0) {
632                 GOTO(out, rc);
633         }
634
635         next = cathandle->u.chd.chd_next_log;
636         if (!IS_ERR_OR_NULL(next)) {
637                 if (!llog_exist(next)) {
638                         if (dt_object_remote(cathandle->lgh_obj)) {
639                                 /* For remote operation, if we put the llog
640                                  * object creation in the current transaction,
641                                  * then the llog object will not be created on
642                                  * the remote target until the transaction stop,
643                                  * if other operations start before the
644                                  * transaction stop, and use the same llog
645                                  * object, will be dependent on the success of
646                                  * this transaction. So let's create the llog
647                                  * object synchronously here to remove the
648                                  * dependency. */
649                                 down_write_nested(&cathandle->lgh_lock,
650                                                  LLOGH_CAT);
651                                 next = cathandle->u.chd.chd_next_log;
652                                 if (IS_ERR_OR_NULL(next)) {
653                                         /* Sigh, another thread just tried,
654                                          * let's fail as well */
655                                         up_write(&cathandle->lgh_lock);
656                                         if (next == NULL)
657                                                 rc = -EIO;
658                                         else
659                                                 rc = PTR_ERR(next);
660                                         GOTO(out, rc);
661                                 }
662
663                                 down_write_nested(&next->lgh_lock, LLOGH_LOG);
664                                 if (!llog_exist(next)) {
665                                         rc = llog_cat_new_log(env, cathandle,
666                                                               next, NULL);
667                                         if (rc < 0)
668                                                 cathandle->u.chd.chd_next_log =
669                                                                 ERR_PTR(rc);
670                                 }
671                                 up_write(&next->lgh_lock);
672                                 up_write(&cathandle->lgh_lock);
673                                 if (rc < 0)
674                                         GOTO(out, rc);
675                         } else {
676                                 rc = llog_declare_create(env, next, th);
677                                 llog_declare_write_rec(env, cathandle,
678                                                 &lirec->lid_hdr, -1, th);
679                         }
680                 }
681                 /* XXX: we hope for declarations made for existing llog
682                  *      this might be not correct with some backends
683                  *      where declarations are expected against specific
684                  *      object like ZFS with full debugging enabled */
685                 /*llog_declare_write_rec(env, next, rec, -1, th);*/
686         }
687 out:
688         RETURN(rc);
689 }
690 EXPORT_SYMBOL(llog_cat_declare_add_rec);
691
692 int llog_cat_add(const struct lu_env *env, struct llog_handle *cathandle,
693                  struct llog_rec_hdr *rec, struct llog_cookie *reccookie)
694 {
695         struct llog_ctxt        *ctxt;
696         struct dt_device        *dt;
697         struct thandle          *th = NULL;
698         int                      rc;
699
700         ctxt = cathandle->lgh_ctxt;
701         LASSERT(ctxt);
702         LASSERT(ctxt->loc_exp);
703
704         LASSERT(cathandle->lgh_obj != NULL);
705         dt = lu2dt_dev(cathandle->lgh_obj->do_lu.lo_dev);
706
707         th = dt_trans_create(env, dt);
708         if (IS_ERR(th))
709                 RETURN(PTR_ERR(th));
710
711         rc = llog_cat_declare_add_rec(env, cathandle, rec, th);
712         if (rc)
713                 GOTO(out_trans, rc);
714
715         rc = dt_trans_start_local(env, dt, th);
716         if (rc)
717                 GOTO(out_trans, rc);
718         rc = llog_cat_add_rec(env, cathandle, rec, reccookie, th);
719 out_trans:
720         dt_trans_stop(env, dt, th);
721         RETURN(rc);
722 }
723 EXPORT_SYMBOL(llog_cat_add);
724
725 /* For each cookie in the cookie array, we clear the log in-use bit and either:
726  * - the log is empty, so mark it free in the catalog header and delete it
727  * - the log is not empty, just write out the log header
728  *
729  * The cookies may be in different log files, so we need to get new logs
730  * each time.
731  *
732  * Assumes caller has already pushed us into the kernel context.
733  */
734 int llog_cat_cancel_records(const struct lu_env *env,
735                             struct llog_handle *cathandle, int count,
736                             struct llog_cookie *cookies)
737 {
738         int i, index, rc = 0, failed = 0;
739
740         ENTRY;
741
742         for (i = 0; i < count; i++, cookies++) {
743                 struct llog_handle *loghandle;
744                 struct llog_logid *lgl = &cookies->lgc_lgl;
745                 int  lrc;
746
747                 rc = llog_cat_id2handle(env, cathandle, &loghandle, lgl);
748                 if (rc) {
749                         CDEBUG(D_HA, "%s: cannot find llog for handle "DFID":%x"
750                                ": rc = %d\n",
751                                cathandle->lgh_ctxt->loc_obd->obd_name,
752                                PFID(&lgl->lgl_oi.oi_fid), lgl->lgl_ogen, rc);
753                         failed++;
754                         continue;
755                 }
756
757                 if ((cathandle->lgh_ctxt->loc_flags &
758                      LLOG_CTXT_FLAG_NORMAL_FID) && !llog_exist(loghandle)) {
759                         /* For update log, some of loghandles of cathandle
760                          * might not exist because remote llog creation might
761                          * be failed, so let's skip the record cancellation
762                          * for these non-exist llogs.
763                          */
764                         lrc = -ENOENT;
765                         CDEBUG(D_HA, "%s: llog "DFID":%x does not exist"
766                                ": rc = %d\n",
767                                cathandle->lgh_ctxt->loc_obd->obd_name,
768                                PFID(&lgl->lgl_oi.oi_fid), lgl->lgl_ogen, lrc);
769                         failed++;
770                         if (rc == 0)
771                                 rc = lrc;
772                         continue;
773                 }
774
775                 lrc = llog_cancel_rec(env, loghandle, cookies->lgc_index);
776                 if (lrc == LLOG_DEL_PLAIN) { /* log has been destroyed */
777                         index = loghandle->u.phd.phd_cookie.lgc_index;
778                         lrc = llog_cat_cleanup(env, cathandle, loghandle,
779                                                index);
780                         if (rc == 0)
781                                 rc = lrc;
782                 } else if (lrc == -ENOENT) {
783                         if (rc == 0) /* ENOENT shouldn't rewrite any error */
784                                 rc = lrc;
785                 } else if (lrc < 0) {
786                         failed++;
787                         if (rc == 0)
788                                 rc = lrc;
789                 }
790                 llog_handle_put(loghandle);
791         }
792         if (rc)
793                 CERROR("%s: fail to cancel %d of %d llog-records: rc = %d\n",
794                        cathandle->lgh_ctxt->loc_obd->obd_name, failed, count,
795                        rc);
796
797         RETURN(rc);
798 }
799 EXPORT_SYMBOL(llog_cat_cancel_records);
800
801 static int llog_cat_process_cb(const struct lu_env *env,
802                                struct llog_handle *cat_llh,
803                                struct llog_rec_hdr *rec, void *data)
804 {
805         struct llog_process_data *d = data;
806         struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
807         struct llog_handle *llh;
808         struct llog_log_hdr *hdr;
809         int rc;
810
811         ENTRY;
812         if (rec->lrh_type != LLOG_LOGID_MAGIC) {
813                 CERROR("invalid record in catalog\n");
814                 RETURN(-EINVAL);
815         }
816         CDEBUG(D_HA, "processing log "DFID":%x at index %u of catalog "
817                DFID"\n", PFID(&lir->lid_id.lgl_oi.oi_fid), lir->lid_id.lgl_ogen,
818                rec->lrh_index, PFID(&cat_llh->lgh_id.lgl_oi.oi_fid));
819
820         rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
821         if (rc) {
822                 CERROR("%s: cannot find handle for llog "DFID": rc = %d\n",
823                        cat_llh->lgh_ctxt->loc_obd->obd_name,
824                        PFID(&lir->lid_id.lgl_oi.oi_fid), rc);
825                 if (rc == -ENOENT || rc == -ESTALE) {
826                         /* After a server crash, a stub of index
827                          * record in catlog could be kept, because
828                          * plain log destroy + catlog index record
829                          * deletion are not atomic. So we end up with
830                          * an index but no actual record. Destroy the
831                          * index and move on. */
832                         rc = llog_cat_cleanup(env, cat_llh, NULL,
833                                               rec->lrh_index);
834                 }
835
836                 RETURN(rc);
837         }
838
839         /* clean old empty llogs, do not consider current llog in use */
840         /* ignore remote (lgh_obj=NULL) llogs */
841         hdr = llh->lgh_hdr;
842         if ((hdr->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
843             hdr->llh_count == 1 && cat_llh->lgh_obj != NULL &&
844             llh != cat_llh->u.chd.chd_current_log) {
845                 rc = llog_destroy(env, llh);
846                 if (rc)
847                         CERROR("%s: fail to destroy empty log: rc = %d\n",
848                                llh->lgh_ctxt->loc_obd->obd_name, rc);
849                 GOTO(out, rc = LLOG_DEL_PLAIN);
850         }
851
852         if (rec->lrh_index < d->lpd_startcat) {
853                 /* Skip processing of the logs until startcat */
854                 rc = 0;
855         } else if (d->lpd_startidx > 0) {
856                 struct llog_process_cat_data cd;
857
858                 cd.lpcd_first_idx = d->lpd_startidx;
859                 cd.lpcd_last_idx = 0;
860                 rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
861                                           &cd, false);
862                 /* Continue processing the next log from idx 0 */
863                 d->lpd_startidx = 0;
864         } else {
865                 rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
866                                           NULL, false);
867         }
868
869 out:
870         /* The empty plain log was destroyed while processing */
871         if (rc == LLOG_DEL_PLAIN)
872                 rc = llog_cat_cleanup(env, cat_llh, llh,
873                                       llh->u.phd.phd_cookie.lgc_index);
874         llog_handle_put(llh);
875
876         RETURN(rc);
877 }
878
879 int llog_cat_process_or_fork(const struct lu_env *env,
880                              struct llog_handle *cat_llh, llog_cb_t cat_cb,
881                              llog_cb_t cb, void *data, int startcat,
882                              int startidx, bool fork)
883 {
884         struct llog_process_data d;
885         struct llog_log_hdr *llh = cat_llh->lgh_hdr;
886         int rc;
887         ENTRY;
888
889         LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
890         d.lpd_data = data;
891         d.lpd_cb = cb;
892         d.lpd_startcat = startcat;
893         d.lpd_startidx = startidx;
894
895         if (llh->llh_cat_idx >= cat_llh->lgh_last_idx &&
896             llh->llh_count > 1) {
897                 struct llog_process_cat_data cd;
898
899                 CWARN("%s: catlog "DFID" crosses index zero\n",
900                       cat_llh->lgh_ctxt->loc_obd->obd_name,
901                       PFID(&cat_llh->lgh_id.lgl_oi.oi_fid));
902
903                 cd.lpcd_first_idx = llh->llh_cat_idx;
904                 cd.lpcd_last_idx = 0;
905                 rc = llog_process_or_fork(env, cat_llh, cat_cb,
906                                           &d, &cd, fork);
907                 if (rc != 0)
908                         RETURN(rc);
909
910                 cd.lpcd_first_idx = 0;
911                 cd.lpcd_last_idx = cat_llh->lgh_last_idx;
912                 rc = llog_process_or_fork(env, cat_llh, cat_cb,
913                                           &d, &cd, fork);
914         } else {
915                 rc = llog_process_or_fork(env, cat_llh, cat_cb,
916                                           &d, NULL, fork);
917         }
918
919         RETURN(rc);
920 }
921
922 int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
923                      llog_cb_t cb, void *data, int startcat, int startidx)
924 {
925         return llog_cat_process_or_fork(env, cat_llh, llog_cat_process_cb,
926                                         cb, data, startcat, startidx, false);
927 }
928 EXPORT_SYMBOL(llog_cat_process);
929
930 static int llog_cat_size_cb(const struct lu_env *env,
931                              struct llog_handle *cat_llh,
932                              struct llog_rec_hdr *rec, void *data)
933 {
934         struct llog_process_data *d = data;
935         struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
936         struct llog_handle *llh;
937         int rc;
938         __u64 *cum_size = d->lpd_data;
939         __u64 size;
940
941         ENTRY;
942         if (rec->lrh_type != LLOG_LOGID_MAGIC) {
943                 CERROR("%s: invalid record in catalog, rc = %d\n",
944                        cat_llh->lgh_ctxt->loc_obd->obd_name, -EINVAL);
945                 RETURN(-EINVAL);
946         }
947         CDEBUG(D_HA, "processing log "DFID":%x at index %u of catalog "
948                DFID"\n", PFID(&lir->lid_id.lgl_oi.oi_fid), lir->lid_id.lgl_ogen,
949                rec->lrh_index, PFID(&cat_llh->lgh_id.lgl_oi.oi_fid));
950
951         rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
952         if (rc) {
953                 CWARN("%s: cannot find handle for llog "DFID": rc = %d\n",
954                       cat_llh->lgh_ctxt->loc_obd->obd_name,
955                       PFID(&lir->lid_id.lgl_oi.oi_fid), rc);
956                 RETURN(0);
957         }
958         size = llog_size(env, llh);
959         *cum_size += size;
960
961         CDEBUG(D_INFO, "Add llog entry "DFID" size %llu\n",
962                PFID(&llh->lgh_id.lgl_oi.oi_fid), size);
963
964         llog_handle_put(llh);
965
966         RETURN(0);
967
968 }
969
970 __u64 llog_cat_size(const struct lu_env *env, struct llog_handle *cat_llh)
971 {
972         __u64 size = llog_size(env, cat_llh);
973
974         llog_cat_process_or_fork(env, cat_llh, llog_cat_size_cb,
975                                  NULL, &size, 0, 0, false);
976
977         return size;
978 }
979 EXPORT_SYMBOL(llog_cat_size);
980
981 /* currently returns the number of "free" entries in catalog,
982  * ie the available entries for a new plain LLOG file creation,
983  * even if catalog has wrapped
984  */
985 __u32 llog_cat_free_space(struct llog_handle *cat_llh)
986 {
987         /* simulate almost full Catalog */
988         if (OBD_FAIL_CHECK(OBD_FAIL_CAT_FREE_RECORDS))
989                 return cfs_fail_val;
990
991         if (cat_llh->lgh_hdr->llh_count == 1)
992                 return LLOG_HDR_BITMAP_SIZE(cat_llh->lgh_hdr) - 1;
993
994         if (cat_llh->lgh_last_idx > cat_llh->lgh_hdr->llh_cat_idx)
995                 return LLOG_HDR_BITMAP_SIZE(cat_llh->lgh_hdr) - 1 +
996                        cat_llh->lgh_hdr->llh_cat_idx - cat_llh->lgh_last_idx;
997
998         /* catalog is presently wrapped */
999         return cat_llh->lgh_hdr->llh_cat_idx - cat_llh->lgh_last_idx;
1000 }
1001 EXPORT_SYMBOL(llog_cat_free_space);
1002
1003 static int llog_cat_reverse_process_cb(const struct lu_env *env,
1004                                        struct llog_handle *cat_llh,
1005                                        struct llog_rec_hdr *rec, void *data)
1006 {
1007         struct llog_process_data *d = data;
1008         struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
1009         struct llog_handle *llh;
1010         struct llog_log_hdr *hdr;
1011         int rc;
1012
1013         if (le32_to_cpu(rec->lrh_type) != LLOG_LOGID_MAGIC) {
1014                 CERROR("invalid record in catalog\n");
1015                 RETURN(-EINVAL);
1016         }
1017         CDEBUG(D_HA, "processing log "DFID":%x at index %u of catalog "
1018                DFID"\n", PFID(&lir->lid_id.lgl_oi.oi_fid), lir->lid_id.lgl_ogen,
1019                le32_to_cpu(rec->lrh_index),
1020                PFID(&cat_llh->lgh_id.lgl_oi.oi_fid));
1021
1022         rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
1023         if (rc) {
1024                 CERROR("%s: cannot find handle for llog "DFID": rc = %d\n",
1025                        cat_llh->lgh_ctxt->loc_obd->obd_name,
1026                        PFID(&lir->lid_id.lgl_oi.oi_fid), rc);
1027                 if (rc == -ENOENT || rc == -ESTALE) {
1028                         /* After a server crash, a stub of index
1029                          * record in catlog could be kept, because
1030                          * plain log destroy + catlog index record
1031                          * deletion are not atomic. So we end up with
1032                          * an index but no actual record. Destroy the
1033                          * index and move on. */
1034                         rc = llog_cat_cleanup(env, cat_llh, NULL,
1035                                               rec->lrh_index);
1036                 }
1037
1038                 RETURN(rc);
1039         }
1040
1041         /* clean old empty llogs, do not consider current llog in use */
1042         hdr = llh->lgh_hdr;
1043         if ((hdr->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
1044             hdr->llh_count == 1 &&
1045             llh != cat_llh->u.chd.chd_current_log) {
1046                 rc = llog_destroy(env, llh);
1047                 if (rc)
1048                         CERROR("%s: fail to destroy empty log: rc = %d\n",
1049                                llh->lgh_ctxt->loc_obd->obd_name, rc);
1050                 GOTO(out, rc = LLOG_DEL_PLAIN);
1051         }
1052
1053         rc = llog_reverse_process(env, llh, d->lpd_cb, d->lpd_data, NULL);
1054
1055 out:
1056         /* The empty plain was destroyed while processing */
1057         if (rc == LLOG_DEL_PLAIN)
1058                 rc = llog_cat_cleanup(env, cat_llh, llh,
1059                                       llh->u.phd.phd_cookie.lgc_index);
1060
1061         llog_handle_put(llh);
1062         RETURN(rc);
1063 }
1064
1065 int llog_cat_reverse_process(const struct lu_env *env,
1066                              struct llog_handle *cat_llh,
1067                              llog_cb_t cb, void *data)
1068 {
1069         struct llog_process_data d;
1070         struct llog_process_cat_data cd;
1071         struct llog_log_hdr *llh = cat_llh->lgh_hdr;
1072         int rc;
1073         ENTRY;
1074
1075         LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
1076         d.lpd_data = data;
1077         d.lpd_cb = cb;
1078
1079         if (llh->llh_cat_idx >= cat_llh->lgh_last_idx &&
1080             llh->llh_count > 1) {
1081                 CWARN("%s: catalog "DFID" crosses index zero\n",
1082                       cat_llh->lgh_ctxt->loc_obd->obd_name,
1083                       PFID(&cat_llh->lgh_id.lgl_oi.oi_fid));
1084
1085                 cd.lpcd_first_idx = 0;
1086                 cd.lpcd_last_idx = cat_llh->lgh_last_idx;
1087                 rc = llog_reverse_process(env, cat_llh,
1088                                           llog_cat_reverse_process_cb,
1089                                           &d, &cd);
1090                 if (rc != 0)
1091                         RETURN(rc);
1092
1093                 cd.lpcd_first_idx = le32_to_cpu(llh->llh_cat_idx);
1094                 cd.lpcd_last_idx = 0;
1095                 rc = llog_reverse_process(env, cat_llh,
1096                                           llog_cat_reverse_process_cb,
1097                                           &d, &cd);
1098         } else {
1099                 rc = llog_reverse_process(env, cat_llh,
1100                                           llog_cat_reverse_process_cb,
1101                                           &d, NULL);
1102         }
1103
1104         RETURN(rc);
1105 }
1106 EXPORT_SYMBOL(llog_cat_reverse_process);
1107
1108 static int llog_cat_set_first_idx(struct llog_handle *cathandle, int idx)
1109 {
1110         struct llog_log_hdr *llh = cathandle->lgh_hdr;
1111         int bitmap_size;
1112
1113         ENTRY;
1114
1115         bitmap_size = LLOG_HDR_BITMAP_SIZE(llh);
1116         /*
1117          * The llh_cat_idx equals to the first used index minus 1
1118          * so if we canceled the first index then llh_cat_idx
1119          * must be renewed.
1120          */
1121         if (llh->llh_cat_idx == (idx - 1)) {
1122                 llh->llh_cat_idx = idx;
1123
1124                 while (idx != cathandle->lgh_last_idx) {
1125                         idx = (idx + 1) % bitmap_size;
1126                         if (!ext2_test_bit(idx, LLOG_HDR_BITMAP(llh))) {
1127                                 /* update llh_cat_idx for each unset bit,
1128                                  * expecting the next one is set */
1129                                 llh->llh_cat_idx = idx;
1130                         } else if (idx == 0) {
1131                                 /* skip header bit */
1132                                 llh->llh_cat_idx = 0;
1133                                 continue;
1134                         } else {
1135                                 /* the first index is found */
1136                                 break;
1137                         }
1138                 }
1139
1140                 CDEBUG(D_RPCTRACE, "catlog "DFID" first idx %u, last_idx %u\n",
1141                        PFID(&cathandle->lgh_id.lgl_oi.oi_fid),
1142                        llh->llh_cat_idx, cathandle->lgh_last_idx);
1143         }
1144
1145         RETURN(0);
1146 }
1147
1148 /* Cleanup deleted plain llog traces from catalog */
1149 int llog_cat_cleanup(const struct lu_env *env, struct llog_handle *cathandle,
1150                      struct llog_handle *loghandle, int index)
1151 {
1152         int rc;
1153
1154         LASSERT(index);
1155         if (loghandle != NULL) {
1156                 /* remove destroyed llog from catalog list and
1157                  * chd_current_log variable */
1158                 down_write(&cathandle->lgh_lock);
1159                 if (cathandle->u.chd.chd_current_log == loghandle)
1160                         cathandle->u.chd.chd_current_log = NULL;
1161                 list_del_init(&loghandle->u.phd.phd_entry);
1162                 up_write(&cathandle->lgh_lock);
1163                 LASSERT(index == loghandle->u.phd.phd_cookie.lgc_index);
1164                 /* llog was opened and keep in a list, close it now */
1165                 llog_close(env, loghandle);
1166         }
1167
1168         /* do not attempt to cleanup on-disk llog if on client side */
1169         if (cathandle->lgh_obj == NULL)
1170                 return 0;
1171
1172         /* remove plain llog entry from catalog by index */
1173         llog_cat_set_first_idx(cathandle, index);
1174         rc = llog_cancel_rec(env, cathandle, index);
1175         if (rc == 0)
1176                 CDEBUG(D_HA, "cancel plain log at index %u of catalog "DFID"\n",
1177                        index, PFID(&cathandle->lgh_id.lgl_oi.oi_fid));
1178         return rc;
1179 }