[Stgt-devel] [PATCH 08/18] iser virtualize malloc
Pete Wyckoff
pw
Tue Sep 4 22:09:20 CEST 2007
Virtualize malloc and free when dealing with memory that the
transport will use. It must be per-connection for RDMA.
Signed-off-by: Pete Wyckoff <pw at osc.edu>
---
usr/iscsi/iscsi_tcp.c | 14 ++++++++++++++
usr/iscsi/iscsid.c | 8 ++++----
usr/iscsi/transport.h | 4 ++++
3 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/usr/iscsi/iscsi_tcp.c b/usr/iscsi/iscsi_tcp.c
index c775594..0d189c7 100644
--- a/usr/iscsi/iscsi_tcp.c
+++ b/usr/iscsi/iscsi_tcp.c
@@ -241,6 +241,18 @@ void iscsi_event_modify(int fd, int events)
eprintf("tgt_event_modify failed\n");
}
+void *iscsi_tcp_malloc(struct iscsi_connection *conn __attribute__((unused)),
+ size_t sz)
+{
+ return malloc(sz);
+}
+
+void iscsi_tcp_free(struct iscsi_connection *conn __attribute__((unused)),
+ void *buf)
+{
+ free(buf);
+}
+
struct iscsi_transport iscsi_tcp = {
.name = "iscsi",
.rdma = 0,
@@ -251,4 +263,6 @@ struct iscsi_transport iscsi_tcp = {
.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 85d4c95..2d96930 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -971,7 +971,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(conn, sizeof(*task) + ext_len);
if (!task)
return NULL;
memset(task, 0, sizeof(*task));
@@ -993,8 +993,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);
+ conn->tp->ep_free(conn, (void *) (unsigned long) task->addr);
+ conn->tp->ep_free(conn, task);
/* from alloc */
conn_put(conn);
}
@@ -1133,7 +1133,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(conn, len);
if (!buf)
return -ENOMEM;
scmd->bidi_uaddr = (unsigned long) buf;
diff --git a/usr/iscsi/transport.h b/usr/iscsi/transport.h
index 9660396..c37d0da 100644
--- a/usr/iscsi/transport.h
+++ b/usr/iscsi/transport.h
@@ -1,6 +1,8 @@
#ifndef __TRANSPORT_H
#define __TRANSPORT_H
+struct iscsi_connection;
+
struct iscsi_transport {
const char *name;
int rdma;
@@ -12,6 +14,8 @@ struct iscsi_transport {
size_t (*ep_close) (int ep);
int (*ep_show) (int ep, char *buf, int rest);
void (*ep_event_modify) (int ep, int events);
+ void *(*ep_malloc) (struct iscsi_connection *conn, size_t sz);
+ void (*ep_free) (struct iscsi_connection *conn, void *buf);
};
extern struct iscsi_transport iscsi_tcp;
--
1.5.2.5
More information about the stgt
mailing list