qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 07/10] block: Reuse fail path from bdrv_open()


From: Max Reitz
Subject: Re: [Qemu-devel] [PATCH 07/10] block: Reuse fail path from bdrv_open()
Date: Mon, 27 Jan 2014 19:58:58 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

On 27.01.2014 04:10, Benoît Canet wrote:
Le Sunday 26 Jan 2014 à 20:02:40 (+0100), Max Reitz a écrit :
The fail paths of bdrv_file_open() and bdrv_open() naturally exhibit
similarities, thus it is possible to reuse the one from bdrv_open() and
shorten the one in bdrv_file_open() accordingly.

Signed-off-by: Max Reitz <address@hidden>
---
  block.c | 17 +++++++----------
  1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/block.c b/block.c
index 72eddd5..0f2cd3f 100644
--- a/block.c
+++ b/block.c
@@ -1038,9 +1038,6 @@ static int bdrv_file_open(BlockDriverState *bs, const 
char *filename,
fail:
      QDECREF(options);
-    if (!bs->drv) {
-        QDECREF(bs->options);
-    }
      return ret;
  }
@@ -1240,17 +1237,17 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
      if (flags & BDRV_O_PROTOCOL) {
          assert(!drv);
          ret = bdrv_file_open(bs, filename, options, flags & ~BDRV_O_PROTOCOL,
-                             errp);
+                             &local_err);
+        options = NULL;
          if (ret) {
-            if (*pbs) {
-                bdrv_close(bs);
+            if (bs->drv) {
+                goto close_and_fail;
              } else {
-                bdrv_unref(bs);
+                goto fail;
              }
-        } else {
-            *pbs = bs;
          }
Forget what I said about the goto chain in the previous mail.

But something like:

     if(!ret) {
         *pbs = bs;
         return 0;
     }
     if (bs->drv) {
         goto close_and_fail;
     }
     goto fail;

would keep the code in line.

Best regards

Benoît

Yes, this seems better to me as well. :-)

Or, after patch 9:

if (!ret) {
    goto done;
} else if (bs->drv) {
    goto close_and_fail;
} else {
    goto fail;
}

(which I like a bit more, with the three gotos on the same indentation level)

Max

+        *pbs = bs;
+        return 0;
      }
bs->options = options;
--
1.8.5.3






reply via email to

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