4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/llog.c
38 * OST<->MDS recovery logging infrastructure.
39 * Invariants in implementation:
40 * - we do not share logs among different OST<->MDS connections, so that
41 * if an OST or MDS fails it need only look at log(s) relevant to itself
43 * Author: Andreas Dilger <adilger@clusterfs.com>
44 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
45 * Author: Mikhail Pershin <tappro@whamcloud.com>
48 #define DEBUG_SUBSYSTEM S_LOG
51 #include <liblustre.h>
54 #include <obd_class.h>
55 #include <lustre_log.h>
56 #include "llog_internal.h"
59 * Allocate a new log or catalog handle
60 * Used inside llog_open().
62 struct llog_handle *llog_alloc_handle(void)
64 struct llog_handle *loghandle;
66 OBD_ALLOC_PTR(loghandle);
67 if (loghandle == NULL)
68 return ERR_PTR(-ENOMEM);
70 init_rwsem(&loghandle->lgh_lock);
71 spin_lock_init(&loghandle->lgh_hdr_lock);
72 CFS_INIT_LIST_HEAD(&loghandle->u.phd.phd_entry);
73 cfs_atomic_set(&loghandle->lgh_refcount, 1);
79 * Free llog handle and header data if exists. Used in llog_close() only
81 void llog_free_handle(struct llog_handle *loghandle)
83 LASSERT(loghandle != NULL);
85 /* failed llog_init_handle */
86 if (!loghandle->lgh_hdr)
89 if (loghandle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)
90 LASSERT(cfs_list_empty(&loghandle->u.phd.phd_entry));
91 else if (loghandle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)
92 LASSERT(cfs_list_empty(&loghandle->u.chd.chd_head));
93 LASSERT(sizeof(*(loghandle->lgh_hdr)) == LLOG_CHUNK_SIZE);
94 OBD_FREE(loghandle->lgh_hdr, LLOG_CHUNK_SIZE);
96 OBD_FREE_PTR(loghandle);
99 void llog_handle_get(struct llog_handle *loghandle)
101 cfs_atomic_inc(&loghandle->lgh_refcount);
104 void llog_handle_put(struct llog_handle *loghandle)
106 LASSERT(cfs_atomic_read(&loghandle->lgh_refcount) > 0);
107 if (cfs_atomic_dec_and_test(&loghandle->lgh_refcount))
108 llog_free_handle(loghandle);
111 /* returns negative on error; 0 if success; 1 if success & log destroyed */
112 int llog_cancel_rec(const struct lu_env *env, struct llog_handle *loghandle,
115 struct llog_log_hdr *llh = loghandle->lgh_hdr;
119 CDEBUG(D_RPCTRACE, "Canceling %d in log "LPX64"\n",
120 index, loghandle->lgh_id.lgl_oid);
123 CERROR("Can't cancel index 0 which is header\n");
127 spin_lock(&loghandle->lgh_hdr_lock);
128 if (!ext2_clear_bit(index, llh->llh_bitmap)) {
129 spin_unlock(&loghandle->lgh_hdr_lock);
130 CDEBUG(D_RPCTRACE, "Catalog index %u already clear?\n", index);
136 if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
137 (llh->llh_count == 1) &&
138 (loghandle->lgh_last_idx == (LLOG_BITMAP_BYTES * 8) - 1)) {
139 spin_unlock(&loghandle->lgh_hdr_lock);
140 rc = llog_destroy(env, loghandle);
142 CERROR("%s: can't destroy empty llog #"LPX64"#"LPX64
144 loghandle->lgh_ctxt->loc_obd->obd_name,
145 loghandle->lgh_id.lgl_oid,
146 loghandle->lgh_id.lgl_oseq,
147 loghandle->lgh_id.lgl_ogen, rc);
152 spin_unlock(&loghandle->lgh_hdr_lock);
154 rc = llog_write(env, loghandle, &llh->llh_hdr, NULL, 0, NULL, 0);
156 CERROR("%s: fail to write header for llog #"LPX64"#"LPX64
158 loghandle->lgh_ctxt->loc_obd->obd_name,
159 loghandle->lgh_id.lgl_oid,
160 loghandle->lgh_id.lgl_oseq,
161 loghandle->lgh_id.lgl_ogen, rc);
166 spin_lock(&loghandle->lgh_hdr_lock);
167 ext2_set_bit(index, llh->llh_bitmap);
169 spin_unlock(&loghandle->lgh_hdr_lock);
172 EXPORT_SYMBOL(llog_cancel_rec);
174 static int llog_read_header(const struct lu_env *env,
175 struct llog_handle *handle,
176 struct obd_uuid *uuid)
178 struct llog_operations *lop;
181 rc = llog_handle2ops(handle, &lop);
185 if (lop->lop_read_header == NULL)
188 rc = lop->lop_read_header(env, handle);
189 if (rc == LLOG_EEMPTY) {
190 struct llog_log_hdr *llh = handle->lgh_hdr;
192 handle->lgh_last_idx = 0; /* header is record with index 0 */
193 llh->llh_count = 1; /* for the header record */
194 llh->llh_hdr.lrh_type = LLOG_HDR_MAGIC;
195 llh->llh_hdr.lrh_len = llh->llh_tail.lrt_len = LLOG_CHUNK_SIZE;
196 llh->llh_hdr.lrh_index = llh->llh_tail.lrt_index = 0;
197 llh->llh_timestamp = cfs_time_current_sec();
199 memcpy(&llh->llh_tgtuuid, uuid,
200 sizeof(llh->llh_tgtuuid));
201 llh->llh_bitmap_offset = offsetof(typeof(*llh), llh_bitmap);
202 ext2_set_bit(0, llh->llh_bitmap);
208 int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
209 int flags, struct obd_uuid *uuid)
211 struct llog_log_hdr *llh;
215 LASSERT(handle->lgh_hdr == NULL);
220 handle->lgh_hdr = llh;
221 /* first assign flags to use llog_client_ops */
222 llh->llh_flags = flags;
223 rc = llog_read_header(env, handle, uuid);
225 if (unlikely((llh->llh_flags & LLOG_F_IS_PLAIN &&
226 flags & LLOG_F_IS_CAT) ||
227 (llh->llh_flags & LLOG_F_IS_CAT &&
228 flags & LLOG_F_IS_PLAIN))) {
229 CERROR("%s: llog type is %s but initializing %s\n",
230 handle->lgh_ctxt->loc_obd->obd_name,
231 llh->llh_flags & LLOG_F_IS_CAT ?
233 flags & LLOG_F_IS_CAT ? "catalog" : "plain");
234 GOTO(out, rc = -EINVAL);
235 } else if (llh->llh_flags &
236 (LLOG_F_IS_PLAIN | LLOG_F_IS_CAT)) {
238 * it is possible to open llog without specifying llog
239 * type so it is taken from llh_flags
241 flags = llh->llh_flags;
243 /* for some reason the llh_flags has no type set */
244 CERROR("llog type is not specified!\n");
245 GOTO(out, rc = -EINVAL);
248 !obd_uuid_equals(uuid, &llh->llh_tgtuuid))) {
249 CERROR("%s: llog uuid mismatch: %s/%s\n",
250 handle->lgh_ctxt->loc_obd->obd_name,
252 (char *)llh->llh_tgtuuid.uuid);
253 GOTO(out, rc = -EEXIST);
256 if (flags & LLOG_F_IS_CAT) {
257 LASSERT(cfs_list_empty(&handle->u.chd.chd_head));
258 CFS_INIT_LIST_HEAD(&handle->u.chd.chd_head);
259 llh->llh_size = sizeof(struct llog_logid_rec);
260 } else if (!(flags & LLOG_F_IS_PLAIN)) {
261 CERROR("%s: unknown flags: %#x (expected %#x or %#x)\n",
262 handle->lgh_ctxt->loc_obd->obd_name,
263 flags, LLOG_F_IS_CAT, LLOG_F_IS_PLAIN);
269 handle->lgh_hdr = NULL;
273 EXPORT_SYMBOL(llog_init_handle);
275 int llog_copy_handler(const struct lu_env *env,
276 struct llog_handle *llh,
277 struct llog_rec_hdr *rec,
280 struct llog_rec_hdr local_rec = *rec;
281 struct llog_handle *local_llh = (struct llog_handle *)data;
282 char *cfg_buf = (char*) (rec + 1);
283 struct lustre_cfg *lcfg;
287 /* Append all records */
288 local_rec.lrh_len -= sizeof(*rec) + sizeof(struct llog_rec_tail);
289 rc = llog_write(env, local_llh, &local_rec, NULL, 0,
290 (void *)cfg_buf, -1);
292 lcfg = (struct lustre_cfg *)cfg_buf;
293 CDEBUG(D_INFO, "idx=%d, rc=%d, len=%d, cmd %x %s %s\n",
294 rec->lrh_index, rc, rec->lrh_len, lcfg->lcfg_command,
295 lustre_cfg_string(lcfg, 0), lustre_cfg_string(lcfg, 1));
299 EXPORT_SYMBOL(llog_copy_handler);
301 static int llog_process_thread(void *arg)
303 struct llog_process_info *lpi = arg;
304 struct llog_handle *loghandle = lpi->lpi_loghandle;
305 struct llog_log_hdr *llh = loghandle->lgh_hdr;
306 struct llog_process_cat_data *cd = lpi->lpi_catdata;
308 __u64 cur_offset = LLOG_CHUNK_SIZE;
310 int rc = 0, index = 1, last_index;
312 int last_called_index = 0;
318 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
320 lpi->lpi_rc = -ENOMEM;
325 last_called_index = cd->lpcd_first_idx;
326 index = cd->lpcd_first_idx + 1;
328 if (cd != NULL && cd->lpcd_last_idx)
329 last_index = cd->lpcd_last_idx;
331 last_index = LLOG_BITMAP_BYTES * 8 - 1;
334 struct llog_rec_hdr *rec;
336 /* skip records not set in bitmap */
337 while (index <= last_index &&
338 !ext2_test_bit(index, llh->llh_bitmap))
341 LASSERT(index <= last_index + 1);
342 if (index == last_index + 1)
345 CDEBUG(D_OTHER, "index: %d last_index %d\n",
348 /* get the buf with our target record; avoid old garbage */
349 memset(buf, 0, LLOG_CHUNK_SIZE);
350 last_offset = cur_offset;
351 rc = llog_next_block(lpi->lpi_env, loghandle, &saved_index,
352 index, &cur_offset, buf, LLOG_CHUNK_SIZE);
356 /* NB: when rec->lrh_len is accessed it is already swabbed
357 * since it is used at the "end" of the loop and the rec
358 * swabbing is done at the beginning of the loop. */
359 for (rec = (struct llog_rec_hdr *)buf;
360 (char *)rec < buf + LLOG_CHUNK_SIZE;
361 rec = (struct llog_rec_hdr *)((char *)rec + rec->lrh_len)){
363 CDEBUG(D_OTHER, "processing rec 0x%p type %#x\n",
366 if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
367 lustre_swab_llog_rec(rec);
369 CDEBUG(D_OTHER, "after swabbing, type=%#x idx=%d\n",
370 rec->lrh_type, rec->lrh_index);
372 if (rec->lrh_index == 0) {
373 /* probably another rec just got added? */
374 if (index <= loghandle->lgh_last_idx)
375 GOTO(repeat, rc = 0);
376 GOTO(out, rc = 0); /* no more records */
378 if (rec->lrh_len == 0 ||
379 rec->lrh_len > LLOG_CHUNK_SIZE) {
380 CWARN("invalid length %d in llog record for "
381 "index %d/%d\n", rec->lrh_len,
382 rec->lrh_index, index);
383 GOTO(out, rc = -EINVAL);
386 if (rec->lrh_index < index) {
387 CDEBUG(D_OTHER, "skipping lrh_index %d\n",
393 "lrh_index: %d lrh_len: %d (%d remains)\n",
394 rec->lrh_index, rec->lrh_len,
395 (int)(buf + LLOG_CHUNK_SIZE - (char *)rec));
397 loghandle->lgh_cur_idx = rec->lrh_index;
398 loghandle->lgh_cur_offset = (char *)rec - (char *)buf +
401 /* if set, process the callback on this record */
402 if (ext2_test_bit(index, llh->llh_bitmap)) {
403 rc = lpi->lpi_cb(lpi->lpi_env, loghandle, rec,
405 last_called_index = index;
406 if (rc == LLOG_PROC_BREAK) {
408 } else if (rc == LLOG_DEL_RECORD) {
409 llog_cancel_rec(lpi->lpi_env,
417 CDEBUG(D_OTHER, "Skipped index %d\n", index);
420 /* next record, still in buffer? */
422 if (index > last_index)
429 cd->lpcd_last_idx = last_called_index;
431 OBD_FREE(buf, LLOG_CHUNK_SIZE);
437 static int llog_process_thread_daemonize(void *arg)
439 struct llog_process_info *lpi = arg;
443 cfs_daemonize_ctxt("llog_process_thread");
445 /* client env has no keys, tags is just 0 */
446 rc = lu_env_init(&env, LCT_LOCAL | LCT_MG_THREAD);
451 rc = llog_process_thread(arg);
455 complete(&lpi->lpi_completion);
460 int llog_process_or_fork(const struct lu_env *env,
461 struct llog_handle *loghandle,
462 llog_cb_t cb, void *data, void *catdata, bool fork)
464 struct llog_process_info *lpi;
471 CERROR("cannot alloc pointer\n");
474 lpi->lpi_loghandle = loghandle;
476 lpi->lpi_cbdata = data;
477 lpi->lpi_catdata = catdata;
481 /* The new thread can't use parent env,
482 * init the new one in llog_process_thread_daemonize. */
484 init_completion(&lpi->lpi_completion);
485 rc = cfs_create_thread(llog_process_thread_daemonize, lpi,
488 CERROR("%s: cannot start thread: rc = %d\n",
489 loghandle->lgh_ctxt->loc_obd->obd_name, rc);
493 wait_for_completion(&lpi->lpi_completion);
496 llog_process_thread(lpi);
500 llog_process_thread(lpi);
506 EXPORT_SYMBOL(llog_process_or_fork);
508 int llog_process(const struct lu_env *env, struct llog_handle *loghandle,
509 llog_cb_t cb, void *data, void *catdata)
511 return llog_process_or_fork(env, loghandle, cb, data, catdata, true);
513 EXPORT_SYMBOL(llog_process);
515 inline int llog_get_size(struct llog_handle *loghandle)
517 if (loghandle && loghandle->lgh_hdr)
518 return loghandle->lgh_hdr->llh_count;
521 EXPORT_SYMBOL(llog_get_size);
523 int llog_reverse_process(const struct lu_env *env,
524 struct llog_handle *loghandle, llog_cb_t cb,
525 void *data, void *catdata)
527 struct llog_log_hdr *llh = loghandle->lgh_hdr;
528 struct llog_process_cat_data *cd = catdata;
530 int rc = 0, first_index = 1, index, idx;
533 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
538 first_index = cd->lpcd_first_idx + 1;
539 if (cd != NULL && cd->lpcd_last_idx)
540 index = cd->lpcd_last_idx;
542 index = LLOG_BITMAP_BYTES * 8 - 1;
545 struct llog_rec_hdr *rec;
546 struct llog_rec_tail *tail;
548 /* skip records not set in bitmap */
549 while (index >= first_index &&
550 !ext2_test_bit(index, llh->llh_bitmap))
553 LASSERT(index >= first_index - 1);
554 if (index == first_index - 1)
557 /* get the buf with our target record; avoid old garbage */
558 memset(buf, 0, LLOG_CHUNK_SIZE);
559 rc = llog_prev_block(env, loghandle, index, buf,
565 idx = rec->lrh_index;
566 CDEBUG(D_RPCTRACE, "index %u : idx %u\n", index, idx);
567 while (idx < index) {
568 rec = (void *)rec + rec->lrh_len;
569 if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
570 lustre_swab_llog_rec(rec);
573 LASSERT(idx == index);
574 tail = (void *)rec + rec->lrh_len - sizeof(*tail);
576 /* process records in buffer, starting where we found one */
577 while ((void *)tail > buf) {
578 if (tail->lrt_index == 0)
579 GOTO(out, rc = 0); /* no more records */
581 /* if set, process the callback on this record */
582 if (ext2_test_bit(index, llh->llh_bitmap)) {
583 rec = (void *)tail - tail->lrt_len +
586 rc = cb(env, loghandle, rec, data);
587 if (rc == LLOG_PROC_BREAK) {
589 } else if (rc == LLOG_DEL_RECORD) {
590 llog_cancel_rec(env, loghandle,
598 /* previous record, still in buffer? */
600 if (index < first_index)
602 tail = (void *)tail - tail->lrt_len;
608 OBD_FREE(buf, LLOG_CHUNK_SIZE);
611 EXPORT_SYMBOL(llog_reverse_process);
617 * llog_open - open llog, may not exist
618 * llog_exist - check if llog exists
619 * llog_close - close opened llog, pair for open, frees llog_handle
620 * llog_declare_create - declare llog creation
621 * llog_create - create new llog on disk, need transaction handle
622 * llog_declare_write_rec - declaration of llog write
623 * llog_write_rec - write llog record on disk, need transaction handle
624 * llog_declare_add - declare llog catalog record addition
625 * llog_add - add llog record in catalog, need transaction handle
627 int llog_exist(struct llog_handle *loghandle)
629 struct llog_operations *lop;
634 rc = llog_handle2ops(loghandle, &lop);
637 if (lop->lop_exist == NULL)
640 rc = lop->lop_exist(loghandle);
643 EXPORT_SYMBOL(llog_exist);
645 int llog_declare_create(const struct lu_env *env,
646 struct llog_handle *loghandle, struct thandle *th)
648 struct llog_operations *lop;
653 rc = llog_handle2ops(loghandle, &lop);
656 if (lop->lop_declare_create == NULL)
659 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
661 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
662 rc = lop->lop_declare_create(env, loghandle, th);
664 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
667 EXPORT_SYMBOL(llog_declare_create);
669 int llog_create(const struct lu_env *env, struct llog_handle *handle,
672 struct llog_operations *lop;
677 rc = llog_handle2ops(handle, &lop);
680 if (lop->lop_create == NULL)
683 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
685 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
686 rc = lop->lop_create(env, handle, th);
688 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
691 EXPORT_SYMBOL(llog_create);
693 int llog_declare_write_rec(const struct lu_env *env,
694 struct llog_handle *handle,
695 struct llog_rec_hdr *rec, int idx,
698 struct llog_operations *lop;
703 rc = llog_handle2ops(handle, &lop);
707 if (lop->lop_declare_write_rec == NULL)
710 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
712 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
713 rc = lop->lop_declare_write_rec(env, handle, rec, idx, th);
715 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
718 EXPORT_SYMBOL(llog_declare_write_rec);
720 int llog_write_rec(const struct lu_env *env, struct llog_handle *handle,
721 struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
722 int numcookies, void *buf, int idx, struct thandle *th)
724 struct llog_operations *lop;
725 int raised, rc, buflen;
729 rc = llog_handle2ops(handle, &lop);
734 if (lop->lop_write_rec == NULL)
738 buflen = rec->lrh_len + sizeof(struct llog_rec_hdr) +
739 sizeof(struct llog_rec_tail);
741 buflen = rec->lrh_len;
742 LASSERT(cfs_size_round(buflen) == buflen);
744 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
746 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
747 rc = lop->lop_write_rec(env, handle, rec, logcookies, numcookies,
750 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
753 EXPORT_SYMBOL(llog_write_rec);
755 int llog_add(const struct lu_env *env, struct llog_handle *lgh,
756 struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
757 void *buf, struct thandle *th)
763 if (lgh->lgh_logops->lop_add == NULL)
766 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
768 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
769 rc = lgh->lgh_logops->lop_add(env, lgh, rec, logcookies, buf, th);
771 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
774 EXPORT_SYMBOL(llog_add);
776 int llog_declare_add(const struct lu_env *env, struct llog_handle *lgh,
777 struct llog_rec_hdr *rec, struct thandle *th)
783 if (lgh->lgh_logops->lop_declare_add == NULL)
786 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
788 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
789 rc = lgh->lgh_logops->lop_declare_add(env, lgh, rec, th);
791 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
794 EXPORT_SYMBOL(llog_declare_add);
797 * Helper function to open llog or create it if doesn't exist.
798 * It hides all transaction handling from caller.
800 int llog_open_create(const struct lu_env *env, struct llog_ctxt *ctxt,
801 struct llog_handle **res, struct llog_logid *logid,
809 rc = llog_open(env, ctxt, res, logid, name, LLOG_OPEN_NEW);
813 if (llog_exist(*res))
816 if ((*res)->lgh_obj != NULL) {
819 d = lu2dt_dev((*res)->lgh_obj->do_lu.lo_dev);
821 th = dt_trans_create(env, d);
823 GOTO(out, rc = PTR_ERR(th));
825 rc = llog_declare_create(env, *res, th);
827 rc = dt_trans_start_local(env, d, th);
829 rc = llog_create(env, *res, th);
831 dt_trans_stop(env, d, th);
833 /* lvfs compat code */
834 LASSERT((*res)->lgh_file == NULL);
835 rc = llog_create(env, *res, NULL);
839 llog_close(env, *res);
842 EXPORT_SYMBOL(llog_open_create);
845 * Helper function to delete existent llog.
847 int llog_erase(const struct lu_env *env, struct llog_ctxt *ctxt,
848 struct llog_logid *logid, char *name)
850 struct llog_handle *handle;
855 /* nothing to erase */
856 if (name == NULL && logid == NULL)
859 rc = llog_open(env, ctxt, &handle, logid, name, LLOG_OPEN_EXISTS);
863 rc = llog_init_handle(env, handle, LLOG_F_IS_PLAIN, NULL);
865 rc = llog_destroy(env, handle);
867 rc2 = llog_close(env, handle);
872 EXPORT_SYMBOL(llog_erase);
875 * Helper function for write record in llog.
876 * It hides all transaction handling from caller.
877 * Valid only with local llog.
879 int llog_write(const struct lu_env *env, struct llog_handle *loghandle,
880 struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
881 int cookiecount, void *buf, int idx)
888 LASSERT(loghandle->lgh_ctxt);
890 if (loghandle->lgh_obj != NULL) {
891 struct dt_device *dt;
894 dt = lu2dt_dev(loghandle->lgh_obj->do_lu.lo_dev);
896 th = dt_trans_create(env, dt);
900 rc = llog_declare_write_rec(env, loghandle, rec, idx, th);
904 rc = dt_trans_start_local(env, dt, th);
908 down_write(&loghandle->lgh_lock);
909 rc = llog_write_rec(env, loghandle, rec, reccookie,
910 cookiecount, buf, idx, th);
911 up_write(&loghandle->lgh_lock);
913 dt_trans_stop(env, dt, th);
914 } else { /* lvfs compatibility */
915 down_write(&loghandle->lgh_lock);
916 rc = llog_write_rec(env, loghandle, rec, reccookie,
917 cookiecount, buf, idx, NULL);
918 up_write(&loghandle->lgh_lock);
922 EXPORT_SYMBOL(llog_write);
924 int llog_open(const struct lu_env *env, struct llog_ctxt *ctxt,
925 struct llog_handle **lgh, struct llog_logid *logid,
926 char *name, enum llog_open_param open_param)
934 LASSERT(ctxt->loc_logops);
936 if (ctxt->loc_logops->lop_open == NULL) {
941 *lgh = llog_alloc_handle();
944 (*lgh)->lgh_ctxt = ctxt;
945 (*lgh)->lgh_logops = ctxt->loc_logops;
947 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
949 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
950 rc = ctxt->loc_logops->lop_open(env, *lgh, logid, name, open_param);
952 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
954 llog_free_handle(*lgh);
959 EXPORT_SYMBOL(llog_open);
961 int llog_close(const struct lu_env *env, struct llog_handle *loghandle)
963 struct llog_operations *lop;
968 rc = llog_handle2ops(loghandle, &lop);
971 if (lop->lop_close == NULL)
972 GOTO(out, rc = -EOPNOTSUPP);
973 rc = lop->lop_close(env, loghandle);
975 llog_handle_put(loghandle);
978 EXPORT_SYMBOL(llog_close);