Whamcloud - gitweb
LU-6838 llog: limit file size of plain logs
[fs/lustre-release.git] / lustre / obdclass / llog.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, 2015, 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.c
33  *
34  * OST<->MDS recovery logging infrastructure.
35  * Invariants in implementation:
36  * - we do not share logs among different OST<->MDS connections, so that
37  *   if an OST or MDS fails it need only look at log(s) relevant to itself
38  *
39  * Author: Andreas Dilger <adilger@clusterfs.com>
40  * Author: Alex Zhuravlev <bzzz@whamcloud.com>
41  * Author: Mikhail Pershin <tappro@whamcloud.com>
42  */
43
44 #define DEBUG_SUBSYSTEM S_LOG
45
46 #include <linux/kthread.h>
47 #include <llog_swab.h>
48 #include <lustre_log.h>
49 #include <obd_class.h>
50 #include "llog_internal.h"
51 /*
52  * Allocate a new log or catalog handle
53  * Used inside llog_open().
54  */
55 static struct llog_handle *llog_alloc_handle(void)
56 {
57         struct llog_handle *loghandle;
58
59         OBD_ALLOC_PTR(loghandle);
60         if (loghandle == NULL)
61                 return NULL;
62
63         init_rwsem(&loghandle->lgh_lock);
64         mutex_init(&loghandle->lgh_hdr_mutex);
65         INIT_LIST_HEAD(&loghandle->u.phd.phd_entry);
66         atomic_set(&loghandle->lgh_refcount, 1);
67
68         return loghandle;
69 }
70
71 /*
72  * Free llog handle and header data if exists. Used in llog_close() only
73  */
74 static void llog_free_handle(struct llog_handle *loghandle)
75 {
76         LASSERT(loghandle != NULL);
77
78         /* failed llog_init_handle */
79         if (loghandle->lgh_hdr == NULL)
80                 goto out;
81
82         if (loghandle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)
83                 LASSERT(list_empty(&loghandle->u.phd.phd_entry));
84         else if (loghandle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)
85                 LASSERT(list_empty(&loghandle->u.chd.chd_head));
86         OBD_FREE_LARGE(loghandle->lgh_hdr, loghandle->lgh_hdr_size);
87 out:
88         OBD_FREE_PTR(loghandle);
89 }
90
91 void llog_handle_get(struct llog_handle *loghandle)
92 {
93         atomic_inc(&loghandle->lgh_refcount);
94 }
95
96 void llog_handle_put(struct llog_handle *loghandle)
97 {
98         LASSERT(atomic_read(&loghandle->lgh_refcount) > 0);
99         if (atomic_dec_and_test(&loghandle->lgh_refcount))
100                 llog_free_handle(loghandle);
101 }
102
103 static int llog_declare_destroy(const struct lu_env *env,
104                                 struct llog_handle *handle,
105                                 struct thandle *th)
106 {
107         struct llog_operations *lop;
108         int rc;
109
110         ENTRY;
111
112         rc = llog_handle2ops(handle, &lop);
113         if (rc)
114                 RETURN(rc);
115         if (lop->lop_declare_destroy == NULL)
116                 RETURN(-EOPNOTSUPP);
117
118         rc = lop->lop_declare_destroy(env, handle, th);
119
120         RETURN(rc);
121 }
122
123 int llog_trans_destroy(const struct lu_env *env, struct llog_handle *handle,
124                        struct thandle *th)
125 {
126         struct llog_operations  *lop;
127         int rc;
128         ENTRY;
129
130         rc = llog_handle2ops(handle, &lop);
131         if (rc < 0)
132                 RETURN(rc);
133         if (lop->lop_destroy == NULL)
134                 RETURN(-EOPNOTSUPP);
135
136         LASSERT(handle->lgh_obj != NULL);
137         if (!dt_object_exists(handle->lgh_obj))
138                 RETURN(0);
139
140         rc = lop->lop_destroy(env, handle, th);
141
142         RETURN(rc);
143 }
144
145 int llog_destroy(const struct lu_env *env, struct llog_handle *handle)
146 {
147         struct llog_operations  *lop;
148         struct dt_device        *dt;
149         struct thandle          *th;
150         int rc;
151
152         ENTRY;
153
154         rc = llog_handle2ops(handle, &lop);
155         if (rc < 0)
156                 RETURN(rc);
157         if (lop->lop_destroy == NULL)
158                 RETURN(-EOPNOTSUPP);
159
160         if (handle->lgh_obj == NULL) {
161                 /* if lgh_obj == NULL, then it is from client side destroy */
162                 rc = lop->lop_destroy(env, handle, NULL);
163                 RETURN(rc);
164         }
165
166         if (!dt_object_exists(handle->lgh_obj))
167                 RETURN(0);
168
169         dt = lu2dt_dev(handle->lgh_obj->do_lu.lo_dev);
170
171         th = dt_trans_create(env, dt);
172         if (IS_ERR(th))
173                 RETURN(PTR_ERR(th));
174
175         rc = llog_declare_destroy(env, handle, th);
176         if (rc != 0)
177                 GOTO(out_trans, rc);
178
179         rc = dt_trans_start_local(env, dt, th);
180         if (rc < 0)
181                 GOTO(out_trans, rc);
182
183         rc = lop->lop_destroy(env, handle, th);
184
185 out_trans:
186         dt_trans_stop(env, dt, th);
187
188         RETURN(rc);
189 }
190 EXPORT_SYMBOL(llog_destroy);
191
192 /* returns negative on error; 0 if success; 1 if success & log destroyed */
193 int llog_cancel_rec(const struct lu_env *env, struct llog_handle *loghandle,
194                     int index)
195 {
196         struct llog_thread_info *lgi = llog_info(env);
197         struct dt_device        *dt;
198         struct llog_log_hdr     *llh = loghandle->lgh_hdr;
199         struct thandle          *th;
200         int                      rc;
201         int rc1;
202         bool subtract_count = false;
203
204         ENTRY;
205
206         CDEBUG(D_RPCTRACE, "Canceling %d in log "DOSTID"\n", index,
207                POSTID(&loghandle->lgh_id.lgl_oi));
208
209         if (index == 0) {
210                 CERROR("Can't cancel index 0 which is header\n");
211                 RETURN(-EINVAL);
212         }
213
214         LASSERT(loghandle != NULL);
215         LASSERT(loghandle->lgh_ctxt != NULL);
216         LASSERT(loghandle->lgh_obj != NULL);
217
218         dt = lu2dt_dev(loghandle->lgh_obj->do_lu.lo_dev);
219
220         th = dt_trans_create(env, dt);
221         if (IS_ERR(th))
222                 RETURN(PTR_ERR(th));
223
224         rc = llog_declare_write_rec(env, loghandle, &llh->llh_hdr, index, th);
225         if (rc < 0)
226                 GOTO(out_trans, rc);
227
228         if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY)) {
229                 rc = llog_declare_destroy(env, loghandle, th);
230                 if (rc < 0)
231                         GOTO(out_trans, rc);
232         }
233
234         th->th_wait_submit = 1;
235         rc = dt_trans_start_local(env, dt, th);
236         if (rc < 0)
237                 GOTO(out_trans, rc);
238
239         down_write(&loghandle->lgh_lock);
240         /* clear bitmap */
241         mutex_lock(&loghandle->lgh_hdr_mutex);
242         if (!ext2_clear_bit(index, LLOG_HDR_BITMAP(llh))) {
243                 CDEBUG(D_RPCTRACE, "Catalog index %u already clear?\n", index);
244                 GOTO(out_unlock, rc);
245         }
246
247         loghandle->lgh_hdr->llh_count--;
248         subtract_count = true;
249         /* Pass this index to llog_osd_write_rec(), which will use the index
250          * to only update the necesary bitmap. */
251         lgi->lgi_cookie.lgc_index = index;
252         /* update header */
253         rc = llog_write_rec(env, loghandle, &llh->llh_hdr, &lgi->lgi_cookie,
254                             LLOG_HEADER_IDX, th);
255         if (rc != 0)
256                 GOTO(out_unlock, rc);
257
258         if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
259             (llh->llh_count == 1) &&
260             ((loghandle->lgh_last_idx == LLOG_HDR_BITMAP_SIZE(llh) - 1) ||
261              (loghandle->u.phd.phd_cat_handle != NULL &&
262               loghandle->u.phd.phd_cat_handle->u.chd.chd_current_log !=
263                 loghandle))) {
264                 /* never try to destroy it again */
265                 llh->llh_flags &= ~LLOG_F_ZAP_WHEN_EMPTY;
266                 rc = llog_trans_destroy(env, loghandle, th);
267                 if (rc < 0) {
268                         /* Sigh, can not destroy the final plain llog, but
269                          * the bitmap has been clearly, so the record can not
270                          * be accessed anymore, let's return 0 for now, and
271                          * the orphan will be handled by LFSCK. */
272                         CERROR("%s: can't destroy empty llog #"DOSTID
273                                "#%08x: rc = %d\n",
274                                loghandle->lgh_ctxt->loc_obd->obd_name,
275                                POSTID(&loghandle->lgh_id.lgl_oi),
276                                loghandle->lgh_id.lgl_ogen, rc);
277                         GOTO(out_unlock, rc);
278                 }
279                 rc = LLOG_DEL_PLAIN;
280         }
281
282 out_unlock:
283         mutex_unlock(&loghandle->lgh_hdr_mutex);
284         up_write(&loghandle->lgh_lock);
285 out_trans:
286         rc1 = dt_trans_stop(env, dt, th);
287         if (rc == 0)
288                 rc = rc1;
289         if (rc < 0 && subtract_count) {
290                 mutex_lock(&loghandle->lgh_hdr_mutex);
291                 loghandle->lgh_hdr->llh_count++;
292                 ext2_set_bit(index, LLOG_HDR_BITMAP(llh));
293                 mutex_unlock(&loghandle->lgh_hdr_mutex);
294         }
295         RETURN(rc);
296 }
297
298 int llog_read_header(const struct lu_env *env, struct llog_handle *handle,
299                      const struct obd_uuid *uuid)
300 {
301         struct llog_operations *lop;
302         int rc;
303         ENTRY;
304
305         rc = llog_handle2ops(handle, &lop);
306         if (rc)
307                 RETURN(rc);
308
309         if (lop->lop_read_header == NULL)
310                 RETURN(-EOPNOTSUPP);
311
312         rc = lop->lop_read_header(env, handle);
313         if (rc == LLOG_EEMPTY) {
314                 struct llog_log_hdr *llh = handle->lgh_hdr;
315
316                 /* lrh_len should be initialized in llog_init_handle */
317                 handle->lgh_last_idx = 0; /* header is record with index 0 */
318                 handle->lgh_write_offset = 0;
319                 llh->llh_count = 1;         /* for the header record */
320                 llh->llh_hdr.lrh_type = LLOG_HDR_MAGIC;
321                 LASSERT(handle->lgh_ctxt->loc_chunk_size >=
322                                                 LLOG_MIN_CHUNK_SIZE);
323                 llh->llh_hdr.lrh_len = handle->lgh_ctxt->loc_chunk_size;
324                 llh->llh_hdr.lrh_index = 0;
325                 llh->llh_timestamp = cfs_time_current_sec();
326                 if (uuid)
327                         memcpy(&llh->llh_tgtuuid, uuid,
328                                sizeof(llh->llh_tgtuuid));
329                 llh->llh_bitmap_offset = offsetof(typeof(*llh), llh_bitmap);
330                 /* Since update llog header might also call this function,
331                  * let's reset the bitmap to 0 here */
332                 memset(LLOG_HDR_BITMAP(llh), 0, llh->llh_hdr.lrh_len -
333                                                 llh->llh_bitmap_offset -
334                                                 sizeof(llh->llh_tail));
335                 ext2_set_bit(0, LLOG_HDR_BITMAP(llh));
336                 LLOG_HDR_TAIL(llh)->lrt_len = llh->llh_hdr.lrh_len;
337                 LLOG_HDR_TAIL(llh)->lrt_index = llh->llh_hdr.lrh_index;
338                 rc = 0;
339         }
340         RETURN(rc);
341 }
342 EXPORT_SYMBOL(llog_read_header);
343
344 int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
345                      int flags, struct obd_uuid *uuid)
346 {
347         struct llog_log_hdr     *llh;
348         enum llog_flag           fmt = flags & LLOG_F_EXT_MASK;
349         int                      rc;
350         int                     chunk_size = handle->lgh_ctxt->loc_chunk_size;
351         ENTRY;
352
353         LASSERT(handle->lgh_hdr == NULL);
354
355         LASSERT(chunk_size >= LLOG_MIN_CHUNK_SIZE);
356         OBD_ALLOC_LARGE(llh, chunk_size);
357         if (llh == NULL)
358                 RETURN(-ENOMEM);
359
360         handle->lgh_hdr = llh;
361         handle->lgh_hdr_size = chunk_size;
362         /* first assign flags to use llog_client_ops */
363         llh->llh_flags = flags;
364         rc = llog_read_header(env, handle, uuid);
365         if (rc == 0) {
366                 if (unlikely((llh->llh_flags & LLOG_F_IS_PLAIN &&
367                               flags & LLOG_F_IS_CAT) ||
368                              (llh->llh_flags & LLOG_F_IS_CAT &&
369                               flags & LLOG_F_IS_PLAIN))) {
370                         CERROR("%s: llog type is %s but initializing %s\n",
371                                handle->lgh_ctxt->loc_obd->obd_name,
372                                llh->llh_flags & LLOG_F_IS_CAT ?
373                                "catalog" : "plain",
374                                flags & LLOG_F_IS_CAT ? "catalog" : "plain");
375                         GOTO(out, rc = -EINVAL);
376                 } else if (llh->llh_flags &
377                            (LLOG_F_IS_PLAIN | LLOG_F_IS_CAT)) {
378                         /*
379                          * it is possible to open llog without specifying llog
380                          * type so it is taken from llh_flags
381                          */
382                         flags = llh->llh_flags;
383                 } else {
384                         /* for some reason the llh_flags has no type set */
385                         CERROR("llog type is not specified!\n");
386                         GOTO(out, rc = -EINVAL);
387                 }
388                 if (unlikely(uuid &&
389                              !obd_uuid_equals(uuid, &llh->llh_tgtuuid))) {
390                         CERROR("%s: llog uuid mismatch: %s/%s\n",
391                                handle->lgh_ctxt->loc_obd->obd_name,
392                                (char *)uuid->uuid,
393                                (char *)llh->llh_tgtuuid.uuid);
394                         GOTO(out, rc = -EEXIST);
395                 }
396         }
397         if (flags & LLOG_F_IS_CAT) {
398                 LASSERT(list_empty(&handle->u.chd.chd_head));
399                 INIT_LIST_HEAD(&handle->u.chd.chd_head);
400                 llh->llh_size = sizeof(struct llog_logid_rec);
401                 llh->llh_flags |= LLOG_F_IS_FIXSIZE;
402         } else if (!(flags & LLOG_F_IS_PLAIN)) {
403                 CERROR("%s: unknown flags: %#x (expected %#x or %#x)\n",
404                        handle->lgh_ctxt->loc_obd->obd_name,
405                        flags, LLOG_F_IS_CAT, LLOG_F_IS_PLAIN);
406                 rc = -EINVAL;
407         }
408         llh->llh_flags |= fmt;
409 out:
410         if (rc) {
411                 OBD_FREE_LARGE(llh, chunk_size);
412                 handle->lgh_hdr = NULL;
413         }
414         RETURN(rc);
415 }
416 EXPORT_SYMBOL(llog_init_handle);
417
418 static int llog_process_thread(void *arg)
419 {
420         struct llog_process_info        *lpi = arg;
421         struct llog_handle              *loghandle = lpi->lpi_loghandle;
422         struct llog_log_hdr             *llh = loghandle->lgh_hdr;
423         struct llog_process_cat_data    *cd  = lpi->lpi_catdata;
424         char                            *buf;
425         size_t                           chunk_size;
426         __u64                            cur_offset, tmp_offset;
427         int                              rc = 0, index = 1, last_index;
428         int                              saved_index = 0;
429         int                              last_called_index = 0;
430
431         ENTRY;
432
433         if (llh == NULL)
434                 RETURN(-EINVAL);
435
436         cur_offset = chunk_size = llh->llh_hdr.lrh_len;
437         /* expect chunk_size to be power of two */
438         LASSERT(is_power_of_2(chunk_size));
439
440         OBD_ALLOC_LARGE(buf, chunk_size);
441         if (buf == NULL) {
442                 lpi->lpi_rc = -ENOMEM;
443                 RETURN(0);
444         }
445
446         if (cd != NULL) {
447                 last_called_index = cd->lpcd_first_idx;
448                 index = cd->lpcd_first_idx + 1;
449         }
450         if (cd != NULL && cd->lpcd_last_idx)
451                 last_index = cd->lpcd_last_idx;
452         else
453                 last_index = LLOG_HDR_BITMAP_SIZE(llh) - 1;
454
455         while (rc == 0) {
456                 struct llog_rec_hdr *rec;
457                 off_t chunk_offset;
458                 unsigned int buf_offset = 0;
459                 bool partial_chunk;
460
461                 /* skip records not set in bitmap */
462                 while (index <= last_index &&
463                        !ext2_test_bit(index, LLOG_HDR_BITMAP(llh)))
464                         ++index;
465
466                 /* There are no indices prior the last_index */
467                 if (index > last_index)
468                         break;
469
470                 CDEBUG(D_OTHER, "index: %d last_index %d\n", index,
471                        last_index);
472
473 repeat:
474                 /* get the buf with our target record; avoid old garbage */
475                 memset(buf, 0, chunk_size);
476                 rc = llog_next_block(lpi->lpi_env, loghandle, &saved_index,
477                                      index, &cur_offset, buf, chunk_size);
478                 if (rc != 0)
479                         GOTO(out, rc);
480
481                 /* NB: after llog_next_block() call the cur_offset is the
482                  * offset of the next block after read one.
483                  * The absolute offset of the current chunk is calculated
484                  * from cur_offset value and stored in chunk_offset variable.
485                  */
486                 tmp_offset = cur_offset;
487                 if (do_div(tmp_offset, chunk_size) != 0) {
488                         partial_chunk = true;
489                         chunk_offset = cur_offset & ~(chunk_size - 1);
490                 } else {
491                         partial_chunk = false;
492                         chunk_offset = cur_offset - chunk_size;
493                 }
494
495                 /* NB: when rec->lrh_len is accessed it is already swabbed
496                  * since it is used at the "end" of the loop and the rec
497                  * swabbing is done at the beginning of the loop. */
498                 for (rec = (struct llog_rec_hdr *)(buf + buf_offset);
499                      (char *)rec < buf + chunk_size;
500                      rec = llog_rec_hdr_next(rec)) {
501
502                         CDEBUG(D_OTHER, "processing rec 0x%p type %#x\n",
503                                rec, rec->lrh_type);
504
505                         if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
506                                 lustre_swab_llog_rec(rec);
507
508                         CDEBUG(D_OTHER, "after swabbing, type=%#x idx=%d\n",
509                                rec->lrh_type, rec->lrh_index);
510
511                         /* for partial chunk the end of it is zeroed, check
512                          * for index 0 to distinguish it. */
513                         if (partial_chunk && rec->lrh_index == 0) {
514                                 /* concurrent llog_add() might add new records
515                                  * while llog_processing, check this is not
516                                  * the case and re-read the current chunk
517                                  * otherwise. */
518                                 int records;
519                                 if (index > loghandle->lgh_last_idx)
520                                         GOTO(out, rc = 0);
521                                 /* <2 records means no more records
522                                  * if the last record we processed was
523                                  * the final one, then the underlying
524                                  * object might have been destroyed yet.
525                                  * we better don't access that.. */
526                                 mutex_lock(&loghandle->lgh_hdr_mutex);
527                                 records = loghandle->lgh_hdr->llh_count;
528                                 mutex_unlock(&loghandle->lgh_hdr_mutex);
529                                 if (records <= 1)
530                                         GOTO(out, rc = 0);
531                                 CDEBUG(D_OTHER, "Re-read last llog buffer for "
532                                        "new records, index %u, last %u\n",
533                                        index, loghandle->lgh_last_idx);
534                                 /* save offset inside buffer for the re-read */
535                                 buf_offset = (char *)rec - (char *)buf;
536                                 cur_offset = chunk_offset;
537                                 goto repeat;
538                         }
539
540                         if (rec->lrh_len == 0 || rec->lrh_len > chunk_size) {
541                                 CWARN("invalid length %d in llog record for "
542                                       "index %d/%d\n", rec->lrh_len,
543                                       rec->lrh_index, index);
544                                 GOTO(out, rc = -EINVAL);
545                         }
546
547                         if (rec->lrh_index < index) {
548                                 CDEBUG(D_OTHER, "skipping lrh_index %d\n",
549                                        rec->lrh_index);
550                                 continue;
551                         }
552
553                         if (rec->lrh_index != index) {
554                                 CERROR("%s: Invalid record: index %u but "
555                                        "expected %u\n",
556                                        loghandle->lgh_ctxt->loc_obd->obd_name,
557                                        rec->lrh_index, index);
558                                 GOTO(out, rc = -ERANGE);
559                         }
560
561                         CDEBUG(D_OTHER,
562                                "lrh_index: %d lrh_len: %d (%d remains)\n",
563                                rec->lrh_index, rec->lrh_len,
564                                (int)(buf + chunk_size - (char *)rec));
565
566                         loghandle->lgh_cur_idx = rec->lrh_index;
567                         loghandle->lgh_cur_offset = (char *)rec - (char *)buf +
568                                                     chunk_offset;
569
570                         /* if set, process the callback on this record */
571                         if (ext2_test_bit(index, LLOG_HDR_BITMAP(llh))) {
572                                 rc = lpi->lpi_cb(lpi->lpi_env, loghandle, rec,
573                                                  lpi->lpi_cbdata);
574                                 last_called_index = index;
575                                 if (rc == LLOG_PROC_BREAK) {
576                                         GOTO(out, rc);
577                                 } else if (rc == LLOG_DEL_RECORD) {
578                                         rc = llog_cancel_rec(lpi->lpi_env,
579                                                              loghandle,
580                                                              rec->lrh_index);
581                                 }
582                                 if (rc)
583                                         GOTO(out, rc);
584                         }
585                         /* exit if the last index is reached */
586                         if (index >= last_index)
587                                 GOTO(out, rc = 0);
588                         ++index;
589                 }
590         }
591
592 out:
593         if (cd != NULL)
594                 cd->lpcd_last_idx = last_called_index;
595
596         if (unlikely(rc == -EIO && loghandle->lgh_obj != NULL)) {
597                 if (dt_object_remote(loghandle->lgh_obj)) {
598                         /* If it is remote object, then -EIO might means
599                          * disconnection or eviction, let's return -EAGAIN,
600                          * so for update recovery log processing, it will
601                          * retry until the umount or abort recovery, see
602                          * lod_sub_recovery_thread() */
603                         CERROR("%s retry remote llog process\n",
604                                loghandle->lgh_ctxt->loc_obd->obd_name);
605                         rc = -EAGAIN;
606                 } else {
607                         /* something bad happened to the processing of a local
608                          * llog file, probably I/O error or the log got
609                          * corrupted to be able to finally release the log we
610                          * discard any remaining bits in the header */
611                         CERROR("Local llog found corrupted\n");
612                         while (index <= last_index) {
613                                 if (ext2_test_bit(index,
614                                                   LLOG_HDR_BITMAP(llh)) != 0)
615                                         llog_cancel_rec(lpi->lpi_env, loghandle,
616                                                         index);
617                                 index++;
618                         }
619                         rc = 0;
620                 }
621         }
622
623         OBD_FREE_LARGE(buf, chunk_size);
624         lpi->lpi_rc = rc;
625         return 0;
626 }
627
628 static int llog_process_thread_daemonize(void *arg)
629 {
630         struct llog_process_info        *lpi = arg;
631         struct lu_env                    env;
632         int                              rc;
633
634         unshare_fs_struct();
635
636         /* client env has no keys, tags is just 0 */
637         rc = lu_env_init(&env, LCT_LOCAL | LCT_MG_THREAD);
638         if (rc)
639                 goto out;
640         lpi->lpi_env = &env;
641
642         rc = llog_process_thread(arg);
643
644         lu_env_fini(&env);
645 out:
646         complete(&lpi->lpi_completion);
647         return rc;
648 }
649
650 int llog_process_or_fork(const struct lu_env *env,
651                          struct llog_handle *loghandle,
652                          llog_cb_t cb, void *data, void *catdata, bool fork)
653 {
654         struct llog_process_info *lpi;
655         int                      rc;
656
657         ENTRY;
658
659         OBD_ALLOC_PTR(lpi);
660         if (lpi == NULL) {
661                 CERROR("cannot alloc pointer\n");
662                 RETURN(-ENOMEM);
663         }
664         lpi->lpi_loghandle = loghandle;
665         lpi->lpi_cb        = cb;
666         lpi->lpi_cbdata    = data;
667         lpi->lpi_catdata   = catdata;
668
669         if (fork) {
670                 struct task_struct *task;
671
672                 /* The new thread can't use parent env,
673                  * init the new one in llog_process_thread_daemonize. */
674                 lpi->lpi_env = NULL;
675                 init_completion(&lpi->lpi_completion);
676                 task = kthread_run(llog_process_thread_daemonize, lpi,
677                                    "llog_process_thread");
678                 if (IS_ERR(task)) {
679                         rc = PTR_ERR(task);
680                         CERROR("%s: cannot start thread: rc = %d\n",
681                                loghandle->lgh_ctxt->loc_obd->obd_name, rc);
682                         GOTO(out_lpi, rc);
683                 }
684                 wait_for_completion(&lpi->lpi_completion);
685         } else {
686                 lpi->lpi_env = env;
687                 llog_process_thread(lpi);
688         }
689         rc = lpi->lpi_rc;
690
691 out_lpi:
692         OBD_FREE_PTR(lpi);
693         RETURN(rc);
694 }
695 EXPORT_SYMBOL(llog_process_or_fork);
696
697 int llog_process(const struct lu_env *env, struct llog_handle *loghandle,
698                  llog_cb_t cb, void *data, void *catdata)
699 {
700         int rc;
701         rc = llog_process_or_fork(env, loghandle, cb, data, catdata, true);
702         return rc == LLOG_DEL_PLAIN ? 0 : rc;
703 }
704 EXPORT_SYMBOL(llog_process);
705
706 int llog_reverse_process(const struct lu_env *env,
707                          struct llog_handle *loghandle, llog_cb_t cb,
708                          void *data, void *catdata)
709 {
710         struct llog_log_hdr *llh = loghandle->lgh_hdr;
711         struct llog_process_cat_data *cd = catdata;
712         void *buf;
713         int rc = 0, first_index = 1, index, idx;
714         __u32   chunk_size = llh->llh_hdr.lrh_len;
715         ENTRY;
716
717         OBD_ALLOC_LARGE(buf, chunk_size);
718         if (buf == NULL)
719                 RETURN(-ENOMEM);
720
721         if (cd != NULL)
722                 first_index = cd->lpcd_first_idx + 1;
723         if (cd != NULL && cd->lpcd_last_idx)
724                 index = cd->lpcd_last_idx;
725         else
726                 index = LLOG_HDR_BITMAP_SIZE(llh) - 1;
727
728         while (rc == 0) {
729                 struct llog_rec_hdr *rec;
730                 struct llog_rec_tail *tail;
731
732                 /* skip records not set in bitmap */
733                 while (index >= first_index &&
734                        !ext2_test_bit(index, LLOG_HDR_BITMAP(llh)))
735                         --index;
736
737                 LASSERT(index >= first_index - 1);
738                 if (index == first_index - 1)
739                         break;
740
741                 /* get the buf with our target record; avoid old garbage */
742                 memset(buf, 0, chunk_size);
743                 rc = llog_prev_block(env, loghandle, index, buf, chunk_size);
744                 if (rc)
745                         GOTO(out, rc);
746
747                 rec = buf;
748                 idx = rec->lrh_index;
749                 CDEBUG(D_RPCTRACE, "index %u : idx %u\n", index, idx);
750                 while (idx < index) {
751                         rec = (void *)rec + rec->lrh_len;
752                         if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
753                                 lustre_swab_llog_rec(rec);
754                         idx ++;
755                 }
756                 LASSERT(idx == index);
757                 tail = (void *)rec + rec->lrh_len - sizeof(*tail);
758
759                 /* process records in buffer, starting where we found one */
760                 while ((void *)tail > buf) {
761                         if (tail->lrt_index == 0)
762                                 GOTO(out, rc = 0); /* no more records */
763
764                         /* if set, process the callback on this record */
765                         if (ext2_test_bit(index, LLOG_HDR_BITMAP(llh))) {
766                                 rec = (void *)tail - tail->lrt_len +
767                                       sizeof(*tail);
768
769                                 rc = cb(env, loghandle, rec, data);
770                                 if (rc == LLOG_PROC_BREAK) {
771                                         GOTO(out, rc);
772                                 } else if (rc == LLOG_DEL_RECORD) {
773                                         rc = llog_cancel_rec(env, loghandle,
774                                                              tail->lrt_index);
775                                 }
776                                 if (rc)
777                                         GOTO(out, rc);
778                         }
779
780                         /* previous record, still in buffer? */
781                         --index;
782                         if (index < first_index)
783                                 GOTO(out, rc = 0);
784                         tail = (void *)tail - tail->lrt_len;
785                 }
786         }
787
788 out:
789         if (buf != NULL)
790                 OBD_FREE_LARGE(buf, chunk_size);
791         RETURN(rc);
792 }
793 EXPORT_SYMBOL(llog_reverse_process);
794
795 /**
796  * new llog API
797  *
798  * API functions:
799  *      llog_open - open llog, may not exist
800  *      llog_exist - check if llog exists
801  *      llog_close - close opened llog, pair for open, frees llog_handle
802  *      llog_declare_create - declare llog creation
803  *      llog_create - create new llog on disk, need transaction handle
804  *      llog_declare_write_rec - declaration of llog write
805  *      llog_write_rec - write llog record on disk, need transaction handle
806  *      llog_declare_add - declare llog catalog record addition
807  *      llog_add - add llog record in catalog, need transaction handle
808  */
809 int llog_exist(struct llog_handle *loghandle)
810 {
811         struct llog_operations  *lop;
812         int                      rc;
813
814         ENTRY;
815
816         rc = llog_handle2ops(loghandle, &lop);
817         if (rc)
818                 RETURN(rc);
819         if (lop->lop_exist == NULL)
820                 RETURN(-EOPNOTSUPP);
821
822         rc = lop->lop_exist(loghandle);
823         RETURN(rc);
824 }
825 EXPORT_SYMBOL(llog_exist);
826
827 int llog_declare_create(const struct lu_env *env,
828                         struct llog_handle *loghandle, struct thandle *th)
829 {
830         struct llog_operations  *lop;
831         int                      raised, rc;
832
833         ENTRY;
834
835         rc = llog_handle2ops(loghandle, &lop);
836         if (rc)
837                 RETURN(rc);
838         if (lop->lop_declare_create == NULL)
839                 RETURN(-EOPNOTSUPP);
840
841         raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
842         if (!raised)
843                 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
844         rc = lop->lop_declare_create(env, loghandle, th);
845         if (!raised)
846                 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
847         RETURN(rc);
848 }
849
850 int llog_create(const struct lu_env *env, struct llog_handle *handle,
851                 struct thandle *th)
852 {
853         struct llog_operations  *lop;
854         int                      raised, rc;
855
856         ENTRY;
857
858         rc = llog_handle2ops(handle, &lop);
859         if (rc)
860                 RETURN(rc);
861         if (lop->lop_create == NULL)
862                 RETURN(-EOPNOTSUPP);
863
864         raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
865         if (!raised)
866                 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
867         rc = lop->lop_create(env, handle, th);
868         if (!raised)
869                 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
870         RETURN(rc);
871 }
872
873 int llog_declare_write_rec(const struct lu_env *env,
874                            struct llog_handle *handle,
875                            struct llog_rec_hdr *rec, int idx,
876                            struct thandle *th)
877 {
878         struct llog_operations  *lop;
879         int                      raised, rc;
880
881         ENTRY;
882
883         rc = llog_handle2ops(handle, &lop);
884         if (rc)
885                 RETURN(rc);
886         LASSERT(lop);
887         if (lop->lop_declare_write_rec == NULL)
888                 RETURN(-EOPNOTSUPP);
889
890         raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
891         if (!raised)
892                 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
893         rc = lop->lop_declare_write_rec(env, handle, rec, idx, th);
894         if (!raised)
895                 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
896         RETURN(rc);
897 }
898
899 int llog_write_rec(const struct lu_env *env, struct llog_handle *handle,
900                    struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
901                    int idx, struct thandle *th)
902 {
903         struct llog_operations  *lop;
904         int                      raised, rc, buflen;
905
906         ENTRY;
907
908         /* API sanity checks */
909         if (handle == NULL) {
910                 CERROR("loghandle is missed\n");
911                 RETURN(-EPROTO);
912         } else if (handle->lgh_obj == NULL) {
913                 CERROR("loghandle %p with NULL object\n",
914                         handle);
915                 RETURN(-EPROTO);
916         } else if (th == NULL) {
917                 CERROR("%s: missed transaction handle\n",
918                         handle->lgh_obj->do_lu.lo_dev->ld_obd->obd_name);
919                 RETURN(-EPROTO);
920         } else if (handle->lgh_hdr == NULL) {
921                 CERROR("%s: loghandle %p with no header\n",
922                         handle->lgh_obj->do_lu.lo_dev->ld_obd->obd_name,
923                         handle);
924                 RETURN(-EPROTO);
925         }
926
927         rc = llog_handle2ops(handle, &lop);
928         if (rc)
929                 RETURN(rc);
930
931         if (lop->lop_write_rec == NULL)
932                 RETURN(-EOPNOTSUPP);
933
934         buflen = rec->lrh_len;
935         LASSERT(cfs_size_round(buflen) == buflen);
936
937         raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
938         if (!raised)
939                 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
940         rc = lop->lop_write_rec(env, handle, rec, logcookies, idx, th);
941         if (!raised)
942                 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
943         RETURN(rc);
944 }
945
946 int llog_add(const struct lu_env *env, struct llog_handle *lgh,
947              struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
948              struct thandle *th)
949 {
950         int raised, rc;
951
952         ENTRY;
953
954         if (lgh->lgh_logops->lop_add == NULL)
955                 RETURN(-EOPNOTSUPP);
956
957         raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
958         if (!raised)
959                 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
960         rc = lgh->lgh_logops->lop_add(env, lgh, rec, logcookies, th);
961         if (!raised)
962                 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
963         RETURN(rc);
964 }
965 EXPORT_SYMBOL(llog_add);
966
967 int llog_declare_add(const struct lu_env *env, struct llog_handle *lgh,
968                      struct llog_rec_hdr *rec, struct thandle *th)
969 {
970         int raised, rc;
971
972         ENTRY;
973
974         if (lgh->lgh_logops->lop_declare_add == NULL)
975                 RETURN(-EOPNOTSUPP);
976
977         raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
978         if (!raised)
979                 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
980         rc = lgh->lgh_logops->lop_declare_add(env, lgh, rec, th);
981         if (!raised)
982                 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
983         RETURN(rc);
984 }
985 EXPORT_SYMBOL(llog_declare_add);
986
987 /**
988  * Helper function to open llog or create it if doesn't exist.
989  * It hides all transaction handling from caller.
990  */
991 int llog_open_create(const struct lu_env *env, struct llog_ctxt *ctxt,
992                      struct llog_handle **res, struct llog_logid *logid,
993                      char *name)
994 {
995         struct dt_device        *d;
996         struct thandle          *th;
997         int                      rc;
998
999         ENTRY;
1000
1001         rc = llog_open(env, ctxt, res, logid, name, LLOG_OPEN_NEW);
1002         if (rc)
1003                 RETURN(rc);
1004
1005         if (llog_exist(*res))
1006                 RETURN(0);
1007
1008         LASSERT((*res)->lgh_obj != NULL);
1009
1010         d = lu2dt_dev((*res)->lgh_obj->do_lu.lo_dev);
1011
1012         th = dt_trans_create(env, d);
1013         if (IS_ERR(th))
1014                 GOTO(out, rc = PTR_ERR(th));
1015
1016         /* Create update llog object synchronously, which
1017          * happens during inialization process see
1018          * lod_sub_prep_llog(), to make sure the update
1019          * llog object is created before corss-MDT writing
1020          * updates into the llog object */
1021         if (ctxt->loc_flags & LLOG_CTXT_FLAG_NORMAL_FID)
1022                 th->th_sync = 1;
1023
1024         th->th_wait_submit = 1;
1025         rc = llog_declare_create(env, *res, th);
1026         if (rc == 0) {
1027                 rc = dt_trans_start_local(env, d, th);
1028                 if (rc == 0)
1029                         rc = llog_create(env, *res, th);
1030         }
1031         dt_trans_stop(env, d, th);
1032 out:
1033         if (rc)
1034                 llog_close(env, *res);
1035         RETURN(rc);
1036 }
1037 EXPORT_SYMBOL(llog_open_create);
1038
1039 /**
1040  * Helper function to delete existent llog.
1041  */
1042 int llog_erase(const struct lu_env *env, struct llog_ctxt *ctxt,
1043                struct llog_logid *logid, char *name)
1044 {
1045         struct llog_handle      *handle;
1046         int                      rc = 0, rc2;
1047
1048         ENTRY;
1049
1050         /* nothing to erase */
1051         if (name == NULL && logid == NULL)
1052                 RETURN(0);
1053
1054         rc = llog_open(env, ctxt, &handle, logid, name, LLOG_OPEN_EXISTS);
1055         if (rc < 0)
1056                 RETURN(rc);
1057
1058         rc = llog_init_handle(env, handle, LLOG_F_IS_PLAIN, NULL);
1059         if (rc == 0)
1060                 rc = llog_destroy(env, handle);
1061
1062         rc2 = llog_close(env, handle);
1063         if (rc == 0)
1064                 rc = rc2;
1065         RETURN(rc);
1066 }
1067 EXPORT_SYMBOL(llog_erase);
1068
1069 /*
1070  * Helper function for write record in llog.
1071  * It hides all transaction handling from caller.
1072  * Valid only with local llog.
1073  */
1074 int llog_write(const struct lu_env *env, struct llog_handle *loghandle,
1075                struct llog_rec_hdr *rec, int idx)
1076 {
1077         struct dt_device        *dt;
1078         struct thandle          *th;
1079         int                      rc;
1080
1081         ENTRY;
1082
1083         LASSERT(loghandle);
1084         LASSERT(loghandle->lgh_ctxt);
1085         LASSERT(loghandle->lgh_obj != NULL);
1086
1087         dt = lu2dt_dev(loghandle->lgh_obj->do_lu.lo_dev);
1088
1089         th = dt_trans_create(env, dt);
1090         if (IS_ERR(th))
1091                 RETURN(PTR_ERR(th));
1092
1093         rc = llog_declare_write_rec(env, loghandle, rec, idx, th);
1094         if (rc)
1095                 GOTO(out_trans, rc);
1096
1097         th->th_wait_submit = 1;
1098         rc = dt_trans_start_local(env, dt, th);
1099         if (rc)
1100                 GOTO(out_trans, rc);
1101
1102         down_write(&loghandle->lgh_lock);
1103         rc = llog_write_rec(env, loghandle, rec, NULL, idx, th);
1104         up_write(&loghandle->lgh_lock);
1105 out_trans:
1106         dt_trans_stop(env, dt, th);
1107         RETURN(rc);
1108 }
1109 EXPORT_SYMBOL(llog_write);
1110
1111 int llog_open(const struct lu_env *env, struct llog_ctxt *ctxt,
1112               struct llog_handle **lgh, struct llog_logid *logid,
1113               char *name, enum llog_open_param open_param)
1114 {
1115         int      raised;
1116         int      rc;
1117
1118         ENTRY;
1119
1120         LASSERT(ctxt);
1121         LASSERT(ctxt->loc_logops);
1122
1123         if (ctxt->loc_logops->lop_open == NULL) {
1124                 *lgh = NULL;
1125                 RETURN(-EOPNOTSUPP);
1126         }
1127
1128         *lgh = llog_alloc_handle();
1129         if (*lgh == NULL)
1130                 RETURN(-ENOMEM);
1131         (*lgh)->lgh_ctxt = ctxt;
1132         (*lgh)->lgh_logops = ctxt->loc_logops;
1133
1134         raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
1135         if (!raised)
1136                 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
1137         rc = ctxt->loc_logops->lop_open(env, *lgh, logid, name, open_param);
1138         if (!raised)
1139                 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
1140         if (rc) {
1141                 llog_free_handle(*lgh);
1142                 *lgh = NULL;
1143         }
1144         RETURN(rc);
1145 }
1146 EXPORT_SYMBOL(llog_open);
1147
1148 int llog_close(const struct lu_env *env, struct llog_handle *loghandle)
1149 {
1150         struct llog_operations  *lop;
1151         int                      rc;
1152
1153         ENTRY;
1154
1155         rc = llog_handle2ops(loghandle, &lop);
1156         if (rc)
1157                 GOTO(out, rc);
1158         if (lop->lop_close == NULL)
1159                 GOTO(out, rc = -EOPNOTSUPP);
1160         rc = lop->lop_close(env, loghandle);
1161 out:
1162         llog_handle_put(loghandle);
1163         RETURN(rc);
1164 }
1165 EXPORT_SYMBOL(llog_close);
1166
1167 /**
1168  * Helper function to get the llog size in records. It is used by MGS
1169  * mostly to check that config llog exists and contains data.
1170  *
1171  * \param[in] env       execution environment
1172  * \param[in] ctxt      llog context
1173  * \param[in] name      llog name
1174  *
1175  * \retval              true if there are records in llog besides a header
1176  * \retval              false on error or llog without records
1177  */
1178 int llog_is_empty(const struct lu_env *env, struct llog_ctxt *ctxt,
1179                   char *name)
1180 {
1181         struct llog_handle      *llh;
1182         int                      rc = 0;
1183
1184         rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1185         if (rc < 0) {
1186                 if (likely(rc == -ENOENT))
1187                         rc = 0;
1188                 GOTO(out, rc);
1189         }
1190
1191         rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1192         if (rc)
1193                 GOTO(out_close, rc);
1194         rc = llog_get_size(llh);
1195
1196 out_close:
1197         llog_close(env, llh);
1198 out:
1199         /* The header is record 1, the llog is still considered as empty
1200          * if there is only header */
1201         return (rc <= 1);
1202 }
1203 EXPORT_SYMBOL(llog_is_empty);
1204
1205 int llog_copy_handler(const struct lu_env *env, struct llog_handle *llh,
1206                       struct llog_rec_hdr *rec, void *data)
1207 {
1208         struct llog_handle      *copy_llh = data;
1209
1210         /* Append all records */
1211         return llog_write(env, copy_llh, rec, LLOG_NEXT_IDX);
1212 }
1213
1214 /* backup plain llog */
1215 int llog_backup(const struct lu_env *env, struct obd_device *obd,
1216                 struct llog_ctxt *ctxt, struct llog_ctxt *bctxt,
1217                 char *name, char *backup)
1218 {
1219         struct llog_handle      *llh, *bllh;
1220         int                      rc;
1221
1222         ENTRY;
1223
1224         /* open original log */
1225         rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1226         if (rc < 0) {
1227                 /* the -ENOENT case is also reported to the caller
1228                  * but silently so it should handle that if needed.
1229                  */
1230                 if (rc != -ENOENT)
1231                         CERROR("%s: failed to open log %s: rc = %d\n",
1232                                obd->obd_name, name, rc);
1233                 RETURN(rc);
1234         }
1235
1236         rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1237         if (rc)
1238                 GOTO(out_close, rc);
1239
1240         /* Make sure there's no old backup log */
1241         rc = llog_erase(env, bctxt, NULL, backup);
1242         if (rc < 0 && rc != -ENOENT)
1243                 GOTO(out_close, rc);
1244
1245         /* open backup log */
1246         rc = llog_open_create(env, bctxt, &bllh, NULL, backup);
1247         if (rc) {
1248                 CERROR("%s: failed to open backup logfile %s: rc = %d\n",
1249                        obd->obd_name, backup, rc);
1250                 GOTO(out_close, rc);
1251         }
1252
1253         /* check that backup llog is not the same object as original one */
1254         if (llh->lgh_obj == bllh->lgh_obj) {
1255                 CERROR("%s: backup llog %s to itself (%s), objects %p/%p\n",
1256                        obd->obd_name, name, backup, llh->lgh_obj,
1257                        bllh->lgh_obj);
1258                 GOTO(out_backup, rc = -EEXIST);
1259         }
1260
1261         rc = llog_init_handle(env, bllh, LLOG_F_IS_PLAIN, NULL);
1262         if (rc)
1263                 GOTO(out_backup, rc);
1264
1265         /* Copy log record by record */
1266         rc = llog_process_or_fork(env, llh, llog_copy_handler, (void *)bllh,
1267                                   NULL, false);
1268         if (rc)
1269                 CERROR("%s: failed to backup log %s: rc = %d\n",
1270                        obd->obd_name, name, rc);
1271 out_backup:
1272         llog_close(env, bllh);
1273 out_close:
1274         llog_close(env, llh);
1275         RETURN(rc);
1276 }
1277 EXPORT_SYMBOL(llog_backup);
1278
1279 /* Get size of llog */
1280 __u64 llog_size(const struct lu_env *env, struct llog_handle *llh)
1281 {
1282         int rc;
1283         struct lu_attr la;
1284
1285         rc = llh->lgh_obj->do_ops->do_attr_get(env, llh->lgh_obj, &la);
1286         if (rc) {
1287                 CERROR("%s: attr_get failed, rc = %d\n",
1288                        llh->lgh_ctxt->loc_obd->obd_name, rc);
1289                 return 0;
1290         }
1291
1292         return la.la_size;
1293 }
1294 EXPORT_SYMBOL(llog_size);
1295