Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into s…
Browse files Browse the repository at this point in the history
…taging

Block layer patches:

- Fix resize (extending) of short overlays
- nvme: introduce PMR support from NVMe 1.4 spec
- qemu-storage-daemon: Fix non-string --object properties

# gpg: Signature made Thu 30 Apr 2020 16:51:45 BST
# gpg:                using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6
# gpg:                issuer "kwolf@redhat.com"
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full]
# Primary key fingerprint: DC3D EB15 9A9A F95D 3D74  56FE 7F09 B272 C88F 2FD6

* remotes/kevin/tags/for-upstream:
  qemu-storage-daemon: Fix non-string --object properties
  qom: Factor out user_creatable_add_dict()
  nvme: introduce PMR support from NVMe 1.4 spec
  qcow2: Forward ZERO_WRITE flag for full preallocation
  iotests: Test committing to short backing file
  iotests: Filter testfiles out in filter_img_info()
  block: truncate: Don't make backing file data visible
  file-posix: Support BDRV_REQ_ZERO_WRITE for truncate
  raw-format: Support BDRV_REQ_ZERO_WRITE for truncate
  qcow2: Support BDRV_REQ_ZERO_WRITE for truncate
  block-backend: Add flags to blk_truncate()
  block: Add flags to bdrv(_co)_truncate()
  block: Add flags to BlockDriver.bdrv_co_truncate()
  qemu-iotests: allow qcow2 external discarded clusters to contain stale data
  qcow2: Add incompatibility note between backing files and raw external data files

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Apr 30, 2020
2 parents 27c9456 + eaae29e commit 1c47613
Show file tree
Hide file tree
Showing 49 changed files with 951 additions and 96 deletions.
3 changes: 2 additions & 1 deletion block.c
Expand Up @@ -548,7 +548,8 @@ static int64_t create_file_fallback_truncate(BlockBackend *blk,
int64_t size;
int ret;

ret = blk_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, &local_err);
ret = blk_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, 0,
&local_err);
if (ret < 0 && ret != -ENOTSUP) {
error_propagate(errp, local_err);
return ret;
Expand Down
4 changes: 2 additions & 2 deletions block/block-backend.c
Expand Up @@ -2137,14 +2137,14 @@ int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf,
}

int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
PreallocMode prealloc, Error **errp)
PreallocMode prealloc, BdrvRequestFlags flags, Error **errp)
{
if (!blk_is_available(blk)) {
error_setg(errp, "No medium inserted");
return -ENOMEDIUM;
}

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

int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
Expand Down
4 changes: 2 additions & 2 deletions block/commit.c
Expand Up @@ -133,7 +133,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
}

