[stgt] [PATCH 1/2] add multiple boot parameter parsers support
FUJITA Tomonori
fujita.tomonori at lab.ntt.co.jp
Sat Oct 3 12:31:52 CEST 2009
We don't want the global parameters to handle all boot parameters
(e.g. iSCSI, FCoE, etc).
This patch adds multiple boot parameter parsers support; iSCSI can
defines the own parser, FCoE can, etc.
Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
usr/tgtd.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
usr/tgtd.h | 2 ++
2 files changed, 50 insertions(+), 1 deletions(-)
diff --git a/usr/tgtd.c b/usr/tgtd.c
index 8569d41..3e48484 100644
--- a/usr/tgtd.c
+++ b/usr/tgtd.c
@@ -307,6 +307,44 @@ static void lld_exit(void)
}
}
+struct tgt_param {
+ int (*parse_func)(char *);
+ char *name;
+};
+
+static struct tgt_param params[64];
+
+int setup_param(char *name, int (*parser)(char *))
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(params); i++)
+ if (!params[i].name)
+ break;
+
+ if (i < ARRAY_SIZE(params)) {
+ params[i].name = name;
+ params[i].parse_func = parser;
+
+ return 0;
+ } else
+ return -1;
+}
+
+static int parse_params(char *name, char *p)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(params) && params[i].name; i++) {
+ if (!strcmp(name, params[i].name))
+ return params[i].parse_func(p);
+ }
+
+ fprintf(stderr, "'%s' is an unknown option\n", name);
+
+ return -1;
+}
+
int main(int argc, char **argv)
{
struct sigaction sa_old;
@@ -314,6 +352,7 @@ int main(int argc, char **argv)
int err, ch, longindex, nr_lld = 0;
int is_daemon = 1, is_debug = 0;
int use_kernel = 0;
+ int ret;
/* do not allow ctrl-c for now... */
sa_new.sa_handler = signal_catch;
@@ -328,6 +367,8 @@ int main(int argc, char **argv)
if (1UL << pageshift == pagesize)
break;
+ opterr = 0;
+
while ((ch = getopt_long(argc, argv, short_options, long_options,
&longindex)) >= 0) {
switch (ch) {
@@ -344,7 +385,13 @@ int main(int argc, char **argv)
usage(0);
break;
default:
- usage(1);
+ if (strncmp(argv[optind - 1], "--", 2))
+ usage(1);
+
+ ret = parse_params(argv[optind - 1] + 2, argv[optind]);
+ if (ret)
+ usage(1);
+
break;
}
}
diff --git a/usr/tgtd.h b/usr/tgtd.h
index 303627e..febaed7 100644
--- a/usr/tgtd.h
+++ b/usr/tgtd.h
@@ -277,6 +277,8 @@ extern int dtd_load_unload(int tid, uint64_t lun, int load, char *file);
extern int register_backingstore_template(struct backingstore_template *bst);
extern struct backingstore_template *get_backingstore_template(const char *name);
+extern int setup_param(char *name, int (*parser)(char *));
+
struct event_data {
union {
event_handler_t handler;
--
1.5.6.5
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list