From 5530f18faa5ba30a8fea568c1339e5816655fe22 Mon Sep 17 00:00:00 2001 From: Jeffrey Cody Date: Wed, 21 Mar 2012 21:54:46 +0100 Subject: [PATCH 19/55] cow: convert to .bdrv_co_is_allocated() RH-Author: Jeffrey Cody Message-id: <517dec1c491161865b2cd82e2a8517dd499563d2.1332362400.git.jcody@redhat.com> Patchwork-id: 38869 O-Subject: [RHEL6.3 qemu-kvm PATCH v8 19/54] cow: convert to .bdrv_co_is_allocated() Bugzilla: 582475 RH-Acked-by: Paolo Bonzini RH-Acked-by: Marcelo Tosatti RH-Acked-by: Kevin Wolf From: Stefan Hajnoczi 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: Stefan Hajnoczi Signed-off-by: Kevin Wolf (cherry picked from commit 81145834d39897c6f153ac26a4077f90f269c5fc) Signed-off-by: Stefan Hajnoczi Signed-off-by: Anthony Liguori Signed-off-by: Jeff Cody --- block/cow.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) Signed-off-by: Michal Novotny --- block/cow.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/cow.c b/block/cow.c index 470c93e..9609423 100644 --- a/block/cow.c +++ b/block/cow.c @@ -130,8 +130,8 @@ static inline int is_bit_set(BlockDriverState *bs, int64_t bitnum) /* Return true if first block has been changed (ie. current version is * in COW file). Set the number of continuous blocks for which that * is true. */ -static int cow_is_allocated(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *num_same) +static int coroutine_fn cow_co_is_allocated(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, int *num_same) { int changed; @@ -176,7 +176,7 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num, int ret, n; 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, s->cow_sectors_offset + sector_num * 512, buf, n * 512); @@ -333,7 +333,7 @@ static BlockDriver bdrv_cow = { .bdrv_close = cow_close, .bdrv_create = cow_create, .bdrv_co_flush = cow_co_flush, - .bdrv_is_allocated = cow_is_allocated, + .bdrv_co_is_allocated = cow_co_is_allocated, .create_options = cow_create_options, }; -- 1.7.7.6