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