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 static int llog_process_thread(void *arg)
277 struct llog_process_info *lpi = arg;
278 struct llog_handle *loghandle = lpi->lpi_loghandle;
279 struct llog_log_hdr *llh = loghandle->lgh_hdr;
280 struct llog_process_cat_data *cd = lpi->lpi_catdata;
282 __u64 cur_offset = LLOG_CHUNK_SIZE;
284 int rc = 0, index = 1, last_index;
286 int last_called_index = 0;
292 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
294 lpi->lpi_rc = -ENOMEM;
299 last_called_index = cd->lpcd_first_idx;
300 index = cd->lpcd_first_idx + 1;
302 if (cd != NULL && cd->lpcd_last_idx)
303 last_index = cd->lpcd_last_idx;
305 last_index = LLOG_BITMAP_BYTES * 8 - 1;
308 struct llog_rec_hdr *rec;
310 /* skip records not set in bitmap */
311 while (index <= last_index &&
312 !ext2_test_bit(index, llh->llh_bitmap))
315 LASSERT(index <= last_index + 1);
316 if (index == last_index + 1)
319 CDEBUG(D_OTHER, "index: %d last_index %d\n",
322 /* get the buf with our target record; avoid old garbage */
323 memset(buf, 0, LLOG_CHUNK_SIZE);
324 last_offset = cur_offset;
325 rc = llog_next_block(lpi->lpi_env, loghandle, &saved_index,
326 index, &cur_offset, buf, LLOG_CHUNK_SIZE);
330 /* NB: when rec->lrh_len is accessed it is already swabbed
331 * since it is used at the "end" of the loop and the rec
332 * swabbing is done at the beginning of the loop. */
333 for (rec = (struct llog_rec_hdr *)buf;
334 (char *)rec < buf + LLOG_CHUNK_SIZE;
335 rec = (struct llog_rec_hdr *)((char *)rec + rec->lrh_len)){
337 CDEBUG(D_OTHER, "processing rec 0x%p type %#x\n",
340 if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
341 lustre_swab_llog_rec(rec);
343 CDEBUG(D_OTHER, "after swabbing, type=%#x idx=%d\n",
344 rec->lrh_type, rec->lrh_index);
346 if (rec->lrh_index == 0) {
347 /* probably another rec just got added? */
348 if (index <= loghandle->lgh_last_idx)
349 GOTO(repeat, rc = 0);
350 GOTO(out, rc = 0); /* no more records */
352 if (rec->lrh_len == 0 ||
353 rec->lrh_len > LLOG_CHUNK_SIZE) {
354 CWARN("invalid length %d in llog record for "
355 "index %d/%d\n", rec->lrh_len,
356 rec->lrh_index, index);
357 GOTO(out, rc = -EINVAL);
360 if (rec->lrh_index < index) {
361 CDEBUG(D_OTHER, "skipping lrh_index %d\n",
367 "lrh_index: %d lrh_len: %d (%d remains)\n",
368 rec->lrh_index, rec->lrh_len,
369 (int)(buf + LLOG_CHUNK_SIZE - (char *)rec));
371 loghandle->lgh_cur_idx = rec->lrh_index;
372 loghandle->lgh_cur_offset = (char *)rec - (char *)buf +
375 /* if set, process the callback on this record */
376 if (ext2_test_bit(index, llh->llh_bitmap)) {
377 rc = lpi->lpi_cb(lpi->lpi_env, loghandle, rec,
379 last_called_index = index;
380 if (rc == LLOG_PROC_BREAK) {
382 } else if (rc == LLOG_DEL_RECORD) {
383 llog_cancel_rec(lpi->lpi_env,
391 CDEBUG(D_OTHER, "Skipped index %d\n", index);
394 /* next record, still in buffer? */
396 if (index > last_index)
403 cd->lpcd_last_idx = last_called_index;
405 OBD_FREE(buf, LLOG_CHUNK_SIZE);
411 static int llog_process_thread_daemonize(void *arg)
413 struct llog_process_info *lpi = arg;
417 cfs_daemonize_ctxt("llog_process_thread");
419 /* client env has no keys, tags is just 0 */
420 rc = lu_env_init(&env, LCT_LOCAL);
425 rc = llog_process_thread(arg);
429 complete(&lpi->lpi_completion);
434 int llog_process_or_fork(const struct lu_env *env,
435 struct llog_handle *loghandle,
436 llog_cb_t cb, void *data, void *catdata, bool fork)
438 struct llog_process_info *lpi;
445 CERROR("cannot alloc pointer\n");
448 lpi->lpi_loghandle = loghandle;
450 lpi->lpi_cbdata = data;
451 lpi->lpi_catdata = catdata;
455 /* The new thread can't use parent env,
456 * init the new one in llog_process_thread_daemonize. */
458 init_completion(&lpi->lpi_completion);
459 rc = cfs_create_thread(llog_process_thread_daemonize, lpi,
462 CERROR("%s: cannot start thread: rc = %d\n",
463 loghandle->lgh_ctxt->loc_obd->obd_name, rc);
467 wait_for_completion(&lpi->lpi_completion);
470 llog_process_thread(lpi);
474 llog_process_thread(lpi);
480 EXPORT_SYMBOL(llog_process_or_fork);
482 int llog_process(const struct lu_env *env, struct llog_handle *loghandle,
483 llog_cb_t cb, void *data, void *catdata)
485 return llog_process_or_fork(env, loghandle, cb, data, catdata, true);
487 EXPORT_SYMBOL(llog_process);
489 inline int llog_get_size(struct llog_handle *loghandle)
491 if (loghandle && loghandle->lgh_hdr)
492 return loghandle->lgh_hdr->llh_count;
495 EXPORT_SYMBOL(llog_get_size);
497 int llog_reverse_process(const struct lu_env *env,
498 struct llog_handle *loghandle, llog_cb_t cb,
499 void *data, void *catdata)
501 struct llog_log_hdr *llh = loghandle->lgh_hdr;
502 struct llog_process_cat_data *cd = catdata;
504 int rc = 0, first_index = 1, index, idx;
507 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
512 first_index = cd->lpcd_first_idx + 1;
513 if (cd != NULL && cd->lpcd_last_idx)
514 index = cd->lpcd_last_idx;
516 index = LLOG_BITMAP_BYTES * 8 - 1;
519 struct llog_rec_hdr *rec;
520 struct llog_rec_tail *tail;
522 /* skip records not set in bitmap */
523 while (index >= first_index &&
524 !ext2_test_bit(index, llh->llh_bitmap))
527 LASSERT(index >= first_index - 1);
528 if (index == first_index - 1)
531 /* get the buf with our target record; avoid old garbage */
532 memset(buf, 0, LLOG_CHUNK_SIZE);
533 rc = llog_prev_block(env, loghandle, index, buf,
539 idx = rec->lrh_index;
540 CDEBUG(D_RPCTRACE, "index %u : idx %u\n", index, idx);
541 while (idx < index) {
542 rec = (void *)rec + rec->lrh_len;
543 if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
544 lustre_swab_llog_rec(rec);
547 LASSERT(idx == index);
548 tail = (void *)rec + rec->lrh_len - sizeof(*tail);
550 /* process records in buffer, starting where we found one */
551 while ((void *)tail > buf) {
552 if (tail->lrt_index == 0)
553 GOTO(out, rc = 0); /* no more records */
555 /* if set, process the callback on this record */
556 if (ext2_test_bit(index, llh->llh_bitmap)) {
557 rec = (void *)tail - tail->lrt_len +
560 rc = cb(env, loghandle, rec, data);
561 if (rc == LLOG_PROC_BREAK) {
563 } else if (rc == LLOG_DEL_RECORD) {
564 llog_cancel_rec(env, loghandle,
572 /* previous record, still in buffer? */
574 if (index < first_index)
576 tail = (void *)tail - tail->lrt_len;
582 OBD_FREE(buf, LLOG_CHUNK_SIZE);
585 EXPORT_SYMBOL(llog_reverse_process);
591 * llog_open - open llog, may not exist
592 * llog_exist - check if llog exists
593 * llog_close - close opened llog, pair for open, frees llog_handle
594 * llog_declare_create - declare llog creation
595 * llog_create - create new llog on disk, need transaction handle
596 * llog_declare_write_rec - declaration of llog write
597 * llog_write_rec - write llog record on disk, need transaction handle
598 * llog_declare_add - declare llog catalog record addition
599 * llog_add - add llog record in catalog, need transaction handle
601 int llog_exist(struct llog_handle *loghandle)
603 struct llog_operations *lop;
608 rc = llog_handle2ops(loghandle, &lop);
611 if (lop->lop_exist == NULL)
614 rc = lop->lop_exist(loghandle);
617 EXPORT_SYMBOL(llog_exist);
619 int llog_declare_create(const struct lu_env *env,
620 struct llog_handle *loghandle, struct thandle *th)
622 struct llog_operations *lop;
627 rc = llog_handle2ops(loghandle, &lop);
630 if (lop->lop_declare_create == NULL)
633 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
635 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
636 rc = lop->lop_declare_create(env, loghandle, th);
638 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
641 EXPORT_SYMBOL(llog_declare_create);
643 int llog_create(const struct lu_env *env, struct llog_handle *handle,
646 struct llog_operations *lop;
651 rc = llog_handle2ops(handle, &lop);
654 if (lop->lop_create == NULL)
657 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
659 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
660 rc = lop->lop_create(env, handle, th);
662 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
665 EXPORT_SYMBOL(llog_create);
667 int llog_declare_write_rec(const struct lu_env *env,
668 struct llog_handle *handle,
669 struct llog_rec_hdr *rec, int idx,
672 struct llog_operations *lop;
677 rc = llog_handle2ops(handle, &lop);
681 if (lop->lop_declare_write_rec == NULL)
684 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
686 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
687 rc = lop->lop_declare_write_rec(env, handle, rec, idx, th);
689 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
692 EXPORT_SYMBOL(llog_declare_write_rec);
694 int llog_write_rec(const struct lu_env *env, struct llog_handle *handle,
695 struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
696 int numcookies, void *buf, int idx, struct thandle *th)
698 struct llog_operations *lop;
699 int raised, rc, buflen;
703 rc = llog_handle2ops(handle, &lop);
708 if (lop->lop_write_rec == NULL)
712 buflen = rec->lrh_len + sizeof(struct llog_rec_hdr) +
713 sizeof(struct llog_rec_tail);
715 buflen = rec->lrh_len;
716 LASSERT(cfs_size_round(buflen) == buflen);
718 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
720 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
721 rc = lop->lop_write_rec(env, handle, rec, logcookies, numcookies,
724 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
727 EXPORT_SYMBOL(llog_write_rec);
729 int llog_add(const struct lu_env *env, struct llog_handle *lgh,
730 struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
731 void *buf, struct thandle *th)
737 if (lgh->lgh_logops->lop_add == NULL)
740 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
742 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
743 rc = lgh->lgh_logops->lop_add(env, lgh, rec, logcookies, buf, th);
745 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
748 EXPORT_SYMBOL(llog_add);
750 int llog_declare_add(const struct lu_env *env, struct llog_handle *lgh,
751 struct llog_rec_hdr *rec, struct thandle *th)
757 if (lgh->lgh_logops->lop_declare_add == NULL)
760 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
762 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
763 rc = lgh->lgh_logops->lop_declare_add(env, lgh, rec, th);
765 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
768 EXPORT_SYMBOL(llog_declare_add);
771 * Helper function to open llog or create it if doesn't exist.
772 * It hides all transaction handling from caller.
774 int llog_open_create(const struct lu_env *env, struct llog_ctxt *ctxt,
775 struct llog_handle **res, struct llog_logid *logid,
783 rc = llog_open(env, ctxt, res, logid, name, LLOG_OPEN_NEW);
787 if (llog_exist(*res))
790 if ((*res)->lgh_obj != NULL) {
793 d = lu2dt_dev((*res)->lgh_obj->do_lu.lo_dev);
795 th = dt_trans_create(env, d);
797 GOTO(out, rc = PTR_ERR(th));
799 rc = llog_declare_create(env, *res, th);
801 rc = dt_trans_start_local(env, d, th);
803 rc = llog_create(env, *res, th);
805 dt_trans_stop(env, d, th);
807 /* lvfs compat code */
808 LASSERT((*res)->lgh_file == NULL);
809 rc = llog_create(env, *res, NULL);
813 llog_close(env, *res);
816 EXPORT_SYMBOL(llog_open_create);
819 * Helper function to delete existent llog.
821 int llog_erase(const struct lu_env *env, struct llog_ctxt *ctxt,
822 struct llog_logid *logid, char *name)
824 struct llog_handle *handle;
829 /* nothing to erase */
830 if (name == NULL && logid == NULL)
833 rc = llog_open(env, ctxt, &handle, logid, name, LLOG_OPEN_EXISTS);
837 rc = llog_init_handle(env, handle, LLOG_F_IS_PLAIN, NULL);
839 rc = llog_destroy(env, handle);
841 rc2 = llog_close(env, handle);
846 EXPORT_SYMBOL(llog_erase);
849 * Helper function for write record in llog.
850 * It hides all transaction handling from caller.
851 * Valid only with local llog.
853 int llog_write(const struct lu_env *env, struct llog_handle *loghandle,
854 struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
855 int cookiecount, void *buf, int idx)
862 LASSERT(loghandle->lgh_ctxt);
864 if (loghandle->lgh_obj != NULL) {
865 struct dt_device *dt;
868 dt = lu2dt_dev(loghandle->lgh_obj->do_lu.lo_dev);
870 th = dt_trans_create(env, dt);
874 rc = llog_declare_write_rec(env, loghandle, rec, idx, th);
878 rc = dt_trans_start_local(env, dt, th);
882 down_write(&loghandle->lgh_lock);
883 rc = llog_write_rec(env, loghandle, rec, reccookie,
884 cookiecount, buf, idx, th);
885 up_write(&loghandle->lgh_lock);
887 dt_trans_stop(env, dt, th);
888 } else { /* lvfs compatibility */
889 down_write(&loghandle->lgh_lock);
890 rc = llog_write_rec(env, loghandle, rec, reccookie,
891 cookiecount, buf, idx, NULL);
892 up_write(&loghandle->lgh_lock);
896 EXPORT_SYMBOL(llog_write);
898 int llog_open(const struct lu_env *env, struct llog_ctxt *ctxt,
899 struct llog_handle **lgh, struct llog_logid *logid,
900 char *name, enum llog_open_param open_param)
908 LASSERT(ctxt->loc_logops);
910 if (ctxt->loc_logops->lop_open == NULL) {
915 *lgh = llog_alloc_handle();
918 (*lgh)->lgh_ctxt = ctxt;
919 (*lgh)->lgh_logops = ctxt->loc_logops;
921 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
923 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
924 rc = ctxt->loc_logops->lop_open(env, *lgh, logid, name, open_param);
926 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
928 llog_free_handle(*lgh);
933 EXPORT_SYMBOL(llog_open);
935 int llog_close(const struct lu_env *env, struct llog_handle *loghandle)
937 struct llog_operations *lop;
942 rc = llog_handle2ops(loghandle, &lop);
945 if (lop->lop_close == NULL)
946 GOTO(out, rc = -EOPNOTSUPP);
947 rc = lop->lop_close(env, loghandle);
949 llog_handle_put(loghandle);
952 EXPORT_SYMBOL(llog_close);