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 "smfs_internal.h"
15 void duplicate_inode(struct inode *cache_inode, struct inode *inode)
18 inode->i_mode = cache_inode->i_mode;
19 inode->i_uid = cache_inode->i_uid;
20 inode->i_gid = cache_inode->i_gid;
22 inode->i_nlink = cache_inode->i_nlink;
23 inode->i_size = cache_inode->i_size;
24 inode->i_atime = cache_inode->i_atime;
25 inode->i_ctime = cache_inode->i_ctime;
26 inode->i_mtime = cache_inode->i_mtime;
27 inode->i_blksize = cache_inode->i_blksize; /* This is the optimal IO size
28 * (for stat), not the fs block
30 inode->i_blocks = cache_inode->i_blocks;
31 inode->i_version = cache_inode->i_version;
32 inode->i_state = cache_inode->i_state;
34 static void smfs_read_inode(struct inode *inode)
36 struct super_block *cache_sb;
37 struct inode *cache_inode;
43 CDEBUG(D_INODE, "read_inode ino %lu\n", inode->i_ino);
44 cache_sb = S2CSB(inode->i_sb);
46 cache_inode = iget(cache_sb, inode->i_ino);
47 I2CI(inode) = cache_inode;
49 if(cache_sb && cache_sb->s_op->read_inode)
50 cache_sb->s_op->read_inode(cache_inode);
52 duplicate_inode(cache_inode, inode);
53 sm_set_inode_ops(cache_inode, inode);
55 CDEBUG(D_INODE, "read_inode ino %lu icount %d \n",
56 inode->i_ino, atomic_read(&inode->i_count));
61 /* Although some filesystem(such as ext3) do not have
62 * clear_inode method, but we need it to free the
65 static void smfs_clear_inode(struct inode *inode)
67 struct super_block *cache_sb;
68 struct inode *cache_inode;
74 cache_sb = S2CSB(inode->i_sb);
75 cache_inode = I2CI(inode);
77 duplicate_inode(inode, cache_inode);
79 if (cache_sb->s_op->clear_inode)
80 cache_sb->s_op->clear_inode(cache_inode);
82 duplicate_inode(inode, cache_inode);
86 static void smfs_delete_inode(struct inode *inode)
88 struct inode *cache_inode;
89 struct super_block *cache_sb;
92 cache_inode = I2CI(inode);
93 cache_sb = S2CSB(inode->i_sb);
95 if (!cache_inode || !cache_sb ||
96 !cache_inode->i_nlink) {
100 duplicate_inode(inode, cache_inode);
102 list_del(&cache_inode->i_hash);
103 INIT_LIST_HEAD(&cache_inode->i_hash);
104 list_del(&cache_inode->i_list);
105 INIT_LIST_HEAD(&cache_inode->i_list);
107 if (cache_inode->i_data.nrpages)
108 truncate_inode_pages(&cache_inode->i_data, 0);
110 if (cache_sb->s_op->delete_inode)
111 cache_sb->s_op->delete_inode(cache_inode);
113 duplicate_inode(cache_inode, inode);
117 static void smfs_write_inode(struct inode *inode, int wait)
119 struct inode *cache_inode;
120 struct super_block *cache_sb;
123 cache_inode = I2CI(inode);
124 cache_sb = S2CSB(inode->i_sb);
126 if (!cache_inode || !cache_sb)
129 if (cache_sb->s_op->write_inode)
130 cache_sb->s_op->write_inode(cache_inode, wait);
132 duplicate_inode(cache_inode, inode);
136 static void smfs_dirty_inode(struct inode *inode)
138 struct inode *cache_inode;
139 struct super_block *cache_sb;
142 cache_inode = I2CI(inode);
143 cache_sb = S2CSB(inode->i_sb);
145 if (!cache_inode || !cache_sb)
148 if (cache_sb->s_op->dirty_inode)
149 cache_sb->s_op->dirty_inode(cache_inode);
151 duplicate_inode(cache_inode, inode);
155 static void smfs_put_inode(struct inode *inode)
157 struct inode *cache_inode;
158 struct super_block *cache_sb;
161 cache_inode = I2CI(inode);
162 cache_sb = S2CSB(inode->i_sb);
164 if (!cache_inode || !cache_sb)
171 static void smfs_write_super(struct super_block *sb)
173 struct super_block *cache_sb;
176 cache_sb = S2CSB(sb);
181 if (cache_sb->s_op->write_super)
182 cache_sb->s_op->write_super(cache_sb);
184 duplicate_sb(cache_sb, sb);
188 static void smfs_write_super_lockfs(struct super_block *sb)
190 struct super_block *cache_sb;
193 cache_sb = S2CSB(sb);
198 if (cache_sb->s_op->write_super_lockfs)
199 cache_sb->s_op->write_super_lockfs(cache_sb);
201 duplicate_sb(cache_sb, sb);
205 static void smfs_unlockfs(struct super_block *sb)
207 struct super_block *cache_sb;
210 cache_sb = S2CSB(sb);
215 if (cache_sb->s_op->unlockfs)
216 cache_sb->s_op->unlockfs(cache_sb);
218 duplicate_sb(cache_sb, sb);
221 static int smfs_statfs(struct super_block * sb, struct statfs * buf)
223 struct super_block *cache_sb;
227 cache_sb = S2CSB(sb);
232 if (cache_sb->s_op->statfs)
233 rc = cache_sb->s_op->statfs(cache_sb, buf);
235 duplicate_sb(cache_sb, sb);
239 static int smfs_remount(struct super_block * sb, int * flags, char * data)
241 struct super_block *cache_sb;
245 cache_sb = S2CSB(sb);
250 if (cache_sb->s_op->remount_fs)
251 rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
253 duplicate_sb(cache_sb, sb);
256 struct super_operations smfs_super_ops = {
257 read_inode: smfs_read_inode,
258 //clear_inode: smfs_clear_inode,
259 put_super: smfs_put_super,
260 delete_inode: smfs_delete_inode,
261 write_inode: smfs_write_inode,
262 dirty_inode: smfs_dirty_inode, /* BKL not held. We take it */
263 put_inode: smfs_put_inode, /* BKL not held. Don't need */
265 write_super: smfs_write_super, /* BKL held */
266 write_super_lockfs: smfs_write_super_lockfs, /* BKL not held. Take it */
267 unlockfs: smfs_unlockfs, /* BKL not held. We take it */
268 statfs: smfs_statfs, /* BKL held */
269 remount_fs: smfs_remount, /* BKL held */