Whamcloud - gitweb
copy inode attribute to bottom inode in smfs_dirty_inode
[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         duplicate_inode(inode, cache_inode); 
167         if (cache_sb->s_op->dirty_inode)
168                 cache_sb->s_op->dirty_inode(cache_inode);
169
170         duplicate_inode(cache_inode, inode); 
171         return;
172 }
173
174 static void smfs_put_inode(struct inode *inode)
175 {
176         struct inode *cache_inode;
177         struct super_block *cache_sb;
178
179         ENTRY;
180         cache_inode = I2CI(inode);
181         cache_sb = S2CSB(inode->i_sb);
182
183         if (!cache_inode || !cache_sb)
184                 return;
185         if (cache_sb->s_op->put_inode)
186                 cache_sb->s_op->put_inode(cache_inode);
187
188         return;
189 }
190
191 static void smfs_write_super(struct super_block *sb)
192 {
193         struct super_block *cache_sb;
194
195         ENTRY;
196         cache_sb = S2CSB(sb);
197
198         if (!cache_sb)
199                 return;
200                 
201         if (cache_sb->s_op->write_super)
202                 cache_sb->s_op->write_super(cache_sb);
203
204         duplicate_sb(cache_sb, sb);
205         return;
206 }
207
208 static void smfs_write_super_lockfs(struct super_block *sb)
209 {
210         struct super_block *cache_sb;
211
212         ENTRY;
213         cache_sb = S2CSB(sb);
214
215         if (!cache_sb)
216                 return;
217                 
218         if (cache_sb->s_op->write_super_lockfs)
219                 cache_sb->s_op->write_super_lockfs(cache_sb);
220
221         duplicate_sb(cache_sb, sb);
222         return;
223 }
224
225 static void smfs_unlockfs(struct super_block *sb)
226 {
227         struct super_block *cache_sb;
228
229         ENTRY;
230         cache_sb = S2CSB(sb);
231
232         if (!cache_sb)
233                 return;
234                 
235         if (cache_sb->s_op->unlockfs)
236                 cache_sb->s_op->unlockfs(cache_sb);
237
238         duplicate_sb(cache_sb, sb);
239         return;
240 }
241 static int smfs_statfs(struct super_block * sb, struct statfs * buf) 
242 {
243         struct super_block *cache_sb;
244         int     rc = 0;
245
246         ENTRY;
247         cache_sb = S2CSB(sb);
248
249         if (!cache_sb)
250                 RETURN(-EINVAL);
251                 
252         if (cache_sb->s_op->statfs)
253                 rc = cache_sb->s_op->statfs(cache_sb, buf);
254
255         duplicate_sb(cache_sb, sb);
256         
257         return rc;
258 }
259 static int smfs_remount(struct super_block * sb, int * flags, char * data)
260 {
261         struct super_block *cache_sb;
262         int    rc = 0;
263
264         ENTRY;
265         cache_sb = S2CSB(sb);
266
267         if (!cache_sb)
268                 RETURN(-EINVAL);
269                 
270         if (cache_sb->s_op->remount_fs)
271                 rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
272
273         duplicate_sb(cache_sb, sb);
274         RETURN(rc);
275 }
276 struct super_operations smfs_super_ops = {
277         read_inode:     smfs_read_inode,
278         clear_inode:    smfs_clear_inode,
279         put_super:      smfs_put_super,
280         delete_inode:   smfs_delete_inode,
281         write_inode:    smfs_write_inode,
282         dirty_inode:    smfs_dirty_inode,       /* BKL not held.  We take it */
283         put_inode:      smfs_put_inode,         /* BKL not held.  Don't need */
284
285         write_super:    smfs_write_super,       /* BKL held */
286         write_super_lockfs: smfs_write_super_lockfs, /* BKL not held. Take it */
287         unlockfs:       smfs_unlockfs,          /* BKL not held.  We take it */
288         statfs:         smfs_statfs,            /* BKL held */
289         remount_fs:     smfs_remount,           /* BKL held */
290
291 };
292
293
294
295
296