version 1.1.1.1, 2012/02/21 16:42:02
|
version 1.1.1.2, 2012/10/09 09:13:23
|
Line 1
|
Line 1
|
/* |
/* |
* Copyright (C) 2008-2011 Daisuke Aoyama <aoyama@peach.ne.jp>. | * Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>. |
* All rights reserved. |
* All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
Line 68
|
Line 68
|
#include <sys/time.h> |
#include <sys/time.h> |
#endif |
#endif |
|
|
|
#if !defined(__GNUC__) |
|
#undef __attribute__ |
|
#define __attribute__(x) |
|
#endif |
|
|
/* according to RFC1982 */ |
/* according to RFC1982 */ |
#define SN32_CMPMAX (((uint32_t)1U) << (32 - 1)) |
#define SN32_CMPMAX (((uint32_t)1U) << (32 - 1)) |
#define SN32_LT(S1,S2) \ |
#define SN32_LT(S1,S2) \ |
Line 83
|
Line 88
|
|| ((uint32_t)(S1) > (uint32_t)(S2) \ |
|| ((uint32_t)(S1) > (uint32_t)(S2) \ |
&& ((uint32_t)(S1) - (uint32_t)(S2) < SN32_CMPMAX)))) |
&& ((uint32_t)(S1) - (uint32_t)(S2) < SN32_CMPMAX)))) |
|
|
#define POLLWAIT 3000 | #define POLLWAIT 5000 |
#define MAX_MCSREVWAIT (10 * 1000) |
#define MAX_MCSREVWAIT (10 * 1000) |
#define ISCMDQ 8 |
#define ISCMDQ 8 |
|
|
Line 157 istgt_iscsi_read(CONN_Ptr conn, void *buf, size_t nbyt
|
Line 162 istgt_iscsi_read(CONN_Ptr conn, void *buf, size_t nbyt
|
} while (total < nbytes); |
} while (total < nbytes); |
if (total != (nbytes + pad_bytes)) { |
if (total != (nbytes + pad_bytes)) { |
/* incomplete bytes */ |
/* incomplete bytes */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %d/%d+%d bytes\n", | ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %zd/%zd+%zd bytes\n", |
total, nbytes, pad_bytes); |
total, nbytes, pad_bytes); |
if (total > nbytes) { |
if (total > nbytes) { |
total = nbytes; |
total = nbytes; |
Line 167 istgt_iscsi_read(CONN_Ptr conn, void *buf, size_t nbyt
|
Line 172 istgt_iscsi_read(CONN_Ptr conn, void *buf, size_t nbyt
|
|
|
if (pad_bytes != 0) { |
if (pad_bytes != 0) { |
/* complete padding */ |
/* complete padding */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %d bytes (padding %d)\n", | ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %zd bytes (padding %zd)\n", |
nbytes, pad_bytes); |
nbytes, pad_bytes); |
} else { |
} else { |
/* just aligned */ |
/* just aligned */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %d bytes (no padding)\n", | ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %zd bytes (no padding)\n", |
nbytes); |
nbytes); |
} |
} |
#else /* !ISTGT_USE_RECVBLOCK */ |
#else /* !ISTGT_USE_RECVBLOCK */ |
Line 197 istgt_iscsi_read(CONN_Ptr conn, void *buf, size_t nbyt
|
Line 202 istgt_iscsi_read(CONN_Ptr conn, void *buf, size_t nbyt
|
|
|
if (total != nbytes) { |
if (total != nbytes) { |
/* incomplete bytes */ |
/* incomplete bytes */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %d/%d bytes\n", | ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %zd/%zd bytes\n", |
total, nbytes); |
total, nbytes); |
return total; |
return total; |
} |
} |
Line 213 istgt_iscsi_read(CONN_Ptr conn, void *buf, size_t nbyt
|
Line 218 istgt_iscsi_read(CONN_Ptr conn, void *buf, size_t nbyt
|
if (r < 0) { |
if (r < 0) { |
/* error */ |
/* error */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
"Read %d bytes (padding error) (errno=%d)\n", | "Read %zd bytes (padding error) (errno=%d)\n", |
nbytes, errno); |
nbytes, errno); |
return nbytes; |
return nbytes; |
} |
} |
if (r == 0) { |
if (r == 0) { |
/* EOF */ |
/* EOF */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
"Read %d bytes (padding EOF)\n", | "Read %zd bytes (padding EOF)\n", |
nbytes); |
nbytes); |
return nbytes; |
return nbytes; |
} |
} |
Line 230 istgt_iscsi_read(CONN_Ptr conn, void *buf, size_t nbyt
|
Line 235 istgt_iscsi_read(CONN_Ptr conn, void *buf, size_t nbyt
|
if (total != pad_bytes) { |
if (total != pad_bytes) { |
/* incomplete padding */ |
/* incomplete padding */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
"Read %d bytes (padding %d)\n", | "Read %zd bytes (padding %zd)\n", |
nbytes, total); |
nbytes, total); |
return nbytes; |
return nbytes; |
} |
} |
/* complete padding */ |
/* complete padding */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %d bytes (padding %d)\n", | ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %zd bytes (padding %zd)\n", |
nbytes, pad_bytes); |
nbytes, pad_bytes); |
return nbytes; |
return nbytes; |
} |
} |
|
|
/* just aligned */ |
/* just aligned */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %d bytes (no padding)\n", | ISTGT_TRACELOG(ISTGT_TRACE_NET, "Read %zd bytes (no padding)\n", |
nbytes); |
nbytes); |
#endif /* ISTGT_USE_RECVBLOCK */ |
#endif /* ISTGT_USE_RECVBLOCK */ |
return nbytes; |
return nbytes; |
Line 273 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
Line 278 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
|
|
if (total != nbytes) { |
if (total != nbytes) { |
/* incomplete bytes */ |
/* incomplete bytes */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, "Write %d/%d bytes\n", | ISTGT_TRACELOG(ISTGT_TRACE_NET, "Write %zd/%zd bytes\n", |
total, nbytes); |
total, nbytes); |
return total; |
return total; |
} |
} |
Line 287 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
Line 292 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
if (r < 0) { |
if (r < 0) { |
/* error */ |
/* error */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
"Write %d bytes (padding error) (errno=%d)\n", | "Write %zd bytes (padding error) (errno=%d)\n", |
nbytes, errno); |
nbytes, errno); |
return nbytes; |
return nbytes; |
} |
} |
Line 297 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
Line 302 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
if (total != pad_bytes) { |
if (total != pad_bytes) { |
/* incomplete padding */ |
/* incomplete padding */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
"Write %d bytes (padding %d)\n", | "Write %zd bytes (padding %zd)\n", |
nbytes, total); |
nbytes, total); |
return nbytes; |
return nbytes; |
} |
} |
|
|
/* complete padding */ |
/* complete padding */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
"Write %d bytes (padding %d)\n", | "Write %zd bytes (padding %zd)\n", |
nbytes, pad_bytes); |
nbytes, pad_bytes); |
} else { |
} else { |
/* just aligned */ |
/* just aligned */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
"Write %d bytes (no padding)\n", | "Write %zd bytes (no padding)\n", |
nbytes); |
nbytes); |
} |
} |
#else /* !ISTGT_USE_SENDBLOCK */ |
#else /* !ISTGT_USE_SENDBLOCK */ |
Line 327 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
Line 332 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
|
|
if (total != nbytes) { |
if (total != nbytes) { |
/* incomplete bytes */ |
/* incomplete bytes */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, "Write %d/%d bytes\n", | ISTGT_TRACELOG(ISTGT_TRACE_NET, "Write %zd/%zd bytes\n", |
total, nbytes); |
total, nbytes); |
return r; |
return r; |
} |
} |
Line 344 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
Line 349 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
if (r < 0) { |
if (r < 0) { |
/* error */ |
/* error */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
"Write %d bytes (padding error) (errno=%d)\n", | "Write %zd bytes (padding error) (errno=%d)\n", |
nbytes, errno); |
nbytes, errno); |
return nbytes; |
return nbytes; |
} |
} |
Line 354 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
Line 359 istgt_iscsi_write(CONN_Ptr conn, const void *buf, size
|
if (total != pad_bytes) { |
if (total != pad_bytes) { |
/* incomplete padding */ |
/* incomplete padding */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
"Write %d bytes (padding %d)\n", | "Write %zd bytes (padding %zd)\n", |
nbytes, total); |
nbytes, total); |
return nbytes; |
return nbytes; |
} |
} |
/* complete padding */ |
/* complete padding */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
ISTGT_TRACELOG(ISTGT_TRACE_NET, |
"Write %d bytes (padding %d)\n", | "Write %zd bytes (padding %zd)\n", |
nbytes, pad_bytes); |
nbytes, pad_bytes); |
return nbytes; |
return nbytes; |
} |
} |
|
|
/* just aligned */ |
/* just aligned */ |
ISTGT_TRACELOG(ISTGT_TRACE_NET, "Write %d bytes (no padding)\n", | ISTGT_TRACELOG(ISTGT_TRACE_NET, "Write %zd bytes (no padding)\n", |
nbytes); |
nbytes); |
#endif /* ISTGT_USE_SENDBLOCK */ |
#endif /* ISTGT_USE_SENDBLOCK */ |
return nbytes; |
return nbytes; |
Line 623 istgt_iscsi_read_pdu(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 628 istgt_iscsi_read_pdu(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
} |
} |
|
|
static int istgt_iscsi_write_pdu_internal(CONN_Ptr conn, ISCSI_PDU_Ptr pdu); |
static int istgt_iscsi_write_pdu_internal(CONN_Ptr conn, ISCSI_PDU_Ptr pdu); |
|
static int istgt_iscsi_write_pdu_queue(CONN_Ptr conn, ISCSI_PDU_Ptr pdu, int req_type, int I_bit); |
|
|
|
static int istgt_update_pdu(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd) |
|
{ |
|
uint8_t *rsp; |
|
uint32_t task_tag; |
|
int opcode; |
|
int I_bit; |
|
|
|
I_bit = lu_cmd->I_bit; |
|
rsp = (uint8_t *) &lu_cmd->pdu->bhs; |
|
opcode = BGET8W(&rsp[0], 5, 6); |
|
task_tag = DGET32(&rsp[16]); |
|
if ((opcode == ISCSI_OP_R2T) |
|
|| (opcode == ISCSI_OP_NOPIN && task_tag == 0xffffffffU)) { |
|
SESS_MTX_LOCK(conn); |
|
DSET32(&rsp[24], conn->StatSN); |
|
DSET32(&rsp[28], conn->sess->ExpCmdSN); |
|
DSET32(&rsp[32], conn->sess->MaxCmdSN); |
|
SESS_MTX_UNLOCK(conn); |
|
} else if ((opcode == ISCSI_OP_TASK_RSP) |
|
|| (opcode == ISCSI_OP_NOPIN && task_tag != 0xffffffffU)) { |
|
SESS_MTX_LOCK(conn); |
|
DSET32(&rsp[24], conn->StatSN); |
|
conn->StatSN++; |
|
if (I_bit == 0) { |
|
conn->sess->ExpCmdSN++; |
|
conn->sess->MaxCmdSN++; |
|
} |
|
DSET32(&rsp[28], conn->sess->ExpCmdSN); |
|
DSET32(&rsp[32], conn->sess->MaxCmdSN); |
|
SESS_MTX_UNLOCK(conn); |
|
} |
|
return 0; |
|
} |
|
|
static int |
static int |
istgt_iscsi_write_pdu(CONN_Ptr conn, ISCSI_PDU_Ptr pdu) |
istgt_iscsi_write_pdu(CONN_Ptr conn, ISCSI_PDU_Ptr pdu) |
{ |
{ |
Line 632 istgt_iscsi_write_pdu(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
Line 672 istgt_iscsi_write_pdu(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
if (conn->use_sender == 0) { |
if (conn->use_sender == 0) { |
rc = istgt_iscsi_write_pdu_internal(conn, pdu); |
rc = istgt_iscsi_write_pdu_internal(conn, pdu); |
} else { |
} else { |
|
rc = istgt_iscsi_write_pdu_queue(conn, pdu, ISTGT_LU_TASK_REQPDU, 0); |
|
} |
|
return rc; |
|
} |
|
|
|
static int |
|
istgt_iscsi_write_pdu_upd(CONN_Ptr conn, ISCSI_PDU_Ptr pdu, int I_bit) |
|
{ |
|
int rc; |
|
|
|
if (conn->use_sender == 0) { |
|
rc = istgt_iscsi_write_pdu_internal(conn, pdu); |
|
} else { |
|
rc = istgt_iscsi_write_pdu_queue(conn, pdu, ISTGT_LU_TASK_REQUPDPDU, I_bit); |
|
} |
|
return rc; |
|
} |
|
|
|
static int |
|
istgt_iscsi_write_pdu_queue(CONN_Ptr conn, ISCSI_PDU_Ptr pdu, int req_type, int I_bit) |
|
{ |
|
int rc; |
|
|
|
if (conn->use_sender == 0) { |
|
rc = istgt_iscsi_write_pdu_internal(conn, pdu); |
|
} else { |
ISTGT_LU_TASK_Ptr lu_task; |
ISTGT_LU_TASK_Ptr lu_task; |
ISCSI_PDU_Ptr src_pdu, dst_pdu; |
ISCSI_PDU_Ptr src_pdu, dst_pdu; |
uint8_t *cp; |
uint8_t *cp; |
Line 656 istgt_iscsi_write_pdu(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
Line 722 istgt_iscsi_write_pdu(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
alloc_len += ISCSI_ALIGN(data_len); |
alloc_len += ISCSI_ALIGN(data_len); |
lu_task = xmalloc(alloc_len); |
lu_task = xmalloc(alloc_len); |
memset(lu_task, 0, alloc_len); |
memset(lu_task, 0, alloc_len); |
lu_task->lu_cmd.pdu = (ISCSI_PDU_Ptr) ((uint8_t *)lu_task | lu_task->lu_cmd.pdu = (ISCSI_PDU_Ptr) ((uintptr_t)lu_task |
+ ISCSI_ALIGN(sizeof *lu_task)); |
+ ISCSI_ALIGN(sizeof *lu_task)); |
lu_task->lu_cmd.pdu->ahs = (ISCSI_AHS *) ((uint8_t *)lu_task->lu_cmd.pdu | lu_task->lu_cmd.pdu->ahs = (ISCSI_AHS *) ((uintptr_t)lu_task->lu_cmd.pdu |
+ ISCSI_ALIGN(sizeof *lu_task->lu_cmd.pdu)); |
+ ISCSI_ALIGN(sizeof *lu_task->lu_cmd.pdu)); |
lu_task->lu_cmd.pdu->data = (uint8_t *)lu_task->lu_cmd.pdu->ahs | lu_task->lu_cmd.pdu->data = (uint8_t *) ((uintptr_t)lu_task->lu_cmd.pdu->ahs |
+ ISCSI_ALIGN(4 * total_ahs_len); | + ISCSI_ALIGN(4 * total_ahs_len)); |
|
|
/* specify type and self conn */ |
/* specify type and self conn */ |
lu_task->type = ISTGT_LU_TASK_REQPDU; | //lu_task->type = ISTGT_LU_TASK_REQPDU; |
| lu_task->type = req_type; |
lu_task->conn = conn; |
lu_task->conn = conn; |
|
|
|
/* extra flags */ |
|
lu_task->lu_cmd.I_bit = I_bit; |
|
|
/* copy PDU structure */ |
/* copy PDU structure */ |
src_pdu = pdu; |
src_pdu = pdu; |
dst_pdu = lu_task->lu_cmd.pdu; |
dst_pdu = lu_task->lu_cmd.pdu; |
Line 1346 istgt_iscsi_negotiate_params(CONN_Ptr conn, ISCSI_PARA
|
Line 1416 istgt_iscsi_negotiate_params(CONN_Ptr conn, ISCSI_PARA
|
} |
} |
|
|
static int |
static int |
istgt_iscsi_append_text(CONN_Ptr conn, const char *key, const char *val, uint8_t *data, int alloc_len, int data_len) | istgt_iscsi_append_text(CONN_Ptr conn __attribute__((__unused__)), const char *key, const char *val, uint8_t *data, int alloc_len, int data_len) |
{ |
{ |
int total; |
int total; |
int len; |
int len; |
Line 1782 istgt_iscsi_reject(CONN_Ptr conn, ISCSI_PDU_Ptr pdu, i
|
Line 1852 istgt_iscsi_reject(CONN_Ptr conn, ISCSI_PDU_Ptr pdu, i
|
|
|
DSET32(&rsp[16], 0xffffffffU); |
DSET32(&rsp[16], 0xffffffffU); |
|
|
DSET32(&rsp[24], conn->StatSN); |
|
conn->StatSN++; |
|
if (conn->sess != NULL) { |
if (conn->sess != NULL) { |
SESS_MTX_LOCK(conn); |
SESS_MTX_LOCK(conn); |
|
DSET32(&rsp[24], conn->StatSN); |
|
conn->StatSN++; |
DSET32(&rsp[28], conn->sess->ExpCmdSN); |
DSET32(&rsp[28], conn->sess->ExpCmdSN); |
DSET32(&rsp[32], conn->sess->MaxCmdSN); |
DSET32(&rsp[32], conn->sess->MaxCmdSN); |
SESS_MTX_UNLOCK(conn); |
SESS_MTX_UNLOCK(conn); |
} else { |
} else { |
|
DSET32(&rsp[24], conn->StatSN); |
|
conn->StatSN++; |
DSET32(&rsp[28], 1); |
DSET32(&rsp[28], 1); |
DSET32(&rsp[32], 1); |
DSET32(&rsp[32], 1); |
} |
} |
Line 2298 istgt_iscsi_op_login(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 2370 istgt_iscsi_op_login(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
} |
} |
|
|
/* initialize parameters */ |
/* initialize parameters */ |
conn->StatSN = ExpStatSN; |
|
SESS_MTX_LOCK(conn); |
SESS_MTX_LOCK(conn); |
|
conn->StatSN = ExpStatSN; |
conn->MaxOutstandingR2T |
conn->MaxOutstandingR2T |
= conn->sess->MaxOutstandingR2T; |
= conn->sess->MaxOutstandingR2T; |
conn->sess->isid = isid; |
conn->sess->isid = isid; |
Line 2574 istgt_iscsi_op_login(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 2646 istgt_iscsi_op_login(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
DSET16(&rsp[14], tsih); |
DSET16(&rsp[14], tsih); |
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[16], task_tag); |
|
|
DSET32(&rsp[24], conn->StatSN); |
|
conn->StatSN++; |
|
if (conn->sess != NULL) { |
if (conn->sess != NULL) { |
SESS_MTX_LOCK(conn); |
SESS_MTX_LOCK(conn); |
|
DSET32(&rsp[24], conn->StatSN); |
|
conn->StatSN++; |
DSET32(&rsp[28], conn->sess->ExpCmdSN); |
DSET32(&rsp[28], conn->sess->ExpCmdSN); |
DSET32(&rsp[32], conn->sess->MaxCmdSN); |
DSET32(&rsp[32], conn->sess->MaxCmdSN); |
SESS_MTX_UNLOCK(conn); |
SESS_MTX_UNLOCK(conn); |
} else { |
} else { |
|
DSET32(&rsp[24], conn->StatSN); |
|
conn->StatSN++; |
DSET32(&rsp[28], CmdSN); |
DSET32(&rsp[28], CmdSN); |
DSET32(&rsp[32], CmdSN); |
DSET32(&rsp[32], CmdSN); |
} |
} |
Line 2683 istgt_iscsi_op_text(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 2757 istgt_iscsi_op_text(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
ISTGT_ERRLOG("CmdSN(%u) error\n", CmdSN); |
ISTGT_ERRLOG("CmdSN(%u) error\n", CmdSN); |
return -1; |
return -1; |
} |
} |
SESS_MTX_UNLOCK(conn); |
|
if (SN32_GT(ExpStatSN, conn->StatSN)) { |
if (SN32_GT(ExpStatSN, conn->StatSN)) { |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "StatSN(%u) advanced\n", |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "StatSN(%u) advanced\n", |
ExpStatSN); |
ExpStatSN); |
Line 2692 istgt_iscsi_op_text(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 2765 istgt_iscsi_op_text(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
if (ExpStatSN != conn->StatSN) { |
if (ExpStatSN != conn->StatSN) { |
#if 0 |
#if 0 |
ISTGT_ERRLOG("StatSN(%u) error\n", ExpStatSN); |
ISTGT_ERRLOG("StatSN(%u) error\n", ExpStatSN); |
|
SESS_MTX_UNLOCK(conn); |
return -1; |
return -1; |
#else |
#else |
/* StarPort have a bug */ |
/* StarPort have a bug */ |
Line 2699 istgt_iscsi_op_text(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 2773 istgt_iscsi_op_text(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
conn->StatSN = ExpStatSN; |
conn->StatSN = ExpStatSN; |
#endif |
#endif |
} |
} |
|
SESS_MTX_UNLOCK(conn); |
|
|
if (F_bit && C_bit) { |
if (F_bit && C_bit) { |
ISTGT_ERRLOG("final and continue\n"); |
ISTGT_ERRLOG("final and continue\n"); |
Line 2768 istgt_iscsi_op_text(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 2843 istgt_iscsi_op_text(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
DSET32(&rsp[20], transfer_tag); |
DSET32(&rsp[20], transfer_tag); |
} |
} |
|
|
|
SESS_MTX_LOCK(conn); |
DSET32(&rsp[24], conn->StatSN); |
DSET32(&rsp[24], conn->StatSN); |
conn->StatSN++; |
conn->StatSN++; |
SESS_MTX_LOCK(conn); |
|
if (I_bit == 0) { |
if (I_bit == 0) { |
conn->sess->ExpCmdSN++; |
conn->sess->ExpCmdSN++; |
conn->sess->MaxCmdSN++; |
conn->sess->MaxCmdSN++; |
Line 2850 istgt_iscsi_op_logout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
Line 2925 istgt_iscsi_op_logout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
"CmdSN=%u, ExpStatSN=%u, StatSN=%u\n", |
"CmdSN=%u, ExpStatSN=%u, StatSN=%u\n", |
CmdSN, ExpStatSN, conn->StatSN); |
CmdSN, ExpStatSN, conn->StatSN); |
} |
} |
|
if (conn->sess != NULL) { |
|
SESS_MTX_LOCK(conn); |
|
} |
if (SN32_GT(ExpStatSN, conn->StatSN)) { |
if (SN32_GT(ExpStatSN, conn->StatSN)) { |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "StatSN(%u) advanced\n", |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "StatSN(%u) advanced\n", |
ExpStatSN); |
ExpStatSN); |
Line 2860 istgt_iscsi_op_logout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
Line 2938 istgt_iscsi_op_logout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
ExpStatSN, conn->StatSN); |
ExpStatSN, conn->StatSN); |
/* ignore error */ |
/* ignore error */ |
} |
} |
|
if (conn->sess != NULL) { |
|
SESS_MTX_UNLOCK(conn); |
|
} |
|
|
response = 0; // connection or session closed successfully |
response = 0; // connection or session closed successfully |
|
|
Line 2875 istgt_iscsi_op_logout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
Line 2956 istgt_iscsi_op_logout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
|
|
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[16], task_tag); |
|
|
DSET32(&rsp[24], conn->StatSN); |
|
conn->StatSN++; |
|
if (conn->sess != NULL) { |
if (conn->sess != NULL) { |
SESS_MTX_LOCK(conn); |
SESS_MTX_LOCK(conn); |
|
DSET32(&rsp[24], conn->StatSN); |
|
conn->StatSN++; |
if (conn->sess->connections == 1) { |
if (conn->sess->connections == 1) { |
conn->sess->ExpCmdSN++; |
conn->sess->ExpCmdSN++; |
conn->sess->MaxCmdSN++; |
conn->sess->MaxCmdSN++; |
Line 2887 istgt_iscsi_op_logout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
Line 2968 istgt_iscsi_op_logout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
DSET32(&rsp[32], conn->sess->MaxCmdSN); |
DSET32(&rsp[32], conn->sess->MaxCmdSN); |
SESS_MTX_UNLOCK(conn); |
SESS_MTX_UNLOCK(conn); |
} else { |
} else { |
|
DSET32(&rsp[24], conn->StatSN); |
|
conn->StatSN++; |
DSET32(&rsp[28], CmdSN); |
DSET32(&rsp[28], CmdSN); |
DSET32(&rsp[32], CmdSN); |
DSET32(&rsp[32], CmdSN); |
} |
} |
Line 3053 istgt_iscsi_transfer_in_internal(CONN_Ptr conn, ISTGT_
|
Line 3136 istgt_iscsi_transfer_in_internal(CONN_Ptr conn, ISTGT_
|
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[20], transfer_tag); |
DSET32(&rsp[20], transfer_tag); |
|
|
|
SESS_MTX_LOCK(conn); |
if (S_bit) { |
if (S_bit) { |
DSET32(&rsp[24], conn->StatSN); |
DSET32(&rsp[24], conn->StatSN); |
conn->StatSN++; |
conn->StatSN++; |
} else { |
} else { |
DSET32(&rsp[24], 0); // StatSN or Reserved |
DSET32(&rsp[24], 0); // StatSN or Reserved |
} |
} |
SESS_MTX_LOCK(conn); |
|
if (F_bit && S_bit && lu_cmd->I_bit == 0) { |
if (F_bit && S_bit && lu_cmd->I_bit == 0) { |
conn->sess->MaxCmdSN++; |
conn->sess->MaxCmdSN++; |
} |
} |
Line 3104 istgt_iscsi_op_scsi(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 3187 istgt_iscsi_op_scsi(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
uint32_t transfer_len; |
uint32_t transfer_len; |
uint32_t CmdSN; |
uint32_t CmdSN; |
uint32_t ExpStatSN; |
uint32_t ExpStatSN; |
|
size_t bidi_residual_len; |
|
size_t residual_len; |
|
size_t data_len; |
|
size_t alloc_len; |
int I_bit, F_bit, R_bit, W_bit, Attr_bit; |
int I_bit, F_bit, R_bit, W_bit, Attr_bit; |
int o_bit, u_bit, O_bit, U_bit; |
int o_bit, u_bit, O_bit, U_bit; |
int bidi_residual_len; |
|
int residual_len; |
|
int data_len; |
|
int alloc_len; |
|
int rc; |
int rc; |
|
|
if (!conn->full_feature) { |
if (!conn->full_feature) { |
Line 3219 istgt_iscsi_op_scsi(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 3302 istgt_iscsi_op_scsi(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
CmdSN, conn->sess->ExpCmdSN); |
CmdSN, conn->sess->ExpCmdSN); |
return -1; |
return -1; |
} |
} |
SESS_MTX_UNLOCK(conn); |
|
if (SN32_GT(ExpStatSN, conn->StatSN)) { |
if (SN32_GT(ExpStatSN, conn->StatSN)) { |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "StatSN(%u) advanced\n", |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "StatSN(%u) advanced\n", |
ExpStatSN); |
ExpStatSN); |
Line 3227 istgt_iscsi_op_scsi(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 3309 istgt_iscsi_op_scsi(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
} |
} |
{ |
{ |
uint32_t QCmdSN; |
uint32_t QCmdSN; |
SESS_MTX_LOCK(conn); | //SESS_MTX_LOCK(conn); |
QCmdSN = conn->sess->MaxCmdSN - conn->sess->ExpCmdSN + 1; |
QCmdSN = conn->sess->MaxCmdSN - conn->sess->ExpCmdSN + 1; |
SESS_MTX_UNLOCK(conn); | //SESS_MTX_UNLOCK(conn); |
QCmdSN += conn->queue_depth; |
QCmdSN += conn->queue_depth; |
if (SN32_LT(ExpStatSN + QCmdSN, conn->StatSN)) { |
if (SN32_LT(ExpStatSN + QCmdSN, conn->StatSN)) { |
ISTGT_ERRLOG("StatSN(%u/%u) QCmdSN(%u) error\n", |
ISTGT_ERRLOG("StatSN(%u/%u) QCmdSN(%u) error\n", |
ExpStatSN, conn->StatSN, QCmdSN); |
ExpStatSN, conn->StatSN, QCmdSN); |
|
SESS_MTX_UNLOCK(conn); |
return -1; |
return -1; |
} |
} |
} |
} |
|
SESS_MTX_UNLOCK(conn); |
|
|
lu_cmd.pdu = pdu; |
lu_cmd.pdu = pdu; |
SESS_MTX_LOCK(conn); |
SESS_MTX_LOCK(conn); |
Line 3336 istgt_iscsi_op_scsi(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 3420 istgt_iscsi_op_scsi(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
&& lu_cmd.status == ISTGT_SCSI_STATUS_GOOD) { |
&& lu_cmd.status == ISTGT_SCSI_STATUS_GOOD) { |
if (data_len < transfer_len) { |
if (data_len < transfer_len) { |
/* underflow */ |
/* underflow */ |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "Underflow %u/%u\n", | ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "Underflow %zu/%u\n", |
data_len, transfer_len); |
data_len, transfer_len); |
residual_len = transfer_len - data_len; |
residual_len = transfer_len - data_len; |
U_bit = 1; |
U_bit = 1; |
} else if (data_len > transfer_len) { |
} else if (data_len > transfer_len) { |
/* overflow */ |
/* overflow */ |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "Overflow %u/%u\n", | ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "Overflow %zu/%u\n", |
data_len, transfer_len); |
data_len, transfer_len); |
residual_len = data_len - transfer_len; |
residual_len = data_len - transfer_len; |
O_bit = 1; |
O_bit = 1; |
Line 3371 istgt_iscsi_op_scsi(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 3455 istgt_iscsi_op_scsi(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[20], 0); // SNACK Tag |
DSET32(&rsp[20], 0); // SNACK Tag |
|
|
|
SESS_MTX_LOCK(conn); |
DSET32(&rsp[24], conn->StatSN); |
DSET32(&rsp[24], conn->StatSN); |
conn->StatSN++; |
conn->StatSN++; |
SESS_MTX_LOCK(conn); |
|
if (I_bit == 0) { |
if (I_bit == 0) { |
conn->sess->MaxCmdSN++; |
conn->sess->MaxCmdSN++; |
} |
} |
Line 3418 istgt_iscsi_task_response(CONN_Ptr conn, ISTGT_LU_TASK
|
Line 3502 istgt_iscsi_task_response(CONN_Ptr conn, ISTGT_LU_TASK
|
uint32_t task_tag; |
uint32_t task_tag; |
uint32_t transfer_len; |
uint32_t transfer_len; |
uint32_t CmdSN; |
uint32_t CmdSN; |
|
size_t residual_len; |
|
size_t data_len; |
int I_bit; |
int I_bit; |
int o_bit, u_bit, O_bit, U_bit; |
int o_bit, u_bit, O_bit, U_bit; |
int bidi_residual_len; |
int bidi_residual_len; |
int residual_len; |
|
int data_len; |
|
int rc; |
int rc; |
|
|
lu_cmd = &lu_task->lu_cmd; |
lu_cmd = &lu_task->lu_cmd; |
Line 3460 istgt_iscsi_task_response(CONN_Ptr conn, ISTGT_LU_TASK
|
Line 3544 istgt_iscsi_task_response(CONN_Ptr conn, ISTGT_LU_TASK
|
&& lu_cmd->status == ISTGT_SCSI_STATUS_GOOD) { |
&& lu_cmd->status == ISTGT_SCSI_STATUS_GOOD) { |
if (data_len < transfer_len) { |
if (data_len < transfer_len) { |
/* underflow */ |
/* underflow */ |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "Underflow %u/%u\n", | ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "Underflow %zu/%u\n", |
data_len, transfer_len); |
data_len, transfer_len); |
residual_len = transfer_len - data_len; |
residual_len = transfer_len - data_len; |
U_bit = 1; |
U_bit = 1; |
} else if (data_len > transfer_len) { |
} else if (data_len > transfer_len) { |
/* overflow */ |
/* overflow */ |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "Overflow %u/%u\n", | ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "Overflow %zu/%u\n", |
data_len, transfer_len); |
data_len, transfer_len); |
residual_len = data_len - transfer_len; |
residual_len = data_len - transfer_len; |
O_bit = 1; |
O_bit = 1; |
Line 3495 istgt_iscsi_task_response(CONN_Ptr conn, ISTGT_LU_TASK
|
Line 3579 istgt_iscsi_task_response(CONN_Ptr conn, ISTGT_LU_TASK
|
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[20], 0); // SNACK Tag |
DSET32(&rsp[20], 0); // SNACK Tag |
|
|
|
SESS_MTX_LOCK(conn); |
DSET32(&rsp[24], conn->StatSN); |
DSET32(&rsp[24], conn->StatSN); |
conn->StatSN++; |
conn->StatSN++; |
SESS_MTX_LOCK(conn); |
|
if (I_bit == 0) { |
if (I_bit == 0) { |
conn->sess->MaxCmdSN++; |
conn->sess->MaxCmdSN++; |
} |
} |
Line 3570 istgt_iscsi_op_task(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 3654 istgt_iscsi_op_task(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
conn->sess->ExpCmdSN); |
conn->sess->ExpCmdSN); |
conn->sess->ExpCmdSN = CmdSN; |
conn->sess->ExpCmdSN = CmdSN; |
} |
} |
SESS_MTX_UNLOCK(conn); |
|
if (SN32_GT(ExpStatSN, conn->StatSN)) { |
if (SN32_GT(ExpStatSN, conn->StatSN)) { |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "StatSN(%u) advanced\n", |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "StatSN(%u) advanced\n", |
ExpStatSN); |
ExpStatSN); |
Line 3584 istgt_iscsi_op_task(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 3667 istgt_iscsi_op_task(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
conn->StatSN = ExpStatSN; |
conn->StatSN = ExpStatSN; |
} |
} |
#endif |
#endif |
|
SESS_MTX_UNLOCK(conn); |
|
|
response = 0; // Function complete. |
response = 0; // Function complete. |
switch (function) { |
switch (function) { |
Line 3675 istgt_iscsi_op_task(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 3759 istgt_iscsi_op_task(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
|
|
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[16], task_tag); |
|
|
DSET32(&rsp[24], conn->StatSN); | if (conn->use_sender == 0) { |
conn->StatSN++; | SESS_MTX_LOCK(conn); |
SESS_MTX_LOCK(conn); | DSET32(&rsp[24], conn->StatSN); |
if (I_bit == 0) { | conn->StatSN++; |
conn->sess->ExpCmdSN++; | if (I_bit == 0) { |
conn->sess->MaxCmdSN++; | conn->sess->ExpCmdSN++; |
| conn->sess->MaxCmdSN++; |
| } |
| DSET32(&rsp[28], conn->sess->ExpCmdSN); |
| DSET32(&rsp[32], conn->sess->MaxCmdSN); |
| SESS_MTX_UNLOCK(conn); |
| } else { |
| // update by sender |
} |
} |
DSET32(&rsp[28], conn->sess->ExpCmdSN); |
|
DSET32(&rsp[32], conn->sess->MaxCmdSN); |
|
SESS_MTX_UNLOCK(conn); |
|
|
|
rc = istgt_iscsi_write_pdu(conn, &rsp_pdu); | rc = istgt_iscsi_write_pdu_upd(conn, &rsp_pdu, I_bit); |
if (rc < 0) { |
if (rc < 0) { |
ISTGT_ERRLOG("iscsi_write_pdu() failed\n"); |
ISTGT_ERRLOG("iscsi_write_pdu() failed\n"); |
return -1; |
return -1; |
Line 3752 istgt_iscsi_op_nopout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
Line 3840 istgt_iscsi_op_nopout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
} |
} |
} else if (CmdSN != conn->sess->ExpCmdSN) { |
} else if (CmdSN != conn->sess->ExpCmdSN) { |
SESS_MTX_UNLOCK(conn); |
SESS_MTX_UNLOCK(conn); |
ISTGT_ERRLOG("CmdSN(%u) error\n", CmdSN); | ISTGT_ERRLOG("CmdSN(%u) error ExpCmdSN=%u\n", |
| CmdSN, conn->sess->ExpCmdSN); |
return -1; |
return -1; |
} |
} |
SESS_MTX_UNLOCK(conn); |
|
if (SN32_GT(ExpStatSN, conn->StatSN)) { |
if (SN32_GT(ExpStatSN, conn->StatSN)) { |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "StatSN(%u) advanced\n", |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "StatSN(%u) advanced\n", |
ExpStatSN); |
ExpStatSN); |
Line 3763 istgt_iscsi_op_nopout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
Line 3851 istgt_iscsi_op_nopout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
} |
} |
{ |
{ |
uint32_t QCmdSN; |
uint32_t QCmdSN; |
SESS_MTX_LOCK(conn); | //SESS_MTX_LOCK(conn); |
QCmdSN = conn->sess->MaxCmdSN - conn->sess->ExpCmdSN + 1; |
QCmdSN = conn->sess->MaxCmdSN - conn->sess->ExpCmdSN + 1; |
SESS_MTX_UNLOCK(conn); | //SESS_MTX_UNLOCK(conn); |
QCmdSN += conn->queue_depth; |
QCmdSN += conn->queue_depth; |
if (SN32_LT(ExpStatSN + QCmdSN, conn->StatSN)) { |
if (SN32_LT(ExpStatSN + QCmdSN, conn->StatSN)) { |
ISTGT_ERRLOG("StatSN(%u/%u) QCmdSN(%u) error\n", |
ISTGT_ERRLOG("StatSN(%u/%u) QCmdSN(%u) error\n", |
ExpStatSN, conn->StatSN, QCmdSN); |
ExpStatSN, conn->StatSN, QCmdSN); |
|
SESS_MTX_UNLOCK(conn); |
return -1; |
return -1; |
} |
} |
} |
} |
|
SESS_MTX_UNLOCK(conn); |
|
|
if (task_tag == 0xffffffffU) { |
if (task_tag == 0xffffffffU) { |
if (I_bit == 1) { |
if (I_bit == 1) { |
Line 3812 istgt_iscsi_op_nopout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
Line 3902 istgt_iscsi_op_nopout(CONN_Ptr conn, ISCSI_PDU_Ptr pdu
|
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[20], transfer_tag); |
DSET32(&rsp[20], transfer_tag); |
|
|
DSET32(&rsp[24], conn->StatSN); | if (conn->use_sender == 0) { |
conn->StatSN++; | SESS_MTX_LOCK(conn); |
SESS_MTX_LOCK(conn); | DSET32(&rsp[24], conn->StatSN); |
if (I_bit == 0) { | conn->StatSN++; |
conn->sess->ExpCmdSN++; | if (I_bit == 0) { |
conn->sess->MaxCmdSN++; | conn->sess->ExpCmdSN++; |
| conn->sess->MaxCmdSN++; |
| } |
| DSET32(&rsp[28], conn->sess->ExpCmdSN); |
| DSET32(&rsp[32], conn->sess->MaxCmdSN); |
| SESS_MTX_UNLOCK(conn); |
| } else { |
| // update by sender |
} |
} |
DSET32(&rsp[28], conn->sess->ExpCmdSN); |
|
DSET32(&rsp[32], conn->sess->MaxCmdSN); |
|
SESS_MTX_UNLOCK(conn); |
|
|
|
rc = istgt_iscsi_write_pdu(conn, &rsp_pdu); | rc = istgt_iscsi_write_pdu_upd(conn, &rsp_pdu, I_bit); |
if (rc < 0) { |
if (rc < 0) { |
ISTGT_ERRLOG("iscsi_write_pdu() failed\n"); |
ISTGT_ERRLOG("iscsi_write_pdu() failed\n"); |
return -1; |
return -1; |
Line 3890 istgt_add_transfer_task(CONN_Ptr conn, ISTGT_LU_CMD_Pt
|
Line 3984 istgt_add_transfer_task(CONN_Ptr conn, ISTGT_LU_CMD_Pt
|
ISTGT_R2T_TASK_Ptr r2t_task; |
ISTGT_R2T_TASK_Ptr r2t_task; |
uint32_t transfer_len; |
uint32_t transfer_len; |
uint32_t transfer_tag; |
uint32_t transfer_tag; |
int first_burst_len; | size_t first_burst_len; |
int max_burst_len; | size_t max_burst_len; |
int data_len; | size_t data_len; |
int offset = 0; | size_t offset = 0; |
int len; |
int len; |
int idx; |
int idx; |
int rc; |
int rc; |
Line 4049 istgt_iscsi_op_data(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 4143 istgt_iscsi_op_data(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
uint32_t ExpDataSN; |
uint32_t ExpDataSN; |
uint32_t DataSN; |
uint32_t DataSN; |
uint32_t buffer_offset; |
uint32_t buffer_offset; |
|
size_t data_len; |
|
size_t alloc_len; |
|
size_t offset; |
int F_bit; |
int F_bit; |
int data_len; |
|
int alloc_len; |
|
int offset; |
|
int rc; |
int rc; |
|
|
if (!conn->full_feature) { |
if (!conn->full_feature) { |
Line 4103 istgt_iscsi_op_data(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
Line 4197 istgt_iscsi_op_data(CONN_Ptr conn, ISCSI_PDU_Ptr pdu)
|
ExpDataSN = r2t_task->DataSN; |
ExpDataSN = r2t_task->DataSN; |
|
|
ISTGT_TRACELOG(ISTGT_TRACE_ISCSI, |
ISTGT_TRACELOG(ISTGT_TRACE_ISCSI, |
"StatSN=%u, ExpStatSN=%u, DataSN=%u, Offset=%u, Data=%d\n", | "StatSN=%u, ExpStatSN=%u, DataSN=%u, Offset=%u, Data=%zd\n", |
conn->StatSN, ExpStatSN, DataSN, buffer_offset, data_len); |
conn->StatSN, ExpStatSN, DataSN, buffer_offset, data_len); |
if (DataSN != ExpDataSN) { |
if (DataSN != ExpDataSN) { |
ISTGT_ERRLOG("DataSN(%u) error\n", DataSN); |
ISTGT_ERRLOG("DataSN(%u) error\n", DataSN); |
Line 4158 istgt_iscsi_send_r2t(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
|
Line 4252 istgt_iscsi_send_r2t(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
|
DSET32(&rsp[16], lu_cmd->task_tag); |
DSET32(&rsp[16], lu_cmd->task_tag); |
DSET32(&rsp[20], transfer_tag); |
DSET32(&rsp[20], transfer_tag); |
|
|
DSET32(&rsp[24], conn->StatSN); | if (conn->use_sender == 0) { |
SESS_MTX_LOCK(conn); | SESS_MTX_LOCK(conn); |
DSET32(&rsp[28], conn->sess->ExpCmdSN); | DSET32(&rsp[24], conn->StatSN); |
DSET32(&rsp[32], conn->sess->MaxCmdSN); | DSET32(&rsp[28], conn->sess->ExpCmdSN); |
SESS_MTX_UNLOCK(conn); | DSET32(&rsp[32], conn->sess->MaxCmdSN); |
| SESS_MTX_UNLOCK(conn); |
| } else { |
| // update by sender |
| } |
|
|
DSET32(&rsp[36], *R2TSN); |
DSET32(&rsp[36], *R2TSN); |
*R2TSN += 1; |
*R2TSN += 1; |
DSET32(&rsp[40], (uint32_t) offset); |
DSET32(&rsp[40], (uint32_t) offset); |
DSET32(&rsp[44], (uint32_t) len); |
DSET32(&rsp[44], (uint32_t) len); |
|
|
rc = istgt_iscsi_write_pdu(conn, &rsp_pdu); | rc = istgt_iscsi_write_pdu_upd(conn, &rsp_pdu, 0); |
if (rc < 0) { |
if (rc < 0) { |
ISTGT_ERRLOG("iscsi_write_pdu() failed\n"); |
ISTGT_ERRLOG("iscsi_write_pdu() failed\n"); |
return -1; |
return -1; |
Line 4179 istgt_iscsi_send_r2t(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
|
Line 4277 istgt_iscsi_send_r2t(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
|
} |
} |
|
|
int |
int |
istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd, uint8_t *data, int alloc_len, int transfer_len) | istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd, uint8_t *data, size_t alloc_len, size_t transfer_len) |
{ |
{ |
ISTGT_R2T_TASK_Ptr r2t_task; |
ISTGT_R2T_TASK_Ptr r2t_task; |
ISCSI_PDU data_pdu; |
ISCSI_PDU data_pdu; |
Line 4195 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
Line 4293 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
uint32_t DataSN; |
uint32_t DataSN; |
uint32_t buffer_offset; |
uint32_t buffer_offset; |
uint32_t R2TSN; |
uint32_t R2TSN; |
|
size_t data_len; |
|
size_t segment_len; |
|
size_t first_burst_len; |
|
size_t max_burst_len; |
|
size_t offset; |
int immediate, opcode; |
int immediate, opcode; |
int F_bit; |
int F_bit; |
int data_len; |
|
int segment_len; |
|
int first_burst_len; |
|
int max_burst_len; |
|
int offset; |
|
int len; |
int len; |
int r2t_flag; |
int r2t_flag; |
int r2t_offset; |
int r2t_offset; |
Line 4230 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
Line 4328 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
} |
} |
|
|
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
"Transfer=%d, First=%d, Max=%d, Segment=%d\n", | "Transfer=%zd, First=%zd, Max=%zd, Segment=%zd\n", |
transfer_len, data_len, max_burst_len, segment_len); |
transfer_len, data_len, max_burst_len, segment_len); |
|
|
r2t_task = istgt_get_transfer_task(conn, current_transfer_tag); |
r2t_task = istgt_get_transfer_task(conn, current_transfer_tag); |
Line 4250 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
Line 4348 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
istgt_free_transfer_task(r2t_task); |
istgt_free_transfer_task(r2t_task); |
|
|
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
"Using R2T(%d) offset=%d, DataSN=%d\n", | "Using R2T(%d) offset=%zd, DataSN=%d\n", |
conn->pending_r2t, offset, ExpDataSN); |
conn->pending_r2t, offset, ExpDataSN); |
|
|
rc = istgt_queue_count(&conn->pending_pdus); |
rc = istgt_queue_count(&conn->pending_pdus); |
Line 4302 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
Line 4400 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
data_pdu.copy_pdu = 0; |
data_pdu.copy_pdu = 0; |
do { |
do { |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
"Transfer=%d, Offset=%d, Len=%d\n", | "Transfer=%zd, Offset=%zd, Len=%d\n", |
transfer_len, offset, len); |
transfer_len, offset, len); |
/* send R2T if required */ |
/* send R2T if required */ |
if (r2t_flag == 0 |
if (r2t_flag == 0 |
Line 4330 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
Line 4428 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
r2t_sent = 1; |
r2t_sent = 1; |
ExpDataSN = 0; |
ExpDataSN = 0; |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
"R2T, Transfer=%d, Offset=%d, Len=%d\n", | "R2T, Transfer=%zd, Offset=%zd, Len=%d\n", |
transfer_len, offset, len); |
transfer_len, offset, len); |
} else { |
} else { |
r2t_sent = 0; |
r2t_sent = 0; |
Line 4434 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
Line 4532 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
|
|
ISTGT_TRACELOG(ISTGT_TRACE_ISCSI, |
ISTGT_TRACELOG(ISTGT_TRACE_ISCSI, |
"StatSN=%u, " |
"StatSN=%u, " |
"ExpStatSN=%u, DataSN=%u, Offset=%u, Data=%d\n", | "ExpStatSN=%u, DataSN=%u, Offset=%u, Data=%zd\n", |
conn->StatSN, |
conn->StatSN, |
ExpStatSN, DataSN, buffer_offset, data_len); |
ExpStatSN, DataSN, buffer_offset, data_len); |
if (DataSN != ExpDataSN) { |
if (DataSN != ExpDataSN) { |
Line 4488 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
Line 4586 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
ExpDataSN++; |
ExpDataSN++; |
|
|
if (r2t_flag == 0 && (offset > first_burst_len)) { |
if (r2t_flag == 0 && (offset > first_burst_len)) { |
ISTGT_ERRLOG("data_len(%d) > first_burst_length(%d)", | ISTGT_ERRLOG("data_len(%zd) > first_burst_length(%zd)", |
offset, first_burst_len); |
offset, first_burst_len); |
goto error_return; |
goto error_return; |
} |
} |
Line 4534 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
Line 4632 istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_P
|
} |
} |
|
|
r2t_return: |
r2t_return: |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "Transfered=%d, Offset=%d\n", | ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "Transfered=%zd, Offset=%zd\n", |
transfer_len, offset); |
transfer_len, offset); |
|
|
return 0; |
return 0; |
Line 4586 istgt_iscsi_send_nopin(CONN_Ptr conn)
|
Line 4684 istgt_iscsi_send_nopin(CONN_Ptr conn)
|
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[16], task_tag); |
DSET32(&rsp[20], transfer_tag); |
DSET32(&rsp[20], transfer_tag); |
|
|
DSET32(&rsp[24], conn->StatSN); | if (conn->use_sender == 0) { |
SESS_MTX_LOCK(conn); | SESS_MTX_LOCK(conn); |
DSET32(&rsp[28], conn->sess->ExpCmdSN); | DSET32(&rsp[24], conn->StatSN); |
DSET32(&rsp[32], conn->sess->MaxCmdSN); | DSET32(&rsp[28], conn->sess->ExpCmdSN); |
SESS_MTX_UNLOCK(conn); | DSET32(&rsp[32], conn->sess->MaxCmdSN); |
| SESS_MTX_UNLOCK(conn); |
| } else { |
| // update by sender |
| } |
|
|
rc = istgt_iscsi_write_pdu(conn, &rsp_pdu); | rc = istgt_iscsi_write_pdu_upd(conn, &rsp_pdu, 0); |
if (rc < 0) { |
if (rc < 0) { |
ISTGT_ERRLOG("iscsi_write_pdu() failed\n"); |
ISTGT_ERRLOG("iscsi_write_pdu() failed\n"); |
return -1; |
return -1; |
Line 4711 wait_all_task(CONN_Ptr conn)
|
Line 4813 wait_all_task(CONN_Ptr conn)
|
ISTGT_ERRLOG("kqueue() failed\n"); |
ISTGT_ERRLOG("kqueue() failed\n"); |
return; |
return; |
} |
} |
EV_SET(&kev, conn->task_pipe[0], EVFILT_READ, EV_ADD, 0, 0, NULL); | ISTGT_EV_SET(&kev, conn->task_pipe[0], EVFILT_READ, EV_ADD, 0, 0, NULL); |
rc = kevent(kq, &kev, 1, NULL, 0, NULL); |
rc = kevent(kq, &kev, 1, NULL, 0, NULL); |
if (rc == -1) { |
if (rc == -1) { |
ISTGT_ERRLOG("kevent() failed\n"); |
ISTGT_ERRLOG("kevent() failed\n"); |
Line 4761 wait_all_task(CONN_Ptr conn)
|
Line 4863 wait_all_task(CONN_Ptr conn)
|
#endif /* ISTGT_USE_KQUEUE */ |
#endif /* ISTGT_USE_KQUEUE */ |
|
|
#ifdef ISTGT_USE_KQUEUE |
#ifdef ISTGT_USE_KQUEUE |
if (kev.ident == conn->task_pipe[0]) { | if (kev.ident == (uintptr_t)conn->task_pipe[0]) { |
if (kev.flags & (EV_EOF|EV_ERROR)) { |
if (kev.flags & (EV_EOF|EV_ERROR)) { |
break; |
break; |
} |
} |
Line 4963 sender(void *arg)
|
Line 5065 sender(void *arg)
|
if (rc < 0) { |
if (rc < 0) { |
lu_task->error = 1; |
lu_task->error = 1; |
ISTGT_ERRLOG( |
ISTGT_ERRLOG( |
"iscsi_task_response() failed on %s(%s)\n", | "iscsi_task_response() CmdSN=%u failed" |
| " on %s(%s)\n", lu_task->lu_cmd.CmdSN, |
conn->target_port, conn->initiator_port); |
conn->target_port, conn->initiator_port); |
|
rc = write(conn->task_pipe[1], "E", 1); |
|
if(rc < 0 || rc != 1) { |
|
ISTGT_ERRLOG("write() failed\n"); |
|
} |
break; |
break; |
} |
} |
rc = istgt_lu_destroy_task(lu_task); |
rc = istgt_lu_destroy_task(lu_task); |
Line 4973 sender(void *arg)
|
Line 5080 sender(void *arg)
|
break; |
break; |
} |
} |
} else if (lu_task->type == ISTGT_LU_TASK_REQPDU) { |
} else if (lu_task->type == ISTGT_LU_TASK_REQPDU) { |
|
reqpdu: |
/* send PDU */ |
/* send PDU */ |
rc = istgt_iscsi_write_pdu_internal(lu_task->conn, |
rc = istgt_iscsi_write_pdu_internal(lu_task->conn, |
lu_task->lu_cmd.pdu); |
lu_task->lu_cmd.pdu); |
Line 4982 sender(void *arg)
|
Line 5090 sender(void *arg)
|
"iscsi_write_pdu() failed on %s(%s)\n", |
"iscsi_write_pdu() failed on %s(%s)\n", |
lu_task->conn->target_port, |
lu_task->conn->target_port, |
lu_task->conn->initiator_port); |
lu_task->conn->initiator_port); |
|
rc = write(conn->task_pipe[1], "E", 1); |
|
if(rc < 0 || rc != 1) { |
|
ISTGT_ERRLOG("write() failed\n"); |
|
} |
break; |
break; |
} |
} |
/* free allocated memory by caller */ |
/* free allocated memory by caller */ |
xfree(lu_task); |
xfree(lu_task); |
|
} else if (lu_task->type == ISTGT_LU_TASK_REQUPDPDU) { |
|
rc = istgt_update_pdu(lu_task->conn, &lu_task->lu_cmd); |
|
if (rc < 0) { |
|
lu_task->error = 1; |
|
ISTGT_ERRLOG( |
|
"update_pdu() failed on %s(%s)\n", |
|
lu_task->conn->target_port, |
|
lu_task->conn->initiator_port); |
|
rc = write(conn->task_pipe[1], "E", 1); |
|
if(rc < 0 || rc != 1) { |
|
ISTGT_ERRLOG("write() failed\n"); |
|
} |
|
break; |
|
} |
|
goto reqpdu; |
} else { |
} else { |
ISTGT_ERRLOG("Unknown task type %x\n", lu_task->type); |
ISTGT_ERRLOG("Unknown task type %x\n", lu_task->type); |
rc = -1; |
rc = -1; |
Line 5035 worker(void *arg)
|
Line 5162 worker(void *arg)
|
return NULL; |
return NULL; |
} |
} |
conn->kq = kq; |
conn->kq = kq; |
EV_SET(&kev, conn->sock, EVFILT_READ, EV_ADD, 0, 0, NULL); | ISTGT_EV_SET(&kev, conn->sock, EVFILT_READ, EV_ADD, 0, 0, NULL); |
rc = kevent(kq, &kev, 1, NULL, 0, NULL); |
rc = kevent(kq, &kev, 1, NULL, 0, NULL); |
if (rc == -1) { |
if (rc == -1) { |
ISTGT_ERRLOG("kevent() failed\n"); |
ISTGT_ERRLOG("kevent() failed\n"); |
close(kq); |
close(kq); |
return NULL; |
return NULL; |
} |
} |
EV_SET(&kev, conn->task_pipe[0], EVFILT_READ, EV_ADD, 0, 0, NULL); | ISTGT_EV_SET(&kev, conn->task_pipe[0], EVFILT_READ, EV_ADD, 0, 0, NULL); |
rc = kevent(kq, &kev, 1, NULL, 0, NULL); |
rc = kevent(kq, &kev, 1, NULL, 0, NULL); |
if (rc == -1) { |
if (rc == -1) { |
ISTGT_ERRLOG("kevent() failed\n"); |
ISTGT_ERRLOG("kevent() failed\n"); |
Line 5050 worker(void *arg)
|
Line 5177 worker(void *arg)
|
return NULL; |
return NULL; |
} |
} |
|
|
EV_SET(&kev, SIGINT, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); | if (!conn->istgt->daemon) { |
rc = kevent(kq, &kev, 1, NULL, 0, NULL); | ISTGT_EV_SET(&kev, SIGINT, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); |
if (rc == -1) { | rc = kevent(kq, &kev, 1, NULL, 0, NULL); |
ISTGT_ERRLOG("kevent() failed\n"); | if (rc == -1) { |
close(kq); | ISTGT_ERRLOG("kevent() failed\n"); |
return NULL; | close(kq); |
| return NULL; |
| } |
| ISTGT_EV_SET(&kev, SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); |
| rc = kevent(kq, &kev, 1, NULL, 0, NULL); |
| if (rc == -1) { |
| ISTGT_ERRLOG("kevent() failed\n"); |
| close(kq); |
| return NULL; |
| } |
} |
} |
EV_SET(&kev, SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); |
|
rc = kevent(kq, &kev, 1, NULL, 0, NULL); |
|
if (rc == -1) { |
|
ISTGT_ERRLOG("kevent() failed\n"); |
|
close(kq); |
|
return NULL; |
|
} |
|
#else |
#else |
memset(&fds, 0, sizeof fds); |
memset(&fds, 0, sizeof fds); |
fds[0].fd = conn->sock; |
fds[0].fd = conn->sock; |
fds[0].events = POLLIN; |
fds[0].events = POLLIN; |
fds[1].fd = conn->task_pipe[0]; |
fds[1].fd = conn->task_pipe[0]; |
fds[1].events = POLLIN; |
fds[1].events = POLLIN; |
|
|
nopin_timer = conn->nopininterval; |
|
#endif /* ISTGT_USE_KQUEUE */ |
#endif /* ISTGT_USE_KQUEUE */ |
|
|
conn->pdu.ahs = NULL; |
conn->pdu.ahs = NULL; |
Line 5108 worker(void *arg)
|
Line 5235 worker(void *arg)
|
pthread_sigmask(SIG_UNBLOCK, &signew, &sigold); |
pthread_sigmask(SIG_UNBLOCK, &signew, &sigold); |
|
|
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "loop start (%d)\n", conn->id); |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "loop start (%d)\n", conn->id); |
|
#ifndef ISTGT_USE_KQUEUE |
|
nopin_timer = conn->nopininterval; |
|
#endif /* !ISTGT_USE_KQUEUE */ |
while (1) { |
while (1) { |
/* check exit request */ |
/* check exit request */ |
if (conn->sess != NULL) { |
if (conn->sess != NULL) { |
Line 5187 worker(void *arg)
|
Line 5317 worker(void *arg)
|
} |
} |
if (rc == 0) { |
if (rc == 0) { |
/* no fds */ |
/* no fds */ |
|
//ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "poll TIMEOUT\n"); |
if (nopin_timer > 0) { |
if (nopin_timer > 0) { |
nopin_timer -= POLLWAIT; |
nopin_timer -= POLLWAIT; |
if (nopin_timer <= 0) { |
if (nopin_timer <= 0) { |
Line 5205 worker(void *arg)
|
Line 5336 worker(void *arg)
|
|
|
/* on socket */ |
/* on socket */ |
#ifdef ISTGT_USE_KQUEUE |
#ifdef ISTGT_USE_KQUEUE |
if (kev.ident == conn->sock) { | if (kev.ident == (uintptr_t)conn->sock) { |
if (kev.flags & (EV_EOF|EV_ERROR)) { |
if (kev.flags & (EV_EOF|EV_ERROR)) { |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
"kevent EOF/ERROR\n"); |
"kevent EOF/ERROR\n"); |
Line 5317 worker(void *arg)
|
Line 5448 worker(void *arg)
|
|
|
/* execute on task queue */ |
/* execute on task queue */ |
#ifdef ISTGT_USE_KQUEUE |
#ifdef ISTGT_USE_KQUEUE |
if (kev.ident == conn->task_pipe[0]) { | if (kev.ident == (uintptr_t)conn->task_pipe[0]) { |
if (kev.flags & (EV_EOF|EV_ERROR)) { |
if (kev.flags & (EV_EOF|EV_ERROR)) { |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
"kevent EOF/ERROR\n"); |
"kevent EOF/ERROR\n"); |
Line 5338 worker(void *arg)
|
Line 5469 worker(void *arg)
|
ISTGT_ERRLOG("read() failed\n"); |
ISTGT_ERRLOG("read() failed\n"); |
break; |
break; |
} |
} |
|
if (tmp[0] == 'E') { |
|
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "exit request (%d)\n", |
|
conn->id); |
|
break; |
|
} |
|
|
/* DATA-IN/OUT */ |
/* DATA-IN/OUT */ |
MTX_LOCK(&conn->task_queue_mutex); |
MTX_LOCK(&conn->task_queue_mutex); |
Line 5378 worker(void *arg)
|
Line 5514 worker(void *arg)
|
lu_task = NULL; |
lu_task = NULL; |
conn->exec_lu_task = NULL; |
conn->exec_lu_task = NULL; |
} else { |
} else { |
MTX_LOCK(&lu_task->trans_mutex); |
|
//ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
//ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
// "Task Write Trans START\n"); |
// "Task Write Trans START\n"); |
rc = istgt_iscsi_task_transfer_out(conn, lu_task); |
rc = istgt_iscsi_task_transfer_out(conn, lu_task); |
if (rc < 0) { |
if (rc < 0) { |
lu_task->error = 1; |
lu_task->error = 1; |
MTX_UNLOCK(&lu_task->trans_mutex); |
|
ISTGT_ERRLOG("iscsi_task_transfer_out() failed on %s(%s)\n", |
ISTGT_ERRLOG("iscsi_task_transfer_out() failed on %s(%s)\n", |
conn->target_port, |
conn->target_port, |
conn->initiator_port); |
conn->initiator_port); |
Line 5393 worker(void *arg)
|
Line 5527 worker(void *arg)
|
//ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
//ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, |
// "Task Write Trans END\n"); |
// "Task Write Trans END\n"); |
|
|
|
MTX_LOCK(&lu_task->trans_mutex); |
lu_task->req_transfer_out = 0; |
lu_task->req_transfer_out = 0; |
|
|
/* need response after execution */ |
/* need response after execution */ |
Line 5400 worker(void *arg)
|
Line 5535 worker(void *arg)
|
if (conn->use_sender == 0) { |
if (conn->use_sender == 0) { |
conn->running_tasks++; |
conn->running_tasks++; |
} |
} |
MTX_UNLOCK(&lu_task->trans_mutex); |
|
|
|
rc = pthread_cond_broadcast(&lu_task->trans_cond); |
rc = pthread_cond_broadcast(&lu_task->trans_cond); |
|
MTX_UNLOCK(&lu_task->trans_mutex); |
if (rc != 0) { |
if (rc != 0) { |
//MTX_UNLOCK(&lu_task->trans_mutex); |
|
ISTGT_ERRLOG("cond_broadcast() failed\n"); |
ISTGT_ERRLOG("cond_broadcast() failed\n"); |
break; |
break; |
} |
} |
Line 5476 worker(void *arg)
|
Line 5610 worker(void *arg)
|
wait_all_task(conn); |
wait_all_task(conn); |
|
|
if (conn->use_sender) { |
if (conn->use_sender) { |
|
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "stop sender thread (%d)\n", conn->id); |
/* stop sender thread */ |
/* stop sender thread */ |
|
MTX_LOCK(&conn->result_queue_mutex); |
rc = pthread_cond_broadcast(&conn->result_queue_cond); |
rc = pthread_cond_broadcast(&conn->result_queue_cond); |
|
MTX_UNLOCK(&conn->result_queue_mutex); |
if (rc != 0) { |
if (rc != 0) { |
ISTGT_ERRLOG("cond_broadcast() failed\n"); |
ISTGT_ERRLOG("cond_broadcast() failed\n"); |
/* ignore errors */ |
/* ignore errors */ |
Line 5509 worker(void *arg)
|
Line 5646 worker(void *arg)
|
} |
} |
|
|
int |
int |
istgt_create_conn(ISTGT_Ptr istgt, PORTAL_Ptr portal, int sock, struct sockaddr *sa, socklen_t salen) | istgt_create_conn(ISTGT_Ptr istgt, PORTAL_Ptr portal, int sock, struct sockaddr *sa, socklen_t salen __attribute__((__unused__))) |
{ |
{ |
char buf[MAX_TMPBUF]; |
char buf[MAX_TMPBUF]; |
CONN_Ptr conn; |
CONN_Ptr conn; |
Line 5659 istgt_create_conn(ISTGT_Ptr istgt, PORTAL_Ptr portal,
|
Line 5796 istgt_create_conn(ISTGT_Ptr istgt, PORTAL_Ptr portal,
|
conn->task_pipe[1] = -1; |
conn->task_pipe[1] = -1; |
goto error_return; |
goto error_return; |
} |
} |
rc = pthread_mutex_init(&conn->task_queue_mutex, NULL); | rc = pthread_mutex_init(&conn->task_queue_mutex, &istgt->mutex_attr); |
if (rc != 0) { |
if (rc != 0) { |
ISTGT_ERRLOG("mutex_init() failed\n"); |
ISTGT_ERRLOG("mutex_init() failed\n"); |
goto error_return; |
goto error_return; |
} |
} |
rc = pthread_mutex_init(&conn->result_queue_mutex, NULL); | rc = pthread_mutex_init(&conn->result_queue_mutex, &istgt->mutex_attr); |
if (rc != 0) { |
if (rc != 0) { |
ISTGT_ERRLOG("mutex_init() failed\n"); |
ISTGT_ERRLOG("mutex_init() failed\n"); |
goto error_return; |
goto error_return; |
Line 5684 istgt_create_conn(ISTGT_Ptr istgt, PORTAL_Ptr portal,
|
Line 5821 istgt_create_conn(ISTGT_Ptr istgt, PORTAL_Ptr portal,
|
ISTGT_ERRLOG("cond_init() failed\n"); |
ISTGT_ERRLOG("cond_init() failed\n"); |
goto error_return; |
goto error_return; |
} |
} |
rc = pthread_mutex_init(&conn->r2t_mutex, NULL); | rc = pthread_mutex_init(&conn->r2t_mutex, &istgt->mutex_attr); |
if (rc != 0) { |
if (rc != 0) { |
ISTGT_ERRLOG("mutex_init() failed\n"); |
ISTGT_ERRLOG("mutex_init() failed\n"); |
goto error_return; |
goto error_return; |
Line 5761 istgt_create_conn(ISTGT_Ptr istgt, PORTAL_Ptr portal,
|
Line 5898 istgt_create_conn(ISTGT_Ptr istgt, PORTAL_Ptr portal,
|
istgt_iscsi_param_free(conn->params); |
istgt_iscsi_param_free(conn->params); |
istgt_queue_destroy(&conn->pending_pdus); |
istgt_queue_destroy(&conn->pending_pdus); |
istgt_queue_destroy(&conn->task_queue); |
istgt_queue_destroy(&conn->task_queue); |
|
istgt_queue_destroy(&conn->result_queue); |
xfree(conn->portal.label); |
xfree(conn->portal.label); |
xfree(conn->portal.host); |
xfree(conn->portal.host); |
xfree(conn->portal.port); |
xfree(conn->portal.port); |
Line 6388 istgt_get_active_conns(void)
|
Line 6526 istgt_get_active_conns(void)
|
return num; |
return num; |
} |
} |
|
|
|
int |
|
istgt_stop_conns(void) |
|
{ |
|
CONN_Ptr conn; |
|
char tmp[1]; |
|
int rc; |
|
int i; |
|
|
|
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "istgt_stop_conns\n"); |
|
tmp[0] = 'E'; |
|
MTX_LOCK(&g_conns_mutex); |
|
for (i = 0; i < g_nconns; i++) { |
|
conn = g_conns[i]; |
|
if (conn == NULL) |
|
continue; |
|
rc = write(conn->task_pipe[1], tmp, 1); |
|
if(rc < 0 || rc != 1) { |
|
ISTGT_ERRLOG("write() failed\n"); |
|
/* ignore error */ |
|
} |
|
} |
|
MTX_UNLOCK(&g_conns_mutex); |
|
return 0; |
|
} |
|
|
CONN_Ptr |
CONN_Ptr |
istgt_find_conn(const char *initiator_port, const char *target_name, uint16_t tsih) |
istgt_find_conn(const char *initiator_port, const char *target_name, uint16_t tsih) |
{ |
{ |
Line 6463 istgt_iscsi_init(ISTGT_Ptr istgt)
|
Line 6626 istgt_iscsi_init(ISTGT_Ptr istgt)
|
} |
} |
|
|
int |
int |
istgt_iscsi_shutdown(ISTGT_Ptr istgt) | istgt_iscsi_shutdown(ISTGT_Ptr istgt __attribute__((__unused__))) |
{ |
{ |
CONN_Ptr conn; |
CONN_Ptr conn; |
int retry = 10; |
int retry = 10; |
Line 6515 istgt_iscsi_shutdown(ISTGT_Ptr istgt)
|
Line 6678 istgt_iscsi_shutdown(ISTGT_Ptr istgt)
|
if (rc != 0) { |
if (rc != 0) { |
ISTGT_ERRLOG("mutex_destroy() failed\n"); |
ISTGT_ERRLOG("mutex_destroy() failed\n"); |
return -1; |
return -1; |
|
} |
|
|
|
if (num == 0) { |
|
xfree(g_conns); |
|
g_conns = NULL; |
} |
} |
|
|
return 0; |
return 0; |