aboutsummaryrefslogtreecommitdiff
path: root/block/qcow2.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2016-11-17 14:13:57 -0600
committerKevin Wolf <kwolf@redhat.com>2016-11-22 15:59:22 +0100
commit49228d1e95e1be879c57f5dbccb44405670e343d (patch)
treebb6fe7dedd1e891b3723a1dafbf0c2e1e9b892de /block/qcow2.c
parentb2f95feec5e4d546b932848dd421ec3361e8ef77 (diff)
downloadqemu-49228d1e95e1be879c57f5dbccb44405670e343d.zip
qemu-49228d1e95e1be879c57f5dbccb44405670e343d.tar.gz
qemu-49228d1e95e1be879c57f5dbccb44405670e343d.tar.bz2
block: Return -ENOTSUP rather than assert on unaligned discards
Right now, the block layer rounds discard requests, so that individual drivers are able to assert that discard requests will never be unaligned. But there are some ISCSI devices that track and coalesce multiple unaligned requests, turning it into an actual discard if the requests eventually cover an entire page, which implies that it is better to always pass discard requests as low down the stack as possible. In isolation, this patch has no semantic effect, since the block layer currently never passes an unaligned request through. But the block layer already has code that silently ignores drivers that return -ENOTSUP for a discard request that cannot be honored (as well as drivers that return 0 even when nothing was done). But the next patch will update the block layer to fragment discard requests, so that clients are guaranteed that they are either dealing with an unaligned head or tail, or an aligned core, making it similar to the block layer semantics of write zero fragmentation. CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/qcow2.c')
-rw-r--r--block/qcow2.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/block/qcow2.c b/block/qcow2.c
index e22f6dc..7cfcd84 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2491,6 +2491,11 @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs,
int ret;
BDRVQcow2State *s = bs->opaque;
+ if (!QEMU_IS_ALIGNED(offset | count, s->cluster_size)) {
+ assert(count < s->cluster_size);
+ return -ENOTSUP;
+ }
+
qemu_co_mutex_lock(&s->lock);
ret = qcow2_discard_clusters(bs, offset, count >> BDRV_SECTOR_BITS,
QCOW2_DISCARD_REQUEST, false);