Commit 9f1b92ad authored by Vladimir Sementsov-Ogievskiy's avatar Vladimir Sementsov-Ogievskiy Committed by Max Reitz
Browse files

qemu-img: improve convert_iteration_sectors()



Do not do extra call to _get_block_status()

Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20170407113404.9351-1-vsementsov@virtuozzo.com
Reviewed-by: default avatarJohn Snow <jsnow@redhat.com>
Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
parent 504c205a
Loading
Loading
Loading
Loading
+10 −22
Original line number Diff line number Diff line
@@ -1554,37 +1554,25 @@ static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num)

    if (s->sector_next_status <= sector_num) {
        BlockDriverState *file;
        if (s->target_has_backing) {
            ret = bdrv_get_block_status(blk_bs(s->src[src_cur]),
                                        sector_num - src_cur_offset,
                                        n, &n, &file);
        if (ret < 0) {
            return ret;
        }

        if (ret & BDRV_BLOCK_ZERO) {
            s->status = BLK_ZERO;
        } else if (ret & BDRV_BLOCK_DATA) {
            s->status = BLK_DATA;
        } else if (!s->target_has_backing) {
            /* Without a target backing file we must copy over the contents of
             * the backing file as well. */
            /* Check block status of the backing file chain to avoid
             * needlessly reading zeroes and limiting the iteration to the
             * buffer size */
        } else {
            ret = bdrv_get_block_status_above(blk_bs(s->src[src_cur]), NULL,
                                              sector_num - src_cur_offset,
                                              n, &n, &file);
        }
        if (ret < 0) {
            return ret;
        }

        if (ret & BDRV_BLOCK_ZERO) {
            s->status = BLK_ZERO;
            } else {
        } else if (ret & BDRV_BLOCK_DATA) {
            s->status = BLK_DATA;
            }
        } else {
            s->status = BLK_BACKING_FILE;
            s->status = s->target_has_backing ? BLK_BACKING_FILE : BLK_DATA;
        }

        s->sector_next_status = sector_num + n;