Hi Mike,

I have taken care of points you mentioned in last mail.

Following is git diff with my comments  (for patch without comments please
refer attachment):-

Note1:
I am not sure how much CHAP length user can use is needed so I kept it to
huge limit like iqn, if you want to decrease it, please let me know what
limit should be kept.


Note2:
Forcing session_info_print_tree() to always pass 0 for do_show, because of
two reasons:-
1. As this part of code comes into picture when iscsiadm -m host -P3 command
is used, and this command throws error if you use -S option.
2. Since I have to assume some value, so I took 0 (ie to not to show
password) as to view password/session info we already have iscsiadm -m
session -P3 -S :)

Note3:

I have created two new flags SESSION_INFO_ISCSI_TIM and
SESSION_INFO_ISCSI_AUTH, as they might be needed in future, otherwise
if you want I can merge code these two flag's code into the existing
one flag- SESSION_INFO_ISCSI_PARAMS.


Signed-off-by: Rahul Gupta <[email protected]>

Date: Wed July 27 0:10:30 2011 IST.

iSCSI user space  TODO item-2 : Displaying timeout and CHAP.

diff --git a/include/iscsi_proto.h b/include/iscsi_proto.h
index 1c69feb..5230b8c 100644
--- a/include/iscsi_proto.h
+++ b/include/iscsi_proto.h
@@ -619,6 +619,7 @@ struct iscsi_reject {
 #define KEY_MAXLEN             64 #define VALUE_MAXLEN         255
 #define TARGET_NAME_MAXLEN     VALUE_MAXLEN
+#define CHAP_LEN               VALUE_MAXLEN

 #define ISCSI_DEF_MAX_RECV_SEG_LEN             8192
 #define ISCSI_MIN_MAX_RECV_SEG_LEN             512
diff --git a/usr/host.c b/usr/host.c
index ec983b0..d171455 100644
--- a/usr/host.c
+++ b/usr/host.c
@@ -151,7 +151,7 @@ static int host_info_print_tree(void *data, struct
host_info *hinfo)
        printf("\tSessions:\n");
        printf("\t*********\n");

-       session_info_print_tree(&sessions, "\t",
session_info_flags);+   session_info_print_tree(&sessions, "\t",
session_info_flags, 0);
        session_info_free_list(&sessions);
        return 0;
 }
diff --git a/usr/iscsi_sysfs.c b/usr/iscsi_sysfs.c
index e82fe80..7e8f03f 100644
--- a/usr/iscsi_sysfs.c
+++ b/usr/iscsi_sysfs.c
@@ -675,8 +675,72 @@ int iscsi_sysfs_get_sessioninfo_by_id(struct
session_info *info, char *session)
                return ISCSI_ERR_SYSFS_LOOKUP;
        }

+       ret = sysfs_get_str(session, ISCSI_SESSION_SUBSYS, "username",
+                               (info->chap).username,
+                               sizeof((info->chap).username));
+       if (ret) {
+               log_error("could not read session targetname: %d", ret);
+               return ISCSI_ERR_SYSFS_LOOKUP;
+       }
+       if ((info->chap).username[0] == '\0')
+               strcpy((info->chap).username, "<NULL>");
+       if (ret) {
+               log_error("could not read session username: %d", ret);
+               return ISCSI_ERR_SYSFS_LOOKUP;
+       }
+
+       ret = sysfs_get_str(session, ISCSI_SESSION_SUBSYS, "password",
+                               (info->chap).password,
+                               sizeof((info->chap).password));
+       if ((info->chap).password[0] == '\0')
+               strcpy((info->chap).password, "<NULL>");
+       if (ret) {
+               log_error("could not read session password: %d", ret);
+               return ISCSI_ERR_SYSFS_LOOKUP;
+       }
+
+       ret = sysfs_get_str(session, ISCSI_SESSION_SUBSYS, "username_in",
+                               (info->chap).username_in,
+                               sizeof((info->chap).username_in));
+       if ((info->chap).username_in[0] == '\0')
+               strcpy((info->chap).username_in, "<NULL>");
+       if (ret) {
+               log_error("could not read session username_in: %d", ret);
+               return ISCSI_ERR_SYSFS_LOOKUP;
+       }
+       ret = sysfs_get_str(session, ISCSI_SESSION_SUBSYS, "password_in",
+                               (info->chap).password_in,
+                               sizeof((info->chap).password_in));
+       if ((info->chap).password_in[0] == '\0')
+               strcpy((info->chap).password_in, "<NULL>");
+       if (ret) {
+               log_error("could not read session password_in: %d", ret);
+               return ISCSI_ERR_SYSFS_LOOKUP;
+       }
+
+       ret = sysfs_get_int(session, ISCSI_SESSION_SUBSYS, "recovery_tmo",
+                               &((info->tmo).recovery_tmo));
+       if (ret) {
+               log_error("could not read session recovery_tmo: %d", ret);
+               return ISCSI_ERR_SYSFS_LOOKUP;
+       }
+
+       ret = sysfs_get_int(session, ISCSI_SESSION_SUBSYS, "lu_reset_tmo",
+                               &((info->tmo).lu_reset_tmo));
+       if (ret) {
+               log_error("could not read session lu_reset_tmo: %d", ret);
+               return ISCSI_ERR_SYSFS_LOOKUP;
+       }
+
+       ret = sysfs_get_int(session, ISCSI_SESSION_SUBSYS, "abort_tmo",
+                               &((info->tmo).abort_tmo));
+       if (ret) {
+               log_error("could not read session abort_tmo: %d", ret);
+               return ISCSI_ERR_SYSFS_LOOKUP;
+       }
+
        ret = sysfs_get_int(session, ISCSI_SESSION_SUBSYS, "tpgt",
-                           &info->tpgt);
+                               &info->tpgt);
        if (ret) {
                log_error("could not read session tpgt: %d", ret);
                return ISCSI_ERR_SYSFS_LOOKUP;
@@ -741,7 +805,7 @@ int iscsi_sysfs_get_sessioninfo_by_id(struct
session_info *info, char *session)
        }

        iscsi_sysfs_read_iface(&info->iface, host_no, session);
