6 #define DEBUG_SUBSYSTEM S_SM
8 #include <linux/kmod.h>
9 #include <linux/init.h>
11 #include <linux/slab.h>
12 #include <linux/string.h>
13 #include <linux/smp_lock.h>
14 #include <linux/lustre_idl.h>
15 #if defined(CONFIG_EXT3_FS) || defined (CONFIG_EXT3_FS_MODULE)
16 #include <linux/jbd.h>
17 #include <linux/ext3_fs.h>
18 #include <linux/ext3_jbd.h>
21 #include "smfs_internal.h"
24 #if defined(CONFIG_EXT3_FS) || defined (CONFIG_EXT3_FS_MODULE)
26 #define MAX_PATH_BLOCKS(inode) (PATH_MAX >> EXT3_BLOCK_SIZE_BITS((inode)->i_sb))
27 #define MAX_NAME_BLOCKS(inode) (NAME_MAX >> EXT3_BLOCK_SIZE_BITS((inode)->i_sb))
29 static void *smfs_e3_trans_start(struct inode *inode,
33 int trunc_blks, one_path_blks, extra_path_blks;
34 int extra_name_blks, lml_blks, jblocks;
35 __u32 avail_kmlblocks;
38 avail_kmlblocks = inode->i_sb->u.ext3_sb.s_es->s_free_blocks_count;
40 if ( avail_kmlblocks < 3 ) {
41 return ERR_PTR(-ENOSPC);
44 if ((op != KML_OPCODE_UNLINK && op != KML_OPCODE_RMDIR)
45 && avail_kmlblocks < 6 ) {
46 return ERR_PTR(-ENOSPC);
48 /* Need journal space for:
49 at least three writes to KML (two one block writes, one a path)
50 possibly a second name (unlink, rmdir)
51 possibly a second path (symlink, rename)
52 a one block write to the last rcvd file
55 trunc_blks = EXT3_DATA_TRANS_BLOCKS + 1;
56 one_path_blks = 4*EXT3_DATA_TRANS_BLOCKS + MAX_PATH_BLOCKS(inode) + 3;
57 lml_blks = 4*EXT3_DATA_TRANS_BLOCKS + MAX_PATH_BLOCKS(inode) + 2;
58 extra_path_blks = EXT3_DATA_TRANS_BLOCKS + MAX_PATH_BLOCKS(inode);
59 extra_name_blks = EXT3_DATA_TRANS_BLOCKS + MAX_NAME_BLOCKS(inode);
61 /* additional blocks appear for "two pathname" operations
62 and operations involving the LML records
66 case KML_OPCODE_MKDIR:
67 jblocks = one_path_blks + trunc_blks
68 + EXT3_DATA_TRANS_BLOCKS + 4 + 2;
71 CDEBUG(D_INODE, "invalid operation %d for journal\n", op);
75 CDEBUG(D_INODE, "creating journal handle (%d blocks)\n", jblocks);
78 handle = journal_start(EXT3_JOURNAL(inode), jblocks);
84 static void smfs_e3_trans_commit(void *handle)
91 struct journal_operations smfs_ext3_journal_ops = {
92 .tr_start = smfs_e3_trans_start,
93 .tr_commit = smfs_e3_trans_commit,