qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH 7/8] block: use the new _change_ API instead of _can_set_


From: Hanna Reitz
Subject: Re: [RFC PATCH 7/8] block: use the new _change_ API instead of _can_set_ and _set_
Date: Fri, 15 Jul 2022 15:32:53 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0

On 12.07.22 23:19, Emanuele Giuseppe Esposito wrote:
Replace all direct usage of ->can_set_aio_ctx and ->set_aio_ctx,
and call bdrv_child_try_change_aio_context() in
bdrv_try_set_aio_context(), the main function called through
the whole block layer.

 From this point onwards, ->can_set_aio_ctx and ->set_aio_ctx
won't be used anymore.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
  block.c               | 30 ++++++++++++++++--------------
  block/block-backend.c |  8 ++++++--
  2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/block.c b/block.c
index a7ba590dfa..101188a2d4 100644
--- a/block.c
+++ b/block.c
@@ -2966,17 +2966,18 @@ static void bdrv_attach_child_common_abort(void *opaque)
      }
if (bdrv_child_get_parent_aio_context(child) != s->old_parent_ctx) {
+        Transaction *tran;
          GSList *ignore;
+        bool ret;
- /* No need to ignore `child`, because it has been detached already */
-        ignore = NULL;
-        child->klass->can_set_aio_ctx(child, s->old_parent_ctx, &ignore,
-                                      &error_abort);
-        g_slist_free(ignore);
+        tran = tran_new();
+ /* No need to ignore `child`, because it has been detached already */
          ignore = NULL;
-        child->klass->set_aio_ctx(child, s->old_parent_ctx, &ignore);
+        ret = child->klass->change_aio_ctx(child, s->old_parent_ctx, &ignore,
+                                           tran, &error_abort);
          g_slist_free(ignore);
+        tran_finalize(tran, ret ? ret : -1);

As far as I understand, the transaction is supposed to always succeed; that’s why we pass `&error_abort`, I thought.

If so, `ret` should always be true.  More importantly, though, I think the `ret ? ret : -1` is wrong because it’ll always evaluate to either 1 or -1, but never to 0, which would indicate success.  I think it should be `ret == true ? 0 : -1`, or even better `assert(ret == true); tran_finalize(tran, 0);`.

      }
bdrv_unref(bs);
@@ -3037,17 +3038,18 @@ static int bdrv_attach_child_common(BlockDriverState 
*child_bs,
          Error *local_err = NULL;
          int ret = bdrv_try_set_aio_context(child_bs, parent_ctx, &local_err);
- if (ret < 0 && child_class->can_set_aio_ctx) {
+        if (ret < 0 && child_class->change_aio_ctx) {
+            Transaction *tran = tran_new();
              GSList *ignore = g_slist_prepend(NULL, new_child);
-            if (child_class->can_set_aio_ctx(new_child, child_ctx, &ignore,
-                                             NULL))
-            {
+            bool ret_child;
+
+            ret_child = child_class->change_aio_ctx(new_child, child_ctx,
+                                                    &ignore, tran, NULL);
+            if (ret_child) {

To be honest, due to the mix of return value styles we have, perhaps a `ret_child == true` would help to signal that this is a success path.

                  error_free(local_err);
                  ret = 0;
-                g_slist_free(ignore);
-                ignore = g_slist_prepend(NULL, new_child);
-                child_class->set_aio_ctx(new_child, child_ctx, &ignore);
              }
+            tran_finalize(tran, ret_child ? ret_child : -1);

This too should probably be `ret_child == true ? 0 : -1`.

              g_slist_free(ignore);
          }
@@ -7708,7 +7710,7 @@ int bdrv_try_set_aio_context(BlockDriverState *bs, AioContext *ctx,
                               Error **errp)
  {
      GLOBAL_STATE_CODE();
-    return bdrv_child_try_set_aio_context(bs, ctx, NULL, errp);
+    return bdrv_child_try_change_aio_context(bs, ctx, NULL, errp);

Why not remove this function and adjust all callers?

Hanna

  }
void bdrv_add_aio_context_notifier(BlockDriverState *bs,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]