[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 19/19] block: change discard to co_discard
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 19/19] block: change discard to co_discard |
Date: |
Fri, 21 Oct 2011 19:19:16 +0200 |
From: Paolo Bonzini <address@hidden>
Since coroutine operation is now mandatory, convert both bdrv_discard
implementations to coroutines. For qcow2, this means taking the lock
around the operation. raw-posix remains synchronous.
The bdrv_discard callback is then unused and can be eliminated.
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 2 --
block/qcow2.c | 14 ++++++++++----
block/raw-posix.c | 5 +++--
block_int.h | 2 --
4 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/block.c b/block.c
index 81fb709..70aab63 100644
--- a/block.c
+++ b/block.c
@@ -2962,8 +2962,6 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs,
int64_t sector_num,
qemu_coroutine_yield();
return co.ret;
}
- } else if (bs->drv->bdrv_discard) {
- return bs->drv->bdrv_discard(bs, sector_num, nb_sectors);
} else {
return 0;
}
diff --git a/block/qcow2.c b/block/qcow2.c
index 6ef38bf..a181932 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -978,11 +978,17 @@ static int qcow2_make_empty(BlockDriverState *bs)
return 0;
}
-static int qcow2_discard(BlockDriverState *bs, int64_t sector_num,
- int nb_sectors)
+static coroutine_fn int qcow2_co_discard(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors)
{
- return qcow2_discard_clusters(bs, sector_num << BDRV_SECTOR_BITS,
+ int ret;
+ BDRVQcowState *s = bs->opaque;
+
+ qemu_co_mutex_lock(&s->lock);
+ ret = qcow2_discard_clusters(bs, sector_num << BDRV_SECTOR_BITS,
nb_sectors);
+ qemu_co_mutex_unlock(&s->lock);
+ return ret;
}
static int qcow2_truncate(BlockDriverState *bs, int64_t offset)
@@ -1239,7 +1245,7 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_co_writev = qcow2_co_writev,
.bdrv_co_flush = qcow2_co_flush,
- .bdrv_discard = qcow2_discard,
+ .bdrv_co_discard = qcow2_co_discard,
.bdrv_truncate = qcow2_truncate,
.bdrv_write_compressed = qcow2_write_compressed,
diff --git a/block/raw-posix.c b/block/raw-posix.c
index afcb4c1..a3de373 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -602,7 +602,8 @@ static int xfs_discard(BDRVRawState *s, int64_t sector_num,
int nb_sectors)
}
#endif
-static int raw_discard(BlockDriverState *bs, int64_t sector_num, int
nb_sectors)
+static coroutine_fn int raw_co_discard(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors)
{
#ifdef CONFIG_XFS
BDRVRawState *s = bs->opaque;
@@ -632,7 +633,7 @@ static BlockDriver bdrv_file = {
.bdrv_file_open = raw_open,
.bdrv_close = raw_close,
.bdrv_create = raw_create,
- .bdrv_discard = raw_discard,
+ .bdrv_co_discard = raw_co_discard,
.bdrv_aio_readv = raw_aio_readv,
.bdrv_aio_writev = raw_aio_writev,
diff --git a/block_int.h b/block_int.h
index bc3b07e..dac00f5 100644
--- a/block_int.h
+++ b/block_int.h
@@ -62,8 +62,6 @@ struct BlockDriver {
const uint8_t *buf, int nb_sectors);
void (*bdrv_close)(BlockDriverState *bs);
int (*bdrv_create)(const char *filename, QEMUOptionParameter *options);
- int (*bdrv_discard)(BlockDriverState *bs, int64_t sector_num,
- int nb_sectors);
int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, int *pnum);
int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
--
1.7.6.4
- [Qemu-devel] [PATCH 09/19] fdc: Fix floppy port I/O, (continued)
- [Qemu-devel] [PATCH 09/19] fdc: Fix floppy port I/O, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 11/19] qcow2: Fix bdrv_write_compressed error handling, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 07/19] block: drop redundant bdrv_flush implementation, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 12/19] pc: Fix floppy drives with if=none, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 17/19] block: take lock around bdrv_write implementations, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 14/19] vmdk: clean up open, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 16/19] block: take lock around bdrv_read implementations, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 13/19] vmdk: fix return values of vmdk_parent_open, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 18/19] block: change flush to co_flush, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 15/19] block: add a CoMutex to synchronous read drivers, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 19/19] block: change discard to co_discard,
Kevin Wolf <=
- Re: [Qemu-devel] [PULL 00/19] Block patches, Anthony Liguori, 2011/10/24