Whamcloud - gitweb
update smfs 1)delete inode->i_list in smfs_delete_inode for the cache inode will...
[fs/lustre-release.git] / lustre / smfs / inode.c
1 /*
2  *  smfs/inode.c
3  *
4  */
5
6 #define DEBUG_SUBSYSTEM S_SM
7
8 #include <linux/kmod.h>
9 #include <linux/init.h>
10 #include <linux/fs.h>
11 #include <linux/slab.h>
12 #include <linux/string.h>
13 #include "smfs_internal.h" 
14
15 void duplicate_inode(struct inode *cache_inode, struct inode *inode)
16 {
17         
18         inode->i_mode = cache_inode->i_mode;
19         inode->i_uid = cache_inode->i_uid;
20         inode->i_gid = cache_inode->i_gid;
21
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
29                                          * size */  
30         inode->i_blocks = cache_inode->i_blocks;
31         inode->i_version = cache_inode->i_version;
32         inode->i_state = cache_inode->i_state;
33 }
34 static void smfs_read_inode(struct inode *inode)
35 {
36         struct super_block *cache_sb;
37         struct inode *cache_inode;      
38         ENTRY;
39
40         if (!inode) 
41                 return;
42         
43         CDEBUG(D_INODE, "read_inode ino %lu\n", inode->i_ino);
44         cache_sb = S2CSB(inode->i_sb);
45
46         cache_inode = iget(cache_sb, inode->i_ino);
47         I2CI(inode) = cache_inode;
48         
49         if(cache_sb && cache_sb->s_op->read_inode)
50                 cache_sb->s_op->read_inode(cache_inode);
51
52         duplicate_inode(cache_inode, inode);
53         sm_set_inode_ops(cache_inode, inode);
54         
55         CDEBUG(D_INODE, "read_inode ino %lu icount %d \n", 
56                inode->i_ino, atomic_read(&inode->i_count));
57         
58         iput(cache_inode);      
59         return; 
60 }
61 /* Although some filesystem(such as ext3) do not have
62  * clear_inode method, but we need it to free the 
63  * cache inode 
64  */
65 static void smfs_clear_inode(struct inode *inode)
66 {
67         struct super_block *cache_sb;
68         struct inode *cache_inode;      
69
70         ENTRY;
71         
72         if (!inode) return;
73         
74         cache_sb = S2CSB(inode->i_sb);
75         cache_inode = I2CI(inode);
76
77         duplicate_inode(inode, cache_inode); 
78         
79         if (cache_sb->s_op->clear_inode)
80                 cache_sb->s_op->clear_inode(cache_inode);
81
82         //clear_inode(cache_inode);
83         duplicate_inode(inode, cache_inode);
84         
85         return; 
86 }
87 static void smfs_delete_inode(struct inode *inode)
88 {
89         struct inode *cache_inode;
90         struct super_block *cache_sb;
91
92         ENTRY;
93         cache_inode = I2CI(inode);
94         cache_sb = S2CSB(inode->i_sb);
95
96         if (!cache_inode || !cache_sb)
97                 return;
98                 
99         duplicate_inode(inode, cache_inode); 
100         
101         list_del(&cache_inode->i_hash);
102         INIT_LIST_HEAD(&cache_inode->i_hash);
103         list_del(&cache_inode->i_list);
104         INIT_LIST_HEAD(&cache_inode->i_list);
105         
106         if (cache_inode->i_data.nrpages)
107                 truncate_inode_pages(&cache_inode->i_data, 0);
108         
109         if (cache_sb->s_op->delete_inode)
110                 cache_sb->s_op->delete_inode(cache_inode);
111
112         duplicate_inode(cache_inode, inode); 
113         
114         return;
115 }
116 static void smfs_write_inode(struct inode *inode, int wait)
117 {
118         struct inode *cache_inode;
119         struct super_block *cache_sb;
120
121         ENTRY;
122         cache_inode = I2CI(inode);
123         cache_sb = S2CSB(inode->i_sb);
124
125         if (!cache_inode || !cache_sb)
126                 return;
127                 
128         if (cache_sb->s_op->write_inode)
129                 cache_sb->s_op->write_inode(cache_inode, wait);
130
131         duplicate_inode(cache_inode, inode); 
132         
133         return;
134 }
135 static void smfs_dirty_inode(struct inode *inode)
136 {
137         struct inode *cache_inode;
138         struct super_block *cache_sb;
139
140         ENTRY;
141         cache_inode = I2CI(inode);
142         cache_sb = S2CSB(inode->i_sb);
143
144         if (!cache_inode || !cache_sb)
145                 return;
146                 
147         if (cache_sb->s_op->dirty_inode)
148                 cache_sb->s_op->dirty_inode(cache_inode);
149
150         duplicate_inode(cache_inode, inode); 
151         return;
152 }
153
154 static void smfs_put_inode(struct inode *inode)
155 {
156         struct inode *cache_inode;
157         struct super_block *cache_sb;
158
159         ENTRY;
160         cache_inode = I2CI(inode);
161         cache_sb = S2CSB(inode->i_sb);
162
163         if (!cache_inode || !cache_sb)
164                 return;
165                 
166         if (cache_sb->s_op->put_inode)
167                 cache_sb->s_op->put_inode(cache_inode);
168
169         return;
170 }
171
172 static void smfs_write_super(struct super_block *sb)
173 {
174         struct super_block *cache_sb;
175
176         ENTRY;
177         cache_sb = S2CSB(sb);
178
179         if (!cache_sb)
180                 return;
181                 
182         if (cache_sb->s_op->write_super)
183                 cache_sb->s_op->write_super(cache_sb);
184
185         duplicate_sb(cache_sb, sb);
186         return;
187 }
188
189 static void smfs_write_super_lockfs(struct super_block *sb)
190 {
191         struct super_block *cache_sb;
192
193         ENTRY;
194         cache_sb = S2CSB(sb);
195
196         if (!cache_sb)
197                 return;
198                 
199         if (cache_sb->s_op->write_super_lockfs)
200                 cache_sb->s_op->write_super_lockfs(cache_sb);
201
202         duplicate_sb(cache_sb, sb);
203         return;
204 }
205
206 static void smfs_unlockfs(struct super_block *sb)
207 {
208         struct super_block *cache_sb;
209
210         ENTRY;
211         cache_sb = S2CSB(sb);
212
213         if (!cache_sb)
214                 return;
215                 
216         if (cache_sb->s_op->unlockfs)
217                 cache_sb->s_op->unlockfs(cache_sb);
218
219         duplicate_sb(cache_sb, sb);
220         return;
221 }
222 static int smfs_statfs(struct super_block * sb, struct statfs * buf) 
223 {
224         struct super_block *cache_sb;
225         int     rc = 0;
226
227         ENTRY;
228         cache_sb = S2CSB(sb);
229
230         if (!cache_sb)
231                 return;
232                 
233         if (cache_sb->s_op->statfs)
234                 rc = cache_sb->s_op->statfs(cache_sb, buf);
235
236         duplicate_sb(cache_sb, sb);
237         
238         return rc;
239 }
240 static int smfs_remount(struct super_block * sb, int * flags, char * data)
241 {
242         struct super_block *cache_sb;
243         int    rc = 0;
244
245         ENTRY;
246         cache_sb = S2CSB(sb);
247
248         if (!cache_sb)
249                 RETURN(-EINVAL);
250                 
251         if (cache_sb->s_op->remount_fs)
252                 rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
253
254         duplicate_sb(cache_sb, sb);
255         RETURN(rc);
256 }
257 struct super_operations smfs_super_ops = {
258         read_inode:     smfs_read_inode,
259         //clear_inode:  smfs_clear_inode,
260         put_super:      smfs_put_super,
261         delete_inode:   smfs_delete_inode,
262         write_inode:    smfs_write_inode,
263         dirty_inode:    smfs_dirty_inode,       /* BKL not held.  We take it */
264         put_inode:      smfs_put_inode,         /* BKL not held.  Don't need */
265
266         write_super:    smfs_write_super,       /* BKL held */
267         write_super_lockfs: smfs_write_super_lockfs, /* BKL not held. Take it */
268         unlockfs:       smfs_unlockfs,          /* BKL not held.  We take it */
269         statfs:         smfs_statfs,            /* BKL held */
270         remount_fs:     smfs_remount,           /* BKL held */
271
272 };
273
274
275
276
277