Skip to contentSkip to conversation

block/iscsi: cancel libiscsi task when ABORT TASK TMF completes

PATCH In review Stefan Hajnoczi 3 participants 5 messages Feb 15, 2018 – Feb 20, 2018 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/iscsi: cancel libiscsi task when ABORT TASK TMF completes

The libiscsi iscsi_task_mgmt_async() API documentation says:

abort_task will also cancel the scsi task. The callback for the scsi task will be invoked with SCSI_STATUS_CANCELLED

The libiscsi implementation does not fulfil this promise. The task's callback is not invoked and its struct iscsi_pdu remains in the internal list (effectively leaked).

This patch invokes the libiscsi iscsi_scsi_cancel_task() API to force the task's callback to be invoked with SCSI_STATUS_CANCELLED when the ABORT TASK TMF completes and the task's callback hasn't been invoked yet.

---
 block/iscsi.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
block/iscsi.c +14 -2
index 41e67cb371..4cb188ac2b 100644
@@ -292,8 +292,12 @@ iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data,
 {
     IscsiAIOCB *acb = private_data;
 
-    acb->status = -ECANCELED;
-    iscsi_schedule_bh(acb);
+    /* If the command callback hasn't been called yet, drop the task */
+    if (!acb->bh) {
+        /* Call iscsi_aio_ioctl_cb() with SCSI_STATUS_CANCELLED */
+        iscsi_scsi_cancel_task(iscsi, acb->task);
+    }
+
     qemu_aio_unref(acb); /* acquired in iscsi_aio_cancel() */
 }
 
@@ -941,6 +945,14 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status,
 {
     IscsiAIOCB *acb = opaque;
 
+    if (status == SCSI_STATUS_CANCELLED) {
+        if (!acb->bh) {
+            acb->status = -ECANCELED;
+            iscsi_schedule_bh(acb);
+        }
+        return;
+    }
+
     acb->status = 0;
     if (status < 0) {
         error_report("Failed to ioctl(SG_IO) to iSCSI lun. %s",
Signature · 1 line
2.14.3
#1 lore raw

Am 15.02.2018 um 12:15 schrieb Stefan Hajnoczi:

Quoted 8 lines

The libiscsi iscsi_task_mgmt_async() API documentation says:

abort_task will also cancel the scsi task. The callback for the scsi task will be invoked with SCSI_STATUS_CANCELLED

The libiscsi implementation does not fulfil this promise. The task's callback is not invoked and its struct iscsi_pdu remains in the internal list (effectively leaked).

If that contract is fixed in libiscsi, will the Qemu iSCSI driver still work?

Peter

#2 lore raw
Quoted 11 lines · Peter Lieven

Am 15.02.2018 um 12:15 schrieb Stefan Hajnoczi:

Quoted 8 lines

The libiscsi iscsi_task_mgmt_async() API documentation says:

abort_task will also cancel the scsi task. The callback for the scsi task will be invoked with SCSI_STATUS_CANCELLED

The libiscsi implementation does not fulfil this promise. The task's callback is not invoked and its struct iscsi_pdu remains in the internal list (effectively leaked).

If that contract is fixed in libiscsi, will the Qemu iSCSI driver still work?

In

+ /* If the command callback hasn't been called yet, drop the task */
+ if (!acb->bh) {

and

+ if (status == SCSI_STATUS_CANCELLED) {
+ if (!acb->bh) {

we're mindful of the fact that the callback may have been invoked by libiscsi already. There is no risk of double-completion.

Stefan

#3 lore raw

Am 15.02.2018 um 18:27 schrieb Stefan Hajnoczi:

Quoted 21 lines · Peter Lieven
Quoted 10 lines

Am 15.02.2018 um 12:15 schrieb Stefan Hajnoczi:

Quoted 8 lines

The libiscsi iscsi_task_mgmt_async() API documentation says:

abort_task will also cancel the scsi task. The callback for the scsi task will be invoked with SCSI_STATUS_CANCELLED

The libiscsi implementation does not fulfil this promise. The task's callback is not invoked and its struct iscsi_pdu remains in the internal list (effectively leaked).

If that contract is fixed in libiscsi, will the Qemu iSCSI driver still work?

In

block/iscsi.c +2 -0
+    /* If the command callback hasn't been called yet, drop the task */
+    if (!acb->bh) {

and

block/iscsi.c +2 -0
+    if (status == SCSI_STATUS_CANCELLED) {
+        if (!acb->bh) {
Quoted 2 lines

we're mindful of the fact that the callback may have been invoked by libiscsi already. There is no risk of double-completion.

Hi Stefan,

thanks for the clarification. I am fine with this change. I will check with Ronnie for the libiscsi fix.

Peter

#4 lore raw
Quoted 32 lines · Peter Lieven

Am 15.02.2018 um 18:27 schrieb Stefan Hajnoczi:

Quoted 27 lines · Peter Lieven
Quoted 8 lines

Am 15.02.2018 um 12:15 schrieb Stefan Hajnoczi:

Quoted 6 lines

The libiscsi iscsi_task_mgmt_async() API documentation says:

abort_task will also cancel the scsi task. The callback for the scsi task will be invoked with SCSI_STATUS_CANCELLED

Quoted 6 lines
Quoted 3 lines

The libiscsi implementation does not fulfil this promise. The task's callback is not invoked and its struct iscsi_pdu remains in the internal list (effectively leaked).

If that contract is fixed in libiscsi, will the Qemu iSCSI driver still work?

In

block/iscsi.c +2 -0
+    /* If the command callback hasn't been called yet, drop the task */
+    if (!acb->bh) {

and

block/iscsi.c +2 -0
+    if (status == SCSI_STATUS_CANCELLED) {
+        if (!acb->bh) {
Quoted 2 lines

we're mindful of the fact that the callback may have been invoked by libiscsi already. There is no risk of double-completion.

Quoted 5 lines

Hi Stefan,

thanks for the clarification. I am fine with this change. I will check with Ronnie for the
libiscsi fix.

Great, then this patch can go via Paolo's SCSI tree.

Stefan