[SCSI] iscsi: break up session creation into two stages
[linux-2.6.git] / drivers / scsi / scsi_transport_iscsi.c
index 7b7a194..f39da0c 100644 (file)
 #include <scsi/iscsi_if.h>
 
 #define ISCSI_SESSION_ATTRS 11
-#define ISCSI_CONN_ATTRS 10
+#define ISCSI_CONN_ATTRS 11
 #define ISCSI_HOST_ATTRS 0
 
 struct iscsi_internal {
+       int daemon_pid;
        struct scsi_transport_template t;
        struct iscsi_transport *iscsi_transport;
        struct list_head list;
@@ -145,7 +146,6 @@ static DECLARE_TRANSPORT_CLASS(iscsi_connection_class,
                               NULL);
 
 static struct sock *nls;
-static int daemon_pid;
 static DEFINE_MUTEX(rx_queue_mutex);
 
 struct mempool_zone {
@@ -228,14 +228,11 @@ static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
 static void iscsi_session_release(struct device *dev)
 {
        struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
-       struct iscsi_transport *transport = session->transport;
        struct Scsi_Host *shost;
 
        shost = iscsi_session_to_shost(session);
        scsi_host_put(shost);
-       kfree(session->targetname);
        kfree(session);
-       module_put(transport->owner);
 }
 
 static int iscsi_is_session_dev(const struct device *dev)
@@ -251,10 +248,9 @@ static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
 
        mutex_lock(&ihost->mutex);
        list_for_each_entry(session, &ihost->sessions, host_list) {
-               if ((channel == SCAN_WILD_CARD ||
-                    channel == session->channel) &&
+               if ((channel == SCAN_WILD_CARD || channel == 0) &&
                    (id == SCAN_WILD_CARD || id == session->target_id))
-                       scsi_scan_target(&session->dev, session->channel,
+                       scsi_scan_target(&session->dev, 0,
                                         session->target_id, lun, 1);
        }
        mutex_unlock(&ihost->mutex);
@@ -266,8 +262,8 @@ static void session_recovery_timedout(void *data)
 {
        struct iscsi_cls_session *session = data;
 
-       dev_printk(KERN_INFO, &session->dev, "session recovery timed out "
-                 "after %d secs\n", session->recovery_tmo);
+       dev_printk(KERN_INFO, &session->dev, "iscsi: session recovery timed "
+                 "out after %d secs\n", session->recovery_tmo);
 
        if (session->transport->session_recovery_timedout)
                session->transport->session_recovery_timedout(session);
@@ -291,80 +287,92 @@ void iscsi_block_session(struct iscsi_cls_session *session)
 }
 EXPORT_SYMBOL_GPL(iscsi_block_session);
 
-/**
- * iscsi_create_session - create iscsi class session
- * @shost: scsi host
- * @transport: iscsi transport
- *
- * This can be called from a LLD or iscsi_transport.
- **/
 struct iscsi_cls_session *
-iscsi_create_session(struct Scsi_Host *shost,
-                    struct iscsi_transport *transport, int channel)
+iscsi_alloc_session(struct Scsi_Host *shost,
+                   struct iscsi_transport *transport)
 {
-       struct iscsi_host *ihost;
        struct iscsi_cls_session *session;
-       int err;
-
-       if (!try_module_get(transport->owner))
-               return NULL;
 
        session = kzalloc(sizeof(*session) + transport->sessiondata_size,
                          GFP_KERNEL);
        if (!session)
-               goto module_put;
+               return NULL;
+
        session->transport = transport;
        session->recovery_tmo = 120;
        INIT_WORK(&session->recovery_work, session_recovery_timedout, session);
        INIT_LIST_HEAD(&session->host_list);
        INIT_LIST_HEAD(&session->sess_list);
 
+       session->dev.parent = &shost->shost_gendev;
+       session->dev.release = iscsi_session_release;
+       device_initialize(&session->dev);
        if (transport->sessiondata_size)
                session->dd_data = &session[1];
+       return session;
+}
+EXPORT_SYMBOL_GPL(iscsi_alloc_session);
+
+int iscsi_add_session(struct iscsi_cls_session *session)
+{
+       struct Scsi_Host *shost = iscsi_session_to_shost(session);
+       struct iscsi_host *ihost;
+       int err;
 
        /* this is released in the dev's release function */
        scsi_host_get(shost);
        ihost = shost->shost_data;
 
        session->sid = iscsi_session_nr++;
-       session->channel = channel;
        session->target_id = ihost->next_target_id++;
 
        snprintf(session->dev.bus_id, BUS_ID_SIZE, "session%u",
                 session->sid);
-       session->dev.parent = &shost->shost_gendev;
-       session->dev.release = iscsi_session_release;
-       err = device_register(&session->dev);
+       err = device_add(&session->dev);
        if (err) {
                dev_printk(KERN_ERR, &session->dev, "iscsi: could not "
                           "register session's dev\n");
-               goto free_session;
+               goto release_host;
        }
        transport_register_device(&session->dev);
 
        mutex_lock(&ihost->mutex);
        list_add(&session->host_list, &ihost->sessions);
        mutex_unlock(&ihost->mutex);
+       return 0;
 
-       return session;
-
-free_session:
-       kfree(session);
-module_put:
-       module_put(transport->owner);
-       return NULL;
+release_host:
+       scsi_host_put(shost);
+       return err;
 }
-
-EXPORT_SYMBOL_GPL(iscsi_create_session);
+EXPORT_SYMBOL_GPL(iscsi_add_session);
 
 /**
- * iscsi_destroy_session - destroy iscsi session
- * @session: iscsi_session
+ * iscsi_create_session - create iscsi class session
+ * @shost: scsi host
+ * @transport: iscsi transport
  *
- * Can be called by a LLD or iscsi_transport. There must not be
- * any running connections.
+ * This can be called from a LLD or iscsi_transport.
  **/
-int iscsi_destroy_session(struct iscsi_cls_session *session)
+struct iscsi_cls_session *
+iscsi_create_session(struct Scsi_Host *shost,
+                    struct iscsi_transport *transport)
+{
+       struct iscsi_cls_session *session;
+
+       session = iscsi_alloc_session(shost, transport);
+       if (!session)
+               return NULL;
+
+       if (iscsi_add_session(session)) {
+               iscsi_free_session(session);
+               return NULL;
+       }
+       return session;
+}
+EXPORT_SYMBOL_GPL(iscsi_create_session);
+
+void iscsi_remove_session(struct iscsi_cls_session *session)
 {
        struct Scsi_Host *shost = iscsi_session_to_shost(session);
        struct iscsi_host *ihost = shost->shost_data;
@@ -376,11 +384,33 @@ int iscsi_destroy_session(struct iscsi_cls_session *session)
        list_del(&session->host_list);
        mutex_unlock(&ihost->mutex);
 
+       scsi_remove_target(&session->dev);
+
        transport_unregister_device(&session->dev);
-       device_unregister(&session->dev);
-       return 0;
+       device_del(&session->dev);
+}
+EXPORT_SYMBOL_GPL(iscsi_remove_session);
+
+void iscsi_free_session(struct iscsi_cls_session *session)
+{
+       put_device(&session->dev);
 }
 
+EXPORT_SYMBOL_GPL(iscsi_free_session);
+
+/**
+ * iscsi_destroy_session - destroy iscsi session
+ * @session: iscsi_session
+ *
+ * Can be called by a LLD or iscsi_transport. There must not be
+ * any running connections.
+ **/
+int iscsi_destroy_session(struct iscsi_cls_session *session)
+{
+       iscsi_remove_session(session);
+       iscsi_free_session(session);
+       return 0;
+}
 EXPORT_SYMBOL_GPL(iscsi_destroy_session);
 
 static void iscsi_conn_release(struct device *dev)
@@ -388,7 +418,6 @@ static void iscsi_conn_release(struct device *dev)
        struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev);
        struct device *parent = conn->dev.parent;
 
-       kfree(conn->persistent_address);
        kfree(conn);
        put_device(parent);
 }
@@ -572,13 +601,13 @@ mempool_zone_get_skb(struct mempool_zone *zone)
 }
 
 static int
-iscsi_unicast_skb(struct mempool_zone *zone, struct sk_buff *skb)
+iscsi_unicast_skb(struct mempool_zone *zone, struct sk_buff *skb, int pid)
 {
        unsigned long flags;
        int rc;
 
        skb_get(skb);
-       rc = netlink_unicast(nls, skb, daemon_pid, MSG_DONTWAIT);
+       rc = netlink_unicast(nls, skb, pid, MSG_DONTWAIT);
        if (rc < 0) {
                mempool_free(skb, zone->pool);
                printk(KERN_ERR "iscsi: can not unicast skb (%d)\n", rc);
@@ -600,9 +629,14 @@ int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
        struct sk_buff *skb;
        struct iscsi_uevent *ev;
        char *pdu;
+       struct iscsi_internal *priv;
        int len = NLMSG_SPACE(sizeof(*ev) + sizeof(struct iscsi_hdr) +
                              data_size);
 
+       priv = iscsi_if_transport_lookup(conn->transport);
+       if (!priv)
+               return -EINVAL;
+
        mempool_zone_complete(conn->z_pdu);
 
        skb = mempool_zone_get_skb(conn->z_pdu);
@@ -613,7 +647,7 @@ int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
                return -ENOMEM;
        }
 
-       nlh = __nlmsg_put(skb, daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
+       nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
        ev = NLMSG_DATA(nlh);
        memset(ev, 0, sizeof(*ev));
        ev->transport_handle = iscsi_handle(conn->transport);
@@ -626,7 +660,7 @@ int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
        memcpy(pdu, hdr, sizeof(struct iscsi_hdr));
        memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);
 
-       return iscsi_unicast_skb(conn->z_pdu, skb);
+       return iscsi_unicast_skb(conn->z_pdu, skb, priv->daemon_pid);
 }
 EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
 
@@ -635,8 +669,13 @@ void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error)
        struct nlmsghdr *nlh;
        struct sk_buff  *skb;
        struct iscsi_uevent *ev;
