4 #define DEBUG_SUBSYSTEM S_SM
6 #include <linux/module.h>
7 #include <linux/kmod.h>
8 #include <linux/init.h>
10 #include <linux/slab.h>
11 #include <linux/string.h>
12 #include <linux/errno.h>
13 #include <linux/lustre_idl.h>
14 #include "smfs_internal.h"
17 static struct list_head option_list;
19 char *opt_left = NULL;
21 int init_option(char *data)
23 INIT_LIST_HEAD(&option_list);
24 SM_ALLOC(options, strlen(data) + 1);
26 CERROR("Can not allocate memory \n");
29 memcpy(options, data, strlen(data));
34 void cleanup_option(void)
36 struct option *option;
37 while (!list_empty(&option_list)) {
38 option = list_entry(option_list.next, struct option, list);
39 list_del(&option->list);
40 SM_FREE(option->opt, strlen(option->opt) + 1);
42 SM_FREE(option->value, strlen(option->value) + 1);
43 SM_FREE(option, sizeof(struct option));
45 SM_FREE(options, strlen(options) + 1);
47 int get_opt(struct option **option, char **pos)
49 char *name, *value, *left, *tmp;
50 struct option *tmp_opt;
57 left = strchr(opt_left, ',');
61 left = opt_left + strlen(opt_left);
64 SM_ALLOC(tmp_opt, sizeof(struct option));
66 tmp_opt->value = NULL;
69 while(tmp != left && *tmp != '=') {
73 SM_ALLOC(name, length + 1);
75 memset(name, 0, length + 1);
76 while (opt_left != tmp) *name++ = *opt_left++;
79 /*this option has value*/
80 opt_left ++; /*after '='*/
81 if (left == opt_left) {
82 SM_FREE(tmp_opt->opt, length);
83 SM_FREE(tmp_opt, sizeof(struct option));
87 length = left - opt_left + 1;
88 SM_ALLOC(value, length);
89 tmp_opt->value = value;
90 memset(value, 0, length);
91 while (opt_left != left) *value++ = *opt_left++;
93 list_add(&tmp_opt->list, &option_list);
94 if (*opt_left == ',') opt_left ++; /*after ','*/