Skip to contentSkip to conversation

blockdev: acquire AioContext in hmp_commit()

PATCH In review Stefan Hajnoczi 4 participants 4 messages Oct 30, 2015 – Nov 2, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blockdev: acquire AioContext in hmp_commit()

This one slipped through. Although we acquire AioContext when committing all devices we don't for just a single device.

AioContext must be acquired before calling bdrv_*() functions to synchronize access with other threads that may be using the AioContext.

---
 blockdev.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
blockdev.c +11 -1
index 18712d2..d611779 100644
@@ -1120,6 +1120,9 @@ void hmp_commit(Monitor *mon, const QDict *qdict)
     if (!strcmp(device, "all")) {
         ret = bdrv_commit_all();
     } else {
+        BlockDriverState *bs;
+        AioContext *aio_context;
+
         blk = blk_by_name(device);
         if (!blk) {
             monitor_printf(mon, "Device '%s' not found\n", device);
@@ -1129,7 +1132,14 @@ void hmp_commit(Monitor *mon, const QDict *qdict)
             monitor_printf(mon, "Device '%s' has no medium\n", device);
             return;
         }
-        ret = bdrv_commit(blk_bs(blk));
+
+        bs = blk_bs(blk);
+        aio_context = bdrv_get_aio_context(bs);
+        aio_context_acquire(aio_context);
+
+        ret = bdrv_commit(bs);
+
+        aio_context_release(aio_context);
     }
     if (ret < 0) {
         monitor_printf(mon, "'commit' error for '%s': %s\n", device,
Signature · 1 line
2.4.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 45 lines · Stefan Hajnoczi

This one slipped through. Although we acquire AioContext when committing all devices we don't for just a single device.

AioContext must be acquired before calling bdrv_*() functions to synchronize access with other threads that may be using the AioContext.

---
 blockdev.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
blockdev.c +11 -1
index 18712d2..d611779 100644
@@ -1120,6 +1120,9 @@ void hmp_commit(Monitor *mon, const QDict *qdict)
     if (!strcmp(device, "all")) {
         ret = bdrv_commit_all();
     } else {
+        BlockDriverState *bs;
+        AioContext *aio_context;
+
         blk = blk_by_name(device);
         if (!blk) {
             monitor_printf(mon, "Device '%s' not found\n", device);
@@ -1129,7 +1132,14 @@ void hmp_commit(Monitor *mon, const QDict *qdict)
             monitor_printf(mon, "Device '%s' has no medium\n", device);
             return;
         }
-        ret = bdrv_commit(blk_bs(blk));
+
+        bs = blk_bs(blk);
+        aio_context = bdrv_get_aio_context(bs);
+        aio_context_acquire(aio_context);
+
+        ret = bdrv_commit(bs);
+
+        aio_context_release(aio_context);
     }
     if (ret < 0) {
         monitor_printf(mon, "'commit' error for '%s': %s\n", device,
Signature · 1 line
2.4.3
#2 lore raw
In reply to Stefan Hajnoczi
Quoted 31 lines · Stefan Hajnoczi

This one slipped through. Although we acquire AioContext when committing all devices we don't for just a single device.

AioContext must be acquired before calling bdrv_*() functions to synchronize access with other threads that may be using the AioContext.

---
  blockdev.c | 12 +++++++++++-
  1 file changed, 11 insertions(+), 1 deletion(-)
blockdev.c +4 -1
index 18712d2..d611779 100644
@@ -1120,6 +1120,9 @@ void hmp_commit(Monitor *mon, const QDict *qdict)
      if (!strcmp(device, "all")) {
          ret = bdrv_commit_all();
      } else {
+        BlockDriverState *bs;
+        AioContext *aio_context;
+
          blk = blk_by_name(device);
          if (!blk) {
              monitor_printf(mon, "Device '%s' not found\n", device);
@@ -1129,7 +1132,14 @@ void hmp_commit(Monitor *mon, const QDict *qdict)
              monitor_printf(mon, "Device '%s' has no medium\n", device);
              return;
          }
-        ret = bdrv_commit(blk_bs(blk));
+

blockdev.c void hmp_commit(Monitor *mon, const QDict *qdict) · line 1145

Quoted 10 lines
blockdev.c +7 -0
+        bs = blk_bs(blk);
+        aio_context = bdrv_get_aio_context(bs);
+        aio_context_acquire(aio_context);
+
+        ret = bdrv_commit(bs);
+
+        aio_context_release(aio_context);
      }
      if (ret < 0) {
          monitor_printf(mon, "'commit' error for '%s': %s\n", device,

I like it in general, but could you pls wait a bit before pushing it up. I am working at the moment on a more generic series. I am going to attach this patch to it to consider the situation as a whole.

It would be much trickier than my previous one. There are several other places discovered.

Den

#3 lore raw
Quoted 47 lines · Denis V. Lunev
Quoted 31 lines · Stefan Hajnoczi

This one slipped through. Although we acquire AioContext when committing all devices we don't for just a single device.

AioContext must be acquired before calling bdrv_*() functions to synchronize access with other threads that may be using the AioContext.

---
 blockdev.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
blockdev.c +4 -1
index 18712d2..d611779 100644
@@ -1120,6 +1120,9 @@ void hmp_commit(Monitor *mon, const QDict *qdict)
     if (!strcmp(device, "all")) {
         ret = bdrv_commit_all();
     } else {
+        BlockDriverState *bs;
+        AioContext *aio_context;
+
         blk = blk_by_name(device);
         if (!blk) {
             monitor_printf(mon, "Device '%s' not found\n", device);
@@ -1129,7 +1132,14 @@ void hmp_commit(Monitor *mon, const QDict *qdict)
             monitor_printf(mon, "Device '%s' has no medium\n", device);
             return;
         }
-        ret = bdrv_commit(blk_bs(blk));
+

blockdev.c void hmp_commit(Monitor *mon, const QDict *qdict) · line 1145

Quoted 10 lines
blockdev.c +7 -0
+        bs = blk_bs(blk);
+        aio_context = bdrv_get_aio_context(bs);
+        aio_context_acquire(aio_context);
+
+        ret = bdrv_commit(bs);
+
+        aio_context_release(aio_context);
     }
     if (ret < 0) {
         monitor_printf(mon, "'commit' error for '%s': %s\n", device,

I like it in general, but could you pls wait a bit before pushing it up. I am working at the moment on a more generic series. I am going to attach this patch to it to consider the situation as a whole.

Quoted 2 lines

It would be much trickier than my previous one. There are several other places discovered.

Sure. We need to solve the missing AioContext acquires by hard freeze (2015-11-12, see http://qemu-project.org/Planning/2.5). Until then we can discuss different solutions.

Stefan