4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/lvfs/fsfilt_ext3.c
38 * Author: Andreas Dilger <adilger@clusterfs.com>
41 #define DEBUG_SUBSYSTEM S_FILTER
43 #include <linux/init.h>
44 #include <linux/module.h>
46 #include <linux/slab.h>
47 #include <linux/pagemap.h>
48 #include <linux/quotaops.h>
49 #ifdef HAVE_LINUX_EXPORTFS_H
50 #include <linux/exportfs.h>
52 #include <ext4/ext4.h>
53 #include <ext4/ext4_jbd2.h>
54 #include <linux/version.h>
55 #include <linux/bitops.h>
56 #include <linux/quota.h>
58 #if defined(HAVE_EXT3_XATTR_H)
59 # include <ext3/xattr.h>
60 #elif !defined(EXT3_XATTR_INDEX_TRUSTED)
61 /* ext3 xattr.h not available in rh style kernel-devel rpm */
62 /* CHAOS kernel-devel package will not include fs/ldiskfs/xattr.h */
63 # define EXT3_XATTR_INDEX_TRUSTED 4
64 extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
65 extern int ext3_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
68 #include <libcfs/libcfs.h>
69 #include <lustre_fsfilt.h>
71 #include <linux/lustre_compat25.h>
72 #include <linux/lprocfs_status.h>
74 #include <ext4/ext4_extents.h>
76 /* for kernels 2.6.18 and later */
77 #define FSFILT_SINGLEDATA_TRANS_BLOCKS(sb) EXT3_SINGLEDATA_TRANS_BLOCKS(sb)
79 #define fsfilt_ext3_ext_insert_extent(handle, inode, path, newext, flag) \
80 ext3_ext_insert_extent(handle, inode, path, newext, flag)
82 #define ext3_mb_discard_inode_preallocations(inode) \
83 ext3_discard_preallocations(inode)
85 #define fsfilt_log_start_commit(journal, tid) jbd2_log_start_commit(journal, tid)
86 #define fsfilt_log_wait_commit(journal, tid) jbd2_log_wait_commit(journal, tid)
88 #ifdef HAVE_EXT4_JOURNAL_CALLBACK_ADD
89 # define journal_callback ext4_journal_cb_entry
90 # define fsfilt_journal_callback_set(handle, func, jcb) \
91 ext4_journal_callback_add(handle, func, jcb)
92 #elif defined(HAVE_JBD2_JOURNAL_CALLBACK_SET)
93 # define fsfilt_journal_callback_set(handle, func, jcb) \
94 jbd2_journal_callback_set(handle, func, jcb)
95 #elif defined(HAVE_JOURNAL_CALLBACK_SET)
96 # define fsfilt_journal_callback_set(handle, func, jcb) \
97 journal_callback_set(handle, func, jcb)
99 # error missing journal commit callback
100 #endif /* HAVE_EXT4_JOURNAL_CALLBACK_ADD */
102 static cfs_mem_cache_t *fcb_cache;
104 struct fsfilt_cb_data {
105 struct journal_callback cb_jcb; /* jbd private data - MUST BE FIRST */
106 fsfilt_cb_t cb_func; /* MDS/OBD completion function */
107 struct obd_device *cb_obd; /* MDS/OBD completion device */
108 __u64 cb_last_rcvd; /* MDS/OST last committed operation */
109 void *cb_data; /* MDS/OST completion function data */
112 #ifndef ext3_find_next_bit
113 #define ext3_find_next_bit ext2_find_next_bit
116 #ifndef ext2_find_next_bit
117 #ifdef __LITTLE_ENDIAN
118 #define ext2_find_next_bit(addr, size, off) find_next_bit((unsigned long *)(addr), (size), (off))
120 error "Need implementation of find_next_bit on big-endian systems"
121 #endif /* __LITTLE_ENDIAN */
122 #endif /* !ext2_find_next_le_bit */
124 static char *fsfilt_ext3_get_label(struct super_block *sb)
126 return EXT3_SB(sb)->s_es->s_volume_name;
129 static int fsfilt_ext3_set_label(struct super_block *sb, char *label)
131 /* see e.g. fsfilt_ext3_write_record() */
136 journal = EXT3_SB(sb)->s_journal;
137 handle = ext3_journal_start_sb(sb, 1);
138 if (IS_ERR(handle)) {
139 CERROR("can't start transaction\n");
140 return(PTR_ERR(handle));
143 err = ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
147 memcpy(EXT3_SB(sb)->s_es->s_volume_name, label,
148 sizeof(EXT3_SB(sb)->s_es->s_volume_name));
150 err = ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
153 ext3_journal_stop(handle);
158 static char *fsfilt_ext3_uuid(struct super_block *sb)
160 return EXT3_SB(sb)->s_es->s_uuid;
163 #ifdef HAVE_DISK_INODE_VERSION
165 static __u64 get_i_version(struct inode *inode)
167 return EXT3_I(inode)->i_fs_version;
170 static void set_i_version(struct inode *inode, __u64 new_version)
172 (EXT3_I(inode))->i_fs_version = new_version;
176 * Get the 64-bit version for an inode.
178 static __u64 fsfilt_ext3_get_version(struct inode *inode)
180 CDEBUG(D_INFO, "Get version "LPX64" for inode %lu\n",
181 get_i_version(inode), inode->i_ino);
182 return get_i_version(inode);
186 * Set the 64-bit version and return the old version.
188 static __u64 fsfilt_ext3_set_version(struct inode *inode, __u64 new_version)
190 __u64 old_version = get_i_version(inode);
192 CDEBUG(D_INFO, "Set version "LPX64" (old "LPX64") for inode %lu\n",
193 new_version, old_version, inode->i_ino);
194 set_i_version(inode, new_version);
195 /* version is set after all inode operations are finished, so we should
196 * mark it dirty here */
197 inode->i_sb->s_op->dirty_inode(inode);
203 /* kernel has ext4_blocks_for_truncate since linux-3.1.1 */
204 #ifdef HAVE_BLOCKS_FOR_TRUNCATE
205 # include <ext4/truncate.h>
207 static inline unsigned long ext4_blocks_for_truncate(struct inode *inode)
211 needed = inode->i_blocks >> (inode->i_sb->s_blocksize_bits - 9);
214 if (needed > EXT4_MAX_TRANS_DATA)
215 needed = EXT4_MAX_TRANS_DATA;
216 return EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + needed;
221 * We don't currently need any additional blocks for rmdir and
222 * unlink transactions because we are storing the OST oa_id inside
223 * the inode (which we will be changing anyways as part of this
226 static void *fsfilt_ext3_start(struct inode *inode, int op, void *desc_private,
229 /* For updates to the last received file */
230 int nblocks = FSFILT_SINGLEDATA_TRANS_BLOCKS(inode->i_sb);
234 if (current->journal_info) {
235 CDEBUG(D_INODE, "increasing refcount on %p\n",
236 current->journal_info);
241 case FSFILT_OP_RMDIR:
242 case FSFILT_OP_UNLINK:
243 /* delete one file + create/update logs for each stripe */
244 nblocks += EXT3_DELETE_TRANS_BLOCKS(inode->i_sb);
245 nblocks += (EXT3_INDEX_EXTRA_TRANS_BLOCKS +
246 FSFILT_SINGLEDATA_TRANS_BLOCKS(inode->i_sb)) * logs;
248 case FSFILT_OP_RENAME:
249 /* modify additional directory */
250 nblocks += FSFILT_SINGLEDATA_TRANS_BLOCKS(inode->i_sb);
252 case FSFILT_OP_SYMLINK:
253 /* additional block + block bitmap + GDT for long symlink */
256 case FSFILT_OP_CREATE: {
259 case FSFILT_OP_MKDIR:
260 case FSFILT_OP_MKNOD:
261 /* modify one inode + block bitmap + GDT */
265 /* modify parent directory */
266 nblocks += EXT3_INDEX_EXTRA_TRANS_BLOCKS +
267 EXT3_DATA_TRANS_BLOCKS(inode->i_sb);
268 /* create/update logs for each stripe */
269 nblocks += (EXT3_INDEX_EXTRA_TRANS_BLOCKS +
270 FSFILT_SINGLEDATA_TRANS_BLOCKS(inode->i_sb)) * logs;
272 case FSFILT_OP_SETATTR:
273 /* Setattr on inode */
275 nblocks += EXT3_INDEX_EXTRA_TRANS_BLOCKS +
276 EXT3_DATA_TRANS_BLOCKS(inode->i_sb);
277 /* quota chown log for each stripe */
278 nblocks += (EXT3_INDEX_EXTRA_TRANS_BLOCKS +
279 FSFILT_SINGLEDATA_TRANS_BLOCKS(inode->i_sb)) * logs;
281 case FSFILT_OP_CANCEL_UNLINK:
284 /* blocks for log header bitmap update OR
285 * blocks for catalog header bitmap update + unlink of logs +
286 * blocks for delete the inode (include blocks truncating). */
287 nblocks = (LLOG_CHUNK_SIZE >> inode->i_blkbits) +
288 EXT3_DELETE_TRANS_BLOCKS(inode->i_sb) +
289 ext4_blocks_for_truncate(inode) + 3;
291 default: CERROR("unknown transaction start op %d\n", op);
295 LASSERT(current->journal_info == desc_private);
296 journal = EXT3_SB(inode->i_sb)->s_journal;
297 if (nblocks > journal->j_max_transaction_buffers) {
298 CWARN("too many credits %d for op %ux%u using %d instead\n",
299 nblocks, op, logs, journal->j_max_transaction_buffers);
300 nblocks = journal->j_max_transaction_buffers;
304 LASSERTF(nblocks > 0, "can't start %d credit transaction\n", nblocks);
305 handle = ext3_journal_start(inode, nblocks);
308 LASSERT(current->journal_info == handle);
310 CERROR("error starting handle for op %u (%u credits): rc %ld\n",
311 op, nblocks, PTR_ERR(handle));
316 * Calculate the number of buffer credits needed to write multiple pages in
317 * a single ext3 transaction. No, this shouldn't be here, but as yet ext3
318 * doesn't have a nice API for calculating this sort of thing in advance.
320 * See comment above ext3_writepage_trans_blocks for details. We assume
321 * no data journaling is being done, but it does allow for all of the pages
322 * being non-contiguous. If we are guaranteed contiguous pages we could
323 * reduce the number of (d)indirect blocks a lot.
325 * With N blocks per page and P pages, for each inode we have at most:
327 * min(N*P, blocksize/4 + 1) dindirect blocks
330 * For the entire filesystem, we have at most:
331 * min(sum(nindir + P), ngroups) bitmap blocks (from the above)
332 * min(sum(nindir + P), gdblocks) group descriptor blocks (from the above)
333 * objcount inode blocks
335 * 2 * EXT3_SINGLEDATA_TRANS_BLOCKS for the quota files
337 * 1 EXT3_DATA_TRANS_BLOCKS for the last_rcvd update.
339 static int fsfilt_ext3_credits_needed(int objcount, struct fsfilt_objinfo *fso,
340 int niocount, struct niobuf_local *nb)
342 struct super_block *sb = fso->fso_dentry->d_inode->i_sb;
344 const int blockpp = 1 << (CFS_PAGE_SHIFT - sb->s_blocksize_bits);
345 int nbitmaps = 0, ngdblocks;
346 int needed = objcount + 1; /* inodes + superblock */
349 for (i = 0, j = 0; i < objcount; i++, fso++) {
350 /* two or more dindirect blocks in case we cross boundary */
352 (long)((nb[j + fso->fso_bufcnt - 1].lnb_file_offset -
353 nb[j].lnb_file_offset) >>
354 sb->s_blocksize_bits) /
355 (EXT3_ADDR_PER_BLOCK(sb) * EXT3_ADDR_PER_BLOCK(sb));
356 nbitmaps += min(fso->fso_bufcnt, ndind > 0 ? ndind : 2);
358 /* leaf, indirect, tindirect blocks for first block */
359 nbitmaps += blockpp + 2;
361 j += fso->fso_bufcnt;
364 next_indir = nb[0].lnb_file_offset +
365 (EXT3_ADDR_PER_BLOCK(sb) << sb->s_blocksize_bits);
366 for (i = 1; i < niocount; i++) {
367 if (nb[i].lnb_file_offset >= next_indir) {
368 nbitmaps++; /* additional indirect */
369 next_indir = nb[i].lnb_file_offset +
370 (EXT3_ADDR_PER_BLOCK(sb) <<
371 sb->s_blocksize_bits);
372 } else if (nb[i].lnb_file_offset !=
373 nb[i - 1].lnb_file_offset + sb->s_blocksize) {
374 nbitmaps++; /* additional indirect */
376 nbitmaps += blockpp; /* each leaf in different group? */
379 ngdblocks = nbitmaps;
380 if (nbitmaps > EXT3_SB(sb)->s_groups_count)
381 nbitmaps = EXT3_SB(sb)->s_groups_count;
382 if (ngdblocks > EXT3_SB(sb)->s_gdb_count)
383 ngdblocks = EXT3_SB(sb)->s_gdb_count;
385 needed += nbitmaps + ngdblocks;
387 /* last_rcvd update */
388 needed += EXT3_DATA_TRANS_BLOCKS(sb);
390 #if defined(CONFIG_QUOTA)
391 /* We assume that there will be 1 bit set in s_dquot.flags for each
392 * quota file that is active. This is at least true for now.
394 needed += hweight32(sb_any_quota_loaded(sb)) *
395 FSFILT_SINGLEDATA_TRANS_BLOCKS(sb);
401 /* We have to start a huge journal transaction here to hold all of the
402 * metadata for the pages being written here. This is necessitated by
403 * the fact that we do lots of prepare_write operations before we do
404 * any of the matching commit_write operations, so even if we split
405 * up to use "smaller" transactions none of them could complete until
406 * all of them were opened. By having a single journal transaction,
407 * we eliminate duplicate reservations for common blocks like the
408 * superblock and group descriptors or bitmaps.
410 * We will start the transaction here, but each prepare_write will
411 * add a refcount to the transaction, and each commit_write will
412 * remove a refcount. The transaction will be closed when all of
413 * the pages have been written.
415 static void *fsfilt_ext3_brw_start(int objcount, struct fsfilt_objinfo *fso,
416 int niocount, struct niobuf_local *nb,
417 void *desc_private, int logs)
424 LASSERT(current->journal_info == desc_private);
425 journal = EXT3_SB(fso->fso_dentry->d_inode->i_sb)->s_journal;
426 needed = fsfilt_ext3_credits_needed(objcount, fso, niocount, nb);
428 /* The number of blocks we could _possibly_ dirty can very large.
429 * We reduce our request if it is absurd (and we couldn't get that
430 * many credits for a single handle anyways).
432 * At some point we have to limit the size of I/Os sent at one time,
433 * increase the size of the journal, or we have to calculate the
434 * actual journal requirements more carefully by checking all of
435 * the blocks instead of being maximally pessimistic. It remains to
436 * be seen if this is a real problem or not.
438 if (needed > journal->j_max_transaction_buffers) {
439 CERROR("want too many journal credits (%d) using %d instead\n",
440 needed, journal->j_max_transaction_buffers);
441 needed = journal->j_max_transaction_buffers;
444 LASSERTF(needed > 0, "can't start %d credit transaction\n", needed);
445 handle = ext3_journal_start(fso->fso_dentry->d_inode, needed);
446 if (IS_ERR(handle)) {
447 CERROR("can't get handle for %d credits: rc = %ld\n", needed,
450 LASSERT(handle->h_buffer_credits >= needed);
451 LASSERT(current->journal_info == handle);
457 static int fsfilt_ext3_extend(struct inode *inode, unsigned int nblocks,void *h)
459 handle_t *handle = h;
461 /* fsfilt_extend called with nblocks = 0 for testing in special cases */
463 handle->h_buffer_credits = 0;
464 CWARN("setting credits of handle %p to zero by request\n", h);
467 if (handle->h_buffer_credits > nblocks)
469 if (ext3_journal_extend(handle, nblocks) == 0)
472 ext3_mark_inode_dirty(handle, inode);
473 return ext3_journal_restart(handle, nblocks);
476 static int fsfilt_ext3_commit(struct inode *inode, void *h, int force_sync)
479 handle_t *handle = h;
481 LASSERT(current->journal_info == handle);
483 handle->h_sync = 1; /* recovery likes this */
485 rc = ext3_journal_stop(handle);
490 static int fsfilt_ext3_commit_async(struct inode *inode, void *h,
494 transaction_t *transaction;
495 handle_t *handle = h;
499 LASSERT(current->journal_info == handle);
501 transaction = handle->h_transaction;
502 journal = transaction->t_journal;
503 tid = transaction->t_tid;
504 /* we don't want to be blocked */
506 rc = ext3_journal_stop(handle);
508 CERROR("error while stopping transaction: %d\n", rc);
511 fsfilt_log_start_commit(journal, tid);
513 *wait_handle = (void *) tid;
514 CDEBUG(D_INODE, "commit async: %lu\n", (unsigned long) tid);
518 static int fsfilt_ext3_commit_wait(struct inode *inode, void *h)
520 journal_t *journal = EXT3_JOURNAL(inode);
521 tid_t tid = (tid_t)(long)h;
523 CDEBUG(D_INODE, "commit wait: %lu\n", (unsigned long) tid);
524 if (unlikely(is_journal_aborted(journal)))
527 fsfilt_log_wait_commit(EXT3_JOURNAL(inode), tid);
529 if (unlikely(is_journal_aborted(journal)))
534 static int fsfilt_ext3_setattr(struct dentry *dentry, void *handle,
535 struct iattr *iattr, int do_trunc)
537 struct inode *inode = dentry->d_inode;
540 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
541 /* Try to correct for a bug in 2.1.0 (LU-221) that caused negative
542 * timestamps to appear to be in the far future, due old timestamp
543 * being stored on disk as an unsigned value. This fixes up any
544 * bad values held by the client before storing them on disk,
545 * and ensures any timestamp updates are correct. LU-1042 */
546 if (unlikely(LTIME_S(inode->i_atime) == LU221_BAD_TIME &&
547 !(iattr->ia_valid & ATTR_ATIME))) {
548 iattr->ia_valid |= ATTR_ATIME;
549 LTIME_S(iattr->ia_atime) = 0;
551 if (unlikely(LTIME_S(inode->i_mtime) == LU221_BAD_TIME &&
552 !(iattr->ia_valid & ATTR_MTIME))) {
553 iattr->ia_valid |= ATTR_MTIME;
554 LTIME_S(iattr->ia_mtime) = 0;
556 if (unlikely((LTIME_S(inode->i_ctime) == LU221_BAD_TIME ||
557 LTIME_S(inode->i_ctime) == 0) &&
558 !(iattr->ia_valid & ATTR_CTIME))) {
559 iattr->ia_valid |= ATTR_CTIME;
560 LTIME_S(iattr->ia_ctime) = 0;
563 #warning "remove old LU-221/LU-1042 workaround code"
566 /* When initializating timestamps for new inodes, use the filesystem
567 * mkfs time for ctime to avoid e2fsck ibadness incorrectly thinking
568 * that this is potentially an invalid inode. Files with an old ctime
569 * migrated to a newly-formatted OST with a newer s_mkfs_time will not
570 * hit this check, since it is only for ctime == 0. LU-1010/LU-1042 */
571 if ((iattr->ia_valid & ATTR_CTIME) && LTIME_S(iattr->ia_ctime) == 0)
572 LTIME_S(iattr->ia_ctime) =
573 EXT4_SB(inode->i_sb)->s_es->s_mkfs_time;
575 /* Avoid marking the inode dirty on the superblock list unnecessarily.
576 * We are already writing the inode to disk as part of this
577 * transaction and want to avoid a lot of extra inode writeout
578 * later on. b=9828 */
579 if (iattr->ia_valid & ATTR_SIZE && !do_trunc) {
580 /* ATTR_SIZE would invoke truncate: clear it */
581 iattr->ia_valid &= ~ATTR_SIZE;
582 EXT3_I(inode)->i_disksize = iattr->ia_size;
583 i_size_write(inode, iattr->ia_size);
585 if (iattr->ia_valid & ATTR_UID)
586 inode->i_uid = iattr->ia_uid;
587 if (iattr->ia_valid & ATTR_GID)
588 inode->i_gid = iattr->ia_gid;
589 if (iattr->ia_valid & ATTR_ATIME)
590 inode->i_atime = iattr->ia_atime;
591 if (iattr->ia_valid & ATTR_MTIME)
592 inode->i_mtime = iattr->ia_mtime;
593 if (iattr->ia_valid & ATTR_CTIME)
594 inode->i_ctime = iattr->ia_ctime;
595 if (iattr->ia_valid & ATTR_MODE) {
596 inode->i_mode = iattr->ia_mode;
598 if (!cfs_curproc_is_in_groups(inode->i_gid) &&
599 !cfs_capable(CFS_CAP_FSETID))
600 inode->i_mode &= ~S_ISGID;
603 inode->i_sb->s_op->dirty_inode(inode);
608 /* Don't allow setattr to change file type */
609 if (iattr->ia_valid & ATTR_MODE)
610 iattr->ia_mode = (inode->i_mode & S_IFMT) |
611 (iattr->ia_mode & ~S_IFMT);
613 /* We set these flags on the client, but have already checked perms
614 * so don't confuse inode_change_ok. */
615 iattr->ia_valid &= ~TIMES_SET_FLAGS;
617 if (inode->i_op->setattr) {
618 rc = inode->i_op->setattr(dentry, iattr);
620 #ifndef HAVE_SIMPLE_SETATTR /* simple_setattr() already call it */
621 rc = inode_change_ok(inode, iattr);
624 rc = simple_setattr(dentry, iattr);
631 static int fsfilt_ext3_iocontrol(struct inode *inode, struct file *file,
632 unsigned int cmd, unsigned long arg)
637 /* FIXME: Can't do this because of nested transaction deadlock */
638 if (cmd == EXT3_IOC_SETFLAGS) {
639 /* We can't enable data journaling on OST objects, because
640 * this forces the transaction to be closed in order to
641 * flush the journal, but the caller will already have a
642 * compound transaction open to update the last_rcvd file,
643 * and this thread would deadlock trying to set the flag. */
644 if ((*(int *)arg) & EXT3_JOURNAL_DATA_FL) {
645 CERROR("can't set data journal flag on file\n");
648 /* Because the MDS does not see the EXTENTS_FL set on the
649 * OST objects, mask this flag into all set flags. It is
650 * not legal to clear this flag in any case, so we are not
651 * changing the functionality by doing this. b=22911 */
652 *(int *)arg |= EXT3_I(inode)->i_flags & EXT3_EXTENTS_FL;
655 /* ext4_ioctl does not have a inode argument */
656 if (inode->i_fop->unlocked_ioctl)
657 rc = inode->i_fop->unlocked_ioctl(file, cmd, arg);
664 static int fsfilt_ext3_set_md(struct inode *inode, void *handle,
665 void *lmm, int lmm_size, const char *name)
669 LASSERT(mutex_trylock(&inode->i_mutex) == 0);
671 rc = ext3_xattr_set_handle(handle, inode, EXT3_XATTR_INDEX_TRUSTED,
672 name, lmm, lmm_size, XATTR_NO_CTIME);
674 if (rc && rc != -EROFS)
675 CERROR("error adding MD data to inode %lu: rc = %d\n",
680 /* Must be called with i_mutex held */
681 static int fsfilt_ext3_get_md(struct inode *inode, void *lmm, int lmm_size,
686 LASSERT(mutex_trylock(&inode->i_mutex) == 0);
688 rc = ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED,
689 name, lmm, lmm_size);
691 /* This gives us the MD size */
693 return (rc == -ENODATA) ? 0 : rc;
696 CDEBUG(D_INFO, "error getting EA %d/%s from inode %lu: rc %d\n",
697 EXT3_XATTR_INDEX_TRUSTED, name,
699 memset(lmm, 0, lmm_size);
700 return (rc == -ENODATA) ? 0 : rc;
706 static int fsfilt_ext3_send_bio(int rw, struct inode *inode, struct bio *bio)
712 static ssize_t fsfilt_ext3_readpage(struct file *file, char *buf, size_t count,
715 struct inode *inode = file->f_dentry->d_inode;
718 if (S_ISREG(inode->i_mode))
719 rc = file->f_op->read(file, buf, count, off);
721 const int blkbits = inode->i_sb->s_blocksize_bits;
722 const int blksize = inode->i_sb->s_blocksize;
724 CDEBUG(D_EXT2, "reading %lu at dir %lu+%llu\n",
725 (unsigned long)count, inode->i_ino, *off);
727 struct buffer_head *bh;
730 if (*off < i_size_read(inode)) {
733 bh = ext3_bread(NULL, inode, *off >> blkbits,
736 CDEBUG(D_EXT2, "read %u@%llu\n", blksize, *off);
739 memcpy(buf, bh->b_data, blksize);
742 /* XXX in theory we should just fake
743 * this buffer and continue like ext3,
744 * especially if this is a partial read
746 CERROR("error read dir %lu+%llu: %d\n",
747 inode->i_ino, *off, err);
752 struct ext3_dir_entry_2 *fake = (void *)buf;
754 CDEBUG(D_EXT2, "fake %u@%llu\n", blksize, *off);
755 memset(fake, 0, sizeof(*fake));
756 fake->rec_len = cpu_to_le16(blksize);
768 #ifdef HAVE_EXT4_JOURNAL_CALLBACK_ADD
769 static void fsfilt_ext3_cb_func(struct super_block *sb,
770 struct journal_callback *jcb, int error)
772 static void fsfilt_ext3_cb_func(struct journal_callback *jcb, int error)
775 struct fsfilt_cb_data *fcb = container_of(jcb, typeof(*fcb), cb_jcb);
777 fcb->cb_func(fcb->cb_obd, fcb->cb_last_rcvd, fcb->cb_data, error);
779 OBD_SLAB_FREE(fcb, fcb_cache, sizeof *fcb);
782 static int fsfilt_ext3_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
783 void *handle, fsfilt_cb_t cb_func,
786 struct fsfilt_cb_data *fcb;
788 OBD_SLAB_ALLOC_PTR_GFP(fcb, fcb_cache, CFS_ALLOC_IO);
792 fcb->cb_func = cb_func;
794 fcb->cb_last_rcvd = last_rcvd;
795 fcb->cb_data = cb_data;
797 CDEBUG(D_EXT2, "set callback for last_rcvd: "LPD64"\n", last_rcvd);
798 fsfilt_journal_callback_set(handle, fsfilt_ext3_cb_func, &fcb->cb_jcb);
803 static int fsfilt_ext3_statfs(struct super_block *sb, struct obd_statfs *osfs)
808 memset(&sfs, 0, sizeof(sfs));
809 rc = sb->s_op->statfs(sb->s_root, &sfs);
810 statfs_pack(osfs, &sfs);
814 static int fsfilt_ext3_sync(struct super_block *sb)
816 return ext3_force_commit(sb);
819 #ifndef EXT3_EXTENTS_FL
820 #define EXT3_EXTENTS_FL 0x00080000 /* Inode uses extents */
824 #define EXT_ASSERT(cond) BUG_ON(!(cond))
827 #define EXT_GENERATION(inode) (EXT4_I(inode)->i_ext_generation)
828 #define ext3_ext_base inode
829 #define ext3_ext_base2inode(inode) (inode)
830 #define EXT_DEPTH(inode) ext_depth(inode)
831 #define fsfilt_ext3_ext_walk_space(inode, block, num, cb, cbdata) \
832 ext3_ext_walk_space(inode, block, num, cb, cbdata);
835 unsigned long *blocks;
843 static long ext3_ext_find_goal(struct inode *inode, struct ext3_ext_path *path,
844 unsigned long block, int *aflags)
846 struct ext3_inode_info *ei = EXT3_I(inode);
847 unsigned long bg_start;
848 unsigned long colour;
852 struct ext3_extent *ex;
853 depth = path->p_depth;
855 /* try to predict block placement */
856 if ((ex = path[depth].p_ext))
857 return ext_pblock(ex) + (block - le32_to_cpu(ex->ee_block));
859 /* it looks index is empty
860 * try to find starting from index itself */
861 if (path[depth].p_bh)
862 return path[depth].p_bh->b_blocknr;
865 /* OK. use inode's group */
866 bg_start = (ei->i_block_group * EXT3_BLOCKS_PER_GROUP(inode->i_sb)) +
867 le32_to_cpu(EXT3_SB(inode->i_sb)->s_es->s_first_data_block);
868 colour = (current->pid % 16) *
869 (EXT3_BLOCKS_PER_GROUP(inode->i_sb) / 16);
870 return bg_start + colour + block;
873 #define ll_unmap_underlying_metadata(sb, blocknr) \
874 unmap_underlying_metadata((sb)->s_bdev, blocknr)
876 #ifndef EXT3_MB_HINT_GROUP_ALLOC
877 static unsigned long new_blocks(handle_t *handle, struct ext3_ext_base *base,
878 struct ext3_ext_path *path, unsigned long block,
879 unsigned long *count, int *err)
881 unsigned long pblock, goal;
883 struct inode *inode = ext3_ext_base2inode(base);
885 goal = ext3_ext_find_goal(inode, path, block, &aflags);
886 aflags |= 2; /* block have been already reserved */
887 pblock = ext3_mb_new_blocks(handle, inode, goal, count, aflags, err);
892 static unsigned long new_blocks(handle_t *handle, struct ext3_ext_base *base,
893 struct ext3_ext_path *path, unsigned long block,
894 unsigned long *count, int *err)
896 struct inode *inode = ext3_ext_base2inode(base);
897 struct ext3_allocation_request ar;
898 unsigned long pblock;
901 /* find neighbour allocated blocks */
903 *err = ext3_ext_search_left(base, path, &ar.lleft, &ar.pleft);
907 *err = ext3_ext_search_right(base, path, &ar.lright, &ar.pright);
911 /* allocate new block */
912 ar.goal = ext3_ext_find_goal(inode, path, block, &aflags);
916 ar.flags = EXT3_MB_HINT_DATA;
917 pblock = ext3_mb_new_blocks(handle, &ar, err);
923 static int ext3_ext_new_extent_cb(struct ext3_ext_base *base,
924 struct ext3_ext_path *path,
925 struct ext3_ext_cache *cex,
926 #ifdef HAVE_EXT_PREPARE_CB_EXTENT
927 struct ext3_extent *ex,
931 struct bpointers *bp = cbdata;
932 struct inode *inode = ext3_ext_base2inode(base);
933 struct ext3_extent nex;
934 unsigned long pblock;
940 if (cex->ec_type == EXT3_EXT_CACHE_EXTENT) {
945 if (bp->create == 0) {
947 if (cex->ec_block < bp->start)
948 i = bp->start - cex->ec_block;
949 if (i >= cex->ec_len)
950 CERROR("nothing to do?! i = %d, e_num = %u\n",
952 for (; i < cex->ec_len && bp->num; i++) {
964 tgen = EXT_GENERATION(base);
965 count = ext3_ext_calc_credits_for_insert(base, path);
967 handle = ext3_journal_start(inode, count+EXT3_ALLOC_NEEDED+1);
968 if (IS_ERR(handle)) {
969 return PTR_ERR(handle);
972 if (tgen != EXT_GENERATION(base)) {
973 /* the tree has changed. so path can be invalid at moment */
974 ext3_journal_stop(handle);
978 /* In 2.6.32 kernel, ext4_ext_walk_space()'s callback func is not
979 * protected by i_data_sem as whole. so we patch it to store
980 * generation to path and now verify the tree hasn't changed */
981 down_write((&EXT4_I(inode)->i_data_sem));
983 /* validate extent, make sure the extent tree does not changed */
984 if (EXT_GENERATION(base) != path[0].p_generation) {
985 /* cex is invalid, try again */
986 up_write(&EXT4_I(inode)->i_data_sem);
987 ext3_journal_stop(handle);
992 pblock = new_blocks(handle, base, path, cex->ec_block, &count, &err);
995 EXT_ASSERT(count <= cex->ec_len);
997 /* insert new extent */
998 nex.ee_block = cpu_to_le32(cex->ec_block);
999 ext3_ext_store_pblock(&nex, pblock);
1000 nex.ee_len = cpu_to_le16(count);
1001 err = fsfilt_ext3_ext_insert_extent(handle, base, path, &nex, 0);
1003 /* free data blocks we just allocated */
1004 /* not a good idea to call discard here directly,
1005 * but otherwise we'd need to call it every free() */
1006 #ifdef EXT3_MB_HINT_GROUP_ALLOC
1007 ext3_mb_discard_inode_preallocations(inode);
1009 ext3_free_blocks(handle, inode, ext_pblock(&nex),
1010 cpu_to_le16(nex.ee_len), 0);
1015 * Putting len of the actual extent we just inserted,
1016 * we are asking ext3_ext_walk_space() to continue
1017 * scaning after that block
1019 cex->ec_len = le16_to_cpu(nex.ee_len);
1020 cex->ec_start = ext_pblock(&nex);
1021 BUG_ON(le16_to_cpu(nex.ee_len) == 0);
1022 BUG_ON(le32_to_cpu(nex.ee_block) != cex->ec_block);
1025 up_write((&EXT4_I(inode)->i_data_sem));
1026 ext3_journal_stop(handle);
1031 CERROR("hmm. why do we find this extent?\n");
1032 CERROR("initial space: %lu:%u\n",
1033 bp->start, bp->init_num);
1034 CERROR("current extent: %u/%u/%llu %d\n",
1035 cex->ec_block, cex->ec_len,
1036 (unsigned long long)cex->ec_start,
1040 if (cex->ec_block < bp->start)
1041 i = bp->start - cex->ec_block;
1042 if (i >= cex->ec_len)
1043 CERROR("nothing to do?! i = %d, e_num = %u\n",
1045 for (; i < cex->ec_len && bp->num; i++) {
1046 *(bp->blocks) = cex->ec_start + i;
1047 if (cex->ec_type == EXT3_EXT_CACHE_EXTENT) {
1051 /* unmap any possible underlying metadata from
1052 * the block device mapping. bug 6998. */
1053 ll_unmap_underlying_metadata(inode->i_sb,
1065 int fsfilt_map_nblocks(struct inode *inode, unsigned long block,
1066 unsigned long num, unsigned long *blocks,
1067 int *created, int create)
1069 struct ext3_ext_base *base = inode;
1070 struct bpointers bp;
1073 CDEBUG(D_OTHER, "blocks %lu-%lu requested for inode %u\n",
1074 block, block + num - 1, (unsigned) inode->i_ino);
1077 bp.created = created;
1079 bp.init_num = bp.num = num;
1082 err = fsfilt_ext3_ext_walk_space(base, block, num,
1083 ext3_ext_new_extent_cb, &bp);
1084 ext3_ext_invalidate_cache(base);
1089 int fsfilt_ext3_map_ext_inode_pages(struct inode *inode, struct page **page,
1090 int pages, unsigned long *blocks,
1091 int *created, int create)
1093 int blocks_per_page = CFS_PAGE_SIZE >> inode->i_blkbits;
1095 struct page *fp = NULL;
1098 CDEBUG(D_OTHER, "inode %lu: map %d pages from %lu\n",
1099 inode->i_ino, pages, (*page)->index);
1101 /* pages are sorted already. so, we just have to find
1102 * contig. space and process them properly */
1105 /* start new extent */
1110 } else if (fp->index + clen == (*page)->index) {
1111 /* continue the extent */
1118 /* process found extent */
1119 rc = fsfilt_map_nblocks(inode, fp->index * blocks_per_page,
1120 clen * blocks_per_page, blocks,
1125 /* look for next extent */
1127 blocks += blocks_per_page * clen;
1128 created += blocks_per_page * clen;
1132 rc = fsfilt_map_nblocks(inode, fp->index * blocks_per_page,
1133 clen * blocks_per_page, blocks,
1139 extern int ext3_map_inode_page(struct inode *inode, struct page *page,
1140 unsigned long *blocks, int *created, int create);
1141 int fsfilt_ext3_map_bm_inode_pages(struct inode *inode, struct page **page,
1142 int pages, unsigned long *blocks,
1143 int *created, int create)
1145 int blocks_per_page = CFS_PAGE_SIZE >> inode->i_blkbits;
1149 for (i = 0, cr = created, b = blocks; i < pages; i++, page++) {
1150 rc = ext3_map_inode_page(inode, *page, b, cr, create);
1152 CERROR("ino %lu, blk %lu cr %u create %d: rc %d\n",
1153 inode->i_ino, *b, *cr, create, rc);
1157 b += blocks_per_page;
1158 cr += blocks_per_page;
1163 int fsfilt_ext3_map_inode_pages(struct inode *inode, struct page **page,
1164 int pages, unsigned long *blocks,
1165 int *created, int create,
1166 cfs_mutex_t *optional_mutex)
1170 if (EXT3_I(inode)->i_flags & EXT3_EXTENTS_FL) {
1171 rc = fsfilt_ext3_map_ext_inode_pages(inode, page, pages,
1172 blocks, created, create);
1175 if (optional_mutex != NULL)
1176 cfs_mutex_lock(optional_mutex);
1177 rc = fsfilt_ext3_map_bm_inode_pages(inode, page, pages, blocks,
1179 if (optional_mutex != NULL)
1180 cfs_mutex_unlock(optional_mutex);
1185 int fsfilt_ext3_read(struct inode *inode, void *buf, int size, loff_t *offs)
1187 unsigned long block;
1188 struct buffer_head *bh;
1189 int err, blocksize, csize, boffs, osize = size;
1191 /* prevent reading after eof */
1192 spin_lock(&inode->i_lock);
1193 if (i_size_read(inode) < *offs + size) {
1194 size = i_size_read(inode) - *offs;
1195 spin_unlock(&inode->i_lock);
1197 CDEBUG(D_EXT2, "size %llu is too short for read @%llu\n",
1198 i_size_read(inode), *offs);
1200 } else if (size == 0) {
1204 spin_unlock(&inode->i_lock);
1207 blocksize = 1 << inode->i_blkbits;
1210 block = *offs >> inode->i_blkbits;
1211 boffs = *offs & (blocksize - 1);
1212 csize = min(blocksize - boffs, size);
1213 bh = ext3_bread(NULL, inode, block, 0, &err);
1215 CERROR("can't read block: %d\n", err);
1219 memcpy(buf, bh->b_data + boffs, csize);
1228 EXPORT_SYMBOL(fsfilt_ext3_read);
1230 static int fsfilt_ext3_read_record(struct file * file, void *buf,
1231 int size, loff_t *offs)
1234 rc = fsfilt_ext3_read(file->f_dentry->d_inode, buf, size, offs);
1240 int fsfilt_ext3_write_handle(struct inode *inode, void *buf, int bufsize,
1241 loff_t *offs, handle_t *handle)
1243 struct buffer_head *bh = NULL;
1244 loff_t old_size = i_size_read(inode), offset = *offs;
1245 loff_t new_size = i_size_read(inode);
1246 unsigned long block;
1247 int err = 0, blocksize = 1 << inode->i_blkbits, size, boffs;
1249 while (bufsize > 0) {
1253 block = offset >> inode->i_blkbits;
1254 boffs = offset & (blocksize - 1);
1255 size = min(blocksize - boffs, bufsize);
1256 bh = ext3_bread(handle, inode, block, 1, &err);
1258 CERROR("can't read/create block: %d\n", err);
1262 err = ext3_journal_get_write_access(handle, bh);
1264 CERROR("journal_get_write_access() returned error %d\n",
1268 LASSERT(bh->b_data + boffs + size <= bh->b_data + bh->b_size);
1269 memcpy(bh->b_data + boffs, buf, size);
1270 err = ext3_journal_dirty_metadata(handle, bh);
1272 CERROR("journal_dirty_metadata() returned error %d\n",
1276 if (offset + size > new_size)
1277 new_size = offset + size;
1285 /* correct in-core and on-disk sizes */
1286 if (new_size > i_size_read(inode)) {
1287 spin_lock(&inode->i_lock);
1288 if (new_size > i_size_read(inode))
1289 i_size_write(inode, new_size);
1290 if (i_size_read(inode) > EXT3_I(inode)->i_disksize)
1291 EXT3_I(inode)->i_disksize = i_size_read(inode);
1292 if (i_size_read(inode) > old_size) {
1293 spin_unlock(&inode->i_lock);
1294 mark_inode_dirty(inode);
1296 spin_unlock(&inode->i_lock);
1304 EXPORT_SYMBOL(fsfilt_ext3_write_handle);
1306 static int fsfilt_ext3_write_record(struct file *file, void *buf, int bufsize,
1307 loff_t *offs, int force_sync)
1309 struct inode *inode = file->f_dentry->d_inode;
1311 int err, block_count = 0, blocksize;
1313 /* Determine how many transaction credits are needed */
1314 blocksize = 1 << inode->i_blkbits;
1315 block_count = (*offs & (blocksize - 1)) + bufsize;
1316 block_count = (block_count + blocksize - 1) >> inode->i_blkbits;
1318 handle = ext3_journal_start(inode,
1319 block_count * EXT3_DATA_TRANS_BLOCKS(inode->i_sb) + 2);
1320 if (IS_ERR(handle)) {
1321 CERROR("can't start transaction for %d blocks (%d bytes)\n",
1322 block_count * EXT3_DATA_TRANS_BLOCKS(inode->i_sb) + 2,
1324 return PTR_ERR(handle);
1327 err = fsfilt_ext3_write_handle(inode, buf, bufsize, offs, handle);
1329 if (!err && force_sync)
1330 handle->h_sync = 1; /* recovery likes this */
1332 ext3_journal_stop(handle);
1337 static int fsfilt_ext3_setup(struct super_block *sb)
1339 if (!EXT3_HAS_COMPAT_FEATURE(sb,
1340 EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
1341 CERROR("ext3 mounted without journal\n");
1346 CWARN("Enabling PDIROPS\n");
1347 set_opt(EXT3_SB(sb)->s_mount_opt, PDIROPS);
1348 sb->s_flags |= S_PDIROPS;
1350 if (!EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_DIR_INDEX))
1351 CWARN("filesystem doesn't have dir_index feature enabled\n");
1355 /* If fso is NULL, op is FSFILT operation, otherwise op is number of fso
1356 objects. Logs is number of logfiles to update */
1357 static int fsfilt_ext3_get_op_len(int op, struct fsfilt_objinfo *fso, int logs)
1361 case FSFILT_OP_CREATE:
1362 /* directory leaf, index & indirect & EA*/
1363 return 4 + 3 * logs;
1364 case FSFILT_OP_UNLINK:
1370 struct super_block *sb = fso->fso_dentry->d_inode->i_sb;
1371 int blockpp = 1 << (CFS_PAGE_SHIFT - sb->s_blocksize_bits);
1372 int addrpp = EXT3_ADDR_PER_BLOCK(sb) * blockpp;
1373 for (i = 0; i < op; i++, fso++) {
1374 int nblocks = fso->fso_bufcnt * blockpp;
1375 int ndindirect = min(nblocks, addrpp + 1);
1376 int nindir = nblocks + ndindirect + 1;
1380 return needed + 3 * logs;
1386 lvfs_sbdev_type fsfilt_ext3_journal_sbdev(struct super_block *sb)
1388 return (EXT3_SB(sb)->journal_bdev);
1390 EXPORT_SYMBOL(fsfilt_ext3_journal_sbdev);
1392 static int ll_decode_fh_accept(void *context, struct dentry *de)
1397 #ifdef HAVE_EXPORTFS_DECODE_FH
1398 # define ll_exportfs_decode_fh(mnt, fid, len, type, acceptable, context) \
1399 exportfs_decode_fh(mnt, (struct fid*)(fid), len, type, \
1400 acceptable, context)
1402 # define ll_exportfs_decode_fh(mnt, fid, len, type, acceptable, context) \
1403 export_op_default.decode_fh((mnt)->mnt_sb, &(fid)->ino, len, \
1404 type, acceptable, context)
1405 # define FILEID_INO32_GEN 1
1406 extern struct export_operations export_op_default;
1409 struct dentry *fsfilt_ext3_fid2dentry(struct vfsmount *mnt,
1410 struct fsfilt_fid *fid, int ignore_gen)
1412 struct inode *inode;
1413 struct dentry *result;
1415 result = ll_exportfs_decode_fh(mnt, fid, 2, FILEID_INO32_GEN,
1416 ll_decode_fh_accept, NULL);
1417 if (IS_ERR(result)) {
1418 CDEBUG(D_DENTRY, "%s of %u/%u failed %ld\n", __func__,
1419 fid->ino, fid->gen, PTR_ERR(result));
1423 CDEBUG(D_DENTRY, "%s of %u/%u succeeded\n", __func__,
1424 fid->ino, fid->gen);
1425 inode = result->d_inode;
1429 if (inode->i_nlink == 0 &&
1430 inode->i_mode == 0 && LTIME_S(inode->i_ctime) == 0) {
1431 LCONSOLE_WARN("Found inode with zero nlink, mode and"
1432 " ctime -- this may indicate disk "
1433 "corruption (inode: %lu, link: %lu, "
1434 "count: %d)\n", inode->i_ino,
1435 (unsigned long)inode->i_nlink,
1436 atomic_read(&inode->i_count));
1439 if (fid->gen && inode->i_generation != fid->gen) {
1440 /* we didn't find the right inode.. */
1441 CDEBUG(D_INODE, "found wrong generation: inode %lu, link: %lu, "
1442 "count: %d, generation %u/%u\n",
1443 inode->i_ino, (unsigned long)inode->i_nlink,
1444 atomic_read(&inode->i_count), inode->i_generation,
1452 return ERR_PTR(-ENOENT);
1455 static struct fsfilt_operations fsfilt_ext3_ops = {
1457 .fs_owner = THIS_MODULE,
1458 .fs_getlabel = fsfilt_ext3_get_label,
1459 .fs_setlabel = fsfilt_ext3_set_label,
1460 .fs_uuid = fsfilt_ext3_uuid,
1461 .fs_start = fsfilt_ext3_start,
1462 .fs_brw_start = fsfilt_ext3_brw_start,
1463 .fs_extend = fsfilt_ext3_extend,
1464 .fs_commit = fsfilt_ext3_commit,
1465 .fs_commit_async = fsfilt_ext3_commit_async,
1466 .fs_commit_wait = fsfilt_ext3_commit_wait,
1467 .fs_setattr = fsfilt_ext3_setattr,
1468 .fs_iocontrol = fsfilt_ext3_iocontrol,
1469 .fs_set_md = fsfilt_ext3_set_md,
1470 .fs_get_md = fsfilt_ext3_get_md,
1471 .fs_readpage = fsfilt_ext3_readpage,
1472 .fs_add_journal_cb = fsfilt_ext3_add_journal_cb,
1473 .fs_statfs = fsfilt_ext3_statfs,
1474 .fs_sync = fsfilt_ext3_sync,
1475 .fs_map_inode_pages = fsfilt_ext3_map_inode_pages,
1476 .fs_write_record = fsfilt_ext3_write_record,
1477 .fs_read_record = fsfilt_ext3_read_record,
1478 .fs_setup = fsfilt_ext3_setup,
1479 .fs_send_bio = fsfilt_ext3_send_bio,
1480 .fs_get_op_len = fsfilt_ext3_get_op_len,
1481 #ifdef HAVE_DISK_INODE_VERSION
1482 .fs_get_version = fsfilt_ext3_get_version,
1483 .fs_set_version = fsfilt_ext3_set_version,
1485 .fs_journal_sbdev = fsfilt_ext3_journal_sbdev,
1486 .fs_fid2dentry = fsfilt_ext3_fid2dentry,
1489 static int __init fsfilt_ext3_init(void)
1493 fcb_cache = cfs_mem_cache_create("fsfilt_ext3_fcb",
1494 sizeof(struct fsfilt_cb_data), 0, 0);
1496 CERROR("error allocating fsfilt journal callback cache\n");
1497 GOTO(out, rc = -ENOMEM);
1500 rc = fsfilt_register_ops(&fsfilt_ext3_ops);
1503 int err = cfs_mem_cache_destroy(fcb_cache);
1504 LASSERTF(err == 0, "error destroying new cache: rc %d\n", err);
1510 static void __exit fsfilt_ext3_exit(void)
1514 fsfilt_unregister_ops(&fsfilt_ext3_ops);
1515 rc = cfs_mem_cache_destroy(fcb_cache);
1516 LASSERTF(rc == 0, "couldn't destroy fcb_cache slab\n");
1519 module_init(fsfilt_ext3_init);
1520 module_exit(fsfilt_ext3_exit);
1522 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1523 MODULE_DESCRIPTION("Lustre ext3 Filesystem Helper v0.1");
1524 MODULE_LICENSE("GPL");