-
+
        log_debug(7, "found targetname %s address %s pers address %s port %d "
                 "pers port %d driver %s iface name %s ipaddress %s "
                 "netdev %s hwaddress %s iname %s",
@@ -753,7 +817,7 @@ int iscsi_sysfs_get_sessioninfo_by_id(struct
session_info *info, char *session)
                  info->iface.iname);
        return 0;
 }
-
+
 int iscsi_sysfs_for_each_session(void *data, int *nr_found,
                                 iscsi_sysfs_session_op_fn *fn)
 {
@@ -857,7 +921,7 @@ char *iscsi_sysfs_get_blockdev_from_lun(int
host_no, int target, int lun)
        }

        sysfs_len = strlcpy(path_full, sysfs_path, sizeof(path_full));
-       if(sysfs_len >= sizeof(path_full))
+       if (sysfs_len >= sizeof(path_full))
                sysfs_len = sizeof(path_full) - 1;
        path = &path_full[sysfs_len];
        strlcat(path_full, devpath, sizeof(path_full));
@@ -947,7 +1011,7 @@ static uint32_t get_target_no_from_sid(uint32_t
sid, int *err)
         * /class/iscsi_session/sessionX/device.
         */
        sysfs_len = strlcpy(path_full, sysfs_path, sizeof(path_full));
-       if(sysfs_len >= sizeof(path_full))
+       if (sysfs_len >= sizeof(path_full))
                sysfs_len = sizeof(path_full) - 1;
        path = &path_full[sysfs_len];
        strlcat(path_full, devpath, sizeof(path_full));
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
index 91d886b..3b87c3d 100644
--- a/usr/iscsiadm.c
+++ b/usr/iscsiadm.c
@@ -2245,7 +2245,8 @@ main(int argc, char **argv)

                        if (!do_logout && !do_rescan && !do_stats &&
                            op == OP_NOOP && info_level > 0) {
-                               rc = session_info_print(info_level, info);
+                               rc = session_info_print(info_level, info,
+                                                       do_show);
                                goto free_info;
                        }

@@ -2292,7 +2293,7 @@ free_info:
                                goto out;
                        }

-                       rc = session_info_print(info_level, NULL);
+                       rc = session_info_print(info_level, NULL, do_show);
                }
                break;
        default:
