This is populated by iscsiadm in 'session' mode when the '-r' options is
given, and passed along in the session_rec_t.  It limits the operation
of exec_node_op to only the specific session specified by the user.

This is a prerequisite for "multiple sessions per iface recond".

Copyright (c) 2011 Dell Inc.
Signed-off-by: Jim Ramsay <jim_ram...@dell.com>
---
 usr/config.h     |    2 ++
 usr/idbm.c       |    5 ++++-
 usr/initiator.c  |    3 ++-
 usr/iscsi_util.c |   18 ++++++++++++------
 usr/iscsi_util.h |    5 ++++-
 usr/iscsiadm.c   |   19 ++++++++++++++-----
 6 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/usr/config.h b/usr/config.h
index 5cb4d56..579c8ec 100644
--- a/usr/config.h
+++ b/usr/config.h
@@ -193,6 +193,8 @@ typedef struct session_rec {
        struct iscsi_session_timeout_config     timeo;
        struct iscsi_error_timeout_config       err_timeo;
        struct iscsi_session_operational_config iscsi;
+       struct session_info*                    info;
+       unsigned                                sid;
 } session_rec_t;
 
 #define ISCSI_TRANSPORT_NAME_MAXLEN 16
diff --git a/usr/idbm.c b/usr/idbm.c
index 2cb346d..7e10929 100644
--- a/usr/idbm.c
+++ b/usr/idbm.c
@@ -2435,6 +2435,8 @@ void idbm_node_setup_defaults(node_rec_t *rec)
        rec->session.err_timeo.tgt_reset_timeout = DEF_TGT_RESET_TIMEO;
        rec->session.err_timeo.host_reset_timeout = DEF_HOST_RESET_TIMEO;
        rec->session.timeo.replacement_timeout = DEF_REPLACEMENT_TIMEO;
+       rec->session.info = NULL;
+       rec->session.sid = 0;
        idbm_setup_session_defaults(&rec->session.iscsi);
 
        for (i=0; i<ISCSI_CONN_MAX; i++) {
@@ -2462,7 +2464,8 @@ idbm_find_rec_in_list(struct list_head *rec_list, char 
*targetname, char *addr,
        struct node_rec *rec;
 
        list_for_each_entry(rec, rec_list, list) {
-               if (__iscsi_match_session(rec, targetname, addr, port, iface))
+               if (__iscsi_match_session(rec, targetname, addr, port, iface,
+                               MATCH_ANY_SID))
                        return rec;
        }
 
diff --git a/usr/initiator.c b/usr/initiator.c
index 5eb05b5..c004406 100644
--- a/usr/initiator.c
+++ b/usr/initiator.c
@@ -1611,7 +1611,8 @@ static iscsi_session_t* session_find_by_rec(node_rec_t 
*rec)
                        if (__iscsi_match_session(rec, session->nrec.name,
                                         session->nrec.conn[0].address,
                                         session->nrec.conn[0].port,
-                                        &session->nrec.iface))
+                                        &session->nrec.iface,
+                                        MATCH_ANY_SID))
                                return session;
                }
        }
diff --git a/usr/iscsi_util.c b/usr/iscsi_util.c
index 4481294..d7e97f0 100644
--- a/usr/iscsi_util.c
+++ b/usr/iscsi_util.c
@@ -33,6 +33,7 @@
 #include "iscsi_settings.h"
 #include "iface.h"
 #include "session_info.h"
