[Stgt-devel] rework of smc module
FUJITA Tomonori
fujita.tomonori
Thu Jun 28 12:41:14 CEST 2007
From: Mark Harvey <markh794 at gmail.com>
Subject: Re: [Stgt-devel] rework of smc module
Date: Thu, 28 Jun 2007 18:24:45 +1000
> OK - Not a patch but a 'proof oc concept' type patch.
>
> If this method of lu_config() is ok, then I'll put together a proper patch.
I'm thinking about something like this patch.
BTW, could you fix some of the comments in this patch? And please use
the kernel-doc format when commenting functions. Here's an example:
/**
* sas_remove_children -- tear down a devices SAS data structures
* @dev: device belonging to the sas object
*
* Removes all SAS PHYs and remote PHYs for a given object
*/
void sas_remove_children(struct device *dev)
{
....
}
Note that I don't ask you to comment every functions. It's ok if you
comment only functions that you want to comment.
diff --git a/usr/sbc.c b/usr/sbc.c
index c0075e4..a0c2d34 100644
--- a/usr/sbc.c
+++ b/usr/sbc.c
@@ -39,6 +39,9 @@
#include "scsi.h"
#include "spc.h"
+#include "parser.h"
+#include "tgtadm_error.h"
+
#define BLK_SHIFT 9
static int sbc_rw(int host_no, struct scsi_cmd *cmd)
@@ -315,10 +318,48 @@ static int sbc_lu_init(struct scsi_lu *lu)
return 0;
}
+enum {
+ Opt_hoge1, Opt_hoge2,
+ Opt_err,
+};
+
+static match_table_t tokens = {
+ {Opt_hoge1, "hoge1=%s"},
+ {Opt_hoge2, "hoge2=%s"},
+ {Opt_err, NULL},
+};
+
+static int __sbc_lu_config(struct scsi_lu *lu, char *p)
+{
+ substring_t args[MAX_OPT_ARGS];
+ int token, ret = 0;
+ char buf[64];
+
+ token = match_token(p, tokens, args);
+ switch (token) {
+ case Opt_hoge1:
+ match_strncpy(buf, &args[0], sizeof(buf));
+ eprintf("hoge1: %s\n", buf);
+ break;
+ case Opt_hoge2:
+ match_strncpy(buf, &args[0], sizeof(buf));
+ eprintf("hoge2: %s\n", buf);
+ break;
+ default:
+ ret = TGTADM_INVALID_REQUEST;
+ }
+ return ret;
+}
+
+static int sbc_lu_config(struct scsi_lu *lu, char *params)
+{
+ return lu_config(lu, params, __sbc_lu_config);
+}
+
static struct device_type_template sbc_template = {
.type = TYPE_DISK,
.lu_init = sbc_lu_init,
- .lu_config = spc_lu_config,
+ .lu_config = sbc_lu_config,
.ops = {
{spc_test_unit,},
{spc_illegal_op,},
diff --git a/usr/spc.c b/usr/spc.c
index 1c363cd..8a8ee72 100644
--- a/usr/spc.c
+++ b/usr/spc.c
@@ -295,7 +295,8 @@ static match_table_t tokens = {
{Opt_err, NULL},
};
-int spc_lu_config(struct scsi_lu *lu, char *params) {
+int lu_config(struct scsi_lu *lu, char *params, match_fn_t *fn)
+{
int err = 0;
char *p;
char buf[20];
@@ -343,12 +344,17 @@ int spc_lu_config(struct scsi_lu *lu, char *params) {
lu->attrs.online = atoi(buf);
break;
default:
- err = TGTADM_INVALID_REQUEST;
+ err = fn ? fn(lu, p) : TGTADM_INVALID_REQUEST;
}
}
return err;
}
+int spc_lu_config(struct scsi_lu *lu, char *params)
+{
+ return lu_config(lu, params, NULL);
+}
+
int spc_lu_init(struct scsi_lu *lu)
{
strncpy(lu->attrs.vendor_id, VENDOR_ID, sizeof(lu->attrs.vendor_id));
diff --git a/usr/spc.h b/usr/spc.h
index 1036b70..98e1448 100644
--- a/usr/spc.h
+++ b/usr/spc.h
@@ -8,7 +8,10 @@ extern int spc_test_unit(int host_no, struct scsi_cmd *cmd);
extern int spc_request_sense(int host_no, struct scsi_cmd *cmd);
extern int spc_illegal_op(int host_no, struct scsi_cmd *cmd);
extern int spc_lu_init(struct scsi_lu *lu);
-extern int spc_lu_config(struct scsi_lu *lu, char * params);
+
+typedef int (match_fn_t)(struct scsi_lu *, char *);
+extern int lu_config(struct scsi_lu *lu, char *params, match_fn_t *);
+extern int spc_lu_config(struct scsi_lu *lu, char *params);
extern void dump_cdb(struct scsi_cmd *cmd);
#endif
More information about the stgt
mailing list