Message ID | 1384310380-9805-3-git-send-email-gesaint@linux.vnet.ibm.com |
---|---|
State | New |
Headers | show |
On 2013年11月13日 10:39, Xu Wang wrote: > Backing file loop should be checked before qemu-img create command > execution. If loop is found, qemu-img create should be stopped and > an error printed. > > Signed-off-by: Xu Wang <gesaint@linux.vnet.ibm.com> > --- > block.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/block.c b/block.c > index 3c43179..c2ed6ef 100644 > --- a/block.c > +++ b/block.c > @@ -4629,15 +4629,16 @@ void bdrv_img_create(const char *filename, const char *fmt, > } > > backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE); > + backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT); > if (backing_file && backing_file->value.s) { > - if (!strcmp(filename, backing_file->value.s)) { > - error_setg(errp, "Error: Trying to create an image with the " > - "same filename as the backing file"); > + if (!bdrv_backing_chain_okay(backing_file->value.s, > + backing_fmt->value.s, filename)) { > + error_setg(errp, "bdrv_img_create: loop exists, " > + "image create failed"); Another failure path in file_chain_has_loop() is when bdrv_open fails, which is not a backing chain loop. What if the backing file doesn't exist? Would the error message still mention "look exits", which is very confusing? Fam > goto out; > } > } > > - backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT); > if (backing_fmt && backing_fmt->value.s) { > backing_drv = bdrv_find_format(backing_fmt->value.s); > if (!backing_drv) { >
On 2013年11月13日 14:32, Fam Zheng wrote: > On 2013年11月13日 10:39, Xu Wang wrote: >> Backing file loop should be checked before qemu-img create command >> execution. If loop is found, qemu-img create should be stopped and >> an error printed. >> >> Signed-off-by: Xu Wang <gesaint@linux.vnet.ibm.com> >> --- >> block.c | 9 +++++---- >> 1 file changed, 5 insertions(+), 4 deletions(-) >> >> diff --git a/block.c b/block.c >> index 3c43179..c2ed6ef 100644 >> --- a/block.c >> +++ b/block.c >> @@ -4629,15 +4629,16 @@ void bdrv_img_create(const char *filename, >> const char *fmt, >> } >> >> backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE); >> + backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT); >> if (backing_file && backing_file->value.s) { >> - if (!strcmp(filename, backing_file->value.s)) { >> - error_setg(errp, "Error: Trying to create an image with >> the " >> - "same filename as the backing file"); >> + if (!bdrv_backing_chain_okay(backing_file->value.s, >> + backing_fmt->value.s, filename)) { >> + error_setg(errp, "bdrv_img_create: loop exists, " >> + "image create failed"); > > Another failure path in file_chain_has_loop() is when bdrv_open fails, > which is not a backing chain loop. What if the backing file doesn't > exist? Would the error message still mention "look exits", which is very > confusing? s/look/loop/ Fam > > Fam > >> goto out; >> } >> } >> >> - backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT); >> if (backing_fmt && backing_fmt->value.s) { >> backing_drv = bdrv_find_format(backing_fmt->value.s); >> if (!backing_drv) { >> > >
diff --git a/block.c b/block.c index 3c43179..c2ed6ef 100644 --- a/block.c +++ b/block.c @@ -4629,15 +4629,16 @@ void bdrv_img_create(const char *filename, const char *fmt, } backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE); + backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT); if (backing_file && backing_file->value.s) { - if (!strcmp(filename, backing_file->value.s)) { - error_setg(errp, "Error: Trying to create an image with the " - "same filename as the backing file"); + if (!bdrv_backing_chain_okay(backing_file->value.s, + backing_fmt->value.s, filename)) { + error_setg(errp, "bdrv_img_create: loop exists, " + "image create failed"); goto out; } } - backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT); if (backing_fmt && backing_fmt->value.s) { backing_drv = bdrv_find_format(backing_fmt->value.s); if (!backing_drv) {
Backing file loop should be checked before qemu-img create command execution. If loop is found, qemu-img create should be stopped and an error printed. Signed-off-by: Xu Wang <gesaint@linux.vnet.ibm.com> --- block.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)