+       struct iscsi_internal *priv;
        int len = NLMSG_SPACE(sizeof(*ev));
 
+       priv = iscsi_if_transport_lookup(conn->transport);
+       if (!priv)
+               return;
+
        mempool_zone_complete(conn->z_error);
 
        skb = mempool_zone_get_skb(conn->z_error);
@@ -646,7 +685,7 @@ void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error)
                return;
        }
 
-       nlh = __nlmsg_put(skb, daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
+       nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
        ev = NLMSG_DATA(nlh);
        ev->transport_handle = iscsi_handle(conn->transport);
        ev->type = ISCSI_KEVENT_CONN_ERROR;
@@ -656,7 +695,7 @@ void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error)
        ev->r.connerror.cid = conn->cid;
        ev->r.connerror.sid = iscsi_conn_get_sid(conn);
 
-       iscsi_unicast_skb(conn->z_error, skb);
+       iscsi_unicast_skb(conn->z_error, skb, priv->daemon_pid);
 
        dev_printk(KERN_INFO, &conn->dev, "iscsi: detected conn error (%d)\n",
                   error);
@@ -686,7 +725,7 @@ iscsi_if_send_reply(int pid, int seq, int type, int done, int multi,
        nlh = __nlmsg_put(skb, pid, seq, t, (len - sizeof(*nlh)), 0);
        nlh->nlmsg_flags = flags;
        memcpy(NLMSG_DATA(nlh), payload, size);
-       return iscsi_unicast_skb(z_reply, skb);
+       return iscsi_unicast_skb(z_reply, skb, pid);
 }
 
 static int
