Whamcloud - gitweb
Update smfs: some fix about clear_inode in smfs
[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         duplicate_inode(inode, cache_inode);
83         
84         return; 
85 }
86 static void smfs_delete_inode(struct inode *inode)
87 {
88         struct inode *cache_inode;
89         struct super_block *cache_sb;
90
91         ENTRY;
92         cache_inode = I2CI(inode);
93         cache_sb = S2CSB(inode->i_sb);
94
95         if (!cache_inode || !cache_sb || 
96             !cache_inode->i_nlink) {
97                 clear_inode(inode);     
98                 return;
99         }       
100         duplicate_inode(inode, cache_inode); 
101         
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);
106         
107         if (cache_inode->i_data.nrpages)
108                 truncate_inode_pages(&cache_inode->i_data, 0);
109         
110         if (cache_sb->s_op->delete_inode)
111                 cache_sb->s_op->delete_inode(cache_inode);
112
113         duplicate_inode(cache_inode, inode); 
114         
115         return;
116 }
117 static void smfs_write_inode(struct inode *inode, int wait)
118 {
119         struct inode *cache_inode;
120         struct super_block *cache_sb;
121
122         ENTRY;
123         cache_inode = I2CI(inode);
124         cache_sb = S2CSB(inode->i_sb);
125
126         if (!cache_inode || !cache_sb)
127                 return;
128                 
129         if (cache_sb->s_op->write_inode)
130                 cache_sb->s_op->write_inode(cache_inode, wait);
131
132         duplicate_inode(cache_inode, inode); 
133         
134         return;
135 }
136 static void smfs_dirty_inode(struct inode *inode)
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         if (cache_sb->s_op->dirty_inode)
149                 cache_sb->s_op->dirty_inode(cache_inode);
150
151         duplicate_inode(cache_inode, inode); 
152         return;
153 }
154
155 static void smfs_put_inode(struct inode *inode)
156 {
157         struct inode *cache_inode;
158         struct super_block *cache_sb;
159
160         ENTRY;
161         cache_inode = I2CI(inode);
162         cache_sb = S2CSB(inode->i_sb);
163
164         if (!cache_inode || !cache_sb)
165                 return;
166         iput(cache_inode);
167
168         return;
169 }
170
171 static void smfs_write_super(struct super_block *sb)
172 {
173         struct super_block *cache_sb;
174
175         ENTRY;
176         cache_sb = S2CSB(sb);
177
178         if (!cache_sb)
179                 return;
180                 
181         if (cache_sb->s_op->write_super)
182                 cache_sb->s_op->write_super(cache_sb);
183
184         duplicate_sb(cache_sb, sb);
185         return;
186 }
187
188 static void smfs_write_super_lockfs(struct super_block *sb)
189 {
190         struct super_block *cache_sb;
191
192         ENTRY;
193         cache_sb = S2CSB(sb);
194
195         if (!cache_sb)
196                 return;
197                 
198         if (cache_sb->s_op->write_super_lockfs)
199                 cache_sb->s_op->write_super_lockfs(cache_sb);
200
201         duplicate_sb(cache_sb, sb);
202         return;
203 }
204
205 static void smfs_unlockfs(struct super_block *sb)
206 {
207         struct super_block *cache_sb;
208
209         ENTRY;
210         cache_sb = S2CSB(sb);
211
212         if (!cache_sb)
213                 return;
214                 
215         if (cache_sb->s_op->unlockfs)
216                 cache_sb->s_op->unlockfs(cache_sb);
217
218         duplicate_sb(cache_sb, sb);
219         return;
220 }
221 static int smfs_statfs(struct super_block * sb, struct statfs * buf) 
222 {
223         struct super_block *cache_sb;
224         int     rc = 0;
225
226         ENTRY;
227         cache_sb = S2CSB(sb);
228
229         if (!cache_sb)
230                 RETURN(-EINVAL);
231                 
232         if (cache_sb->s_op->statfs)
233                 rc = cache_sb->s_op->statfs(cache_sb, buf);
234
235         duplicate_sb(cache_sb, sb);
236         
237         return rc;
238 }
239 static int smfs_remount(struct super_block * sb, int * flags, char * data)
240 {
241         struct super_block *cache_sb;
242         int    rc = 0;
243
244         ENTRY;
245         cache_sb = S2CSB(sb);
246
247         if (!cache_sb)
248                 RETURN(-EINVAL);
249                 
250         if (cache_sb->s_op->remount_fs)
251                 rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
252
253         duplicate_sb(cache_sb, sb);
254         RETURN(rc);
255 }
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 */
264
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 */
270
271 };
272
273
274
275
276