* [Qemu-devel] [PATCH 1/4] qemu-option: Don't reinvent append_option_parameters()
2010-12-07 9:35 [Qemu-devel] [PATCH 0/4] qemu-img: Fail creation if backing format is invalid Stefan Hajnoczi
@ 2010-12-07 9:35 ` Stefan Hajnoczi
2010-12-07 9:35 ` [Qemu-devel] [PATCH 2/4] qemu-option: Fix parse_option_parameters() documentation typo Stefan Hajnoczi
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2010-12-07 9:35 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi
parse_option_parameters() may need to create a new option parameter list
from a template list. Use append_option_parameters() instead of
duplicating the code.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
qemu-option.c | 9 +--------
1 files changed, 1 insertions(+), 8 deletions(-)
diff --git a/qemu-option.c b/qemu-option.c
index 1f8f41a..e380fc1 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -416,20 +416,13 @@ QEMUOptionParameter *parse_option_parameters(const char *param,
char value[256];
char *param_delim, *value_delim;
char next_delim;
- size_t num_options;
if (list == NULL) {
return NULL;
}
if (dest == NULL) {
- // Count valid options
- num_options = count_option_parameters(list);
-
- // Create a copy of the option list to fill in values
- dest = qemu_mallocz((num_options + 1) * sizeof(QEMUOptionParameter));
- allocated = dest;
- memcpy(dest, list, (num_options + 1) * sizeof(QEMUOptionParameter));
+ dest = allocated = append_option_parameters(NULL, list);
}
while (*param) {
--
1.7.2.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 2/4] qemu-option: Fix parse_option_parameters() documentation typo
2010-12-07 9:35 [Qemu-devel] [PATCH 0/4] qemu-img: Fail creation if backing format is invalid Stefan Hajnoczi
2010-12-07 9:35 ` [Qemu-devel] [PATCH 1/4] qemu-option: Don't reinvent append_option_parameters() Stefan Hajnoczi
@ 2010-12-07 9:35 ` Stefan Hajnoczi
2010-12-07 9:35 ` [Qemu-devel] [PATCH 3/4] qemu-img: Free option parameter lists in img_create() Stefan Hajnoczi
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2010-12-07 9:35 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi
Yoda said, "list is the templace is". Fix this.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
qemu-option.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/qemu-option.c b/qemu-option.c
index e380fc1..65db542 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -394,8 +394,8 @@ QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
/*
* Parses a parameter string (param) into an option list (dest).
*
- * list is the templace is. If dest is NULL, a new copy of list is created for
- * it. If list is NULL, this function fails.
+ * list is the template option list. If dest is NULL, a new copy of list is
+ * created. If list is NULL, this function fails.
*
* A parameter string consists of one or more parameters, separated by commas.
* Each parameter consists of its name and possibly of a value. In the latter
--
1.7.2.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 3/4] qemu-img: Free option parameter lists in img_create()
2010-12-07 9:35 [Qemu-devel] [PATCH 0/4] qemu-img: Fail creation if backing format is invalid Stefan Hajnoczi
2010-12-07 9:35 ` [Qemu-devel] [PATCH 1/4] qemu-option: Don't reinvent append_option_parameters() Stefan Hajnoczi
2010-12-07 9:35 ` [Qemu-devel] [PATCH 2/4] qemu-option: Fix parse_option_parameters() documentation typo Stefan Hajnoczi
@ 2010-12-07 9:35 ` Stefan Hajnoczi
2010-12-07 9:35 ` [Qemu-devel] [PATCH 4/4] qemu-img: Fail creation if backing format is invalid Stefan Hajnoczi
2010-12-08 9:40 ` [Qemu-devel] Re: [PATCH 0/4] " Kevin Wolf
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2010-12-07 9:35 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi
Free option parameter lists in the img_create() error return path.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
qemu-img.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 5b6e648..23bb7dc 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -439,8 +439,6 @@ static int img_create(int argc, char **argv)
puts("");
ret = bdrv_create(drv, filename, param);
- free_option_parameters(create_options);
- free_option_parameters(param);
if (ret < 0) {
if (ret == -ENOTSUP) {
@@ -452,6 +450,8 @@ static int img_create(int argc, char **argv)
}
}
out:
+ free_option_parameters(create_options);
+ free_option_parameters(param);
if (ret) {
return 1;
}
--
1.7.2.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 4/4] qemu-img: Fail creation if backing format is invalid
2010-12-07 9:35 [Qemu-devel] [PATCH 0/4] qemu-img: Fail creation if backing format is invalid Stefan Hajnoczi
` (2 preceding siblings ...)
2010-12-07 9:35 ` [Qemu-devel] [PATCH 3/4] qemu-img: Free option parameter lists in img_create() Stefan Hajnoczi
@ 2010-12-07 9:35 ` Stefan Hajnoczi
2010-12-08 9:40 ` [Qemu-devel] Re: [PATCH 0/4] " Kevin Wolf
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2010-12-07 9:35 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi
The qemu-img create command should check the backing format to ensure
only image files with valid backing formats are created. By checking in
qemu-img.c we can print a useful error message.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
qemu-img.c | 22 ++++++++++++----------
1 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 23bb7dc..b10f363 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -300,6 +300,7 @@ static int img_create(int argc, char **argv)
const char *base_filename = NULL;
BlockDriver *drv, *proto_drv;
QEMUOptionParameter *param = NULL, *create_options = NULL;
+ QEMUOptionParameter *backing_fmt = NULL;
char *options = NULL;
flags = 0;
@@ -390,14 +391,22 @@ static int img_create(int argc, char **argv)
goto out;
}
+ backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT);
+ if (backing_fmt && backing_fmt->value.s) {
+ if (!bdrv_find_format(backing_fmt->value.s)) {
+ error("Unknown backing file format '%s'",
+ backing_fmt->value.s);
+ ret = -1;
+ goto out;
+ }
+ }
+
// The size for the image must always be specified, with one exception:
// If we are using a backing file, we can obtain the size from there
if (get_option_parameter(param, BLOCK_OPT_SIZE)->value.n == -1) {
QEMUOptionParameter *backing_file =
get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
- QEMUOptionParameter *backing_fmt =
- get_option_parameter(param, BLOCK_OPT_BACKING_FMT);
if (backing_file && backing_file->value.s) {
BlockDriverState *bs;
@@ -406,14 +415,7 @@ static int img_create(int argc, char **argv)
char buf[32];
if (backing_fmt && backing_fmt->value.s) {
- if (bdrv_find_format(backing_fmt->value.s)) {
- fmt = backing_fmt->value.s;
- } else {
- error("Unknown backing file format '%s'",
- backing_fmt->value.s);
- ret = -1;
- goto out;
- }
+ fmt = backing_fmt->value.s;
}
bs = bdrv_new_open(backing_file->value.s, fmt, BDRV_O_FLAGS);
--
1.7.2.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] Re: [PATCH 0/4] qemu-img: Fail creation if backing format is invalid
2010-12-07 9:35 [Qemu-devel] [PATCH 0/4] qemu-img: Fail creation if backing format is invalid Stefan Hajnoczi
` (3 preceding siblings ...)
2010-12-07 9:35 ` [Qemu-devel] [PATCH 4/4] qemu-img: Fail creation if backing format is invalid Stefan Hajnoczi
@ 2010-12-08 9:40 ` Kevin Wolf
4 siblings, 0 replies; 6+ messages in thread
From: Kevin Wolf @ 2010-12-08 9:40 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: qemu-devel
Am 07.12.2010 10:35, schrieb Stefan Hajnoczi:
> This patch series adds a check to validate the backing format before creating
> an image file. This ensures we provide a clear error message as early as
> possible when an unsupported format is used.
>
> The first three patches clean up code on the way and the last patch makes the
> actual backing format validation change.
Thanks, applied all to the block branch.
Kevin
^ permalink raw reply [flat|nested] 6+ messages in thread