Whamcloud - gitweb
add smfs
[fs/lustre-release.git] / lustre / smfs / super.c
1 /*
2  *  snap_current
3  *
4  *  Copyright (C) 1998 Peter J. Braam
5  *  Copyright (C) 2000 Stelias Computing, Inc.
6  *  Copyright (C) 2000 Red Hat, Inc.
7  *  Copyright (C) 2000 Mountain View Data, Inc.
8  *
9  *  Author: Peter J. Braam <braam@mountainviewdata.com>
10  */
11 #define DEBUG_SUBSYSTEM S_SNAP
12
13 #include <linux/module.h>
14 #include <linux/kmod.h>
15 #include <linux/init.h>
16 #include <linux/fs.h>
17 #include <linux/slab.h>
18 #include <linux/string.h>
19 #include <linux/loop.h>
20 //#include <linux/jbd.h>
21 //#include <linux/ext3_fs.h>
22 #include <linux/errno.h>
23 #include "smfs_internal.h" 
24
25 /* Find the options for the clone. These consist of a cache device
26    and an index in the snaptable associated with that device. 
27 */
28 static char *smfs_options(char *options, char **devstr, char **namestr)
29 {
30         struct option *opt_value = NULL;
31         char *pos;
32         
33         while (!(get_opt(&opt_value, &pos))) {                  
34                 if (!strcmp(opt_value->opt, "dev")) {
35                         if (devstr != NULL)
36                                 *devstr = opt_value->value;
37                 } else if (!strcmp(opt_value->opt, "type")) {
38                         if (namestr != NULL)
39                                 *namestr = opt_value->value;
40                 } else {
41                         break;
42                 }
43         }
44         return pos;
45 }
46 extern struct super_operations smfs_super_ops;
47
48 static struct super_block *sm_mount_cache(struct super_block *sb, 
49                                           char *devstr,
50                                           char *typestr)
51 {
52         return NULL;    
53 }
54
55 struct super_block *
56 smfs_read_super(
57         struct super_block *sb,
58         void *data,
59         int silent)
60 {
61         struct smfs_inode_info *smi;
62         struct smfs_super_info *smb;
63         struct dentry *bottom_root;
64         struct inode *root_inode = NULL;
65         struct super_block *cache_sb;
66         char *devstr = NULL, *typestr = NULL;
67         char *cache_data;
68         ino_t root_ino;
69         int err = 0;
70
71         ENTRY;
72
73         CDEBUG(D_SUPER, "mount opts: %s\n", data ? (char *)data : "(none)");
74         
75         init_option(data);
76         /* read and validate options */
77         cache_data = smfs_options(data, &devstr, &typestr);
78         if (*cache_data) {
79                 CERROR("invalid mount option %s\n", (char*)data);
80                 GOTO(out_err, err=-EINVAL);
81         }
82         if (!typestr || !devstr) {
83                 CERROR("mount options name and dev mandatory\n");
84                 GOTO(out_err, err=-EINVAL);
85         }
86         
87         cache_sb = sm_mount_cache(sb, devstr, typestr);
88         if (!cache_sb) {
89                 CERROR("Can not mount %s as %s\n", devstr, typestr);
90                 GOTO(out_err, err=-EINVAL);
91         }
92         /* set up the super block */
93         smb = S2SMI(sb); 
94         smb->smsi_sb = cache_sb;
95         sb->s_op = &smfs_super_ops;
96
97         bottom_root = dget(cache_sb->s_root);
98         if (!bottom_root) {
99                 CERROR("bottom not mounted\n");
100                 GOTO(out_err, err=-ENOENT);
101         }
102
103         root_ino = bottom_root->d_inode->i_ino;
104         smi = I2SMI(root_inode);
105         /*FIXME Intialize smi here*/
106         
107         CDEBUG(D_SUPER, "readinode %p, root ino %ld, root inode at %p\n",
108                sb->s_op->read_inode, root_ino, root_inode);
109         
110         sb->s_root = d_alloc_root(bottom_root->d_inode);
111         
112         if (!sb->s_root) {
113                 GOTO(out_err, err=-EINVAL);
114         }
115
116         CDEBUG(D_SUPER, "sb %lx, &sb->u.generic_sbp: %lx\n",
117                 (ulong) sb, (ulong) &sb->u.generic_sbp);
118         
119  out_err:
120         cleanup_option();
121         if (err)
122                 return NULL;
123         return sb;
124 }
125
126 static DECLARE_FSTYPE(smfs_type, "smfs", smfs_read_super, 0);
127
128 int init_smfs(void)
129 {
130         int err;
131
132         err = register_filesystem(&smfs_type);
133         if (err) {
134                 CERROR("smfs: failed in register Storage Management filesystem!\n");
135         }
136         return err;
137 }
138
139 int cleanup_smfs(void)
140 {
141         int err;
142
143         ENTRY;
144         err = unregister_filesystem(&smfs_type);
145         if (err) {
146                 CERROR("smfs: failed to unregister Storage Management filesystem!\n");
147         }
148         return 0;
149 }