Commit 7b7232f3 authored by Mike Christie's avatar Mike Christie Committed by

[SCSI] iscsi update: cleanup iscsi class interface

From:
michaelc@cs.wisc.edu
fujita.tomonori@lab.ntt.co.jp
da-x@monatomic.org

and err path fixup from:
ogerlitz@voltaire.com

This patch cleans up that interface by having the lld and class
pass a iscsi_cls_session or iscsi_cls_conn between each other when
the function is used by HW and SW iscsi llds. This way the lld
does not have to remember if it has to send a handle or pointer
and a handle or pointer to connection, session or host.

This also has the class verify the session handle that gets passed from
userspace instead of using the pointer passed into the kernel directly.
Signed-off-by: default avatarMike Christie <michaelc@cs.wisc.edu>
Signed-off-by: default avatarAlex Aizman <itn780@yahoo.com>
Signed-off-by: default avatarDmitry Yusupov <dmitry_yus@yahoo.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent bb08f92e
...@@ -146,7 +146,7 @@ iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err) ...@@ -146,7 +146,7 @@ iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err)
spin_unlock_irqrestore(&session->lock, flags); spin_unlock_irqrestore(&session->lock, flags);
set_bit(SUSPEND_BIT, &conn->suspend_tx); set_bit(SUSPEND_BIT, &conn->suspend_tx);
set_bit(SUSPEND_BIT, &conn->suspend_rx); set_bit(SUSPEND_BIT, &conn->suspend_rx);
iscsi_conn_error(iscsi_handle(conn), err); iscsi_conn_error(conn->cls_conn, err);
} }
static inline int static inline int
...@@ -689,7 +689,7 @@ iscsi_hdr_recv(struct iscsi_conn *conn) ...@@ -689,7 +689,7 @@ iscsi_hdr_recv(struct iscsi_conn *conn)
break; break;
if (!conn->in.datalen) { if (!conn->in.datalen) {
rc = iscsi_recv_pdu(iscsi_handle(conn), hdr, rc = iscsi_recv_pdu(conn->cls_conn, hdr,
NULL, 0); NULL, 0);
if (conn->login_mtask != mtask) { if (conn->login_mtask != mtask) {
spin_lock(&session->lock); spin_lock(&session->lock);
...@@ -737,7 +737,7 @@ iscsi_hdr_recv(struct iscsi_conn *conn) ...@@ -737,7 +737,7 @@ iscsi_hdr_recv(struct iscsi_conn *conn)
if (!conn->in.datalen) { if (!conn->in.datalen) {
struct iscsi_mgmt_task *mtask; struct iscsi_mgmt_task *mtask;
rc = iscsi_recv_pdu(iscsi_handle(conn), hdr, rc = iscsi_recv_pdu(conn->cls_conn, hdr,
NULL, 0); NULL, 0);
mtask = (struct iscsi_mgmt_task *) mtask = (struct iscsi_mgmt_task *)
session->mgmt_cmds[conn->in.itt - session->mgmt_cmds[conn->in.itt -
...@@ -761,7 +761,7 @@ iscsi_hdr_recv(struct iscsi_conn *conn) ...@@ -761,7 +761,7 @@ iscsi_hdr_recv(struct iscsi_conn *conn)
rc = iscsi_check_assign_cmdsn(session, rc = iscsi_check_assign_cmdsn(session,
(struct iscsi_nopin*)hdr); (struct iscsi_nopin*)hdr);
if (!rc && hdr->ttt != ISCSI_RESERVED_TAG) if (!rc && hdr->ttt != ISCSI_RESERVED_TAG)
rc = iscsi_recv_pdu(iscsi_handle(conn), rc = iscsi_recv_pdu(conn->cls_conn,
hdr, NULL, 0); hdr, NULL, 0);
} else } else
rc = ISCSI_ERR_PROTO; rc = ISCSI_ERR_PROTO;
...@@ -1044,7 +1044,7 @@ iscsi_data_recv(struct iscsi_conn *conn) ...@@ -1044,7 +1044,7 @@ iscsi_data_recv(struct iscsi_conn *conn)
goto exit; goto exit;
} }
rc = iscsi_recv_pdu(iscsi_handle(conn), conn->in.hdr, rc = iscsi_recv_pdu(conn->cls_conn, conn->in.hdr,
conn->data, conn->in.datalen); conn->data, conn->in.datalen);
if (!rc && conn->datadgst_en && if (!rc && conn->datadgst_en &&
...@@ -2428,19 +2428,20 @@ iscsi_pool_free(struct iscsi_queue *q, void **items) ...@@ -2428,19 +2428,20 @@ iscsi_pool_free(struct iscsi_queue *q, void **items)
} }
static struct iscsi_cls_conn * static struct iscsi_cls_conn *
iscsi_conn_create(struct Scsi_Host *shost, uint32_t conn_idx) iscsi_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
{ {
struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
struct iscsi_session *session = iscsi_hostdata(shost->hostdata); struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
struct iscsi_conn *conn; struct iscsi_conn *conn;
struct iscsi_cls_conn *cls_conn; struct iscsi_cls_conn *cls_conn;
cls_conn = iscsi_create_conn(hostdata_session(shost->hostdata), cls_conn = iscsi_create_conn(cls_session, conn_idx);
conn_idx);
if (!cls_conn) if (!cls_conn)
return NULL; return NULL;
conn = cls_conn->dd_data; conn = cls_conn->dd_data;
memset(conn, 0, sizeof(*conn));
memset(conn, 0, sizeof(struct iscsi_conn)); conn->cls_conn = cls_conn;
conn->c_stage = ISCSI_CONN_INITIAL_STAGE; conn->c_stage = ISCSI_CONN_INITIAL_STAGE;
conn->in_progress = IN_PROGRESS_WAIT_HEADER; conn->in_progress = IN_PROGRESS_WAIT_HEADER;
conn->id = conn_idx; conn->id = conn_idx;
...@@ -2625,11 +2626,13 @@ iscsi_conn_destroy(struct iscsi_cls_conn *cls_conn) ...@@ -2625,11 +2626,13 @@ iscsi_conn_destroy(struct iscsi_cls_conn *cls_conn)
} }
static int static int
iscsi_conn_bind(iscsi_sessionh_t sessionh, iscsi_connh_t connh, iscsi_conn_bind(struct iscsi_cls_session *cls_session,
uint32_t transport_fd, int is_leading) struct iscsi_cls_conn *cls_conn, uint32_t transport_fd,
int is_leading)
{ {
struct iscsi_session *session = iscsi_ptr(sessionh); struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
struct iscsi_conn *tmp = ERR_PTR(-EEXIST), *conn = iscsi_ptr(connh); struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
struct iscsi_conn *tmp = ERR_PTR(-EEXIST), *conn = cls_conn->dd_data;
struct sock *sk; struct sock *sk;
struct socket *sock; struct socket *sock;
int err; int err;
...@@ -2703,9 +2706,9 @@ iscsi_conn_bind(iscsi_sessionh_t sessionh, iscsi_connh_t connh, ...@@ -2703,9 +2706,9 @@ iscsi_conn_bind(iscsi_sessionh_t sessionh, iscsi_connh_t connh,
} }
static int static int
iscsi_conn_start(iscsi_connh_t connh) iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
{ {
struct iscsi_conn *conn = iscsi_ptr(connh); struct iscsi_conn *conn = cls_conn->dd_data;
struct iscsi_session *session = conn->session; struct iscsi_session *session = conn->session;
struct sock *sk; struct sock *sk;
...@@ -2754,9 +2757,9 @@ iscsi_conn_start(iscsi_connh_t connh) ...@@ -2754,9 +2757,9 @@ iscsi_conn_start(iscsi_connh_t connh)
} }
static void static void
iscsi_conn_stop(iscsi_connh_t connh, int flag) iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
{ {
struct iscsi_conn *conn = iscsi_ptr(connh); struct iscsi_conn *conn = cls_conn->dd_data;
struct iscsi_session *session = conn->session; struct iscsi_session *session = conn->session;
struct sock *sk; struct sock *sk;
unsigned long flags; unsigned long flags;
...@@ -3253,9 +3256,9 @@ static struct scsi_host_template iscsi_sht = { ...@@ -3253,9 +3256,9 @@ static struct scsi_host_template iscsi_sht = {
static struct iscsi_transport iscsi_tcp_transport; static struct iscsi_transport iscsi_tcp_transport;
static struct Scsi_Host * static struct iscsi_cls_session *
iscsi_session_create(struct scsi_transport_template *scsit, iscsi_session_create(struct scsi_transport_template *scsit,
uint32_t initial_cmdsn) uint32_t initial_cmdsn, uint32_t *sid)
{ {
struct Scsi_Host *shost; struct Scsi_Host *shost;
struct iscsi_session *session; struct iscsi_session *session;
...@@ -3275,6 +3278,7 @@ iscsi_session_create(struct scsi_transport_template *scsit, ...@@ -3275,6 +3278,7 @@ iscsi_session_create(struct scsi_transport_template *scsit,
session->exp_cmdsn = initial_cmdsn + 1; session->exp_cmdsn = initial_cmdsn + 1;
session->max_cmdsn = initial_cmdsn + 1; session->max_cmdsn = initial_cmdsn + 1;
session->max_r2t = 1; session->max_r2t = 1;
*sid = shost->host_no;
/* initialize SCSI PDU commands pool */ /* initialize SCSI PDU commands pool */
if (iscsi_pool_init(&session->cmdpool, session->cmds_max, if (iscsi_pool_init(&session->cmdpool, session->cmds_max,
...@@ -3311,7 +3315,7 @@ iscsi_session_create(struct scsi_transport_template *scsit, ...@@ -3311,7 +3315,7 @@ iscsi_session_create(struct scsi_transport_template *scsit,
if (iscsi_r2tpool_alloc(session)) if (iscsi_r2tpool_alloc(session))
goto r2tpool_alloc_fail; goto r2tpool_alloc_fail;
return shost; return hostdata_session(shost->hostdata);
r2tpool_alloc_fail: r2tpool_alloc_fail:
for (cmd_i = 0; cmd_i < session->mgmtpool_max; cmd_i++) for (cmd_i = 0; cmd_i < session->mgmtpool_max; cmd_i++)
...@@ -3321,12 +3325,14 @@ iscsi_session_create(struct scsi_transport_template *scsit, ...@@ -3321,12 +3325,14 @@ iscsi_session_create(struct scsi_transport_template *scsit,
mgmtpool_alloc_fail: mgmtpool_alloc_fail:
iscsi_pool_free(&session->cmdpool, (void**)session->cmds); iscsi_pool_free(&session->cmdpool, (void**)session->cmds);
cmdpool_alloc_fail: cmdpool_alloc_fail:
iscsi_transport_destroy_session(shost);
return NULL; return NULL;
} }
static void static void
iscsi_session_destroy(struct Scsi_Host *shost) iscsi_session_destroy(struct iscsi_cls_session *cls_session)
{ {
struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
struct iscsi_session *session = iscsi_hostdata(shost->hostdata); struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
int cmd_i; int cmd_i;
struct iscsi_data_task *dtask, *n; struct iscsi_data_task *dtask, *n;
...@@ -3350,10 +3356,10 @@ iscsi_session_destroy(struct Scsi_Host *shost) ...@@ -3350,10 +3356,10 @@ iscsi_session_destroy(struct Scsi_Host *shost)
} }
static int static int
iscsi_conn_set_param(iscsi_connh_t connh, enum iscsi_param param, iscsi_conn_set_param(struct iscsi_cls_conn *cls_conn, enum iscsi_param param,
uint32_t value) uint32_t value)
{ {
struct iscsi_conn *conn = iscsi_ptr(connh); struct iscsi_conn *conn = cls_conn->dd_data;
struct iscsi_session *session = conn->session; struct iscsi_session *session = conn->session;
spin_lock_bh(&session->lock); spin_lock_bh(&session->lock);
...@@ -3495,9 +3501,10 @@ iscsi_conn_set_param(iscsi_connh_t connh, enum iscsi_param param, ...@@ -3495,9 +3501,10 @@ iscsi_conn_set_param(iscsi_connh_t connh, enum iscsi_param param,
} }
static int static int
iscsi_session_get_param(struct Scsi_Host *shost, iscsi_session_get_param(struct iscsi_cls_session *cls_session,
enum iscsi_param param, uint32_t *value) enum iscsi_param param, uint32_t *value)
{ {
struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
struct iscsi_session *session = iscsi_hostdata(shost->hostdata); struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
switch(param) { switch(param) {
...@@ -3539,9 +3546,10 @@ iscsi_session_get_param(struct Scsi_Host *shost, ...@@ -3539,9 +3546,10 @@ iscsi_session_get_param(struct Scsi_Host *shost,
} }
static int static int
iscsi_conn_get_param(void *data, enum iscsi_param param, uint32_t *value) iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
enum iscsi_param param, uint32_t *value)
{ {
struct iscsi_conn *conn = data; struct iscsi_conn *conn = cls_conn->dd_data;
switch(param) { switch(param) {
case ISCSI_PARAM_MAX_RECV_DLENGTH: case ISCSI_PARAM_MAX_RECV_DLENGTH:
...@@ -3564,9 +3572,9 @@ iscsi_conn_get_param(void *data, enum iscsi_param param, uint32_t *value) ...@@ -3564,9 +3572,9 @@ iscsi_conn_get_param(void *data, enum iscsi_param param, uint32_t *value)
} }
static void static void
iscsi_conn_get_stats(iscsi_connh_t connh, struct iscsi_stats *stats) iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
{ {
struct iscsi_conn *conn = iscsi_ptr(connh); struct iscsi_conn *conn = cls_conn->dd_data;
stats->txdata_octets = conn->txdata_octets; stats->txdata_octets = conn->txdata_octets;
stats->rxdata_octets = conn->rxdata_octets; stats->rxdata_octets = conn->rxdata_octets;
...@@ -3587,10 +3595,10 @@ iscsi_conn_get_stats(iscsi_connh_t connh, struct iscsi_stats *stats) ...@@ -3587,10 +3595,10 @@ iscsi_conn_get_stats(iscsi_connh_t connh, struct iscsi_stats *stats)
} }
static int static int
iscsi_conn_send_pdu(iscsi_connh_t connh, struct iscsi_hdr *hdr, char *data, iscsi_conn_send_pdu(struct iscsi_cls_conn *cls_conn, struct iscsi_hdr *hdr,
uint32_t data_size) char *data, uint32_t data_size)
{ {
struct iscsi_conn *conn = iscsi_ptr(connh); struct iscsi_conn *conn = cls_conn->dd_data;
int rc; int rc;
mutex_lock(&conn->xmitmutex); mutex_lock(&conn->xmitmutex);
......
...@@ -113,7 +113,10 @@ struct iscsi_tcp_recv { ...@@ -113,7 +113,10 @@ struct iscsi_tcp_recv {
int datadgst; int datadgst;
}; };
struct iscsi_cls_conn;
struct iscsi_conn { struct iscsi_conn {
struct iscsi_cls_conn *cls_conn; /* ptr to class connection */
struct iscsi_hdr hdr; /* header placeholder */ struct iscsi_hdr hdr; /* header placeholder */
char hdrext[4*sizeof(__u16) + char hdrext[4*sizeof(__u16) +
sizeof(__u32)]; sizeof(__u32)];
......
This diff is collapsed.
...@@ -163,9 +163,6 @@ enum iscsi_param { ...@@ -163,9 +163,6 @@ enum iscsi_param {
}; };
#define ISCSI_PARAM_MAX 14 #define ISCSI_PARAM_MAX 14
typedef uint64_t iscsi_sessionh_t; /* iSCSI Data-Path session handle */
typedef uint64_t iscsi_connh_t; /* iSCSI Data-Path connection handle */
#define iscsi_ptr(_handle) ((void*)(unsigned long)_handle) #define iscsi_ptr(_handle) ((void*)(unsigned long)_handle)
#define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr) #define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr)
#define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata)) #define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata))
......
...@@ -63,25 +63,28 @@ struct iscsi_transport { ...@@ -63,25 +63,28 @@ struct iscsi_transport {
int max_lun; int max_lun;
unsigned int max_conn; unsigned int max_conn;
unsigned int max_cmd_len; unsigned int max_cmd_len;
struct Scsi_Host *(*create_session) (struct scsi_transport_template *t, struct iscsi_cls_session *(*create_session)
uint32_t initial_cmdsn); (struct scsi_transport_template *t, uint32_t sn, uint32_t *sid);
void (*destroy_session) (struct Scsi_Host *shost); void (*destroy_session) (struct iscsi_cls_session *session);
struct iscsi_cls_conn *(*create_conn) (struct Scsi_Host *shost, struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess,
uint32_t cid); uint32_t cid);
int (*bind_conn) (iscsi_sessionh_t session, iscsi_connh_t conn, int (*bind_conn) (struct iscsi_cls_session *session,
struct iscsi_cls_conn *cls_conn,
uint32_t transport_fd, int is_leading); uint32_t transport_fd, int is_leading);
int (*start_conn) (iscsi_connh_t conn); int (*start_conn) (struct iscsi_cls_conn *conn);
void (*stop_conn) (iscsi_connh_t conn, int flag); void (*stop_conn) (struct iscsi_cls_conn *conn, int flag);
void (*destroy_conn) (struct iscsi_cls_conn *conn); void (*destroy_conn) (struct iscsi_cls_conn *conn);
int (*set_param) (iscsi_connh_t conn, enum iscsi_param param, int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param,
uint32_t value); uint32_t value);
int (*get_conn_param) (void *conndata, enum iscsi_param param, int (*get_conn_param) (struct iscsi_cls_conn *conn,
enum iscsi_param param,
uint32_t *value); uint32_t *value);
int (*get_session_param) (struct Scsi_Host *shost, int (*get_session_param) (struct iscsi_cls_session *session,
enum iscsi_param param, uint32_t *value); enum iscsi_param param, uint32_t *value);
int (*send_pdu) (iscsi_connh_t conn, struct iscsi_hdr *hdr, int (*send_pdu) (struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
char *data, uint32_t data_size); char *data, uint32_t data_size);
void (*get_stats) (iscsi_connh_t conn, struct iscsi_stats *stats); void (*get_stats) (struct iscsi_cls_conn *conn,
struct iscsi_stats *stats);
}; };
/* /*
...@@ -93,15 +96,14 @@ extern int iscsi_unregister_transport(struct iscsi_transport *tt); ...@@ -93,15 +96,14 @@ extern int iscsi_unregister_transport(struct iscsi_transport *tt);
/* /*
* control plane upcalls * control plane upcalls
*/ */
extern void iscsi_conn_error(iscsi_connh_t conn, enum iscsi_err error); extern void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error);
extern int iscsi_recv_pdu(iscsi_connh_t conn, struct iscsi_hdr *hdr, extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
char *data, uint32_t data_size); char *data, uint32_t data_size);
struct iscsi_cls_conn { struct iscsi_cls_conn {
struct list_head conn_list; /* item in connlist */ struct list_head conn_list; /* item in connlist */
void *dd_data; /* LLD private data */ void *dd_data; /* LLD private data */
struct iscsi_transport *transport; struct iscsi_transport *transport;
iscsi_connh_t connh;
int active; /* must be accessed with the connlock */ int active; /* must be accessed with the connlock */
struct device dev; /* sysfs transport/container device */ struct device dev; /* sysfs transport/container device */
struct mempool_zone *z_error; struct mempool_zone *z_error;
...@@ -113,7 +115,7 @@ struct iscsi_cls_conn { ...@@ -113,7 +115,7 @@ struct iscsi_cls_conn {
container_of(_dev, struct iscsi_cls_conn, dev) container_of(_dev, struct iscsi_cls_conn, dev)
struct iscsi_cls_session { struct iscsi_cls_session {
struct list_head list; /* item in session_list */ struct list_head sess_list; /* item in session_list */
struct iscsi_transport *transport; struct iscsi_transport *transport;
struct device dev; /* sysfs transport/container device */ struct device dev; /* sysfs transport/container device */
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment