Whamcloud - gitweb
9d99e9a4be3cd596c096fb3cc4cfef5920cea83a
[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 <portals/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 = 0;
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                  * These need to be fixed for bug 1987
173                  */
174                 if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) {
175                         CERROR("bad log %*s header magic: %#x (expected %#x)\n",
176                                handle->lgh_file->f_dentry->d_name.len,
177                                handle->lgh_file->f_dentry->d_name.name,
178                                llh_hdr->lrh_type, LLOG_HDR_MAGIC);
179                         rc = -EIO;
180                 } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) {
181                         CERROR("incorrectly sized log %*s header: %#x "
182                                "(expected %#x)\n",
183                                handle->lgh_file->f_dentry->d_name.len,
184                                handle->lgh_file->f_dentry->d_name.name,
185                                llh_hdr->lrh_len, LLOG_CHUNK_SIZE);
186                         CERROR("you may need to re-run lconf --write_conf.\n");
187                         rc = -EIO;
188                 }
189         }
190
191         handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index;
192         handle->lgh_file->f_pos = handle->lgh_file->f_dentry->d_inode->i_size;
193
194         RETURN(rc);
195 }
196
197 /* returns negative in on error; 0 if success && reccookie == 0; 1 otherwise */
198 /* appends if idx == -1, otherwise overwrites record idx. */
199 static int llog_lvfs_write_rec(struct llog_handle *loghandle,
200                                struct llog_rec_hdr *rec,
201                                struct llog_cookie *reccookie, int cookiecount,
202                                void *buf, int idx)
203 {
204         struct llog_log_hdr *llh;
205         int reclen = rec->lrh_len, index, rc;
206         struct llog_rec_tail *lrt;
207         struct obd_device *obd;
208         struct file *file;
209         size_t left;
210         ENTRY;
211
212         llh = loghandle->lgh_hdr;
213         file = loghandle->lgh_file;
214         obd = loghandle->lgh_ctxt->loc_exp->exp_obd;
215
216         /* record length should not bigger than LLOG_CHUNK_SIZE */
217         if (buf)
218                 rc = (reclen > LLOG_CHUNK_SIZE - sizeof(struct llog_rec_hdr) -
219                       sizeof(struct llog_rec_tail)) ? -E2BIG : 0;
220         else
221                 rc = (reclen > LLOG_CHUNK_SIZE) ? -E2BIG : 0;
222         if (rc)
223                 RETURN(rc);
224
225         if (idx != -1) {
226                 loff_t saved_offset;
227
228                 /* no header: only allowed to insert record 1 */
229                 if (idx != 1 && !file->f_dentry->d_inode->i_size) {
230                         CERROR("idx != -1 in empty log\n");
231                         LBUG();
232                 }
233
234                 if (idx && llh->llh_size && llh->llh_size != reclen)
235                         RETURN(-EINVAL);
236
237                 rc = llog_lvfs_write_blob(obd, file, &llh->llh_hdr, NULL, 0);
238                 /* we are done if we only write the header or on error */
239                 if (rc || idx == 0)
240                         RETURN(rc);
241
242                 saved_offset = sizeof(*llh) + (idx-1)*rec->lrh_len;
243                 rc = llog_lvfs_write_blob(obd, file, rec, buf, saved_offset);
244                 if (rc == 0 && reccookie) {
245                         reccookie->lgc_lgl = loghandle->lgh_id;
246                         reccookie->lgc_index = idx;
247                         rc = 1;
248                 }
249                 RETURN(rc);
250         }
251
252         /* Make sure that records don't cross a chunk boundary, so we can
253          * process them page-at-a-time if needed.  If it will cross a chunk
254          * boundary, write in a fake (but referenced) entry to pad the chunk.
255          *
256          * We know that llog_current_log() will return a loghandle that is
257          * big enough to hold reclen, so all we care about is padding here.
258          */
259         left = LLOG_CHUNK_SIZE - (file->f_pos & (LLOG_CHUNK_SIZE - 1));
260         if (buf)
261                 reclen = sizeof(*rec) + rec->lrh_len + 
262                         sizeof(struct llog_rec_tail);
263
264         /* NOTE: padding is a record, but no bit is set */
265         if (left != 0 && left != reclen &&
266             left < (reclen + LLOG_MIN_REC_SIZE)) {
267                 int bitmap_size = sizeof(llh->llh_bitmap) * 8;
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 == bitmap_size - 1)
274                         RETURN(-ENOSPC);
275         }
276
277         loghandle->lgh_last_idx++;
278         index = loghandle->lgh_last_idx;
279         rec->lrh_index = index;
280         if (buf == NULL) {
281                 lrt = (struct llog_rec_tail *)
282                         ((char *)rec + rec->lrh_len - sizeof(*lrt));
283                 lrt->lrt_len = rec->lrh_len;
284                 lrt->lrt_index = rec->lrh_index;
285         }
286         if (ext2_set_bit(index, llh->llh_bitmap)) {
287                 CERROR("argh, index %u already set in log bitmap?\n", index);
288                 LBUG(); /* should never happen */
289         }
290         llh->llh_count++;
291         llh->llh_tail.lrt_index = index;
292
293         rc = llog_lvfs_write_blob(obd, file, &llh->llh_hdr, NULL, 0);
294         if (rc)
295                 RETURN(rc);
296
297         rc = llog_lvfs_write_blob(obd, file, rec, buf, file->f_pos);
298         if (rc)
299                 RETURN(rc);
300
301         CDEBUG(D_HA, "added record "LPX64": idx: %u, %u bytes\n",
302                loghandle->lgh_id.lgl_oid, index, rec->lrh_len);
303         if (rc == 0 && reccookie) {
304                 reccookie->lgc_lgl = loghandle->lgh_id;
305                 reccookie->lgc_index = index;
306                 if (rec->lrh_type == MDS_UNLINK_REC)
307                         reccookie->lgc_subsys = LLOG_UNLINK_ORIG_CTXT;
308                 else if (rec->lrh_type == OST_SZ_REC)
309                         reccookie->lgc_subsys = LLOG_SIZE_ORIG_CTXT;
310                 else if (rec->lrh_type == OST_RAID1_REC)
311                         reccookie->lgc_subsys = LLOG_RD1_ORIG_CTXT;
312                 else
313                         reccookie->lgc_subsys = -1;
314                 rc = 1;
315         }
316         if (rc == 0 && rec->lrh_type == LLOG_GEN_REC)
317                 rc = 1;
318
319         RETURN(rc);
320 }
321
322 /* We can skip reading at least as many log blocks as the number of
323 * minimum sized log records we are skipping.  If it turns out
324 * that we are not far enough along the log (because the
325 * actual records are larger than minimum size) we just skip
326 * some more records. */
327
328 static void llog_skip_over(__u64 *off, int curr, int goal)
329 {
330         if (goal <= curr)
331                 return;
332         *off = (*off + (goal-curr-1) * LLOG_MIN_REC_SIZE) &
333                 ~(LLOG_CHUNK_SIZE - 1);
334 }
335
336
337 /* sets:
338  *  - cur_offset to the furthest point read in the log file
339  *  - cur_idx to the log index preceeding cur_offset
340  * returns -EIO/-EINVAL on error
341  */
342 static int llog_lvfs_next_block(struct llog_handle *loghandle, int *cur_idx,
343                                 int next_idx, __u64 *cur_offset, void *buf,
344                                 int len)
345 {
346         int rc;
347         ENTRY;
348
349         if (len == 0 || len & (LLOG_CHUNK_SIZE - 1))
350                 RETURN(-EINVAL);
351
352         CDEBUG(D_OTHER, "looking for log index %u (cur idx %u off "LPU64")\n",
353                next_idx, *cur_idx, *cur_offset);
354
355         while (*cur_offset < loghandle->lgh_file->f_dentry->d_inode->i_size) {
356                 struct llog_rec_hdr *rec;
357                 struct llog_rec_tail *tail;
358                 loff_t ppos;
359
360                 llog_skip_over(cur_offset, *cur_idx, next_idx);
361
362                 ppos = *cur_offset;
363                 rc = fsfilt_read_record(loghandle->lgh_ctxt->loc_exp->exp_obd,
364                                         loghandle->lgh_file, buf, len,
365                                         &ppos);
366
367                 if (rc) {
368                         CERROR("Cant read llog block at log id "LPU64
369                                "/%u offset "LPU64"\n",
370                                loghandle->lgh_id.lgl_oid,
371                                loghandle->lgh_id.lgl_ogen,
372                                *cur_offset);
373                         RETURN(rc);
374                 }
375
376                 /* put number of bytes read into rc to make code simpler */
377                 rc = ppos - *cur_offset;
378                 *cur_offset = ppos;
379
380                 if (rc == 0) /* end of file, nothing to do */
381                         RETURN(0);
382
383                 if (rc < sizeof(*tail)) {
384                         CERROR("Invalid llog block at log id "LPU64"/%u offset "
385                                LPU64"\n", loghandle->lgh_id.lgl_oid,
386                                loghandle->lgh_id.lgl_ogen, *cur_offset);
387                         RETURN(-EINVAL);
388                 }
389
390                 tail = buf + rc - sizeof(struct llog_rec_tail);
391                 *cur_idx = tail->lrt_index;
392
393                 /* this shouldn't happen */
394                 if (tail->lrt_index == 0) {
395                         CERROR("Invalid llog tail at log id "LPU64"/%u offset "
396                                LPU64"\n", loghandle->lgh_id.lgl_oid,
397                                loghandle->lgh_id.lgl_ogen, *cur_offset);
398                         RETURN(-EINVAL);
399                 }
400                 if (tail->lrt_index < next_idx)
401                         continue;
402
403                 /* sanity check that the start of the new buffer is no farther
404                  * than the record that we wanted.  This shouldn't happen. */
405                 rec = buf;
406                 if (rec->lrh_index > next_idx) {
407                         CERROR("missed desired record? %u > %u\n",
408                                rec->lrh_index, next_idx);
409                         RETURN(-ENOENT);
410                 }
411                 RETURN(0);
412         }
413         RETURN(-EIO);
414 }
415
416 static struct file *llog_filp_open(char *name, int flags, int mode)
417 {
418         char *logname;
419         struct file *filp;
420         int len;
421
422         OBD_ALLOC(logname, PATH_MAX);
423         if (logname == NULL)
424                 return ERR_PTR(-ENOMEM);
425
426         len = snprintf(logname, PATH_MAX, "LOGS/%s", name);
427         if (len >= PATH_MAX - 1) {
428                 filp = ERR_PTR(-ENAMETOOLONG);
429         } else {
430                 filp = l_filp_open(logname, flags, mode);
431                 if (IS_ERR(filp))
432                         CERROR("logfile creation %s: %ld\n", logname,
433                                PTR_ERR(filp));
434         }
435
436         OBD_FREE(logname, PATH_MAX);
437         return filp;
438 }
439
440 /* This is a callback from the llog_* functions.
441  * Assumes caller has already pushed us into the kernel context. */
442 static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res,
443                             struct llog_logid *logid, char *name)
444 {
445         struct llog_handle *handle;
446         struct obd_device *obd;
447         struct l_dentry *dchild = NULL;
448         struct obdo *oa = NULL;
449         int rc = 0, cleanup_phase = 1;
450         int open_flags = O_RDWR | O_CREAT | O_LARGEFILE;
451         ENTRY;
452
453         handle = llog_alloc_handle();
454         if (handle == NULL)
455                 RETURN(-ENOMEM);
456         *res = handle;
457
458         LASSERT(ctxt);
459         LASSERT(ctxt->loc_exp);
460         obd = ctxt->loc_exp->exp_obd;
461
462         if (logid != NULL) {
463                 dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, logid->lgl_oid,
464                                              logid->lgl_ogen, logid->lgl_ogr);
465
466                 if (IS_ERR(dchild)) {
467                         rc = PTR_ERR(dchild);
468                         CERROR("error looking up logfile "LPX64":0x%x: rc %d\n",
469                                logid->lgl_oid, logid->lgl_ogen, rc);
470                         GOTO(cleanup, rc);
471                 }
472
473                 cleanup_phase = 2;
474                 if (dchild->d_inode == NULL) {
475                         rc = -ENOENT;
476                         CERROR("nonexistent log file "LPX64":"LPX64": rc %d\n",
477                                logid->lgl_oid, logid->lgl_ogr, rc);
478                         GOTO(cleanup, rc);
479                 }
480
481                 handle->lgh_file = l_dentry_open(&obd->obd_ctxt, dchild,
482                                                     O_RDWR | O_LARGEFILE);
483                 if (IS_ERR(handle->lgh_file)) {
484                         rc = PTR_ERR(handle->lgh_file);
485                         CERROR("error opening logfile "LPX64"0x%x: rc %d\n",
486                                logid->lgl_oid, logid->lgl_ogen, rc);
487                         GOTO(cleanup, rc);
488                 }
489
490                 /* assign the value of lgh_id for handle directly */
491                 handle->lgh_id = *logid;
492
493         } else if (name) {
494                 handle->lgh_file = llog_filp_open(name, open_flags, 0644);
495                 if (IS_ERR(handle->lgh_file))
496                         GOTO(cleanup, rc = PTR_ERR(handle->lgh_file));
497
498                 handle->lgh_id.lgl_ogr = 1;
499                 handle->lgh_id.lgl_oid =
500                         handle->lgh_file->f_dentry->d_inode->i_ino;
501                 handle->lgh_id.lgl_ogen =
502                         handle->lgh_file->f_dentry->d_inode->i_generation;
503         } else {
504                 oa = obdo_alloc();
505                 if (oa == NULL)
506                         GOTO(cleanup, rc = -ENOMEM);
507                 /* XXX get some filter group constants */
508                 oa->o_gr = 1;
509                 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLGROUP;
510                 rc = obd_create(ctxt->loc_exp, oa, NULL, NULL);
511                 if (rc)
512                         GOTO(cleanup, rc);
513
514                 dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, oa->o_id,
515                                              oa->o_generation, oa->o_gr);
516
517                 if (IS_ERR(dchild))
518                         GOTO(cleanup, rc = PTR_ERR(dchild));
519                 cleanup_phase = 2;
520                 handle->lgh_file = l_dentry_open(&obd->obd_ctxt, dchild,
521                                                  open_flags);
522                 if (IS_ERR(handle->lgh_file))
523                         GOTO(cleanup, rc = PTR_ERR(handle->lgh_file));
524
525                 handle->lgh_id.lgl_ogr = oa->o_gr;
526                 handle->lgh_id.lgl_oid = oa->o_id;
527                 handle->lgh_id.lgl_ogen = oa->o_generation;
528         }
529
530         handle->lgh_ctxt = ctxt;
531  finish:
532         if (oa)
533                 obdo_free(oa);
534         RETURN(rc);
535 cleanup:
536         switch (cleanup_phase) {
537         case 2:
538                 l_dput(dchild);
539         case 1:
540                 llog_free_handle(handle);
541         }
542         goto finish;
543 }
544
545 static int llog_lvfs_close(struct llog_handle *handle)
546 {
547         int rc;
548         ENTRY;
549
550         rc = filp_close(handle->lgh_file, 0);
551         if (rc)
552                 CERROR("error closing log: rc %d\n", rc);
553         RETURN(rc);
554 }
555
556 static int llog_lvfs_destroy(struct llog_handle *handle)
557 {
558         struct dentry *fdentry;
559         struct obdo *oa;
560         int rc;
561         ENTRY;
562
563         fdentry = handle->lgh_file->f_dentry;
564         if (!strcmp(fdentry->d_parent->d_name.name, "LOGS")) {
565                 struct obd_device *obd = handle->lgh_ctxt->loc_exp->exp_obd;
566                 struct inode *inode = fdentry->d_parent->d_inode;
567                 struct obd_run_ctxt saved;
568
569                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
570                 dget(fdentry);
571                 rc = llog_lvfs_close(handle);
572
573                 if (rc == 0) {
574                         down(&inode->i_sem);
575                         rc = vfs_unlink(inode, fdentry);
576                         up(&inode->i_sem);
577                 }
578
579                 dput(fdentry);
580                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
581                 RETURN(rc);
582         }
583
584         oa = obdo_alloc();
585         if (oa == NULL)
586                 RETURN(-ENOMEM);
587
588         oa->o_id = handle->lgh_id.lgl_oid;
589         oa->o_gr = handle->lgh_id.lgl_ogr;
590         oa->o_generation = handle->lgh_id.lgl_ogen;
591         oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLGENER;
592
593         rc = llog_lvfs_close(handle);
594         if (rc)
595                 GOTO(out, rc);
596
597         rc = obd_destroy(handle->lgh_ctxt->loc_exp, oa, NULL, NULL);
598  out:
599         obdo_free(oa);
600         RETURN(rc);
601 }
602
603 /* reads the catalog list */
604 int llog_get_cat_list(struct obd_device *obd, struct obd_device *disk_obd,
605                       char *name, int count, struct llog_catid *idarray)
606 {
607         struct obd_run_ctxt saved;
608         struct l_file *file;
609         int rc;
610         int size = sizeof(*idarray) * count;
611         loff_t off = 0;
612
613         LASSERT(count);
614
615         push_ctxt(&saved, &obd->obd_ctxt, NULL);
616         file = filp_open(name, O_RDWR | O_CREAT | O_LARGEFILE, 0700);
617         if (!file || IS_ERR(file)) {
618                 rc = PTR_ERR(file);
619                 CERROR("OBD filter: cannot open/create %s: rc = %d\n",
620                        name, rc);
621                 GOTO(out, rc);
622         }
623
624         if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
625                 CERROR("%s is not a regular file!: mode = %o\n", name,
626                        file->f_dentry->d_inode->i_mode);
627                 GOTO(out, rc = -ENOENT);
628         }
629
630         rc = fsfilt_read_record(disk_obd, file, idarray, size, &off);
631         if (rc) {
632                 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
633                        name, rc);
634                 GOTO(out, rc);
635         }
636
637  out:
638         pop_ctxt(&saved, &obd->obd_ctxt, NULL);
639         if (file && !IS_ERR(file))
640                 rc = filp_close(file, 0);
641         RETURN(rc);
642 }
643 EXPORT_SYMBOL(llog_get_cat_list);
644
645 /* writes the cat list */
646 int llog_put_cat_list(struct obd_device *obd, struct obd_device *disk_obd,
647                       char *name, int count, struct llog_catid *idarray)
648 {
649         struct obd_run_ctxt saved;
650         struct l_file *file;
651         int rc;
652         int size = sizeof(*idarray) * count;
653         loff_t off = 0;
654
655         LASSERT(count);
656
657         push_ctxt(&saved, &obd->obd_ctxt, NULL);
658         file = filp_open(name, O_RDWR | O_CREAT | O_LARGEFILE, 0700);
659         if (!file || IS_ERR(file)) {
660                 rc = PTR_ERR(file);
661                 CERROR("OBD filter: cannot open/create %s: rc = %d\n",
662                        name, rc);
663                 GOTO(out, rc);
664         }
665
666         if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
667                 CERROR("%s is not a regular file!: mode = %o\n", name,
668                        file->f_dentry->d_inode->i_mode);
669                 GOTO(out, rc = -ENOENT);
670         }
671
672         rc = fsfilt_write_record(disk_obd, file, idarray, size, &off, 1);
673         if (rc) {
674                 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
675                        name, rc);
676                 GOTO(out, rc);
677         }
678
679  out:
680         pop_ctxt(&saved, &obd->obd_ctxt, NULL);
681         if (file && !IS_ERR(file))
682                 rc = filp_close(file, 0);
683         RETURN(rc);
684 }
685
686 struct llog_operations llog_lvfs_ops = {
687         lop_write_rec:   llog_lvfs_write_rec,
688         lop_next_block:  llog_lvfs_next_block,
689         lop_read_header: llog_lvfs_read_header,
690         lop_create:      llog_lvfs_create,
691         lop_destroy:     llog_lvfs_destroy,
692         lop_close:       llog_lvfs_close,
693         //        lop_cancel: llog_lvfs_cancel,
694 };
695
696 EXPORT_SYMBOL(llog_lvfs_ops);
697
698 #else /* !__KERNEL__ */
699
700 static int llog_lvfs_read_header(struct llog_handle *handle)
701 {
702         LBUG();
703         return 0;
704 }
705
706 static int llog_lvfs_write_rec(struct llog_handle *loghandle,
707                                struct llog_rec_hdr *rec,
708                                struct llog_cookie *reccookie, int cookiecount,
709                                void *buf, int idx)
710 {
711         LBUG();
712         return 0;
713 }
714
715 static int llog_lvfs_next_block(struct llog_handle *loghandle, int *cur_idx,
716                                 int next_idx, __u64 *cur_offset, void *buf,
717                                 int len)
718 {
719         LBUG();
720         return 0;
721 }
722
723 static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res,
724                             struct llog_logid *logid, char *name)
725 {
726         LBUG();
727         return 0;
728 }
729
730 static int llog_lvfs_close(struct llog_handle *handle)
731 {
732         LBUG();
733         return 0;
734 }
735
736 static int llog_lvfs_destroy(struct llog_handle *handle)
737 {
738         LBUG();
739         return 0;
740 }
741
742 int llog_get_cat_list(struct obd_device *obd, struct obd_device *disk_obd,
743                       char *name, int count, struct llog_catid *idarray)
744 {
745         LBUG();
746         return 0;
747 }
748
749 int llog_put_cat_list(struct obd_device *obd, struct obd_device *disk_obd,
750                       char *name, int count, struct llog_catid *idarray)
751 {
752         LBUG();
753         return 0;
754 }
755
756 struct llog_operations llog_lvfs_ops = {
757         lop_write_rec:   llog_lvfs_write_rec,
758         lop_next_block:  llog_lvfs_next_block,
759         lop_read_header: llog_lvfs_read_header,
760         lop_create:      llog_lvfs_create,
761         lop_destroy:     llog_lvfs_destroy,
762         lop_close:       llog_lvfs_close,
763 //        lop_cancel:      llog_lvfs_cancel,
764 };
765 #endif