Whamcloud - gitweb
update smfs 1)fix read file bugs 2)add some superblock operations 3)some minor fix
[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         clear_inode(cache_inode);
83         duplicate_inode(inode, cache_inode);
84         
85         return; 
86 }
87 static void smfs_delete_inode(struct inode *inode)
88 {
89         struct inode *cache_inode;
90         struct super_block *cache_sb;
91
92         ENTRY;
93         cache_inode = I2CI(inode);
94         cache_sb = S2CSB(inode->i_sb);
95
96         if (!cache_inode || !cache_sb)
97                 return;
98                 
99         duplicate_inode(inode, cache_inode); 
100         
101         if (cache_sb->s_op->delete_inode)
102                 cache_sb->s_op->delete_inode(cache_inode);
103
104         duplicate_inode(cache_inode, inode); 
105         
106         return;
107 }
108 static void smfs_write_inode(struct inode *inode, int wait)
109 {
110         struct inode *cache_inode;
111         struct super_block *cache_sb;
112
113         ENTRY;
114         cache_inode = I2CI(inode);
115         cache_sb = S2CSB(inode->i_sb);
116
117         if (!cache_inode || !cache_sb)
118                 return;
119                 
120         if (cache_sb->s_op->write_inode)
121                 cache_sb->s_op->write_inode(cache_inode, wait);
122
123         duplicate_inode(cache_inode, inode); 
124         
125         return;
126 }
127 static void smfs_dirty_inode(struct inode *inode)
128 {
129         struct inode *cache_inode;
130         struct super_block *cache_sb;
131
132         ENTRY;
133         cache_inode = I2CI(inode);
134         cache_sb = S2CSB(inode->i_sb);
135
136         if (!cache_inode || !cache_sb)
137                 return;
138                 
139         if (cache_sb->s_op->dirty_inode)
140                 cache_sb->s_op->dirty_inode(cache_inode);
141
142         duplicate_inode(cache_inode, inode); 
143         return;
144 }
145
146 static void smfs_put_inode(struct inode *inode)
147 {
148         struct inode *cache_inode;
149         struct super_block *cache_sb;
150
151         ENTRY;
152         cache_inode = I2CI(inode);
153         cache_sb = S2CSB(inode->i_sb);
154
155         if (!cache_inode || !cache_sb)
156                 return;
157                 
158         if (cache_sb->s_op->put_inode)
159                 cache_sb->s_op->put_inode(cache_inode);
160
161         return;
162 }
163
164 static void smfs_write_super(struct super_block *sb)
165 {
166         struct super_block *cache_sb;
167
168         ENTRY;
169         cache_sb = S2CSB(sb);
170
171         if (!cache_sb)
172                 return;
173                 
174         if (cache_sb->s_op->write_super)
175                 cache_sb->s_op->write_super(cache_sb);
176
177         duplicate_sb(cache_sb, sb);
178         return;
179 }
180
181 static void smfs_write_super_lockfs(struct super_block *sb)
182 {
183         struct super_block *cache_sb;
184
185         ENTRY;
186         cache_sb = S2CSB(sb);
187
188         if (!cache_sb)
189                 return;
190                 
191         if (cache_sb->s_op->write_super_lockfs)
192                 cache_sb->s_op->write_super_lockfs(cache_sb);
193
194         duplicate_sb(cache_sb, sb);
195         return;
196 }
197
198 static void smfs_unlockfs(struct super_block *sb)
199 {
200         struct super_block *cache_sb;
201
202         ENTRY;
203         cache_sb = S2CSB(sb);
204
205         if (!cache_sb)
206                 return;
207                 
208         if (cache_sb->s_op->unlockfs)
209                 cache_sb->s_op->unlockfs(cache_sb);
210
211         duplicate_sb(cache_sb, sb);
212         return;
213 }
214 static void smfs_statfs(struct super_block * sb, struct statfs * buf) 
215 {
216         struct super_block *cache_sb;
217
218         ENTRY;
219         cache_sb = S2CSB(sb);
220
221         if (!cache_sb)
222                 return;
223                 
224         if (cache_sb->s_op->statfs)
225                 cache_sb->s_op->statfs(cache_sb, buf);
226
227         duplicate_sb(cache_sb, sb);
228         return;
229 }
230 static int smfs_remount(struct super_block * sb, int * flags, char * data)
231 {
232         struct super_block *cache_sb;
233         int    rc = 0;
234
235         ENTRY;
236         cache_sb = S2CSB(sb);
237
238         if (!cache_sb)
239                 RETURN(-EINVAL);
240                 
241         if (cache_sb->s_op->remount_fs)
242                 rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
243
244         duplicate_sb(cache_sb, sb);
245         RETURN(rc);
246 }
247 struct super_operations smfs_super_ops = {
248         read_inode:     smfs_read_inode,
249         clear_inode:    smfs_clear_inode,
250         put_super:      smfs_put_super,
251         delete_inode:   smfs_delete_inode,
252         write_inode:    smfs_write_inode,
253         dirty_inode:    smfs_dirty_inode,       /* BKL not held.  We take it */
254         put_inode:      smfs_put_inode,         /* BKL not held.  Don't need */
255
256         write_super:    smfs_write_super,       /* BKL held */
257         write_super_lockfs: smfs_write_super_lockfs, /* BKL not held. Take it */
258         unlockfs:       smfs_unlockfs,          /* BKL not held.  We take it */
259         statfs:         smfs_statfs,            /* BKL held */
260         remount_fs:     smfs_remount,           /* BKL held */
261
262 };
263
264
265
266
267