aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2016-07-15 17:22:51 -0600
committerStefan Hajnoczi <stefanha@redhat.com>2016-07-20 14:11:55 +0100
commit0c51a893b643bc9393c685b47b9cea1e6831565f (patch)
tree9636a6178fd16b1efadc97009c5b600a5d589303
parent9f1963b3f72521f75a549f8afd61b19e7da63c6f (diff)
downloadqemu-0c51a893b643bc9393c685b47b9cea1e6831565f.zip
qemu-0c51a893b643bc9393c685b47b9cea1e6831565f.tar.gz
qemu-0c51a893b643bc9393c685b47b9cea1e6831565f.tar.bz2
block: Convert bdrv_discard() to byte-based
Another step towards byte-based interfaces everywhere. Replace the sector-based bdrv_discard() with a new byte-based bdrv_pdiscard(), which silently ignores any unaligned head or tail. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-id: 1468624988-423-3-git-send-email-eblake@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r--block/block-backend.c3
-rw-r--r--block/io.c19
-rw-r--r--block/qcow2-refcount.c4
-rw-r--r--include/block/block.h2
4 files changed, 13 insertions, 15 deletions
diff --git a/block/block-backend.c b/block/block-backend.c
index d982cf9..83b6407 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1512,7 +1512,8 @@ int blk_discard(BlockBackend *blk, int64_t sector_num, int nb_sectors)
return ret;
}
- return bdrv_discard(blk_bs(blk), sector_num, nb_sectors);
+ return bdrv_pdiscard(blk_bs(blk), sector_num << BDRV_SECTOR_BITS,
+ nb_sectors << BDRV_SECTOR_BITS);
}
int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
diff --git a/block/io.c b/block/io.c
index 14d448d..8d41305 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2391,16 +2391,15 @@ int bdrv_flush(BlockDriverState *bs)
typedef struct DiscardCo {
BlockDriverState *bs;
- int64_t sector_num;
- int nb_sectors;
+ int64_t offset;
+ int count;
int ret;
} DiscardCo;
-static void coroutine_fn bdrv_discard_co_entry(void *opaque)
+static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque)
{
DiscardCo *rwco = opaque;
- rwco->ret = bdrv_co_pdiscard(rwco->bs, rwco->sector_num << BDRV_SECTOR_BITS,
- rwco->nb_sectors << BDRV_SECTOR_BITS);
+ rwco->ret = bdrv_co_pdiscard(rwco->bs, rwco->offset, rwco->count);
}
int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
@@ -2495,23 +2494,23 @@ out:
return ret;
}
-int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
+int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count)
{
Coroutine *co;
DiscardCo rwco = {
.bs = bs,
- .sector_num = sector_num,
- .nb_sectors = nb_sectors,
+ .offset = offset,
+ .count = count,
.ret = NOT_DONE,
};
if (qemu_in_coroutine()) {
/* Fast-path if already in coroutine context */
- bdrv_discard_co_entry(&rwco);
+ bdrv_pdiscard_co_entry(&rwco);
} else {
AioContext *aio_context = bdrv_get_aio_context(bs);
- co = qemu_coroutine_create(bdrv_discard_co_entry, &rwco);
+ co = qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco);
qemu_coroutine_enter(co);
while (rwco.ret == NOT_DONE) {
aio_poll(aio_context, true);
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 49b6ce6..cbfb3fe 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -615,9 +615,7 @@ void qcow2_process_discards(BlockDriverState *bs, int ret)
/* Discard is optional, ignore the return value */
if (ret >= 0) {
- bdrv_discard(bs->file->bs,
- d->offset >> BDRV_SECTOR_BITS,
- d->bytes >> BDRV_SECTOR_BITS);
+ bdrv_pdiscard(bs->file->bs, d->offset, d->bytes);
}
g_free(d);
diff --git a/include/block/block.h b/include/block/block.h
index 4f5cebf..94cabbb 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -341,7 +341,7 @@ void bdrv_drain(BlockDriverState *bs);
void coroutine_fn bdrv_co_drain(BlockDriverState *bs);
void bdrv_drain_all(void);
-int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
+int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count);
int bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int count);
int bdrv_has_zero_init_1(BlockDriverState *bs);
int bdrv_has_zero_init(BlockDriverState *bs);