提交 81145834 编写于 作者: S Stefan Hajnoczi 提交者: Kevin Wolf

cow: convert to .bdrv_co_is_allocated()

The cow block driver does not keep internal state for cluster lookups.
This means it is safe to perform cluster lookups in coroutine context
without risk of race conditions that corrupt internal state.
Signed-off-by: NStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 e850b35a
...@@ -132,8 +132,8 @@ static inline int is_bit_set(BlockDriverState *bs, int64_t bitnum) ...@@ -132,8 +132,8 @@ static inline int is_bit_set(BlockDriverState *bs, int64_t bitnum)
/* Return true if first block has been changed (ie. current version is /* Return true if first block has been changed (ie. current version is
* in COW file). Set the number of continuous blocks for which that * in COW file). Set the number of continuous blocks for which that
* is true. */ * is true. */
static int cow_is_allocated(BlockDriverState *bs, int64_t sector_num, static int coroutine_fn cow_co_is_allocated(BlockDriverState *bs,
int nb_sectors, int *num_same) int64_t sector_num, int nb_sectors, int *num_same)
{ {
int changed; int changed;
...@@ -178,7 +178,7 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num, ...@@ -178,7 +178,7 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num,
int ret, n; int ret, n;
while (nb_sectors > 0) { while (nb_sectors > 0) {
if (cow_is_allocated(bs, sector_num, nb_sectors, &n)) { if (bdrv_is_allocated(bs, sector_num, nb_sectors, &n)) {
ret = bdrv_pread(bs->file, ret = bdrv_pread(bs->file,
s->cow_sectors_offset + sector_num * 512, s->cow_sectors_offset + sector_num * 512,
buf, n * 512); buf, n * 512);
...@@ -335,7 +335,7 @@ static BlockDriver bdrv_cow = { ...@@ -335,7 +335,7 @@ static BlockDriver bdrv_cow = {
.bdrv_read = cow_co_read, .bdrv_read = cow_co_read,
.bdrv_write = cow_co_write, .bdrv_write = cow_co_write,
.bdrv_co_flush_to_disk = cow_co_flush, .bdrv_co_flush_to_disk = cow_co_flush,
.bdrv_is_allocated = cow_is_allocated, .bdrv_co_is_allocated = cow_co_is_allocated,
.create_options = cow_create_options, .create_options = cow_create_options,
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册