pdu: Introduce iscsi_cancel_pdus()

Introduce a helper exported from lib/pdu.c which cancels all pdus for a
given context. This patch eliminates repeated code from various other
files which have the same purpose. The only functional difference is
that the cancellation done from iscsi-command.c was (incorrectly) not
checking for iscsi->is_loggedin before issuing callbacks.

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
This commit is contained in:
Felipe Franciosi
2017-11-25 16:59:00 +00:00
parent 5aafc29991
commit 3c4925e8da
5 changed files with 33 additions and 65 deletions

View File

@@ -768,3 +768,32 @@ iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
{
return iscsi->drv->queue_pdu(iscsi, pdu);
}
void
iscsi_cancel_pdus(struct iscsi_context *iscsi)
{
struct iscsi_pdu *pdu;
while ((pdu = iscsi->outqueue)) {
ISCSI_LIST_REMOVE(&iscsi->outqueue, pdu);
if (iscsi->is_loggedin && pdu->callback) {
/* If an error happened during connect/login,
we don't want to call any of the callbacks.
*/
pdu->callback(iscsi, SCSI_STATUS_CANCELLED,
NULL, pdu->private_data);
}
iscsi->drv->free_pdu(iscsi, pdu);
}
while ((pdu = iscsi->waitpdu)) {
ISCSI_LIST_REMOVE(&iscsi->waitpdu, pdu);
if (iscsi->is_loggedin && pdu->callback) {
/* If an error happened during connect/login,
we don't want to call any of the callbacks.
*/
pdu->callback(iscsi, SCSI_STATUS_CANCELLED,
NULL, pdu->private_data);
}
iscsi->drv->free_pdu(iscsi, pdu);
}
}