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