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