Skip to contentSkip to conversation

blkdebug/blkverify: Allow command-line configuration

PATCH Superseded Max Reitz 2 participants 9 messages Nov 21, 2013 – Nov 22, 2013 Block layer

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

cover blkdebug/blkverify: Allow command-line configuration

Currently, the configuration of blkdebug and blkverify is done through the "filename" alone. There is now way of manually choosing blkdebug or blkverify as a driver and using a normal image filename.

In the case of blkdebug, the filename starts with the protocol prefix, follows up with the name of a configuration file and ends with the name of the image file.

In the case of blkverify, the filename starts with the protocol prefix, follows up with the raw reference image filename and ends with the name of the image file.

This patch allows the configuration of both drivers completely through command-line options. The driver has to be selected through the file.driver option (or similar), the image filename has to be given as the filename (obviously) and, depending on the driver, further options have to be given to control the behavior.

In case of blkverify, the x-raw option specifies the name of the raw reference image file.

In case of blkdebug, one may either set the config option to the filename of a configuration file, or the contents of the configuration file may be given directly on the command line (see description of patch 3 for an example).

Max Reitz (6):
blkdebug: Use errp for read_config()
blkdebug: Don't require sophisticated filename
qemu-option: Add qemu_config_parse_qdict()
blkdebug: Always call read_config()
blkdebug: Use command-line in read_config()
blkverify: Don't require protocol filename

 block/blkdebug.c           |  50 +++++++++++++-------
 block/blkverify.c          |   4 +-
 include/qemu/config-file.h |   6 +++
 util/qemu-config.c         | 111 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 154 insertions(+), 17 deletions(-)
Signature · 1 line
1.8.4.2
author
#1 lore raw

PATCH 1/6 blkdebug: Use errp for read_config()

Use an Error variable in the read_config() function.

---
 block/blkdebug.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
block/blkdebug.c +9 -4
index 16d2b91..76f80c0 100644
@@ -271,7 +271,7 @@ static void remove_rule(BlkdebugRule *rule)
     g_free(rule);
 }
 