+#include "iscsi_util.h"
 
 void daemon_init(void)
 {
@@ -285,24 +286,28 @@ free_res1:
 }
 
 int __iscsi_match_session(node_rec_t *rec, char *targetname,
-                         char *address, int port, struct iface_rec *iface)
+                         char *address, int port, struct iface_rec *iface,
+                         unsigned sid)
 {
        if (!rec) {
                log_debug(6, "no rec info to match\n");
                return 1;
        }
 
-       log_debug(6, "match session [%s,%s,%d][%s %s,%s,%s]",
+       log_debug(6, "match session [%s,%s,%d][%s %s,%s,%s]:%u",
                  rec->name, rec->conn[0].address, rec->conn[0].port,
                  rec->iface.name, rec->iface.transport_name,
-                 rec->iface.hwaddress, rec->iface.ipaddress);
+                 rec->iface.hwaddress, rec->iface.ipaddress,
+                 rec->session.sid);
 
        if (iface)
-               log_debug(6, "to [%s,%s,%d][%s %s,%s,%s]",
+               log_debug(6, "to [%s,%s,%d][%s %s,%s,%s]:%u",
                          targetname, address, port, iface->name,
                          iface->transport_name, iface->hwaddress,
-                         iface->ipaddress);
+                         iface->ipaddress, sid);
 
+       if (rec->session.sid && sid && rec->session.sid != sid)
+               return 0;
 
        if (strlen(rec->name) && strcmp(rec->name, targetname))
                return 0;
@@ -323,5 +328,6 @@ int iscsi_match_session(void *data, struct session_info 
*info)
 {
        return __iscsi_match_session(data, info->targetname,
                                     info->persistent_address,
-                                    info->persistent_port, &info->iface);
+                                    info->persistent_port, &info->iface,
+                                        info->sid);
 }
diff --git a/usr/iscsi_util.h b/usr/iscsi_util.h
index 87b2bb2..9428867 100644
--- a/usr/iscsi_util.h
+++ b/usr/iscsi_util.h
@@ -16,7 +16,10 @@ extern char *str_to_ipport(char *str, int *port, int *tgpt);
 extern int iscsi_match_session(void *data, struct session_info *info);
 extern int __iscsi_match_session(struct node_rec *rec, char *targetname,
                                 char *address, int port,
-                                struct iface_rec *iface);
+                                struct iface_rec *iface,
+                                unsigned sid);
+
+#define MATCH_ANY_SID 0
 
 extern char *strstrip(char *s);
 extern char *cfg_get_string_param(char *pathname, const char *key);
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
index e3a6b81..937b99e 100644
--- a/usr/iscsiadm.c
+++ b/usr/iscsiadm.c
@@ -292,7 +292,12 @@ for_each_session(struct node_rec *rec, 
iscsi_sysfs_session_op_fn *fn)
 {
        int err, num_found = 0;
 
-       err = iscsi_sysfs_for_each_session(rec, &num_found, fn);
+       if (rec && rec->session.info) {
+               num_found = 1;
+               err = fn(rec, rec->session.info);
+       } else {
+               err = iscsi_sysfs_for_each_session(rec, &num_found, fn);
+       }
        if (err)
                log_error("Could not execute operation on all sessions: %s",
                          iscsi_err_to_str(err));
@@ -465,7 +470,7 @@ static int rec_match_fn(void *data, node_rec_t *rec)
 
        if (!__iscsi_match_session(op_data->match_rec, rec->name,
                                   rec->conn[0].address, rec->conn[0].port,
-                                  &rec->iface))
+                                  &rec->iface, rec->session.sid))
                return -1;
        return op_data->fn(op_data->data, rec);
 }
@@ -850,7 +855,8 @@ static int delete_stale_rec(void *data, struct node_rec 
*rec)
                                          new_rec->name,
                                          new_rec->conn[0].address,
                                          new_rec->conn[0].port,
-                                         &new_rec->iface))
+                                         &new_rec->iface,
+                                         new_rec->session.sid))
                        return -1;
        }
        /* if there is a error we can continue on */
@@ -1239,9 +1245,10 @@ static int exec_node_op(int op, int do_login, int 
do_logout,
        struct db_set_param set_param;
 
        if (rec)
-               log_debug(2, "%s: %s:%s node [%s,%s,%d]", __FUNCTION__,
+               log_debug(2, "%s: %s:%s node [%s,%s,%d] sid %u", __FUNCTION__,
                          rec->iface.transport_name, rec->iface.name,
-                         rec->name, rec->conn[0].address, rec->conn[0].port);
+                         rec->name, rec->conn[0].address, rec->conn[0].port,
+                         rec->session.sid);
 
        if (op == OP_NEW) {
                rc = add_static_recs(rec);
@@ -2144,6 +2151,8 @@ main(int argc, char **argv)
                                rc = ISCSI_ERR_NOMEM;
                                goto free_info;
                        }
+                       rec->session.info = info;
+                       rec->session.sid = sid;
 
                        /* drop down to node ops */
                        rc = exec_node_op(op, do_login, do_logout, do_show,
-- 
1.7.5.3


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

Reply via email to