Whamcloud - gitweb
Update smfs 1. Use d_alloc to alloc the cache dentry 2. some minor fixs
[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         /*FIXME: because i_count of cache_inode may not 
78          * be 0 or 1 in before smfs_delete inode, So we 
79          * need to dec it to 1 before we call delete_inode
80          * of the bellow cache filesystem Check again latter*/
81
82         if (atomic_read(&cache_inode->i_count) < 1)
83                 BUG();
84         
85         while (atomic_read(&cache_inode->i_count) != 1) {
86                 atomic_dec(&cache_inode->i_count);
87         }
88         iput(cache_inode);
89         
90         I2CI(inode) = NULL;
91         return; 
92 }
93 static void smfs_delete_inode(struct inode *inode)
94 {
95         struct inode *cache_inode;
96         struct super_block *cache_sb;
97
98         ENTRY;
99         cache_inode = I2CI(inode);
100         cache_sb = S2CSB(inode->i_sb);
101
102         if (!cache_inode || !cache_sb)  
103                 return;
104
105         /*FIXME: because i_count of cache_inode may not 
106          * be 0 or 1 in before smfs_delete inode, So we 
107          * need to dec it to 1 before we call delete_inode
108          * of the bellow cache filesystem Check again latter*/
109
110         if (atomic_read(&cache_inode->i_count) < 1)
111                 BUG();
112         
113         while (atomic_read(&cache_inode->i_count) != 1) {
114                 atomic_dec(&cache_inode->i_count);
115         }
116         
117         duplicate_inode(inode, cache_inode); 
118         
119         list_del(&cache_inode->i_hash);
120         INIT_LIST_HEAD(&cache_inode->i_hash);
121         list_del(&cache_inode->i_list);
122         INIT_LIST_HEAD(&cache_inode->i_list);
123         
124         if (cache_inode->i_data.nrpages)
125                 truncate_inode_pages(&cache_inode->i_data, 0);
126         
127         if (cache_sb->s_op->delete_inode)
128                 cache_sb->s_op->delete_inode(cache_inode);
129
130         duplicate_inode(cache_inode, inode); 
131         
132         I2CI(inode) = NULL;
133         return;
134 }
135 static void smfs_write_inode(struct inode *inode, int wait)
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->write_inode)
148                 cache_sb->s_op->write_inode(cache_inode, wait);
149
150         duplicate_inode(cache_inode, inode); 
151         
152         return;
153 }
154 static void smfs_dirty_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->dirty_inode)
167                 cache_sb->s_op->dirty_inode(cache_inode);
168
169         duplicate_inode(cache_inode, inode); 
170         return;
171 }
172
173 static void smfs_put_inode(struct inode *inode)
174 {
175         struct inode *cache_inode;
176         struct super_block *cache_sb;
177
178         ENTRY;
179         cache_inode = I2CI(inode);
180         cache_sb = S2CSB(inode->i_sb);
181
182         if (!cache_inode || !cache_sb)
183                 return;
184         if (cache_sb->s_op->put_inode)
185                 cache_sb->s_op->put_inode(cache_inode);
186
187         return;
188 }
189
190 static void smfs_write_super(struct super_block *sb)
191 {
192         struct super_block *cache_sb;
193
194         ENTRY;
195         cache_sb = S2CSB(sb);
196
197         if (!cache_sb)
198                 return;
199                 
200         if (cache_sb->s_op->write_super)
201                 cache_sb->s_op->write_super(cache_sb);
202
203         duplicate_sb(cache_sb, sb);
204         return;
205 }
206
207 static void smfs_write_super_lockfs(struct super_block *sb)
208 {
209         struct super_block *cache_sb;
210
211         ENTRY;
212         cache_sb = S2CSB(sb);
213
214         if (!cache_sb)
215                 return;
216                 
217         if (cache_sb->s_op->write_super_lockfs)
218                 cache_sb->s_op->write_super_lockfs(cache_sb);
219
220         duplicate_sb(cache_sb, sb);
221         return;
222 }
223
224 static void smfs_unlockfs(struct super_block *sb)
225 {
226         struct super_block *cache_sb;
227
228         ENTRY;
229         cache_sb = S2CSB(sb);
230
231         if (!cache_sb)
232                 return;
233                 
234         if (cache_sb->s_op->unlockfs)
235                 cache_sb->s_op->unlockfs(cache_sb);
236
237         duplicate_sb(cache_sb, sb);
238         return;
239 }
240 static int smfs_statfs(struct super_block * sb, struct statfs * buf) 
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->statfs)
252                 rc = cache_sb->s_op->statfs(cache_sb, buf);
253
254         duplicate_sb(cache_sb, sb);
255         
256         return rc;
257 }
258 static int smfs_remount(struct super_block * sb, int * flags, char * data)
259 {
260         struct super_block *cache_sb;
261         int    rc = 0;
262
263         ENTRY;
264         cache_sb = S2CSB(sb);
265
266         if (!cache_sb)
267                 RETURN(-EINVAL);
268                 
269         if (cache_sb->s_op->remount_fs)
270                 rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
271
272         duplicate_sb(cache_sb, sb);
273         RETURN(rc);
274 }
275 struct super_operations smfs_super_ops = {
276         read_inode:     smfs_read_inode,
277         clear_inode:    smfs_clear_inode,
278         put_super:      smfs_put_super,
279         delete_inode:   smfs_delete_inode,
280         write_inode:    smfs_write_inode,
281         dirty_inode:    smfs_dirty_inode,       /* BKL not held.  We take it */
282         put_inode:      smfs_put_inode,         /* BKL not held.  Don't need */
283
284         write_super:    smfs_write_super,       /* BKL held */
285         write_super_lockfs: smfs_write_super_lockfs, /* BKL not held. Take it */
286         unlockfs:       smfs_unlockfs,          /* BKL not held.  We take it */
287         statfs:         smfs_statfs,            /* BKL held */
288         remount_fs:     smfs_remount,           /* BKL held */
289
290 };
291
292
293
294
295