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