@@ -698,12 +737,17 @@ iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
        struct iscsi_cls_conn *conn;
        struct nlmsghdr *nlhstat;
        struct iscsi_uevent *evstat;
+       struct iscsi_internal *priv;
        int len = NLMSG_SPACE(sizeof(*ev) +
                              sizeof(struct iscsi_stats) +
                              sizeof(struct iscsi_stats_custom) *
                              ISCSI_STATS_CUSTOM_MAX);
        int err = 0;
 
+       priv = iscsi_if_transport_lookup(transport);
+       if (!priv)
+               return -EINVAL;
+
        conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid);
        if (!conn)
                return -EEXIST;
@@ -720,7 +764,7 @@ iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
                        return -ENOMEM;
                }
 
-               nlhstat = __nlmsg_put(skbstat, daemon_pid, 0, 0,
+               nlhstat = __nlmsg_put(skbstat, priv->daemon_pid, 0, 0,
                                      (len - sizeof(*nlhstat)), 0);
                evstat = NLMSG_DATA(nlhstat);
                memset(evstat, 0, sizeof(*evstat));
@@ -746,7 +790,7 @@ iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
                skb_trim(skbstat, NLMSG_ALIGN(actual_size));
                nlhstat->nlmsg_len = actual_size;
 
-               err = iscsi_unicast_skb(conn->z_pdu, skbstat);
+               err = iscsi_unicast_skb(conn->z_pdu, skbstat, priv->daemon_pid);
        } while (err < 0 && err != -ECONNREFUSED);
 
        return err;
