Whamcloud - gitweb
- landing b_fid.
[fs/lustre-release.git] / lustre / smfs / dir.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2004 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #define DEBUG_SUBSYSTEM S_SM
24
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/string.h>
28 #include <linux/slab.h>
29 #include <linux/stat.h>
30 #include <linux/unistd.h>
31 #include <linux/smp_lock.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 <linux/lustre_snap.h>
39
40 #include "smfs_internal.h"
41
42 #define NAME_ALLOC_LEN(len)     ((len+16) & ~15)
43
44 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
45 static int smfs_create(struct inode *dir, struct dentry *dentry,
46                        int mode)
47 #else
48 static int smfs_create(struct inode *dir, struct dentry *dentry,
49                        int mode, struct nameidata *nd)
50 #endif
51 {
52         struct inode  *inode = NULL;
53         struct inode  *cache_dir = NULL;
54         struct dentry *cache_dentry = NULL;
55         struct dentry *cache_parent = NULL;
56         void *handle = NULL;
57         int rc = 0;
58
59         ENTRY;
60
61         cache_dir = I2CI(dir);
62         if (!cache_dir)
63                 RETURN(-ENOENT);
64
65         handle = smfs_trans_start(dir, FSFILT_OP_CREATE, NULL);
66         if (IS_ERR(handle))
67                        RETURN(-ENOSPC);
68         
69         lock_kernel();
70         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_CREATE, handle,
71                   PRE_HOOK, rc, exit);
72         
73         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
74         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
75
76         if (!cache_dentry || !cache_parent)
77                 GOTO(exit, rc = -ENOMEM);
78        
79         pre_smfs_inode(dir, cache_dir);
80         
81 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
82         if (cache_dir && cache_dir->i_op->create)
83                 rc = cache_dir->i_op->create(cache_dir, cache_dentry,
84                                              mode);
85 #else
86         if (cache_dir && cache_dir->i_op->create)
87                 rc = cache_dir->i_op->create(cache_dir, cache_dentry,
88                                              mode, nd);
89 #endif
90         if (rc)
91                 GOTO(exit, rc);
92         
93         SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode,
94                        rc, exit); 
95
96         d_instantiate(dentry, inode);
97         post_smfs_inode(dir, cache_dir);
98         
99         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_CREATE, handle,
100                   POST_HOOK, rc,  exit); 
101 exit:
102         unlock_kernel();
103         post_smfs_dentry(cache_dentry);
104         post_smfs_dentry(cache_parent);
105         smfs_trans_commit(dir, handle, 0);
106         RETURN(rc);
107 }
108
109 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
110 static struct dentry *smfs_lookup(struct inode *dir, struct dentry *dentry)
111 #else
112 static struct dentry *smfs_lookup(struct inode *dir, struct dentry *dentry,
113                                   struct nameidata *nd)
114 #endif
115 {
116         struct inode *cache_dir;
117         struct inode *cache_inode;
118         struct inode *inode = NULL;
119         struct dentry *cache_dentry = NULL;
120         struct dentry *cache_parent = NULL;
121         struct dentry *rc = NULL;
122         void *handle = NULL;
123         int rc2 = 0;
124
125         ENTRY;
126
127         if (!(cache_dir = I2CI(dir)))
128                 RETURN(ERR_PTR(-ENOENT));
129
130         /* preparing artificial backing fs dentries. */
131         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry->d_parent);
132         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
133
134         if (!cache_dentry || !cache_parent)
135                 GOTO(exit, rc = ERR_PTR(-ENOMEM));
136
137         if (!cache_dir && cache_dir->i_op->lookup)
138                 GOTO(exit, rc = ERR_PTR(-ENOENT));
139
140         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_LOOKUP, handle, 
141                   PRE_HOOK, rc2, exit); 
142
143         /* perform lookup in backing fs. */
144 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
145         rc = cache_dir->i_op->lookup(cache_dir, cache_dentry);
146 #else
147         rc = cache_dir->i_op->lookup(cache_dir, cache_dentry, nd);
148 #endif
149         if (rc && IS_ERR(rc))
150                 GOTO(exit, rc);
151         
152         if ((cache_inode = rc ? rc->d_inode : cache_dentry->d_inode)) {
153                 if (IS_ERR(cache_inode)) {
154                         dentry->d_inode = cache_inode;
155                         GOTO(exit, rc = NULL);
156                 }
157                 SMFS_GET_INODE(dir->i_sb, cache_inode, dir, inode, rc2, exit);
158         }
159
160         d_add(dentry, inode);
161         rc = NULL;
162
163         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_LOOKUP, handle, POST_HOOK, rc2, 
164                   exit); 
165 exit:
166         if (rc2 < 0)
167                 rc = ERR_PTR(rc2);
168         post_smfs_dentry(cache_dentry);
169         post_smfs_dentry(cache_parent);
170         smfs_trans_commit(dir, handle, 0);
171         RETURN(rc);
172 }
173
174 static int smfs_link(struct dentry *old_dentry,
175                      struct inode *dir, struct dentry *dentry)
176 {
177         struct inode *cache_old_inode = NULL;
178         struct inode *cache_dir = I2CI(dir);
179         struct inode *inode = NULL;
180         struct dentry *cache_dentry = NULL;
181         struct dentry *cache_old_dentry = NULL;
182         struct dentry *cache_parent = NULL;
183         void *handle = NULL;
184         int rc = 0;
185
186         inode = old_dentry->d_inode;
187         cache_old_inode = I2CI(inode);
188
189         handle = smfs_trans_start(dir, FSFILT_OP_LINK, NULL);
190         if (IS_ERR(handle))
191                  RETURN(-ENOSPC);
192         
193         lock_kernel();
194         SMFS_HOOK(dir, old_dentry, NULL, NULL, HOOK_LINK, handle,
195                   PRE_HOOK, rc, exit); 
196         
197         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
198         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
199
200         if (!cache_parent || !cache_dentry)
201                 GOTO(exit, rc = -ENOMEM);
202
203         cache_old_dentry = pre_smfs_dentry(NULL, cache_old_inode,
204                                            old_dentry);
205         if (!cache_old_dentry)
206                 GOTO(exit, rc = -ENOMEM);
207
208         pre_smfs_inode(dir, cache_dir);
209         pre_smfs_inode(inode, cache_old_dentry->d_inode);
210
211         if (cache_dir->i_op->link)
212                 rc = cache_dir->i_op->link(cache_old_dentry, cache_dir,
213                                            cache_dentry);
214         if (rc)
215                 GOTO(exit, rc);
216
217         atomic_inc(&inode->i_count);
218         post_smfs_inode(inode, cache_old_dentry->d_inode);
219         d_instantiate(dentry, inode);
220         post_smfs_inode(dir, cache_dir);
221
222         SMFS_HOOK(dir, old_dentry, dentry, NULL, HOOK_LINK, handle,
223                   POST_HOOK, rc, exit); 
224 exit:
225         unlock_kernel();
226         post_smfs_dentry(cache_dentry);
227         post_smfs_dentry(cache_parent);
228         post_smfs_dentry(cache_old_dentry);
229         smfs_trans_commit(dir, handle, 0);
230         RETURN(rc);
231 }
232
233 static int smfs_unlink(struct inode * dir,
234                        struct dentry *dentry)
235 {
236         struct inode *cache_dir = I2CI(dir);
237         struct inode *cache_inode = I2CI(dentry->d_inode);
238         struct dentry *cache_dentry;
239         struct dentry *cache_parent;
240         void   *handle = NULL;
241         int    rc = 0;
242         int    mode = 0;
243
244         if (!cache_dir || !cache_inode)
245                 RETURN(-ENOENT);
246
247         handle = smfs_trans_start(dir, FSFILT_OP_UNLINK, NULL);
248         if (IS_ERR(handle))
249                 RETURN(-ENOSPC);
250
251         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_UNLINK, handle, PRE_HOOK, rc, 
252                   exit); 
253         
254         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
255         cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry);
256
257         if (!cache_parent || !cache_dentry)
258                 GOTO(exit, rc = -ENOMEM);
259                 
260         lock_kernel();
261         pre_smfs_inode(dir, cache_dir);
262         pre_smfs_inode(dentry->d_inode, cache_inode);
263         if (cache_dir->i_op->unlink)
264                 rc = cache_dir->i_op->unlink(cache_dir, cache_dentry);
265         post_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
266         post_smfs_inode(dir, cache_dir);
267         unlock_kernel();
268         
269         SMFS_HOOK(dir, dentry, &mode, NULL, HOOK_UNLINK, handle, POST_HOOK, 
270                   rc, exit); 
271 exit:
272         post_smfs_dentry(cache_dentry);
273         post_smfs_dentry(cache_parent);
274         smfs_trans_commit(dir, handle, 0);
275         RETURN(rc);
276 }
277
278 static int smfs_symlink(struct inode *dir, struct dentry *dentry,
279                         const char *symname)
280 {
281         struct inode *cache_dir = I2CI(dir);
282         struct inode *inode = NULL;
283         struct dentry *cache_dentry;
284         struct dentry *cache_parent;
285         void   *handle = NULL;
286         int    rc = 0, tgt_len;
287
288         if (!cache_dir)
289                 RETURN(-ENOENT);
290
291         handle = smfs_trans_start(dir, FSFILT_OP_SYMLINK, NULL);
292         if (IS_ERR(handle))
293                 RETURN(-ENOSPC);
294         
295         lock_kernel();
296         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_SYMLINK, handle, PRE_HOOK, rc, 
297                   exit); 
298
299         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
300         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
301
302         if (!cache_parent || !cache_dentry)
303                 GOTO(exit, rc = -ENOMEM);
304        
305         pre_smfs_inode(dir, cache_dir);
306         if (cache_dir->i_op->symlink)
307                 rc = cache_dir->i_op->symlink(cache_dir, cache_dentry, symname);
308
309         post_smfs_inode(dir, cache_dir);
310         
311         SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode, rc, exit); 
312         if (inode)
313                 d_instantiate(dentry, inode);
314         else
315                 rc = -ENOENT;
316
317         tgt_len = strlen(symname) + 1;
318         
319         SMFS_HOOK(dir, dentry, (char *)symname, &tgt_len, HOOK_SYMLINK, handle, 
320                   POST_HOOK, rc, exit); 
321 exit:
322         unlock_kernel();
323         post_smfs_dentry(cache_dentry);
324         post_smfs_dentry(cache_parent);
325         smfs_trans_commit(dir, handle, 0);
326         RETURN(rc);
327 }
328
329 static int smfs_mkdir(struct inode *dir, struct dentry *dentry,
330                       int mode)
331 {
332         struct inode *cache_dir = I2CI(dir);
333         struct inode *inode = NULL;
334         struct dentry *cache_dentry;
335         struct dentry *cache_parent;
336         void   *handle = NULL;
337         int    rc = 0;
338
339         if (!cache_dir)
340                 RETURN(-ENOENT);
341
342         handle = smfs_trans_start(dir, FSFILT_OP_MKDIR, NULL);
343         if (IS_ERR(handle))
344                 RETURN(-ENOSPC);
345
346         lock_kernel();
347         
348         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKDIR, handle, PRE_HOOK, rc, 
349                   exit); 
350         
351         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
352         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
353
354         if (!cache_parent || !cache_dentry)
355                 GOTO(exit, rc = -ENOMEM);
356
357         pre_smfs_inode(dir, cache_dir);
358
359         if (cache_dir->i_op->mkdir)
360                 rc = cache_dir->i_op->mkdir(cache_dir, cache_dentry, mode);
361
362         if (rc)
363                 GOTO(exit, rc);
364   
365         SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode, rc, exit); 
366         d_instantiate(dentry, inode);
367         post_smfs_inode(dir, cache_dir);
368
369         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKDIR, handle, POST_HOOK, rc,
370                   exit); 
371 exit:
372         unlock_kernel();
373         post_smfs_dentry(cache_dentry);
374         post_smfs_dentry(cache_parent);
375         smfs_trans_commit(dir, handle, 0);
376         RETURN(rc);
377 }
378
379 static int smfs_rmdir(struct inode *dir, struct dentry *dentry)
380 {
381         struct inode *cache_dir = I2CI(dir);
382         struct inode *cache_inode = I2CI(dentry->d_inode);
383         struct dentry *cache_dentry = NULL;
384         struct dentry *cache_parent = NULL;
385         void *handle = NULL;
386         int    rc = 0, mode = S_IFDIR;
387
388         if (!cache_dir)
389                 RETURN(-ENOENT);
390
391         handle = smfs_trans_start(dir, FSFILT_OP_RMDIR, NULL);
392         if (IS_ERR(handle) ) {
393                 CERROR("smfs_do_mkdir: no space for transaction\n");
394                 RETURN(-ENOSPC);
395         }
396
397         lock_kernel();
398
399         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_RMDIR, handle, PRE_HOOK, rc, 
400                   exit); 
401
402         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
403         cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry);
404
405         if (!cache_parent || !cache_dentry)
406                 GOTO(exit, rc = -ENOMEM);
407
408         pre_smfs_inode(dir, cache_dir);
409         pre_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
410         if (cache_dir->i_op->rmdir)
411                 rc = cache_dir->i_op->rmdir(cache_dir, cache_dentry);
412
413         post_smfs_inode(dir, cache_dir);
414         post_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
415         unlock_kernel();
416         
417         SMFS_HOOK(dir, dentry, &mode, NULL, HOOK_RMDIR, handle, POST_HOOK, 
418                   rc, exit); 
419 exit:
420         post_smfs_dentry(cache_dentry);
421         post_smfs_dentry(cache_parent);
422         smfs_trans_commit(dir, handle, 0);
423         RETURN(rc);
424 }
425
426 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
427 static int smfs_mknod(struct inode *dir, struct dentry *dentry,
428                       int mode, int rdev)
429 #else
430 static int smfs_mknod(struct inode *dir, struct dentry *dentry,
431                       int mode, dev_t rdev)
432 #endif
433 {
434         struct inode *cache_dir = I2CI(dir);
435         struct inode *inode = NULL;
436         struct dentry *cache_dentry = NULL;
437         struct dentry *cache_parent = NULL;
438         void *handle = NULL;
439         int rc = 0;
440
441         if (!cache_dir)
442                 RETURN(-ENOENT);
443
444         handle = smfs_trans_start(dir, FSFILT_OP_MKNOD, NULL);
445         if (IS_ERR(handle)) {
446                 CERROR("smfs_do_mkdir: no space for transaction\n");
447                 RETURN(-ENOSPC);
448         }
449
450         lock_kernel();
451         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKNOD, handle, PRE_HOOK, rc, 
452                   exit); 
453         
454         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry->d_parent);
455         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
456         if (!cache_parent || !cache_dentry)
457                 GOTO(exit, rc = -ENOMEM);
458
459         pre_smfs_inode(dir, cache_dir);
460         pre_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
461
462         if (!cache_dir->i_op->mknod)
463                 RETURN(-ENOENT);
464
465         if ((rc = cache_dir->i_op->mknod(cache_dir, cache_dentry,
466                                          mode, rdev)))
467                 GOTO(exit, rc);
468
469         SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode, rc, exit); 
470
471         d_instantiate(dentry, inode);
472
473         pre_smfs_inode(dir, cache_dir);
474         pre_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
475
476         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKNOD, handle, POST_HOOK, rc, 
477                   exit); 
478         
479 exit:
480         unlock_kernel();
481         post_smfs_dentry(cache_dentry);
482         post_smfs_dentry(cache_parent);
483         smfs_trans_commit(dir, handle, 0);
484         RETURN(rc);
485 }
486
487 static int smfs_rename(struct inode *old_dir, struct dentry *old_dentry,
488                        struct inode *new_dir,struct dentry *new_dentry)
489 {
490         struct inode *cache_old_dir = I2CI(old_dir);
491         struct inode *cache_new_dir = I2CI(new_dir);
492         struct inode *cache_old_inode = I2CI(old_dentry->d_inode);
493
494         struct inode *cache_new_inode = new_dentry->d_inode ?
495             I2CI(new_dentry->d_inode) : NULL;
496
497         struct dentry *cache_old_dentry = NULL;
498         struct dentry *cache_new_dentry = NULL;
499         struct dentry *cache_new_parent = NULL;
500         struct dentry *cache_old_parent = NULL;
501         void *handle = NULL;
502         int    rc = 0;
503
504         if (!cache_old_dir || !cache_new_dir || !cache_old_inode)
505                 RETURN(-ENOENT);
506
507         handle = smfs_trans_start(old_dir, FSFILT_OP_RENAME, NULL);
508         if (IS_ERR(handle)) {
509                 CERROR("smfs_do_mkdir: no space for transaction\n");
510                 RETURN(-ENOSPC);
511         }
512         lock_kernel();
513
514         
515         SMFS_HOOK(old_dir, old_dentry, new_dir, new_dentry, HOOK_RENAME,
516                   handle, PRE_HOOK, rc, exit); 
517         
518         cache_old_parent = pre_smfs_dentry(NULL, cache_old_dir, old_dentry);
519
520         cache_old_dentry = pre_smfs_dentry(cache_old_parent, cache_old_inode,
521                                            old_dentry);
522         
523         if (!cache_old_parent || !cache_old_dentry)
524                 GOTO(exit, rc = -ENOMEM);
525
526         cache_new_parent = pre_smfs_dentry(NULL, cache_new_dir, new_dentry);
527         
528         cache_new_dentry = pre_smfs_dentry(cache_new_parent, cache_new_inode,
529                                            new_dentry);
530
531         if (!cache_new_parent || !cache_new_dentry)
532                 GOTO(exit, rc = -ENOMEM);
533
534         pre_smfs_inode(old_dir, cache_old_dir);
535         pre_smfs_inode(new_dir, cache_new_dir);
536
537         if (cache_old_dir->i_op->rename)
538                 rc = cache_old_dir->i_op->rename(cache_old_dir, cache_old_dentry,
539                                                  cache_new_dir, cache_new_dentry);
540         
541         post_smfs_inode(old_dir, cache_old_dir);
542         post_smfs_inode(new_dir, cache_new_dir);
543
544         SMFS_HOOK(old_dir, old_dentry, new_dir, new_dentry, HOOK_RENAME, handle, 
545                   POST_HOOK, rc, exit); 
546         
547         if (new_dentry->d_inode)
548                 post_smfs_inode(new_dentry->d_inode, cache_new_dentry->d_inode);
549 exit:
550         unlock_kernel();
551         post_smfs_dentry(cache_old_dentry);
552         post_smfs_dentry(cache_old_parent);
553         post_smfs_dentry(cache_new_dentry);
554         post_smfs_dentry(cache_new_parent);
555         smfs_trans_commit(old_dir, handle, 0);
556         RETURN(rc);
557 }
558
559 struct inode_operations smfs_dir_iops = {
560         create:         smfs_create,
561         lookup:         smfs_lookup,
562         link:           smfs_link,              /* BKL held */
563         unlink:         smfs_unlink,            /* BKL held */
564         symlink:        smfs_symlink,           /* BKL held */
565         mkdir:          smfs_mkdir,             /* BKL held */
566         rmdir:          smfs_rmdir,             /* BKL held */
567         mknod:          smfs_mknod,             /* BKL held */
568         rename:         smfs_rename,            /* BKL held */
569         setxattr:       smfs_setxattr,          /* BKL held */
570         getxattr:       smfs_getxattr,          /* BKL held */
571         listxattr:      smfs_listxattr,         /* BKL held */
572         removexattr:    smfs_removexattr,       /* BKL held */
573 };
574
575 static ssize_t smfs_read_dir(struct file *filp, char *buf,
576                              size_t size, loff_t *ppos)
577 {
578         struct dentry *dentry = filp->f_dentry;
579         struct inode *cache_inode = NULL;
580         struct smfs_file_info *sfi = NULL;
581         loff_t tmp_ppos;
582         loff_t *cache_ppos;
583         int    rc = 0;
584
585         cache_inode = I2CI(dentry->d_inode);
586
587         if (!cache_inode)
588                 RETURN(-EINVAL);
589
590         sfi = F2SMFI(filp);
591         if (sfi->magic != SMFS_FILE_MAGIC) BUG();
592
593         if (ppos != &(filp->f_pos))
594                 cache_ppos = &tmp_ppos;
595         else
596                 cache_ppos = &sfi->c_file->f_pos;
597         *cache_ppos = *ppos;
598
599         if (cache_inode->i_fop->read)
600                 rc = cache_inode->i_fop->read(sfi->c_file, buf, size,
601                                               cache_ppos);
602         *ppos = *cache_ppos;
603         duplicate_file(filp, sfi->c_file);
604         RETURN(rc);
605 }
606
607 static int smfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
608 {
609         struct dentry *dentry = filp->f_dentry;
610         struct inode *cache_inode = NULL;
611         struct smfs_file_info *sfi = NULL;
612         int    rc = 0;
613
614         cache_inode = I2CI(dentry->d_inode);
615         if (!cache_inode)
616                 RETURN(-EINVAL);
617
618         sfi = F2SMFI(filp);
619         if (sfi->magic != SMFS_FILE_MAGIC) BUG();
620
621         SMFS_HOOK(dentry->d_inode, filp, dirent, filldir, HOOK_READDIR, NULL, 
622                   PRE_HOOK, rc, exit); 
623         
624         if (cache_inode->i_fop->readdir)
625                 rc = cache_inode->i_fop->readdir(sfi->c_file, dirent, filldir);
626
627         SMFS_HOOK(dentry->d_inode, filp, dirent, filldir, HOOK_READDIR, NULL, 
628                   POST_HOOK, rc, exit);
629         
630         duplicate_file(filp, sfi->c_file);
631 exit:
632         if (rc > 0)
633                 rc = 0;
634         RETURN(rc);
635 }
636
637 struct file_operations smfs_dir_fops = {
638         .read           = smfs_read_dir,
639         .readdir        = smfs_readdir,       /* BKL held */
640         .ioctl          = smfs_ioctl,         /* BKL held */
641         .fsync          = smfs_fsync,         /* BKL held */
642         .open           = smfs_open,
643         .release        = smfs_release,
644 };