Skip to content

Commit

Permalink
Merge pull request #400 from anatoliy-glagolev/master
Browse files Browse the repository at this point in the history
lun_reset cancelling lun tasks only
  • Loading branch information
sahlberg authored May 29, 2024
2 parents dd94a21 + 35cf3a4 commit 2227e7b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/iscsi-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ void iscsi_pdu_set_ritt(struct iscsi_pdu *pdu, uint32_t ritt);
void iscsi_pdu_set_datasn(struct iscsi_pdu *pdu, uint32_t datasn);
void iscsi_pdu_set_bufferoffset(struct iscsi_pdu *pdu, uint32_t bufferoffset);
void iscsi_cancel_pdus(struct iscsi_context *iscsi);
void iscsi_cancel_lun_pdus(struct iscsi_context *iscsi, uint32_t lun);
int iscsi_pdu_add_data(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
const unsigned char *dptr, int dsize);
int iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu);
Expand Down
33 changes: 33 additions & 0 deletions lib/pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,3 +969,36 @@ iscsi_cancel_pdus(struct iscsi_context *iscsi)
iscsi->drv->free_pdu(iscsi, pdu);
}
}

void
iscsi_cancel_lun_pdus(struct iscsi_context *iscsi, uint32_t lun)
{
struct iscsi_pdu *pdu;
struct iscsi_pdu *next_pdu;
uint32_t cmdsn_gap = 0;
struct scsi_task * task = NULL;

for (pdu = iscsi->outqueue; pdu; pdu = next_pdu) {
next_pdu = pdu->next;
task = iscsi_scsi_get_task_from_pdu(pdu);

if (cmdsn_gap > 0) {
iscsi_pdu_set_cmdsn(pdu, pdu->cmdsn - cmdsn_gap);
}
if (task == NULL || task->lun != lun) {
continue;
}
if (!(pdu->outdata.data[0] & ISCSI_PDU_IMMEDIATE) &&
(pdu->outdata.data[0] & 0x3f) != ISCSI_PDU_DATA_OUT) {
iscsi->cmdsn--;
cmdsn_gap++;
}
ISCSI_LIST_REMOVE(&iscsi->outqueue, pdu);
iscsi_set_error(iscsi, "command cancelled");
if (pdu->callback) {
pdu->callback(iscsi, SCSI_STATUS_CANCELLED,
NULL, pdu->private_data);
}
iscsi->drv->free_pdu(iscsi, pdu);
}
}
2 changes: 1 addition & 1 deletion lib/task_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ iscsi_task_mgmt_lun_reset_async(struct iscsi_context *iscsi,
uint32_t lun,
iscsi_command_cb cb, void *private_data)
{
iscsi_scsi_cancel_all_tasks(iscsi);
iscsi_cancel_lun_pdus(iscsi, lun);

return iscsi_task_mgmt_async(iscsi,
lun, ISCSI_TM_LUN_RESET,
Expand Down

0 comments on commit 2227e7b

Please sign in to comment.