-static int read_config(BDRVBlkdebugState *s, const char *filename)
+static int read_config(BDRVBlkdebugState *s, const char *filename, Error **errp)
 {
     FILE *f;
     int ret;
@@ -279,11 +279,16 @@ static int read_config(BDRVBlkdebugState *s, const char *filename)
 
     f = fopen(filename, "r");
     if (f == NULL) {
+        error_setg_errno(errp, errno, "Could not read blkdebug config file "
+                         "'%s'", filename);
         return -errno;
     }
 
     ret = qemu_config_parse(f, config_groups, filename);
     if (ret < 0) {
+        error_setg(errp, "Could not parse blkdebug config file '%s'",
+                   filename);
+        ret = -EINVAL;
         goto fail;
     }
 
@@ -370,9 +375,9 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
     /* Read rules from config file */
     config = qemu_opt_get(opts, "config");
     if (config) {
-        ret = read_config(s, config);
-        if (ret < 0) {
-            error_setg_errno(errp, -ret, "Could not read blkdebug config file");
+        ret = read_config(s, config, &local_err);
+        if (ret) {
+            error_propagate(errp, local_err);
             goto fail;
         }
     }
Signature · 1 line
1.8.4.2
author
#2 lore raw

PATCH 2/6 blkdebug: Don't require sophisticated filename

In reply to Max Reitz

If the filename is not prefixed by "blkdebug:" in blkdebug_parse_filename(), the blkdebug driver was not selected through that protocol prefix, but by an explicit command line option (file.driver=blkdebug or something similar). Contrary to the current reaction, this is not a problem at all; we just need to store the filename (in the x-image option) and can go on; the user just has to manually specify the config option.

---
 block/blkdebug.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/blkdebug.c +3 -1
index 76f80c0..59d33a8 100644
@@ -315,7 +315,9 @@ static void blkdebug_parse_filename(const char *filename, QDict *options,
 
     /* Parse the blkdebug: prefix */
     if (!strstart(filename, "blkdebug:", &filename)) {
-        error_setg(errp, "File name string must start with 'blkdebug:'");
+        /* There was no prefix; therefore, all options have to be already
+           present in the QDict (except for the filename) */
+        qdict_put(options, "x-image", qstring_from_str(filename));
         return;
     }
 
Signature · 1 line
1.8.4.2
author
#3 lore raw

PATCH 3/6 qemu-option: Add qemu_config_parse_qdict()

In reply to Max Reitz

This function basically parses command-line options given as a QDict replacing a config file.

For instance, the QDict {"section.opt1": 42, "section.opt2": 23} corresponds to the config file:

[section]
opt1 = 42
opt2 = 23

It is possible to specify multiple sections and also multiple sections of the same type. On the command line, this looks like the following:

inject-error.0.event=reftable_load,\
inject-error.1.event=l2_load,\
set-state.event=l1_update

This would correspond to the following config file:

[inject-error "inject-error.0"]
event = reftable_load

[inject-error "inject-error.1"]
event = l2_load

[set-state]
event = l1_update

---
 include/qemu/config-file.h |   6 +++
 util/qemu-config.c         | 111 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
include/qemu/config-file.h +6 -0
index 508428f..dbd97c4 100644
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include "qemu/option.h"
 #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
 
 QemuOptsList *qemu_find_opts(const char *group);
 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
@@ -18,6 +19,11 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname);
 
 int qemu_read_config_file(const char *filename);
 
+/* Parse QDict options as a replacement for a config file (allowing multiple
+   enumerated (0..(n-1)) configuration "sections") */
+void qemu_config_parse_qdict(QDict *options, QemuOptsList **lists,
+                             Error **errp);
+
 /* Read default QEMU config files
  */
 int qemu_read_default_config_files(bool userconfig);
util/qemu-config.c +111 -0

114 lines not on this page · raw message

Signature · 1 line
1.8.4.2
#4 lore raw

Re: [Qemu-devel] [PATCH 3/6] qemu-option: Add qemu_config_parse_qdict()

Quoted 102 lines · Max Reitz

This function basically parses command-line options given as a QDict replacing a config file.

For instance, the QDict {"section.opt1": 42, "section.opt2": 23} corresponds to the config file:

[section]
opt1 = 42
opt2 = 23

It is possible to specify multiple sections and also multiple sections of the same type. On the command line, this looks like the following:

inject-error.0.event=reftable_load,\
inject-error.1.event=l2_load,\
set-state.event=l1_update

This would correspond to the following config file:

[inject-error "inject-error.0"]
event = reftable_load

[inject-error "inject-error.1"]
event = l2_load

[set-state]
event = l1_update

---
  include/qemu/config-file.h |   6 +++
  util/qemu-config.c         | 111 +++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 117 insertions(+)
include/qemu/config-file.h +6 -0
index 508428f..dbd97c4 100644
@@ -4,6 +4,7 @@
  #include <stdio.h>
  #include "qemu/option.h"
  #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
 
  QemuOptsList *qemu_find_opts(const char *group);
  QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
@@ -18,6 +19,11 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname);
 
  int qemu_read_config_file(const char *filename);
 
+/* Parse QDict options as a replacement for a config file (allowing multiple
+   enumerated (0..(n-1)) configuration "sections") */
+void qemu_config_parse_qdict(QDict *options, QemuOptsList **lists,
+                             Error **errp);
+
  /* Read default QEMU config files
   */
  int qemu_read_default_config_files(bool userconfig);
util/qemu-config.c +36 -0
index 04da942..80d82d4 100644
@@ -356,3 +356,114 @@ int qemu_read_config_file(const char *filename)
          return -EINVAL;
      }
  }
