Message ID | 1381988203-28576-2-git-send-email-famz@redhat.com |
---|---|
State | New |
Headers | show |
On Thu, 10/17 13:36, Fam Zheng wrote: > Signed-off-by: Fam Zheng <famz@redhat.com> > --- > block.c | 27 ++++++++++++++++++++++----- > 1 file changed, 22 insertions(+), 5 deletions(-) > > diff --git a/block.c b/block.c > index fd05a80..38b3e80 100644 > --- a/block.c > +++ b/block.c > @@ -1158,11 +1158,28 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, > /* If there is a backing file, use it */ > if ((flags & BDRV_O_NO_BACKING) == 0) { > QDict *backing_options; > - > - qdict_extract_subqdict(options, &backing_options, "backing."); > - ret = bdrv_open_backing_file(bs, backing_options, &local_err); > - if (ret < 0) { > - goto close_and_fail; > + const char *backing_bs; > + > + backing_bs = qdict_get_try_str(options, "backing"); > + if (backing_bs) { > + bs->backing_hd = bdrv_find(backing_bs); > + bdrv_ref(bs->backing_hd); This should be moved down into if. Fam > + qdict_del(options, "backing"); > + if (bs->backing_hd) { > + pstrcpy(bs->backing_file, sizeof(bs->backing_file), > + bs->backing_hd->filename); > + pstrcpy(bs->backing_format, sizeof(bs->backing_format), > + bs->backing_hd->drv->format_name); > + } else { > + error_setg(errp, "Backing device not found: %s", backing_bs); > + goto close_and_fail; > + } > + } else { > + qdict_extract_subqdict(options, &backing_options, "backing."); > + ret = bdrv_open_backing_file(bs, backing_options, &local_err); > + if (ret < 0) { > + goto close_and_fail; > + } > } > } > > -- > 1.8.3.1 > >
diff --git a/block.c b/block.c index fd05a80..38b3e80 100644 --- a/block.c +++ b/block.c @@ -1158,11 +1158,28 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, /* If there is a backing file, use it */ if ((flags & BDRV_O_NO_BACKING) == 0) { QDict *backing_options; - - qdict_extract_subqdict(options, &backing_options, "backing."); - ret = bdrv_open_backing_file(bs, backing_options, &local_err); - if (ret < 0) { - goto close_and_fail; + const char *backing_bs; + + backing_bs = qdict_get_try_str(options, "backing"); + if (backing_bs) { + bs->backing_hd = bdrv_find(backing_bs); + bdrv_ref(bs->backing_hd); + qdict_del(options, "backing"); + if (bs->backing_hd) { + pstrcpy(bs->backing_file, sizeof(bs->backing_file), + bs->backing_hd->filename); + pstrcpy(bs->backing_format, sizeof(bs->backing_format), + bs->backing_hd->drv->format_name); + } else { + error_setg(errp, "Backing device not found: %s", backing_bs); + goto close_and_fail; + } + } else { + qdict_extract_subqdict(options, &backing_options, "backing."); + ret = bdrv_open_backing_file(bs, backing_options, &local_err); + if (ret < 0) { + goto close_and_fail; + } } }
Signed-off-by: Fam Zheng <famz@redhat.com> --- block.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)