diff mbox

[v3] mirror: Check for bdrv_get_info result

Message ID 1398758005-11098-1-git-send-email-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng April 29, 2014, 7:53 a.m. UTC
bdrv_get_info could fail. Add check before using the returned value.

Signed-off-by: Fam Zheng <famz@redhat.com>

---
v3: Don't leak things, jump to immediate_exit. (Kevin)

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/mirror.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Kevin Wolf April 29, 2014, 9:47 a.m. UTC | #1
Am 29.04.2014 um 09:53 hat Fam Zheng geschrieben:
> bdrv_get_info could fail. Add check before using the returned value.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> 
> ---
> v3: Don't leak things, jump to immediate_exit. (Kevin)
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/mirror.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/block/mirror.c b/block/mirror.c
> index 2618c37..fbea051 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -339,7 +339,11 @@ static void coroutine_fn mirror_run(void *opaque)
>      bdrv_get_backing_filename(s->target, backing_filename,
>                                sizeof(backing_filename));
>      if (backing_filename[0] && !s->target->backing_hd) {
> -        bdrv_get_info(s->target, &bdi);
> +        ret = bdrv_get_info(s->target, &bdi);
> +        if (ret < 0) {
> +            block_job_completed(&s->common, ret);
> +            goto immediate_exit;

Now block_job_completed() gets called twice.

> +        }
>          if (s->granularity < bdi.cluster_size) {
>              s->buf_size = MAX(s->buf_size, bdi.cluster_size);
>              s->cow_bitmap = bitmap_new(length);

Kevin
diff mbox

Patch

diff --git a/block/mirror.c b/block/mirror.c
index 2618c37..fbea051 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -339,7 +339,11 @@  static void coroutine_fn mirror_run(void *opaque)
     bdrv_get_backing_filename(s->target, backing_filename,
                               sizeof(backing_filename));
     if (backing_filename[0] && !s->target->backing_hd) {
-        bdrv_get_info(s->target, &bdi);
+        ret = bdrv_get_info(s->target, &bdi);
+        if (ret < 0) {
+            block_job_completed(&s->common, ret);
+            goto immediate_exit;
+        }
         if (s->granularity < bdi.cluster_size) {
             s->buf_size = MAX(s->buf_size, bdi.cluster_size);
             s->cow_bitmap = bitmap_new(length);