On 3/4/20 2:57 PM, Gabriel Krisman Bertazi wrote:
+static const struct {
+       int state;
+       char *name;
+} connection_state_name[] = {
+       {ISCSI_CONN_UP, "up"},
+       {ISCSI_CONN_DOWN, "down"},
+       {ISCSI_CONN_FAILED, "failed"}
+};
+
+static ssize_t
+show_conn_state(struct device *dev, struct device_attribute *attr,
+                    char *buf)
+{
+       struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent);
+
+       return sprintf(buf, "%s\n",
+                      connection_state_name[conn->state].name);
+}
+static ISCSI_CLASS_ATTR(conn, state, S_IRUGO, show_conn_state,
+                       NULL);

The above code can only work if ISCSI_CONN_UP == 0, ISCSI_CONN_DOWN == 1 and ISCSI_CONN_FAILED == 2. Please don't hardcode such a dependency and use designated initializers instead.

Thanks,

Bart.

--
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/open-iscsi/387eebf7-3256-3462-f91d-e42a5de4824d%40acm.org.

Reply via email to