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,
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)
* '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;
}
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;
int64_t offset;
bool exact;
PreallocMode prealloc;
+ BdrvRequestFlags flags;
Error **errp;
int ret;
} TruncateCo;
{
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 = {
.offset = offset,
.exact = exact,
.prealloc = prealloc,
+ .flags = flags,
.errp = errp,
.ret = NOT_DONE,
};
} 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;
* 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++;
/* 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);
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;
}
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;
}
ret = bdrv_truncate(bs->file, offset + s->cluster_size, false,
- PREALLOC_MODE_OFF, &local_err);
+ PREALLOC_MODE_OFF, 0, &local_err);
if (ret < 0) {
error_report_err(local_err);
goto resize_fail;
mode = PREALLOC_MODE_OFF;
}
ret = bdrv_co_truncate(s->data_file, host_offset + cur_bytes, false,
- mode, errp);
+ mode, 0, errp);
if (ret < 0) {
return ret;
}
* always fulfilled, so there is no need to pass it on.)
*/
bdrv_co_truncate(bs->file, (last_cluster + 1) * s->cluster_size,
- false, PREALLOC_MODE_OFF, &local_err);
+ false, PREALLOC_MODE_OFF, 0, &local_err);
if (local_err) {
warn_reportf_err(local_err,
"Failed to truncate the tail of the image: ");
* file should be resized to the exact target size, too,
* so we pass @exact here.
*/
- ret = bdrv_co_truncate(s->data_file, offset, exact, prealloc, errp);
+ ret = bdrv_co_truncate(s->data_file, offset, exact, prealloc, 0,
+ errp);
if (ret < 0) {
goto fail;
}
new_file_size = allocation_start +
nb_new_data_clusters * s->cluster_size;
/* Image file grows, so @exact does not matter */
- ret = bdrv_co_truncate(bs->file, new_file_size, false, prealloc, errp);
+ ret = bdrv_co_truncate(bs->file, new_file_size, false, prealloc, 0,
+ errp);
if (ret < 0) {
error_prepend(errp, "Failed to resize underlying file: ");
qcow2_free_clusters(bs, allocation_start,
if (len < 0) {
return len;
}
- return bdrv_co_truncate(bs->file, len, false, PREALLOC_MODE_OFF, NULL);
+ return bdrv_co_truncate(bs->file, len, false, PREALLOC_MODE_OFF, 0,
+ NULL);
}
if (offset_into_cluster(s, offset)) {
}
ret = bdrv_truncate(bs->file, (3 + l1_clusters) * s->cluster_size, false,
- PREALLOC_MODE_OFF, &local_err);
+ PREALLOC_MODE_OFF, 0, &local_err);
if (ret < 0) {
error_report_err(local_err);
goto fail;
s->size = offset;
offset += s->offset;
- return bdrv_co_truncate(bs->file, offset, exact, prealloc, errp);
+ return bdrv_co_truncate(bs->file, offset, exact, prealloc, 0, errp);
}
static void raw_eject(BlockDriverState *bs, bool eject_flag)
goto exit;
}
ret = bdrv_truncate(bs->file, new_file_size, false,
- PREALLOC_MODE_OFF, NULL);
+ PREALLOC_MODE_OFF, 0, NULL);
if (ret < 0) {
goto exit;
}
}
return bdrv_truncate(bs->file, *new_offset + s->block_size, false,
- PREALLOC_MODE_OFF, NULL);
+ PREALLOC_MODE_OFF, 0, NULL);
}
/*
}
length = QEMU_ALIGN_UP(length, BDRV_SECTOR_SIZE);
ret = bdrv_truncate(s->extents[i].file, length, false,
- PREALLOC_MODE_OFF, NULL);
+ PREALLOC_MODE_OFF, 0, NULL);
if (ret < 0) {
return ret;
}
void bdrv_refresh_filename(BlockDriverState *bs);
int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
- PreallocMode prealloc, Error **errp);
+ PreallocMode prealloc, BdrvRequestFlags flags,
+ Error **errp);
int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact,
- PreallocMode prealloc, Error **errp);
+ PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
int64_t bdrv_nb_sectors(BlockDriverState *bs);
int64_t bdrv_getlength(BlockDriverState *bs);
int ret;
/* Normal success path */
- ret = bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, NULL);
+ ret = bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, 0, NULL);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
- ret = bdrv_truncate(c, -2, false, PREALLOC_MODE_OFF, NULL);
+ ret = bdrv_truncate(c, -2, false, PREALLOC_MODE_OFF, 0, NULL);
g_assert_cmpint(ret, ==, -EINVAL);
/* Error: Read-only image */
c->bs->read_only = true;
c->bs->open_flags &= ~BDRV_O_RDWR;
- ret = bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, NULL);
+ ret = bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, 0, NULL);
g_assert_cmpint(ret, ==, -EACCES);
c->bs->read_only = false;