Commit 7b8e4857 authored by Kevin Wolf's avatar Kevin Wolf
Browse files

block: Add flags to bdrv(_co)_truncate()



Now that block drivers can support flags for .bdrv_co_truncate, expose
the parameter in the node level interfaces bdrv_co_truncate() and
bdrv_truncate().

Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: default avatarAlberto Garcia <berto@igalia.com>
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
Message-Id: <20200424125448.63318-3-kwolf@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent 92b92799
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2144,7 +2144,7 @@ int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
        return -ENOMEDIUM;
    }

    return bdrv_truncate(blk->root, offset, exact, prealloc, errp);
    return bdrv_truncate(blk->root, offset, exact, prealloc, 0, errp);
}

int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
+1 −1
Original line number Diff line number Diff line
@@ -313,7 +313,7 @@ block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,

    offset += payload_offset;

    return bdrv_co_truncate(bs->file, offset, exact, prealloc, errp);
    return bdrv_co_truncate(bs->file, offset, exact, prealloc, 0, errp);
}

static void block_crypto_close(BlockDriverState *bs)
+7 −5
Original line number Diff line number Diff line
@@ -3339,12 +3339,12 @@ static void bdrv_parent_cb_resize(BlockDriverState *bs)
 * 'offset' bytes in length.
 */
int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
                                  PreallocMode prealloc, Error **errp)
                                  PreallocMode prealloc, BdrvRequestFlags flags,
                                  Error **errp)
{
    BlockDriverState *bs = child->bs;
    BlockDriver *drv = bs->drv;
    BdrvTrackedRequest req;
    BdrvRequestFlags flags = 0;
    int64_t old_size, new_bytes;
    int ret;

@@ -3402,7 +3402,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
        }
        ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, flags, errp);
    } else if (bs->file && drv->is_filter) {
        ret = bdrv_co_truncate(bs->file, offset, exact, prealloc, errp);
        ret = bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, errp);
    } else {
        error_setg(errp, "Image format driver does not support resize");
        ret = -ENOTSUP;
@@ -3435,6 +3435,7 @@ typedef struct TruncateCo {
    int64_t offset;
    bool exact;
    PreallocMode prealloc;
    BdrvRequestFlags flags;
    Error **errp;
    int ret;
} TruncateCo;
@@ -3443,12 +3444,12 @@ static void coroutine_fn bdrv_truncate_co_entry(void *opaque)
{
    TruncateCo *tco = opaque;
    tco->ret = bdrv_co_truncate(tco->child, tco->offset, tco->exact,
                                tco->prealloc, tco->errp);
                                tco->prealloc, tco->flags, tco->errp);
    aio_wait_kick();
}

int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact,
                  PreallocMode prealloc, Error **errp)
                  PreallocMode prealloc, BdrvRequestFlags flags, Error **errp)
{
    Coroutine *co;
    TruncateCo tco = {
@@ -3456,6 +3457,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact,
        .offset     = offset,
        .exact      = exact,
        .prealloc   = prealloc,
        .flags      = flags,
        .errp       = errp,
        .ret        = NOT_DONE,
    };
+3 −3
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
        } else {
            ret = bdrv_truncate(bs->file,
                                (s->data_end + space) << BDRV_SECTOR_BITS,
                                false, PREALLOC_MODE_OFF, NULL);
                                false, PREALLOC_MODE_OFF, 0, NULL);
        }
        if (ret < 0) {
            return ret;
@@ -493,7 +493,7 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs,
             * That means we have to pass exact=true.
             */
            ret = bdrv_truncate(bs->file, res->image_end_offset, true,
                                PREALLOC_MODE_OFF, &local_err);
                                PREALLOC_MODE_OFF, 0, &local_err);
            if (ret < 0) {
                error_report_err(local_err);
                res->check_errors++;
@@ -889,7 +889,7 @@ static void parallels_close(BlockDriverState *bs)

        /* errors are ignored, so we might as well pass exact=true */
        bdrv_truncate(bs->file, s->data_end << BDRV_SECTOR_BITS, true,
                      PREALLOC_MODE_OFF, NULL);
                      PREALLOC_MODE_OFF, 0, NULL);
    }

    g_free(s->bat_dirty_bmap);
+2 −2
Original line number Diff line number Diff line
@@ -480,7 +480,7 @@ static int get_cluster_offset(BlockDriverState *bs,
                    return -E2BIG;
                }
                ret = bdrv_truncate(bs->file, cluster_offset + s->cluster_size,
                                    false, PREALLOC_MODE_OFF, NULL);
                                    false, PREALLOC_MODE_OFF, 0, NULL);
                if (ret < 0) {
                    return ret;
                }
@@ -1035,7 +1035,7 @@ static int qcow_make_empty(BlockDriverState *bs)
            l1_length) < 0)
        return -1;
    ret = bdrv_truncate(bs->file, s->l1_table_offset + l1_length, false,
                        PREALLOC_MODE_OFF, NULL);
                        PREALLOC_MODE_OFF, 0, NULL);
    if (ret < 0)
        return ret;

Loading