Skip to contentSkip to conversation

iscsi: fix race between task completition and task abortion

PATCH In review Stefan Priebe 4 participants 7 messages Aug 14, 2012 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iscsi: fix race between task completition and task abortion

From: spriebe <[email protected]>

---
 block/iscsi.c |   36 ++++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 16 deletions(-)
block/iscsi.c +20 -16
index 12ca76d..257f97f 100644
@@ -76,6 +76,10 @@ static void
 iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data,
                     void *private_data)
 {
+           IscsiAIOCB *acb = (IscsiAIOCB *)private_data;
+
+           scsi_free_scsi_task(acb->task);
+           acb->task = NULL;
 }
 
 static void
@@ -85,14 +89,19 @@ iscsi_aio_cancel(BlockDriverAIOCB *blockacb)
     IscsiLun *iscsilun = acb->iscsilun;
 
     acb->common.cb(acb->common.opaque, -ECANCELED);
-    acb->canceled = 1;
 
-    /* send a task mgmt call to the target to cancel the task on the target */
-    iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task,
-                                     iscsi_abort_task_cb, NULL);
+    if (acb->canceled != 0)
+        return;
+
+    acb->canceled = 1;
 
-    /* then also cancel the task locally in libiscsi */
-    iscsi_scsi_task_cancel(iscsilun->iscsi, acb->task);
+    /* send a task mgmt call to the target to cancel the task on the target
+     * this also cancels the task in libiscsi
+     */
+    if (acb->task) {
+        iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task,
+                                         iscsi_abort_task_cb, &acb);
+    }
 }
 
 static AIOPool iscsi_aio_pool = {
@@ -184,6 +193,11 @@ iscsi_readv_writev_bh_cb(void *p)
     }
 
     qemu_aio_release(acb);
+
+    if (acb->task) {
+      scsi_free_scsi_task(acb->task);
+      acb->task = NULL;
+    }
 }
 
 
@@ -212,8 +226,6 @@ iscsi_aio_write16_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static int64_t sector_qemu2lun(int64_t sector, IscsiLun *iscsilun)
@@ -313,8 +325,6 @@ iscsi_aio_read16_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *
@@ -429,8 +439,6 @@ iscsi_synccache10_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *
@@ -483,8 +491,6 @@ iscsi_unmap_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *
@@ -560,8 +566,6 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 1 line · Stefan Priebe

From: spriebe <[email protected]>

CCing Ronnie, iSCSI block driver author.

Quoted 107 lines
---
 block/iscsi.c |   36 ++++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 16 deletions(-)
block/iscsi.c +20 -16
index 12ca76d..257f97f 100644
@@ -76,6 +76,10 @@ static void
 iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data,
                     void *private_data)
 {
+           IscsiAIOCB *acb = (IscsiAIOCB *)private_data;
+
+           scsi_free_scsi_task(acb->task);
+           acb->task = NULL;
 }
 
 static void
@@ -85,14 +89,19 @@ iscsi_aio_cancel(BlockDriverAIOCB *blockacb)
     IscsiLun *iscsilun = acb->iscsilun;
 
     acb->common.cb(acb->common.opaque, -ECANCELED);
-    acb->canceled = 1;
 
-    /* send a task mgmt call to the target to cancel the task on the target */
-    iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task,
-                                     iscsi_abort_task_cb, NULL);
+    if (acb->canceled != 0)
+        return;
+
+    acb->canceled = 1;
 
-    /* then also cancel the task locally in libiscsi */
-    iscsi_scsi_task_cancel(iscsilun->iscsi, acb->task);
+    /* send a task mgmt call to the target to cancel the task on the target
+     * this also cancels the task in libiscsi
+     */
+    if (acb->task) {
+        iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task,
+                                         iscsi_abort_task_cb, &acb);
+    }
 }
 
 static AIOPool iscsi_aio_pool = {
@@ -184,6 +193,11 @@ iscsi_readv_writev_bh_cb(void *p)
     }
 
     qemu_aio_release(acb);
+
+    if (acb->task) {
+      scsi_free_scsi_task(acb->task);
+      acb->task = NULL;
+    }
 }
 
 
@@ -212,8 +226,6 @@ iscsi_aio_write16_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static int64_t sector_qemu2lun(int64_t sector, IscsiLun *iscsilun)
@@ -313,8 +325,6 @@ iscsi_aio_read16_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *
@@ -429,8 +439,6 @@ iscsi_synccache10_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *
@@ -483,8 +491,6 @@ iscsi_unmap_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *
@@ -560,8 +566,6 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
Signature · 1 line
1.7.2.5
#2 lore raw

