Added "state" field to "struct tgt_driver".
When a LLD goes through its init function, the state chages to INIT state
if all is ok, or to ERR if init fails.
This state is displayed using "-m system -o show" for every registered LLD.
Management operations are allowed only for LLDs that have passed
initialization successfully.
Signed-off-by: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx>
---
usr/driver.c | 17 +++++++++++++++++
usr/driver.h | 9 +++++++++
usr/tgtd.c | 6 +++++-
3 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/usr/driver.c b/usr/driver.c
index f9e0d57..bf612b9 100644
--- a/usr/driver.c
+++ b/usr/driver.c
@@ -51,9 +51,26 @@ int register_driver(struct tgt_driver *drv)
for (i = 0; i < ARRAY_SIZE(tgt_drivers); i++)
if (!tgt_drivers[i]) {
+ drv->drv_state = DRIVER_REGD;
tgt_drivers[i] = drv;
return 0;
}
return -1;
}
+
+const char *driver_state_name(struct tgt_driver *drv)
+{
+ switch (drv->drv_state) {
+ case DRIVER_REGD:
+ return "uninitialized";
+ case DRIVER_INIT:
+ return "ready";
+ case DRIVER_ERR:
+ return "error";
+ case DRIVER_EXIT:
+ return "stopped";
+ default:
+ return "unsupported";
+ }
+}
diff --git a/usr/driver.h b/usr/driver.h
index 798dcd3..091c3b0 100644
--- a/usr/driver.h
+++ b/usr/driver.h
@@ -1,8 +1,16 @@
#ifndef __DRIVER_H__
#define __DRIVER_H__
+enum tgt_driver_state {
+ DRIVER_REGD = 0, /* just registered */
+ DRIVER_INIT, /* initialized ok */
+ DRIVER_ERR, /* failed to initialize */
+ DRIVER_EXIT /* exited */
+};
+
struct tgt_driver {
const char *name;
+ enum tgt_driver_state drv_state;
int (*init)(int, char *);
void (*exit)(void);
@@ -31,5 +39,6 @@ struct tgt_driver {
extern struct tgt_driver *tgt_drivers[];
extern int get_driver_index(char *name);
extern int register_driver(struct tgt_driver *drv);
+extern const char *driver_state_name(struct tgt_driver *drv);
#endif /* __DRIVER_H__ */
diff --git a/usr/tgtd.c b/usr/tgtd.c
index 30d5e9d..0d6f11f 100644
--- a/usr/tgtd.c
+++ b/usr/tgtd.c
@@ -414,8 +414,11 @@ static int lld_init(char *args)
for (i = nr = 0; tgt_drivers[i]; i++) {
if (tgt_drivers[i]->init) {
err = tgt_drivers[i]->init(i, args);
- if (err)
+ if (err) {
+ tgt_drivers[i]->drv_state = DRIVER_ERR;
continue;
+ }
+ tgt_drivers[i]->drv_state = DRIVER_INIT;
}
nr++;
}
@@ -429,6 +432,7 @@ static void lld_exit(void)
for (i = 0; tgt_drivers[i]; i++) {
if (tgt_drivers[i]->exit)
tgt_drivers[i]->exit();
+ tgt_drivers[i]->drv_state = DRIVER_EXIT;
}
}
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html