Re: [PATCH] iscsi: Report connection state on sysfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux