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 "DOSTID"\n",
120 index, POSTID(&loghandle->lgh_id.lgl_oi));
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 #"DOSTID
144 loghandle->lgh_ctxt->loc_obd->obd_name,
145 POSTID(&loghandle->lgh_id.lgl_oi),
146 loghandle->lgh_id.lgl_ogen, rc);
151 spin_unlock(&loghandle->lgh_hdr_lock);
153 rc = llog_write(env, loghandle, &llh->llh_hdr, NULL, 0, NULL, 0);
155 CERROR("%s: fail to write header for llog #"DOSTID
157 loghandle->lgh_ctxt->loc_obd->obd_name,
158 POSTID(&loghandle->lgh_id.lgl_oi),
159 loghandle->lgh_id.lgl_ogen, rc);
164 spin_lock(&loghandle->lgh_hdr_lock);
165 ext2_set_bit(index, llh->llh_bitmap);
167 spin_unlock(&loghandle->lgh_hdr_lock);
170 EXPORT_SYMBOL(llog_cancel_rec);
172 static int llog_read_header(const struct lu_env *env,
173 struct llog_handle *handle,
174 struct obd_uuid *uuid)
176 struct llog_operations *lop;
179 rc = llog_handle2ops(handle, &lop);
183 if (lop->lop_read_header == NULL)
186 rc = lop->lop_read_header(env, handle);
187 if (rc == LLOG_EEMPTY) {
188 struct llog_log_hdr *llh = handle->lgh_hdr;
190 handle->lgh_last_idx = 0; /* header is record with index 0 */
191 llh->llh_count = 1; /* for the header record */
192 llh->llh_hdr.lrh_type = LLOG_HDR_MAGIC;
193 llh->llh_hdr.lrh_len = llh->llh_tail.lrt_len = LLOG_CHUNK_SIZE;
194 llh->llh_hdr.lrh_index = llh->llh_tail.lrt_index = 0;
195 llh->llh_timestamp = cfs_time_current_sec();
197 memcpy(&llh->llh_tgtuuid, uuid,
198 sizeof(llh->llh_tgtuuid));
199 llh->llh_bitmap_offset = offsetof(typeof(*llh), llh_bitmap);
200 ext2_set_bit(0, llh->llh_bitmap);
206 int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
207 int flags, struct obd_uuid *uuid)
209 struct llog_log_hdr *llh;
213 LASSERT(handle->lgh_hdr == NULL);
218 handle->lgh_hdr = llh;
219 /* first assign flags to use llog_client_ops */
220 llh->llh_flags = flags;
221 rc = llog_read_header(env, handle, uuid);
223 if (unlikely((llh->llh_flags & LLOG_F_IS_PLAIN &&
224 flags & LLOG_F_IS_CAT) ||
225 (llh->llh_flags & LLOG_F_IS_CAT &&
226 flags & LLOG_F_IS_PLAIN))) {
227 CERROR("%s: llog type is %s but initializing %s\n",
228 handle->lgh_ctxt->loc_obd->obd_name,
229 llh->llh_flags & LLOG_F_IS_CAT ?
231 flags & LLOG_F_IS_CAT ? "catalog" : "plain");
232 GOTO(out, rc = -EINVAL);
233 } else if (llh->llh_flags &
234 (LLOG_F_IS_PLAIN | LLOG_F_IS_CAT)) {
236 * it is possible to open llog without specifying llog
237 * type so it is taken from llh_flags
239 flags = llh->llh_flags;
241 /* for some reason the llh_flags has no type set */
242 CERROR("llog type is not specified!\n");
243 GOTO(out, rc = -EINVAL);
246 !obd_uuid_equals(uuid, &llh->llh_tgtuuid))) {
247 CERROR("%s: llog uuid mismatch: %s/%s\n",
248 handle->lgh_ctxt->loc_obd->obd_name,
250 (char *)llh->llh_tgtuuid.uuid);
251 GOTO(out, rc = -EEXIST);
254 if (flags & LLOG_F_IS_CAT) {
255 LASSERT(cfs_list_empty(&handle->u.chd.chd_head));
256 CFS_INIT_LIST_HEAD(&handle->u.chd.chd_head);
257 llh->llh_size = sizeof(struct llog_logid_rec);
258 } else if (!(flags & LLOG_F_IS_PLAIN)) {
259 CERROR("%s: unknown flags: %#x (expected %#x or %#x)\n",
260 handle->lgh_ctxt->loc_obd->obd_name,
261 flags, LLOG_F_IS_CAT, LLOG_F_IS_PLAIN);
267 handle->lgh_hdr = NULL;
271 EXPORT_SYMBOL(llog_init_handle);
273 int llog_copy_handler(const struct lu_env *env,
274 struct llog_handle *llh,
275 struct llog_rec_hdr *rec,
278 struct llog_rec_hdr local_rec = *rec;
279 struct llog_handle *local_llh = (struct llog_handle *)data;
280 char *cfg_buf = (char*) (rec + 1);
281 struct lustre_cfg *lcfg;
285 /* Append all records */
286 local_rec.lrh_len -= sizeof(*rec) + sizeof(struct llog_rec_tail);
287 rc = llog_write(env, local_llh, &local_rec, NULL, 0,
288 (void *)cfg_buf, -1);
290 lcfg = (struct lustre_cfg *)cfg_buf;
291 CDEBUG(D_INFO, "idx=%d, rc=%d, len=%d, cmd %x %s %s\n",
292 rec->lrh_index, rc, rec->lrh_len, lcfg->lcfg_command,
293 lustre_cfg_string(lcfg, 0), lustre_cfg_string(lcfg, 1));
297 EXPORT_SYMBOL(llog_copy_handler);
299 static int llog_process_thread(void *arg)
301 struct llog_process_info *lpi = arg;
302 struct llog_handle *loghandle = lpi->lpi_loghandle;
303 struct llog_log_hdr *llh = loghandle->lgh_hdr;
304 struct llog_process_cat_data *cd = lpi->lpi_catdata;
306 __u64 cur_offset = LLOG_CHUNK_SIZE;
308 int rc = 0, index = 1, last_index;
310 int last_called_index = 0;
316 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
318 lpi->lpi_rc = -ENOMEM;
323 last_called_index = cd->lpcd_first_idx;
324 index = cd->lpcd_first_idx + 1;
326 if (cd != NULL && cd->lpcd_last_idx)
327 last_index = cd->lpcd_last_idx;
329 last_index = LLOG_BITMAP_BYTES * 8 - 1;
332 struct llog_rec_hdr *rec;
334 /* skip records not set in bitmap */
335 while (index <= last_index &&
336 !ext2_test_bit(index, llh->llh_bitmap))
339 LASSERT(index <= last_index + 1);
340 if (index == last_index + 1)
343 CDEBUG(D_OTHER, "index: %d last_index %d\n",
346 /* get the buf with our target record; avoid old garbage */
347 memset(buf, 0, LLOG_CHUNK_SIZE);
348 last_offset = cur_offset;
349 rc = llog_next_block(lpi->lpi_env, loghandle, &saved_index,
350 index, &cur_offset, buf, LLOG_CHUNK_SIZE);
354 /* NB: when rec->lrh_len is accessed it is already swabbed
355 * since it is used at the "end" of the loop and the rec
356 * swabbing is done at the beginning of the loop. */
357 for (rec = (struct llog_rec_hdr *)buf;
358 (char *)rec < buf + LLOG_CHUNK_SIZE;
359 rec = (struct llog_rec_hdr *)((char *)rec + rec->lrh_len)){
361 CDEBUG(D_OTHER, "processing rec 0x%p type %#x\n",
364 if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
365 lustre_swab_llog_rec(rec);
367 CDEBUG(D_OTHER, "after swabbing, type=%#x idx=%d\n",
368 rec->lrh_type, rec->lrh_index);
370 if (rec->lrh_index == 0) {
371 /* probably another rec just got added? */
372 if (index <= loghandle->lgh_last_idx)
373 GOTO(repeat, rc = 0);
374 GOTO(out, rc = 0); /* no more records */
376 if (rec->lrh_len == 0 ||
377 rec->lrh_len > LLOG_CHUNK_SIZE) {
378 CWARN("invalid length %d in llog record for "
379 "index %d/%d\n", rec->lrh_len,
380 rec->lrh_index, index);
381 GOTO(out, rc = -EINVAL);
384 if (rec->lrh_index < index) {
385 CDEBUG(D_OTHER, "skipping lrh_index %d\n",
391 "lrh_index: %d lrh_len: %d (%d remains)\n",
392 rec->lrh_index, rec->lrh_len,
393 (int)(buf + LLOG_CHUNK_SIZE - (char *)rec));
395 loghandle->lgh_cur_idx = rec->lrh_index;
396 loghandle->lgh_cur_offset = (char *)rec - (char *)buf +
399 /* if set, process the callback on this record */
400 if (ext2_test_bit(index, llh->llh_bitmap)) {
401 rc = lpi->lpi_cb(lpi->lpi_env, loghandle, rec,
403 last_called_index = index;
404 if (rc == LLOG_PROC_BREAK) {
406 } else if (rc == LLOG_DEL_RECORD) {
407 llog_cancel_rec(lpi->lpi_env,
415 CDEBUG(D_OTHER, "Skipped index %d\n", index);
418 /* next record, still in buffer? */
420 if (index > last_index)
427 cd->lpcd_last_idx = last_called_index;
429 OBD_FREE(buf, LLOG_CHUNK_SIZE);
435 static int llog_process_thread_daemonize(void *arg)
437 struct llog_process_info *lpi = arg;
441 cfs_daemonize_ctxt("llog_process_thread");
443 /* client env has no keys, tags is just 0 */
444 rc = lu_env_init(&env, LCT_LOCAL | LCT_MG_THREAD);
449 rc = llog_process_thread(arg);
453 complete(&lpi->lpi_completion);
458 int llog_process_or_fork(const struct lu_env *env,
459 struct llog_handle *loghandle,
460 llog_cb_t cb, void *data, void *catdata, bool fork)
462 struct llog_process_info *lpi;
469 CERROR("cannot alloc pointer\n");
472 lpi->lpi_loghandle = loghandle;
474 lpi->lpi_cbdata = data;
475 lpi->lpi_catdata = catdata;
479 /* The new thread can't use parent env,
480 * init the new one in llog_process_thread_daemonize. */
482 init_completion(&lpi->lpi_completion);
483 rc = cfs_create_thread(llog_process_thread_daemonize, lpi,
486 CERROR("%s: cannot start thread: rc = %d\n",
487 loghandle->lgh_ctxt->loc_obd->obd_name, rc);
491 wait_for_completion(&lpi->lpi_completion);
494 llog_process_thread(lpi);
498 llog_process_thread(lpi);
504 EXPORT_SYMBOL(llog_process_or_fork);
506 int llog_process(const struct lu_env *env, struct llog_handle *loghandle,
507 llog_cb_t cb, void *data, void *catdata)
509 return llog_process_or_fork(env, loghandle, cb, data, catdata, true);
511 EXPORT_SYMBOL(llog_process);
513 inline int llog_get_size(struct llog_handle *loghandle)
515 if (loghandle && loghandle->lgh_hdr)
516 return loghandle->lgh_hdr->llh_count;
519 EXPORT_SYMBOL(llog_get_size);
521 int llog_reverse_process(const struct lu_env *env,
522 struct llog_handle *loghandle, llog_cb_t cb,
523 void *data, void *catdata)
525 struct llog_log_hdr *llh = loghandle->lgh_hdr;
526 struct llog_process_cat_data *cd = catdata;
528 int rc = 0, first_index = 1, index, idx;
531 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
536 first_index = cd->lpcd_first_idx + 1;
537 if (cd != NULL && cd->lpcd_last_idx)
538 index = cd->lpcd_last_idx;
540 index = LLOG_BITMAP_BYTES * 8 - 1;
543 struct llog_rec_hdr *rec;
544 struct llog_rec_tail *tail;
546 /* skip records not set in bitmap */
547 while (index >= first_index &&
548 !ext2_test_bit(index, llh->llh_bitmap))
551 LASSERT(index >= first_index - 1);
552 if (index == first_index - 1)
555 /* get the buf with our target record; avoid old garbage */
556 memset(buf, 0, LLOG_CHUNK_SIZE);
557 rc = llog_prev_block(env, loghandle, index, buf,
563 idx = rec->lrh_index;
564 CDEBUG(D_RPCTRACE, "index %u : idx %u\n", index, idx);
565 while (idx < index) {
566 rec = (void *)rec + rec->lrh_len;
567 if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
568 lustre_swab_llog_rec(rec);
571 LASSERT(idx == index);
572 tail = (void *)rec + rec->lrh_len - sizeof(*tail);
574 /* process records in buffer, starting where we found one */
575 while ((void *)tail > buf) {
576 if (tail->lrt_index == 0)
577 GOTO(out, rc = 0); /* no more records */
579 /* if set, process the callback on this record */
580 if (ext2_test_bit(index, llh->llh_bitmap)) {
581 rec = (void *)tail - tail->lrt_len +
584 rc = cb(env, loghandle, rec, data);
585 if (rc == LLOG_PROC_BREAK) {
587 } else if (rc == LLOG_DEL_RECORD) {
588 llog_cancel_rec(env, loghandle,
596 /* previous record, still in buffer? */
598 if (index < first_index)
600 tail = (void *)tail - tail->lrt_len;
606 OBD_FREE(buf, LLOG_CHUNK_SIZE);
609 EXPORT_SYMBOL(llog_reverse_process);
615 * llog_open - open llog, may not exist
616 * llog_exist - check if llog exists
617 * llog_close - close opened llog, pair for open, frees llog_handle
618 * llog_declare_create - declare llog creation
619 * llog_create - create new llog on disk, need transaction handle
620 * llog_declare_write_rec - declaration of llog write
621 * llog_write_rec - write llog record on disk, need transaction handle
622 * llog_declare_add - declare llog catalog record addition
623 * llog_add - add llog record in catalog, need transaction handle
625 int llog_exist(struct llog_handle *loghandle)
627 struct llog_operations *lop;
632 rc = llog_handle2ops(loghandle, &lop);
635 if (lop->lop_exist == NULL)
638 rc = lop->lop_exist(loghandle);
641 EXPORT_SYMBOL(llog_exist);
643 int llog_declare_create(const struct lu_env *env,
644 struct llog_handle *loghandle, struct thandle *th)
646 struct llog_operations *lop;
651 rc = llog_handle2ops(loghandle, &lop);
654 if (lop->lop_declare_create == NULL)
657 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
659 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
660 rc = lop->lop_declare_create(env, loghandle, th);
662 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
665 EXPORT_SYMBOL(llog_declare_create);
667 int llog_create(const struct lu_env *env, struct llog_handle *handle,
670 struct llog_operations *lop;
675 rc = llog_handle2ops(handle, &lop);
678 if (lop->lop_create == NULL)
681 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
683 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
684 rc = lop->lop_create(env, handle, th);
686 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
689 EXPORT_SYMBOL(llog_create);
691 int llog_declare_write_rec(const struct lu_env *env,
692 struct llog_handle *handle,
693 struct llog_rec_hdr *rec, int idx,
696 struct llog_operations *lop;
701 rc = llog_handle2ops(handle, &lop);
705 if (lop->lop_declare_write_rec == NULL)
708 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
710 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
711 rc = lop->lop_declare_write_rec(env, handle, rec, idx, th);
713 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
716 EXPORT_SYMBOL(llog_declare_write_rec);
718 int llog_write_rec(const struct lu_env *env, struct llog_handle *handle,
719 struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
720 int numcookies, void *buf, int idx, struct thandle *th)
722 struct llog_operations *lop;
723 int raised, rc, buflen;
727 rc = llog_handle2ops(handle, &lop);
732 if (lop->lop_write_rec == NULL)
736 buflen = rec->lrh_len + sizeof(struct llog_rec_hdr) +
737 sizeof(struct llog_rec_tail);
739 buflen = rec->lrh_len;
740 LASSERT(cfs_size_round(buflen) == buflen);
742 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
744 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
745 rc = lop->lop_write_rec(env, handle, rec, logcookies, numcookies,
748 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
751 EXPORT_SYMBOL(llog_write_rec);
753 int llog_add(const struct lu_env *env, struct llog_handle *lgh,
754 struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
755 void *buf, struct thandle *th)
761 if (lgh->lgh_logops->lop_add == NULL)
764 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
766 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
767 rc = lgh->lgh_logops->lop_add(env, lgh, rec, logcookies, buf, th);
769 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
772 EXPORT_SYMBOL(llog_add);
774 int llog_declare_add(const struct lu_env *env, struct llog_handle *lgh,
775 struct llog_rec_hdr *rec, struct thandle *th)
781 if (lgh->lgh_logops->lop_declare_add == NULL)
784 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
786 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
787 rc = lgh->lgh_logops->lop_declare_add(env, lgh, rec, th);
789 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
792 EXPORT_SYMBOL(llog_declare_add);
795 * Helper function to open llog or create it if doesn't exist.
796 * It hides all transaction handling from caller.
798 int llog_open_create(const struct lu_env *env, struct llog_ctxt *ctxt,
799 struct llog_handle **res, struct llog_logid *logid,
807 rc = llog_open(env, ctxt, res, logid, name, LLOG_OPEN_NEW);
811 if (llog_exist(*res))
814 if ((*res)->lgh_obj != NULL) {
817 d = lu2dt_dev((*res)->lgh_obj->do_lu.lo_dev);
819 th = dt_trans_create(env, d);
821 GOTO(out, rc = PTR_ERR(th));
823 rc = llog_declare_create(env, *res, th);
825 rc = dt_trans_start_local(env, d, th);
827 rc = llog_create(env, *res, th);
829 dt_trans_stop(env, d, th);
831 /* lvfs compat code */
832 LASSERT((*res)->lgh_file == NULL);
833 rc = llog_create(env, *res, NULL);
837 llog_close(env, *res);
840 EXPORT_SYMBOL(llog_open_create);
843 * Helper function to delete existent llog.
845 int llog_erase(const struct lu_env *env, struct llog_ctxt *ctxt,
846 struct llog_logid *logid, char *name)
848 struct llog_handle *handle;
853 /* nothing to erase */
854 if (name == NULL && logid == NULL)
857 rc = llog_open(env, ctxt, &handle, logid, name, LLOG_OPEN_EXISTS);
861 rc = llog_init_handle(env, handle, LLOG_F_IS_PLAIN, NULL);
863 rc = llog_destroy(env, handle);
865 rc2 = llog_close(env, handle);
870 EXPORT_SYMBOL(llog_erase);
873 * Helper function for write record in llog.
874 * It hides all transaction handling from caller.
875 * Valid only with local llog.
877 int llog_write(const struct lu_env *env, struct llog_handle *loghandle,
878 struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
879 int cookiecount, void *buf, int idx)
886 LASSERT(loghandle->lgh_ctxt);
888 if (loghandle->lgh_obj != NULL) {
889 struct dt_device *dt;
892 dt = lu2dt_dev(loghandle->lgh_obj->do_lu.lo_dev);
894 th = dt_trans_create(env, dt);
898 rc = llog_declare_write_rec(env, loghandle, rec, idx, th);
902 rc = dt_trans_start_local(env, dt, th);
906 down_write(&loghandle->lgh_lock);
907 rc = llog_write_rec(env, loghandle, rec, reccookie,
908 cookiecount, buf, idx, th);
909 up_write(&loghandle->lgh_lock);
911 dt_trans_stop(env, dt, th);
912 } else { /* lvfs compatibility */
913 down_write(&loghandle->lgh_lock);
914 rc = llog_write_rec(env, loghandle, rec, reccookie,
915 cookiecount, buf, idx, NULL);
916 up_write(&loghandle->lgh_lock);
920 EXPORT_SYMBOL(llog_write);
922 int llog_open(const struct lu_env *env, struct llog_ctxt *ctxt,
923 struct llog_handle **lgh, struct llog_logid *logid,
924 char *name, enum llog_open_param open_param)
932 LASSERT(ctxt->loc_logops);
934 if (ctxt->loc_logops->lop_open == NULL) {
939 *lgh = llog_alloc_handle();
942 (*lgh)->lgh_ctxt = ctxt;
943 (*lgh)->lgh_logops = ctxt->loc_logops;
945 raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
947 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
948 rc = ctxt->loc_logops->lop_open(env, *lgh, logid, name, open_param);
950 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
952 llog_free_handle(*lgh);
957 EXPORT_SYMBOL(llog_open);
959 int llog_close(const struct lu_env *env, struct llog_handle *loghandle)
961 struct llog_operations *lop;
966 rc = llog_handle2ops(loghandle, &lop);
969 if (lop->lop_close == NULL)
970 GOTO(out, rc = -EOPNOTSUPP);
971 rc = lop->lop_close(env, loghandle);
973 llog_handle_put(loghandle);
976 EXPORT_SYMBOL(llog_close);