[Stgt-devel] [PATCH 5/7] iser generalize iscsi
Pete Wyckoff
pw
Mon Jul 30 21:00:31 CEST 2007
Virtualize more functions in the iscsi transport to support RDMA:
memory management, event modification, and new RDMA read/write calls.
Export some functions from iscsid.c for RDMA to use. It needs to call
directly to the TX and RX handlers when network or progress events happen.
Add session flag for RDMA. Transport flag already existed and was unused.
Add two teensy functions in natural places: be64_to_cpu and back, and
list_del_init.
Signed-off-by: Pete Wyckoff <pw at osc.edu>
---
usr/iscsi/iscsi_tcp.c | 40 +++++++++++++++++++++++++++++++---------
usr/iscsi/iscsid.c | 36 +++++++++++++++++++-----------------
usr/iscsi/iscsid.h | 8 ++++++++
usr/iscsi/transport.h | 9 +++++++++
usr/list.h | 6 ++++++
5 files changed, 73 insertions(+), 26 deletions(-)
diff --git a/usr/iscsi/iscsi_tcp.c b/usr/iscsi/iscsi_tcp.c
index 0c35aa5..e7f5989 100644
--- a/usr/iscsi/iscsi_tcp.c
+++ b/usr/iscsi/iscsi_tcp.c
@@ -183,7 +183,7 @@ static int iscsi_tcp_init(void)
return !nr_sock;
}
-static size_t iscsi_tcp_read (int ep, void *buf, size_t nbytes)
+static size_t iscsi_tcp_read(int ep, void *buf, size_t nbytes)
{
return read(ep, buf, nbytes);
}
@@ -232,13 +232,35 @@ static int iscsi_tcp_show(int ep, char *buf, int rest)
return total > 0 ? total : 0;
}
+void iscsi_event_modify(int fd, int events)
+{
+ int ret;
+
+ ret = tgt_event_modify(fd, events);
+ if (ret)
+ eprintf("tgt_event_modify failed");
+}
+
+void *iscsi_tcp_malloc(size_t sz)
+{
+ return malloc(sz);
+}
+
+void iscsi_tcp_free(void *buf)
+{
+ free(buf);
+}
+
struct iscsi_transport iscsi_tcp = {
- .name = "iscsi",
- .rdma = 0,
- .ep_init = iscsi_tcp_init,
- .ep_read = iscsi_tcp_read,
- .ep_write_begin = iscsi_tcp_write_begin,
- .ep_write_end = iscsi_tcp_write_end,
- .ep_close = iscsi_tcp_close,
- .ep_show = iscsi_tcp_show,
+ .name = "iscsi",
+ .rdma = 0,
+ .ep_init = iscsi_tcp_init,
+ .ep_read = iscsi_tcp_read,
+ .ep_write_begin = iscsi_tcp_write_begin,
+ .ep_write_end = iscsi_tcp_write_end,
+ .ep_close = iscsi_tcp_close,
+ .ep_show = iscsi_tcp_show,
+ .ep_event_modify = iscsi_event_modify,
+ .ep_malloc = iscsi_tcp_malloc,
+ .ep_free = iscsi_tcp_free,
};
diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index be0f449..4a37c6f 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -966,7 +966,7 @@ iscsi_alloc_task(struct iscsi_connection *conn, int ext_len)
struct iscsi_hdr *req = (struct iscsi_hdr *) &conn->req.bhs;
struct iscsi_task *task;
- task = malloc(sizeof(*task) + ext_len);
+ task = conn->tp->ep_malloc(sizeof(*task) + ext_len);
if (!task)
return NULL;
memset(task, 0, sizeof(*task));
@@ -988,8 +988,8 @@ void iscsi_free_task(struct iscsi_task *task)
struct iscsi_connection *conn = task->conn;
if (task->addr && task->addr != (unsigned long) task->data)
- free((void *) (unsigned long) task->addr);
- free(task);
+ task->conn->tp->ep_free((void *) (unsigned long) task->addr);
+ task->conn->tp->ep_free(task);
/* from alloc */
conn_put(conn);
}
@@ -1034,7 +1034,7 @@ static int iscsi_scsi_cmd_done(uint64_t nid, int result, struct scsi_cmd *scmd)
}
list_add_tail(&task->c_list, &task->conn->tx_clist);
- tgt_event_modify(task->conn->fd, EPOLLIN | EPOLLOUT);
+ task->conn->tp->ep_event_modify(task->conn->fd, EPOLLIN | EPOLLOUT);
return 0;
}
@@ -1126,7 +1126,7 @@ static int iscsi_target_cmd_queue(struct iscsi_task *task)
void *buf;
len = roundup(task->read_len, 4);
- buf = malloc(len);
+ buf = conn->tp->ep_malloc(len);
if (!buf)
return -ENOMEM;
scmd->bidi_uaddr = (unsigned long) buf;
@@ -1148,7 +1148,7 @@ static int iscsi_target_cmd_queue(struct iscsi_task *task)
return target_cmd_queue(conn->session->target->tid, scmd);
}
-static int iscsi_scsi_cmd_execute(struct iscsi_task *task)
+int iscsi_scsi_cmd_execute(struct iscsi_task *task)
{
struct iscsi_connection *conn = task->conn;
struct iscsi_cmd *req = (struct iscsi_cmd *) &task->req;
@@ -1158,13 +1158,13 @@ static int iscsi_scsi_cmd_execute(struct iscsi_task *task)
if (rw && task->r2t_count) {
if (!task->unsol_count) {
list_add_tail(&task->c_list, &task->conn->tx_clist);
- tgt_event_modify(conn->fd, EPOLLIN | EPOLLOUT);
+ conn->tp->ep_event_modify(conn->fd, EPOLLIN | EPOLLOUT);
}
return err;
}
task->offset = 0; /* for use as transmit pointer for data-ins */
- tgt_event_modify(conn->fd, EPOLLIN);
+ conn->tp->ep_event_modify(conn->fd, EPOLLIN);
err = iscsi_target_cmd_queue(task);
return err;
}
@@ -1194,7 +1194,7 @@ static int iscsi_tm_done(struct mgmt_req *mreq)
break;
}
list_add_tail(&task->c_list, &task->conn->tx_clist);
- tgt_event_modify(task->conn->fd, EPOLLIN | EPOLLOUT);
+ task->conn->tp->ep_event_modify(task->conn->fd, EPOLLIN | EPOLLOUT);
return 0;
}
@@ -1250,7 +1250,8 @@ static int iscsi_task_execute(struct iscsi_task *task)
case ISCSI_OP_NOOP_OUT:
case ISCSI_OP_LOGOUT:
list_add_tail(&task->c_list, &task->conn->tx_clist);
- tgt_event_modify(task->conn->fd, EPOLLIN | EPOLLOUT);
+ task->conn->tp->ep_event_modify(task->conn->fd,
+ EPOLLIN | EPOLLOUT);
break;
case ISCSI_OP_SCSI_CMD:
/* convenient directionality for our internal use */
@@ -1270,7 +1271,8 @@ static int iscsi_task_execute(struct iscsi_task *task)
err = iscsi_tm_execute(task);
if (err) {
list_add_tail(&task->c_list, &task->conn->tx_clist);
- tgt_event_modify(task->conn->fd, EPOLLIN | EPOLLOUT);
+ task->conn->tp->ep_event_modify(task->conn->fd,
+ EPOLLIN | EPOLLOUT);
}
break;
case ISCSI_OP_TEXT:
@@ -1709,7 +1711,7 @@ static int iscsi_task_tx_start(struct iscsi_connection *conn)
nodata:
dprintf("no more data\n");
- tgt_event_modify(conn->fd, EPOLLIN);
+ conn->tp->ep_event_modify(conn->fd, EPOLLIN);
return -EAGAIN;
}
@@ -1736,7 +1738,7 @@ static int do_recv(int fd, struct iscsi_connection *conn, int next_state)
return ret;
}
-static void iscsi_rx_handler(int fd, struct iscsi_connection *conn)
+void iscsi_rx_handler(int fd, struct iscsi_connection *conn)
{
int ret = 0, hdigest, ddigest;
uint32_t crc;
@@ -1873,7 +1875,7 @@ again:
conn_read_pdu(conn);
} else {
conn_write_pdu(conn);
- tgt_event_modify(fd, EPOLLOUT);
+ conn->tp->ep_event_modify(fd, EPOLLOUT);
ret = cmnd_execute(conn);
if (ret)
conn->state = STATE_CLOSE;
@@ -1903,7 +1905,7 @@ again:
return 0;
}
-static void iscsi_tx_handler(int fd, struct iscsi_connection *conn)
+void iscsi_tx_handler(int fd, struct iscsi_connection *conn)
{
int ret = 0, hdigest, ddigest;
uint32_t crc;
@@ -2017,7 +2019,7 @@ static void iscsi_tx_handler(int fd, struct iscsi_connection *conn)
else {
conn->state = STATE_SCSI;
conn_read_pdu(conn);
- tgt_event_modify(fd, EPOLLIN);
+ conn->tp->ep_event_modify(fd, EPOLLIN);
}
break;
case STATE_EXIT:
@@ -2028,7 +2030,7 @@ static void iscsi_tx_handler(int fd, struct iscsi_connection *conn)
break;
default:
conn_read_pdu(conn);
- tgt_event_modify(fd, EPOLLIN);
+ conn->tp->ep_event_modify(fd, EPOLLIN);
break;
}
}
diff --git a/usr/iscsi/iscsid.h b/usr/iscsi/iscsid.h
index a8c8cb1..95540f2 100644
--- a/usr/iscsi/iscsid.h
+++ b/usr/iscsi/iscsid.h
@@ -33,8 +33,10 @@
#define cpu_to_be16(x) __cpu_to_be16(x)
#define cpu_to_be32(x) __cpu_to_be32(x)
+#define cpu_to_be64(x) __cpu_to_be64(x)
#define be16_to_cpu(x) __be16_to_cpu(x)
#define be32_to_cpu(x) __be32_to_cpu(x)
+#define be64_to_cpu(x) __be64_to_cpu(x)
#define ISCSI_NAME_LEN 256
@@ -89,6 +91,9 @@ struct iscsi_session {
struct param session_param[ISCSI_PARAM_MAX];
char *info;
+
+ /* if this session uses rdma connections */
+ int rdma;
};
struct iscsi_task {
@@ -261,6 +266,9 @@ extern void iscsi_event_handler(int fd, int events, void *data);
extern char *text_key_find(struct iscsi_connection *conn, char *searchKey);
extern void text_key_add(struct iscsi_connection *conn, char *key, char *value);
extern void conn_read_pdu(struct iscsi_connection *conn);
+extern void iscsi_tx_handler(int fd, struct iscsi_connection *conn);
+extern void iscsi_rx_handler(int fd, struct iscsi_connection *conn);
+extern int iscsi_scsi_cmd_execute(struct iscsi_task *task);
/* iscsid.c iscsi_task */
extern void iscsi_free_task(struct iscsi_task *task);
diff --git a/usr/iscsi/transport.h b/usr/iscsi/transport.h
index ec34bb0..bfba784 100644
--- a/usr/iscsi/transport.h
+++ b/usr/iscsi/transport.h
@@ -1,6 +1,9 @@
#ifndef __TRANSPORT_H
#define __TRANSPORT_H
+struct iscsi_pdu;
+struct iscsi_task;
+
struct iscsi_transport {
const char *name;
int rdma;
@@ -11,6 +14,12 @@ struct iscsi_transport {
void (*ep_write_end)(int ep);
size_t (*ep_close) (int ep);
int (*ep_show) (int ep, char *buf, int rest);
+ int (*ep_rdma_write) (int ep, struct iscsi_pdu *rsp,
+ struct iscsi_task *task);
+ int (*ep_rdma_read) (int ep, struct iscsi_pdu *rsp);
+ void *(*ep_malloc) (size_t sz);
+ void (*ep_free) (void *buf);
+ void (*ep_event_modify) (int ep, int events);
};
extern struct iscsi_transport iscsi_tcp;
diff --git a/usr/list.h b/usr/list.h
index 3e85c9b..d2e0019 100644
--- a/usr/list.h
+++ b/usr/list.h
@@ -83,4 +83,10 @@ static inline void list_del(struct list_head *entry)
entry->next = entry->prev = NULL;
}
+static inline void list_del_init(struct list_head *entry)
+{
+ __list_del(entry->prev, entry->next);
+ INIT_LIST_HEAD(entry);
+}
+
#endif
--
1.5.2.4
More information about the stgt
mailing list