Whamcloud - gitweb
1. Adding iput(cache_inode) in smfs_clear_inode for clearing cache inode 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 "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         iput(cache_inode);
77
78         return; 
79 }
80 static void smfs_delete_inode(struct inode *inode)
81 {
82         struct inode *cache_inode;
83         struct super_block *cache_sb;
84
85         ENTRY;
86         cache_inode = I2CI(inode);
87         cache_sb = S2CSB(inode->i_sb);
88
89         if (!cache_inode || !cache_sb)  
90                 return;
91
92         /*FIXME: because i_count of cache_inode may not 
93          * be 0 or 1 in before smfs_delete inode, So we 
94          * need to dec it to 1 before we call delete_inode
95          * of the bellow cache filesystem Check again latter*/
96
97         if (atomic_read(&cache_inode->i_count) < 1)
98                 BUG();
99         
100         while (atomic_read(&cache_inode->i_count) != 1) {
101                 atomic_dec(&cache_inode->i_count);
102         }
103         
104         duplicate_inode(inode, cache_inode); 
105         
106         list_del(&cache_inode->i_hash);
107         INIT_LIST_HEAD(&cache_inode->i_hash);
108         list_del(&cache_inode->i_list);
109         INIT_LIST_HEAD(&cache_inode->i_list);
110         
111         if (cache_inode->i_data.nrpages)
112                 truncate_inode_pages(&cache_inode->i_data, 0);
113         
114         if (cache_sb->s_op->delete_inode)
115                 cache_sb->s_op->delete_inode(cache_inode);
116
117         duplicate_inode(cache_inode, inode); 
118         
119         return;
120 }
121 static void smfs_write_inode(struct inode *inode, int wait)
122 {
123         struct inode *cache_inode;
124         struct super_block *cache_sb;
125
126         ENTRY;
127         cache_inode = I2CI(inode);
128         cache_sb = S2CSB(inode->i_sb);
129
130         if (!cache_inode || !cache_sb)
131                 return;
132                 
133         if (cache_sb->s_op->write_inode)
134                 cache_sb->s_op->write_inode(cache_inode, wait);
135
136         duplicate_inode(cache_inode, inode); 
137         
138         return;
139 }
140 static void smfs_dirty_inode(struct inode *inode)
141 {
142         struct inode *cache_inode;
143         struct super_block *cache_sb;
144
145         ENTRY;
146         cache_inode = I2CI(inode);
147         cache_sb = S2CSB(inode->i_sb);
148
149         if (!cache_inode || !cache_sb)
150                 return;
151                 
152         if (cache_sb->s_op->dirty_inode)
153                 cache_sb->s_op->dirty_inode(cache_inode);
154
155         duplicate_inode(cache_inode, inode); 
156         return;
157 }
158
159 static void smfs_put_inode(struct inode *inode)
160 {
161         struct inode *cache_inode;
162         struct super_block *cache_sb;
163
164         ENTRY;
165         cache_inode = I2CI(inode);
166         cache_sb = S2CSB(inode->i_sb);
167
168         if (!cache_inode || !cache_sb)
169                 return;
170         if (cache_sb->s_op->put_inode)
171                 cache_sb->s_op->put_inode(cache_inode);
172
173         return;
174 }
175
176 static void smfs_write_super(struct super_block *sb)
177 {
178         struct super_block *cache_sb;
179
180         ENTRY;
181         cache_sb = S2CSB(sb);
182
183         if (!cache_sb)
184                 return;
185                 
186         if (cache_sb->s_op->write_super)
187                 cache_sb->s_op->write_super(cache_sb);
188
189         duplicate_sb(cache_sb, sb);
190         return;
191 }
192
193 static void smfs_write_super_lockfs(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_lockfs)
204                 cache_sb->s_op->write_super_lockfs(cache_sb);
205
206         duplicate_sb(cache_sb, sb);
207         return;
208 }
209
210 static void smfs_unlockfs(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->unlockfs)
221                 cache_sb->s_op->unlockfs(cache_sb);
222
223         duplicate_sb(cache_sb, sb);
224         return;
225 }
226 static int smfs_statfs(struct super_block * sb, struct statfs * buf) 
227 {
228         struct super_block *cache_sb;
229         int     rc = 0;
230
231         ENTRY;
232         cache_sb = S2CSB(sb);
233
234         if (!cache_sb)
235                 RETURN(-EINVAL);
236                 
237         if (cache_sb->s_op->statfs)
238                 rc = cache_sb->s_op->statfs(cache_sb, buf);
239
240         duplicate_sb(cache_sb, sb);
241         
242         return rc;
243 }
244 static int smfs_remount(struct super_block * sb, int * flags, char * data)
245 {
246         struct super_block *cache_sb;
247         int    rc = 0;
248
249         ENTRY;
250         cache_sb = S2CSB(sb);
251
252         if (!cache_sb)
253                 RETURN(-EINVAL);
254                 
255         if (cache_sb->s_op->remount_fs)
256                 rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
257
258         duplicate_sb(cache_sb, sb);
259         RETURN(rc);
260 }
261 struct super_operations smfs_super_ops = {
262         read_inode:     smfs_read_inode,
263         clear_inode:    smfs_clear_inode,
264         put_super:      smfs_put_super,
265         delete_inode:   smfs_delete_inode,
266         write_inode:    smfs_write_inode,
267         dirty_inode:    smfs_dirty_inode,       /* BKL not held.  We take it */
268         put_inode:      smfs_put_inode,         /* BKL not held.  Don't need */
269
270         write_super:    smfs_write_super,       /* BKL held */
271         write_super_lockfs: smfs_write_super_lockfs, /* BKL not held. Take it */
272         unlockfs:       smfs_unlockfs,          /* BKL not held.  We take it */
273         statfs:         smfs_statfs,            /* BKL held */
274         remount_fs:     smfs_remount,           /* BKL held */
275
276 };
277
278
279
280
281