Commit 8243ccb7 authored by Max Reitz's avatar Max Reitz
Browse files

block: Add PreallocMode to BD.bdrv_truncate()



Add a PreallocMode parameter to the bdrv_truncate() function implemented
by each block driver. Currently, we always pass PREALLOC_MODE_OFF and no
driver accepts anything else.

Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Message-id: 20170613202107.10125-2-mreitz@redhat.com
Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
parent 32a1681a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3434,7 +3434,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)

    assert(!(bs->open_flags & BDRV_O_INACTIVE));

    ret = drv->bdrv_truncate(bs, offset, errp);
    ret = drv->bdrv_truncate(bs, offset, PREALLOC_MODE_OFF, errp);
    if (ret == 0) {
        ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);
        bdrv_dirty_bitmap_truncate(bs);
+8 −1
Original line number Diff line number Diff line
@@ -821,8 +821,15 @@ static int64_t blkdebug_getlength(BlockDriverState *bs)
    return bdrv_getlength(bs->file->bs);
}

static int blkdebug_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
static int blkdebug_truncate(BlockDriverState *bs, int64_t offset,
                             PreallocMode prealloc, Error **errp)
{
    if (prealloc != PREALLOC_MODE_OFF) {
        error_setg(errp, "Unsupported preallocation mode '%s'",
                   PreallocMode_lookup[prealloc]);
        return -ENOTSUP;
    }

    return bdrv_truncate(bs->file, offset, errp);
}

+7 −1
Original line number Diff line number Diff line
@@ -361,12 +361,18 @@ static int block_crypto_create_generic(QCryptoBlockFormat format,
}

static int block_crypto_truncate(BlockDriverState *bs, int64_t offset,
                                 Error **errp)
                                 PreallocMode prealloc, Error **errp)
{
    BlockCrypto *crypto = bs->opaque;
    size_t payload_offset =
        qcrypto_block_get_payload_offset(crypto->block);

    if (prealloc != PREALLOC_MODE_OFF) {
        error_setg(errp, "Unsupported preallocation mode '%s'",
                   PreallocMode_lookup[prealloc]);
        return -ENOTSUP;
    }

    offset += payload_offset;

    return bdrv_truncate(bs->file, offset, errp);
+8 −1
Original line number Diff line number Diff line
@@ -1624,12 +1624,19 @@ static void raw_close(BlockDriverState *bs)
    }
}

static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
static int raw_truncate(BlockDriverState *bs, int64_t offset,
                        PreallocMode prealloc, Error **errp)
{
    BDRVRawState *s = bs->opaque;
    struct stat st;
    int ret;

    if (prealloc != PREALLOC_MODE_OFF) {
        error_setg(errp, "Unsupported preallocation mode '%s'",
                   PreallocMode_lookup[prealloc]);
        return -ENOTSUP;
    }

    if (fstat(s->fd, &st)) {
        ret = -errno;
        error_setg_errno(errp, -ret, "Failed to fstat() the file");
+8 −1
Original line number Diff line number Diff line
@@ -461,12 +461,19 @@ static void raw_close(BlockDriverState *bs)
    }
}

static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
static int raw_truncate(BlockDriverState *bs, int64_t offset,
                        PreallocMode prealloc, Error **errp)
{
    BDRVRawState *s = bs->opaque;
    LONG low, high;
    DWORD dwPtrLow;

    if (prealloc != PREALLOC_MODE_OFF) {
        error_setg(errp, "Unsupported preallocation mode '%s'",
                   PreallocMode_lookup[prealloc]);
        return -ENOTSUP;
    }

    low = offset;
    high = offset >> 32;

Loading