Whamcloud - gitweb
update smfs
[fs/lustre-release.git] / lustre / smfs / dir.c
1 /*
2  * dir.c
3  */
4 #define DEBUG_SUBSYSTEM S_SNAP
5
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/string.h>
9 #include <linux/slab.h>
10 #include <linux/stat.h>
11 #include <linux/unistd.h>
12
13 #include "smfs_internal.h" 
14
15 static void d_unalloc(struct dentry *dentry)
16 {
17         if (dentry) {                                                                                                                                                                                
18                 list_del(&dentry->d_hash);
19                 INIT_LIST_HEAD(&dentry->d_hash);
20                 dput(dentry);   
21         }
22 }
23 static struct inode *sm_create_inode(struct super_block *sb,
24                                      struct inode *cache_inode) 
25 {
26         struct inode *inode;
27
28         inode = new_inode(sb);
29         if (inode) {
30                 /*FIXME there are still some 
31                  * other attributes need to
32                  * duplicated*/
33                 inode->i_ino = cache_inode->i_ino;                      
34                 inode->i_mode = cache_inode->i_mode;                    
35         }       
36         
37         return inode;
38 }
39                                                                                                                                                                                                      
40 static void prepare_parent_dentry(struct dentry *dentry, struct inode *inode)
41 {
42         atomic_set(&dentry->d_count, 1);
43         dentry->d_vfs_flags = 0;
44         dentry->d_flags = 0;
45         dentry->d_inode = inode;
46         dentry->d_op = NULL;
47         dentry->d_fsdata = NULL;
48         dentry->d_mounted = 0;
49         INIT_LIST_HEAD(&dentry->d_hash);
50         INIT_LIST_HEAD(&dentry->d_lru);
51         INIT_LIST_HEAD(&dentry->d_subdirs);
52         INIT_LIST_HEAD(&dentry->d_alias);
53 }
54
55 static int smfs_create(struct inode *dir, 
56                        struct dentry *dentry, 
57                        int mode)
58 {
59         struct  inode *cache_dir; 
60         struct  inode *cache_inode, *inode;
61         struct  dentry tmp; 
62         struct  dentry *cache_dentry;
63         int     rc;
64         
65         ENTRY;
66         
67         cache_dir = I2CI(dir);
68         if (!cache_dir)
69                 RETURN(-ENOENT);
70        
71         prepare_parent_dentry(&tmp, cache_dir);      
72         cache_dentry = d_alloc(&tmp, &dentry->d_name);
73         
74         if (!cache_dentry) 
75                 RETURN(-ENOENT);
76         
77         if(cache_dir && cache_dir->i_op->create)
78                 rc = cache_dir->i_op->create(cache_dir, cache_dentry, mode);
79         if (rc)
80                 GOTO(exit, rc);
81  
82         cache_inode = cache_dentry->d_inode;
83         inode = sm_create_inode(dir->i_sb, cache_inode);        
84         
85         if (!inode) 
86                 GOTO(exit, rc);         
87         
88         sm_set_inode_ops(cache_inode, inode);
89 exit:
90         d_unalloc(cache_dentry);        
91         RETURN(rc);
92 }
93
94 struct inode_operations smfs_dir_fops = {
95         create: smfs_create,
96 };
97