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