@@ -862,23 +906,13 @@ iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev
        return 0;
 }
 
-static void
-iscsi_copy_param(struct iscsi_uevent *ev, uint32_t *value, char *data)
-{
-       if (ev->u.set_param.len != sizeof(uint32_t))
-               BUG();
-       memcpy(value, data, min_t(uint32_t, sizeof(uint32_t),
-               ev->u.set_param.len));
-}
-
 static int
 iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
 {
        char *data = (char*)ev + sizeof(*ev);
        struct iscsi_cls_conn *conn;
        struct iscsi_cls_session *session;
-       int err = 0;
-       uint32_t value = 0;
+       int err = 0, value = 0;
 
        session = iscsi_session_lookup(ev->u.set_param.sid);
        conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
@@ -887,42 +921,13 @@ iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
 
        switch (ev->u.set_param.param) {
        case ISCSI_PARAM_SESS_RECOVERY_TMO:
-               iscsi_copy_param(ev, &value, data);
+               sscanf(data, "%d", &value);
                if (value != 0)
                        session->recovery_tmo = value;
                break;
-       case ISCSI_PARAM_TARGET_NAME:
-               /* this should not change between logins */
-               if (session->targetname)
-                       return 0;
-
-               session->targetname = kstrdup(data, GFP_KERNEL);
-               if (!session->targetname)
-                       return -ENOMEM;
-               break;
-       case ISCSI_PARAM_TPGT:
-               iscsi_copy_param(ev, &value, data);
-               session->tpgt = value;
-               break;
-       case ISCSI_PARAM_PERSISTENT_PORT:
-               iscsi_copy_param(ev, &value, data);
-               conn->persistent_port = value;
-               break;
-       case ISCSI_PARAM_PERSISTENT_ADDRESS:
-               /*
-                * this is the address returned in discovery so it should
-                * not change between logins.
-                */
-               if (conn->persistent_address)
-                       return 0;
-
-               conn->persistent_address = kstrdup(data, GFP_KERNEL);
-               if (!conn->persistent_address)
-                       return -ENOMEM;
-               break;
        default:
-               iscsi_copy_param(ev, &value, data);
-               err = transport->set_param(conn, ev->u.set_param.param, value);
+               err = transport->set_param(conn, ev->u.set_param.param,
+                                          data, ev->u.set_param.len);
        }
 
        return err;
@@ -963,6 +968,21 @@ iscsi_if_transport_ep(struct iscsi_transport *transport,
 }
 
 static int
+iscsi_tgt_dscvr(struct iscsi_transport *transport,
+               struct iscsi_uevent *ev)
+{
+       struct sockaddr *dst_addr;
+
+       if (!transport->tgt_dscvr)
+               return -EINVAL;
+
+       dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
+       return transport->tgt_dscvr(ev->u.tgt_dscvr.type,
+                                   ev->u.tgt_dscvr.host_no,
+                                   ev->u.tgt_dscvr.enable, dst_addr);
+}
+
+static int
 iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 {
        int err = 0;
@@ -981,6 +1001,8 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
        if (!try_module_get(transport->owner))
                return -EINVAL;
 
+       priv->daemon_pid = NETLINK_CREDS(skb)->pid;
+
        switch (nlh->nlmsg_type) {
        case ISCSI_UEVENT_CREATE_SESSION:
                err = iscsi_if_create_session(priv, ev);
@@ -1048,6 +1070,9 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
        case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
                err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type);
                break;
+       case ISCSI_UEVENT_TGT_DSCVR:
+               err = iscsi_tgt_dscvr(transport, ev);
+               break;
        default:
                err = -EINVAL;
                break;
@@ -1073,7 +1098,6 @@ iscsi_if_rx(struct sock *sk, int len)
                        skb_pull(skb, skb->len);
                        goto free_skb;
                }
-               daemon_pid = NETLINK_CREDS(skb)->pid;
 
                while (skb->len >= NLMSG_SPACE(0)) {
                        int err;
@@ -1131,48 +1155,31 @@ struct class_device_attribute class_device_attr_##_prefix##_##_name =   \
 /*
  * iSCSI connection attrs
  */
-#define iscsi_conn_int_attr_show(param, format)                                \
+#define iscsi_conn_attr_show(param)                                    \
 static ssize_t                                                         \
-show_conn_int_param_##param(struct class_device *cdev, char *buf)      \
+show_conn_param_##param(struct class_device *cdev, char *buf)          \
 {                                                                      \
-       uint32_t value = 0;                                             \
        struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev);         \
        struct iscsi_transport *t = conn->transport;                    \
-                                                                       \
-       t->get_conn_param(conn, param, &value);                         \
-       return snprintf(buf, 20, format"\n", value);                    \
+       return t->get_conn_param(conn, param, buf);                     \
 }
 
-#define iscsi_conn_int_attr(field, param, format)                      \
-       iscsi_conn_int_attr_show(param, format)                         \
-static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_int_param_##param, \
+#define iscsi_conn_attr(field, param)                                  \
+       iscsi_conn_attr_show(param)                                     \
+static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
                        NULL);
 
