From dade09da11e6d7da9c674d376b49eca96c8c115c Mon Sep 17 00:00:00 2001 From: Dong Xu Wang Date: Tue, 6 Sep 2011 01:10:36 +0800 Subject: [PATCH] still can not re-boot --- block/add-cow.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/block/add-cow.c b/block/add-cow.c index a2d3546e4b..9daf626444 100644 --- a/block/add-cow.c +++ b/block/add-cow.c @@ -125,7 +125,7 @@ static int add_cow_is_allocated(BlockDriverState *bs, int64_t sector_num, changed = is_bit_set(bs, sector_num); if (changed < 0) { - return 0; + return 0; } for (*num_same = 1; *num_same < nb_sectors; (*num_same)++) { @@ -197,7 +197,7 @@ static int add_cow_create(const char *filename, QEMUOptionParameter *options) sizeof(add_cow_header.backing_file), backing_filename); pstrcpy(add_cow_header.image_file, sizeof(add_cow_header.image_file), image_filename); - + add_cow_header.sectorsize = cpu_to_be32(512); add_cow_header.size = cpu_to_be64(image_sectors * 512); @@ -207,6 +207,11 @@ static int add_cow_create(const char *filename, QEMUOptionParameter *options) } bdrv_close(bs); + ret = bdrv_create_file(image_filename, NULL); + if (ret < 0) { + return ret; + } + BlockDriver* drv = bdrv_find_format("add-cow"); assert(drv != NULL); ret = bdrv_open(bs, filename, BDRV_O_RDWR | BDRV_O_NO_FLUSH, drv); @@ -265,7 +270,6 @@ static int add_cow_aio_read_cb(void *opaque) BDRVAddCowState *s = bs->opaque; int ret; int n; - redo: acb->nb_sectors -= acb->n; acb->sector_num += acb->n; acb->buf += acb->n * 512; @@ -282,12 +286,14 @@ static int add_cow_aio_read_cb(void *opaque) qemu_co_mutex_unlock(&s->lock); ret = bdrv_co_readv(bs->cow_hd, acb->sector_num, n, &acb->hd_qiov); - acb->n = n; qemu_co_mutex_lock(&s->lock); if (ret < 0) { return -EIO; } + acb->n = n; + return 1; } else { + acb->n = n; if (bs->backing_hd) { acb->hd_iov.iov_base = (void *)acb->buf; acb->hd_iov.iov_len = n * 512; @@ -299,13 +305,13 @@ static int add_cow_aio_read_cb(void *opaque) if (ret < 0) { return -EIO; } + return 1; } else { memset(acb->buf, 0, 512 * n); - acb->n = n; - goto redo; + return 1; } acb->n = n; - } + } return 1; } @@ -349,7 +355,7 @@ static int add_cow_co_readv(BlockDriverState *bs, int64_t sector_num, BDRVAddCowState *s = bs->opaque; AddCowAIOCB *acb; int ret; - + acb = add_cow_aio_setup(bs, sector_num, qiov, nb_sectors, 0); qemu_co_mutex_lock(&s->lock); do { @@ -422,6 +428,17 @@ static QEMUOptionParameter add_cow_create_options[] = { { NULL } }; +static int add_cow_flush(BlockDriverState *bs) +{ + return bdrv_flush(bs->file); +} + +static BlockDriverAIOCB *add_cow_aio_flush(BlockDriverState *bs, + BlockDriverCompletionFunc *cb, void *opaque) +{ + return bdrv_aio_flush(bs->file, cb, opaque); +} + static BlockDriver bdrv_add_cow = { .format_name = "add-cow", .instance_size = sizeof(BDRVAddCowState), @@ -435,7 +452,9 @@ static BlockDriver bdrv_add_cow = { .bdrv_co_writev = add_cow_co_writev, .bdrv_truncate = bdrv_add_cow_truncate, - .create_options = add_cow_create_options, + .create_options = add_cow_create_options, + .bdrv_flush = add_cow_flush, + .bdrv_aio_flush = add_cow_aio_flush, }; static void bdrv_add_cow_init(void) -- 2.11.4.GIT