+
+static void config_parse_qdict_section(QDict *options, QemuOptsList *opts,
+                                       Error **errp)
+{
+    QemuOpts *subopts, *subopts_i;
+    QDict *subqdict, *subqdict_i = NULL;
+    char *prefix = g_strdup_printf("%s.", opts->name);
+    Error *local_err = NULL;
+    size_t orig_size, enum_size;
+
+    qdict_extract_subqdict(options, &subqdict, prefix);
+    orig_size = qdict_size(subqdict);
+    if (!orig_size) {
+        goto out;
+    }
+
+    subopts = qemu_opts_create_nofail(opts);
+    qemu_opts_absorb_qdict(subopts, subqdict, &local_err);
+    if (error_is_set(&local_err)) {
+        error_propagate(errp, local_err);
+        goto out;
+    }
+
+    enum_size = qdict_size(subqdict);
+    if (enum_size < orig_size && enum_size) {
+        error_setg(errp, "Unknown option '%s' for '%s'",
+                   qdict_first(subqdict)->key, opts->name);
+        goto out;
+    }
+
+    if (enum_size) {
+        /* Multiple, enumerated rules */
+        int i;
+
+        /* Not required anymore */
+        qemu_opts_del(subopts);

util/qemu-config.c int qemu_read_config_file(const char *filename) · line 404

Quoted 10 lines
util/qemu-config.c +10 -0
+
+        for (i = 0; i < INT_MAX; i++) {
+            char i_prefix[32], opt_name[48];
+            size_t snprintf_ret;
+
+            snprintf_ret = snprintf(i_prefix, 32, "%i.", i);
+            assert(snprintf_ret < 32);
+
+            snprintf_ret = snprintf(opt_name, 48, "%s.%i", opts->name, i);
+            assert(snprintf_ret < 48);

Is there a length limit of opts->name? I.e. is this an error case rather than an assertion case?

util/qemu-config.c int qemu_read_config_file(const char *filename) · line 411

Quoted 7 lines
util/qemu-config.c +7 -0
+
+            qdict_extract_subqdict(subqdict, &subqdict_i, i_prefix);
+            if (!qdict_size(subqdict_i)) {
+                break;
+            }
+
+            subopts_i = qemu_opts_create(opts, opt_name, 1, NULL);

Could pass in errp and skip error_setg below.

Quoted 4 lines
util/qemu-config.c +4 -0
+            if (!subopts_i) {
+                error_setg(errp, "Option ID '%s' already in use", opt_name);
+                goto out;
+            }

util/qemu-config.c int qemu_read_config_file(const char *filename) · line 425

Quoted 10 lines
util/qemu-config.c +10 -0
+
+            qemu_opts_absorb_qdict(subopts_i, subqdict_i, &local_err);
+            if (error_is_set(&local_err)) {
+                error_propagate(errp, local_err);
+                qemu_opts_del(subopts_i);
+                goto out;
+            }
+
+            if (qdict_size(subqdict_i)) {
+                error_setg(errp, "[%s] rules don't support the option '%s'",

s/rules don't/section doesn't/

util/qemu-config.c int qemu_read_config_file(const char *filename) · line 433

Quoted 8 lines
util/qemu-config.c +8 -0
+                           opts->name, qdict_first(subqdict_i)->key);
+                qemu_opts_del(subopts_i);
+                goto out;
+            }
+
+            /*
+            if (add_rule(subopts_i, (void *)ard) < 0) {
+                error_setg(errp, "Could not add [%s] rule %i", opts->name, i);

s/rule/section/
Or just remove this hunk?

Quoted 27 lines
util/qemu-config.c +26 -0
+                goto out;
+            }
+            */
+
+            QDECREF(subqdict_i);
+            subqdict_i = NULL;
+        }
+
+        if (qdict_size(subqdict)) {
+            error_setg(errp, "Unused option '%s' for [%s]",
+                       qdict_first(subqdict)->key, opts->name);
+            goto out;
+        }
+    }
+
+out:
+    QDECREF(subqdict);
+    QDECREF(subqdict_i);
+
+    free(prefix);
+}
+
+void qemu_config_parse_qdict(QDict *options, QemuOptsList **lists,
+                             Error **errp)
+{
+    int i;

util/qemu-config.c int qemu_read_config_file(const char *filename) · line 469

Quoted 10 lines
util/qemu-config.c +10 -0
+    Error *local_err = NULL;
+
+    for (i = 0; lists[i]; i++) {
+        config_parse_qdict_section(options, lists[i], &local_err);
+        if (error_is_set(&local_err)) {
+            error_propagate(errp, local_err);
+            return;
+        }
+    }
+}

This does the work, but also seems ad-hoc. Providing an array of dicts in the command line should be a general logic, which would also be very useful for Quorum driver.

Fam

author
#5 lore raw

Re: [Qemu-devel] [PATCH 3/6] qemu-option: Add qemu_config_parse_qdict()

Quoted 112 lines · Fam Zheng
Quoted 111 lines · Max Reitz

This function basically parses command-line options given as a QDict replacing a config file.

