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