Whamcloud - gitweb
get rid of some .h file we do not need in options.c
[fs/lustre-release.git] / lustre / smfs / options.c
1 /*
2  *  snapfs/options.c
3  */
4 #define DEBUG_SUBSYSTEM S_SM
5
6 #include <linux/module.h>
7 #include <linux/kmod.h>
8 #include <linux/init.h>
9 #include <linux/fs.h>
10 #include <linux/slab.h>
11 #include <linux/string.h>
12 #include <linux/errno.h>
13 #include "smfs_internal.h" 
14
15
16 static struct list_head option_list;
17 char  *options = NULL;
18 char  *opt_left = NULL;
19
20 int init_option(char *data)
21 {
22         INIT_LIST_HEAD(&option_list);
23         SM_ALLOC(options, strlen(data) + 1);
24         if (!options) {
25                 CERROR("Can not allocate memory \n");
26                 return -ENOMEM;
27         }
28         memcpy(options, data, strlen(data));
29         opt_left = options;
30         return 0;
31 }
32 /*cleanup options*/
33 void cleanup_option(void)
34 {
35         struct option *option;
36         while (!list_empty(&option_list)) {
37                 option = list_entry(option_list.next, struct option, list);
38                 list_del(&option->list);
39                 SM_FREE(option->opt, strlen(option->opt) + 1);
40                 SM_FREE(option->value, strlen(option->value) + 1);
41                 SM_FREE(option, sizeof(struct option));
42         }
43         SM_FREE(options, strlen(options) + 1);
44 }
45 int get_opt(struct option **option, char **pos)
46 {
47         char  *name, *value, *left;
48         struct option *tmp_opt;
49         int  length;
50
51         *pos = opt_left;
52
53         if (! *opt_left)
54                 return -ENODATA;
55
56         left = strchr(opt_left, '=');
57
58         if (left == opt_left || !left) 
59                 return -EINVAL;
60
61         SM_ALLOC(tmp_opt, sizeof(struct option));       
62                 
63         length = left - opt_left + 1;
64         SM_ALLOC(name, length);
65         tmp_opt->opt = name;
66         memset(name, 0, length);
67         while (opt_left != left) *name++ = *opt_left++;
68
69         opt_left ++; /*after '='*/
70
71         left = strchr(opt_left, ',');
72         if (left == opt_left) {
73                 SM_FREE(tmp_opt->opt, length);
74                 SM_FREE(tmp_opt, sizeof(struct option));
75                 opt_left = *pos;
76                 return -EINVAL;
77         }
78         if (!left) 
79                 left = opt_left + strlen(opt_left); 
80         length = left - opt_left + 1;
81         SM_ALLOC(value, length);
82         tmp_opt->value = value;
83         memset(value, 0, length);
84         while (opt_left != left) *value++ = *opt_left++;
85
86         list_add(&tmp_opt->list, &option_list);
87         
88         if (*opt_left == ',') opt_left ++; /*after ','*/        
89
90         *option = tmp_opt;
91         return 0;
92 }