1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/smfs/options.c
5 * Lustre filesystem abstraction routines
7 * Copyright (C) 2004 Cluster File Systems, Inc.
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define DEBUG_SUBSYSTEM S_SM
27 #include <linux/module.h>
28 #include <linux/kmod.h>
29 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/errno.h>
34 #include <linux/obd_class.h>
35 #include <linux/obd_support.h>
36 #include <linux/lustre_lib.h>
37 #include <linux/lustre_idl.h>
38 #include <linux/lustre_smfs.h>
39 #include <linux/lustre_fsfilt.h>
40 #include "smfs_internal.h"
42 static struct list_head option_list;
43 static char *options = NULL;
44 static char *opt_left = NULL;
46 int init_option(char *data)
48 INIT_LIST_HEAD(&option_list);
49 OBD_ALLOC(options, strlen(data) + 1);
51 CERROR("Can not allocate memory \n");
54 memcpy(options, data, strlen(data));
60 void cleanup_option(void)
62 struct option *option;
63 while (!list_empty(&option_list)) {
64 option = list_entry(option_list.next, struct option, list);
65 list_del(&option->list);
66 OBD_FREE(option->opt, strlen(option->opt) + 1);
68 OBD_FREE(option->value, strlen(option->value) + 1);
69 OBD_FREE(option, sizeof(struct option));
71 OBD_FREE(options, strlen(options) + 1);
74 int get_opt(struct option **option, char **pos)
76 char *name, *value, *left, *tmp;
77 struct option *tmp_opt;
84 left = strchr(opt_left, ',');
88 left = opt_left + strlen(opt_left);
90 OBD_ALLOC(tmp_opt, sizeof(struct option));
92 tmp_opt->value = NULL;
95 while(tmp != left && *tmp != '=') {
99 OBD_ALLOC(name, length + 1);
101 while (opt_left != tmp) *name++ = *opt_left++;
104 /*this option has value*/
105 opt_left ++; /*after '='*/
106 if (left == opt_left) {
107 OBD_FREE(tmp_opt->opt, strlen(tmp_opt->opt) + 1);
108 OBD_FREE(tmp_opt, sizeof(struct option));
112 length = left - opt_left;
113 OBD_ALLOC(value, length + 1);
115 OBD_FREE(tmp_opt->opt, strlen(tmp_opt->opt) + 1);
116 OBD_FREE(tmp_opt, sizeof(struct option));
119 tmp_opt->value = value;
120 while (opt_left != left) *value++ = *opt_left++;
122 list_add(&tmp_opt->list, &option_list);
123 if (*opt_left == ',') opt_left ++; /*after ','*/