if (base_len < len) {
ret = blk_truncate(s->base, len, false, PREALLOC_MODE_OFF, NULL);
ret = blk_truncate(s->base, len, false, PREALLOC_MODE_OFF, 0, NULL);
if (ret) {
goto out;
}
Expand Down Expand Up @@ -458,7 +458,7 @@ int bdrv_commit(BlockDriverState *bs)
* grow the backing file image if possible. If not possible,
* we must return an error */
if (length > backing_length) {
ret = blk_truncate(backing, length, false, PREALLOC_MODE_OFF,
ret = blk_truncate(backing, length, false, PREALLOC_MODE_OFF, 0,
&local_err);
if (ret < 0) {
error_report_err(local_err);
Expand Down
7 changes: 4 additions & 3 deletions block/crypto.c
Expand Up @@ -115,7 +115,7 @@ static ssize_t block_crypto_init_func(QCryptoBlock *block,
* which will be used by the crypto header
*/
return blk_truncate(data->blk, data->size + headerlen, false,
data->prealloc, errp);
data->prealloc, 0, errp);
}


Expand Down Expand Up @@ -299,7 +299,8 @@ static int block_crypto_co_create_generic(BlockDriverState *bs,

static int coroutine_fn
block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
PreallocMode prealloc, Error **errp)
PreallocMode prealloc, BdrvRequestFlags flags,
Error **errp)
{
BlockCrypto *crypto = bs->opaque;
uint64_t payload_offset =
Expand All @@ -312,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)
Expand Down
6 changes: 5 additions & 1 deletion block/file-posix.c
Expand Up @@ -702,6 +702,10 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
#endif

bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK;
if (S_ISREG(st.st_mode)) {
/* When extending regular files, we get zeros from the OS */
bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE;
}
ret = 0;
fail:
if (filename && (bdrv_flags & BDRV_O_TEMPORARY)) {
Expand Down Expand Up @@ -2080,7 +2084,7 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset,

static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
bool exact, PreallocMode prealloc,
Error **errp)
BdrvRequestFlags flags, Error **errp)
{
BDRVRawState *s = bs->opaque;
struct stat st;
Expand Down
2 changes: 1 addition & 1 deletion block/file-win32.c
Expand Up @@ -469,7 +469,7 @@ static void raw_close(BlockDriverState *bs)

static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
bool exact, PreallocMode prealloc,
Error **errp)
BdrvRequestFlags flags, Error **errp)
{
BDRVRawState *s = bs->opaque;
LONG low, high;
Expand Down
1 change: 1 addition & 0 deletions block/gluster.c
Expand Up @@ -1228,6 +1228,7 @@ static coroutine_fn int qemu_gluster_co_truncate(BlockDriverState *bs,
int64_t offset,
bool exact,
PreallocMode prealloc,
BdrvRequestFlags flags,
Error **errp)
{
BDRVGlusterState *s = bs->opaque;
Expand Down
43 changes: 38 additions & 5 deletions block/io.c
Expand Up @@ -3339,7 +3339,8 @@ 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;
Expand Down Expand Up @@ -3393,10 +3394,40 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
goto out;
}

/*
* If the image has a backing file that is large enough that it would
* provide data for the new area, we cannot leave it unallocated because
* then the backing file content would become visible. Instead, zero-fill
* the new area.
*
* Note that if the image has a backing file, but was opened without the
* backing file, taking care of keeping things consistent with that backing
* file is the user's responsibility.
*/
if (new_bytes && bs->backing) {
int64_t backing_len;

backing_len = bdrv_getlength(backing_bs(bs));
if (backing_len < 0) {
ret = backing_len;
error_setg_errno(errp, -ret, "Could not get backing file size");
goto out;
}

if (backing_len > old_size) {
flags |= BDRV_REQ_ZERO_WRITE;
}
}

if (drv->bdrv_co_truncate) {
ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, errp);
if (flags & ~bs->supported_truncate_flags) {
error_setg(errp, "Block driver does not support requested flags");
ret = -ENOTSUP;
goto out;
}
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;
Expand Down Expand Up @@ -3429,6 +3460,7 @@ typedef struct TruncateCo {
int64_t offset;
bool exact;
PreallocMode prealloc;
BdrvRequestFlags flags;
Error **errp;
int ret;
} TruncateCo;
Expand All @@ -3437,19 +3469,20 @@ 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 = {
.child = child,
.offset = offset,
.exact = exact,
.prealloc = prealloc,
.flags = flags,
.errp = errp,
.ret = NOT_DONE,
};
Expand Down
2 changes: 1 addition & 1 deletion block/iscsi.c
Expand Up @@ -2124,7 +2124,7 @@ static void iscsi_reopen_commit(BDRVReopenState *reopen_state)

static int coroutine_fn iscsi_co_truncate(BlockDriverState *bs, int64_t offset,
bool exact, PreallocMode prealloc,
Error **errp)
BdrvRequestFlags flags, Error **errp)
{
IscsiLun *iscsilun = bs->opaque;
int64_t cur_length;
Expand Down
2 changes: 1 addition & 1 deletion block/mirror.c
Expand Up @@ -900,7 +900,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)

if (s->bdev_length > base_length) {
ret = blk_truncate(s->target, s->bdev_length, false,
PREALLOC_MODE_OFF, NULL);
PREALLOC_MODE_OFF, 0, NULL);
if (ret < 0) {
goto immediate_exit;
}
Expand Down
3 changes: 2 additions & 1 deletion block/nfs.c
Expand Up @@ -755,7 +755,8 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)

static int coroutine_fn
nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
PreallocMode prealloc, Error **errp)
PreallocMode prealloc, BdrvRequestFlags flags,
Error **errp)
{
NFSClient *client = bs->opaque;
int ret;
Expand Down
6 changes: 3 additions & 3 deletions block/parallels.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions block/qcow.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion block/qcow2-cluster.c
Expand Up @@ -1795,7 +1795,7 @@ int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,
/* Caller must pass aligned values, except at image end */
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
end_offset >= bs->total_sectors << BDRV_SECTOR_BITS);

/* The zero flag is only supported by version 3 and newer */
if (s->qcow_version < 3) {
Expand Down
2 changes: 1 addition & 1 deletion block/qcow2-refcount.c
Expand Up @@ -2018,7 +2018,7 @@ static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res,
}

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;
Expand Down

0 comments on commit 1c47613

Please sign in to comment.