For instance, the QDict {"section.opt1": 42, "section.opt2": 23} corresponds to the config file:

[section]
opt1 = 42
opt2 = 23

It is possible to specify multiple sections and also multiple sections of the same type. On the command line, this looks like the following:

inject-error.0.event=reftable_load,\
inject-error.1.event=l2_load,\
set-state.event=l1_update

This would correspond to the following config file:

[inject-error "inject-error.0"]
event = reftable_load

[inject-error "inject-error.1"]
event = l2_load

[set-state]
event = l1_update

---
  include/qemu/config-file.h |   6 +++
  util/qemu-config.c         | 111 
+++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 117 insertions(+)
include/qemu/config-file.h +2 -0
index 508428f..dbd97c4 100644
@@ -4,6 +4,7 @@
  #include <stdio.h>
  #include "qemu/option.h"
  #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
 
  QemuOptsList *qemu_find_opts(const char *group);
  QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
@@ -18,6 +19,11 @@ int qemu_config_parse(FILE *fp, QemuOptsList 
 **lists, const char *fname);
 
  int qemu_read_config_file(const char *filename);
 
+/* Parse QDict options as a replacement for a config file (allowing 

multiple

include/qemu/config-file.h +4 -0
+   enumerated (0..(n-1)) configuration "sections") */
+void qemu_config_parse_qdict(QDict *options, QemuOptsList **lists,
+                             Error **errp);
+
  /* Read default QEMU config files
   */
  int qemu_read_default_config_files(bool userconfig);
util/qemu-config.c +2 -0
index 04da942..80d82d4 100644
@@ -356,3 +356,114 @@ int qemu_read_config_file(const char *filename)
          return -EINVAL;
      }
  }
