Skip to contentSkip to conversation

gluster: fix .bdrv_reopen_prepare when backing file is a JSON object

PATCH Superseded Stefano Garzarella 3 participants 8 messages Jul 12, 2019 – Jul 15, 2019 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gluster: fix .bdrv_reopen_prepare when backing file is a JSON object

When the backing_file is specified as a JSON object, the qemu_gluster_reopen_prepare() fails with this message:

    invalid URI json:{"server.0.host": ...}

In this case, we should call qemu_gluster_init() using the QDict 'state->options' that contains the parameters already parsed.

---
 block/gluster.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
block/gluster.c +10 -1
index 62f8ff2147..26971db1ea 100644
@@ -931,7 +931,16 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
     gconf->has_debug = true;
     gconf->logfile = g_strdup(s->logfile);
     gconf->has_logfile = true;
-    reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL, errp);
+    /*
+     * If 'bs->filename' starts with "json:", then 'state->options' will
+     * contain the parameters already parsed.
+     */
+    if (state->bs->filename && !strstart(state->bs->filename, "json:", NULL)) {
+        reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL,
+                                         errp);
+    } else {
+        reop_s->glfs = qemu_gluster_init(gconf, NULL, state->options, errp);
+    }
     if (reop_s->glfs == NULL) {
         ret = -errno;
         goto exit;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 22 lines · Stefano Garzarella

When the backing_file is specified as a JSON object, the qemu_gluster_reopen_prepare() fails with this message:

    invalid URI json:{"server.0.host": ...}

In this case, we should call qemu_gluster_init() using the QDict 'state->options' that contains the parameters already parsed.

---
 block/gluster.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
block/gluster.c +0 -1
index 62f8ff2147..26971db1ea 100644
@@ -931,7 +931,16 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
     gconf->has_debug = true;
     gconf->logfile = g_strdup(s->logfile);
     gconf->has_logfile = true;
-    reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL, errp);

block/gluster.c static int qemu_gluster_reopen_prepare(BDRVReopenState *state, · line 943

Quoted 10 lines
block/gluster.c +10 -0
+    /*
+     * If 'bs->filename' starts with "json:", then 'state->options' will
+     * contain the parameters already parsed.
+     */
+    if (state->bs->filename && !strstart(state->bs->filename, "json:", NULL)) {
+        reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL,
+                                         errp);
+    } else {
+        reop_s->glfs = qemu_gluster_init(gconf, NULL, state->options, errp);
+    }

Hmmm, aren’t they always in state->options?

Max

#2 lore raw
Quoted 27 lines · Max Reitz
Quoted 26 lines · Stefano Garzarella

When the backing_file is specified as a JSON object, the qemu_gluster_reopen_prepare() fails with this message:

    invalid URI json:{"server.0.host": ...}

In this case, we should call qemu_gluster_init() using the QDict 'state->options' that contains the parameters already parsed.

---
 block/gluster.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
block/gluster.c +4 -1
index 62f8ff2147..26971db1ea 100644
@@ -931,7 +931,16 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
     gconf->has_debug = true;
     gconf->logfile = g_strdup(s->logfile);
     gconf->has_logfile = true;
-    reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL, errp);
+    /*
+     * If 'bs->filename' starts with "json:", then 'state->options' will
+     * contain the parameters already parsed.
+     */
Quoted 8 lines

block/gluster.c static int qemu_gluster_reopen_prepare(BDRVReopenState *state, · line 943

Quoted 6 lines
block/gluster.c +6 -0
+    if (state->bs->filename && !strstart(state->bs->filename, "json:", NULL)) {
+        reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL,
+                                         errp);
+    } else {
+        reop_s->glfs = qemu_gluster_init(gconf, NULL, state->options, errp);
+    }

Hmmm, aren’t they always in state->options?

Yes, you are rigth, but the qemu_gluster_parse() doesn't search for the 'filename' in the QDict *options.

Maybe I can simply modify it in this way in order to hanlde this case, calling qemu_gluster_init() only with 'state->options'.