diff --git a/usr/session_info.c b/usr/session_info.c
index cded5e3..f1570f1 100644
--- a/usr/session_info.c
+++ b/usr/session_info.c
@@ -224,7 +224,7 @@ static int print_scsi_state(int sid, char *prefix,
unsigned int flags)
 }

 void session_info_print_tree(struct list_head *list, char *prefix,
-                            unsigned int flags)
+                            unsigned int flags, int do_show)
 {
        struct session_info *curr, *prev = NULL;

@@ -278,6 +278,34 @@ void session_info_print_tree(struct list_head
*list, char *prefix,
                        printf("%s\t\tSID: %d\n", prefix, curr->sid);
                        print_iscsi_state(curr->sid, prefix);
                }
+               if (flags & SESSION_INFO_ISCSI_TIM) {
+                       printf("%s\t\t*********\n", prefix);
+                       printf("%s\t\tTimeouts:\n", prefix);
+                       printf("%s\t\t*********\n", prefix);
+                       printf("%s\t\tRecovery Timeout: %d\n", prefix,
+                               ((curr->tmo).recovery_tmo));
+                       printf("%s\t\tLUN reset Timeout: %d\n", prefix,
+                               ((curr->tmo).lu_reset_tmo));
+                       printf("%s\t\tAbort Timeout: %d\n", prefix,
+                               ((curr->tmo).abort_tmo));
+               }
+               if (flags & SESSION_INFO_ISCSI_AUTH) {
+                       printf("%s\t\t*****\n", prefix);
+                       printf("%s\t\tCHAP:\n", prefix);
+                       printf("%s\t\t*****\n", prefix);
+                       if (!do_show) {
+                               strcpy(curr->chap.password, "********");
+                               strcpy(curr->chap.password_in, "********");
+                       }
+                       printf("%s\t\tusername: %s\n", prefix,
+                               ((curr->chap).username));
+                       printf("%s\t\tpassword: %s\n", prefix,
+                               ((curr->chap).password));
+                       printf("%s\t\tusername_in: %s\n", prefix,
+                               ((curr->chap).username_in));
+                       printf("%s\t\tpassword_in: %s\n", prefix,
+                               ((curr->chap).password_in));
+               }

                if (flags & SESSION_INFO_ISCSI_PARAMS)
                        print_iscsi_params(curr->sid, prefix);
@@ -289,7 +317,7 @@ void session_info_print_tree(struct list_head
*list, char *prefix,
        }
 }

