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_lvfs.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>
44 #define DEBUG_SUBSYSTEM S_LOG
47 #include <liblustre.h>
51 #include <obd_class.h>
52 #include <lustre_log.h>
54 #include <libcfs/list.h>
56 #include <lustre_fsfilt.h>
57 #include <lustre_disk.h>
58 #include "llog_internal.h"
60 #if defined(__KERNEL__) && defined(LLOG_LVFS)
62 static int llog_lvfs_pad(struct obd_device *obd, struct l_file *file,
65 struct llog_rec_hdr rec = { 0 };
66 struct llog_rec_tail tail;
70 LASSERT(len >= LLOG_MIN_REC_SIZE && (len & 0x7) == 0);
72 tail.lrt_len = rec.lrh_len = len;
73 tail.lrt_index = rec.lrh_index = index;
74 rec.lrh_type = LLOG_PAD_MAGIC;
76 rc = fsfilt_write_record(obd, file, &rec, sizeof(rec), &file->f_pos, 0);
78 CERROR("error writing padding record: rc %d\n", rc);
82 file->f_pos += len - sizeof(rec) - sizeof(tail);
83 rc = fsfilt_write_record(obd, file, &tail, sizeof(tail),&file->f_pos,0);
85 CERROR("error writing padding record: rc %d\n", rc);
93 static int llog_lvfs_write_blob(struct obd_device *obd, struct l_file *file,
94 struct llog_rec_hdr *rec, void *buf, loff_t off)
97 struct llog_rec_tail end;
98 loff_t saved_off = file->f_pos;
99 int buflen = rec->lrh_len;
106 CWARN("0-length record\n");
109 rc = fsfilt_write_record(obd, file, rec, buflen,&file->f_pos,0);
111 CERROR("error writing log record: rc %d\n", rc);
118 rec->lrh_len = sizeof(*rec) + buflen + sizeof(end);
119 rc = fsfilt_write_record(obd, file, rec, sizeof(*rec), &file->f_pos, 0);
121 CERROR("error writing log hdr: rc %d\n", rc);
125 rc = fsfilt_write_record(obd, file, buf, buflen, &file->f_pos, 0);
127 CERROR("error writing log buffer: rc %d\n", rc);
131 end.lrt_len = rec->lrh_len;
132 end.lrt_index = rec->lrh_index;
133 rc = fsfilt_write_record(obd, file, &end, sizeof(end), &file->f_pos, 0);
135 CERROR("error writing log tail: rc %d\n", rc);
141 if (saved_off > file->f_pos)
142 file->f_pos = saved_off;
147 static int llog_lvfs_read_blob(struct obd_device *obd, struct l_file *file,
148 void *buf, int size, loff_t off)
154 rc = fsfilt_read_record(obd, file, buf, size, &offset);
156 CERROR("error reading log record: rc %d\n", rc);
162 static int llog_lvfs_read_header(const struct lu_env *env,
163 struct llog_handle *handle)
165 struct obd_device *obd;
169 LASSERT(sizeof(*handle->lgh_hdr) == LLOG_CHUNK_SIZE);
171 obd = handle->lgh_ctxt->loc_exp->exp_obd;
173 if (i_size_read(handle->lgh_file->f_dentry->d_inode) == 0) {
174 CDEBUG(D_HA, "not reading header from 0-byte log\n");
178 rc = llog_lvfs_read_blob(obd, handle->lgh_file, handle->lgh_hdr,
181 CERROR("error reading log header from %.*s\n",
182 handle->lgh_file->f_dentry->d_name.len,
183 handle->lgh_file->f_dentry->d_name.name);
185 struct llog_rec_hdr *llh_hdr = &handle->lgh_hdr->llh_hdr;
187 if (LLOG_REC_HDR_NEEDS_SWABBING(llh_hdr))
188 lustre_swab_llog_hdr(handle->lgh_hdr);
190 if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) {
191 CERROR("bad log %.*s header magic: %#x (expected %#x)\n",
192 handle->lgh_file->f_dentry->d_name.len,
193 handle->lgh_file->f_dentry->d_name.name,
194 llh_hdr->lrh_type, LLOG_HDR_MAGIC);
196 } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) {
197 CERROR("incorrectly sized log %.*s header: %#x "
199 handle->lgh_file->f_dentry->d_name.len,
200 handle->lgh_file->f_dentry->d_name.name,
201 llh_hdr->lrh_len, LLOG_CHUNK_SIZE);
202 CERROR("you may need to re-run lconf --write_conf.\n");
207 handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index;
208 handle->lgh_file->f_pos = i_size_read(handle->lgh_file->f_dentry->d_inode);
213 /* returns negative in on error; 0 if success && reccookie == 0; 1 otherwise */
214 /* appends if idx == -1, otherwise overwrites record idx. */
215 static int llog_lvfs_write_rec(const struct lu_env *env,
216 struct llog_handle *loghandle,
217 struct llog_rec_hdr *rec,
218 struct llog_cookie *reccookie, int cookiecount,
221 struct llog_log_hdr *llh;
222 int reclen = rec->lrh_len, index, rc;
223 struct llog_rec_tail *lrt;
224 struct obd_device *obd;
229 llh = loghandle->lgh_hdr;
230 file = loghandle->lgh_file;
231 obd = loghandle->lgh_ctxt->loc_exp->exp_obd;
233 /* record length should not bigger than LLOG_CHUNK_SIZE */
235 rc = (reclen > LLOG_CHUNK_SIZE - sizeof(struct llog_rec_hdr) -
236 sizeof(struct llog_rec_tail)) ? -E2BIG : 0;
238 rc = (reclen > LLOG_CHUNK_SIZE) ? -E2BIG : 0;
243 /* write_blob adds header and tail to lrh_len. */
244 reclen = sizeof(*rec) + rec->lrh_len +
245 sizeof(struct llog_rec_tail);
250 /* no header: only allowed to insert record 1 */
251 if (idx != 1 && !i_size_read(file->f_dentry->d_inode)) {
252 CERROR("idx != -1 in empty log\n");
256 if (idx && llh->llh_size && llh->llh_size != rec->lrh_len)
259 if (!ext2_test_bit(idx, llh->llh_bitmap))
260 CERROR("Modify unset record %u\n", idx);
261 if (idx != rec->lrh_index)
262 CERROR("Index mismatch %d %u\n", idx, rec->lrh_index);
264 rc = llog_lvfs_write_blob(obd, file, &llh->llh_hdr, NULL, 0);
265 /* we are done if we only write the header or on error */
269 /* Assumes constant lrh_len */
270 saved_offset = sizeof(*llh) + (idx - 1) * reclen;
273 struct llog_rec_hdr check;
275 /* We assume that caller has set lgh_cur_* */
276 saved_offset = loghandle->lgh_cur_offset;
278 "modify record "LPX64": idx:%d/%u/%d, len:%u "
280 loghandle->lgh_id.lgl_oid, idx, rec->lrh_index,
281 loghandle->lgh_cur_idx, rec->lrh_len,
282 (long long)(saved_offset - sizeof(*llh)));
283 if (rec->lrh_index != loghandle->lgh_cur_idx) {
284 CERROR("modify idx mismatch %u/%d\n",
285 idx, loghandle->lgh_cur_idx);
288 #if 1 /* FIXME remove this safety check at some point */
289 /* Verify that the record we're modifying is the
291 rc = llog_lvfs_read_blob(obd, file, &check,
292 sizeof(check), saved_offset);
293 if (check.lrh_index != idx || check.lrh_len != reclen) {
294 CERROR("Bad modify idx %u/%u size %u/%u (%d)\n",
295 idx, check.lrh_index, reclen,
302 rc = llog_lvfs_write_blob(obd, file, rec, buf, saved_offset);
303 if (rc == 0 && reccookie) {
304 reccookie->lgc_lgl = loghandle->lgh_id;
305 reccookie->lgc_index = idx;
311 /* Make sure that records don't cross a chunk boundary, so we can
312 * process them page-at-a-time if needed. If it will cross a chunk
313 * boundary, write in a fake (but referenced) entry to pad the chunk.
315 * We know that llog_current_log() will return a loghandle that is
316 * big enough to hold reclen, so all we care about is padding here.
318 left = LLOG_CHUNK_SIZE - (file->f_pos & (LLOG_CHUNK_SIZE - 1));
320 /* NOTE: padding is a record, but no bit is set */
321 if (left != 0 && left != reclen &&
322 left < (reclen + LLOG_MIN_REC_SIZE)) {
323 index = loghandle->lgh_last_idx + 1;
324 rc = llog_lvfs_pad(obd, file, left, index);
327 loghandle->lgh_last_idx++; /*for pad rec*/
329 /* if it's the last idx in log file, then return -ENOSPC */
330 if (loghandle->lgh_last_idx >= LLOG_BITMAP_SIZE(llh) - 1)
332 loghandle->lgh_last_idx++;
333 index = loghandle->lgh_last_idx;
334 LASSERT(index < LLOG_BITMAP_SIZE(llh));
335 rec->lrh_index = index;
337 lrt = (struct llog_rec_tail *)
338 ((char *)rec + rec->lrh_len - sizeof(*lrt));
339 lrt->lrt_len = rec->lrh_len;
340 lrt->lrt_index = rec->lrh_index;
342 /*The caller should make sure only 1 process access the lgh_last_idx,
343 *Otherwise it might hit the assert.*/
344 LASSERT(index < LLOG_BITMAP_SIZE(llh));
345 if (ext2_set_bit(index, llh->llh_bitmap)) {
346 CERROR("argh, index %u already set in log bitmap?\n", index);
347 LBUG(); /* should never happen */
350 llh->llh_tail.lrt_index = index;
352 rc = llog_lvfs_write_blob(obd, file, &llh->llh_hdr, NULL, 0);
356 rc = llog_lvfs_write_blob(obd, file, rec, buf, file->f_pos);
360 CDEBUG(D_RPCTRACE, "added record "LPX64": idx: %u, %u \n",
361 loghandle->lgh_id.lgl_oid, index, rec->lrh_len);
362 if (rc == 0 && reccookie) {
363 reccookie->lgc_lgl = loghandle->lgh_id;
364 reccookie->lgc_index = index;
365 if ((rec->lrh_type == MDS_UNLINK_REC) ||
366 (rec->lrh_type == MDS_SETATTR64_REC))
367 reccookie->lgc_subsys = LLOG_MDS_OST_ORIG_CTXT;
368 else if (rec->lrh_type == OST_SZ_REC)
369 reccookie->lgc_subsys = LLOG_SIZE_ORIG_CTXT;
371 reccookie->lgc_subsys = -1;
374 if (rc == 0 && rec->lrh_type == LLOG_GEN_REC)
380 /* We can skip reading at least as many log blocks as the number of
381 * minimum sized log records we are skipping. If it turns out
382 * that we are not far enough along the log (because the
383 * actual records are larger than minimum size) we just skip
384 * some more records. */
386 static void llog_skip_over(__u64 *off, int curr, int goal)
390 *off = (*off + (goal-curr-1) * LLOG_MIN_REC_SIZE) &
391 ~(LLOG_CHUNK_SIZE - 1);
396 * - cur_offset to the furthest point read in the log file
397 * - cur_idx to the log index preceeding cur_offset
398 * returns -EIO/-EINVAL on error
400 static int llog_lvfs_next_block(const struct lu_env *env,
401 struct llog_handle *loghandle, int *cur_idx,
402 int next_idx, __u64 *cur_offset, void *buf,
408 if (len == 0 || len & (LLOG_CHUNK_SIZE - 1))
411 CDEBUG(D_OTHER, "looking for log index %u (cur idx %u off "LPU64")\n",
412 next_idx, *cur_idx, *cur_offset);
414 while (*cur_offset < i_size_read(loghandle->lgh_file->f_dentry->d_inode)) {
415 struct llog_rec_hdr *rec;
416 struct llog_rec_tail *tail;
419 llog_skip_over(cur_offset, *cur_idx, next_idx);
422 rc = fsfilt_read_record(loghandle->lgh_ctxt->loc_exp->exp_obd,
423 loghandle->lgh_file, buf, len,
426 CERROR("Cant read llog block at log id "LPU64
427 "/%u offset "LPU64"\n",
428 loghandle->lgh_id.lgl_oid,
429 loghandle->lgh_id.lgl_ogen,
434 /* put number of bytes read into rc to make code simpler */
435 rc = ppos - *cur_offset;
439 /* signal the end of the valid buffer to llog_process */
440 memset(buf + rc, 0, len - rc);
443 if (rc == 0) /* end of file, nothing to do */
446 if (rc < sizeof(*tail)) {
447 CERROR("Invalid llog block at log id "LPU64"/%u offset "
448 LPU64"\n", loghandle->lgh_id.lgl_oid,
449 loghandle->lgh_id.lgl_ogen, *cur_offset);
454 tail = (struct llog_rec_tail *)((char *)buf + rc -
455 sizeof(struct llog_rec_tail));
457 if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
458 lustre_swab_llog_rec(rec);
460 *cur_idx = tail->lrt_index;
462 /* this shouldn't happen */
463 if (tail->lrt_index == 0) {
464 CERROR("Invalid llog tail at log id "LPU64"/%u offset "
465 LPU64"\n", loghandle->lgh_id.lgl_oid,
466 loghandle->lgh_id.lgl_ogen, *cur_offset);
469 if (tail->lrt_index < next_idx)
472 /* sanity check that the start of the new buffer is no farther
473 * than the record that we wanted. This shouldn't happen. */
474 if (rec->lrh_index > next_idx) {
475 CERROR("missed desired record? %u > %u\n",
476 rec->lrh_index, next_idx);
484 static int llog_lvfs_prev_block(const struct lu_env *env,
485 struct llog_handle *loghandle,
486 int prev_idx, void *buf, int len)
492 if (len == 0 || len & (LLOG_CHUNK_SIZE - 1))
495 CDEBUG(D_OTHER, "looking for log index %u\n", prev_idx);
497 cur_offset = LLOG_CHUNK_SIZE;
498 llog_skip_over(&cur_offset, 0, prev_idx);
500 while (cur_offset < i_size_read(loghandle->lgh_file->f_dentry->d_inode)) {
501 struct llog_rec_hdr *rec;
502 struct llog_rec_tail *tail;
507 rc = fsfilt_read_record(loghandle->lgh_ctxt->loc_exp->exp_obd,
508 loghandle->lgh_file, buf, len,
511 CERROR("Cant read llog block at log id "LPU64
512 "/%u offset "LPU64"\n",
513 loghandle->lgh_id.lgl_oid,
514 loghandle->lgh_id.lgl_ogen,
519 /* put number of bytes read into rc to make code simpler */
520 rc = ppos - cur_offset;
523 if (rc == 0) /* end of file, nothing to do */
526 if (rc < sizeof(*tail)) {
527 CERROR("Invalid llog block at log id "LPU64"/%u offset "
528 LPU64"\n", loghandle->lgh_id.lgl_oid,
529 loghandle->lgh_id.lgl_ogen, cur_offset);
533 tail = buf + rc - sizeof(struct llog_rec_tail);
535 /* this shouldn't happen */
536 if (tail->lrt_index == 0) {
537 CERROR("Invalid llog tail at log id "LPU64"/%u offset "
538 LPU64"\n", loghandle->lgh_id.lgl_oid,
539 loghandle->lgh_id.lgl_ogen, cur_offset);
542 if (le32_to_cpu(tail->lrt_index) < prev_idx)
545 /* sanity check that the start of the new buffer is no farther
546 * than the record that we wanted. This shouldn't happen. */
548 if (le32_to_cpu(rec->lrh_index) > prev_idx) {
549 CERROR("missed desired record? %u > %u\n",
550 le32_to_cpu(rec->lrh_index), prev_idx);
558 static struct file *llog_filp_open(char *dir, char *name, int flags, int mode)
564 OBD_ALLOC(logname, PATH_MAX);
566 return ERR_PTR(-ENOMEM);
568 len = snprintf(logname, PATH_MAX, "%s/%s", dir, name);
569 if (len >= PATH_MAX - 1) {
570 filp = ERR_PTR(-ENAMETOOLONG);
572 filp = l_filp_open(logname, flags, mode);
573 if (IS_ERR(filp) && PTR_ERR(filp) != -ENOENT)
574 CERROR("logfile creation %s: %ld\n", logname,
577 OBD_FREE(logname, PATH_MAX);
581 static int llog_lvfs_open(const struct lu_env *env, struct llog_handle *handle,
582 struct llog_logid *logid, char *name,
583 enum llog_open_param open_param)
585 struct llog_ctxt *ctxt = handle->lgh_ctxt;
586 struct l_dentry *dchild = NULL;
587 struct obd_device *obd;
593 LASSERT(ctxt->loc_exp);
594 LASSERT(ctxt->loc_exp->exp_obd);
595 obd = ctxt->loc_exp->exp_obd;
599 dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, logid->lgl_oid,
600 logid->lgl_ogen, logid->lgl_oseq);
601 if (IS_ERR(dchild)) {
602 rc = PTR_ERR(dchild);
603 CERROR("%s: error looking up logfile #"LPX64"#"
604 LPX64"#%08x: rc = %d\n",
605 ctxt->loc_obd->obd_name, logid->lgl_oid,
606 logid->lgl_oseq, logid->lgl_ogen, rc);
609 if (dchild->d_inode == NULL) {
612 CERROR("%s: nonexistent llog #"LPX64"#"LPX64"#%08x: "
613 "rc = %d\n", ctxt->loc_obd->obd_name,
614 logid->lgl_oid, logid->lgl_oseq,
615 logid->lgl_ogen, rc);
618 /* l_dentry_open will call dput(dchild) if there is an error */
619 handle->lgh_file = l_dentry_open(&obd->obd_lvfs_ctxt, dchild,
620 O_RDWR | O_LARGEFILE);
621 if (IS_ERR(handle->lgh_file)) {
622 rc = PTR_ERR(handle->lgh_file);
623 handle->lgh_file = NULL;
624 CERROR("%s: error opening llog #"LPX64"#"LPX64"#%08x: "
625 "rc = %d\n", ctxt->loc_obd->obd_name,
626 logid->lgl_oid, logid->lgl_oseq,
627 logid->lgl_ogen, rc);
631 handle->lgh_id = *logid;
633 handle->lgh_file = llog_filp_open(MOUNT_CONFIGS_DIR, name,
634 O_RDWR | O_LARGEFILE, 0644);
635 if (IS_ERR(handle->lgh_file)) {
636 rc = PTR_ERR(handle->lgh_file);
637 handle->lgh_file = NULL;
638 if (rc == -ENOENT && open_param == LLOG_OPEN_NEW) {
639 OBD_ALLOC(handle->lgh_name, strlen(name) + 1);
640 if (handle->lgh_name)
641 strcpy(handle->lgh_name, name);
643 GOTO(out, rc = -ENOMEM);
649 handle->lgh_id.lgl_oseq = FID_SEQ_LLOG;
650 handle->lgh_id.lgl_oid =
651 handle->lgh_file->f_dentry->d_inode->i_ino;
652 handle->lgh_id.lgl_ogen =
653 handle->lgh_file->f_dentry->d_inode->i_generation;
656 LASSERTF(open_param == LLOG_OPEN_NEW, "%#x\n", open_param);
657 handle->lgh_file = NULL;
660 /* No new llog is expected but doesn't exist */
661 if (open_param != LLOG_OPEN_NEW && handle->lgh_file == NULL)
662 GOTO(out_name, rc = -ENOENT);
666 if (handle->lgh_name != NULL)
667 OBD_FREE(handle->lgh_name, strlen(name) + 1);
672 static int llog_lvfs_exist(struct llog_handle *handle)
674 return (handle->lgh_file != NULL);
677 /* This is a callback from the llog_* functions.
678 * Assumes caller has already pushed us into the kernel context. */
679 static int llog_lvfs_create(const struct lu_env *env,
680 struct llog_handle *handle,
683 struct llog_ctxt *ctxt = handle->lgh_ctxt;
684 struct obd_device *obd;
685 struct l_dentry *dchild = NULL;
686 struct obdo *oa = NULL;
688 int open_flags = O_RDWR | O_CREAT | O_LARGEFILE;
693 LASSERT(ctxt->loc_exp);
694 obd = ctxt->loc_exp->exp_obd;
695 LASSERT(handle->lgh_file == NULL);
697 if (handle->lgh_name) {
698 handle->lgh_file = llog_filp_open(MOUNT_CONFIGS_DIR,
701 if (IS_ERR(handle->lgh_file))
702 RETURN(PTR_ERR(handle->lgh_file));
704 handle->lgh_id.lgl_oseq = FID_SEQ_LLOG;
705 handle->lgh_id.lgl_oid =
706 handle->lgh_file->f_dentry->d_inode->i_ino;
707 handle->lgh_id.lgl_ogen =
708 handle->lgh_file->f_dentry->d_inode->i_generation;
714 oa->o_seq = FID_SEQ_LLOG;
715 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLGROUP;
717 rc = obd_create(NULL, ctxt->loc_exp, oa, NULL, NULL);
721 /* FIXME: rationalize the misuse of o_generation in
722 * this API along with mds_obd_{create,destroy}.
723 * Hopefully it is only an internal API issue. */
724 #define o_generation o_parent_oid
725 dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, oa->o_id,
726 oa->o_generation, oa->o_seq);
728 GOTO(out, rc = PTR_ERR(dchild));
730 handle->lgh_file = l_dentry_open(&obd->obd_lvfs_ctxt, dchild,
732 if (IS_ERR(handle->lgh_file))
733 GOTO(out, rc = PTR_ERR(handle->lgh_file));
735 handle->lgh_id.lgl_oseq = oa->o_seq;
736 handle->lgh_id.lgl_oid = oa->o_id;
737 handle->lgh_id.lgl_ogen = oa->o_generation;
744 static int llog_lvfs_close(const struct lu_env *env,
745 struct llog_handle *handle)
751 if (handle->lgh_file == NULL)
753 rc = filp_close(handle->lgh_file, 0);
755 CERROR("%s: error closing llog #"LPX64"#"LPX64"#%08x: "
756 "rc = %d\n", handle->lgh_ctxt->loc_obd->obd_name,
757 handle->lgh_id.lgl_oid, handle->lgh_id.lgl_oseq,
758 handle->lgh_id.lgl_ogen, rc);
759 handle->lgh_file = NULL;
760 if (handle->lgh_name)
761 OBD_FREE(handle->lgh_name, strlen(handle->lgh_name) + 1);
765 static int llog_lvfs_destroy(const struct lu_env *env,
766 struct llog_handle *handle)
768 struct dentry *fdentry;
770 struct obd_device *obd = handle->lgh_ctxt->loc_exp->exp_obd;
777 dir = MOUNT_CONFIGS_DIR;
779 LASSERT(handle->lgh_file);
780 fdentry = handle->lgh_file->f_dentry;
781 inode = fdentry->d_parent->d_inode;
782 if (strcmp(fdentry->d_parent->d_name.name, dir) == 0) {
783 struct lvfs_run_ctxt saved;
784 struct vfsmount *mnt = mntget(handle->lgh_file->f_vfsmnt);
786 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
788 rc = llog_lvfs_close(env, handle);
790 mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT);
791 rc = ll_vfs_unlink(inode, fdentry, mnt);
792 mutex_unlock(&inode->i_mutex);
797 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
805 oa->o_id = handle->lgh_id.lgl_oid;
806 oa->o_seq = handle->lgh_id.lgl_oseq;
807 oa->o_generation = handle->lgh_id.lgl_ogen;
809 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLGENER;
811 rc = llog_lvfs_close(env, handle);
815 th = fsfilt_start_log(obd, inode, FSFILT_OP_UNLINK, NULL, 1);
817 CERROR("fsfilt_start failed: %ld\n", PTR_ERR(th));
818 GOTO(out, rc = PTR_ERR(th));
821 rc = obd_destroy(NULL, handle->lgh_ctxt->loc_exp, oa,
822 NULL, NULL, NULL, NULL);
824 rc1 = fsfilt_commit(obd, inode, th, 0);
825 if (rc == 0 && rc1 != 0)
832 /* reads the catalog list */
833 int llog_get_cat_list(struct obd_device *disk_obd,
834 char *name, int idx, int count, struct llog_catid *idarray)
836 struct lvfs_run_ctxt saved;
839 int size = sizeof(*idarray) * count;
840 loff_t off = idx * sizeof(*idarray);
846 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
847 file = filp_open(name, O_RDWR | O_CREAT | O_LARGEFILE, 0700);
848 if (!file || IS_ERR(file)) {
850 CERROR("OBD filter: cannot open/create %s: rc = %d\n",
855 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
856 CERROR("%s is not a regular file!: mode = %o\n", name,
857 file->f_dentry->d_inode->i_mode);
858 GOTO(out, rc = -ENOENT);
861 CDEBUG(D_CONFIG, "cat list: disk size=%d, read=%d\n",
862 (int)i_size_read(file->f_dentry->d_inode), size);
864 /* read for new ost index or for empty file */
865 memset(idarray, 0, size);
866 if (i_size_read(file->f_dentry->d_inode) < off)
869 rc = fsfilt_read_record(disk_obd, file, idarray, size, &off);
871 CERROR("OBD filter: error reading %s: rc %d\n", name, rc);
877 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
878 if (file && !IS_ERR(file))
879 rc1 = filp_close(file, 0);
884 EXPORT_SYMBOL(llog_get_cat_list);
886 /* writes the cat list */
887 int llog_put_cat_list(struct obd_device *disk_obd,
888 char *name, int idx, int count, struct llog_catid *idarray)
890 struct lvfs_run_ctxt saved;
893 int size = sizeof(*idarray) * count;
894 loff_t off = idx * sizeof(*idarray);
899 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
900 file = filp_open(name, O_RDWR | O_CREAT | O_LARGEFILE, 0700);
901 if (!file || IS_ERR(file)) {
903 CERROR("OBD filter: cannot open/create %s: rc = %d\n",
908 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
909 CERROR("%s is not a regular file!: mode = %o\n", name,
910 file->f_dentry->d_inode->i_mode);
911 GOTO(out, rc = -ENOENT);
914 rc = fsfilt_write_record(disk_obd, file, idarray, size, &off, 1);
916 CDEBUG(D_INODE,"OBD filter: error writeing %s: rc %d\n",
922 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
923 if (file && !IS_ERR(file))
924 rc1 = filp_close(file, 0);
931 EXPORT_SYMBOL(llog_put_cat_list);
933 struct llog_operations llog_lvfs_ops = {
934 .lop_write_rec = llog_lvfs_write_rec,
935 .lop_next_block = llog_lvfs_next_block,
936 .lop_prev_block = llog_lvfs_prev_block,
937 .lop_read_header = llog_lvfs_read_header,
938 .lop_create = llog_lvfs_create,
939 .lop_destroy = llog_lvfs_destroy,
940 .lop_close = llog_lvfs_close,
941 .lop_open = llog_lvfs_open,
942 .lop_exist = llog_lvfs_exist,
944 EXPORT_SYMBOL(llog_lvfs_ops);
945 #else /* !__KERNEL__ */
946 int llog_get_cat_list(struct obd_device *disk_obd,
947 char *name, int idx, int count,
948 struct llog_catid *idarray)
954 int llog_put_cat_list(struct obd_device *disk_obd,
955 char *name, int idx, int count,
956 struct llog_catid *idarray)
962 struct llog_operations llog_lvfs_ops = {};