Commit d663640c authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Stefan Hajnoczi
Browse files

block: expect errors from bdrv_co_is_allocated



Some bdrv_is_allocated callers do not expect errors, but the fallback
in qcow2.c might make other callers trip on assertion failures or
infinite loops.

Fix the callers to always look for errors.

Cc: qemu-stable@nongnu.org
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent 4f578637
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -1857,8 +1857,11 @@ int bdrv_commit(BlockDriverState *bs)
    buf = g_malloc(COMMIT_BUF_SECTORS * BDRV_SECTOR_SIZE);

    for (sector = 0; sector < total_sectors; sector += n) {
        if (bdrv_is_allocated(bs, sector, COMMIT_BUF_SECTORS, &n)) {

        ret = bdrv_is_allocated(bs, sector, COMMIT_BUF_SECTORS, &n);
        if (ret < 0) {
            goto ro_cleanup;
        }
        if (ret) {
            if (bdrv_read(bs, sector, buf, n) != 0) {
                ret = -EIO;
                goto ro_cleanup;
+5 −1
Original line number Diff line number Diff line
@@ -212,7 +212,11 @@ static int coroutine_fn cow_read(BlockDriverState *bs, int64_t sector_num,
    int ret, n;

    while (nb_sectors > 0) {
        if (cow_co_is_allocated(bs, sector_num, nb_sectors, &n)) {
        ret = cow_co_is_allocated(bs, sector_num, nb_sectors, &n);
        if (ret < 0) {
            return ret;
        }
        if (ret) {
            ret = bdrv_pread(bs->file,
                        s->cow_sectors_offset + sector_num * 512,
                        buf, n * 512);
+1 −3
Original line number Diff line number Diff line
@@ -696,13 +696,11 @@ static int coroutine_fn qcow2_co_is_allocated(BlockDriverState *bs,
    int ret;

    *pnum = nb_sectors;
    /* FIXME We can get errors here, but the bdrv_co_is_allocated interface
     * can't pass them on today */
    qemu_co_mutex_lock(&s->lock);
    ret = qcow2_get_cluster_offset(bs, sector_num << 9, pnum, &cluster_offset);
    qemu_co_mutex_unlock(&s->lock);
    if (ret < 0) {
        *pnum = 0;
        return ret;
    }

    return (cluster_offset != 0) || (ret == QCOW2_CLUSTER_ZERO);
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ wait:
        if (ret == 1) {
            /* Allocated in the top, no need to copy.  */
            copy = false;
        } else {
        } else if (ret >= 0) {
            /* Copy if allocated in the intermediate images.  Limit to the
             * known-unallocated area [sector_num, sector_num+n).  */
            ret = bdrv_is_allocated_above(bs->backing_hd, base,
+14 −2
Original line number Diff line number Diff line
@@ -1508,8 +1508,15 @@ static int img_convert(int argc, char **argv)
                   are present in both the output's and input's base images (no
                   need to copy them). */
                if (out_baseimg) {
                    if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset,
                                           n, &n1)) {
                    ret = bdrv_is_allocated(bs[bs_i], sector_num - bs_offset,
                                            n, &n1);
                    if (ret < 0) {
                        error_report("error while reading metadata for sector "
                                     "%" PRId64 ": %s",
                                     sector_num - bs_offset, strerror(-ret));
                        goto out;
                    }
                    if (!ret) {
                        sector_num += n1;
                        continue;
                    }
@@ -2099,6 +2106,11 @@ static int img_rebase(int argc, char **argv)

            /* If the cluster is allocated, we don't need to take action */
            ret = bdrv_is_allocated(bs, sector, n, &n);
            if (ret < 0) {
                error_report("error while reading image metadata: %s",
                             strerror(-ret));
                goto out;
            }
            if (ret) {
                continue;
            }
Loading