-int session_info_print(int info_level, struct session_info *info)
+int session_info_print(int info_level, struct session_info *info, int do_show)
 {
        struct list_head list;
        int num_found = 0, err = 0;
@@ -317,17 +345,18 @@ int session_info_print(int info_level, struct
session_info *info)
                flags |= (SESSION_INFO_SCSI_DEVS | SESSION_INFO_HOST_DEVS);
                /* fall through */
        case 2:
-               flags |= SESSION_INFO_ISCSI_PARAMS;+            flags |=
(SESSION_INFO_ISCSI_PARAMS | SESSION_INFO_ISCSI_TIM
+                               | SESSION_INFO_ISCSI_AUTH);
                /* fall through */
        case 1:
                INIT_LIST_HEAD(&list);
                struct session_link_info link_info;

-               flags |= (SESSION_INFO_ISCSI_STATE |SESSION_INFO_IFACE);
+               flags |= (SESSION_INFO_ISCSI_STATE | SESSION_INFO_IFACE);
                if (info) {
                        INIT_LIST_HEAD(&info->list);
                        list_add_tail(&list, &info->list);
-                       session_info_print_tree(&list, "", flags);
+                       session_info_print_tree(&list, "", flags, do_show);
                        num_found = 1;
                        break;
                }
@@ -342,7 +371,7 @@ int session_info_print(int info_level, struct
session_info *info)
                if (err || !num_found)
                        break;

-               session_info_print_tree(&list, "", flags);
+               session_info_print_tree(&list, "", flags, do_show);
                session_info_free_list(&list);
                break;
        default:
diff --git a/usr/session_info.h b/usr/session_info.h
index 7a22aee..341888d 100644
--- a/usr/session_info.h
+++ b/usr/session_info.h
@@ -9,12 +9,29 @@

 struct list;

+struct session_timeout {
+       int abort_tmo;
+       int lu_reset_tmo;
+       int recovery_tmo;
+       int tgt_reset_tmo;
+};
+
+struct session_CHAP {
+       char username[CHAP_LEN];
+       char password[CHAP_LEN];
+       char username_in[CHAP_LEN];
+       char password_in[CHAP_LEN];
+};
+
 struct session_info {
        struct list_head list;
        /* local info */
        struct iface_rec iface;
        int sid;

+       struct session_timeout tmo;
+       struct session_CHAP chap;
+
        /* remote info */
        char targetname[TARGET_NAME_MAXLEN + 1];
        int tpgt;
@@ -37,11 +54,15 @@ struct session_link_info {
 #define SESSION_INFO_ISCSI_STATE       0x4
 #define SESSION_INFO_SCSI_DEVS         0x8
 #define SESSION_INFO_HOST_DEVS         0x10
+#define SESSION_INFO_ISCSI_TIM          0x20
+#define SESSION_INFO_ISCSI_AUTH         0x40
+

 extern int session_info_create_list(void *data, struct session_info *info);
 extern void session_info_free_list(struct list_head *list);
-extern int session_info_print(int info_level, struct session_info *match_info);
+extern int session_info_print(int info_level, struct session_info *match_info,
+                               int do_show);
 extern void session_info_print_tree(struct list_head *list, char *prefix,
-                                   unsigned int flags);
+                                   unsigned int flags, int do_show);

 #endif


Regards,
Rahul.


On Thu, Jul 21, 2011 at 12:19 AM, Mike Christie <[email protected]>wrote:

> On 07/19/2011 12:32 PM, rahul gupta wrote:
> > Hi Mike,
> >
> > As we discussed last week, I have taken up TODO- userspace list item #2.
> >
> > I have analysed and coded on some part of it on this weekend :-
> > For timeout and CHAP I have taken following parameters values from /sys
> and
> > printed it.
> >
> > [root@a usr]# ls /sys/class/iscsi_session/session17/ | grep tmo
> > abort_tmo
> > lu_reset_tmo
> > recovery_tmo
> >
> > The o/p looks like:-
> >
> > [root@a usr]# ./iscsiadm -m session -P3
> > Target: iqn.2004-05.xyz.bumblee
> >         Current Portal: 103.3.3.60:3260,1
> >         Persistent Portal: 103.3.3.60:3260,1
> >                 **********
> >                 Interface:
> >                 **********
> >                 Iface Name: default
> >                 Iface Transport: tcp
> >                 Iface Initiatorname: iqn.1994-05.com.redhat:2899883c314b
> >                 Iface IPaddress: 103.3.3.105
> >                 Iface HWaddress: default
> >                 Iface Netdev: default
> >                 SID: 17
> >                 iSCSI Connection State: LOGGED IN
> >                 iSCSI Session State: LOGGED_IN
> >                 Internal iscsid Session State: NO CHANGE
> >                 *********
> >                 Timeout:
>
> Maybe it should be Timeouts (with a 's') since there is more than 1.
>
> >                 *********
> >                 Recovery Timeout: 120
> >                 Lun reset Timeout: 30
>
>
> should probably be all caps "LUN".
>
> Looks ok though.
>
> >                 Abort Timeout: 15
> >                 **********
> >                 CHAP:
> >                 **********
> >                 username: initiator_id
> >                 password: initiator_sec1
> >                 username_in: target_id1
> >                 password_in: target_secret1
> >
> >                 ************************
> >                 Negotiated iSCSI params:
> >                 ************************
> >                 HeaderDigest: None
> >                 DataDigest: None
> >                 MaxRecvDataSegmentLength: 262144
> >                 MaxXmitDataSegmentLength: 8192
> >                 FirstBurstLength: 65536
> >                 MaxBurstLength: 262144
> >                 ImmediateData: Yes
> >                 InitialR2T: No
> >                 MaxOutstandingR2T: 1
> >                 ************************
> >                 Attached SCSI devices:
> >                 ************************
> >                 Host Number: 23 State: running
> >                 scsi23 Channel 00 Id 0 Lun: 0
> >                         Attached scsi disk sdb          State: running
> >
> >
> > If output looks ok then I will improve and forward the final patch, also
> let
> > me know if I have missed out something in timeout/CHAP.
> >
> > For displaying CHAP :-
> > Shall I display password also in text form or print '*' instead.
> > (as on running iscsiadm -m node -T <target name> -p <ip>, it displays
> only.
>
> For node mode you have to pass it the --show/-S param to show chap
> passwords. You can probably force the same thing in session mode.
>
>
>
> > I mean :-
> > [root@localhost ~]# iscsiadm -m node -T <target name> -p <ip>
> > # BEGIN RECORD 2.0-872
> > node.name = iqn.2004-05.com.xyz.bumblee2
> > node.tpgt = 1
> > node.startup = automatic
> > node.leading_login = No
> > iface.hwaddress = <empty>
> > iface.ipaddress = <empty>
> >
> > .
> > .
> > node.session.auth.authmethod = CHAP
> > node.session.auth.username = initiator_id1
> > node.session.auth.password = ********
> > node.session.auth.username_in = target_id1
> > node.session.auth.password_in = ********
> > node.session.timeo.replacement_timeout = 120
> > .
> > .
> > )
> >
> > These values needs to be printed in print level3 only or in 0/1/2.
>
>
> Maybe just level 2, because we are printing the values used for the
> iscsi session.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.

Attachment: chap_tmo_display.patch
Description: Binary data

Reply via email to