1 #include "iscsi/task.h"
2 #include "iscsi/iscsi.h"
3 #include "iscsi/conn.h"
7 #include "spdk_cunit.h"
9 #include "spdk_internal/log.h"
10 #include "spdk_internal/mock.h"
12 #include "scsi/scsi_internal.h"
14 SPDK_LOG_REGISTER_COMPONENT("iscsi", SPDK_LOG_ISCSI
)
16 struct spdk_trace_histories
*g_trace_histories
;
17 DEFINE_STUB_V(spdk_trace_add_register_fn
, (struct spdk_trace_register_fn
*reg_fn
));
18 DEFINE_STUB_V(spdk_trace_register_owner
, (uint8_t type
, char id_prefix
));
19 DEFINE_STUB_V(spdk_trace_register_object
, (uint8_t type
, char id_prefix
));
20 DEFINE_STUB_V(spdk_trace_register_description
, (const char *name
,
21 uint16_t tpoint_id
, uint8_t owner_type
, uint8_t object_type
, uint8_t new_object
,
22 uint8_t arg1_type
, const char *arg1_name
));
23 DEFINE_STUB_V(_spdk_trace_record
, (uint64_t tsc
, uint16_t tpoint_id
, uint16_t poller_id
,
24 uint32_t size
, uint64_t object_id
, uint64_t arg1
));
26 TAILQ_HEAD(, spdk_iscsi_pdu
) g_write_pdu_list
= TAILQ_HEAD_INITIALIZER(g_write_pdu_list
);
28 static bool g_task_pool_is_empty
= false;
29 static bool g_pdu_pool_is_empty
= false;
31 struct spdk_iscsi_task
*
32 iscsi_task_get(struct spdk_iscsi_conn
*conn
,
33 struct spdk_iscsi_task
*parent
,
34 spdk_scsi_task_cpl cpl_fn
)
36 struct spdk_iscsi_task
*task
;
38 if (g_task_pool_is_empty
) {
42 task
= calloc(1, sizeof(*task
));
48 task
->scsi
.cpl_fn
= cpl_fn
;
51 task
->parent
= parent
;
52 task
->tag
= parent
->tag
;
53 task
->lun_id
= parent
->lun_id
;
54 task
->scsi
.dxfer_dir
= parent
->scsi
.dxfer_dir
;
55 task
->scsi
.transfer_len
= parent
->scsi
.transfer_len
;
56 task
->scsi
.lun
= parent
->scsi
.lun
;
57 task
->scsi
.cdb
= parent
->scsi
.cdb
;
58 task
->scsi
.target_port
= parent
->scsi
.target_port
;
59 task
->scsi
.initiator_port
= parent
->scsi
.initiator_port
;
60 if (conn
&& (task
->scsi
.dxfer_dir
== SPDK_SCSI_DIR_FROM_DEV
)) {
65 task
->scsi
.iovs
= &task
->scsi
.iov
;
70 spdk_scsi_task_put(struct spdk_scsi_task
*task
)
76 iscsi_put_pdu(struct spdk_iscsi_pdu
*pdu
)
84 CU_FAIL("negative ref count");
89 if (pdu
->data
&& !pdu
->data_from_mempool
) {
96 struct spdk_iscsi_pdu
*
97 iscsi_get_pdu(struct spdk_iscsi_conn
*conn
)
99 struct spdk_iscsi_pdu
*pdu
;
101 assert(conn
!= NULL
);
102 if (g_pdu_pool_is_empty
) {
106 pdu
= malloc(sizeof(*pdu
));
111 memset(pdu
, 0, offsetof(struct spdk_iscsi_pdu
, ahs
));
118 DEFINE_STUB_V(spdk_scsi_task_process_null_lun
, (struct spdk_scsi_task
*task
));
120 DEFINE_STUB_V(spdk_scsi_task_process_abort
, (struct spdk_scsi_task
*task
));
122 DEFINE_STUB_V(spdk_scsi_dev_queue_task
,
123 (struct spdk_scsi_dev
*dev
, struct spdk_scsi_task
*task
));
125 DEFINE_STUB(spdk_scsi_dev_find_port_by_id
, struct spdk_scsi_port
*,
126 (struct spdk_scsi_dev
*dev
, uint64_t id
), NULL
);
128 DEFINE_STUB_V(spdk_scsi_dev_queue_mgmt_task
,
129 (struct spdk_scsi_dev
*dev
, struct spdk_scsi_task
*task
));
132 spdk_scsi_dev_get_name(const struct spdk_scsi_dev
*dev
)
141 DEFINE_STUB(spdk_scsi_dev_construct
, struct spdk_scsi_dev
*,
142 (const char *name
, const char **bdev_name_list
,
143 int *lun_id_list
, int num_luns
, uint8_t protocol_id
,
144 void (*hotremove_cb
)(const struct spdk_scsi_lun
*, void *),
145 void *hotremove_ctx
),
148 DEFINE_STUB_V(spdk_scsi_dev_destruct
,
149 (struct spdk_scsi_dev
*dev
, spdk_scsi_dev_destruct_cb_t cb_fn
, void *cb_arg
));
151 DEFINE_STUB(spdk_scsi_dev_add_port
, int,
152 (struct spdk_scsi_dev
*dev
, uint64_t id
, const char *name
), 0);
154 DEFINE_STUB(iscsi_drop_conns
, int,
155 (struct spdk_iscsi_conn
*conn
, const char *conn_match
, int drop_all
),
158 DEFINE_STUB(spdk_scsi_dev_delete_port
, int,
159 (struct spdk_scsi_dev
*dev
, uint64_t id
), 0);
161 DEFINE_STUB_V(shutdown_iscsi_conns
, (void));
163 DEFINE_STUB_V(iscsi_conns_request_logout
, (struct spdk_iscsi_tgt_node
*target
));
165 DEFINE_STUB(iscsi_get_active_conns
, int, (struct spdk_iscsi_tgt_node
*target
), 0);
168 iscsi_task_cpl(struct spdk_scsi_task
*scsi_task
)
170 struct spdk_iscsi_task
*iscsi_task
;
172 if (scsi_task
!= NULL
) {
173 iscsi_task
= iscsi_task_from_scsi_task(scsi_task
);
174 if (iscsi_task
->parent
&& (iscsi_task
->scsi
.dxfer_dir
== SPDK_SCSI_DIR_FROM_DEV
)) {
175 assert(iscsi_task
->conn
->data_in_cnt
> 0);
176 iscsi_task
->conn
->data_in_cnt
--;
183 DEFINE_STUB_V(iscsi_task_mgmt_cpl
, (struct spdk_scsi_task
*scsi_task
));
185 DEFINE_STUB(iscsi_conn_read_data
, int,
186 (struct spdk_iscsi_conn
*conn
, int bytes
, void *buf
), 0);
188 DEFINE_STUB(iscsi_conn_readv_data
, int,
189 (struct spdk_iscsi_conn
*conn
, struct iovec
*iov
, int iovcnt
), 0);
192 iscsi_conn_write_pdu(struct spdk_iscsi_conn
*conn
, struct spdk_iscsi_pdu
*pdu
,
193 iscsi_conn_xfer_complete_cb cb_fn
, void *cb_arg
)
195 TAILQ_INSERT_TAIL(&g_write_pdu_list
, pdu
, tailq
);
198 DEFINE_STUB_V(iscsi_conn_logout
, (struct spdk_iscsi_conn
*conn
));
200 DEFINE_STUB_V(spdk_scsi_task_set_status
,
201 (struct spdk_scsi_task
*task
, int sc
, int sk
, int asc
, int ascq
));
204 spdk_scsi_task_set_data(struct spdk_scsi_task
*task
, void *data
, uint32_t len
)
206 SPDK_CU_ASSERT_FATAL(task
->iovs
!= NULL
);
207 task
->iovs
[0].iov_base
= data
;
208 task
->iovs
[0].iov_len
= len
;