Whamcloud - gitweb
- remove non-needed CERROR
[fs/lustre-release.git] / lustre / smfs / inode.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/smfs/inode.c
5  *  Lustre filesystem abstraction routines
6  *
7  *  Copyright (C) 2004 Cluster File Systems, Inc.
8  *
9  *   This file is part of Lustre, http://www.lustre.org.
10  *
11  *   Lustre is free software; you can redistribute it and/or
12  *   modify it under the terms of version 2 of the GNU General Public
13  *   License as published by the Free Software Foundation.
14  *
15  *   Lustre is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with Lustre; if not, write to the Free Software
22  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 #define DEBUG_SUBSYSTEM S_SM
26
27 #include <linux/kmod.h>
28 #include <linux/init.h>
29 #include <linux/fs.h>
30 #include <linux/slab.h>
31 #include <linux/string.h>
32 #include <linux/obd_class.h>
33 #include <linux/obd_support.h>
34 #include <linux/lustre_lib.h>
35 #include <linux/lustre_idl.h>
36 #include <linux/lustre_fsfilt.h>
37 #include <linux/lustre_smfs.h>
38 #include "smfs_internal.h"
39
40 #define SMFS_IOPEN_INO  1
41
42 static void smfs_init_inode_info(struct inode *inode, void *opaque)
43 {
44         
45         struct inode *cache_inode = NULL;
46         struct smfs_iget_args *sargs = opaque;
47         unsigned long ino;
48
49         LASSERTF((!I2SMI(inode)), "Inode %lu already has smfs_inode_info %p \n",
50                  inode->i_ino, I2SMI(inode));
51         
52         /* getting backing fs inode. */
53         LASSERT(sargs);
54         ino = inode->i_ino;
55         cache_inode = iget(S2CSB(inode->i_sb), ino); 
56         
57         OBD_ALLOC(inode->u.generic_ip, sizeof(struct smfs_inode_info));
58
59         LASSERT(inode->u.generic_ip);
60               
61         I2CI(inode) = cache_inode;
62         CDEBUG(D_INODE,"Init inode info #%lu (%p) icount %u\n", inode->i_ino, inode, 
63                         atomic_read(&cache_inode->i_count));
64         
65         post_smfs_inode(inode, cache_inode);
66         sm_set_inode_ops(cache_inode, inode);
67         //iopen stuff
68         if (ino == SMFS_IOPEN_INO) {
69                 inode->i_op = &smfs_iopen_iops;
70                 inode->i_fop = &smfs_iopen_fops;
71         }
72         //inherit parent inode flags
73         if (sargs->s_inode) { 
74                 I2SMI(inode)->smi_flags = I2SMI(sargs->s_inode)->smi_flags;
75                 CDEBUG(D_INODE, "set inode %lu flags 0x%.8x\n", inode->i_ino,
76                       I2SMI(inode)->smi_flags);
77         } 
78 }
79
80 static void smfs_clear_inode_info(struct inode *inode)
81 {
82         struct inode *cache_inode = I2CI(inode);
83         struct smfs_inode_info * info = I2SMI(inode);
84         
85         CDEBUG(D_INODE, "Clear_info: inode %lu (%p)\n", inode->i_ino, inode);
86
87         inode->u.generic_ip = NULL;      
88         iput(cache_inode);
89         OBD_FREE(info, sizeof(*info));
90 }
91
92 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
93 static void smfs_read_inode2(struct inode *inode, void *opaque)
94 {
95         ENTRY;
96
97         if (!inode) {
98                 EXIT;
99                 return;
100         }
101         
102         smfs_init_inode_info(inode, opaque);
103         CDEBUG(D_INODE, "read_inode ino %lu icount %d \n",
104                inode->i_ino, atomic_read(&inode->i_count));
105         EXIT;
106 }
107
108 static int smfs_test_inode(struct inode *inode, unsigned long ino, 
109                            void *opaque)
110 #else
111 static int smfs_test_inode(struct inode *inode, void *opaque)
112 #endif
113 {
114         struct smfs_iget_args *sargs = (struct smfs_iget_args*)opaque;
115
116         if (!sargs || (inode->i_ino != sargs->s_ino))
117                 return 0;
118         
119 #ifdef CONFIG_SNAPFS
120         if (SMFS_DO_COW(S2SMI(inode->i_sb)) && 
121             !smfs_snap_test_inode(inode, opaque))
122                 return 0;  
123 #endif
124                 
125         return 1;
126 }
127
128 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
129 int smfs_set_inode(struct inode *inode, void *opaque)
130 {
131         struct smfs_iget_args *sargs = opaque;
132         
133         inode->i_ino = sargs->s_ino;
134         
135         return 0;
136 }
137
138 static struct inode *smfs_iget(struct super_block *sb, ino_t hash,
139                         struct smfs_iget_args *sargs)
140 {
141         struct inode *inode;
142         LASSERT(hash != 0);
143
144         inode = iget5_locked(sb, hash, smfs_test_inode,
145                              smfs_set_inode, sargs);
146         if (inode) {
147                 if (inode->i_state & I_NEW) {
148                         smfs_init_inode_info(inode, (void*)sargs);
149                         unlock_new_inode(inode);
150                 }
151                 
152                 CDEBUG(D_INODE, "inode: %lu/%u(%p) index %d "
153                        "ino %d\n", inode->i_ino, inode->i_generation,
154                        inode, sargs->s_index, sargs->s_ino);
155                 
156         }
157         return inode;
158 }
159 #else
160 struct inode *smfs_iget(struct super_block *sb, ino_t hash,
161                         struct smfs_iget_args *sargs)
162 {
163         struct inode *inode;
164         LASSERT(hash != 0);
165
166         inode = iget4(sb, hash, smfs_test_inode, sargs);
167         if (inode) {
168                 struct inode *cache_inode = I2CI(inode);
169                 
170                 CDEBUG(D_INODE, "new inode: %lu/%u(%p)\n", inode->i_ino,
171                        inode->i_generation, inode);
172         }
173         return inode;
174 }
175 #endif
176
177 struct inode *smfs_get_inode(struct super_block *sb, ino_t hash,
178                              struct inode *dir, int index)
179 {
180         struct smfs_iget_args sargs;
181         struct inode *inode;
182         ENTRY;
183        
184         sargs.s_ino = hash; 
185         sargs.s_inode = dir; 
186         sargs.s_index = index;
187         
188         inode = smfs_iget(sb, hash, &sargs);
189
190         RETURN(inode);
191 }
192 #ifdef FC3_KERNEL 
193 static int smfs_write_inode(struct inode *inode, int wait)
194 #else
195 static void smfs_write_inode(struct inode *inode, int wait)
196 #endif
197 {
198         struct inode *cache_inode = I2CI(inode);
199 #ifdef FC3_KERNEL
200         int rc = 0;
201 #endif        
202         ENTRY;
203
204         LASSERT(cache_inode);
205         
206         CDEBUG(D_INODE,"Write inode %lu\n",inode->i_ino);
207
208         pre_smfs_inode(inode, cache_inode);
209         
210 #ifdef FC3_KERNEL
211         rc = cache_inode->i_sb->s_op->write_inode(cache_inode, wait);
212 #else
213         cache_inode->i_sb->s_op->write_inode(cache_inode, wait);
214 #endif
215         post_smfs_inode(inode, cache_inode);
216         
217 #ifdef FC3_KERNEL
218         RETURN(rc);
219 #else
220         EXIT;
221 #endif
222 }
223
224 static void smfs_dirty_inode(struct inode *inode)
225 {
226         struct inode *cache_inode;
227         ENTRY;
228
229         cache_inode = I2CI(inode);
230         LASSERT(cache_inode);
231         
232         pre_smfs_inode(inode, cache_inode);
233     
234         S2CSB(inode->i_sb)->s_op->dirty_inode(cache_inode);
235
236         post_smfs_inode(inode, cache_inode);
237         EXIT;
238 }
239
240 static void smfs_delete_inode(struct inode *inode)
241 {
242         struct inode * cache_inode = I2CI(inode);
243
244         //smfs_clear_inode_info(inode);
245         clear_inode(inode);
246 }
247
248 static void smfs_clear_inode(struct inode *inode)
249 {
250         smfs_clear_inode_info(inode);
251 }
252
253 static void smfs_write_super(struct super_block *sb)
254 {
255         ENTRY;
256
257         LASSERT(S2CSB(sb));
258
259         S2CSB(sb)->s_op->write_super(S2CSB(sb));
260         duplicate_sb(sb, S2CSB(sb));
261         EXIT;
262 }
263
264 static void smfs_write_super_lockfs(struct super_block *sb)
265 {
266         struct super_block * cache_sb = S2CSB(sb);
267         ENTRY;
268
269         LASSERT(cache_sb);
270
271         cache_sb->s_op->write_super_lockfs(cache_sb);
272         duplicate_sb(sb, cache_sb);
273         EXIT;
274 }
275
276 static void smfs_unlockfs(struct super_block *sb)
277 {
278         struct super_block * cache_sb = S2CSB(sb);
279         ENTRY;
280
281         LASSERT(cache_sb);
282         
283         cache_sb->s_op->unlockfs(cache_sb);
284
285         duplicate_sb(sb, cache_sb);
286         EXIT;
287 }
288
289 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
290 static int smfs_statfs(struct super_block *sb, struct statfs *buf)
291 #else
292 static int smfs_statfs(struct super_block *sb, struct kstatfs *buf)
293 #endif
294 {
295         struct super_block *cache_sb = S2CSB(sb);
296         int rc = 0;
297         ENTRY;
298
299         LASSERT(cache_sb);
300
301         rc = cache_sb->s_op->statfs(cache_sb, buf);
302         duplicate_sb(sb, cache_sb);
303
304         RETURN(rc);
305 }
306
307 static int smfs_remount(struct super_block *sb, int *flags, char *data)
308 {
309         struct super_block *cache_sb = S2CSB(sb);
310         int rc = 0;
311         ENTRY;
312
313         LASSERT(cache_sb);
314
315         rc = cache_sb->s_op->remount_fs(cache_sb, flags, data);
316         duplicate_sb(sb, cache_sb);
317
318         RETURN(rc);
319 }
320
321 struct super_operations smfs_super_ops = {
322 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
323         .read_inode2        = smfs_read_inode2,
324 #endif 
325         .clear_inode        = smfs_clear_inode,
326         .put_super          = smfs_put_super,
327         .delete_inode       = smfs_delete_inode,
328         .write_inode        = smfs_write_inode,
329         .dirty_inode        = smfs_dirty_inode, /* BKL not held. */
330         .write_super        = smfs_write_super, /* BKL held */
331         .write_super_lockfs = smfs_write_super_lockfs, /* BKL not held. */
332         .unlockfs           = smfs_unlockfs,    /* BKL not held. */
333         .statfs             = smfs_statfs,      /* BKL held */
334         .remount_fs         = smfs_remount,     /* BKL held */
335 };
336
337