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