+
+static void config_parse_qdict_section(QDict *options, QemuOptsList 

*opts,

util/qemu-config.c +39 -0
+                                       Error **errp)
+{
+    QemuOpts *subopts, *subopts_i;
+    QDict *subqdict, *subqdict_i = NULL;
+    char *prefix = g_strdup_printf("%s.", opts->name);
+    Error *local_err = NULL;
+    size_t orig_size, enum_size;
+
+    qdict_extract_subqdict(options, &subqdict, prefix);
+    orig_size = qdict_size(subqdict);
+    if (!orig_size) {
+        goto out;
+    }
+
+    subopts = qemu_opts_create_nofail(opts);
+    qemu_opts_absorb_qdict(subopts, subqdict, &local_err);
+    if (error_is_set(&local_err)) {
+        error_propagate(errp, local_err);
+        goto out;
+    }
+
+    enum_size = qdict_size(subqdict);
+    if (enum_size < orig_size && enum_size) {
+        error_setg(errp, "Unknown option '%s' for '%s'",
+                   qdict_first(subqdict)->key, opts->name);
+        goto out;
+    }
+
+    if (enum_size) {
+        /* Multiple, enumerated rules */
+        int i;
+
+        /* Not required anymore */
+        qemu_opts_del(subopts);
+
+        for (i = 0; i < INT_MAX; i++) {
+            char i_prefix[32], opt_name[48];
+            size_t snprintf_ret;
+
Quoted 8 lines
Quoted 6 lines
util/qemu-config.c +4 -0
+            snprintf_ret = snprintf(i_prefix, 32, "%i.", i);
+            assert(snprintf_ret < 32);
+
+            snprintf_ret = snprintf(opt_name, 48, "%s.%i", 

opts->name, i);
+ assert(snprintf_ret < 48);

Is there a length limit of opts->name? I.e. is this an error case rather than an assertion case?

Hm, yes, I had most of the code directly in block/blkdebug.c at first, that's why there are some issues here which work fine just for blkdebug, but are not that good in the general case. I'll use g_strdup_sprintf instead.

Quoted 10 lines

util/qemu-config.c int qemu_read_config_file(const char *filename) · line 411

Quoted 8 lines
util/qemu-config.c +7 -0
+
+            qdict_extract_subqdict(subqdict, &subqdict_i, i_prefix);
+            if (!qdict_size(subqdict_i)) {
+                break;
+            }
+
+            subopts_i = qemu_opts_create(opts, opt_name, 1, NULL);

Could pass in errp and skip error_setg below.

Oh, right, missed that, thanks.

Quoted 11 lines
Quoted 11 lines
util/qemu-config.c +2 -0
+            if (!subopts_i) {
+                error_setg(errp, "Option ID '%s' already in use", 

opt_name);

util/qemu-config.c +7 -0
+                goto out;
+            }
+
+            qemu_opts_absorb_qdict(subopts_i, subqdict_i, &local_err);
+            if (error_is_set(&local_err)) {
+                error_propagate(errp, local_err);
+                qemu_opts_del(subopts_i);
Quoted 8 lines
Quoted 6 lines
util/qemu-config.c +5 -0
+                goto out;
+            }
+
+            if (qdict_size(subqdict_i)) {
+                error_setg(errp, "[%s] rules don't support the 

option '%s'",

s/rules don't/section doesn't/

Yes, this one also is fine for blkdebug, but not so much for the general case.

Quoted 11 lines
Quoted 10 lines
util/qemu-config.c +8 -0
+                           opts->name, qdict_first(subqdict_i)->key);
+                qemu_opts_del(subopts_i);
+                goto out;
+            }
+
+            /*
+            if (add_rule(subopts_i, (void *)ard) < 0) {
+                error_setg(errp, "Could not add [%s] rule %i", 

opts->name, i);

Quoted 2 lines

s/rule/section/
Or just remove this hunk?

Hm, I probably should have completely reviewed my own code before sending it. Will do that in v2, promise. ;-)

Quoted 32 lines
Quoted 32 lines
util/qemu-config.c +31 -0
+                goto out;
+            }
+            */
+
+            QDECREF(subqdict_i);
+            subqdict_i = NULL;
+        }
+
+        if (qdict_size(subqdict)) {
+            error_setg(errp, "Unused option '%s' for [%s]",
+                       qdict_first(subqdict)->key, opts->name);
+            goto out;
+        }
+    }
+
+out:
+    QDECREF(subqdict);
+    QDECREF(subqdict_i);
+
+    free(prefix);
+}
+
+void qemu_config_parse_qdict(QDict *options, QemuOptsList **lists,
+                             Error **errp)
+{
+    int i;
+    Error *local_err = NULL;
+
+    for (i = 0; lists[i]; i++) {
+        config_parse_qdict_section(options, lists[i], &local_err);
+        if (error_is_set(&local_err)) {
Quoted 8 lines

util/qemu-config.c int qemu_read_config_file(const char *filename) · line 469

Quoted 6 lines
util/qemu-config.c +5 -0
+            error_propagate(errp, local_err);
+            return;
+        }
+    }
+}

This does the work, but also seems ad-hoc. Providing an array of dicts in the command line should be a general logic, which would also be very useful for Quorum driver.

Yes, I thought about quorum, too. I don't think just using QemuOpts there would be too bad, since the above function could do all the work there as well. I could probably introduce a QDict function which splits a QDict with keys enumerated in this way into a QList of QDicts. I'll have a look into how much more complex that will be and, depending on that, include it in v2 or not.

Thanks for reviewing,

Max

author
#6 lore raw

PATCH 4/6 blkdebug: Always call read_config()

In reply to Max Reitz

Move the check whether there actually is a config file into the read_config() function.

---
 block/blkdebug.c | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)