-iscsi_conn_int_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH, "%u");
-iscsi_conn_int_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH, "%u");
-iscsi_conn_int_attr(header_digest, ISCSI_PARAM_HDRDGST_EN, "%d");
-iscsi_conn_int_attr(data_digest, ISCSI_PARAM_DATADGST_EN, "%d");
-iscsi_conn_int_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN, "%d");
-iscsi_conn_int_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN, "%d");
-iscsi_conn_int_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT, "%d");
-iscsi_conn_int_attr(port, ISCSI_PARAM_CONN_PORT, "%d");
-
-#define iscsi_conn_str_attr_show(param)                                        \
-static ssize_t                                                         \
-show_conn_str_param_##param(struct class_device *cdev, char *buf)      \
-{                                                                      \
-       struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev);         \
-       struct iscsi_transport *t = conn->transport;                    \
-       return t->get_conn_str_param(conn, param, buf);                 \
-}
-
-#define iscsi_conn_str_attr(field, param)                              \
-       iscsi_conn_str_attr_show(param)                                 \
-static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_str_param_##param, \
-                       NULL);
-
-iscsi_conn_str_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
-iscsi_conn_str_attr(address, ISCSI_PARAM_CONN_ADDRESS);
+iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH);
+iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH);
+iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN);
+iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
+iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
+iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
+iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
+iscsi_conn_attr(port, ISCSI_PARAM_CONN_PORT);
+iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
+iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
+iscsi_conn_attr(address, ISCSI_PARAM_CONN_ADDRESS);
 
 #define iscsi_cdev_to_session(_cdev) \
        iscsi_dev_to_session(_cdev->dev)
