On 3/6/20 11:59 AM, Gabriel Krisman Bertazi wrote:
+static const char *const connection_state_names[] = {
+ [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);
+ const char *state = "unknown";
+
+ if (conn->state < ARRAY_SIZE(connection_state_names))
+ state = connection_state_names[conn->state];
+
+ return sprintf(buf, "%s\n", state);
+}
+static ISCSI_CLASS_ATTR(conn, state, S_IRUGO, show_conn_state,
+ NULL);
Thank you for having made this change.
+/* iscsi class connection state */
+enum {
+ ISCSI_CONN_UP = 0,
+ ISCSI_CONN_DOWN,
+ ISCSI_CONN_FAILED,
+};
+
struct iscsi_cls_conn {
struct list_head conn_list; /* item in connlist */
struct list_head conn_list_err; /* item in connlist_err */
@@ -198,6 +205,7 @@ struct iscsi_cls_conn {
struct iscsi_endpoint *ep;
struct device dev; /* sysfs transport/container device */
+ unsigned int state;
};
Can 'state' have another value than those declared in the enumeration
type? If not, how about changing the type of 'state' from 'unsigned int'
into 'enum ...'? If that change is made, a check will have to be added
in show_conn_state() whether conn->state >= 0 since the C standard does
not guarantee whether enumeration types are signed or unsigned.
Bart.