Commit 7a6cba611d09f8eccdfc90d5ad3eb03762e60ce9
1 parent
17acfe32
Disk cache flush support.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1949 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
9 changed files
with
46 additions
and
1 deletions
block-cow.c
| ... | ... | @@ -250,6 +250,12 @@ static int cow_create(const char *filename, int64_t image_sectors, |
| 250 | 250 | return 0; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | +static void cow_flush(BlockDriverState *bs) | |
| 254 | +{ | |
| 255 | + BDRVCowState *s = bs->opaque; | |
| 256 | + fsync(s->fd); | |
| 257 | +} | |
| 258 | + | |
| 253 | 259 | BlockDriver bdrv_cow = { |
| 254 | 260 | "cow", |
| 255 | 261 | sizeof(BDRVCowState), |
| ... | ... | @@ -259,6 +265,7 @@ BlockDriver bdrv_cow = { |
| 259 | 265 | cow_write, |
| 260 | 266 | cow_close, |
| 261 | 267 | cow_create, |
| 268 | + cow_flush, | |
| 262 | 269 | cow_is_allocated, |
| 263 | 270 | }; |
| 264 | 271 | #endif | ... | ... |
block-qcow.c
| ... | ... | @@ -693,6 +693,12 @@ int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num, |
| 693 | 693 | return 0; |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | +static void qcow_flush(BlockDriverState *bs) | |
| 697 | +{ | |
| 698 | + BDRVQcowState *s = bs->opaque; | |
| 699 | + fsync(s->fd); | |
| 700 | +} | |
| 701 | + | |
| 696 | 702 | BlockDriver bdrv_qcow = { |
| 697 | 703 | "qcow", |
| 698 | 704 | sizeof(BDRVQcowState), |
| ... | ... | @@ -702,6 +708,7 @@ BlockDriver bdrv_qcow = { |
| 702 | 708 | qcow_write, |
| 703 | 709 | qcow_close, |
| 704 | 710 | qcow_create, |
| 711 | + qcow_flush, | |
| 705 | 712 | qcow_is_allocated, |
| 706 | 713 | qcow_set_key, |
| 707 | 714 | qcow_make_empty | ... | ... |
block-vmdk.c
| ... | ... | @@ -426,6 +426,12 @@ static void vmdk_close(BlockDriverState *bs) |
| 426 | 426 | close(s->fd); |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | +static void vmdk_flush(BlockDriverState *bs) | |
| 430 | +{ | |
| 431 | + BDRVVmdkState *s = bs->opaque; | |
| 432 | + fsync(s->fd); | |
| 433 | +} | |
| 434 | + | |
| 429 | 435 | BlockDriver bdrv_vmdk = { |
| 430 | 436 | "vmdk", |
| 431 | 437 | sizeof(BDRVVmdkState), |
| ... | ... | @@ -435,5 +441,6 @@ BlockDriver bdrv_vmdk = { |
| 435 | 441 | vmdk_write, |
| 436 | 442 | vmdk_close, |
| 437 | 443 | vmdk_create, |
| 444 | + vmdk_flush, | |
| 438 | 445 | vmdk_is_allocated, |
| 439 | 446 | }; | ... | ... |
block-vvfat.c
block.c
| ... | ... | @@ -615,6 +615,14 @@ const char *bdrv_get_device_name(BlockDriverState *bs) |
| 615 | 615 | return bs->device_name; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | +void bdrv_flush(BlockDriverState *bs) | |
| 619 | +{ | |
| 620 | + if (bs->drv->bdrv_flush) | |
| 621 | + bs->drv->bdrv_flush(bs); | |
| 622 | + if (bs->backing_hd) | |
| 623 | + bdrv_flush(bs->backing_hd); | |
| 624 | +} | |
| 625 | + | |
| 618 | 626 | void bdrv_info(void) |
| 619 | 627 | { |
| 620 | 628 | BlockDriverState *bs; |
| ... | ... | @@ -770,6 +778,12 @@ static int raw_create(const char *filename, int64_t total_size, |
| 770 | 778 | return 0; |
| 771 | 779 | } |
| 772 | 780 | |
| 781 | +static void raw_flush(BlockDriverState *bs) | |
| 782 | +{ | |
| 783 | + BDRVRawState *s = bs->opaque; | |
| 784 | + fsync(s->fd); | |
| 785 | +} | |
| 786 | + | |
| 773 | 787 | BlockDriver bdrv_raw = { |
| 774 | 788 | "raw", |
| 775 | 789 | sizeof(BDRVRawState), |
| ... | ... | @@ -779,6 +793,7 @@ BlockDriver bdrv_raw = { |
| 779 | 793 | raw_write, |
| 780 | 794 | raw_close, |
| 781 | 795 | raw_create, |
| 796 | + raw_flush, | |
| 782 | 797 | }; |
| 783 | 798 | |
| 784 | 799 | void bdrv_init(void) | ... | ... |
block_int.h
| ... | ... | @@ -36,6 +36,7 @@ struct BlockDriver { |
| 36 | 36 | void (*bdrv_close)(BlockDriverState *bs); |
| 37 | 37 | int (*bdrv_create)(const char *filename, int64_t total_sectors, |
| 38 | 38 | const char *backing_file, int flags); |
| 39 | + void (*bdrv_flush)(BlockDriverState *bs); | |
| 39 | 40 | int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num, |
| 40 | 41 | int nb_sectors, int *pnum); |
| 41 | 42 | int (*bdrv_set_key)(BlockDriverState *bs, const char *key); | ... | ... |
hw/ide.c
| ... | ... | @@ -1656,6 +1656,11 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
| 1656 | 1656 | break; |
| 1657 | 1657 | case WIN_FLUSH_CACHE: |
| 1658 | 1658 | case WIN_FLUSH_CACHE_EXT: |
| 1659 | + if (s->bs) | |
| 1660 | + bdrv_flush(s->bs); | |
| 1661 | + s->status = READY_STAT; | |
| 1662 | + ide_set_irq(s); | |
| 1663 | + break; | |
| 1659 | 1664 | case WIN_STANDBYNOW1: |
| 1660 | 1665 | case WIN_IDLEIMMEDIATE: |
| 1661 | 1666 | s->status = READY_STAT; | ... | ... |
hw/scsi-disk.c
| ... | ... | @@ -373,7 +373,7 @@ int32_t scsi_send_command(SCSIDevice *s, uint32_t tag, uint8_t *buf, int lun) |
| 373 | 373 | break; |
| 374 | 374 | case 0x35: |
| 375 | 375 | DPRINTF("Syncronise cache (sector %d, count %d)\n", lba, len); |
| 376 | - /* ??? Extend block layer and use fsync to implement this. */ | |
| 376 | + bdrv_flush(s->bdrv); | |
| 377 | 377 | break; |
| 378 | 378 | case 0x43: |
| 379 | 379 | { | ... | ... |
vl.h
| ... | ... | @@ -496,6 +496,8 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num, |
| 496 | 496 | void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr); |
| 497 | 497 | int bdrv_commit(BlockDriverState *bs); |
| 498 | 498 | void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size); |
| 499 | +/* Ensure contents are flushed to disk. */ | |
| 500 | +void bdrv_flush(BlockDriverState *bs); | |
| 499 | 501 | |
| 500 | 502 | #define BDRV_TYPE_HD 0 |
| 501 | 503 | #define BDRV_TYPE_CDROM 1 | ... | ... |