block/blkdebug.c +22 -20
index 59d33a8..8d52173 100644
@@ -273,23 +273,25 @@ static void remove_rule(BlkdebugRule *rule)
 
 static int read_config(BDRVBlkdebugState *s, const char *filename, Error **errp)
 {
-    FILE *f;
+    FILE *f = NULL;
     int ret;
     struct add_rule_data d;
 
-    f = fopen(filename, "r");
-    if (f == NULL) {
-        error_setg_errno(errp, errno, "Could not read blkdebug config file "
-                         "'%s'", filename);
-        return -errno;
-    }
+    if (filename) {
+        f = fopen(filename, "r");
+        if (f == NULL) {
+            error_setg_errno(errp, errno, "Could not read blkdebug config file "
+                             "'%s'", filename);
+            return -errno;
+        }
 
-    ret = qemu_config_parse(f, config_groups, filename);
-    if (ret < 0) {
-        error_setg(errp, "Could not parse blkdebug config file '%s'",
-                   filename);
-        ret = -EINVAL;
-        goto fail;
+        ret = qemu_config_parse(f, config_groups, filename);
+        if (ret < 0) {
+            error_setg(errp, "Could not parse blkdebug config file '%s'",
+                       filename);
+            ret = -EINVAL;
+            goto fail;
+        }
     }
 
     d.s = s;
@@ -303,7 +305,9 @@ static int read_config(BDRVBlkdebugState *s, const char *filename, Error **errp)
 fail:
     qemu_opts_reset(&inject_error_opts);
     qemu_opts_reset(&set_state_opts);
-    fclose(f);
+    if (f) {
+        fclose(f);
+    }
     return ret;
 }
 
@@ -376,12 +380,10 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
 
     /* Read rules from config file */
     config = qemu_opt_get(opts, "config");
-    if (config) {
-        ret = read_config(s, config, &local_err);
-        if (ret) {
-            error_propagate(errp, local_err);
-            goto fail;
-        }
+    ret = read_config(s, config, &local_err);
+    if (ret) {
+        error_propagate(errp, local_err);
+        goto fail;
     }
 
     /* Set initial state */
Signature · 1 line
1.8.4.2
author
#7 lore raw

PATCH 5/6 blkdebug: Use command-line in read_config()

In reply to Max Reitz

Use qemu_config_parse_qdict() to parse the command-line options in addition to the config file.

---
 block/blkdebug.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
block/blkdebug.c +12 -3
index 8d52173..5f94ee7 100644
@@ -271,11 +271,13 @@ static void remove_rule(BlkdebugRule *rule)
     g_free(rule);
 }
 
-static int read_config(BDRVBlkdebugState *s, const char *filename, Error **errp)
+static int read_config(BDRVBlkdebugState *s, const char *filename,
+                       QDict *options, Error **errp)
 {
     FILE *f = NULL;
     int ret;
     struct add_rule_data d;
+    Error *local_err = NULL;
 
     if (filename) {
         f = fopen(filename, "r");
@@ -294,6 +296,13 @@ static int read_config(BDRVBlkdebugState *s, const char *filename, Error **errp)
         }
     }
 
+    qemu_config_parse_qdict(options, config_groups, &local_err);
+    if (error_is_set(&local_err)) {
+        error_propagate(errp, local_err);
+        ret = -EINVAL;
+        goto fail;
+    }
+
     d.s = s;
     d.action = ACTION_INJECT_ERROR;
     qemu_opts_foreach(&inject_error_opts, add_rule, &d, 0);
@@ -378,9 +387,9 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
         goto fail;
     }
 
-    /* Read rules from config file */
+    /* Read rules from config file or command line options */
     config = qemu_opt_get(opts, "config");
-    ret = read_config(s, config, &local_err);
+    ret = read_config(s, config, options, &local_err);
     if (ret) {
         error_propagate(errp, local_err);
         goto fail;
Signature · 1 line
1.8.4.2
author
#8 lore raw

PATCH 6/6 blkverify: Don't require protocol filename

In reply to Max Reitz

If the filename is not prefixed by "blkverify:" in blkverify_parse_filename(), the blkverify driver was not selected through that protocol prefix, but by an explicit command line option (like file.driver=blkverify). Contrary to the current reaction, this is not really a problem; the whole filename just has to be stored (in the x-image option) and the user has to manually specify the x-raw option.

---
The x-raw option is undocumented and may be removed at any point in time; but I don't see a reason why this should happen. Passing the reference filename through an option maybe was a bit dirty in the past; but by “exposing” it in the way this patch does, it becomes probably the only clean solution.

The only problem I can see right now is the naming of the option, but we should always be able to leave it as an alias, if necessary.

---
 block/blkverify.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/blkverify.c +3 -1
index 3c63528..bdbdd68 100644
@@ -78,7 +78,9 @@ static void blkverify_parse_filename(const char *filename, QDict *options,
 
     /* Parse the blkverify: prefix */
     if (!strstart(filename, "blkverify:", &filename)) {
-        error_setg(errp, "File name string must start with 'blkverify:'");
+        /* There was no prefix; therefore, all options have to be already
+           present in the QDict (except for the filename) */
+        qdict_put(options, "x-image", qstring_from_str(filename));
         return;
     }
 
Signature · 1 line
1.8.4.2