block/gluster.c +5 -0
index 26971db1ea..91d674cd2b 100644
@@ -695,6 +695,11 @@ static int qemu_gluster_parse(BlockdevOptionsGluster *gconf,
                               QDict *options, Error **errp)
 {
     int ret;
+
+    if (!filename) {
+        filename = qdict_get_try_str(options, GLUSTER_OPT_FILENAME);
+    }
+
     if (filename) {
         ret = qemu_gluster_parse_uri(gconf, filename);
         if (ret < 0) {

Do you think it is better/cleaner?

Thanks,
Stefano

#3 lore raw
Quoted 61 lines · Stefano Garzarella
Quoted 27 lines · Max Reitz
Quoted 26 lines · Stefano Garzarella

When the backing_file is specified as a JSON object, the qemu_gluster_reopen_prepare() fails with this message:

    invalid URI json:{"server.0.host": ...}

In this case, we should call qemu_gluster_init() using the QDict 'state->options' that contains the parameters already parsed.

---
 block/gluster.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
block/gluster.c +4 -1
index 62f8ff2147..26971db1ea 100644
@@ -931,7 +931,16 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
     gconf->has_debug = true;
     gconf->logfile = g_strdup(s->logfile);
     gconf->has_logfile = true;
-    reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL, errp);
+    /*
+     * If 'bs->filename' starts with "json:", then 'state->options' will
+     * contain the parameters already parsed.
+     */
Quoted 8 lines

block/gluster.c static int qemu_gluster_reopen_prepare(BDRVReopenState *state, · line 943

Quoted 6 lines
block/gluster.c +6 -0
+    if (state->bs->filename && !strstart(state->bs->filename, "json:", NULL)) {
+        reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL,
+                                         errp);
+    } else {
+        reop_s->glfs = qemu_gluster_init(gconf, NULL, state->options, errp);
+    }

Hmmm, aren’t they always in state->options?

Yes, you are rigth, but the qemu_gluster_parse() doesn't search for the 'filename' in the QDict *options.

Maybe I can simply modify it in this way in order to hanlde this case, calling qemu_gluster_init() only with 'state->options'.

block/gluster.c +5 -0
index 26971db1ea..91d674cd2b 100644
@@ -695,6 +695,11 @@ static int qemu_gluster_parse(BlockdevOptionsGluster *gconf,
                               QDict *options, Error **errp)
 {
     int ret;
+
+    if (!filename) {
+        filename = qdict_get_try_str(options, GLUSTER_OPT_FILENAME);
+    }
+
     if (filename) {
         ret = qemu_gluster_parse_uri(gconf, filename);
         if (ret < 0) {
Quoted 1 line

Do you think it is better/cleaner?

No, because the rest of the function completely ignores @options if @filename is set.

Hm. I can’t think of anything better than your original solution, then.
Except the “state->bs->filename” should probably be a
“state->bs->filename[0]” (as Patchew has pointed out).

Max

#4 lore raw
Quoted 62 lines · Max Reitz
Quoted 61 lines · Stefano Garzarella
Quoted 27 lines · Max Reitz
Quoted 26 lines · Stefano Garzarella

When the backing_file is specified as a JSON object, the qemu_gluster_reopen_prepare() fails with this message:

    invalid URI json:{"server.0.host": ...}

In this case, we should call qemu_gluster_init() using the QDict 'state->options' that contains the parameters already parsed.

---
 block/gluster.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
block/gluster.c +4 -1
index 62f8ff2147..26971db1ea 100644
@@ -931,7 +931,16 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
     gconf->has_debug = true;
     gconf->logfile = g_strdup(s->logfile);
     gconf->has_logfile = true;
-    reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL, errp);
+    /*
+     * If 'bs->filename' starts with "json:", then 'state->options' will
+     * contain the parameters already parsed.
+     */
Quoted 8 lines

block/gluster.c static int qemu_gluster_reopen_prepare(BDRVReopenState *state, · line 943

Quoted 6 lines
block/gluster.c +6 -0
+    if (state->bs->filename && !strstart(state->bs->filename, "json:", NULL)) {
+        reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL,
+                                         errp);
+    } else {
+        reop_s->glfs = qemu_gluster_init(gconf, NULL, state->options, errp);
+    }

Hmmm, aren’t they always in state->options?

Yes, you are rigth, but the qemu_gluster_parse() doesn't search for the 'filename' in the QDict *options.

Maybe I can simply modify it in this way in order to hanlde this case, calling qemu_gluster_init() only with 'state->options'.

block/gluster.c +5 -0
index 26971db1ea..91d674cd2b 100644
@@ -695,6 +695,11 @@ static int qemu_gluster_parse(BlockdevOptionsGluster *gconf,
                               QDict *options, Error **errp)
 {
     int ret;
+
+    if (!filename) {
+        filename = qdict_get_try_str(options, GLUSTER_OPT_FILENAME);
+    }
+
     if (filename) {
         ret = qemu_gluster_parse_uri(gconf, filename);
         if (ret < 0) {
Quoted 8 lines
Quoted 1 line

Do you think it is better/cleaner?

No, because the rest of the function completely ignores @options if @filename is set.

Hm. I can’t think of anything better than your original solution, then.
Except the “state->bs->filename” should probably be a
“state->bs->filename[0]” (as Patchew has pointed out).

Sure, I'll fix it in the v2.

Thanks,
Stefano

#5 lore raw
Quoted 68 lines · Stefano Garzarella
Quoted 67 lines · Max Reitz
Quoted 61 lines · Stefano Garzarella
Quoted 27 lines · Max Reitz
Quoted 26 lines · Stefano Garzarella

When the backing_file is specified as a JSON object, the qemu_gluster_reopen_prepare() fails with this message:

    invalid URI json:{"server.0.host": ...}

In this case, we should call qemu_gluster_init() using the QDict 'state->options' that contains the parameters already parsed.

---
 block/gluster.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
block/gluster.c +4 -1
index 62f8ff2147..26971db1ea 100644
@@ -931,7 +931,16 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
     gconf->has_debug = true;
     gconf->logfile = g_strdup(s->logfile);
     gconf->has_logfile = true;
-    reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL, errp);
+    /*
+     * If 'bs->filename' starts with "json:", then 'state->options' will
+     * contain the parameters already parsed.
+     */
Quoted 8 lines

block/gluster.c static int qemu_gluster_reopen_prepare(BDRVReopenState *state, · line 943

Quoted 6 lines
block/gluster.c +6 -0
+    if (state->bs->filename && !strstart(state->bs->filename, "json:", NULL)) {
+        reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL,
+                                         errp);
+    } else {
+        reop_s->glfs = qemu_gluster_init(gconf, NULL, state->options, errp);
+    }

Hmmm, aren’t they always in state->options?

Yes, you are rigth, but the qemu_gluster_parse() doesn't search for the 'filename' in the QDict *options.

Maybe I can simply modify it in this way in order to hanlde this case, calling qemu_gluster_init() only with 'state->options'.

block/gluster.c +5 -0
index 26971db1ea..91d674cd2b 100644
@@ -695,6 +695,11 @@ static int qemu_gluster_parse(BlockdevOptionsGluster *gconf,
                               QDict *options, Error **errp)
 {
     int ret;
+
+    if (!filename) {
+        filename = qdict_get_try_str(options, GLUSTER_OPT_FILENAME);
+    }
+
     if (filename) {
         ret = qemu_gluster_parse_uri(gconf, filename);
         if (ret < 0) {
Quoted 1 line

Do you think it is better/cleaner?

No, because the rest of the function completely ignores @options if @filename is set.

Quoted 5 lines
Quoted 3 lines

Hm. I can’t think of anything better than your original solution, then.
Except the “state->bs->filename” should probably be a
“state->bs->filename[0]” (as Patchew has pointed out).

Sure, I'll fix it in the v2.

Oh, wait. You can actually just use state->bs->exact_filename. That will never be a json:{} filename, so you don’t have to do the prefix check (just see whether it is empty).

Max

#6 lore raw
Quoted 73 lines · Max Reitz
Quoted 72 lines · Stefano Garzarella
Quoted 70 lines · Max Reitz
Quoted 61 lines · Stefano Garzarella
Quoted 27 lines · Max Reitz
Quoted 26 lines · Stefano Garzarella

When the backing_file is specified as a JSON object, the qemu_gluster_reopen_prepare() fails with this message:

    invalid URI json:{"server.0.host": ...}

In this case, we should call qemu_gluster_init() using the QDict 'state->options' that contains the parameters already parsed.

---
 block/gluster.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
block/gluster.c +4 -1
index 62f8ff2147..26971db1ea 100644
@@ -931,7 +931,16 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
     gconf->has_debug = true;
     gconf->logfile = g_strdup(s->logfile);
     gconf->has_logfile = true;
-    reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL, errp);
+    /*
+     * If 'bs->filename' starts with "json:", then 'state->options' will
+     * contain the parameters already parsed.
+     */
Quoted 8 lines

block/gluster.c static int qemu_gluster_reopen_prepare(BDRVReopenState *state, · line 943

Quoted 6 lines
block/gluster.c +6 -0
+    if (state->bs->filename && !strstart(state->bs->filename, "json:", NULL)) {
+        reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL,
+                                         errp);
+    } else {
+        reop_s->glfs = qemu_gluster_init(gconf, NULL, state->options, errp);
+    }

Hmmm, aren’t they always in state->options?

Yes, you are rigth, but the qemu_gluster_parse() doesn't search for the 'filename' in the QDict *options.

Maybe I can simply modify it in this way in order to hanlde this case, calling qemu_gluster_init() only with 'state->options'.

block/gluster.c +5 -0
index 26971db1ea..91d674cd2b 100644
@@ -695,6 +695,11 @@ static int qemu_gluster_parse(BlockdevOptionsGluster *gconf,
                               QDict *options, Error **errp)
 {
     int ret;
+
+    if (!filename) {
+        filename = qdict_get_try_str(options, GLUSTER_OPT_FILENAME);
+    }
+
     if (filename) {
         ret = qemu_gluster_parse_uri(gconf, filename);
         if (ret < 0) {
Quoted 1 line

Do you think it is better/cleaner?

No, because the rest of the function completely ignores @options if @filename is set.

Hm. I can’t think of anything better than your original solution, then.
Except the “state->bs->filename” should probably be a
“state->bs->filename[0]” (as Patchew has pointed out).

Quoted 5 lines
Quoted 1 line

Sure, I'll fix it in the v2.

Oh, wait. You can actually just use state->bs->exact_filename. That will never be a json:{} filename, so you don’t have to do the prefix check (just see whether it is empty).

Yeah, thanks for the suggestion!

Stefano

#7 lore raw
In reply to Stefano Garzarella
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the asan build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-fedora V=1 NETWORK=1
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1 === TEST SCRIPT END ===

  CC      audio/noaudio.o
  CC      audio/wavaudio.o
  CC      audio/mixeng.o
/tmp/qemu-test/src/block/gluster.c:938:20: error: address of array 'state->bs->filename' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
    if (state->bs->filename && !strstart(state->bs->filename, "json:", NULL)) {
        ~~~~~~~~~~~^~~~~~~~ ~~

1 error generated.

The full log is available at
http://patchew.org/logs/[email protected]/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]