1 #include "iscsi/task.h" 2 #include "iscsi/iscsi.h" 3 #include "iscsi/conn.h" 4 5 #include "spdk/env.h" 6 #include "spdk/event.h" 7 #include "spdk/sock.h" 8 #include "spdk_cunit.h" 9 10 #include "spdk_internal/log.h" 11 #include "spdk_internal/mock.h" 12 13 #include "scsi/scsi_internal.h" 14 15 SPDK_LOG_REGISTER_COMPONENT("iscsi", SPDK_LOG_ISCSI) 16 17 TAILQ_HEAD(, spdk_iscsi_pdu) g_write_pdu_list; 18 19 struct spdk_iscsi_task * 20 spdk_iscsi_task_get(struct spdk_iscsi_conn *conn, 21 struct spdk_iscsi_task *parent, 22 spdk_scsi_task_cpl cpl_fn) 23 { 24 struct spdk_iscsi_task *task; 25 26 task = calloc(1, sizeof(*task)); 27 if (!task) { 28 return NULL; 29 } 30 task->scsi.iovs = &task->scsi.iov; 31 return task; 32 } 33 34 void 35 spdk_scsi_task_put(struct spdk_scsi_task *task) 36 { 37 free(task); 38 } 39 40 void 41 spdk_put_pdu(struct spdk_iscsi_pdu *pdu) 42 { 43 if (!pdu) { 44 return; 45 } 46 47 pdu->ref--; 48 if (pdu->ref < 0) { 49 CU_FAIL("negative ref count"); 50 pdu->ref = 0; 51 } 52 53 if (pdu->ref == 0) { 54 if (pdu->data && !pdu->data_from_mempool) { 55 free(pdu->data); 56 } 57 free(pdu); 58 } 59 } 60 61 struct spdk_iscsi_pdu * 62 spdk_get_pdu(void) 63 { 64 struct spdk_iscsi_pdu *pdu; 65 66 pdu = malloc(sizeof(*pdu)); 67 if (!pdu) { 68 return NULL; 69 } 70 71 memset(pdu, 0, offsetof(struct spdk_iscsi_pdu, ahs)); 72 pdu->ref = 1; 73 74 return pdu; 75 } 76 77 DEFINE_STUB_V(spdk_scsi_task_process_null_lun, (struct spdk_scsi_task *task)); 78 79 DEFINE_STUB_V(spdk_scsi_task_process_abort, (struct spdk_scsi_task *task)); 80 81 DEFINE_STUB_V(spdk_scsi_dev_queue_task, 82 (struct spdk_scsi_dev *dev, struct spdk_scsi_task *task)); 83 84 DEFINE_STUB(spdk_scsi_dev_find_port_by_id, struct spdk_scsi_port *, 85 (struct spdk_scsi_dev *dev, uint64_t id), NULL); 86 87 DEFINE_STUB_V(spdk_scsi_dev_queue_mgmt_task, 88 (struct spdk_scsi_dev *dev, struct spdk_scsi_task *task)); 89 90 const char * 91 spdk_scsi_dev_get_name(const struct spdk_scsi_dev *dev) 92 { 93 if (dev != NULL) { 94 return dev->name; 95 } 96 97 return NULL; 98 } 99 100 DEFINE_STUB(spdk_event_allocate, struct spdk_event *, 101 (uint32_t core, spdk_event_fn fn, void *arg1, void *arg2), NULL); 102 103 DEFINE_STUB(spdk_scsi_dev_construct, struct spdk_scsi_dev *, 104 (const char *name, const char **bdev_name_list, 105 int *lun_id_list, int num_luns, uint8_t protocol_id, 106 void (*hotremove_cb)(const struct spdk_scsi_lun *, void *), 107 void *hotremove_ctx), 108 NULL); 109 110 DEFINE_STUB_V(spdk_scsi_dev_destruct, 111 (struct spdk_scsi_dev *dev, spdk_scsi_dev_destruct_cb_t cb_fn, void *cb_arg)); 112 113 DEFINE_STUB(spdk_scsi_dev_add_port, int, 114 (struct spdk_scsi_dev *dev, uint64_t id, const char *name), 0); 115 116 DEFINE_STUB(spdk_iscsi_drop_conns, int, 117 (struct spdk_iscsi_conn *conn, const char *conn_match, int drop_all), 118 0); 119 120 DEFINE_STUB(spdk_scsi_dev_delete_port, int, 121 (struct spdk_scsi_dev *dev, uint64_t id), 0); 122 123 DEFINE_STUB_V(spdk_shutdown_iscsi_conns, (void)); 124 125 DEFINE_STUB_V(spdk_iscsi_conns_start_exit, (struct spdk_iscsi_tgt_node *target)); 126 127 DEFINE_STUB(spdk_iscsi_get_active_conns, int, (struct spdk_iscsi_tgt_node *target), 0); 128 129 void 130 spdk_iscsi_task_cpl(struct spdk_scsi_task *scsi_task) 131 { 132 struct spdk_iscsi_task *iscsi_task; 133 134 if (scsi_task != NULL) { 135 iscsi_task = spdk_iscsi_task_from_scsi_task(scsi_task); 136 free(iscsi_task); 137 } 138 } 139 140 DEFINE_STUB_V(spdk_iscsi_task_mgmt_cpl, (struct spdk_scsi_task *scsi_task)); 141 142 DEFINE_STUB(spdk_iscsi_conn_read_data, int, 143 (struct spdk_iscsi_conn *conn, int bytes, void *buf), 0); 144 145 DEFINE_STUB(spdk_iscsi_conn_readv_data, int, 146 (struct spdk_iscsi_conn *conn, struct iovec *iov, int iovcnt), 0); 147 148 void 149 spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) 150 { 151 TAILQ_INSERT_TAIL(&g_write_pdu_list, pdu, tailq); 152 } 153 154 DEFINE_STUB_V(spdk_iscsi_conn_logout, (struct spdk_iscsi_conn *conn)); 155 156 DEFINE_STUB_V(spdk_scsi_task_set_status, 157 (struct spdk_scsi_task *task, int sc, int sk, int asc, int ascq)); 158 159 void 160 spdk_scsi_task_set_data(struct spdk_scsi_task *task, void *data, uint32_t len) 161 { 162 SPDK_CU_ASSERT_FATAL(task->iovs != NULL); 163 task->iovs[0].iov_base = data; 164 task->iovs[0].iov_len = len; 165 } 166