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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2014 Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 * lustre/obdclass/llog_osd.c
35 * Low level llog routines on top of OSD API
37 * This file provides set of methods for llog operations on top of
38 * dt_device. It contains all supported llog_operations interfaces and
39 * supplimental functions.
41 * Author: Alexey Zhuravlev <alexey.zhuravlev@intel.com>
42 * Author: Mikhail Pershin <mike.pershin@intel.com>
45 #define DEBUG_SUBSYSTEM S_LOG
48 #include <obd_class.h>
49 #include <lustre_fid.h>
50 #include <dt_object.h>
52 #include "llog_internal.h"
53 #include "local_storage.h"
56 * Implementation of the llog_operations::lop_declare_create
58 * This function is a wrapper over local_storage API function
59 * local_object_declare_create().
61 * \param[in] env execution environment
62 * \param[in] los local_storage for bottom storage device
63 * \param[in] o dt_object to create
64 * \param[in] th current transaction handle
66 * \retval 0 on successful declaration of the new object
67 * \retval negative error if declaration was failed
69 static int llog_osd_declare_new_object(const struct lu_env *env,
70 struct local_oid_storage *los,
74 struct llog_thread_info *lgi = llog_info(env);
76 lgi->lgi_attr.la_valid = LA_MODE;
77 lgi->lgi_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
78 lgi->lgi_dof.dof_type = dt_mode_to_dft(S_IFREG);
80 return local_object_declare_create(env, los, o, &lgi->lgi_attr,
85 * Implementation of the llog_operations::lop_create
87 * This function is a wrapper over local_storage API function
88 * local_object_create().
90 * \param[in] env execution environment
91 * \param[in] los local_storage for bottom storage device
92 * \param[in] o dt_object to create
93 * \param[in] th current transaction handle
95 * \retval 0 on successful creation of the new object
96 * \retval negative error if creation was failed
98 static int llog_osd_create_new_object(const struct lu_env *env,
99 struct local_oid_storage *los,
103 struct llog_thread_info *lgi = llog_info(env);
105 lgi->lgi_attr.la_valid = LA_MODE;
106 lgi->lgi_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
107 lgi->lgi_dof.dof_type = dt_mode_to_dft(S_IFREG);
109 return local_object_create(env, los, o, &lgi->lgi_attr,
114 * Write a padding record to the llog
116 * This function writes a padding record to the end of llog. That may
117 * be needed if llog contains records of variable size, e.g. config logs
119 * The padding record just aligns llog to the LLOG_CHUNK_SIZE boundary if
120 * the current record doesn't fit in the remaining space.
122 * It allocates full length to avoid two separate writes for header and tail.
123 * Such 2-steps scheme needs extra protection and complex error handling.
125 * \param[in] env execution environment
126 * \param[in] o dt_object to create
127 * \param[in,out] off pointer to the padding start offset
128 * \param[in] len padding length
129 * \param[in] index index of the padding record in a llog
130 * \param[in] th current transaction handle
132 * \retval 0 on successful padding write
133 * \retval negative error if write failed
135 static int llog_osd_pad(const struct lu_env *env, struct dt_object *o,
136 loff_t *off, int len, int index, struct thandle *th)
138 struct llog_thread_info *lgi = llog_info(env);
139 struct llog_rec_hdr *rec;
140 struct llog_rec_tail *tail;
147 LASSERT(len >= LLOG_MIN_REC_SIZE && (len & 0x7) == 0);
154 rec->lrh_index = index;
155 rec->lrh_type = LLOG_PAD_MAGIC;
157 tail = rec_tail(rec);
159 tail->lrt_index = index;
161 lgi->lgi_buf.lb_buf = rec;
162 lgi->lgi_buf.lb_len = len;
163 rc = dt_record_write(env, o, &lgi->lgi_buf, off, th);
165 CERROR("%s: error writing padding record: rc = %d\n",
166 o->do_lu.lo_dev->ld_obd->obd_name, rc);
173 * Implementation of the llog_operations::lop_read_header
175 * This function reads the current llog header from the bottom storage
178 * \param[in] env execution environment
179 * \param[in] handle llog handle of the current llog
181 * \retval 0 on successful header read
182 * \retval negative error if read failed
184 static int llog_osd_read_header(const struct lu_env *env,
185 struct llog_handle *handle)
187 struct llog_rec_hdr *llh_hdr;
189 struct llog_thread_info *lgi;
190 enum llog_flag flags;
195 LASSERT(sizeof(*handle->lgh_hdr) == LLOG_CHUNK_SIZE);
200 lgi = llog_info(env);
202 rc = dt_attr_get(env, o, &lgi->lgi_attr, NULL);
206 LASSERT(lgi->lgi_attr.la_valid & LA_SIZE);
208 if (lgi->lgi_attr.la_size == 0) {
209 CDEBUG(D_HA, "not reading header from 0-byte log\n");
213 flags = handle->lgh_hdr->llh_flags;
216 lgi->lgi_buf.lb_buf = handle->lgh_hdr;
217 lgi->lgi_buf.lb_len = LLOG_CHUNK_SIZE;
219 rc = dt_record_read(env, o, &lgi->lgi_buf, &lgi->lgi_off);
221 CERROR("%s: error reading log header from "DFID": rc = %d\n",
222 o->do_lu.lo_dev->ld_obd->obd_name,
223 PFID(lu_object_fid(&o->do_lu)), rc);
227 llh_hdr = &handle->lgh_hdr->llh_hdr;
228 if (LLOG_REC_HDR_NEEDS_SWABBING(llh_hdr))
229 lustre_swab_llog_hdr(handle->lgh_hdr);
231 if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) {
232 CERROR("%s: bad log %s "DFID" header magic: %#x "
233 "(expected %#x)\n", o->do_lu.lo_dev->ld_obd->obd_name,
234 handle->lgh_name ? handle->lgh_name : "",
235 PFID(lu_object_fid(&o->do_lu)),
236 llh_hdr->lrh_type, LLOG_HDR_MAGIC);
238 } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) {
239 CERROR("%s: incorrectly sized log %s "DFID" header: "
240 "%#x (expected %#x)\n"
241 "you may need to re-run lconf --write_conf.\n",
242 o->do_lu.lo_dev->ld_obd->obd_name,
243 handle->lgh_name ? handle->lgh_name : "",
244 PFID(lu_object_fid(&o->do_lu)),
245 llh_hdr->lrh_len, LLOG_CHUNK_SIZE);
249 handle->lgh_hdr->llh_flags |= (flags & LLOG_F_EXT_MASK);
250 handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index;
256 * Implementation of the llog_operations::lop_declare_write
258 * This function declares the new record write.
260 * \param[in] env execution environment
261 * \param[in] loghandle llog handle of the current llog
262 * \param[in] rec llog record header. This is a real header of the full
263 * llog record to write. This is the beginning of buffer
264 * to write, the length of buffer is stored in
266 * \param[in] idx index of the llog record. If \a idx == -1 then this is
267 * append case, otherwise \a idx is the index of record
269 * \param[in] th current transaction handle
271 * \retval 0 on successful declaration
272 * \retval negative error if declaration failed
274 static int llog_osd_declare_write_rec(const struct lu_env *env,
275 struct llog_handle *loghandle,
276 struct llog_rec_hdr *rec,
277 int idx, struct thandle *th)
279 struct llog_thread_info *lgi = llog_info(env);
289 LASSERT(rec->lrh_len <= LLOG_CHUNK_SIZE);
291 o = loghandle->lgh_obj;
294 lgi->lgi_buf.lb_len = sizeof(struct llog_log_hdr);
295 lgi->lgi_buf.lb_buf = NULL;
296 /* each time we update header */
297 rc = dt_declare_record_write(env, o, &lgi->lgi_buf, 0,
299 if (rc || idx == 0) /* if error or just header */
303 * the pad record can be inserted so take into account double
306 lgi->lgi_buf.lb_len = rec->lrh_len * 2;
307 lgi->lgi_buf.lb_buf = NULL;
308 /* XXX: implement declared window or multi-chunks approach */
309 rc = dt_declare_record_write(env, o, &lgi->lgi_buf, -1, th);
315 * Implementation of the llog_operations::lop_write
317 * This function writes the new record in the llog or modify the existed one.
319 * \param[in] env execution environment
320 * \param[in] loghandle llog handle of the current llog
321 * \param[in] rec llog record header. This is a real header of
322 * the full llog record to write. This is
323 * the beginning of buffer to write, the length
324 * of buffer is stored in \a rec::lrh_len
325 * \param[out] reccookie pointer to the cookie to return back if needed.
326 * It is used for further cancel of this llog
328 * \param[in] idx index of the llog record. If \a idx == -1 then
329 * this is append case, otherwise \a idx is
330 * the index of record to modify
331 * \param[in] th current transaction handle
333 * \retval 0 on successful write && \a reccookie == NULL
334 * 1 on successful write && \a reccookie != NULL
335 * \retval negative error if write failed
337 static int llog_osd_write_rec(const struct lu_env *env,
338 struct llog_handle *loghandle,
339 struct llog_rec_hdr *rec,
340 struct llog_cookie *reccookie,
341 int idx, struct thandle *th)
343 struct llog_thread_info *lgi = llog_info(env);
344 struct llog_log_hdr *llh;
345 int reclen = rec->lrh_len;
347 struct llog_rec_tail *lrt;
350 bool header_is_updated = false;
355 llh = loghandle->lgh_hdr;
357 o = loghandle->lgh_obj;
361 CDEBUG(D_OTHER, "new record %x to "DFID"\n",
362 rec->lrh_type, PFID(lu_object_fid(&o->do_lu)));
364 /* record length should not bigger than LLOG_CHUNK_SIZE */
365 if (reclen > LLOG_CHUNK_SIZE)
368 rc = dt_attr_get(env, o, &lgi->lgi_attr, NULL);
373 * The modification case.
374 * If idx set then the record with that index must be modified.
375 * There are three cases possible:
376 * 1) the common case is the llog header update (idx == 0)
377 * 2) the llog record modification during llog process.
378 * This is indicated by the \a loghandle::lgh_cur_idx > 0.
379 * In that case the \a loghandle::lgh_cur_offset
380 * 3) otherwise this is assumed that llog consist of records of
381 * fixed size, i.e. catalog. The llog header must has llh_size
382 * field equal to record size. The record offset is calculated
383 * just by /a idx value
385 * During modification we don't need extra header update because
386 * the bitmap and record count are not changed. The record header
387 * and tail remains the same too.
389 if (idx != LLOG_NEXT_IDX) {
390 /* llog can be empty only when first record is being written */
391 LASSERT(ergo(idx > 0, lgi->lgi_attr.la_size > 0));
393 if (!ext2_test_bit(idx, llh->llh_bitmap)) {
394 CERROR("%s: modify unset record %u\n",
395 o->do_lu.lo_dev->ld_obd->obd_name, idx);
399 if (idx != rec->lrh_index) {
400 CERROR("%s: modify index mismatch %d %u\n",
401 o->do_lu.lo_dev->ld_obd->obd_name, idx,
406 if (idx == LLOG_HEADER_IDX) {
407 /* llog header update */
408 LASSERT(reclen == sizeof(struct llog_log_hdr));
409 LASSERT(rec == &llh->llh_hdr);
412 lgi->lgi_buf.lb_len = reclen;
413 lgi->lgi_buf.lb_buf = rec;
414 rc = dt_record_write(env, o, &lgi->lgi_buf,
417 } else if (loghandle->lgh_cur_idx > 0) {
419 * The lgh_cur_offset can be used only if index is
422 if (idx != loghandle->lgh_cur_idx) {
423 CERROR("%s: modify index mismatch %d %d\n",
424 o->do_lu.lo_dev->ld_obd->obd_name, idx,
425 loghandle->lgh_cur_idx);
429 lgi->lgi_off = loghandle->lgh_cur_offset;
430 CDEBUG(D_OTHER, "modify record "DOSTID": idx:%d, "
431 "len:%u offset %llu\n",
432 POSTID(&loghandle->lgh_id.lgl_oi), idx,
433 rec->lrh_len, (long long)lgi->lgi_off);
434 } else if (llh->llh_size > 0) {
435 if (llh->llh_size != rec->lrh_len) {
436 CERROR("%s: wrong record size, llh_size is %u"
437 " but record size is %u\n",
438 o->do_lu.lo_dev->ld_obd->obd_name,
439 llh->llh_size, rec->lrh_len);
442 lgi->lgi_off = sizeof(*llh) + (idx - 1) * reclen;
444 /* This can be result of lgh_cur_idx is not set during
445 * llog processing or llh_size is not set to proper
446 * record size for fixed records llog. Therefore it is
447 * impossible to get record offset. */
448 CERROR("%s: can't get record offset, idx:%d, "
449 "len:%u.\n", o->do_lu.lo_dev->ld_obd->obd_name,
454 /* update only data, header and tail remain the same */
455 lgi->lgi_off += sizeof(struct llog_rec_hdr);
456 lgi->lgi_buf.lb_len = REC_DATA_LEN(rec);
457 lgi->lgi_buf.lb_buf = REC_DATA(rec);
458 rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
459 if (rc == 0 && reccookie) {
460 reccookie->lgc_lgl = loghandle->lgh_id;
461 reccookie->lgc_index = idx;
469 * The most common case of using llog. The new index is assigned to
470 * the new record, new bit is set in llog bitmap and llog count is
473 * Make sure that records don't cross a chunk boundary, so we can
474 * process them page-at-a-time if needed. If it will cross a chunk
475 * boundary, write in a fake (but referenced) entry to pad the chunk.
477 LASSERT(lgi->lgi_attr.la_valid & LA_SIZE);
478 lgi->lgi_off = lgi->lgi_attr.la_size;
479 left = LLOG_CHUNK_SIZE - (lgi->lgi_off & (LLOG_CHUNK_SIZE - 1));
480 /* NOTE: padding is a record, but no bit is set */
481 if (left != 0 && left != reclen &&
482 left < (reclen + LLOG_MIN_REC_SIZE)) {
483 index = loghandle->lgh_last_idx + 1;
484 rc = llog_osd_pad(env, o, &lgi->lgi_off, left, index, th);
487 loghandle->lgh_last_idx++; /* for pad rec */
489 /* if it's the last idx in log file, then return -ENOSPC */
490 if (loghandle->lgh_last_idx >= LLOG_BITMAP_SIZE(llh) - 1)
493 /* increment the last_idx along with llh_tail index, they should
494 * be equal for a llog lifetime */
495 loghandle->lgh_last_idx++;
496 index = loghandle->lgh_last_idx;
497 llh->llh_tail.lrt_index = index;
499 * NB: the caller should make sure only 1 process access
500 * the lgh_last_idx, e.g. append should be exclusive.
501 * Otherwise it might hit the assert.
503 LASSERT(index < LLOG_BITMAP_SIZE(llh));
504 rec->lrh_index = index;
506 lrt->lrt_len = rec->lrh_len;
507 lrt->lrt_index = rec->lrh_index;
509 /* the lgh_hdr_lock protects llog header data from concurrent
510 * update/cancel, the llh_count and llh_bitmap are protected */
511 spin_lock(&loghandle->lgh_hdr_lock);
512 if (ext2_set_bit(index, llh->llh_bitmap)) {
513 CERROR("%s: index %u already set in log bitmap\n",
514 o->do_lu.lo_dev->ld_obd->obd_name, index);
515 spin_unlock(&loghandle->lgh_hdr_lock);
516 LBUG(); /* should never happen */
519 spin_unlock(&loghandle->lgh_hdr_lock);
522 lgi->lgi_buf.lb_len = llh->llh_hdr.lrh_len;
523 lgi->lgi_buf.lb_buf = &llh->llh_hdr;
524 rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
528 header_is_updated = true;
529 rc = dt_attr_get(env, o, &lgi->lgi_attr, NULL);
533 LASSERT(lgi->lgi_attr.la_valid & LA_SIZE);
534 lgi->lgi_off = lgi->lgi_attr.la_size;
535 lgi->lgi_buf.lb_len = reclen;
536 lgi->lgi_buf.lb_buf = rec;
537 rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
541 CDEBUG(D_OTHER, "added record "DOSTID": idx: %u, %u\n",
542 POSTID(&loghandle->lgh_id.lgl_oi), index, rec->lrh_len);
543 if (reccookie != NULL) {
544 reccookie->lgc_lgl = loghandle->lgh_id;
545 reccookie->lgc_index = index;
546 if ((rec->lrh_type == MDS_UNLINK_REC) ||
547 (rec->lrh_type == MDS_SETATTR64_REC))
548 reccookie->lgc_subsys = LLOG_MDS_OST_ORIG_CTXT;
549 else if (rec->lrh_type == OST_SZ_REC)
550 reccookie->lgc_subsys = LLOG_SIZE_ORIG_CTXT;
552 reccookie->lgc_subsys = -1;
557 /* cleanup llog for error case */
558 spin_lock(&loghandle->lgh_hdr_lock);
559 ext2_clear_bit(index, llh->llh_bitmap);
561 spin_unlock(&loghandle->lgh_hdr_lock);
563 /* restore llog last_idx */
564 loghandle->lgh_last_idx--;
565 llh->llh_tail.lrt_index = loghandle->lgh_last_idx;
567 /* restore the header on disk if it was written */
568 if (header_is_updated) {
570 lgi->lgi_buf.lb_len = llh->llh_hdr.lrh_len;
571 lgi->lgi_buf.lb_buf = &llh->llh_hdr;
572 dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
579 * We can skip reading at least as many log blocks as the number of
580 * minimum sized log records we are skipping. If it turns out
581 * that we are not far enough along the log (because the
582 * actual records are larger than minimum size) we just skip
585 static inline void llog_skip_over(__u64 *off, int curr, int goal)
589 *off = (*off + (goal - curr - 1) * LLOG_MIN_REC_SIZE) &
590 ~(LLOG_CHUNK_SIZE - 1);
594 * Remove optional fields that the client doesn't expect.
595 * This is typically in order to ensure compatibility with older clients.
596 * It is assumed that since we exclusively remove fields, the block will be
597 * big enough to handle the remapped records. It is also assumed that records
598 * of a block have the same format (i.e.: the same features enabled).
600 * \param[in,out] hdr Header of the block of records to remap.
601 * \param[in,out] last_hdr Last header, don't read past this point.
602 * \param[in] flags Flags describing the fields to keep.
604 static void changelog_block_trim_ext(struct llog_rec_hdr *hdr,
605 struct llog_rec_hdr *last_hdr,
606 enum changelog_rec_flags flags)
608 if (hdr->lrh_type != CHANGELOG_REC)
612 struct changelog_rec *rec = (struct changelog_rec *)(hdr + 1);
614 changelog_remap_rec(rec, rec->cr_flags & flags);
615 hdr = llog_rec_hdr_next(hdr);
616 } while ((char *)hdr <= (char *)last_hdr);
620 * Implementation of the llog_operations::lop_next_block
622 * This function finds the the next llog block to return which contains
623 * record with required index. It is main part of llog processing.
625 * \param[in] env execution environment
626 * \param[in] loghandle llog handle of the current llog
627 * \param[in,out] cur_idx index preceeding cur_offset
628 * \param[in] next_idx target index to find
629 * \param[in,out] cur_offset furtherst point read in the file
630 * \param[in] buf pointer to data buffer to fill
631 * \param[in] len required len to read, it is
632 * LLOG_CHUNK_SIZE usually.
634 * \retval 0 on successful buffer read
635 * \retval negative value on error
637 static int llog_osd_next_block(const struct lu_env *env,
638 struct llog_handle *loghandle, int *cur_idx,
639 int next_idx, __u64 *cur_offset, void *buf,
642 struct llog_thread_info *lgi = llog_info(env);
644 struct dt_device *dt;
652 if (len == 0 || len & (LLOG_CHUNK_SIZE - 1))
655 CDEBUG(D_OTHER, "looking for log index %u (cur idx %u off "LPU64")\n",
656 next_idx, *cur_idx, *cur_offset);
659 LASSERT(loghandle->lgh_ctxt);
661 o = loghandle->lgh_obj;
663 LASSERT(dt_object_exists(o));
664 dt = lu2dt_dev(o->do_lu.lo_dev);
667 rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA);
671 while (*cur_offset < lgi->lgi_attr.la_size) {
672 struct llog_rec_hdr *rec, *last_rec;
673 struct llog_rec_tail *tail;
675 llog_skip_over(cur_offset, *cur_idx, next_idx);
677 /* read up to next LLOG_CHUNK_SIZE block */
678 lgi->lgi_buf.lb_len = LLOG_CHUNK_SIZE -
679 (*cur_offset & (LLOG_CHUNK_SIZE - 1));
680 lgi->lgi_buf.lb_buf = buf;
682 rc = dt_read(env, o, &lgi->lgi_buf, cur_offset);
684 CERROR("%s: can't read llog block from log "DFID
685 " offset "LPU64": rc = %d\n",
686 o->do_lu.lo_dev->ld_obd->obd_name,
687 PFID(lu_object_fid(&o->do_lu)), *cur_offset,
693 /* signal the end of the valid buffer to
695 memset(buf + rc, 0, len - rc);
698 if (rc == 0) /* end of file, nothing to do */
701 if (rc < sizeof(*tail)) {
702 CERROR("%s: invalid llog block at log id "DOSTID"/%u "
704 o->do_lu.lo_dev->ld_obd->obd_name,
705 POSTID(&loghandle->lgh_id.lgl_oi),
706 loghandle->lgh_id.lgl_ogen, *cur_offset);
707 GOTO(out, rc = -EINVAL);
711 if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
712 lustre_swab_llog_rec(rec);
714 tail = (struct llog_rec_tail *)((char *)buf + rc -
715 sizeof(struct llog_rec_tail));
716 /* get the last record in block */
717 last_rec = (struct llog_rec_hdr *)((char *)buf + rc -
720 if (LLOG_REC_HDR_NEEDS_SWABBING(last_rec))
721 lustre_swab_llog_rec(last_rec);
722 LASSERT(last_rec->lrh_index == tail->lrt_index);
724 *cur_idx = tail->lrt_index;
726 /* this shouldn't happen */
727 if (tail->lrt_index == 0) {
728 CERROR("%s: invalid llog tail at log id "DOSTID"/%u "
730 o->do_lu.lo_dev->ld_obd->obd_name,
731 POSTID(&loghandle->lgh_id.lgl_oi),
732 loghandle->lgh_id.lgl_ogen, *cur_offset);
733 GOTO(out, rc = -EINVAL);
735 if (tail->lrt_index < next_idx)
738 /* sanity check that the start of the new buffer is no farther
739 * than the record that we wanted. This shouldn't happen. */
740 if (rec->lrh_index > next_idx) {
741 CERROR("%s: missed desired record? %u > %u\n",
742 o->do_lu.lo_dev->ld_obd->obd_name,
743 rec->lrh_index, next_idx);
744 GOTO(out, rc = -ENOENT);
747 /* Trim unsupported extensions for compat w/ older clients */
748 if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_JOBID))
749 changelog_block_trim_ext(rec, last_rec,
750 CLF_VERSION | CLF_RENAME);
754 GOTO(out, rc = -EIO);
760 * Implementation of the llog_operations::lop_prev_block
762 * This function finds the llog block to return which contains
763 * record with required index but in reverse order - from end of llog
765 * It is main part of reverse llog processing.
767 * \param[in] env execution environment
768 * \param[in] loghandle llog handle of the current llog
769 * \param[in] prev_idx target index to find
770 * \param[in] buf pointer to data buffer to fill
771 * \param[in] len required len to read, it is LLOG_CHUNK_SIZE usually.
773 * \retval 0 on successful buffer read
774 * \retval negative value on error
776 static int llog_osd_prev_block(const struct lu_env *env,
777 struct llog_handle *loghandle,
778 int prev_idx, void *buf, int len)
780 struct llog_thread_info *lgi = llog_info(env);
782 struct dt_device *dt;
788 if (len == 0 || len & (LLOG_CHUNK_SIZE - 1))
791 CDEBUG(D_OTHER, "looking for log index %u\n", prev_idx);
794 LASSERT(loghandle->lgh_ctxt);
796 o = loghandle->lgh_obj;
798 LASSERT(dt_object_exists(o));
799 dt = lu2dt_dev(o->do_lu.lo_dev);
802 cur_offset = LLOG_CHUNK_SIZE;
803 llog_skip_over(&cur_offset, 0, prev_idx);
805 rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA);
809 while (cur_offset < lgi->lgi_attr.la_size) {
810 struct llog_rec_hdr *rec, *last_rec;
811 struct llog_rec_tail *tail;
813 lgi->lgi_buf.lb_len = len;
814 lgi->lgi_buf.lb_buf = buf;
815 rc = dt_read(env, o, &lgi->lgi_buf, &cur_offset);
817 CERROR("%s: can't read llog block from log "DFID
818 " offset "LPU64": rc = %d\n",
819 o->do_lu.lo_dev->ld_obd->obd_name,
820 PFID(lu_object_fid(&o->do_lu)), cur_offset, rc);
824 if (rc == 0) /* end of file, nothing to do */
827 if (rc < sizeof(*tail)) {
828 CERROR("%s: invalid llog block at log id "DOSTID"/%u "
830 o->do_lu.lo_dev->ld_obd->obd_name,
831 POSTID(&loghandle->lgh_id.lgl_oi),
832 loghandle->lgh_id.lgl_ogen, cur_offset);
833 GOTO(out, rc = -EINVAL);
837 if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
838 lustre_swab_llog_rec(rec);
840 tail = (struct llog_rec_tail *)((char *)buf + rc -
841 sizeof(struct llog_rec_tail));
842 /* get the last record in block */
843 last_rec = (struct llog_rec_hdr *)((char *)buf + rc -
844 le32_to_cpu(tail->lrt_len));
846 if (LLOG_REC_HDR_NEEDS_SWABBING(last_rec))
847 lustre_swab_llog_rec(last_rec);
848 LASSERT(last_rec->lrh_index == tail->lrt_index);
850 /* this shouldn't happen */
851 if (tail->lrt_index == 0) {
852 CERROR("%s: invalid llog tail at log id "DOSTID"/%u "
854 o->do_lu.lo_dev->ld_obd->obd_name,
855 POSTID(&loghandle->lgh_id.lgl_oi),
856 loghandle->lgh_id.lgl_ogen, cur_offset);
857 GOTO(out, rc = -EINVAL);
859 if (tail->lrt_index < prev_idx)
862 /* sanity check that the start of the new buffer is no farther
863 * than the record that we wanted. This shouldn't happen. */
864 if (rec->lrh_index > prev_idx) {
865 CERROR("%s: missed desired record? %u > %u\n",
866 o->do_lu.lo_dev->ld_obd->obd_name,
867 rec->lrh_index, prev_idx);
868 GOTO(out, rc = -ENOENT);
871 /* Trim unsupported extensions for compat w/ older clients */
872 if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_JOBID))
873 changelog_block_trim_ext(rec, last_rec,
874 CLF_VERSION | CLF_RENAME);
878 GOTO(out, rc = -EIO);
884 * This is helper function to get llog directory object. It is used by named
885 * llog operations to find/insert/delete llog entry from llog directory.
887 * \param[in] env execution environment
888 * \param[in] ctxt llog context
890 * \retval dt_object of llog directory
891 * \retval ERR_PTR of negative value on error
893 static struct dt_object *llog_osd_dir_get(const struct lu_env *env,
894 struct llog_ctxt *ctxt)
896 struct dt_device *dt;
897 struct dt_thread_info *dti = dt_info(env);
898 struct dt_object *dir;
901 dt = ctxt->loc_exp->exp_obd->obd_lvfs_ctxt.dt;
902 if (ctxt->loc_dir == NULL) {
903 rc = dt_root_get(env, dt, &dti->dti_fid);
906 dir = dt_locate(env, dt, &dti->dti_fid);
908 if (!IS_ERR(dir) && !dt_try_as_dir(env, dir)) {
909 lu_object_put(env, &dir->do_lu);
910 return ERR_PTR(-ENOTDIR);
913 lu_object_get(&ctxt->loc_dir->do_lu);
921 * Implementation of the llog_operations::lop_open
923 * This function opens the llog by its logid or by name, it may open also
924 * non existent llog and assing then new id to it.
925 * The llog_open/llog_close pair works similar to lu_object_find/put,
926 * the object may not exist prior open. The result of open is just dt_object
927 * in the llog header.
929 * \param[in] env execution environment
930 * \param[in] handle llog handle of the current llog
931 * \param[in] logid logid of llog to open (nameless llog)
932 * \param[in] name name of llog to open (named llog)
933 * \param[in] open_param
934 * LLOG_OPEN_NEW - new llog, may not exist
935 * LLOG_OPEN_EXIST - old llog, must exist
937 * \retval 0 on successful open, llog_handle::lgh_obj
938 * contains the dt_object of the llog.
939 * \retval negative value on error
941 static int llog_osd_open(const struct lu_env *env, struct llog_handle *handle,
942 struct llog_logid *logid, char *name,
943 enum llog_open_param open_param)
945 struct llog_thread_info *lgi = llog_info(env);
946 struct llog_ctxt *ctxt = handle->lgh_ctxt;
948 struct dt_device *dt;
949 struct ls_device *ls;
950 struct local_oid_storage *los;
957 LASSERT(ctxt->loc_exp);
958 LASSERT(ctxt->loc_exp->exp_obd);
959 dt = ctxt->loc_exp->exp_obd->obd_lvfs_ctxt.dt;
962 ls = ls_device_get(dt);
966 mutex_lock(&ls->ls_los_mutex);
967 los = dt_los_find(ls, name != NULL ? FID_SEQ_LLOG_NAME : FID_SEQ_LLOG);
968 mutex_unlock(&ls->ls_los_mutex);
970 ls_device_put(env, ls);
975 logid_to_fid(logid, &lgi->lgi_fid);
977 struct dt_object *llog_dir;
979 llog_dir = llog_osd_dir_get(env, ctxt);
980 if (IS_ERR(llog_dir))
981 GOTO(out, rc = PTR_ERR(llog_dir));
982 dt_read_lock(env, llog_dir, 0);
983 rc = dt_lookup_dir(env, llog_dir, name, &lgi->lgi_fid);
984 dt_read_unlock(env, llog_dir);
985 lu_object_put(env, &llog_dir->do_lu);
986 if (rc == -ENOENT && open_param == LLOG_OPEN_NEW) {
987 /* generate fid for new llog */
988 rc = local_object_fid_generate(env, los,
993 OBD_ALLOC(handle->lgh_name, strlen(name) + 1);
994 if (handle->lgh_name)
995 strcpy(handle->lgh_name, name);
997 GOTO(out, rc = -ENOMEM);
999 LASSERTF(open_param & LLOG_OPEN_NEW, "%#x\n", open_param);
1000 /* generate fid for new llog */
1001 rc = local_object_fid_generate(env, los, &lgi->lgi_fid);
1006 o = ls_locate(env, ls, &lgi->lgi_fid, NULL);
1008 GOTO(out_name, rc = PTR_ERR(o));
1010 /* No new llog is expected but doesn't exist */
1011 if (open_param != LLOG_OPEN_NEW && !dt_object_exists(o))
1012 GOTO(out_put, rc = -ENOENT);
1014 fid_to_logid(&lgi->lgi_fid, &handle->lgh_id);
1015 handle->lgh_obj = o;
1016 handle->private_data = los;
1017 LASSERT(handle->lgh_ctxt);
1022 lu_object_put(env, &o->do_lu);
1024 if (handle->lgh_name != NULL)
1025 OBD_FREE(handle->lgh_name, strlen(name) + 1);
1032 * Implementation of the llog_operations::lop_exist
1034 * This function checks that llog exists on storage.
1036 * \param[in] handle llog handle of the current llog
1038 * \retval true if llog object exists and is not just destroyed
1039 * \retval false if llog doesn't exist or just destroyed
1041 static int llog_osd_exist(struct llog_handle *handle)
1043 LASSERT(handle->lgh_obj);
1044 return (dt_object_exists(handle->lgh_obj) &&
1045 !lu_object_is_dying(handle->lgh_obj->do_lu.lo_header));
1049 * Implementation of the llog_operations::lop_declare_create
1051 * This function declares the llog create. It declares also name insert
1052 * into llog directory in case of named llog.
1054 * \param[in] env execution environment
1055 * \param[in] res llog handle of the current llog
1056 * \param[in] th current transaction handle
1058 * \retval 0 on successful create declaration
1059 * \retval negative value on error
1061 static int llog_osd_declare_create(const struct lu_env *env,
1062 struct llog_handle *res, struct thandle *th)
1064 struct llog_thread_info *lgi = llog_info(env);
1065 struct dt_insert_rec *rec = &lgi->lgi_dt_rec;
1066 struct local_oid_storage *los;
1067 struct dt_object *o;
1072 LASSERT(res->lgh_obj);
1075 /* object can be created by another thread */
1077 if (dt_object_exists(o))
1080 los = res->private_data;
1083 rc = llog_osd_declare_new_object(env, los, o, th);
1087 /* do not declare header initialization here as it's declared
1088 * in llog_osd_declare_write_rec() which is always called */
1090 if (res->lgh_name) {
1091 struct dt_object *llog_dir;
1093 llog_dir = llog_osd_dir_get(env, res->lgh_ctxt);
1094 if (IS_ERR(llog_dir))
1095 RETURN(PTR_ERR(llog_dir));
1096 logid_to_fid(&res->lgh_id, &lgi->lgi_fid);
1097 rec->rec_fid = &lgi->lgi_fid;
1098 rec->rec_type = S_IFREG;
1099 rc = dt_declare_insert(env, llog_dir,
1100 (struct dt_rec *)rec,
1101 (struct dt_key *)res->lgh_name, th);
1102 lu_object_put(env, &llog_dir->do_lu);
1104 CERROR("%s: can't declare named llog %s: rc = %d\n",
1105 o->do_lu.lo_dev->ld_obd->obd_name,
1112 * Implementation of the llog_operations::lop_create
1114 * This function creates the llog according with llog_handle::lgh_obj
1115 * and llog_handle::lgh_name.
1117 * \param[in] env execution environment
1118 * \param[in] res llog handle of the current llog
1119 * \param[in] th current transaction handle
1121 * \retval 0 on successful create
1122 * \retval negative value on error
1124 static int llog_osd_create(const struct lu_env *env, struct llog_handle *res,
1127 struct llog_thread_info *lgi = llog_info(env);
1128 struct dt_insert_rec *rec = &lgi->lgi_dt_rec;
1129 struct local_oid_storage *los;
1130 struct dt_object *o;
1139 /* llog can be already created */
1140 if (dt_object_exists(o))
1143 los = res->private_data;
1146 dt_write_lock(env, o, 0);
1147 if (!dt_object_exists(o))
1148 rc = llog_osd_create_new_object(env, los, o, th);
1152 dt_write_unlock(env, o);
1156 if (res->lgh_name) {
1157 struct dt_object *llog_dir;
1159 llog_dir = llog_osd_dir_get(env, res->lgh_ctxt);
1160 if (IS_ERR(llog_dir))
1161 RETURN(PTR_ERR(llog_dir));
1163 logid_to_fid(&res->lgh_id, &lgi->lgi_fid);
1164 rec->rec_fid = &lgi->lgi_fid;
1165 rec->rec_type = S_IFREG;
1166 dt_read_lock(env, llog_dir, 0);
1167 rc = dt_insert(env, llog_dir, (struct dt_rec *)rec,
1168 (struct dt_key *)res->lgh_name,
1169 th, BYPASS_CAPA, 1);
1170 dt_read_unlock(env, llog_dir);
1171 lu_object_put(env, &llog_dir->do_lu);
1173 CERROR("%s: can't create named llog %s: rc = %d\n",
1174 o->do_lu.lo_dev->ld_obd->obd_name,
1181 * Implementation of the llog_operations::lop_close
1183 * This function closes the llog. It just put llog object and referenced
1186 * \param[in] env execution environment
1187 * \param[in] handle llog handle of the current llog
1189 * \retval 0 on successful llog close
1190 * \retval negative value on error
1192 static int llog_osd_close(const struct lu_env *env, struct llog_handle *handle)
1194 struct local_oid_storage *los;
1199 LASSERT(handle->lgh_obj);
1201 lu_object_put(env, &handle->lgh_obj->do_lu);
1203 los = handle->private_data;
1207 if (handle->lgh_name)
1208 OBD_FREE(handle->lgh_name, strlen(handle->lgh_name) + 1);
1214 * Implementation of the llog_operations::lop_destroy
1216 * This function destroys the llog and deletes also entry in the
1217 * llog directory in case of named llog. Llog should be opened prior that.
1218 * Destroy method is not part of external transaction and does everything
1221 * \param[in] env execution environment
1222 * \param[in] loghandle llog handle of the current llog
1224 * \retval 0 on successful destroy
1225 * \retval negative value on error
1227 static int llog_osd_destroy(const struct lu_env *env,
1228 struct llog_handle *loghandle)
1230 struct llog_ctxt *ctxt;
1231 struct dt_object *o, *llog_dir = NULL;
1232 struct dt_device *d;
1239 ctxt = loghandle->lgh_ctxt;
1242 o = loghandle->lgh_obj;
1245 d = lu2dt_dev(o->do_lu.lo_dev);
1247 LASSERT(d == ctxt->loc_exp->exp_obd->obd_lvfs_ctxt.dt);
1249 th = dt_trans_create(env, d);
1251 RETURN(PTR_ERR(th));
1253 if (loghandle->lgh_name) {
1254 llog_dir = llog_osd_dir_get(env, ctxt);
1255 if (IS_ERR(llog_dir))
1256 GOTO(out_trans, rc = PTR_ERR(llog_dir));
1258 name = loghandle->lgh_name;
1259 rc = dt_declare_delete(env, llog_dir,
1260 (struct dt_key *)name, th);
1262 GOTO(out_trans, rc);
1265 rc = dt_declare_ref_del(env, o, th);
1267 GOTO(out_trans, rc);
1269 rc = dt_declare_destroy(env, o, th);
1271 GOTO(out_trans, rc);
1273 rc = dt_trans_start_local(env, d, th);
1275 GOTO(out_trans, rc);
1277 dt_write_lock(env, o, 0);
1278 if (dt_object_exists(o)) {
1280 dt_read_lock(env, llog_dir, 0);
1281 rc = dt_delete(env, llog_dir,
1282 (struct dt_key *) name,
1284 dt_read_unlock(env, llog_dir);
1286 CERROR("%s: can't remove llog %s: rc = %d\n",
1287 o->do_lu.lo_dev->ld_obd->obd_name,
1289 GOTO(out_unlock, rc);
1292 dt_ref_del(env, o, th);
1293 rc = dt_destroy(env, o, th);
1295 GOTO(out_unlock, rc);
1298 dt_write_unlock(env, o);
1300 dt_trans_stop(env, d, th);
1301 if (llog_dir != NULL)
1302 lu_object_put(env, &llog_dir->do_lu);
1307 * Implementation of the llog_operations::lop_setup
1309 * This function setup the llog on local storage.
1311 * \param[in] env execution environment
1312 * \param[in] obd obd device the llog belongs to
1313 * \param[in] olg the llog group, it is always zero group now.
1314 * \param[in] ctxt_idx the llog index, it defines the purpose of this llog.
1315 * Every new llog type have to use own index.
1316 * \param[in] disk_obd the storage obd, where llog is stored.
1318 * \retval 0 on successful llog setup
1319 * \retval negative value on error
1321 static int llog_osd_setup(const struct lu_env *env, struct obd_device *obd,
1322 struct obd_llog_group *olg, int ctxt_idx,
1323 struct obd_device *disk_obd)
1325 struct llog_thread_info *lgi = llog_info(env);
1326 struct llog_ctxt *ctxt;
1331 LASSERT(olg->olg_ctxts[ctxt_idx]);
1333 ctxt = llog_ctxt_get(olg->olg_ctxts[ctxt_idx]);
1336 /* initialize data allowing to generate new fids,
1337 * literally we need a sequece */
1338 lgi->lgi_fid.f_seq = FID_SEQ_LLOG;
1339 lgi->lgi_fid.f_oid = 1;
1340 lgi->lgi_fid.f_ver = 0;
1341 rc = local_oid_storage_init(env, disk_obd->obd_lvfs_ctxt.dt,
1343 &ctxt->loc_los_nameless);
1347 lgi->lgi_fid.f_seq = FID_SEQ_LLOG_NAME;
1348 lgi->lgi_fid.f_oid = 1;
1349 lgi->lgi_fid.f_ver = 0;
1350 rc = local_oid_storage_init(env, disk_obd->obd_lvfs_ctxt.dt,
1352 &ctxt->loc_los_named);
1354 local_oid_storage_fini(env, ctxt->loc_los_nameless);
1355 ctxt->loc_los_nameless = NULL;
1361 llog_ctxt_put(ctxt);
1366 * Implementation of the llog_operations::lop_cleanup
1368 * This function cleanups the llog on local storage.
1370 * \param[in] env execution environment
1371 * \param[in] ctxt the llog context
1375 static int llog_osd_cleanup(const struct lu_env *env, struct llog_ctxt *ctxt)
1377 if (ctxt->loc_los_nameless != NULL) {
1378 local_oid_storage_fini(env, ctxt->loc_los_nameless);
1379 ctxt->loc_los_nameless = NULL;
1382 if (ctxt->loc_los_named != NULL) {
1383 local_oid_storage_fini(env, ctxt->loc_los_named);
1384 ctxt->loc_los_named = NULL;
1390 struct llog_operations llog_osd_ops = {
1391 .lop_next_block = llog_osd_next_block,
1392 .lop_prev_block = llog_osd_prev_block,
1393 .lop_read_header = llog_osd_read_header,
1394 .lop_destroy = llog_osd_destroy,
1395 .lop_setup = llog_osd_setup,
1396 .lop_cleanup = llog_osd_cleanup,
1397 .lop_open = llog_osd_open,
1398 .lop_exist = llog_osd_exist,
1399 .lop_declare_create = llog_osd_declare_create,
1400 .lop_create = llog_osd_create,
1401 .lop_declare_write_rec = llog_osd_declare_write_rec,
1402 .lop_write_rec = llog_osd_write_rec,
1403 .lop_close = llog_osd_close,
1405 EXPORT_SYMBOL(llog_osd_ops);
1408 * Read the special file which contains the list of llog catalogs IDs
1410 * This function reads the CATALOGS file which contains the array of llog
1411 * catalogs IDs. The main purpose of this file is to store OSP llogs indexed
1412 * by OST/MDT number.
1414 * \param[in] env execution environment
1415 * \param[in] d corresponding storage device
1416 * \param[in] idx position to start from, usually OST/MDT index
1417 * \param[in] count how many catalog IDs to read
1418 * \param[out] idarray the buffer for the data. If it is NULL then
1419 * function returns just number of catalog IDs
1421 * \param[in] fid LLOG_CATALOGS_OID for CATALOG object
1423 * \retval 0 on successful read of catalog IDs
1424 * \retval negative value on error
1425 * \retval positive value which is number of records in
1426 * the file if \a idarray is NULL
1428 int llog_osd_get_cat_list(const struct lu_env *env, struct dt_device *d,
1429 int idx, int count, struct llog_catid *idarray,
1430 const struct lu_fid *fid)
1432 struct llog_thread_info *lgi = llog_info(env);
1433 struct dt_object *o = NULL;
1441 size = sizeof(*idarray) * count;
1442 lgi->lgi_off = idx * sizeof(*idarray);
1444 lgi->lgi_fid = *fid;
1445 o = dt_locate(env, d, &lgi->lgi_fid);
1449 if (!dt_object_exists(o)) {
1450 th = dt_trans_create(env, d);
1452 GOTO(out, rc = PTR_ERR(th));
1454 lgi->lgi_attr.la_valid = LA_MODE;
1455 lgi->lgi_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
1456 lgi->lgi_dof.dof_type = dt_mode_to_dft(S_IFREG);
1458 rc = dt_declare_create(env, o, &lgi->lgi_attr, NULL,
1461 GOTO(out_trans, rc);
1463 rc = dt_trans_start_local(env, d, th);
1465 GOTO(out_trans, rc);
1467 dt_write_lock(env, o, 0);
1468 if (!dt_object_exists(o))
1469 rc = dt_create(env, o, &lgi->lgi_attr, NULL,
1471 dt_write_unlock(env, o);
1473 dt_trans_stop(env, d, th);
1478 rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA);
1482 if (!S_ISREG(lgi->lgi_attr.la_mode)) {
1483 CERROR("%s: CATALOGS is not a regular file!: mode = %o\n",
1484 o->do_lu.lo_dev->ld_obd->obd_name,
1485 lgi->lgi_attr.la_mode);
1486 GOTO(out, rc = -ENOENT);
1489 CDEBUG(D_CONFIG, "cat list: disk size=%d, read=%d\n",
1490 (int)lgi->lgi_attr.la_size, size);
1492 /* return just number of llogs */
1493 if (idarray == NULL) {
1494 rc = lgi->lgi_attr.la_size / sizeof(*idarray);
1498 /* read for new ost index or for empty file */
1499 memset(idarray, 0, size);
1500 if (lgi->lgi_attr.la_size <= lgi->lgi_off)
1502 if (lgi->lgi_attr.la_size < lgi->lgi_off + size)
1503 size = lgi->lgi_attr.la_size - lgi->lgi_off;
1505 lgi->lgi_buf.lb_buf = idarray;
1506 lgi->lgi_buf.lb_len = size;
1507 rc = dt_record_read(env, o, &lgi->lgi_buf, &lgi->lgi_off);
1508 /* -EFAULT means the llog is a sparse file. This is not an error
1509 * after arbitrary OST index is supported. */
1510 if (rc < 0 && rc != -EFAULT) {
1511 CERROR("%s: error reading CATALOGS: rc = %d\n",
1512 o->do_lu.lo_dev->ld_obd->obd_name, rc);
1518 lu_object_put(env, &o->do_lu);
1521 EXPORT_SYMBOL(llog_osd_get_cat_list);
1524 * Write the special file which contains the list of llog catalogs IDs
1526 * This function writes the CATALOG file which contains the array of llog
1527 * catalogs IDs. It is used mostly to store OSP llogs indexed by OST/MDT
1530 * \param[in] env execution environment
1531 * \param[in] d corresponding storage device
1532 * \param[in] idx position to start from, usually OST/MDT index
1533 * \param[in] count how many catalog IDs to write
1534 * \param[out] idarray the buffer with the data to write.
1535 * \param[in] fid LLOG_CATALOGS_OID for CATALOG object
1537 * \retval 0 on successful write of catalog IDs
1538 * \retval negative value on error
1540 int llog_osd_put_cat_list(const struct lu_env *env, struct dt_device *d,
1541 int idx, int count, struct llog_catid *idarray,
1542 const struct lu_fid *fid)
1544 struct llog_thread_info *lgi = llog_info(env);
1545 struct dt_object *o = NULL;
1554 size = sizeof(*idarray) * count;
1555 lgi->lgi_off = idx * sizeof(*idarray);
1556 lgi->lgi_fid = *fid;
1558 o = dt_locate(env, d, &lgi->lgi_fid);
1562 if (!dt_object_exists(o))
1563 GOTO(out, rc = -ENOENT);
1565 rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA);
1569 if (!S_ISREG(lgi->lgi_attr.la_mode)) {
1570 CERROR("%s: CATALOGS is not a regular file!: mode = %o\n",
1571 o->do_lu.lo_dev->ld_obd->obd_name,
1572 lgi->lgi_attr.la_mode);
1573 GOTO(out, rc = -ENOENT);
1576 th = dt_trans_create(env, d);
1578 GOTO(out, rc = PTR_ERR(th));
1580 lgi->lgi_buf.lb_len = size;
1581 lgi->lgi_buf.lb_buf = idarray;
1582 rc = dt_declare_record_write(env, o, &lgi->lgi_buf, lgi->lgi_off, th);
1586 rc = dt_trans_start_local(env, d, th);
1588 GOTO(out_trans, rc);
1590 rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
1592 CDEBUG(D_INODE, "can't write CATALOGS at index %d: rc = %d\n",
1595 dt_trans_stop(env, d, th);
1597 lu_object_put(env, &o->do_lu);
1600 EXPORT_SYMBOL(llog_osd_put_cat_list);