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.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lustre/obdclass/llog.c
36 * OST<->MDS recovery logging infrastructure.
37 * Invariants in implementation:
38 * - we do not share logs among different OST<->MDS connections, so that
39 * if an OST or MDS fails it need only look at log(s) relevant to itself
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
43 * Author: Mikhail Pershin <tappro@whamcloud.com>
46 #define DEBUG_SUBSYSTEM S_LOG
49 #include <liblustre.h>
52 #include <obd_class.h>
53 #include <lustre_log.h>
54 #include "llog_internal.h"
57 * Allocate a new log or catalog handle
58 * Used inside llog_open().
60 struct llog_handle *llog_alloc_handle(void)
62 struct llog_handle *loghandle;
64 OBD_ALLOC_PTR(loghandle);
65 if (loghandle == NULL)
66 return ERR_PTR(-ENOMEM);
68 init_rwsem(&loghandle->lgh_lock);
69 spin_lock_init(&loghandle->lgh_hdr_lock);
70 CFS_INIT_LIST_HEAD(&loghandle->u.phd.phd_entry);
76 * Free llog handle and header data if exists. Used in llog_close() only
78 void llog_free_handle(struct llog_handle *loghandle)
83 if (!loghandle->lgh_hdr)
85 if (loghandle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)
86 cfs_list_del_init(&loghandle->u.phd.phd_entry);
87 if (loghandle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)
88 LASSERT(cfs_list_empty(&loghandle->u.chd.chd_head));
89 LASSERT(sizeof(*(loghandle->lgh_hdr)) == LLOG_CHUNK_SIZE);
90 OBD_FREE(loghandle->lgh_hdr, LLOG_CHUNK_SIZE);
93 OBD_FREE_PTR(loghandle);
96 /* returns negative on error; 0 if success; 1 if success & log destroyed */
97 int llog_cancel_rec(const struct lu_env *env, struct llog_handle *loghandle,
100 struct llog_log_hdr *llh = loghandle->lgh_hdr;
104 CDEBUG(D_RPCTRACE, "Canceling %d in log "LPX64"\n",
105 index, loghandle->lgh_id.lgl_oid);
108 CERROR("Can't cancel index 0 which is header\n");
112 spin_lock(&loghandle->lgh_hdr_lock);
113 if (!ext2_clear_bit(index, llh->llh_bitmap)) {
114 spin_unlock(&loghandle->lgh_hdr_lock);
115 CDEBUG(D_RPCTRACE, "Catalog index %u already clear?\n", index);
121 if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
122 (llh->llh_count == 1) &&
123 (loghandle->lgh_last_idx == (LLOG_BITMAP_BYTES * 8) - 1)) {
124 spin_unlock(&loghandle->lgh_hdr_lock);
125 rc = llog_destroy(env, loghandle);
127 CERROR("%s: can't destroy empty llog #"LPX64"#"LPX64
129 loghandle->lgh_ctxt->loc_obd->obd_name,
130 loghandle->lgh_id.lgl_oid,
131 loghandle->lgh_id.lgl_oseq,
132 loghandle->lgh_id.lgl_ogen, rc);
137 spin_unlock(&loghandle->lgh_hdr_lock);
139 rc = llog_write(env, loghandle, &llh->llh_hdr, NULL, 0, NULL, 0);
141 CERROR("%s: fail to write header for llog #"LPX64"#"LPX64
143 loghandle->lgh_ctxt->loc_obd->obd_name,
144 loghandle->lgh_id.lgl_oid,
145 loghandle->lgh_id.lgl_oseq,
146 loghandle->lgh_id.lgl_ogen, rc);
151 spin_lock(&loghandle->lgh_hdr_lock);
152 ext2_set_bit(index, llh->llh_bitmap);
154 spin_unlock(&loghandle->lgh_hdr_lock);
157 EXPORT_SYMBOL(llog_cancel_rec);
159 static int llog_read_header(const struct lu_env *env,
160 struct llog_handle *handle,
161 struct obd_uuid *uuid)
163 struct llog_operations *lop;
166 rc = llog_handle2ops(handle, &lop);
170 if (lop->lop_read_header == NULL)
173 rc = lop->lop_read_header(env, handle);
174 if (rc == LLOG_EEMPTY) {
175 struct llog_log_hdr *llh = handle->lgh_hdr;
177 handle->lgh_last_idx = 0; /* header is record with index 0 */
178 llh->llh_count = 1; /* for the header record */
179 llh->llh_hdr.lrh_type = LLOG_HDR_MAGIC;
180 llh->llh_hdr.lrh_len = llh->llh_tail.lrt_len = LLOG_CHUNK_SIZE;
181 llh->llh_hdr.lrh_index = llh->llh_tail.lrt_index = 0;
182 llh->llh_timestamp = cfs_time_current_sec();
184 memcpy(&llh->llh_tgtuuid, uuid,
185 sizeof(llh->llh_tgtuuid));
186 llh->llh_bitmap_offset = offsetof(typeof(*llh), llh_bitmap);
187 ext2_set_bit(0, llh->llh_bitmap);
193 int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
194 int flags, struct obd_uuid *uuid)
196 struct llog_log_hdr *llh;
200 LASSERT(handle->lgh_hdr == NULL);
205 handle->lgh_hdr = llh;
206 /* first assign flags to use llog_client_ops */
207 llh->llh_flags = flags;
208 rc = llog_read_header(env, handle, uuid);
210 if (unlikely((llh->llh_flags & LLOG_F_IS_PLAIN &&
211 flags & LLOG_F_IS_CAT) ||
212 (llh->llh_flags & LLOG_F_IS_CAT &&
213 flags & LLOG_F_IS_PLAIN))) {
214 CERROR("%s: llog type is %s but initializing %s\n",
215 handle->lgh_ctxt->loc_obd->obd_name,
216 llh->llh_flags & LLOG_F_IS_CAT ?
218 flags & LLOG_F_IS_CAT ? "catalog" : "plain");
219 GOTO(out, rc = -EINVAL);
220 } else if (llh->llh_flags &
221 (LLOG_F_IS_PLAIN | LLOG_F_IS_CAT)) {
223 * it is possible to open llog without specifying llog
224 * type so it is taken from llh_flags
226 flags = llh->llh_flags;
228 /* for some reason the llh_flags has no type set */
229 CERROR("llog type is not specified!\n");
230 GOTO(out, rc = -EINVAL);
233 !obd_uuid_equals(uuid, &llh->llh_tgtuuid))) {
234 CERROR("%s: llog uuid mismatch: %s/%s\n",
235 handle->lgh_ctxt->loc_obd->obd_name,
237 (char *)llh->llh_tgtuuid.uuid);
238 GOTO(out, rc = -EEXIST);
241 if (flags & LLOG_F_IS_CAT) {
242 LASSERT(cfs_list_empty(&handle->u.chd.chd_head));
243 CFS_INIT_LIST_HEAD(&handle->u.chd.chd_head);
244 llh->llh_size = sizeof(struct llog_logid_rec);
245 } else if (!(flags & LLOG_F_IS_PLAIN)) {
246 CERROR("%s: unknown flags: %#x (expected %#x or %#x)\n",
247 handle->lgh_ctxt->loc_obd->obd_name,
248 flags, LLOG_F_IS_CAT, LLOG_F_IS_PLAIN);
254 handle->lgh_hdr = NULL;
258 EXPORT_SYMBOL(llog_init_handle);
260 static int llog_process_thread(void *arg)
262 struct llog_process_info *lpi = arg;
263 struct llog_handle *loghandle = lpi->lpi_loghandle;
264 struct llog_log_hdr *llh = loghandle->lgh_hdr;
265 struct llog_process_cat_data *cd = lpi->lpi_catdata;
267 __u64 cur_offset = LLOG_CHUNK_SIZE;
269 int rc = 0, index = 1, last_index;
271 int last_called_index = 0;
277 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
279 lpi->lpi_rc = -ENOMEM;
284 last_called_index = cd->lpcd_first_idx;
285 index = cd->lpcd_first_idx + 1;
287 if (cd != NULL && cd->lpcd_last_idx)
288 last_index = cd->lpcd_last_idx;
290 last_index = LLOG_BITMAP_BYTES * 8 - 1;
293 struct llog_rec_hdr *rec;
295 /* skip records not set in bitmap */
296 while (index <= last_index &&
297 !ext2_test_bit(index, llh->llh_bitmap))
300 LASSERT(index <= last_index + 1);
301 if (index == last_index + 1)
304 CDEBUG(D_OTHER, "index: %d last_index %d\n",
307 /* get the buf with our target record; avoid old garbage */
308 memset(buf, 0, LLOG_CHUNK_SIZE);
309 last_offset = cur_offset;
310 rc = llog_next_block(lpi->lpi_env, loghandle, &saved_index,
311 index, &cur_offset, buf, LLOG_CHUNK_SIZE);
315 /* NB: when rec->lrh_len is accessed it is already swabbed
316 * since it is used at the "end" of the loop and the rec
317 * swabbing is done at the beginning of the loop. */
318 for (rec = (struct llog_rec_hdr *)buf;
319 (char *)rec < buf + LLOG_CHUNK_SIZE;
320 rec = (struct llog_rec_hdr *)((char *)rec + rec->lrh_len)){
322 CDEBUG(D_OTHER, "processing rec 0x%p type %#x\n",
325 if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
326 lustre_swab_llog_rec(rec);
328 CDEBUG(D_OTHER, "after swabbing, type=%#x idx=%d\n",
329 rec->lrh_type, rec->lrh_index);
331 if (rec->lrh_index == 0) {
332 /* probably another rec just got added? */
333 if (index <= loghandle->lgh_last_idx)
334 GOTO(repeat, rc = 0);
335 GOTO(out, rc = 0); /* no more records */
337 if (rec->lrh_len == 0 ||
338 rec->lrh_len > LLOG_CHUNK_SIZE) {
339 CWARN("invalid length %d in llog record for "
340 "index %d/%d\n", rec->lrh_len,
341 rec->lrh_index, index);
342 GOTO(out, rc = -EINVAL);
345 if (rec->lrh_index < index) {
346 CDEBUG(D_OTHER, "skipping lrh_index %d\n",
352 "lrh_index: %d lrh_len: %d (%d remains)\n",
353 rec->lrh_index, rec->lrh_len,
354 (int)(buf + LLOG_CHUNK_SIZE - (char *)rec));
356 loghandle->lgh_cur_idx = rec->lrh_index;
357 loghandle->lgh_cur_offset = (char *)rec - (char *)buf +
360 /* if set, process the callback on this record */
361 if (ext2_test_bit(index, llh->llh_bitmap)) {
362 rc = lpi->lpi_cb(lpi->lpi_env, loghandle, rec,
364 last_called_index = index;
365 if (rc == LLOG_PROC_BREAK) {
367 } else if (rc == LLOG_DEL_RECORD) {
368 llog_cancel_rec(lpi->lpi_env,
376 CDEBUG(D_OTHER, "Skipped index %d\n", index);
379 /* next record, still in buffer? */
381 if (index > last_index)
388 cd->lpcd_last_idx = last_called_index;
390 OBD_FREE(buf, LLOG_CHUNK_SIZE);
396 static int llog_process_thread_daemonize(void *arg)
398 struct llog_process_info *lpi = arg;
402 cfs_daemonize_ctxt("llog_process_thread");
404 /* client env has no keys, tags is just 0 */
405 rc = lu_env_init(&env, LCT_LOCAL);
410 rc = llog_process_thread(arg);
414 complete(&lpi->lpi_completion);
419 int llog_process_or_fork(const struct lu_env *env,
420 struct llog_handle *loghandle,
421 llog_cb_t cb, void *data, void *catdata, bool fork)
423 struct llog_process_info *lpi;
430 CERROR("cannot alloc pointer\n");
433 lpi->lpi_loghandle = loghandle;
435 lpi->lpi_cbdata = data;
436 lpi->lpi_catdata = catdata;
440 /* The new thread can't use parent env,
441 * init the new one in llog_process_thread_daemonize. */
443 init_completion(&lpi->lpi_completion);
444 rc = cfs_create_thread(llog_process_thread_daemonize, lpi,
447 CERROR("%s: cannot start thread: rc = %d\n",
448 loghandle->lgh_ctxt->loc_obd->obd_name, rc);
452 wait_for_completion(&lpi->lpi_completion);
455 llog_process_thread(lpi);
459 llog_process_thread(lpi);
465 EXPORT_SYMBOL(llog_process_or_fork);
467 int llog_process(const struct lu_env *env, struct llog_handle *loghandle,
468 llog_cb_t cb, void *data, void *catdata)
470 return llog_process_or_fork(env, loghandle, cb, data, catdata, true);
472 EXPORT_SYMBOL(llog_process);
474 inline int llog_get_size(struct llog_handle *loghandle)
476 if (loghandle && loghandle->lgh_hdr)
477 return loghandle->lgh_hdr->llh_count;
480 EXPORT_SYMBOL(llog_get_size);
482 int llog_reverse_process(const struct lu_env *env,
483 struct llog_handle *loghandle, llog_cb_t cb,
484 void *data, void *catdata)
486 struct llog_log_hdr *llh = loghandle->lgh_hdr;
487 struct llog_process_cat_data *cd = catdata;
489 int rc = 0, first_index = 1, index, idx;
492 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
497 first_index = cd->lpcd_first_idx + 1;
498 if (cd != NULL && cd->lpcd_last_idx)
499 index = cd->lpcd_last_idx;
501 index = LLOG_BITMAP_BYTES * 8 - 1;
504 struct llog_rec_hdr *rec;
505 struct llog_rec_tail *tail;
507 /* skip records not set in bitmap */
508 while (index >= first_index &&
509 !ext2_test_bit(index, llh->llh_bitmap))
512 LASSERT(index >= first_index - 1);
513 if (index == first_index - 1)
516 /* get the buf with our target record; avoid old garbage */
517 memset(buf, 0, LLOG_CHUNK_SIZE);
518 rc = llog_prev_block(env, loghandle, index, buf,
524 idx = rec->lrh_index;
525 CDEBUG(D_RPCTRACE, "index %u : idx %u\n", index, idx);
526 while (idx < index) {
527 rec = (void *)rec + rec->lrh_len;
528 if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
529 lustre_swab_llog_rec(rec);
532 LASSERT(idx == index);
533 tail = (void *)rec + rec->lrh_len - sizeof(*tail);
535 /* process records in buffer, starting where we found one */
536 while ((void *)tail > buf) {
537 if (tail->lrt_index == 0)
538 GOTO(out, rc = 0); /* no more records */
540 /* if set, process the callback on this record */
541 if (ext2_test_bit(index, llh->llh_bitmap)) {
542 rec = (void *)tail - tail->lrt_len +
545 rc = cb(env, loghandle, rec, data);
546 if (rc == LLOG_PROC_BREAK) {
548 } else if (rc == LLOG_DEL_RECORD) {
549 llog_cancel_rec(env, loghandle,
557 /* previous record, still in buffer? */
559 if (index < first_index)
561 tail = (void *)tail - tail->lrt_len;
567 OBD_FREE(buf, LLOG_CHUNK_SIZE);
570 EXPORT_SYMBOL(llog_reverse_process);
576 * llog_open - open llog, may not exist
577 * llog_exist - check if llog exists
578 * llog_close - close opened llog, pair for open, frees llog_handle
579 * llog_declare_create - declare llog creation
580 * llog_create - create new llog on disk, need transaction handle
581 * llog_declare_write_rec - declaration of llog write
582 * llog_write_rec - write llog record on disk, need transaction handle
583 * llog_declare_add - declare llog catalog record addition
584 * llog_add - add llog record in catalog, need transaction handle
586 int llog_exist(struct llog_handle *loghandle)
588 struct llog_operations *lop;
593 rc = llog_handle2ops(loghandle, &lop);
596 if (lop->lop_exist == NULL)
599 rc = lop->lop_exist(loghandle);
602 EXPORT_SYMBOL(llog_exist);
604 int llog_declare_create(const struct lu_env *env,
605 struct llog_handle *loghandle, struct thandle *th)
607 struct llog_operations *lop;
612 rc = llog_handle2ops(loghandle, &lop);
615 if (lop->lop_declare_create == NULL)
618 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
620 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
621 rc = lop->lop_declare_create(env, loghandle, th);
623 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
626 EXPORT_SYMBOL(llog_declare_create);
628 int llog_create(const struct lu_env *env, struct llog_handle *handle,
631 struct llog_operations *lop;
636 rc = llog_handle2ops(handle, &lop);
639 if (lop->lop_create == NULL)
642 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
644 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
645 rc = lop->lop_create(env, handle, th);
647 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
650 EXPORT_SYMBOL(llog_create);
652 int llog_declare_write_rec(const struct lu_env *env,
653 struct llog_handle *handle,
654 struct llog_rec_hdr *rec, int idx,
657 struct llog_operations *lop;
662 rc = llog_handle2ops(handle, &lop);
666 if (lop->lop_declare_write_rec == NULL)
669 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
671 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
672 rc = lop->lop_declare_write_rec(env, handle, rec, idx, th);
674 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
677 EXPORT_SYMBOL(llog_declare_write_rec);
679 int llog_write_rec(const struct lu_env *env, struct llog_handle *handle,
680 struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
681 int numcookies, void *buf, int idx, struct thandle *th)
683 struct llog_operations *lop;
684 int raised, rc, buflen;
688 rc = llog_handle2ops(handle, &lop);
693 if (lop->lop_write_rec == NULL)
697 buflen = rec->lrh_len + sizeof(struct llog_rec_hdr) +
698 sizeof(struct llog_rec_tail);
700 buflen = rec->lrh_len;
701 LASSERT(cfs_size_round(buflen) == buflen);
703 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
705 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
706 rc = lop->lop_write_rec(env, handle, rec, logcookies, numcookies,
709 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
712 EXPORT_SYMBOL(llog_write_rec);
714 int llog_add(const struct lu_env *env, struct llog_handle *lgh,
715 struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
716 void *buf, struct thandle *th)
722 if (lgh->lgh_logops->lop_add == NULL)
725 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
727 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
728 rc = lgh->lgh_logops->lop_add(env, lgh, rec, logcookies, buf, th);
730 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
733 EXPORT_SYMBOL(llog_add);
735 int llog_declare_add(const struct lu_env *env, struct llog_handle *lgh,
736 struct llog_rec_hdr *rec, struct thandle *th)
742 if (lgh->lgh_logops->lop_declare_add == NULL)
745 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
747 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
748 rc = lgh->lgh_logops->lop_declare_add(env, lgh, rec, th);
750 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
753 EXPORT_SYMBOL(llog_declare_add);
756 * Helper function to open llog or create it if doesn't exist.
757 * It hides all transaction handling from caller.
759 int llog_open_create(const struct lu_env *env, struct llog_ctxt *ctxt,
760 struct llog_handle **res, struct llog_logid *logid,
768 rc = llog_open(env, ctxt, res, logid, name, LLOG_OPEN_NEW);
772 if (llog_exist(*res))
775 if ((*res)->lgh_obj != NULL) {
778 d = lu2dt_dev((*res)->lgh_obj->do_lu.lo_dev);
780 th = dt_trans_create(env, d);
782 GOTO(out, rc = PTR_ERR(th));
784 rc = llog_declare_create(env, *res, th);
786 rc = dt_trans_start_local(env, d, th);
788 rc = llog_create(env, *res, th);
790 dt_trans_stop(env, d, th);
792 /* lvfs compat code */
793 LASSERT((*res)->lgh_file == NULL);
794 rc = llog_create(env, *res, NULL);
798 llog_close(env, *res);
801 EXPORT_SYMBOL(llog_open_create);
804 * Helper function to delete existent llog.
806 int llog_erase(const struct lu_env *env, struct llog_ctxt *ctxt,
807 struct llog_logid *logid, char *name)
809 struct llog_handle *handle;
814 /* nothing to erase */
815 if (name == NULL && logid == NULL)
818 rc = llog_open(env, ctxt, &handle, logid, name, LLOG_OPEN_EXISTS);
822 rc = llog_init_handle(env, handle, LLOG_F_IS_PLAIN, NULL);
824 rc = llog_destroy(env, handle);
826 rc2 = llog_close(env, handle);
831 EXPORT_SYMBOL(llog_erase);
834 * Helper function for write record in llog.
835 * It hides all transaction handling from caller.
836 * Valid only with local llog.
838 int llog_write(const struct lu_env *env, struct llog_handle *loghandle,
839 struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
840 int cookiecount, void *buf, int idx)
847 LASSERT(loghandle->lgh_ctxt);
849 if (loghandle->lgh_obj != NULL) {
850 struct dt_device *dt;
853 dt = lu2dt_dev(loghandle->lgh_obj->do_lu.lo_dev);
855 th = dt_trans_create(env, dt);
859 rc = llog_declare_write_rec(env, loghandle, rec, idx, th);
863 rc = dt_trans_start_local(env, dt, th);
867 down_write(&loghandle->lgh_lock);
868 rc = llog_write_rec(env, loghandle, rec, reccookie,
869 cookiecount, buf, idx, th);
870 up_write(&loghandle->lgh_lock);
872 dt_trans_stop(env, dt, th);
873 } else { /* lvfs compatibility */
874 down_write(&loghandle->lgh_lock);
875 rc = llog_write_rec(env, loghandle, rec, reccookie,
876 cookiecount, buf, idx, NULL);
877 up_write(&loghandle->lgh_lock);
881 EXPORT_SYMBOL(llog_write);
883 int llog_open(const struct lu_env *env, struct llog_ctxt *ctxt,
884 struct llog_handle **lgh, struct llog_logid *logid,
885 char *name, enum llog_open_param open_param)
893 LASSERT(ctxt->loc_logops);
895 if (ctxt->loc_logops->lop_open == NULL) {
900 *lgh = llog_alloc_handle();
903 (*lgh)->lgh_ctxt = ctxt;
904 (*lgh)->lgh_logops = ctxt->loc_logops;
906 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
908 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
909 rc = ctxt->loc_logops->lop_open(env, *lgh, logid, name, open_param);
911 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
913 llog_free_handle(*lgh);
918 EXPORT_SYMBOL(llog_open);
920 int llog_close(const struct lu_env *env, struct llog_handle *loghandle)
922 struct llog_operations *lop;
927 rc = llog_handle2ops(loghandle, &lop);
930 if (lop->lop_close == NULL)
931 GOTO(out, -EOPNOTSUPP);
932 rc = lop->lop_close(env, loghandle);
934 llog_free_handle(loghandle);
937 EXPORT_SYMBOL(llog_close);