@@ -1180,61 +1187,36 @@ iscsi_conn_str_attr(address, ISCSI_PARAM_CONN_ADDRESS);
 /*
  * iSCSI session attrs
  */
-#define iscsi_session_int_attr_show(param, format)                     \
+#define iscsi_session_attr_show(param)                                 \
 static ssize_t                                                         \
-show_session_int_param_##param(struct class_device *cdev, char *buf)   \
-{                                                                      \
-       uint32_t value = 0;                                             \
-       struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev);        \
-       struct iscsi_transport *t = session->transport;                 \
-                                                                       \
-       t->get_session_param(session, param, &value);                   \
-       return snprintf(buf, 20, format"\n", value);                    \
-}
-
-#define iscsi_session_int_attr(field, param, format)                   \
-       iscsi_session_int_attr_show(param, format)                      \
-static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_int_param_##param, \
-                       NULL);
-
-iscsi_session_int_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, "%d");
-iscsi_session_int_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, "%hu");
-iscsi_session_int_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, "%d");
-iscsi_session_int_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, "%u");
-iscsi_session_int_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, "%u");
-iscsi_session_int_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, "%d");
-iscsi_session_int_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, "%d");
-iscsi_session_int_attr(erl, ISCSI_PARAM_ERL, "%d");
-iscsi_session_int_attr(tpgt, ISCSI_PARAM_TPGT, "%d");
-
-#define iscsi_session_str_attr_show(param)                             \
-static ssize_t                                                         \
-show_session_str_param_##param(struct class_device *cdev, char *buf)   \
+show_session_param_##param(struct class_device *cdev, char *buf)       \
 {                                                                      \
        struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \
        struct iscsi_transport *t = session->transport;                 \
-       return t->get_session_str_param(session, param, buf);           \
+       return t->get_session_param(session, param, buf);               \
 }
 
-#define iscsi_session_str_attr(field, param)                           \
-       iscsi_session_str_attr_show(param)                              \
-static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_str_param_##param, \
+#define iscsi_session_attr(field, param)                               \
+       iscsi_session_attr_show(param)                                  \
+static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
                        NULL);
 
-iscsi_session_str_attr(targetname, ISCSI_PARAM_TARGET_NAME);
+iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME);
+iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN);
+iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T);
+iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN);
+iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST);
+iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST);
+iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN);
+iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN);
+iscsi_session_attr(erl, ISCSI_PARAM_ERL);
+iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT);
 
-/*
- * Private session and conn attrs. userspace uses several iscsi values
- * to identify each session between reboots. Some of these values may not
- * be present in the iscsi_transport/LLD driver becuase userspace handles
- * login (and failback for login redirect) so for these type of drivers
- * the class manages the attrs and values for the iscsi_transport/LLD
- */
 #define iscsi_priv_session_attr_show(field, format)                    \
 static ssize_t                                                         \
-show_priv_session_##field(struct class_device *cdev, char *buf)        \
+show_priv_session_##field(struct class_device *cdev, char *buf)                \
 {                                                                      \
-       struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \
+       struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev);\
        return sprintf(buf, format"\n", session->field);                \
 }
 
@@ -1242,31 +1224,15 @@ show_priv_session_##field(struct class_device *cdev, char *buf) \
        iscsi_priv_session_attr_show(field, format)                     \
 static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO, show_priv_session_##field, \
                        NULL)
-iscsi_priv_session_attr(targetname, "%s");
-iscsi_priv_session_attr(tpgt, "%d");
 iscsi_priv_session_attr(recovery_tmo, "%d");
 
