Whamcloud - gitweb
*** empty log message ***
[fs/lustre-release.git] / lustre / lvfs / fsfilt_ext3.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/lib/fsfilt_ext3.c
5  *  Lustre filesystem abstraction routines
6  *
7  *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
8  *   Author: Andreas Dilger <adilger@clusterfs.com>
9  *
10  *   This file is part of Lustre, http://www.lustre.org.
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #define DEBUG_SUBSYSTEM S_FILTER
27
28 #include <linux/init.h>
29 #include <linux/module.h>
30 #include <linux/fs.h>
31 #include <linux/jbd.h>
32 #include <linux/slab.h>
33 #include <linux/pagemap.h>
34 #include <linux/quotaops.h>
35 #include <linux/ext3_fs.h>
36 #include <linux/ext3_jbd.h>
37 #include <linux/version.h>
38 #include <linux/bitops.h>
39 #include <linux/quota.h>
40 #include <linux/quotaio_v1.h>
41 #include <linux/quotaio_v2.h>
42 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
43 #include <linux/ext3_xattr.h>
44 #else
45 #include <ext3/xattr.h>
46 #endif
47
48 #include <libcfs/kp30.h>
49 #include <linux/lustre_fsfilt.h>
50 #include <linux/obd.h>
51 #include <linux/obd_class.h>
52 #include <linux/lustre_quota.h>
53 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
54 #include <linux/iobuf.h>
55 #endif
56
57 #ifdef EXT3_MULTIBLOCK_ALLOCATOR
58 #include <linux/ext3_extents.h>
59 #endif
60
61 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7))
62 # define lock_24kernel() lock_kernel()
63 # define unlock_24kernel() unlock_kernel()
64 #else
65 # define lock_24kernel() do {} while (0)
66 # define unlock_24kernel() do {} while (0)
67 #endif
68
69 static kmem_cache_t *fcb_cache;
70
71 struct fsfilt_cb_data {
72         struct journal_callback cb_jcb; /* jbd private data - MUST BE FIRST */
73         fsfilt_cb_t cb_func;            /* MDS/OBD completion function */
74         struct obd_device *cb_obd;      /* MDS/OBD completion device */
75         __u64 cb_last_rcvd;             /* MDS/OST last committed operation */
76         void *cb_data;                  /* MDS/OST completion function data */
77 };
78
79 #ifndef EXT3_XATTR_INDEX_TRUSTED        /* temporary until we hit l28 kernel */
80 #define EXT3_XATTR_INDEX_TRUSTED        4
81 #endif
82 #define XATTR_LUSTRE_MDS_LOV_EA         "lov"
83
84 /*
85  * We don't currently need any additional blocks for rmdir and
86  * unlink transactions because we are storing the OST oa_id inside
87  * the inode (which we will be changing anyways as part of this
88  * transaction).
89  */
90 static void *fsfilt_ext3_start(struct inode *inode, int op, void *desc_private,
91                                int logs)
92 {
93         /* For updates to the last received file */
94         int nblocks = EXT3_SINGLEDATA_TRANS_BLOCKS;
95         journal_t *journal;
96         void *handle;
97
98         if (current->journal_info) {
99                 CDEBUG(D_INODE, "increasing refcount on %p\n",
100                        current->journal_info);
101                 goto journal_start;
102         }
103
104         switch(op) {
105         case FSFILT_OP_RMDIR:
106         case FSFILT_OP_UNLINK:
107                 /* delete one file + create/update logs for each stripe */
108                 nblocks += EXT3_DELETE_TRANS_BLOCKS;
109                 nblocks += (EXT3_INDEX_EXTRA_TRANS_BLOCKS +
110                             EXT3_SINGLEDATA_TRANS_BLOCKS) * logs;
111                 break;
112         case FSFILT_OP_RENAME:
113                 /* modify additional directory */
114                 nblocks += EXT3_SINGLEDATA_TRANS_BLOCKS;
115                 /* no break */
116         case FSFILT_OP_SYMLINK:
117                 /* additional block + block bitmap + GDT for long symlink */
118                 nblocks += 3;
119                 /* no break */
120         case FSFILT_OP_CREATE: {
121 #if defined(EXT3_EXTENTS_FL) && defined(EXT3_INDEX_FL)
122                 static int warned;
123                 if (!warned) {
124                         if (!test_opt(inode->i_sb, EXTENTS)) {
125                                 warned = 1;
126                         } else if (((EXT3_I(inode)->i_flags &
127                               cpu_to_le32(EXT3_EXTENTS_FL | EXT3_INDEX_FL)) ==
128                               cpu_to_le32(EXT3_EXTENTS_FL | EXT3_INDEX_FL))) {
129                                 CWARN("extent-mapped directory found - contact "
130                                       "CFS: support@clusterfs.com\n");
131                                 warned = 1;
132                         }
133                 }
134 #endif
135                 /* no break */
136         }
137         case FSFILT_OP_MKDIR:
138         case FSFILT_OP_MKNOD:
139                 /* modify one inode + block bitmap + GDT */
140                 nblocks += 3;
141                 /* no break */
142         case FSFILT_OP_LINK:
143                 /* modify parent directory */
144                 nblocks += EXT3_INDEX_EXTRA_TRANS_BLOCKS +
145                         EXT3_DATA_TRANS_BLOCKS;
146                 /* create/update logs for each stripe */
147                 nblocks += (EXT3_INDEX_EXTRA_TRANS_BLOCKS +
148                             EXT3_SINGLEDATA_TRANS_BLOCKS) * logs;
149                 break;
150         case FSFILT_OP_SETATTR:
151                 /* Setattr on inode */
152                 nblocks += 1;
153                 nblocks += EXT3_INDEX_EXTRA_TRANS_BLOCKS +
154                         EXT3_DATA_TRANS_BLOCKS;
155                 /* quota chown log for each stripe */
156                 nblocks += (EXT3_INDEX_EXTRA_TRANS_BLOCKS +
157                             EXT3_SINGLEDATA_TRANS_BLOCKS) * logs;
158                 break;
159         case FSFILT_OP_CANCEL_UNLINK:
160                 /* blocks for log header bitmap update OR
161                  * blocks for catalog header bitmap update + unlink of logs */
162                 nblocks = (LLOG_CHUNK_SIZE >> inode->i_blkbits) +
163                         EXT3_DELETE_TRANS_BLOCKS * logs;
164                 break;
165         default: CERROR("unknown transaction start op %d\n", op);
166                 LBUG();
167         }
168
169         LASSERT(current->journal_info == desc_private);
170         journal = EXT3_SB(inode->i_sb)->s_journal;
171         if (nblocks > journal->j_max_transaction_buffers) {
172                 CERROR("too many credits %d for op %ux%u using %d instead\n",
173                        nblocks, op, logs, journal->j_max_transaction_buffers);
174                 nblocks = journal->j_max_transaction_buffers;
175         }
176
177  journal_start:
178         LASSERTF(nblocks > 0, "can't start %d credit transaction\n", nblocks);
179         lock_24kernel();
180         handle = journal_start(EXT3_JOURNAL(inode), nblocks);
181         unlock_24kernel();
182
183         if (!IS_ERR(handle))
184                 LASSERT(current->journal_info == handle);
185         else
186                 CERROR("error starting handle for op %u (%u credits): rc %ld\n",
187                        op, nblocks, PTR_ERR(handle));
188         return handle;
189 }
190
191 /*
192  * Calculate the number of buffer credits needed to write multiple pages in
193  * a single ext3 transaction.  No, this shouldn't be here, but as yet ext3
194  * doesn't have a nice API for calculating this sort of thing in advance.
195  *
196  * See comment above ext3_writepage_trans_blocks for details.  We assume
197  * no data journaling is being done, but it does allow for all of the pages
198  * being non-contiguous.  If we are guaranteed contiguous pages we could
199  * reduce the number of (d)indirect blocks a lot.
200  *
201  * With N blocks per page and P pages, for each inode we have at most:
202  * N*P indirect
203  * min(N*P, blocksize/4 + 1) dindirect blocks
204  * niocount tindirect
205  *
206  * For the entire filesystem, we have at most:
207  * min(sum(nindir + P), ngroups) bitmap blocks (from the above)
208  * min(sum(nindir + P), gdblocks) group descriptor blocks (from the above)
209  * objcount inode blocks
210  * 1 superblock
211  * 2 * EXT3_SINGLEDATA_TRANS_BLOCKS for the quota files
212  *
213  * 1 EXT3_DATA_TRANS_BLOCKS for the last_rcvd update.
214  */
215 static int fsfilt_ext3_credits_needed(int objcount, struct fsfilt_objinfo *fso,
216                                       int niocount, struct niobuf_local *nb)
217 {
218         struct super_block *sb = fso->fso_dentry->d_inode->i_sb;
219         __u64 next_indir;
220         const int blockpp = 1 << (PAGE_CACHE_SHIFT - sb->s_blocksize_bits);
221         int nbitmaps = 0, ngdblocks;
222         int needed = objcount + 1; /* inodes + superblock */
223         int i, j;
224
225         for (i = 0, j = 0; i < objcount; i++, fso++) {
226                 /* two or more dindirect blocks in case we cross boundary */
227                 int ndind = (long)((nb[j + fso->fso_bufcnt - 1].offset -
228                                     nb[j].offset) >>
229                                    sb->s_blocksize_bits) /
230                         (EXT3_ADDR_PER_BLOCK(sb) * EXT3_ADDR_PER_BLOCK(sb));
231                 nbitmaps += min(fso->fso_bufcnt, ndind > 0 ? ndind : 2);
232
233                 /* leaf, indirect, tindirect blocks for first block */
234                 nbitmaps += blockpp + 2;
235
236                 j += fso->fso_bufcnt;
237         }
238
239         next_indir = nb[0].offset +
240                 (EXT3_ADDR_PER_BLOCK(sb) << sb->s_blocksize_bits);
241         for (i = 1; i < niocount; i++) {
242                 if (nb[i].offset >= next_indir) {
243                         nbitmaps++;     /* additional indirect */
244                         next_indir = nb[i].offset +
245                                 (EXT3_ADDR_PER_BLOCK(sb)<<sb->s_blocksize_bits);
246                 } else if (nb[i].offset != nb[i - 1].offset + sb->s_blocksize) {
247                         nbitmaps++;     /* additional indirect */
248                 }
249                 nbitmaps += blockpp;    /* each leaf in different group? */
250         }
251
252         ngdblocks = nbitmaps;
253         if (nbitmaps > EXT3_SB(sb)->s_groups_count)
254                 nbitmaps = EXT3_SB(sb)->s_groups_count;
255         if (ngdblocks > EXT3_SB(sb)->s_gdb_count)
256                 ngdblocks = EXT3_SB(sb)->s_gdb_count;
257
258         needed += nbitmaps + ngdblocks;
259
260         /* last_rcvd update */
261         needed += EXT3_DATA_TRANS_BLOCKS;
262
263 #if defined(CONFIG_QUOTA)
264         /* We assume that there will be 1 bit set in s_dquot.flags for each
265          * quota file that is active.  This is at least true for now.
266          */
267         needed += hweight32(sb_any_quota_enabled(sb)) *
268                 EXT3_SINGLEDATA_TRANS_BLOCKS;
269 #endif
270
271         return needed;
272 }
273
274 /* We have to start a huge journal transaction here to hold all of the
275  * metadata for the pages being written here.  This is necessitated by
276  * the fact that we do lots of prepare_write operations before we do
277  * any of the matching commit_write operations, so even if we split
278  * up to use "smaller" transactions none of them could complete until
279  * all of them were opened.  By having a single journal transaction,
280  * we eliminate duplicate reservations for common blocks like the
281  * superblock and group descriptors or bitmaps.
282  *
283  * We will start the transaction here, but each prepare_write will
284  * add a refcount to the transaction, and each commit_write will
285  * remove a refcount.  The transaction will be closed when all of
286  * the pages have been written.
287  */
288 static void *fsfilt_ext3_brw_start(int objcount, struct fsfilt_objinfo *fso,
289                                    int niocount, struct niobuf_local *nb,
290                                    void *desc_private, int logs)
291 {
292         journal_t *journal;
293         handle_t *handle;
294         int needed;
295         ENTRY;
296
297         LASSERT(current->journal_info == desc_private);
298         journal = EXT3_SB(fso->fso_dentry->d_inode->i_sb)->s_journal;
299         needed = fsfilt_ext3_credits_needed(objcount, fso, niocount, nb);
300
301         /* The number of blocks we could _possibly_ dirty can very large.
302          * We reduce our request if it is absurd (and we couldn't get that
303          * many credits for a single handle anyways).
304          *
305          * At some point we have to limit the size of I/Os sent at one time,
306          * increase the size of the journal, or we have to calculate the
307          * actual journal requirements more carefully by checking all of
308          * the blocks instead of being maximally pessimistic.  It remains to
309          * be seen if this is a real problem or not.
310          */
311         if (needed > journal->j_max_transaction_buffers) {
312                 CERROR("want too many journal credits (%d) using %d instead\n",
313                        needed, journal->j_max_transaction_buffers);
314                 needed = journal->j_max_transaction_buffers;
315         }
316
317         LASSERTF(needed > 0, "can't start %d credit transaction\n", needed);
318         lock_24kernel();
319         handle = journal_start(journal, needed);
320         unlock_24kernel();
321         if (IS_ERR(handle)) {
322                 CERROR("can't get handle for %d credits: rc = %ld\n", needed,
323                        PTR_ERR(handle));
324         } else {
325                 LASSERT(handle->h_buffer_credits >= needed);
326                 LASSERT(current->journal_info == handle);
327         }
328
329         RETURN(handle);
330 }
331
332 static int fsfilt_ext3_commit(struct inode *inode, void *h, int force_sync)
333 {
334         int rc;
335         handle_t *handle = h;
336
337         LASSERT(current->journal_info == handle);
338         if (force_sync)
339                 handle->h_sync = 1; /* recovery likes this */
340
341         lock_24kernel();
342         rc = journal_stop(handle);
343         unlock_24kernel();
344
345         return rc;
346 }
347
348 static int fsfilt_ext3_commit_async(struct inode *inode, void *h,
349                                     void **wait_handle)
350 {
351         unsigned long tid;
352         transaction_t *transaction;
353 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
354         unsigned long rtid;
355 #endif
356         handle_t *handle = h;
357         journal_t *journal;
358         int rc;
359
360         LASSERT(current->journal_info == handle);
361
362         lock_kernel();
363         transaction = handle->h_transaction;
364         journal = transaction->t_journal;
365         tid = transaction->t_tid;
366         /* we don't want to be blocked */
367         handle->h_sync = 0;
368         rc = journal_stop(handle);
369         if (rc) {
370                 CERROR("error while stopping transaction: %d\n", rc);
371                 unlock_kernel();
372                 return rc;
373         }
374 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
375         rtid = log_start_commit(journal, transaction);
376         if (rtid != tid)
377                 CERROR("strange race: %lu != %lu\n",
378                        (unsigned long) tid, (unsigned long) rtid);
379 #else
380         log_start_commit(journal, transaction->t_tid);
381 #endif
382         unlock_kernel();
383
384         *wait_handle = (void *) tid;
385         CDEBUG(D_INODE, "commit async: %lu\n", (unsigned long) tid);
386         return 0;
387 }
388
389 static int fsfilt_ext3_commit_wait(struct inode *inode, void *h)
390 {
391         journal_t *journal = EXT3_JOURNAL(inode);
392         tid_t tid = (tid_t)(long)h;
393
394         CDEBUG(D_INODE, "commit wait: %lu\n", (unsigned long) tid);
395         if (unlikely(is_journal_aborted(journal)))
396                 return -EIO;
397
398         log_wait_commit(EXT3_JOURNAL(inode), tid);
399
400         if (unlikely(is_journal_aborted(journal)))
401                 return -EIO;
402         return 0;
403 }
404
405 static int fsfilt_ext3_setattr(struct dentry *dentry, void *handle,
406                                struct iattr *iattr, int do_trunc)
407 {
408         struct inode *inode = dentry->d_inode;
409         int rc;
410
411         lock_kernel();
412
413         /* A _really_ horrible hack to avoid removing the data stored
414          * in the block pointers; this is really the "small" stripe MD data.
415          * We can avoid further hackery by virtue of the MDS file size being
416          * zero all the time (which doesn't invoke block truncate at unlink
417          * time), so we assert we never change the MDS file size from zero. */
418         if (iattr->ia_valid & ATTR_SIZE && !do_trunc) {
419                 /* ATTR_SIZE would invoke truncate: clear it */
420                 iattr->ia_valid &= ~ATTR_SIZE;
421                 EXT3_I(inode)->i_disksize = inode->i_size = iattr->ia_size;
422
423                 /* make sure _something_ gets set - so new inode
424                  * goes to disk (probably won't work over XFS */
425                 if (!(iattr->ia_valid & (ATTR_MODE | ATTR_MTIME | ATTR_CTIME))){
426                         iattr->ia_valid |= ATTR_MODE;
427                         iattr->ia_mode = inode->i_mode;
428                 }
429         }
430
431         /* Don't allow setattr to change file type */
432         iattr->ia_mode = (inode->i_mode & S_IFMT)|(iattr->ia_mode & ~S_IFMT);
433
434         /* We set these flags on the client, but have already checked perms
435          * so don't confuse inode_change_ok. */
436         iattr->ia_valid &= ~(ATTR_MTIME_SET | ATTR_ATIME_SET);
437
438         if (inode->i_op->setattr) {
439                 rc = inode->i_op->setattr(dentry, iattr);
440         } else {
441                 rc = inode_change_ok(inode, iattr);
442                 if (!rc)
443                         rc = inode_setattr(inode, iattr);
444         }
445
446         unlock_kernel();
447
448         return rc;
449 }
450
451 static int fsfilt_ext3_iocontrol(struct inode * inode, struct file *file,
452                                  unsigned int cmd, unsigned long arg)
453 {
454         int rc = 0;
455         ENTRY;
456
457         if (inode->i_fop->ioctl)
458                 rc = inode->i_fop->ioctl(inode, file, cmd, arg);
459         else
460                 RETURN(-ENOTTY);
461
462         RETURN(rc);
463 }
464
465 static int fsfilt_ext3_set_md(struct inode *inode, void *handle,
466                               void *lmm, int lmm_size)
467 {
468         int rc;
469
470         LASSERT(down_trylock(&inode->i_sem) != 0);
471
472         if (EXT3_I(inode)->i_file_acl /* || large inode EA flag */)
473                 CWARN("setting EA on %lu/%u again... interesting\n",
474                        inode->i_ino, inode->i_generation);
475
476         lock_kernel();
477         rc = ext3_xattr_set_handle(handle, inode, EXT3_XATTR_INDEX_TRUSTED,
478                                    XATTR_LUSTRE_MDS_LOV_EA, lmm, lmm_size, 0);
479
480         unlock_kernel();
481
482         if (rc)
483                 CERROR("error adding MD data to inode %lu: rc = %d\n",
484                        inode->i_ino, rc);
485         return rc;
486 }
487
488 /* Must be called with i_sem held */
489 static int fsfilt_ext3_get_md(struct inode *inode, void *lmm, int lmm_size)
490 {
491         int rc;
492
493         LASSERT(down_trylock(&inode->i_sem) != 0);
494         lock_kernel();
495
496         rc = ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED,
497                             XATTR_LUSTRE_MDS_LOV_EA, lmm, lmm_size);
498         unlock_kernel();
499
500         /* This gives us the MD size */
501         if (lmm == NULL)
502                 return (rc == -ENODATA) ? 0 : rc;
503
504         if (rc < 0) {
505                 CDEBUG(D_INFO, "error getting EA %d/%s from inode %lu: rc %d\n",
506                        EXT3_XATTR_INDEX_TRUSTED, XATTR_LUSTRE_MDS_LOV_EA,
507                        inode->i_ino, rc);
508                 memset(lmm, 0, lmm_size);
509                 return (rc == -ENODATA) ? 0 : rc;
510         }
511
512         return rc;
513 }
514
515 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
516 static int fsfilt_ext3_send_bio(int rw, struct inode *inode, struct bio *bio)
517 {
518         submit_bio(rw, bio);
519         return 0;
520 }
521 #else
522 static int fsfilt_ext3_send_bio(int rw, struct inode *inode, struct kiobuf *bio)
523 {
524         int rc, blk_per_page;
525
526         rc = brw_kiovec(rw, 1, &bio, inode->i_dev,
527                         KIOBUF_GET_BLOCKS(bio), 1 << inode->i_blkbits);
528         /*
529          * brw_kiovec() returns number of bytes actually written. If error
530          * occurred after something was written, error code is returned though
531          * kiobuf->errno. (See bug 6854.)
532          */
533
534         blk_per_page = PAGE_CACHE_SIZE >> inode->i_blkbits;
535
536         if (rc != (1 << inode->i_blkbits) * bio->nr_pages * blk_per_page) {
537                 CERROR("short write?  expected %d, wrote %d (%d)\n",
538                        (1 << inode->i_blkbits) * bio->nr_pages * blk_per_page,
539                        rc, bio->errno);
540         }
541         if (bio->errno != 0) {
542                 CERROR("IO error. Wrote %d of %d (%d)\n",
543                        rc,
544                        (1 << inode->i_blkbits) * bio->nr_pages * blk_per_page,
545                        bio->errno);
546                 rc = bio->errno;
547         }
548
549         return rc;
550 }
551 #endif
552
553 static ssize_t fsfilt_ext3_readpage(struct file *file, char *buf, size_t count,
554                                     loff_t *off)
555 {
556         struct inode *inode = file->f_dentry->d_inode;
557         int rc = 0;
558
559         if (S_ISREG(inode->i_mode))
560                 rc = file->f_op->read(file, buf, count, off);
561         else {
562                 const int blkbits = inode->i_sb->s_blocksize_bits;
563                 const int blksize = inode->i_sb->s_blocksize;
564
565                 CDEBUG(D_EXT2, "reading "LPSZ" at dir %lu+%llu\n",
566                        count, inode->i_ino, *off);
567                 while (count > 0) {
568                         struct buffer_head *bh;
569
570                         bh = NULL;
571                         if (*off < inode->i_size) {
572                                 int err = 0;
573
574                                 bh = ext3_bread(NULL, inode, *off >> blkbits,
575                                                 0, &err);
576
577                                 CDEBUG(D_EXT2, "read %u@%llu\n", blksize, *off);
578
579                                 if (bh) {
580                                         memcpy(buf, bh->b_data, blksize);
581                                         brelse(bh);
582                                 } else if (err) {
583                                         /* XXX in theory we should just fake
584                                          * this buffer and continue like ext3,
585                                          * especially if this is a partial read
586                                          */
587                                         CERROR("error read dir %lu+%llu: %d\n",
588                                                inode->i_ino, *off, err);
589                                         RETURN(err);
590                                 }
591                         }
592                         if (!bh) {
593                                 struct ext3_dir_entry_2 *fake = (void *)buf;
594
595                                 CDEBUG(D_EXT2, "fake %u@%llu\n", blksize, *off);
596                                 memset(fake, 0, sizeof(*fake));
597                                 fake->rec_len = cpu_to_le32(blksize);
598                         }
599                         count -= blksize;
600                         buf += blksize;
601                         *off += blksize;
602                         rc += blksize;
603                 }
604         }
605
606         return rc;
607 }
608
609 static void fsfilt_ext3_cb_func(struct journal_callback *jcb, int error)
610 {
611         struct fsfilt_cb_data *fcb = (struct fsfilt_cb_data *)jcb;
612
613         fcb->cb_func(fcb->cb_obd, fcb->cb_last_rcvd, fcb->cb_data, error);
614
615         OBD_SLAB_FREE(fcb, fcb_cache, sizeof *fcb);
616 }
617
618 static int fsfilt_ext3_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
619                                       void *handle, fsfilt_cb_t cb_func,
620                                       void *cb_data)
621 {
622         struct fsfilt_cb_data *fcb;
623
624         OBD_SLAB_ALLOC(fcb, fcb_cache, GFP_NOFS, sizeof *fcb);
625         if (fcb == NULL)
626                 RETURN(-ENOMEM);
627
628         fcb->cb_func = cb_func;
629         fcb->cb_obd = obd;
630         fcb->cb_last_rcvd = last_rcvd;
631         fcb->cb_data = cb_data;
632
633         CDEBUG(D_EXT2, "set callback for last_rcvd: "LPD64"\n", last_rcvd);
634         lock_24kernel();
635         journal_callback_set(handle, fsfilt_ext3_cb_func,
636                              (struct journal_callback *)fcb);
637         unlock_24kernel();
638
639         return 0;
640 }
641
642 /*
643  * We need to hack the return value for the free inode counts because
644  * the current EA code requires one filesystem block per inode with EAs,
645  * so it is possible to run out of blocks before we run out of inodes.
646  *
647  * This can be removed when the ext3 EA code is fixed.
648  */
649 static int fsfilt_ext3_statfs(struct super_block *sb, struct obd_statfs *osfs)
650 {
651         struct kstatfs sfs;
652         int rc;
653
654         memset(&sfs, 0, sizeof(sfs));
655
656         rc = sb->s_op->statfs(sb, &sfs);
657
658         if (!rc && sfs.f_bfree < sfs.f_ffree) {
659                 sfs.f_files = (sfs.f_files - sfs.f_ffree) + sfs.f_bfree;
660                 sfs.f_ffree = sfs.f_bfree;
661         }
662
663         statfs_pack(osfs, &sfs);
664         return rc;
665 }
666
667 static int fsfilt_ext3_sync(struct super_block *sb)
668 {
669         return ext3_force_commit(sb);
670 }
671
672 #if defined(EXT3_MULTIBLOCK_ALLOCATOR) && (!defined(EXT3_EXT_CACHE_NO) || defined(EXT_CACHE_MARK))
673 #warning "kernel code has old extents/mballoc patch, disabling"
674 #undef EXT3_MULTIBLOCK_ALLOCATOR
675 #endif
676 #ifndef EXT3_EXTENTS_FL
677 #define EXT3_EXTENTS_FL                 0x00080000 /* Inode uses extents */
678 #endif
679
680 #ifdef EXT3_MULTIBLOCK_ALLOCATOR
681 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
682 #define ext3_up_truncate_sem(inode)  up_write(&EXT3_I(inode)->truncate_sem);
683 #define ext3_down_truncate_sem(inode)  down_write(&EXT3_I(inode)->truncate_sem);
684 #else
685 #define ext3_up_truncate_sem(inode)  up(&EXT3_I(inode)->truncate_sem);
686 #define ext3_down_truncate_sem(inode)  down(&EXT3_I(inode)->truncate_sem);
687 #endif
688
689 #include <linux/lustre_version.h>
690 #if EXT3_EXT_MAGIC == 0xf301
691 #define ee_start e_start
692 #define ee_block e_block
693 #define ee_len   e_num
694 #endif
695 #ifndef EXT3_BB_MAX_BLOCKS
696 #define ext3_mb_new_blocks(handle, inode, goal, count, aflags, err) \
697         ext3_new_blocks(handle, inode, count, goal, err)
698 #endif
699
700 struct bpointers {
701         unsigned long *blocks;
702         int *created;
703         unsigned long start;
704         int num;
705         int init_num;
706         int create;
707 };
708
709 static int ext3_ext_find_goal(struct inode *inode, struct ext3_ext_path *path,
710                               unsigned long block, int *aflags)
711 {
712         struct ext3_inode_info *ei = EXT3_I(inode);
713         unsigned long bg_start;
714         unsigned long colour;
715         int depth;
716
717         if (path) {
718                 struct ext3_extent *ex;
719                 depth = path->p_depth;
720
721                 /* try to predict block placement */
722                 if ((ex = path[depth].p_ext)) {
723 #if 0
724                         /* This prefers to eat into a contiguous extent
725                          * rather than find an extent that the whole
726                          * request will fit into.  This can fragment data
727                          * block allocation and prevents our lovely 1M I/Os
728                          * from reaching the disk intact. */
729                         if (ex->ee_block + ex->ee_len == block)
730                                 *aflags |= 1;
731 #endif
732                         return ex->ee_start + (block - ex->ee_block);
733                 }
734
735                 /* it looks index is empty
736                  * try to find starting from index itself */
737                 if (path[depth].p_bh)
738                         return path[depth].p_bh->b_blocknr;
739         }
740
741         /* OK. use inode's group */
742         bg_start = (ei->i_block_group * EXT3_BLOCKS_PER_GROUP(inode->i_sb)) +
743                 le32_to_cpu(EXT3_SB(inode->i_sb)->s_es->s_first_data_block);
744         colour = (current->pid % 16) *
745                 (EXT3_BLOCKS_PER_GROUP(inode->i_sb) / 16);
746         return bg_start + colour + block;
747 }
748
749 static int ext3_ext_new_extent_cb(struct ext3_extents_tree *tree,
750                                   struct ext3_ext_path *path,
751                                   struct ext3_ext_cache *cex)
752 {
753         struct inode *inode = tree->inode;
754         struct bpointers *bp = tree->private;
755         struct ext3_extent nex;
756         int count, err, goal;
757         unsigned long pblock;
758         unsigned long tgen;
759         loff_t new_i_size;
760         handle_t *handle;
761         int i, aflags = 0;
762
763         i = EXT_DEPTH(tree);
764         EXT_ASSERT(i == path->p_depth);
765         EXT_ASSERT(path[i].p_hdr);
766
767         if (cex->ec_type == EXT3_EXT_CACHE_EXTENT) {
768                 err = EXT_CONTINUE;
769                 goto map;
770         }
771
772         if (bp->create == 0) {
773                 i = 0;
774                 if (cex->ec_block < bp->start)
775                         i = bp->start - cex->ec_block;
776                 if (i >= cex->ec_len)
777                         CERROR("nothing to do?! i = %d, e_num = %u\n",
778                                         i, cex->ec_len);
779                 for (; i < cex->ec_len && bp->num; i++) {
780                         *(bp->created) = 0;
781                         bp->created++;
782                         *(bp->blocks) = 0;
783                         bp->blocks++;
784                         bp->num--;
785                         bp->start++;
786                 }
787
788                 return EXT_CONTINUE;
789         }
790
791         tgen = EXT_GENERATION(tree);
792         count = ext3_ext_calc_credits_for_insert(tree, path);
793         ext3_up_truncate_sem(inode);
794
795         lock_24kernel();
796         handle = journal_start(EXT3_JOURNAL(inode), count+EXT3_ALLOC_NEEDED+1);
797         unlock_24kernel();
798         if (IS_ERR(handle)) {
799                 ext3_down_truncate_sem(inode);
800                 return PTR_ERR(handle);
801         }
802
803         ext3_down_truncate_sem(inode);
804         if (tgen != EXT_GENERATION(tree)) {
805                 /* the tree has changed. so path can be invalid at moment */
806                 lock_24kernel();
807                 journal_stop(handle);
808                 unlock_24kernel();
809                 return EXT_REPEAT;
810         }
811
812         count = cex->ec_len;
813         goal = ext3_ext_find_goal(inode, path, cex->ec_block, &aflags);
814         aflags |= 2; /* block have been already reserved */
815         pblock = ext3_mb_new_blocks(handle, inode, goal, &count, aflags, &err);
816         if (!pblock)
817                 goto out;
818         EXT_ASSERT(count <= cex->ec_len);
819
820         /* insert new extent */
821         nex.ee_block = cex->ec_block;
822         nex.ee_start = pblock;
823         nex.ee_len = count;
824         err = ext3_ext_insert_extent(handle, tree, path, &nex);
825         if (err)
826                 goto out;
827
828         /*
829          * Putting len of the actual extent we just inserted,
830          * we are asking ext3_ext_walk_space() to continue
831          * scaning after that block
832          */
833         cex->ec_len = nex.ee_len;
834         cex->ec_start = nex.ee_start;
835         BUG_ON(nex.ee_len == 0);
836         BUG_ON(nex.ee_block != cex->ec_block);
837
838         /* correct on-disk inode size */
839         if (nex.ee_len > 0) {
840                 new_i_size = (loff_t) nex.ee_block + nex.ee_len;
841                 new_i_size = new_i_size << inode->i_blkbits;
842                 if (new_i_size > EXT3_I(inode)->i_disksize) {
843                         EXT3_I(inode)->i_disksize = new_i_size;
844                         err = ext3_mark_inode_dirty(handle, inode);
845                 }
846         }
847
848 out:
849         lock_24kernel();
850         journal_stop(handle);
851         unlock_24kernel();
852 map:
853         if (err >= 0) {
854                 /* map blocks */
855                 if (bp->num == 0) {
856                         CERROR("hmm. why do we find this extent?\n");
857                         CERROR("initial space: %lu:%u\n",
858                                 bp->start, bp->init_num);
859                         CERROR("current extent: %u/%u/%u %d\n",
860                                 cex->ec_block, cex->ec_len,
861                                 cex->ec_start, cex->ec_type);
862                 }
863                 i = 0;
864                 if (cex->ec_block < bp->start)
865                         i = bp->start - cex->ec_block;
866                 if (i >= cex->ec_len)
867                         CERROR("nothing to do?! i = %d, e_num = %u\n",
868                                         i, cex->ec_len);
869                 for (; i < cex->ec_len && bp->num; i++) {
870                         if (cex->ec_type == EXT3_EXT_CACHE_EXTENT)
871                                 *(bp->created) = 0;
872                         else
873                                 *(bp->created) = 1;
874                         bp->created++;
875                         *(bp->blocks) = cex->ec_start + i;
876                         bp->blocks++;
877                         bp->num--;
878                         bp->start++;
879                 }
880         }
881         return err;
882 }
883
884 int fsfilt_map_nblocks(struct inode *inode, unsigned long block,
885                        unsigned long num, unsigned long *blocks,
886                        int *created, int create)
887 {
888         struct ext3_extents_tree tree;
889         struct bpointers bp;
890         int err;
891
892         CDEBUG(D_OTHER, "blocks %lu-%lu requested for inode %u\n",
893                 block, block + num, (unsigned) inode->i_ino);
894
895         ext3_init_tree_desc(&tree, inode);
896         tree.private = &bp;
897         bp.blocks = blocks;
898         bp.created = created;
899         bp.start = block;
900         bp.init_num = bp.num = num;
901         bp.create = create;
902
903         ext3_down_truncate_sem(inode);
904         err = ext3_ext_walk_space(&tree, block, num, ext3_ext_new_extent_cb);
905         ext3_ext_invalidate_cache(&tree);
906         ext3_up_truncate_sem(inode);
907
908         return err;
909 }
910
911 int fsfilt_ext3_map_ext_inode_pages(struct inode *inode, struct page **page,
912                                     int pages, unsigned long *blocks,
913                                     int *created, int create)
914 {
915         int blocks_per_page = PAGE_SIZE >> inode->i_blkbits;
916         int rc = 0, i = 0;
917         struct page *fp = NULL;
918         int clen = 0;
919
920         CDEBUG(D_OTHER, "inode %lu: map %d pages from %lu\n",
921                 inode->i_ino, pages, (*page)->index);
922
923         /* pages are sorted already. so, we just have to find
924          * contig. space and process them properly */
925         while (i < pages) {
926                 if (fp == NULL) {
927                         /* start new extent */
928                         fp = *page++;
929                         clen = 1;
930                         i++;
931                         continue;
932                 } else if (fp->index + clen == (*page)->index) {
933                         /* continue the extent */
934                         page++;
935                         clen++;
936                         i++;
937                         continue;
938                 }
939
940                 /* process found extent */
941                 rc = fsfilt_map_nblocks(inode, fp->index * blocks_per_page,
942                                         clen * blocks_per_page, blocks,
943                                         created, create);
944                 if (rc)
945                         GOTO(cleanup, rc);
946
947                 /* look for next extent */
948                 fp = NULL;
949                 blocks += blocks_per_page * clen;
950                 created += blocks_per_page * clen;
951         }
952
953         if (fp)
954                 rc = fsfilt_map_nblocks(inode, fp->index * blocks_per_page,
955                                         clen * blocks_per_page, blocks,
956                                         created, create);
957 cleanup:
958         return rc;
959 }
960 #endif
961
962 extern int ext3_map_inode_page(struct inode *inode, struct page *page,
963                                unsigned long *blocks, int *created, int create);
964 int fsfilt_ext3_map_bm_inode_pages(struct inode *inode, struct page **page,
965                                    int pages, unsigned long *blocks,
966                                    int *created, int create)
967 {
968         int blocks_per_page = PAGE_SIZE >> inode->i_blkbits;
969         unsigned long *b;
970         int rc = 0, i, *cr;
971
972         for (i = 0, cr = created, b = blocks; i < pages; i++, page++) {
973                 rc = ext3_map_inode_page(inode, *page, b, cr, create);
974                 if (rc) {
975                         CERROR("ino %lu, blk %lu cr %u create %d: rc %d\n",
976                                inode->i_ino, *b, *cr, create, rc);
977                         break;
978                 }
979
980                 b += blocks_per_page;
981                 cr += blocks_per_page;
982         }
983         return rc;
984 }
985
986 int fsfilt_ext3_map_inode_pages(struct inode *inode, struct page **page,
987                                 int pages, unsigned long *blocks,
988                                 int *created, int create,
989                                 struct semaphore *optional_sem)
990 {
991         int rc;
992 #ifdef EXT3_MULTIBLOCK_ALLOCATOR
993         if (EXT3_I(inode)->i_flags & EXT3_EXTENTS_FL) {
994                 rc = fsfilt_ext3_map_ext_inode_pages(inode, page, pages,
995                                                      blocks, created, create);
996                 return rc;
997         }
998 #endif
999         if (optional_sem != NULL)
1000                 down(optional_sem);
1001         rc = fsfilt_ext3_map_bm_inode_pages(inode, page, pages, blocks,
1002                                             created, create);
1003         if (optional_sem != NULL)
1004                 up(optional_sem);
1005
1006         return rc;
1007 }
1008
1009 extern int ext3_prep_san_write(struct inode *inode, long *blocks,
1010                                int nblocks, loff_t newsize);
1011 static int fsfilt_ext3_prep_san_write(struct inode *inode, long *blocks,
1012                                       int nblocks, loff_t newsize)
1013 {
1014         return ext3_prep_san_write(inode, blocks, nblocks, newsize);
1015 }
1016
1017 static int fsfilt_ext3_read_record(struct file * file, void *buf,
1018                                    int size, loff_t *offs)
1019 {
1020         struct inode *inode = file->f_dentry->d_inode;
1021         unsigned long block;
1022         struct buffer_head *bh;
1023         int err, blocksize, csize, boffs;
1024
1025         /* prevent reading after eof */
1026         lock_kernel();
1027         if (inode->i_size < *offs + size) {
1028                 size = inode->i_size - *offs;
1029                 unlock_kernel();
1030                 if (size < 0) {
1031                         CERROR("size %llu is too short for read %u@%llu\n",
1032                                inode->i_size, size, *offs);
1033                         return -EIO;
1034                 } else if (size == 0) {
1035                         return 0;
1036                 }
1037         } else {
1038                 unlock_kernel();
1039         }
1040
1041         blocksize = 1 << inode->i_blkbits;
1042
1043         while (size > 0) {
1044                 block = *offs >> inode->i_blkbits;
1045                 boffs = *offs & (blocksize - 1);
1046                 csize = min(blocksize - boffs, size);
1047                 bh = ext3_bread(NULL, inode, block, 0, &err);
1048                 if (!bh) {
1049                         CERROR("can't read block: %d\n", err);
1050                         return err;
1051                 }
1052
1053                 memcpy(buf, bh->b_data + boffs, csize);
1054                 brelse(bh);
1055
1056                 *offs += csize;
1057                 buf += csize;
1058                 size -= csize;
1059         }
1060         return 0;
1061 }
1062
1063 static int fsfilt_ext3_write_record(struct file *file, void *buf, int bufsize,
1064                                     loff_t *offs, int force_sync)
1065 {
1066         struct buffer_head *bh = NULL;
1067         unsigned long block;
1068         struct inode *inode = file->f_dentry->d_inode;
1069         loff_t old_size = inode->i_size, offset = *offs;
1070         loff_t new_size = inode->i_size;
1071         journal_t *journal;
1072         handle_t *handle;
1073         int err, block_count = 0, blocksize, size, boffs;
1074
1075         /* Determine how many transaction credits are needed */
1076         blocksize = 1 << inode->i_blkbits;
1077         block_count = (*offs & (blocksize - 1)) + bufsize;
1078         block_count = (block_count + blocksize - 1) >> inode->i_blkbits;
1079
1080         journal = EXT3_SB(inode->i_sb)->s_journal;
1081         lock_24kernel();
1082         handle = journal_start(journal,
1083                                block_count * EXT3_DATA_TRANS_BLOCKS + 2);
1084         unlock_24kernel();
1085         if (IS_ERR(handle)) {
1086                 CERROR("can't start transaction\n");
1087                 return PTR_ERR(handle);
1088         }
1089
1090         while (bufsize > 0) {
1091                 if (bh != NULL)
1092                         brelse(bh);
1093
1094                 block = offset >> inode->i_blkbits;
1095                 boffs = offset & (blocksize - 1);
1096                 size = min(blocksize - boffs, bufsize);
1097                 bh = ext3_bread(handle, inode, block, 1, &err);
1098                 if (!bh) {
1099                         CERROR("can't read/create block: %d\n", err);
1100                         goto out;
1101                 }
1102
1103                 err = ext3_journal_get_write_access(handle, bh);
1104                 if (err) {
1105                         CERROR("journal_get_write_access() returned error %d\n",
1106                                err);
1107                         goto out;
1108                 }
1109                 LASSERT(bh->b_data + boffs + size <= bh->b_data + bh->b_size);
1110                 memcpy(bh->b_data + boffs, buf, size);
1111                 err = ext3_journal_dirty_metadata(handle, bh);
1112                 if (err) {
1113                         CERROR("journal_dirty_metadata() returned error %d\n",
1114                                err);
1115                         goto out;
1116                 }
1117                 if (offset + size > new_size)
1118                         new_size = offset + size;
1119                 offset += size;
1120                 bufsize -= size;
1121                 buf += size;
1122         }
1123
1124         if (force_sync)
1125                 handle->h_sync = 1; /* recovery likes this */
1126 out:
1127         if (bh)
1128                 brelse(bh);
1129
1130         /* correct in-core and on-disk sizes */
1131         if (new_size > inode->i_size) {
1132                 lock_kernel();
1133                 if (new_size > inode->i_size)
1134                         inode->i_size = new_size;
1135                 if (inode->i_size > EXT3_I(inode)->i_disksize)
1136                         EXT3_I(inode)->i_disksize = inode->i_size;
1137                 if (inode->i_size > old_size)
1138                         mark_inode_dirty(inode);
1139                 unlock_kernel();
1140         }
1141
1142         lock_24kernel();
1143         journal_stop(handle);
1144         unlock_24kernel();
1145
1146         if (err == 0)
1147                 *offs = offset;
1148         return err;
1149 }
1150
1151 static int fsfilt_ext3_setup(struct super_block *sb)
1152 {
1153 #if 0
1154         EXT3_SB(sb)->dx_lock = fsfilt_ext3_dx_lock;
1155         EXT3_SB(sb)->dx_unlock = fsfilt_ext3_dx_unlock;
1156 #endif
1157 #ifdef S_PDIROPS
1158         CWARN("Enabling PDIROPS\n");
1159         set_opt(EXT3_SB(sb)->s_mount_opt, PDIROPS);
1160         sb->s_flags |= S_PDIROPS;
1161 #endif
1162         return 0;
1163 }
1164
1165 /* If fso is NULL, op is FSFILT operation, otherwise op is number of fso
1166    objects. Logs is number of logfiles to update */
1167 static int fsfilt_ext3_get_op_len(int op, struct fsfilt_objinfo *fso, int logs)
1168 {
1169         if ( !fso ) {
1170                 switch(op) {
1171                 case FSFILT_OP_CREATE:
1172                                  /* directory leaf, index & indirect & EA*/
1173                         return 4 + 3 * logs;
1174                 case FSFILT_OP_UNLINK:
1175                         return 3 * logs;
1176                 }
1177         } else {
1178                 int i;
1179                 int needed = 0;
1180                 struct super_block *sb = fso->fso_dentry->d_inode->i_sb;
1181                 int blockpp = 1 << (PAGE_CACHE_SHIFT - sb->s_blocksize_bits);
1182                 int addrpp = EXT3_ADDR_PER_BLOCK(sb) * blockpp;
1183                 for (i = 0; i < op; i++, fso++) {
1184                         int nblocks = fso->fso_bufcnt * blockpp;
1185                         int ndindirect = min(nblocks, addrpp + 1);
1186                         int nindir = nblocks + ndindirect + 1;
1187
1188                         needed += nindir;
1189                 }
1190                 return needed + 3 * logs;
1191         }
1192
1193         return 0;
1194 }
1195
1196 static inline struct ext3_group_desc *
1197 get_group_desc(struct super_block *sb, int group)
1198 {
1199         unsigned long desc_block, desc;
1200         struct ext3_group_desc *gdp;
1201
1202         desc_block = group / EXT3_DESC_PER_BLOCK(sb);
1203         desc = group % EXT3_DESC_PER_BLOCK(sb);
1204         gdp = (struct ext3_group_desc *)
1205               EXT3_SB(sb)->s_group_desc[desc_block]->b_data;
1206
1207         return gdp + desc;
1208 }
1209
1210 static inline struct buffer_head *
1211 read_inode_bitmap(struct super_block *sb, unsigned long group)
1212 {
1213         struct ext3_group_desc *desc;
1214         struct buffer_head *bh;
1215
1216         desc = get_group_desc(sb, group);
1217         bh = sb_bread(sb, le32_to_cpu(desc->bg_inode_bitmap));
1218
1219         return bh;
1220 }
1221
1222 static inline struct inode *ext3_iget_inuse(struct super_block *sb,
1223                                      struct buffer_head *bitmap_bh,
1224                                      int index, unsigned long ino)
1225 {
1226         struct inode *inode = NULL;
1227
1228         if (ext3_test_bit(index, bitmap_bh->b_data))
1229                 inode = iget(sb, ino);
1230
1231         return inode;
1232 }
1233
1234 #ifdef HAVE_QUOTA_SUPPORT
1235 # include "fsfilt_ext3_quota.h"
1236 #endif
1237
1238 static struct fsfilt_operations fsfilt_ext3_ops = {
1239         .fs_type                = "ext3",
1240         .fs_owner               = THIS_MODULE,
1241         .fs_start               = fsfilt_ext3_start,
1242         .fs_brw_start           = fsfilt_ext3_brw_start,
1243         .fs_commit              = fsfilt_ext3_commit,
1244         .fs_commit_async        = fsfilt_ext3_commit_async,
1245         .fs_commit_wait         = fsfilt_ext3_commit_wait,
1246         .fs_setattr             = fsfilt_ext3_setattr,
1247         .fs_iocontrol           = fsfilt_ext3_iocontrol,
1248         .fs_set_md              = fsfilt_ext3_set_md,
1249         .fs_get_md              = fsfilt_ext3_get_md,
1250         .fs_readpage            = fsfilt_ext3_readpage,
1251         .fs_add_journal_cb      = fsfilt_ext3_add_journal_cb,
1252         .fs_statfs              = fsfilt_ext3_statfs,
1253         .fs_sync                = fsfilt_ext3_sync,
1254         .fs_map_inode_pages     = fsfilt_ext3_map_inode_pages,
1255         .fs_prep_san_write      = fsfilt_ext3_prep_san_write,
1256         .fs_write_record        = fsfilt_ext3_write_record,
1257         .fs_read_record         = fsfilt_ext3_read_record,
1258         .fs_setup               = fsfilt_ext3_setup,
1259         .fs_send_bio            = fsfilt_ext3_send_bio,
1260         .fs_get_op_len          = fsfilt_ext3_get_op_len,
1261 #ifdef HAVE_QUOTA_SUPPORT
1262         .fs_quotactl            = fsfilt_ext3_quotactl,
1263         .fs_quotacheck          = fsfilt_ext3_quotacheck,
1264         .fs_quotainfo           = fsfilt_ext3_quotainfo,
1265         .fs_dquot               = fsfilt_ext3_dquot,
1266 #endif
1267 };
1268
1269 static int __init fsfilt_ext3_init(void)
1270 {
1271         int rc;
1272
1273         fcb_cache = kmem_cache_create("fsfilt_ext3_fcb",
1274                                       sizeof(struct fsfilt_cb_data), 0,
1275                                       0, NULL, NULL);
1276         if (!fcb_cache) {
1277                 CERROR("error allocating fsfilt journal callback cache\n");
1278                 GOTO(out, rc = -ENOMEM);
1279         }
1280
1281         rc = fsfilt_register_ops(&fsfilt_ext3_ops);
1282
1283         if (rc)
1284                 kmem_cache_destroy(fcb_cache);
1285 out:
1286         return rc;
1287 }
1288
1289 static void __exit fsfilt_ext3_exit(void)
1290 {
1291         fsfilt_unregister_ops(&fsfilt_ext3_ops);
1292         LASSERT(kmem_cache_destroy(fcb_cache) == 0);
1293 }
1294
1295 module_init(fsfilt_ext3_init);
1296 module_exit(fsfilt_ext3_exit);
1297
1298 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1299 MODULE_DESCRIPTION("Lustre ext3 Filesystem Helper v0.1");
1300 MODULE_LICENSE("GPL");