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