Whamcloud - gitweb
Branch: b1_4
[fs/lustre-release.git] / lustre / obdclass / llog_lvfs.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001-2003 Cluster File Systems, Inc.
5  *   Author: Andreas Dilger <adilger@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * OST<->MDS recovery logging infrastructure.
23  *
24  * Invariants in implementation:
25  * - we do not share logs among different OST<->MDS connections, so that
26  *   if an OST or MDS fails it need only look at log(s) relevant to itself
27  */
28
29 #define DEBUG_SUBSYSTEM S_LOG
30
31 #ifndef EXPORT_SYMTAB
32 #define EXPORT_SYMTAB
33 #endif
34
35 #ifdef __KERNEL__
36 #include <linux/fs.h>
37 #else
38 #include <liblustre.h>
39 #endif
40
41 #include <linux/obd.h>
42 #include <linux/obd_class.h>
43 #include <linux/lustre_log.h>
44 #include <linux/obd_ost.h>
45 #include <libcfs/list.h>
46 #include <linux/lvfs.h>
47 #include <linux/lustre_fsfilt.h>
48 #include "llog_internal.h"
49
50 #ifdef __KERNEL__
51
52 static int llog_lvfs_pad(struct obd_device *obd, struct l_file *file,
53                                 int len, int index)
54 {
55         struct llog_rec_hdr rec = { 0 };
56         struct llog_rec_tail tail;
57         int rc;
58         ENTRY;
59
60         LASSERT(len >= LLOG_MIN_REC_SIZE && (len & 0x7) == 0);
61
62         tail.lrt_len = rec.lrh_len = len;
63         tail.lrt_index = rec.lrh_index = index;
64         rec.lrh_type = LLOG_PAD_MAGIC;
65
66         rc = fsfilt_write_record(obd, file, &rec, sizeof(rec), &file->f_pos, 0);
67         if (rc) {
68                 CERROR("error writing padding record: rc %d\n", rc);
69                 goto out;
70         }
71
72         file->f_pos += len - sizeof(rec) - sizeof(tail);
73         rc = fsfilt_write_record(obd, file, &tail, sizeof(tail),&file->f_pos,0);
74         if (rc) {
75                 CERROR("error writing padding record: rc %d\n", rc);
76                 goto out;
77         }
78
79  out:
80         RETURN(rc);
81 }
82
83 static int llog_lvfs_write_blob(struct obd_device *obd, struct l_file *file,
84                                 struct llog_rec_hdr *rec, void *buf, loff_t off)
85 {
86         int rc;
87         struct llog_rec_tail end;
88         loff_t saved_off = file->f_pos;
89         int buflen = rec->lrh_len;
90
91         ENTRY;
92         file->f_pos = off;
93
94         if (!buf) {
95                 rc = fsfilt_write_record(obd, file, rec, buflen,&file->f_pos,0);
96                 if (rc) {
97                         CERROR("error writing log record: rc %d\n", rc);
98                         goto out;
99                 }
100                 GOTO(out, rc = 0);
101         }
102
103         /* the buf case */
104         rec->lrh_len = sizeof(*rec) + buflen + sizeof(end);
105         rc = fsfilt_write_record(obd, file, rec, sizeof(*rec), &file->f_pos, 0);
106         if (rc) {
107                 CERROR("error writing log hdr: rc %d\n", rc);
108                 goto out;
109         }
110
111         rc = fsfilt_write_record(obd, file, buf, buflen, &file->f_pos, 0);
112         if (rc) {
113                 CERROR("error writing log buffer: rc %d\n", rc);
114                 goto out;
115         }
116
117         end.lrt_len = rec->lrh_len;
118         end.lrt_index = rec->lrh_index;
119         rc = fsfilt_write_record(obd, file, &end, sizeof(end), &file->f_pos, 0);
120         if (rc) {
121                 CERROR("error writing log tail: rc %d\n", rc);
122                 goto out;
123         }
124
125         rc = 0;
126  out:
127         if (saved_off > file->f_pos)
128                 file->f_pos = saved_off;
129         LASSERT(rc <= 0);
130         RETURN(rc);
131 }
132
133 static int llog_lvfs_read_blob(struct obd_device *obd, struct l_file *file,
134                                 void *buf, int size, loff_t off)
135 {
136         loff_t offset = off;
137         int rc;
138         ENTRY;
139
140         rc = fsfilt_read_record(obd, file, buf, size, &offset);
141         if (rc) {
142                 CERROR("error reading log record: rc %d\n", rc);
143                 RETURN(rc);
144         }
145         RETURN(0);
146 }
147
148 static int llog_lvfs_read_header(struct llog_handle *handle)
149 {
150         struct obd_device *obd;
151         int rc;
152         ENTRY;
153
154         LASSERT(sizeof(*handle->lgh_hdr) == LLOG_CHUNK_SIZE);
155
156         obd = handle->lgh_ctxt->loc_exp->exp_obd;
157
158         if (handle->lgh_file->f_dentry->d_inode->i_size == 0) {
159                 CDEBUG(D_HA, "not reading header from 0-byte log\n");
160                 RETURN(LLOG_EEMPTY);
161         }
162
163         rc = llog_lvfs_read_blob(obd, handle->lgh_file, handle->lgh_hdr,
164                                  LLOG_CHUNK_SIZE, 0);
165         if (rc) {
166                 CERROR("error reading log header from %.*s\n",
167                        handle->lgh_file->f_dentry->d_name.len,
168                        handle->lgh_file->f_dentry->d_name.name);
169         } else {
170                 struct llog_rec_hdr *llh_hdr = &handle->lgh_hdr->llh_hdr;
171
172                 if (LLOG_REC_HDR_NEEDS_SWABBING(llh_hdr))
173                         lustre_swab_llog_hdr(handle->lgh_hdr);
174
175                 if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) {
176                         CERROR("bad log %.*s header magic: %#x (expected %#x)\n",
177                                handle->lgh_file->f_dentry->d_name.len,
178                                handle->lgh_file->f_dentry->d_name.name,
179                                llh_hdr->lrh_type, LLOG_HDR_MAGIC);
180                         rc = -EIO;
181                 } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) {
182                         CERROR("incorrectly sized log %.*s header: %#x "
183                                "(expected %#x)\n",
184                                handle->lgh_file->f_dentry->d_name.len,
185                                handle->lgh_file->f_dentry->d_name.name,
186                                llh_hdr->lrh_len, LLOG_CHUNK_SIZE);
187                         CERROR("you may need to re-run lconf --write_conf.\n");
188                         rc = -EIO;
189                 }
190         }
191
192         handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index;
193         handle->lgh_file->f_pos = handle->lgh_file->f_dentry->d_inode->i_size;
194
195         RETURN(rc);
196 }
197
198 /* returns negative in on error; 0 if success && reccookie == 0; 1 otherwise */
199 /* appends if idx == -1, otherwise overwrites record idx. */
200 static int llog_lvfs_write_rec(struct llog_handle *loghandle,
201                                struct llog_rec_hdr *rec,
202                                struct llog_cookie *reccookie, int cookiecount,
203                                void *buf, int idx)
204 {
205         struct llog_log_hdr *llh;
206         int reclen = rec->lrh_len, index, rc;
207         struct llog_rec_tail *lrt;
208         struct obd_device *obd;
209         struct file *file;
210         size_t left;
211         ENTRY;
212
213         llh = loghandle->lgh_hdr;
214         file = loghandle->lgh_file;
215         obd = loghandle->lgh_ctxt->loc_exp->exp_obd;
216
217         /* record length should not bigger than LLOG_CHUNK_SIZE */
218         if (buf)
219                 rc = (reclen > LLOG_CHUNK_SIZE - sizeof(struct llog_rec_hdr) -
220                       sizeof(struct llog_rec_tail)) ? -E2BIG : 0;
221         else
222                 rc = (reclen > LLOG_CHUNK_SIZE) ? -E2BIG : 0;
223         if (rc)
224                 RETURN(rc);
225
226         if (idx != -1) {
227                 loff_t saved_offset;
228
229                 /* no header: only allowed to insert record 1 */
230                 if (idx != 1 && !file->f_dentry->d_inode->i_size) {
231                         CERROR("idx != -1 in empty log\n");
232                         LBUG();
233                 }
234
235                 if (idx && llh->llh_size && llh->llh_size != reclen)
236                         RETURN(-EINVAL);
237
238                 rc = llog_lvfs_write_blob(obd, file, &llh->llh_hdr, NULL, 0);
239                 /* we are done if we only write the header or on error */
240                 if (rc || idx == 0)
241                         RETURN(rc);
242
243                 saved_offset = sizeof(*llh) + (idx-1)*rec->lrh_len;
244                 rc = llog_lvfs_write_blob(obd, file, rec, buf, saved_offset);
245                 if (rc == 0 && reccookie) {
246                         reccookie->lgc_lgl = loghandle->lgh_id;
247                         reccookie->lgc_index = idx;
248                         rc = 1;
249                 }
250                 RETURN(rc);
251         }
252
253         /* Make sure that records don't cross a chunk boundary, so we can
254          * process them page-at-a-time if needed.  If it will cross a chunk
255          * boundary, write in a fake (but referenced) entry to pad the chunk.
256          *
257          * We know that llog_current_log() will return a loghandle that is
258          * big enough to hold reclen, so all we care about is padding here.
259          */
260         left = LLOG_CHUNK_SIZE - (file->f_pos & (LLOG_CHUNK_SIZE - 1));
261         if (buf)
262                 reclen = sizeof(*rec) + rec->lrh_len + 
263                         sizeof(struct llog_rec_tail);
264
265         /* NOTE: padding is a record, but no bit is set */
266         if (left != 0 && left != reclen &&
267             left < (reclen + LLOG_MIN_REC_SIZE)) {
268                 loghandle->lgh_last_idx++;
269                 rc = llog_lvfs_pad(obd, file, left, loghandle->lgh_last_idx);
270                 if (rc)
271                         RETURN(rc);
272                 /* if it's the last idx in log file, then return -ENOSPC */
273                 if (loghandle->lgh_last_idx == LLOG_BITMAP_SIZE(llh) - 1)
274                         RETURN(-ENOSPC);
275         }
276
277         loghandle->lgh_last_idx++;
278         index = loghandle->lgh_last_idx;
279         LASSERT(index < LLOG_BITMAP_SIZE(llh));
280         rec->lrh_index = index;
281         if (buf == NULL) {
282                 lrt = (struct llog_rec_tail *)
283                         ((char *)rec + rec->lrh_len - sizeof(*lrt));
284                 lrt->lrt_len = rec->lrh_len;
285                 lrt->lrt_index = rec->lrh_index;
286         }
287         if (ext2_set_bit(index, llh->llh_bitmap)) {
288                 CERROR("argh, index %u already set in log bitmap?\n", index);
289                 LBUG(); /* should never happen */
290         }
291         llh->llh_count++;
292         llh->llh_tail.lrt_index = index;
293
294         rc = llog_lvfs_write_blob(obd, file, &llh->llh_hdr, NULL, 0);
295         if (rc)
296                 RETURN(rc);
297
298         rc = llog_lvfs_write_blob(obd, file, rec, buf, file->f_pos);
299         if (rc)
300                 RETURN(rc);
301
302         CDEBUG(D_HA, "added record "LPX64": idx: %u, %u bytes\n",
303                loghandle->lgh_id.lgl_oid, index, rec->lrh_len);
304         if (rc == 0 && reccookie) {
305                 reccookie->lgc_lgl = loghandle->lgh_id;
306                 reccookie->lgc_index = index;
307                 if ((rec->lrh_type == MDS_UNLINK_REC) || 
308                                 (rec->lrh_type == MDS_SETATTR_REC))
309                         reccookie->lgc_subsys = LLOG_MDS_OST_ORIG_CTXT;
310                 else if (rec->lrh_type == OST_SZ_REC)
311                         reccookie->lgc_subsys = LLOG_SIZE_ORIG_CTXT;
312                 else if (rec->lrh_type == OST_RAID1_REC)
313                         reccookie->lgc_subsys = LLOG_RD1_ORIG_CTXT;
314                 else
315                         reccookie->lgc_subsys = -1;
316                 rc = 1;
317         }
318         if (rc == 0 && rec->lrh_type == LLOG_GEN_REC)
319                 rc = 1;
320
321         RETURN(rc);
322 }
323
324 /* We can skip reading at least as many log blocks as the number of
325 * minimum sized log records we are skipping.  If it turns out
326 * that we are not far enough along the log (because the
327 * actual records are larger than minimum size) we just skip
328 * some more records. */
329
330 static void llog_skip_over(__u64 *off, int curr, int goal)
331 {
332         if (goal <= curr)
333                 return;
334         *off = (*off + (goal-curr-1) * LLOG_MIN_REC_SIZE) &
335                 ~(LLOG_CHUNK_SIZE - 1);
336 }
337
338
339 /* sets:
340  *  - cur_offset to the furthest point read in the log file
341  *  - cur_idx to the log index preceeding cur_offset
342  * returns -EIO/-EINVAL on error
343  */
344 static int llog_lvfs_next_block(struct llog_handle *loghandle, int *cur_idx,
345                                 int next_idx, __u64 *cur_offset, void *buf,
346                                 int len)
347 {
348         int rc;
349         ENTRY;
350
351         if (len == 0 || len & (LLOG_CHUNK_SIZE - 1))
352                 RETURN(-EINVAL);
353
354         CDEBUG(D_OTHER, "looking for log index %u (cur idx %u off "LPU64")\n",
355                next_idx, *cur_idx, *cur_offset);
356
357         while (*cur_offset < loghandle->lgh_file->f_dentry->d_inode->i_size) {
358                 struct llog_rec_hdr *rec;
359                 struct llog_rec_tail *tail;
360                 loff_t ppos;
361
362                 llog_skip_over(cur_offset, *cur_idx, next_idx);
363
364                 ppos = *cur_offset;
365                 rc = fsfilt_read_record(loghandle->lgh_ctxt->loc_exp->exp_obd,
366                                         loghandle->lgh_file, buf, len,
367                                         &ppos);
368
369                 if (rc) {
370                         CERROR("Cant read llog block at log id "LPU64
371                                "/%u offset "LPU64"\n",
372                                loghandle->lgh_id.lgl_oid,
373                                loghandle->lgh_id.lgl_ogen,
374                                *cur_offset);
375                         RETURN(rc);
376                 }
377
378                 /* put number of bytes read into rc to make code simpler */
379                 rc = ppos - *cur_offset;
380                 *cur_offset = ppos;
381
382                 if (rc == 0) /* end of file, nothing to do */
383                         RETURN(0);
384
385                 if (rc < sizeof(*tail)) {
386                         CERROR("Invalid llog block at log id "LPU64"/%u offset "
387                                LPU64"\n", loghandle->lgh_id.lgl_oid,
388                                loghandle->lgh_id.lgl_ogen, *cur_offset);
389                         RETURN(-EINVAL);
390                 }
391
392                 rec = buf;
393                 tail = (struct llog_rec_tail *)((char *)buf + rc -
394                                                 sizeof(struct llog_rec_tail));
395
396                 if (LLOG_REC_HDR_NEEDS_SWABBING(rec)) {
397                         lustre_swab_llog_rec(rec, tail);
398                 }
399
400                 *cur_idx = tail->lrt_index;
401
402                 /* this shouldn't happen */
403                 if (tail->lrt_index == 0) {
404                         CERROR("Invalid llog tail at log id "LPU64"/%u offset "
405                                LPU64"\n", loghandle->lgh_id.lgl_oid,
406                                loghandle->lgh_id.lgl_ogen, *cur_offset);
407                         RETURN(-EINVAL);
408                 }
409                 if (tail->lrt_index < next_idx)
410                         continue;
411
412                 /* sanity check that the start of the new buffer is no farther
413                  * than the record that we wanted.  This shouldn't happen. */
414                 if (rec->lrh_index > next_idx) {
415                         CERROR("missed desired record? %u > %u\n",
416                                rec->lrh_index, next_idx);
417                         RETURN(-ENOENT);
418                 }
419                 RETURN(0);
420         }
421         RETURN(-EIO);
422 }
423
424 static struct file *llog_filp_open(char *name, int flags, int mode)
425 {
426         char *logname;
427         struct file *filp;
428         int len;
429
430         OBD_ALLOC(logname, PATH_MAX);
431         if (logname == NULL)
432                 return ERR_PTR(-ENOMEM);
433
434         len = snprintf(logname, PATH_MAX, "LOGS/%s", name);
435         if (len >= PATH_MAX - 1) {
436                 filp = ERR_PTR(-ENAMETOOLONG);
437         } else {
438                 filp = l_filp_open(logname, flags, mode);
439                 if (IS_ERR(filp))
440                         CERROR("logfile creation %s: %ld\n", logname,
441                                PTR_ERR(filp));
442         }
443
444         OBD_FREE(logname, PATH_MAX);
445         return filp;
446 }
447
448 /* This is a callback from the llog_* functions.
449  * Assumes caller has already pushed us into the kernel context. */
450 static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res,
451                             struct llog_logid *logid, char *name)
452 {
453         struct llog_handle *handle;
454         struct obd_device *obd;
455         struct l_dentry *dchild = NULL;
456         struct obdo *oa = NULL;
457         int rc = 0, cleanup_phase = 1;
458         int open_flags = O_RDWR | O_CREAT | O_LARGEFILE;
459         ENTRY;
460
461         handle = llog_alloc_handle();
462         if (handle == NULL)
463                 RETURN(-ENOMEM);
464         *res = handle;
465
466         LASSERT(ctxt);
467         LASSERT(ctxt->loc_exp);
468         obd = ctxt->loc_exp->exp_obd;
469
470         if (logid != NULL) {
471                 dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, logid->lgl_oid,
472                                              logid->lgl_ogen, logid->lgl_ogr);
473
474                 if (IS_ERR(dchild)) {
475                         rc = PTR_ERR(dchild);
476                         CERROR("error looking up logfile "LPX64":0x%x: rc %d\n",
477                                logid->lgl_oid, logid->lgl_ogen, rc);
478                         GOTO(cleanup, rc);
479                 }
480
481                 cleanup_phase = 2;
482                 if (dchild->d_inode == NULL) {
483                         rc = -ENOENT;
484                         CERROR("nonexistent log file "LPX64":"LPX64": rc %d\n",
485                                logid->lgl_oid, logid->lgl_ogr, rc);
486                         GOTO(cleanup, rc);
487                 }
488
489                 handle->lgh_file = l_dentry_open(&obd->obd_ctxt, dchild,
490                                                     O_RDWR | O_LARGEFILE);
491                 if (IS_ERR(handle->lgh_file)) {
492                         rc = PTR_ERR(handle->lgh_file);
493                         CERROR("error opening logfile "LPX64"0x%x: rc %d\n",
494                                logid->lgl_oid, logid->lgl_ogen, rc);
495                         GOTO(cleanup, rc);
496                 }
497
498                 /* assign the value of lgh_id for handle directly */
499                 handle->lgh_id = *logid;
500
501         } else if (name) {
502                 handle->lgh_file = llog_filp_open(name, open_flags, 0644);
503                 if (IS_ERR(handle->lgh_file))
504                         GOTO(cleanup, rc = PTR_ERR(handle->lgh_file));
505
506                 handle->lgh_id.lgl_ogr = 1;
507                 handle->lgh_id.lgl_oid =
508                         handle->lgh_file->f_dentry->d_inode->i_ino;
509                 handle->lgh_id.lgl_ogen =
510                         handle->lgh_file->f_dentry->d_inode->i_generation;
511         } else {
512                 oa = obdo_alloc();
513                 if (oa == NULL)
514                         GOTO(cleanup, rc = -ENOMEM);
515                 /* XXX get some filter group constants */
516                 oa->o_gr = 1;
517                 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLGROUP;
518                 rc = obd_create(ctxt->loc_exp, oa, NULL, NULL);
519                 if (rc)
520                         GOTO(cleanup, rc);
521
522                 dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, oa->o_id,
523                                              oa->o_generation, oa->o_gr);
524
525                 if (IS_ERR(dchild))
526                         GOTO(cleanup, rc = PTR_ERR(dchild));
527                 cleanup_phase = 2;
528                 handle->lgh_file = l_dentry_open(&obd->obd_ctxt, dchild,
529                                                  open_flags);
530                 if (IS_ERR(handle->lgh_file))
531                         GOTO(cleanup, rc = PTR_ERR(handle->lgh_file));
532
533                 handle->lgh_id.lgl_ogr = oa->o_gr;
534                 handle->lgh_id.lgl_oid = oa->o_id;
535                 handle->lgh_id.lgl_ogen = oa->o_generation;
536         }
537
538         handle->lgh_ctxt = ctxt;
539  finish:
540         if (oa)
541                 obdo_free(oa);
542         RETURN(rc);
543 cleanup:
544         switch (cleanup_phase) {
545         case 2:
546                 l_dput(dchild);
547         case 1:
548                 llog_free_handle(handle);
549         }
550         goto finish;
551 }
552
553 static int llog_lvfs_close(struct llog_handle *handle)
554 {
555         int rc;
556         ENTRY;
557
558         rc = filp_close(handle->lgh_file, 0);
559         if (rc)
560                 CERROR("error closing log: rc %d\n", rc);
561         RETURN(rc);
562 }
563
564 static int llog_lvfs_destroy(struct llog_handle *handle)
565 {
566         struct dentry *fdentry;
567         struct obdo *oa;
568         int rc;
569         ENTRY;
570
571         fdentry = handle->lgh_file->f_dentry;
572         if (!strcmp(fdentry->d_parent->d_name.name, "LOGS")) {
573                 struct obd_device *obd = handle->lgh_ctxt->loc_exp->exp_obd;
574                 struct inode *inode = fdentry->d_parent->d_inode;
575                 struct obd_run_ctxt saved;
576
577                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
578                 dget(fdentry);
579                 rc = llog_lvfs_close(handle);
580
581                 if (rc == 0) {
582                         down(&inode->i_sem);
583                         rc = vfs_unlink(inode, fdentry);
584                         up(&inode->i_sem);
585                 }
586
587                 dput(fdentry);
588                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
589                 RETURN(rc);
590         }
591
592         oa = obdo_alloc();
593         if (oa == NULL)
594                 RETURN(-ENOMEM);
595
596         oa->o_id = handle->lgh_id.lgl_oid;
597         oa->o_gr = handle->lgh_id.lgl_ogr;
598         oa->o_generation = handle->lgh_id.lgl_ogen;
599         oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLGENER;
600
601         rc = llog_lvfs_close(handle);
602         if (rc)
603                 GOTO(out, rc);
604
605         rc = obd_destroy(handle->lgh_ctxt->loc_exp, oa, NULL, NULL);
606  out:
607         obdo_free(oa);
608         RETURN(rc);
609 }
610
611 /* reads the catalog list */
612 int llog_get_cat_list(struct obd_device *obd, struct obd_device *disk_obd,
613                       char *name, int count, struct llog_catid *idarray)
614 {
615         struct obd_run_ctxt saved;
616         struct l_file *file;
617         int rc;
618         int size = sizeof(*idarray) * count;
619         loff_t off = 0;
620
621         LASSERT(count);
622
623         push_ctxt(&saved, &obd->obd_ctxt, NULL);
624         file = filp_open(name, O_RDWR | O_CREAT | O_LARGEFILE, 0700);
625         if (!file || IS_ERR(file)) {
626                 rc = PTR_ERR(file);
627                 CERROR("OBD filter: cannot open/create %s: rc = %d\n",
628                        name, rc);
629                 GOTO(out, rc);
630         }
631
632         if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
633                 CERROR("%s is not a regular file!: mode = %o\n", name,
634                        file->f_dentry->d_inode->i_mode);
635                 GOTO(out, rc = -ENOENT);
636         }
637
638         rc = fsfilt_read_record(disk_obd, file, idarray, size, &off);
639         if (rc) {
640                 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
641                        name, rc);
642                 GOTO(out, rc);
643         }
644
645  out:
646         pop_ctxt(&saved, &obd->obd_ctxt, NULL);
647         if (file && !IS_ERR(file))
648                 rc = filp_close(file, 0);
649         RETURN(rc);
650 }
651 EXPORT_SYMBOL(llog_get_cat_list);
652
653 /* writes the cat list */
654 int llog_put_cat_list(struct obd_device *obd, struct obd_device *disk_obd,
655                       char *name, int count, struct llog_catid *idarray)
656 {
657         struct obd_run_ctxt saved;
658         struct l_file *file;
659         int rc;
660         int size = sizeof(*idarray) * count;
661         loff_t off = 0;
662
663         LASSERT(count);
664
665         push_ctxt(&saved, &obd->obd_ctxt, NULL);
666         file = filp_open(name, O_RDWR | O_CREAT | O_LARGEFILE, 0700);
667         if (!file || IS_ERR(file)) {
668                 rc = PTR_ERR(file);
669                 CERROR("OBD filter: cannot open/create %s: rc = %d\n",
670                        name, rc);
671                 GOTO(out, rc);
672         }
673
674         if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
675                 CERROR("%s is not a regular file!: mode = %o\n", name,
676                        file->f_dentry->d_inode->i_mode);
677                 GOTO(out, rc = -ENOENT);
678         }
679
680         rc = fsfilt_write_record(disk_obd, file, idarray, size, &off, 1);
681         if (rc) {
682                 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
683                        name, rc);
684                 GOTO(out, rc);
685         }
686
687  out:
688         pop_ctxt(&saved, &obd->obd_ctxt, NULL);
689         if (file && !IS_ERR(file))
690                 rc = filp_close(file, 0);
691         RETURN(rc);
692 }
693
694 struct llog_operations llog_lvfs_ops = {
695         lop_write_rec:   llog_lvfs_write_rec,
696         lop_next_block:  llog_lvfs_next_block,
697         lop_read_header: llog_lvfs_read_header,
698         lop_create:      llog_lvfs_create,
699         lop_destroy:     llog_lvfs_destroy,
700         lop_close:       llog_lvfs_close,
701         //        lop_cancel: llog_lvfs_cancel,
702 };
703
704 EXPORT_SYMBOL(llog_lvfs_ops);
705
706 #else /* !__KERNEL__ */
707
708 static int llog_lvfs_read_header(struct llog_handle *handle)
709 {
710         LBUG();
711         return 0;
712 }
713
714 static int llog_lvfs_write_rec(struct llog_handle *loghandle,
715                                struct llog_rec_hdr *rec,
716                                struct llog_cookie *reccookie, int cookiecount,
717                                void *buf, int idx)
718 {
719         LBUG();
720         return 0;
721 }
722
723 static int llog_lvfs_next_block(struct llog_handle *loghandle, int *cur_idx,
724                                 int next_idx, __u64 *cur_offset, void *buf,
725                                 int len)
726 {
727         LBUG();
728         return 0;
729 }
730
731 static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res,
732                             struct llog_logid *logid, char *name)
733 {
734         LBUG();
735         return 0;
736 }
737
738 static int llog_lvfs_close(struct llog_handle *handle)
739 {
740         LBUG();
741         return 0;
742 }
743
744 static int llog_lvfs_destroy(struct llog_handle *handle)
745 {
746         LBUG();
747         return 0;
748 }
749
750 int llog_get_cat_list(struct obd_device *obd, struct obd_device *disk_obd,
751                       char *name, int count, struct llog_catid *idarray)
752 {
753         LBUG();
754         return 0;
755 }
756
757 int llog_put_cat_list(struct obd_device *obd, struct obd_device *disk_obd,
758                       char *name, int count, struct llog_catid *idarray)
759 {
760         LBUG();
761         return 0;
762 }
763
764 struct llog_operations llog_lvfs_ops = {
765         lop_write_rec:   llog_lvfs_write_rec,
766         lop_next_block:  llog_lvfs_next_block,
767         lop_read_header: llog_lvfs_read_header,
768         lop_create:      llog_lvfs_create,
769         lop_destroy:     llog_lvfs_destroy,
770         lop_close:       llog_lvfs_close,
771 //        lop_cancel:      llog_lvfs_cancel,
772 };
773 #endif