Stefan H

How should I do Acked-by properly,

Is a reply with the text

sufficient ?

regards
ronnie sahlberg

Quoted 112 lines · Stefan Hajnoczi
Quoted 1 line · Stefan Priebe

From: spriebe <[email protected]>

CCing Ronnie, iSCSI block driver author.

Quoted 107 lines
---
 block/iscsi.c |   36 ++++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 16 deletions(-)
block/iscsi.c +20 -17
index 12ca76d..257f97f 100644
@@ -76,6 +76,10 @@ static void
 iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data,
                     void *private_data)
 {
+           IscsiAIOCB *acb = (IscsiAIOCB *)private_data;
+
+           scsi_free_scsi_task(acb->task);
+           acb->task = NULL;
 }
 
 static void
@@ -85,14 +89,19 @@ iscsi_aio_cancel(BlockDriverAIOCB *blockacb)
     IscsiLun *iscsilun = acb->iscsilun;
 
     acb->common.cb(acb->common.opaque, -ECANCELED);
-    acb->canceled = 1;
 
-    /* send a task mgmt call to the target to cancel the task on the target */
-    iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task,
-                                     iscsi_abort_task_cb, NULL);
+    if (acb->canceled != 0)
+        return;
+
+    acb->canceled = 1;
 
-    /* then also cancel the task locally in libiscsi */
-    iscsi_scsi_task_cancel(iscsilun->iscsi, acb->task);
+    /* send a task mgmt call to the target to cancel the task on the target
+     * this also cancels the task in libiscsi
+     */
+    if (acb->task) {
+        iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task,
+                                         iscsi_abort_task_cb, &acb);
+    }
 }
 
 static AIOPool iscsi_aio_pool = {
@@ -184,6 +193,11 @@ iscsi_readv_writev_bh_cb(void *p)
     }
 
     qemu_aio_release(acb);
+
+    if (acb->task) {
+      scsi_free_scsi_task(acb->task);
+      acb->task = NULL;
+    }
 }
 
 
@@ -212,8 +226,6 @@ iscsi_aio_write16_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static int64_t sector_qemu2lun(int64_t sector, IscsiLun *iscsilun)
@@ -313,8 +325,6 @@ iscsi_aio_read16_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *
@@ -429,8 +439,6 @@ iscsi_synccache10_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *
@@ -483,8 +491,6 @@ iscsi_unmap_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *
@@ -560,8 +566,6 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status,
     }
 
     iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
-    scsi_free_scsi_task(acb->task);
-    acb->task = NULL;
 }
 
 static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
--

1.7.2.5

#4 lore raw

Am 14.08.2012 14:11, schrieb Stefan Hajnoczi:

Quoted 9 lines
Quoted 5 lines · ronnie sahlberg

Is a reply with the text

sufficient ?

Yes

But is this only meant as a question or a real Acked-by and I should pick it up? (Still for 1.2, I guess?)

Kevin

#6 lore raw
In reply to Stefan Priebe

Am 14.08.2012 08:44, schrieb Stefan Priebe:

Quoted 5 lines

From: spriebe <[email protected]>

---
 block/iscsi.c |   36 ++++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 16 deletions(-)

It would be nice to have your full name and a valid email address in the
From: line (needs an update of your git config) and a more detailed explanation of the problem that you're fixing.

Having a Signed-off-by line, however, is absolutely required and the patch can't be merged without it.

block/iscsi.c static void · line 82

Quoted 13 lines
block/iscsi.c +4 -0
index 12ca76d..257f97f 100644
@@ -76,6 +76,10 @@ static void
 iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data,
                     void *private_data)
 {
+           IscsiAIOCB *acb = (IscsiAIOCB *)private_data;
+
+           scsi_free_scsi_task(acb->task);
+           acb->task = NULL;

Please use scripts/checkpatch.pl. qemu uses an indentation of four spaces, more coding style violations follow.

Kevin

#5 lore raw
In reply to Kevin Wolf

Am 14.08.2012 16:08, schrieb Kevin Wolf:

Quoted 5 lines

Am 14.08.2012 14:11, schrieb Stefan Hajnoczi:

Quoted 4 lines
Quoted 2 lines · ronnie sahlberg

Is a reply with the text

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

sufficient ?

Yes

But is this only meant as a question or a real Acked-by and I should pick it up? (Still for 1.2, I guess?)

I'll send a new patch in a few minutes. It fixes the signed-off, style and a logic problem as well.

Stefan