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