-#define iscsi_priv_conn_attr_show(field, format)                       \
-static ssize_t                                                         \
-show_priv_conn_##field(struct class_device *cdev, char *buf)           \
-{                                                                      \
-       struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev);         \
-       return sprintf(buf, format"\n", conn->field);                   \
-}
-
-#define iscsi_priv_conn_attr(field, format)                            \
-       iscsi_priv_conn_attr_show(field, format)                        \
-static ISCSI_CLASS_ATTR(priv_conn, field, S_IRUGO, show_priv_conn_##field, \
-                       NULL)
-iscsi_priv_conn_attr(persistent_address, "%s");
-iscsi_priv_conn_attr(persistent_port, "%d");
-
 #define SETUP_PRIV_SESSION_RD_ATTR(field)                              \
 do {                                                                   \
        priv->session_attrs[count] = &class_device_attr_priv_sess_##field; \
        count++;                                                        \
 } while (0)
 
+
 #define SETUP_SESSION_RD_ATTR(field, param_flag)                       \
 do {                                                                   \
        if (tt->param_mask & param_flag) {                              \
@@ -1275,12 +1241,6 @@ do {                                                                     \
        }                                                               \
 } while (0)
 
-#define SETUP_PRIV_CONN_RD_ATTR(field)                                 \
-do {                                                                   \
-       priv->conn_attrs[count] = &class_device_attr_priv_conn_##field; \
-       count++;                                                        \
-} while (0)
-
 #define SETUP_CONN_RD_ATTR(field, param_flag)                          \
 do {                                                                   \
        if (tt->param_mask & param_flag) {                              \
@@ -1406,16 +1366,9 @@ iscsi_register_transport(struct iscsi_transport *tt)
        SETUP_CONN_RD_ATTR(ofmarker, ISCSI_OFMARKER_EN);
        SETUP_CONN_RD_ATTR(address, ISCSI_CONN_ADDRESS);
        SETUP_CONN_RD_ATTR(port, ISCSI_CONN_PORT);
-
-       if (tt->param_mask & ISCSI_PERSISTENT_ADDRESS)
-               SETUP_CONN_RD_ATTR(persistent_address, ISCSI_PERSISTENT_ADDRESS);
-       else
-               SETUP_PRIV_CONN_RD_ATTR(persistent_address);
-
-       if (tt->param_mask & ISCSI_PERSISTENT_PORT)
-               SETUP_CONN_RD_ATTR(persistent_port, ISCSI_PERSISTENT_PORT);
-       else
-               SETUP_PRIV_CONN_RD_ATTR(persistent_port);
+       SETUP_CONN_RD_ATTR(exp_statsn, ISCSI_EXP_STATSN);
+       SETUP_CONN_RD_ATTR(persistent_address, ISCSI_PERSISTENT_ADDRESS);
+       SETUP_CONN_RD_ATTR(persistent_port, ISCSI_PERSISTENT_PORT);
 
        BUG_ON(count > ISCSI_CONN_ATTRS);
        priv->conn_attrs[count] = NULL;
@@ -1435,18 +1388,10 @@ iscsi_register_transport(struct iscsi_transport *tt)
        SETUP_SESSION_RD_ATTR(data_pdu_in_order, ISCSI_PDU_INORDER_EN);
        SETUP_SESSION_RD_ATTR(data_seq_in_order, ISCSI_DATASEQ_INORDER_EN);
        SETUP_SESSION_RD_ATTR(erl, ISCSI_ERL);
+       SETUP_SESSION_RD_ATTR(targetname, ISCSI_TARGET_NAME);
+       SETUP_SESSION_RD_ATTR(tpgt, ISCSI_TPGT);
        SETUP_PRIV_SESSION_RD_ATTR(recovery_tmo);
 
-       if (tt->param_mask & ISCSI_TARGET_NAME)
-               SETUP_SESSION_RD_ATTR(targetname, ISCSI_TARGET_NAME);
-       else
-               SETUP_PRIV_SESSION_RD_ATTR(targetname);
-
-       if (tt->param_mask & ISCSI_TPGT)
-               SETUP_SESSION_RD_ATTR(tpgt, ISCSI_TPGT);
-       else
-               SETUP_PRIV_SESSION_RD_ATTR(tpgt);
-
        BUG_ON(count > ISCSI_SESSION_ATTRS);
        priv->session_attrs[count] = NULL;