Whamcloud - gitweb
file configurable-x86-stack-2.4.22-rh.patch was initially added on branch b_devel.
[fs/lustre-release.git] / lustre / obdclass / 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/fs.h>
29 #include <linux/jbd.h>
30 #include <linux/slab.h>
31 #include <linux/pagemap.h>
32 #include <linux/quotaops.h>
33 #include <linux/ext3_fs.h>
34 #include <linux/ext3_jbd.h>
35 #include <linux/version.h>
36 /* XXX ugh */
37 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
38  #include <linux/ext3_xattr.h>
39 #else 
40  #include <linux/../../fs/ext3/xattr.h>
41 #endif
42 #include <linux/kp30.h>
43 #include <linux/lustre_fsfilt.h>
44 #include <linux/obd.h>
45 #include <linux/obd_class.h>
46 #include <linux/module.h>
47
48 static kmem_cache_t *fcb_cache;
49 static atomic_t fcb_cache_count = ATOMIC_INIT(0);
50
51 struct fsfilt_cb_data {
52         struct journal_callback cb_jcb; /* jbd private data - MUST BE FIRST */
53         fsfilt_cb_t cb_func;            /* MDS/OBD completion function */
54         struct obd_device *cb_obd;      /* MDS/OBD completion device */
55         __u64 cb_last_rcvd;             /* MDS/OST last committed operation */
56         void *cb_data;                  /* MDS/OST completion function data */
57 };
58
59 #define EXT3_XATTR_INDEX_LUSTRE         5
60 #define XATTR_LUSTRE_MDS_OBJID          "system.lustre_mds_objid"
61
62 /*
63  * We don't currently need any additional blocks for rmdir and
64  * unlink transactions because we are storing the OST oa_id inside
65  * the inode (which we will be changing anyways as part of this
66  * transaction).
67  */
68 static void *fsfilt_ext3_start(struct inode *inode, int op, void *desc_private)
69 {
70         /* For updates to the last recieved file */
71         int nblocks = EXT3_DATA_TRANS_BLOCKS;
72         void *handle;
73
74         LASSERT(current->journal_info == NULL);
75
76         switch(op) {
77         case FSFILT_OP_CREATE_LOG:
78                 nblocks += EXT3_INDEX_EXTRA_TRANS_BLOCKS+EXT3_DATA_TRANS_BLOCKS;
79                 op = FSFILT_OP_CREATE;
80                 break;
81         case FSFILT_OP_UNLINK_LOG:
82                 nblocks += EXT3_INDEX_EXTRA_TRANS_BLOCKS+EXT3_DATA_TRANS_BLOCKS;
83                 op = FSFILT_OP_UNLINK;
84                 break;
85         }
86
87         switch(op) {
88         case FSFILT_OP_RMDIR:
89         case FSFILT_OP_UNLINK:
90                 nblocks += EXT3_DELETE_TRANS_BLOCKS;
91                 break;
92         case FSFILT_OP_RENAME:
93                 /* modify additional directory */
94                 nblocks += EXT3_DATA_TRANS_BLOCKS;
95                 /* no break */
96         case FSFILT_OP_SYMLINK:
97                 /* additional block + block bitmap + GDT for long symlink */
98                 nblocks += 3;
99                 /* no break */
100         case FSFILT_OP_CREATE:
101         case FSFILT_OP_MKDIR:
102         case FSFILT_OP_MKNOD:
103                 /* modify one inode + block bitmap + GDT */
104                 nblocks += 3;
105                 /* no break */
106         case FSFILT_OP_LINK:
107                 /* modify parent directory */
108                 nblocks += EXT3_INDEX_EXTRA_TRANS_BLOCKS+EXT3_DATA_TRANS_BLOCKS;
109                 break;
110         case FSFILT_OP_SETATTR:
111                 /* Setattr on inode */
112                 nblocks += 1;
113                 break;
114         default: CERROR("unknown transaction start op %d\n", op);
115                  LBUG();
116         }
117
118         LASSERT(current->journal_info == desc_private);
119         lock_kernel();
120         handle = journal_start(EXT3_JOURNAL(inode), nblocks);
121         unlock_kernel();
122
123         if (!IS_ERR(handle))
124                 LASSERT(current->journal_info == handle);
125         return handle;
126 }
127
128 /*
129  * Calculate the number of buffer credits needed to write multiple pages in
130  * a single ext3 transaction.  No, this shouldn't be here, but as yet ext3
131  * doesn't have a nice API for calculating this sort of thing in advance.
132  *
133  * See comment above ext3_writepage_trans_blocks for details.  We assume
134  * no data journaling is being done, but it does allow for all of the pages
135  * being non-contiguous.  If we are guaranteed contiguous pages we could
136  * reduce the number of (d)indirect blocks a lot.
137  *
138  * With N blocks per page and P pages, for each inode we have at most:
139  * N*P indirect
140  * min(N*P, blocksize/4 + 1) dindirect blocks
141  * niocount tindirect
142  *
143  * For the entire filesystem, we have at most:
144  * min(sum(nindir + P), ngroups) bitmap blocks (from the above)
145  * min(sum(nindir + P), gdblocks) group descriptor blocks (from the above)
146  * objcount inode blocks
147  * 1 superblock
148  * 2 * EXT3_SINGLEDATA_TRANS_BLOCKS for the quota files
149  *
150  * 1 EXT3_DATA_TRANS_BLOCKS for the last_rcvd update.
151  */
152 static int fsfilt_ext3_credits_needed(int objcount, struct fsfilt_objinfo *fso)
153 {
154         struct super_block *sb = fso->fso_dentry->d_inode->i_sb;
155         int blockpp = 1 << (PAGE_CACHE_SHIFT - sb->s_blocksize_bits);
156         int addrpp = EXT3_ADDR_PER_BLOCK(sb) * blockpp;
157         int nbitmaps = 0;
158         int ngdblocks = 0;
159         int needed = objcount + 1;
160         int i;
161
162         for (i = 0; i < objcount; i++, fso++) {
163                 int nblocks = fso->fso_bufcnt * blockpp;
164                 int ndindirect = min(nblocks, addrpp + 1);
165                 int nindir = nblocks + ndindirect + 1;
166
167                 nbitmaps += nindir + nblocks;
168                 ngdblocks += nindir + nblocks;
169
170                 needed += nindir;
171         }
172
173         /* Assumes ext3 and ext3 have same sb_info layout at the start. */
174         if (nbitmaps > EXT3_SB(sb)->s_groups_count)
175                 nbitmaps = EXT3_SB(sb)->s_groups_count;
176         if (ngdblocks > EXT3_SB(sb)->s_gdb_count)
177                 ngdblocks = EXT3_SB(sb)->s_gdb_count;
178
179         needed += nbitmaps + ngdblocks;
180
181         /* last_rcvd update */
182         needed += EXT3_DATA_TRANS_BLOCKS;
183
184 #ifdef CONFIG_QUOTA
185         /* We assume that there will be 1 bit set in s_dquot.flags for each
186          * quota file that is active.  This is at least true for now.
187          */
188         needed += hweight32(sb_any_quota_enabled(sb)) *
189                 EXT3_SINGLEDATA_TRANS_BLOCKS;
190 #endif
191
192         return needed;
193 }
194
195 /* We have to start a huge journal transaction here to hold all of the
196  * metadata for the pages being written here.  This is necessitated by
197  * the fact that we do lots of prepare_write operations before we do
198  * any of the matching commit_write operations, so even if we split
199  * up to use "smaller" transactions none of them could complete until
200  * all of them were opened.  By having a single journal transaction,
201  * we eliminate duplicate reservations for common blocks like the
202  * superblock and group descriptors or bitmaps.
203  *
204  * We will start the transaction here, but each prepare_write will
205  * add a refcount to the transaction, and each commit_write will
206  * remove a refcount.  The transaction will be closed when all of
207  * the pages have been written.
208  */
209 static void *fsfilt_ext3_brw_start(int objcount, struct fsfilt_objinfo *fso,
210                                    int niocount, void *desc_private)
211 {
212         journal_t *journal;
213         handle_t *handle;
214         int needed;
215         ENTRY;
216
217         LASSERT(current->journal_info == desc_private);
218         journal = EXT3_SB(fso->fso_dentry->d_inode->i_sb)->s_journal;
219         needed = fsfilt_ext3_credits_needed(objcount, fso);
220
221         /* The number of blocks we could _possibly_ dirty can very large.
222          * We reduce our request if it is absurd (and we couldn't get that
223          * many credits for a single handle anyways).
224          *
225          * At some point we have to limit the size of I/Os sent at one time,
226          * increase the size of the journal, or we have to calculate the
227          * actual journal requirements more carefully by checking all of
228          * the blocks instead of being maximally pessimistic.  It remains to
229          * be seen if this is a real problem or not.
230          */
231         if (needed > journal->j_max_transaction_buffers) {
232                 CERROR("want too many journal credits (%d) using %d instead\n",
233                        needed, journal->j_max_transaction_buffers);
234                 needed = journal->j_max_transaction_buffers;
235         }
236
237         lock_kernel();
238         handle = journal_start(journal, needed);
239         unlock_kernel();
240         if (IS_ERR(handle)) {
241                 CERROR("can't get handle for %d credits: rc = %ld\n", needed,
242                        PTR_ERR(handle));
243         } else {
244                 LASSERT(handle->h_buffer_credits >= needed);
245                 LASSERT(current->journal_info == handle);
246         }
247
248         RETURN(handle);
249 }
250
251 static int fsfilt_ext3_commit(struct inode *inode, void *h, int force_sync)
252 {
253         int rc;
254         handle_t *handle = h;
255
256         LASSERT(current->journal_info == handle);
257         if (force_sync)
258                 handle->h_sync = 1; /* recovery likes this */
259
260         lock_kernel();
261         rc = journal_stop(handle);
262         unlock_kernel();
263
264         LASSERT(current->journal_info == NULL);
265         return rc;
266 }
267
268 static int fsfilt_ext3_setattr(struct dentry *dentry, void *handle,
269                                struct iattr *iattr, int do_trunc)
270 {
271         struct inode *inode = dentry->d_inode;
272         int rc;
273
274         lock_kernel();
275
276         /* A _really_ horrible hack to avoid removing the data stored
277          * in the block pointers; this is really the "small" stripe MD data.
278          * We can avoid further hackery by virtue of the MDS file size being
279          * zero all the time (which doesn't invoke block truncate at unlink
280          * time), so we assert we never change the MDS file size from zero. */
281         if (iattr->ia_valid & ATTR_SIZE && !do_trunc) {
282                 /* ATTR_SIZE would invoke truncate: clear it */
283                 iattr->ia_valid &= ~ATTR_SIZE;
284                 EXT3_I(inode)->i_disksize = inode->i_size = iattr->ia_size;
285
286                 /* make sure _something_ gets set - so new inode
287                  * goes to disk (probably won't work over XFS */
288                 if (!(iattr->ia_valid & (ATTR_MODE | ATTR_MTIME | ATTR_CTIME))){
289                         iattr->ia_valid |= ATTR_MODE;
290                         iattr->ia_mode = inode->i_mode;
291                 }
292         }
293
294         /* Don't allow setattr to change file type */
295         iattr->ia_mode = (inode->i_mode & S_IFMT)|(iattr->ia_mode & ~S_IFMT);
296
297         /* We set these flags on the client, but have already checked perms
298          * so don't confuse inode_change_ok. */
299         iattr->ia_valid &= ~(ATTR_MTIME_SET | ATTR_ATIME_SET);
300
301         if (inode->i_op->setattr) {
302                 rc = inode->i_op->setattr(dentry, iattr);
303         } else {
304                 rc = inode_change_ok(inode, iattr);
305                 if (!rc)
306                         rc = inode_setattr(inode, iattr);
307         }
308
309         unlock_kernel();
310
311         return rc;
312 }
313
314 static int fsfilt_ext3_set_md(struct inode *inode, void *handle,
315                               void *lmm, int lmm_size)
316 {
317         int rc;
318
319         /* Nasty hack city - store stripe MD data in the block pointers if
320          * it will fit, because putting it in an EA currently kills the MDS
321          * performance.  We'll fix this with "fast EAs" in the future.
322          */
323         if (inode->i_blocks == 0 && lmm_size <= sizeof(EXT3_I(inode)->i_data) -
324                                             sizeof(EXT3_I(inode)->i_data[0])) {
325                 /* XXX old_size is debugging only */
326                 int old_size = EXT3_I(inode)->i_data[0];
327                 if (old_size != 0) {
328                         LASSERT(old_size < sizeof(EXT3_I(inode)->i_data));
329                         CERROR("setting EA on %lu again... interesting\n",
330                                inode->i_ino);
331                 }
332
333                 EXT3_I(inode)->i_data[0] = cpu_to_le32(lmm_size);
334                 memcpy(&EXT3_I(inode)->i_data[1], lmm, lmm_size);
335                 mark_inode_dirty(inode);
336                 return 0;
337         } else {
338                 down(&inode->i_sem);
339                 lock_kernel();
340 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
341                 rc = ext3_xattr_set(handle, inode, EXT3_XATTR_INDEX_LUSTRE,
342                                     XATTR_LUSTRE_MDS_OBJID, lmm, lmm_size, 0);
343 #else
344                 rc = ext3_xattr_set_handle(handle, inode, 
345                                            EXT3_XATTR_INDEX_LUSTRE,
346                                            XATTR_LUSTRE_MDS_OBJID, lmm, 
347                                            lmm_size, 0);
348 #endif
349                 unlock_kernel();
350                 up(&inode->i_sem);
351         }
352
353         if (rc)
354                 CERROR("error adding MD data to inode %lu: rc = %d\n",
355                        inode->i_ino, rc);
356         return rc;
357 }
358
359 static int fsfilt_ext3_get_md(struct inode *inode, void *lmm, int lmm_size)
360 {
361         int rc;
362
363         if (inode->i_blocks == 0 && EXT3_I(inode)->i_data[0]) {
364                 int size = le32_to_cpu(EXT3_I(inode)->i_data[0]);
365                 LASSERT(size < sizeof(EXT3_I(inode)->i_data));
366                 if (lmm) {
367                         if (size > lmm_size)
368                                 return -ERANGE;
369                         memcpy(lmm, &EXT3_I(inode)->i_data[1], size);
370                 }
371                 return size;
372         }
373
374         down(&inode->i_sem);
375         lock_kernel();
376         rc = ext3_xattr_get(inode, EXT3_XATTR_INDEX_LUSTRE,
377                             XATTR_LUSTRE_MDS_OBJID, lmm, lmm_size);
378         unlock_kernel();
379         up(&inode->i_sem);
380
381         /* This gives us the MD size */
382         if (lmm == NULL)
383                 return (rc == -ENODATA) ? 0 : rc;
384
385         if (rc < 0) {
386                 CDEBUG(D_INFO, "error getting EA %s from inode %lu: "
387                        "rc = %d\n", XATTR_LUSTRE_MDS_OBJID, inode->i_ino, rc);
388                 memset(lmm, 0, lmm_size);
389                 return (rc == -ENODATA) ? 0 : rc;
390         }
391
392         return rc;
393 }
394
395 static ssize_t fsfilt_ext3_readpage(struct file *file, char *buf, size_t count,
396                                     loff_t *off)
397 {
398         struct inode *inode = file->f_dentry->d_inode;
399         int rc = 0;
400
401         if (S_ISREG(inode->i_mode))
402                 rc = file->f_op->read(file, buf, count, off);
403         else {
404                 const int blkbits = inode->i_sb->s_blocksize_bits;
405                 const int blksize = inode->i_sb->s_blocksize;
406
407                 CDEBUG(D_EXT2, "reading "LPSZ" at dir %lu+%llu\n",
408                        count, inode->i_ino, *off);
409                 while (count > 0) {
410                         struct buffer_head *bh;
411
412                         bh = NULL;
413                         if (*off < inode->i_size) {
414                                 int err = 0;
415
416                                 bh = ext3_bread(NULL, inode, *off >> blkbits,
417                                                 0, &err);
418
419                                 CDEBUG(D_EXT2, "read %u@%llu\n", blksize, *off);
420
421                                 if (bh) {
422                                         memcpy(buf, bh->b_data, blksize);
423                                         brelse(bh);
424                                 } else if (err) {
425                                         /* XXX in theory we should just fake
426                                          * this buffer and continue like ext3,
427                                          * especially if this is a partial read
428                                          */
429                                         CERROR("error read dir %lu+%llu: %d\n",
430                                                inode->i_ino, *off, err);
431                                         RETURN(err);
432                                 }
433                         }
434                         if (!bh) {
435                                 struct ext3_dir_entry_2 *fake = (void *)buf;
436
437                                 CDEBUG(D_EXT2, "fake %u@%llu\n", blksize, *off);
438                                 memset(fake, 0, sizeof(*fake));
439                                 fake->rec_len = cpu_to_le32(blksize);
440                         }
441                         count -= blksize;
442                         buf += blksize;
443                         *off += blksize;
444                         rc += blksize;
445                 }
446         }
447
448         return rc;
449 }
450
451 static void fsfilt_ext3_cb_func(struct journal_callback *jcb, int error)
452 {
453         struct fsfilt_cb_data *fcb = (struct fsfilt_cb_data *)jcb;
454
455         fcb->cb_func(fcb->cb_obd, fcb->cb_last_rcvd, fcb->cb_data, error);
456
457         OBD_SLAB_FREE(fcb, fcb_cache, sizeof *fcb);
458         atomic_dec(&fcb_cache_count);
459 }
460
461 static int fsfilt_ext3_set_last_rcvd(struct obd_device *obd, __u64 last_rcvd,
462                                      void *handle, fsfilt_cb_t cb_func,
463                                      void *cb_data)
464 {
465         struct fsfilt_cb_data *fcb;
466
467         OBD_SLAB_ALLOC(fcb, fcb_cache, GFP_NOFS, sizeof *fcb);
468         if (fcb == NULL)
469                 RETURN(-ENOMEM);
470
471         atomic_inc(&fcb_cache_count);
472         fcb->cb_func = cb_func;
473         fcb->cb_obd = obd;
474         fcb->cb_last_rcvd = last_rcvd;
475         fcb->cb_data = cb_data;
476
477         CDEBUG(D_EXT2, "set callback for last_rcvd: "LPD64"\n", last_rcvd);
478         lock_kernel();
479         journal_callback_set(handle, fsfilt_ext3_cb_func,
480                              (struct journal_callback *)fcb);
481         unlock_kernel();
482
483         return 0;
484 }
485
486 static int fsfilt_ext3_journal_data(struct file *filp)
487 {
488 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
489         /* bug 1576: enable data journaling on 2.5 when appropriate */
490         struct inode *inode = filp->f_dentry->d_inode;
491         EXT3_I(inode)->i_flags |= EXT3_JOURNAL_DATA_FL;
492 #endif
493         return 0;
494 }
495
496 /*
497  * We need to hack the return value for the free inode counts because
498  * the current EA code requires one filesystem block per inode with EAs,
499  * so it is possible to run out of blocks before we run out of inodes.
500  *
501  * This can be removed when the ext3 EA code is fixed.
502  */
503 static int fsfilt_ext3_statfs(struct super_block *sb, struct obd_statfs *osfs)
504 {
505         struct kstatfs sfs;
506         int rc = vfs_statfs(sb, &sfs);
507
508         if (!rc && sfs.f_bfree < sfs.f_ffree) {
509                 sfs.f_files = (sfs.f_files - sfs.f_ffree) + sfs.f_bfree;
510                 sfs.f_ffree = sfs.f_bfree;
511         }
512
513         statfs_pack(osfs, &sfs);
514         return rc;
515 }
516
517 static int fsfilt_ext3_sync(struct super_block *sb)
518 {
519         return ext3_force_commit(sb);
520 }
521
522 extern int ext3_prep_san_write(struct inode *inode, long *blocks,
523                                int nblocks, loff_t newsize);
524 static int fsfilt_ext3_prep_san_write(struct inode *inode, long *blocks,
525                                       int nblocks, loff_t newsize)
526 {
527         return ext3_prep_san_write(inode, blocks, nblocks, newsize);
528 }
529
530 static int fsfilt_ext3_read_record(struct file * file, void *buf,
531                                    int size, loff_t *offs)
532 {
533         struct buffer_head *bh;
534         unsigned long block, boffs;
535         struct inode *inode = file->f_dentry->d_inode;
536         int err;
537
538         if (inode->i_size < *offs + size) {
539                 CERROR("file size %llu is too short for read %u@%llu\n",
540                        inode->i_size, size, *offs);
541                 return -EIO;
542         }
543
544         block = *offs >> inode->i_blkbits;
545         bh = ext3_bread(NULL, inode, block, 0, &err);
546         if (!bh) {
547                 CERROR("can't read block: %d\n", err);
548                 return err;
549         }
550
551         boffs = (unsigned)*offs % bh->b_size;
552         if (boffs + size > bh->b_size) {
553                 CERROR("request crosses block's border. offset %llu, size %u\n",
554                        *offs, size);
555                 brelse(bh);
556                 return -EIO;
557         }
558
559         memcpy(buf, bh->b_data + boffs, size);
560         brelse(bh);
561         *offs += size;
562         return size;
563 }
564
565 static int fsfilt_ext3_write_record(struct file * file, void *buf,
566                                     int size, loff_t *offs)
567 {
568         struct buffer_head *bh;
569         unsigned long block, boffs;
570         struct inode *inode = file->f_dentry->d_inode;
571         loff_t old_size = inode->i_size;
572         journal_t *journal;
573         handle_t *handle;
574         int err;
575
576         journal = EXT3_SB(inode->i_sb)->s_journal;
577         handle = journal_start(journal, EXT3_DATA_TRANS_BLOCKS + 2);
578         if (handle == NULL) {
579                 CERROR("can't start transaction\n");
580                 return -EIO;
581         }
582
583         block = *offs >> inode->i_blkbits;
584         if (*offs + size > inode->i_size) {
585                 down(&inode->i_sem);
586                 if (*offs + size > inode->i_size)
587                         inode->i_size = ((loff_t)block + 1) << inode->i_blkbits;
588                 up(&inode->i_sem);
589         }
590
591         bh = ext3_bread(handle, inode, block, 1, &err);
592         if (!bh) {
593                 CERROR("can't read/create block: %d\n", err);
594                 goto out;
595         }
596
597         /* This is a hack only needed because ext3_get_block_handle() updates
598          * i_disksize after marking the inode dirty in ext3_splice_branch().
599          * We will fix that when we get a chance, as ext3_mark_inode_dirty()
600          * is not without cost, nor is it even exported.
601          */
602         if (inode->i_size > old_size)
603                 mark_inode_dirty(inode);
604
605         boffs = (unsigned)*offs % bh->b_size;
606         if (boffs + size > bh->b_size) {
607                 CERROR("request crosses block's border. offset %llu, size %u\n",
608                        *offs, size);
609                 err = -EIO;
610                 goto out;
611         }
612
613         err = ext3_journal_get_write_access(handle, bh);
614         if (err) {
615                 CERROR("journal_get_write_access() returned error %d\n", err);
616                 goto out;
617         }
618         memcpy(bh->b_data + boffs, buf, size);
619         err = ext3_journal_dirty_metadata(handle, bh);
620         if (err) {
621                 CERROR("journal_dirty_metadata() returned error %d\n", err);
622                 goto out;
623         }
624         err = size;
625 out:
626         if (bh)
627                 brelse(bh);
628         journal_stop(handle);
629         if (err > 0)
630                 *offs += size;
631         return err;
632 }
633
634 static struct fsfilt_operations fsfilt_ext3_ops = {
635         fs_type:                "ext3",
636         fs_owner:               THIS_MODULE,
637         fs_start:               fsfilt_ext3_start,
638         fs_brw_start:           fsfilt_ext3_brw_start,
639         fs_commit:              fsfilt_ext3_commit,
640         fs_setattr:             fsfilt_ext3_setattr,
641         fs_set_md:              fsfilt_ext3_set_md,
642         fs_get_md:              fsfilt_ext3_get_md,
643         fs_readpage:            fsfilt_ext3_readpage,
644         fs_journal_data:        fsfilt_ext3_journal_data,
645         fs_set_last_rcvd:       fsfilt_ext3_set_last_rcvd,
646         fs_statfs:              fsfilt_ext3_statfs,
647         fs_sync:                fsfilt_ext3_sync,
648         fs_prep_san_write:      fsfilt_ext3_prep_san_write,
649         fs_write_record:        fsfilt_ext3_write_record,
650         fs_read_record:         fsfilt_ext3_read_record,
651 };
652
653 static int __init fsfilt_ext3_init(void)
654 {
655         int rc;
656
657         //rc = ext3_xattr_register();
658         fcb_cache = kmem_cache_create("fsfilt_ext3_fcb",
659                                       sizeof(struct fsfilt_cb_data), 0,
660                                       0, NULL, NULL);
661         if (!fcb_cache) {
662                 CERROR("error allocating fsfilt journal callback cache\n");
663                 GOTO(out, rc = -ENOMEM);
664         }
665
666         rc = fsfilt_register_ops(&fsfilt_ext3_ops);
667
668         if (rc)
669                 kmem_cache_destroy(fcb_cache);
670 out:
671         return rc;
672 }
673
674 static void __exit fsfilt_ext3_exit(void)
675 {
676         int rc;
677
678         fsfilt_unregister_ops(&fsfilt_ext3_ops);
679         rc = kmem_cache_destroy(fcb_cache);
680
681         if (rc || atomic_read(&fcb_cache_count)) {
682                 CERROR("can't free fsfilt callback cache: count %d, rc = %d\n",
683                        atomic_read(&fcb_cache_count), rc);
684         }
685
686         //rc = ext3_xattr_unregister();
687 }
688
689 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
690 MODULE_DESCRIPTION("Lustre ext3 Filesystem Helper v0.1");
691 MODULE_LICENSE("GPL");
692
693 module_init(fsfilt_ext3_init);
694 module_exit(fsfilt_ext3_exit);