1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/lib/fsfilt_ext3.c
5 * Lustre filesystem abstraction routines
7 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
8 * Author: Andreas Dilger <adilger@clusterfs.com>
10 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
26 #define DEBUG_SUBSYSTEM S_FILTER
28 #include <linux/init.h>
29 #include <linux/module.h>
31 #include <linux/jbd.h>
32 #include <linux/slab.h>
33 #include <linux/pagemap.h>
34 #include <linux/quotaops.h>
35 #include <linux/ext3_fs.h>
36 #include <linux/ext3_jbd.h>
37 #include <linux/version.h>
38 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
39 #include <linux/ext3_xattr.h>
41 #include <ext3/xattr.h>
44 #include <linux/kp30.h>
45 #include <linux/lustre_fsfilt.h>
46 #include <linux/obd.h>
47 #include <linux/obd_class.h>
48 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
49 #include <linux/module.h>
50 #include <linux/iobuf.h>
53 static kmem_cache_t *fcb_cache;
54 static atomic_t fcb_cache_count = ATOMIC_INIT(0);
56 struct fsfilt_cb_data {
57 struct journal_callback cb_jcb; /* jbd private data - MUST BE FIRST */
58 fsfilt_cb_t cb_func; /* MDS/OBD completion function */
59 struct obd_device *cb_obd; /* MDS/OBD completion device */
60 __u64 cb_last_rcvd; /* MDS/OST last committed operation */
61 void *cb_data; /* MDS/OST completion function data */
64 #ifndef EXT3_XATTR_INDEX_TRUSTED /* temporary until we hit l28 kernel */
65 #define EXT3_XATTR_INDEX_TRUSTED 4
67 #define XATTR_LUSTRE_MDS_LOV_EA "lov"
70 * We don't currently need any additional blocks for rmdir and
71 * unlink transactions because we are storing the OST oa_id inside
72 * the inode (which we will be changing anyways as part of this
75 static void *fsfilt_ext3_start(struct inode *inode, int op, void *desc_private,
78 /* For updates to the last recieved file */
79 int nblocks = EXT3_SINGLEDATA_TRANS_BLOCKS;
83 if (current->journal_info) {
84 CDEBUG(D_INODE, "increasing refcount on %p\n",
85 current->journal_info);
89 /* XXX BUG 3188 -- must return to one set of opcodes */
90 /* FIXME - cache hook */
92 nblocks += EXT3_INDEX_EXTRA_TRANS_BLOCKS+EXT3_DATA_TRANS_BLOCKS;
98 nblocks += EXT3_INDEX_EXTRA_TRANS_BLOCKS+EXT3_DATA_TRANS_BLOCKS;
103 case FSFILT_OP_RMDIR:
104 case FSFILT_OP_UNLINK:
105 /* delete one file + create/update logs for each stripe */
106 nblocks += EXT3_DELETE_TRANS_BLOCKS;
107 nblocks += (EXT3_INDEX_EXTRA_TRANS_BLOCKS +
108 EXT3_SINGLEDATA_TRANS_BLOCKS) * logs;
110 case FSFILT_OP_RENAME:
111 /* modify additional directory */
112 nblocks += EXT3_SINGLEDATA_TRANS_BLOCKS;
114 case FSFILT_OP_SYMLINK:
115 /* additional block + block bitmap + GDT for long symlink */
118 case FSFILT_OP_CREATE:
119 /* create/update logs for each stripe */
120 nblocks += (EXT3_INDEX_EXTRA_TRANS_BLOCKS +
121 EXT3_SINGLEDATA_TRANS_BLOCKS) * logs;
123 case FSFILT_OP_MKDIR:
124 case FSFILT_OP_MKNOD:
125 /* modify one inode + block bitmap + GDT */
129 /* modify parent directory */
130 nblocks += EXT3_INDEX_EXTRA_TRANS_BLOCKS +
131 EXT3_DATA_TRANS_BLOCKS;
133 case FSFILT_OP_SETATTR:
134 /* Setattr on inode */
137 case FSFILT_OP_CANCEL_UNLINK:
138 /* blocks for log header bitmap update OR
139 * blocks for catalog header bitmap update + unlink of logs */
140 nblocks = (LLOG_CHUNK_SIZE >> inode->i_blkbits) +
141 EXT3_DELETE_TRANS_BLOCKS * logs;
144 nblocks += EXT3_INDEX_EXTRA_TRANS_BLOCKS+EXT3_DATA_TRANS_BLOCKS;
146 default: CERROR("unknown transaction start op %d\n", op);
150 LASSERT(current->journal_info == desc_private);
151 journal = EXT3_SB(inode->i_sb)->s_journal;
152 if (nblocks > journal->j_max_transaction_buffers) {
153 CERROR("too many credits %d for op %ux%u using %d instead\n",
154 nblocks, op, logs, journal->j_max_transaction_buffers);
155 nblocks = journal->j_max_transaction_buffers;
160 handle = journal_start(EXT3_JOURNAL(inode), nblocks);
164 LASSERT(current->journal_info == handle);
166 CERROR("error starting handle for op %u (%u credits): rc %ld\n",
167 op, nblocks, PTR_ERR(handle));
172 * Calculate the number of buffer credits needed to write multiple pages in
173 * a single ext3 transaction. No, this shouldn't be here, but as yet ext3
174 * doesn't have a nice API for calculating this sort of thing in advance.
176 * See comment above ext3_writepage_trans_blocks for details. We assume
177 * no data journaling is being done, but it does allow for all of the pages
178 * being non-contiguous. If we are guaranteed contiguous pages we could
179 * reduce the number of (d)indirect blocks a lot.
181 * With N blocks per page and P pages, for each inode we have at most:
183 * min(N*P, blocksize/4 + 1) dindirect blocks
186 * For the entire filesystem, we have at most:
187 * min(sum(nindir + P), ngroups) bitmap blocks (from the above)
188 * min(sum(nindir + P), gdblocks) group descriptor blocks (from the above)
189 * objcount inode blocks
191 * 2 * EXT3_SINGLEDATA_TRANS_BLOCKS for the quota files
193 * 1 EXT3_DATA_TRANS_BLOCKS for the last_rcvd update.
195 static int fsfilt_ext3_credits_needed(int objcount, struct fsfilt_objinfo *fso,
196 int niocount, struct niobuf_local *nb)
198 struct super_block *sb = fso->fso_dentry->d_inode->i_sb;
200 const int blockpp = 1 << (PAGE_CACHE_SHIFT - sb->s_blocksize_bits);
201 int nbitmaps = 0, ngdblocks;
202 int needed = objcount + 1; /* inodes + superblock */
205 for (i = 0, j = 0; i < objcount; i++, fso++) {
206 /* two or more dindirect blocks in case we cross boundary */
207 int ndind = (long)((nb[j + fso->fso_bufcnt - 1].offset -
209 sb->s_blocksize_bits) /
210 (EXT3_ADDR_PER_BLOCK(sb) * EXT3_ADDR_PER_BLOCK(sb));
211 nbitmaps += min(fso->fso_bufcnt, ndind > 0 ? ndind : 2);
213 /* leaf, indirect, tindirect blocks for first block */
214 nbitmaps += blockpp + 2;
216 j += fso->fso_bufcnt;
219 next_indir = nb[0].offset +
220 (EXT3_ADDR_PER_BLOCK(sb) << sb->s_blocksize_bits);
221 for (i = 1; i < niocount; i++) {
222 if (nb[i].offset >= next_indir) {
223 nbitmaps++; /* additional indirect */
224 next_indir = nb[i].offset +
225 (EXT3_ADDR_PER_BLOCK(sb)<<sb->s_blocksize_bits);
226 } else if (nb[i].offset != nb[i - 1].offset + sb->s_blocksize) {
227 nbitmaps++; /* additional indirect */
229 nbitmaps += blockpp; /* each leaf in different group? */
232 ngdblocks = nbitmaps;
233 if (nbitmaps > EXT3_SB(sb)->s_groups_count)
234 nbitmaps = EXT3_SB(sb)->s_groups_count;
235 if (ngdblocks > EXT3_SB(sb)->s_gdb_count)
236 ngdblocks = EXT3_SB(sb)->s_gdb_count;
238 needed += nbitmaps + ngdblocks;
240 /* last_rcvd update */
241 needed += EXT3_DATA_TRANS_BLOCKS;
243 #if defined(CONFIG_QUOTA) && !defined(__x86_64__) /* XXX */
244 /* We assume that there will be 1 bit set in s_dquot.flags for each
245 * quota file that is active. This is at least true for now.
247 needed += hweight32(sb_any_quota_enabled(sb)) *
248 EXT3_SINGLEDATA_TRANS_BLOCKS;
254 /* We have to start a huge journal transaction here to hold all of the
255 * metadata for the pages being written here. This is necessitated by
256 * the fact that we do lots of prepare_write operations before we do
257 * any of the matching commit_write operations, so even if we split
258 * up to use "smaller" transactions none of them could complete until
259 * all of them were opened. By having a single journal transaction,
260 * we eliminate duplicate reservations for common blocks like the
261 * superblock and group descriptors or bitmaps.
263 * We will start the transaction here, but each prepare_write will
264 * add a refcount to the transaction, and each commit_write will
265 * remove a refcount. The transaction will be closed when all of
266 * the pages have been written.
268 static void *fsfilt_ext3_brw_start(int objcount, struct fsfilt_objinfo *fso,
269 int niocount, struct niobuf_local *nb,
270 void *desc_private, int logs)
277 LASSERT(current->journal_info == desc_private);
278 journal = EXT3_SB(fso->fso_dentry->d_inode->i_sb)->s_journal;
279 needed = fsfilt_ext3_credits_needed(objcount, fso, niocount, nb);
281 /* The number of blocks we could _possibly_ dirty can very large.
282 * We reduce our request if it is absurd (and we couldn't get that
283 * many credits for a single handle anyways).
285 * At some point we have to limit the size of I/Os sent at one time,
286 * increase the size of the journal, or we have to calculate the
287 * actual journal requirements more carefully by checking all of
288 * the blocks instead of being maximally pessimistic. It remains to
289 * be seen if this is a real problem or not.
291 if (needed > journal->j_max_transaction_buffers) {
292 CERROR("want too many journal credits (%d) using %d instead\n",
293 needed, journal->j_max_transaction_buffers);
294 needed = journal->j_max_transaction_buffers;
298 handle = journal_start(journal, needed);
300 if (IS_ERR(handle)) {
301 CERROR("can't get handle for %d credits: rc = %ld\n", needed,
304 LASSERT(handle->h_buffer_credits >= needed);
305 LASSERT(current->journal_info == handle);
311 static int fsfilt_ext3_commit(struct inode *inode, void *h, int force_sync)
314 handle_t *handle = h;
316 LASSERT(current->journal_info == handle);
318 handle->h_sync = 1; /* recovery likes this */
321 rc = journal_stop(handle);
327 static int fsfilt_ext3_commit_async(struct inode *inode, void *h,
331 transaction_t *transaction;
332 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
335 handle_t *handle = h;
339 LASSERT(current->journal_info == handle);
342 transaction = handle->h_transaction;
343 journal = transaction->t_journal;
344 tid = transaction->t_tid;
345 /* we don't want to be blocked */
347 rc = journal_stop(handle);
349 CERROR("error while stopping transaction: %d\n", rc);
353 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
354 rtid = log_start_commit(journal, transaction);
356 CERROR("strange race: %lu != %lu\n",
357 (unsigned long) tid, (unsigned long) rtid);
359 log_start_commit(journal, transaction->t_tid);
363 *wait_handle = (void *) tid;
364 CDEBUG(D_INODE, "commit async: %lu\n", (unsigned long) tid);
368 static int fsfilt_ext3_commit_wait(struct inode *inode, void *h)
370 tid_t tid = (tid_t)(long)h;
372 CDEBUG(D_INODE, "commit wait: %lu\n", (unsigned long) tid);
373 if (is_journal_aborted(EXT3_JOURNAL(inode)))
376 log_wait_commit(EXT3_JOURNAL(inode), tid);
381 static int fsfilt_ext3_setattr(struct dentry *dentry, void *handle,
382 struct iattr *iattr, int do_trunc)
384 struct inode *inode = dentry->d_inode;
389 /* A _really_ horrible hack to avoid removing the data stored
390 * in the block pointers; this is really the "small" stripe MD data.
391 * We can avoid further hackery by virtue of the MDS file size being
392 * zero all the time (which doesn't invoke block truncate at unlink
393 * time), so we assert we never change the MDS file size from zero. */
394 if (iattr->ia_valid & ATTR_SIZE && !do_trunc) {
395 /* ATTR_SIZE would invoke truncate: clear it */
396 iattr->ia_valid &= ~ATTR_SIZE;
397 EXT3_I(inode)->i_disksize = inode->i_size = iattr->ia_size;
399 /* make sure _something_ gets set - so new inode
400 * goes to disk (probably won't work over XFS */
401 if (!(iattr->ia_valid & (ATTR_MODE | ATTR_MTIME | ATTR_CTIME))){
402 iattr->ia_valid |= ATTR_MODE;
403 iattr->ia_mode = inode->i_mode;
407 /* Don't allow setattr to change file type */
408 iattr->ia_mode = (inode->i_mode & S_IFMT)|(iattr->ia_mode & ~S_IFMT);
410 /* We set these flags on the client, but have already checked perms
411 * so don't confuse inode_change_ok. */
412 iattr->ia_valid &= ~(ATTR_MTIME_SET | ATTR_ATIME_SET);
414 if (inode->i_op->setattr) {
415 rc = inode->i_op->setattr(dentry, iattr);
417 rc = inode_change_ok(inode, iattr);
419 rc = inode_setattr(inode, iattr);
427 static int fsfilt_ext3_iocontrol(struct inode * inode, struct file *file,
428 unsigned int cmd, unsigned long arg)
433 if (inode->i_fop->ioctl)
434 rc = inode->i_fop->ioctl(inode, file, cmd, arg);
441 static int fsfilt_ext3_set_md(struct inode *inode, void *handle,
442 void *lmm, int lmm_size)
446 /* keep this when we get rid of OLD_EA (too noisy during conversion) */
447 if (EXT3_I(inode)->i_file_acl /* || large inode EA flag */)
448 CWARN("setting EA on %lu/%u again... interesting\n",
449 inode->i_ino, inode->i_generation);
452 rc = ext3_xattr_set_handle(handle, inode, EXT3_XATTR_INDEX_TRUSTED,
453 XATTR_LUSTRE_MDS_LOV_EA, lmm, lmm_size, 0);
458 CERROR("error adding MD data to inode %lu: rc = %d\n",
463 /* Must be called with i_sem held */
464 static int fsfilt_ext3_get_md(struct inode *inode, void *lmm, int lmm_size)
468 LASSERT(down_trylock(&inode->i_sem) != 0);
471 rc = ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED,
472 XATTR_LUSTRE_MDS_LOV_EA, lmm, lmm_size);
475 /* This gives us the MD size */
477 return (rc == -ENODATA) ? 0 : rc;
480 CDEBUG(D_INFO, "error getting EA %d/%s from inode %lu: rc %d\n",
481 EXT3_XATTR_INDEX_TRUSTED, XATTR_LUSTRE_MDS_LOV_EA,
483 memset(lmm, 0, lmm_size);
484 return (rc == -ENODATA) ? 0 : rc;
490 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
491 static int fsfilt_ext3_send_bio(struct inode *inode, struct bio *bio)
493 submit_bio(WRITE, bio);
497 static int fsfilt_ext3_send_bio(struct inode *inode, struct kiobuf *bio)
499 int rc, blocks_per_page;
501 rc = brw_kiovec(WRITE, 1, &bio, inode->i_dev,
502 bio->blocks, 1 << inode->i_blkbits);
504 blocks_per_page = PAGE_SIZE >> inode->i_blkbits;
506 if (rc != (1 << inode->i_blkbits) * bio->nr_pages *
508 CERROR("short write? expected %d, wrote %d\n",
509 (1 << inode->i_blkbits) * bio->nr_pages *
510 blocks_per_page, rc);
517 /* FIXME-UMKA: This should be used in 2.6.x io code later. */
518 static struct page *fsfilt_ext3_getpage(struct inode *inode, long int index)
523 page = grab_cache_page(inode->i_mapping, index);
525 return ERR_PTR(-ENOMEM);
527 if (PageUptodate(page)) {
532 rc = inode->i_mapping->a_ops->readpage(NULL, page);
534 page_cache_release(page);
541 static ssize_t fsfilt_ext3_readpage(struct file *file, char *buf, size_t count,
544 struct inode *inode = file->f_dentry->d_inode;
547 if (S_ISREG(inode->i_mode))
548 rc = file->f_op->read(file, buf, count, off);
550 const int blkbits = inode->i_sb->s_blocksize_bits;
551 const int blksize = inode->i_sb->s_blocksize;
553 CDEBUG(D_EXT2, "reading "LPSZ" at dir %lu+%llu\n",
554 count, inode->i_ino, *off);
556 struct buffer_head *bh;
559 if (*off < inode->i_size) {
562 bh = ext3_bread(NULL, inode, *off >> blkbits,
565 CDEBUG(D_EXT2, "read %u@%llu\n", blksize, *off);
568 memcpy(buf, bh->b_data, blksize);
571 /* XXX in theory we should just fake
572 * this buffer and continue like ext3,
573 * especially if this is a partial read
575 CERROR("error read dir %lu+%llu: %d\n",
576 inode->i_ino, *off, err);
581 struct ext3_dir_entry_2 *fake = (void *)buf;
583 CDEBUG(D_EXT2, "fake %u@%llu\n", blksize, *off);
584 memset(fake, 0, sizeof(*fake));
585 fake->rec_len = cpu_to_le32(blksize);
597 static void fsfilt_ext3_cb_func(struct journal_callback *jcb, int error)
599 struct fsfilt_cb_data *fcb = (struct fsfilt_cb_data *)jcb;
601 fcb->cb_func(fcb->cb_obd, fcb->cb_last_rcvd, fcb->cb_data, error);
603 OBD_SLAB_FREE(fcb, fcb_cache, sizeof *fcb);
604 atomic_dec(&fcb_cache_count);
607 static int fsfilt_ext3_add_journal_cb(struct obd_device *obd,
608 struct super_block *sb,
610 void *handle, fsfilt_cb_t cb_func,
613 struct fsfilt_cb_data *fcb;
615 OBD_SLAB_ALLOC(fcb, fcb_cache, GFP_NOFS, sizeof *fcb);
619 atomic_inc(&fcb_cache_count);
620 fcb->cb_func = cb_func;
622 fcb->cb_last_rcvd = last_rcvd;
623 fcb->cb_data = cb_data;
625 CDEBUG(D_EXT2, "set callback for last_rcvd: "LPD64"\n", last_rcvd);
627 journal_callback_set(handle, fsfilt_ext3_cb_func,
628 (struct journal_callback *)fcb);
635 * We need to hack the return value for the free inode counts because
636 * the current EA code requires one filesystem block per inode with EAs,
637 * so it is possible to run out of blocks before we run out of inodes.
639 * This can be removed when the ext3 EA code is fixed.
641 static int fsfilt_ext3_statfs(struct super_block *sb, struct obd_statfs *osfs)
646 memset(&sfs, 0, sizeof(sfs));
648 rc = sb->s_op->statfs(sb, &sfs);
650 if (!rc && sfs.f_bfree < sfs.f_ffree) {
651 sfs.f_files = (sfs.f_files - sfs.f_ffree) + sfs.f_bfree;
652 sfs.f_ffree = sfs.f_bfree;
655 statfs_pack(osfs, &sfs);
659 static int fsfilt_ext3_sync(struct super_block *sb)
661 return ext3_force_commit(sb);
664 extern int ext3_map_inode_page(struct inode *inode, struct page *page,
665 unsigned long *blocks, int *created, int create);
666 int fsfilt_ext3_map_inode_page(struct inode *inode, struct page *page,
667 unsigned long *blocks, int *created, int create)
669 return ext3_map_inode_page(inode, page, blocks, created, create);
672 extern int ext3_prep_san_write(struct inode *inode, long *blocks,
673 int nblocks, loff_t newsize);
674 static int fsfilt_ext3_prep_san_write(struct inode *inode, long *blocks,
675 int nblocks, loff_t newsize)
677 return ext3_prep_san_write(inode, blocks, nblocks, newsize);
680 static int fsfilt_ext3_read_record(struct file * file, void *buf,
681 int size, loff_t *offs)
683 struct inode *inode = file->f_dentry->d_inode;
685 struct buffer_head *bh;
686 int err, blocksize, csize, boffs;
688 /* prevent reading after eof */
690 if (inode->i_size < *offs + size) {
691 size = inode->i_size - *offs;
694 CERROR("size %llu is too short for read %u@%llu\n",
695 inode->i_size, size, *offs);
697 } else if (size == 0) {
704 blocksize = 1 << inode->i_blkbits;
707 block = *offs >> inode->i_blkbits;
708 boffs = *offs & (blocksize - 1);
709 csize = min(blocksize - boffs, size);
710 bh = ext3_bread(NULL, inode, block, 0, &err);
712 CERROR("can't read block: %d\n", err);
716 memcpy(buf, bh->b_data + boffs, csize);
726 static int fsfilt_ext3_write_record(struct file *file, void *buf, int bufsize,
727 loff_t *offs, int force_sync)
729 struct buffer_head *bh = NULL;
731 struct inode *inode = file->f_dentry->d_inode;
732 loff_t old_size = inode->i_size, offset = *offs;
733 loff_t new_size = inode->i_size;
736 int err, block_count = 0, blocksize, size, boffs;
738 /* Determine how many transaction credits are needed */
739 blocksize = 1 << inode->i_blkbits;
740 block_count = (*offs & (blocksize - 1)) + bufsize;
741 block_count = (block_count + blocksize - 1) >> inode->i_blkbits;
743 journal = EXT3_SB(inode->i_sb)->s_journal;
745 handle = journal_start(journal,
746 block_count * EXT3_DATA_TRANS_BLOCKS + 2);
748 if (IS_ERR(handle)) {
749 CERROR("can't start transaction\n");
750 return PTR_ERR(handle);
753 while (bufsize > 0) {
757 block = offset >> inode->i_blkbits;
758 boffs = offset & (blocksize - 1);
759 size = min(blocksize - boffs, bufsize);
760 bh = ext3_bread(handle, inode, block, 1, &err);
762 CERROR("can't read/create block: %d\n", err);
766 err = ext3_journal_get_write_access(handle, bh);
768 CERROR("journal_get_write_access() returned error %d\n",
772 LASSERT(bh->b_data + boffs + size <= bh->b_data + bh->b_size);
773 memcpy(bh->b_data + boffs, buf, size);
774 err = ext3_journal_dirty_metadata(handle, bh);
776 CERROR("journal_dirty_metadata() returned error %d\n",
780 if (offset + size > new_size)
781 new_size = offset + size;
788 handle->h_sync = 1; /* recovery likes this */
793 /* correct in-core and on-disk sizes */
794 if (new_size > inode->i_size) {
796 if (new_size > inode->i_size)
797 inode->i_size = new_size;
798 if (inode->i_size > EXT3_I(inode)->i_disksize)
799 EXT3_I(inode)->i_disksize = inode->i_size;
800 if (inode->i_size > old_size)
801 mark_inode_dirty(inode);
806 journal_stop(handle);
814 static int fsfilt_ext3_setup(struct super_block *sb)
817 EXT3_SB(sb)->dx_lock = fsfilt_ext3_dx_lock;
818 EXT3_SB(sb)->dx_unlock = fsfilt_ext3_dx_unlock;
821 CWARN("Enabling PDIROPS\n");
822 set_opt(EXT3_SB(sb)->s_mount_opt, PDIROPS);
823 sb->s_flags |= S_PDIROPS;
828 static int fsfilt_ext3_set_xattr(struct inode * inode, void *handle, char *name,
829 void *buffer, int buffer_size)
835 rc = ext3_xattr_set_handle(handle, inode, EXT3_XATTR_INDEX_TRUSTED,
836 name, buffer, buffer_size, 0);
839 CERROR("set xattr %s from inode %lu: rc %d\n",
840 name, inode->i_ino, rc);
844 static int fsfilt_ext3_get_xattr(struct inode *inode, char *name,
845 void *buffer, int buffer_size)
850 rc = ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED,
851 name, buffer, buffer_size);
855 return (rc == -ENODATA) ? 0 : rc;
857 CDEBUG(D_INFO, "error getting EA %s from inode %lu: rc %d\n",
858 name, inode->i_ino, rc);
859 memset(buffer, 0, buffer_size);
860 return (rc == -ENODATA) ? 0 : rc;
866 /* If fso is NULL, op is FSFILT operation, otherwise op is number of fso
867 objects. Logs is number of logfiles to update */
868 static int fsfilt_ext3_get_op_len(int op, struct fsfilt_objinfo *fso, int logs)
872 case FSFILT_OP_CREATE:
873 /* directory leaf, index & indirect & EA*/
875 case FSFILT_OP_UNLINK:
881 struct super_block *sb = fso->fso_dentry->d_inode->i_sb;
882 int blockpp = 1 << (PAGE_CACHE_SHIFT - sb->s_blocksize_bits);
883 int addrpp = EXT3_ADDR_PER_BLOCK(sb) * blockpp;
884 for (i = 0; i < op; i++, fso++) {
885 int nblocks = fso->fso_bufcnt * blockpp;
886 int ndindirect = min(nblocks, addrpp + 1);
887 int nindir = nblocks + ndindirect + 1;
891 return needed + 3 * logs;
897 static struct fsfilt_operations fsfilt_ext3_ops = {
899 .fs_owner = THIS_MODULE,
900 .fs_start = fsfilt_ext3_start,
901 .fs_brw_start = fsfilt_ext3_brw_start,
902 .fs_commit = fsfilt_ext3_commit,
903 .fs_commit_async = fsfilt_ext3_commit_async,
904 .fs_commit_wait = fsfilt_ext3_commit_wait,
905 .fs_setattr = fsfilt_ext3_setattr,
906 .fs_iocontrol = fsfilt_ext3_iocontrol,
907 .fs_set_md = fsfilt_ext3_set_md,
908 .fs_get_md = fsfilt_ext3_get_md,
909 .fs_readpage = fsfilt_ext3_readpage,
910 .fs_add_journal_cb = fsfilt_ext3_add_journal_cb,
911 .fs_statfs = fsfilt_ext3_statfs,
912 .fs_sync = fsfilt_ext3_sync,
913 .fs_map_inode_page = fsfilt_ext3_map_inode_page,
914 .fs_prep_san_write = fsfilt_ext3_prep_san_write,
915 .fs_write_record = fsfilt_ext3_write_record,
916 .fs_read_record = fsfilt_ext3_read_record,
917 .fs_setup = fsfilt_ext3_setup,
918 .fs_getpage = fsfilt_ext3_getpage,
919 .fs_send_bio = fsfilt_ext3_send_bio,
920 .fs_set_xattr = fsfilt_ext3_set_xattr,
921 .fs_get_xattr = fsfilt_ext3_get_xattr,
922 .fs_get_op_len = fsfilt_ext3_get_op_len,
925 static int __init fsfilt_ext3_init(void)
929 fcb_cache = kmem_cache_create("fsfilt_ext3_fcb",
930 sizeof(struct fsfilt_cb_data), 0,
933 CERROR("error allocating fsfilt journal callback cache\n");
934 GOTO(out, rc = -ENOMEM);
937 rc = fsfilt_register_ops(&fsfilt_ext3_ops);
940 kmem_cache_destroy(fcb_cache);
945 static void __exit fsfilt_ext3_exit(void)
949 fsfilt_unregister_ops(&fsfilt_ext3_ops);
950 rc = kmem_cache_destroy(fcb_cache);
952 if (rc || atomic_read(&fcb_cache_count)) {
953 CERROR("can't free fsfilt callback cache: count %d, rc = %d\n",
954 atomic_read(&fcb_cache_count), rc);
958 module_init(fsfilt_ext3_init);
959 module_exit(fsfilt_ext3_exit);
961 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
962 MODULE_DESCRIPTION("Lustre ext3 Filesystem Helper v0.1");
963 MODULE_LICENSE("GPL");