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,6 +250,12 @@ static int cow_create(const char *filename, int64_t image_sectors, | ||
| 250 | return 0; | 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 | BlockDriver bdrv_cow = { | 259 | BlockDriver bdrv_cow = { |
| 254 | "cow", | 260 | "cow", |
| 255 | sizeof(BDRVCowState), | 261 | sizeof(BDRVCowState), |
| @@ -259,6 +265,7 @@ BlockDriver bdrv_cow = { | @@ -259,6 +265,7 @@ BlockDriver bdrv_cow = { | ||
| 259 | cow_write, | 265 | cow_write, |
| 260 | cow_close, | 266 | cow_close, |
| 261 | cow_create, | 267 | cow_create, |
| 268 | + cow_flush, | ||
| 262 | cow_is_allocated, | 269 | cow_is_allocated, |
| 263 | }; | 270 | }; |
| 264 | #endif | 271 | #endif |
block-qcow.c
| @@ -693,6 +693,12 @@ int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num, | @@ -693,6 +693,12 @@ int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num, | ||
| 693 | return 0; | 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 | BlockDriver bdrv_qcow = { | 702 | BlockDriver bdrv_qcow = { |
| 697 | "qcow", | 703 | "qcow", |
| 698 | sizeof(BDRVQcowState), | 704 | sizeof(BDRVQcowState), |
| @@ -702,6 +708,7 @@ BlockDriver bdrv_qcow = { | @@ -702,6 +708,7 @@ BlockDriver bdrv_qcow = { | ||
| 702 | qcow_write, | 708 | qcow_write, |
| 703 | qcow_close, | 709 | qcow_close, |
| 704 | qcow_create, | 710 | qcow_create, |
| 711 | + qcow_flush, | ||
| 705 | qcow_is_allocated, | 712 | qcow_is_allocated, |
| 706 | qcow_set_key, | 713 | qcow_set_key, |
| 707 | qcow_make_empty | 714 | qcow_make_empty |
block-vmdk.c
| @@ -426,6 +426,12 @@ static void vmdk_close(BlockDriverState *bs) | @@ -426,6 +426,12 @@ static void vmdk_close(BlockDriverState *bs) | ||
| 426 | close(s->fd); | 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 | BlockDriver bdrv_vmdk = { | 435 | BlockDriver bdrv_vmdk = { |
| 430 | "vmdk", | 436 | "vmdk", |
| 431 | sizeof(BDRVVmdkState), | 437 | sizeof(BDRVVmdkState), |
| @@ -435,5 +441,6 @@ BlockDriver bdrv_vmdk = { | @@ -435,5 +441,6 @@ BlockDriver bdrv_vmdk = { | ||
| 435 | vmdk_write, | 441 | vmdk_write, |
| 436 | vmdk_close, | 442 | vmdk_close, |
| 437 | vmdk_create, | 443 | vmdk_create, |
| 444 | + vmdk_flush, | ||
| 438 | vmdk_is_allocated, | 445 | vmdk_is_allocated, |
| 439 | }; | 446 | }; |
block-vvfat.c
| @@ -2772,6 +2772,7 @@ BlockDriver bdrv_vvfat = { | @@ -2772,6 +2772,7 @@ BlockDriver bdrv_vvfat = { | ||
| 2772 | vvfat_read, | 2772 | vvfat_read, |
| 2773 | vvfat_write, | 2773 | vvfat_write, |
| 2774 | vvfat_close, | 2774 | vvfat_close, |
| 2775 | + NULL, /* ??? Not sure if we can do any meaningful flushing. */ | ||
| 2775 | NULL, | 2776 | NULL, |
| 2776 | vvfat_is_allocated | 2777 | vvfat_is_allocated |
| 2777 | }; | 2778 | }; |
block.c
| @@ -615,6 +615,14 @@ const char *bdrv_get_device_name(BlockDriverState *bs) | @@ -615,6 +615,14 @@ const char *bdrv_get_device_name(BlockDriverState *bs) | ||
| 615 | return bs->device_name; | 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 | void bdrv_info(void) | 626 | void bdrv_info(void) |
| 619 | { | 627 | { |
| 620 | BlockDriverState *bs; | 628 | BlockDriverState *bs; |
| @@ -770,6 +778,12 @@ static int raw_create(const char *filename, int64_t total_size, | @@ -770,6 +778,12 @@ static int raw_create(const char *filename, int64_t total_size, | ||
| 770 | return 0; | 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 | BlockDriver bdrv_raw = { | 787 | BlockDriver bdrv_raw = { |
| 774 | "raw", | 788 | "raw", |
| 775 | sizeof(BDRVRawState), | 789 | sizeof(BDRVRawState), |
| @@ -779,6 +793,7 @@ BlockDriver bdrv_raw = { | @@ -779,6 +793,7 @@ BlockDriver bdrv_raw = { | ||
| 779 | raw_write, | 793 | raw_write, |
| 780 | raw_close, | 794 | raw_close, |
| 781 | raw_create, | 795 | raw_create, |
| 796 | + raw_flush, | ||
| 782 | }; | 797 | }; |
| 783 | 798 | ||
| 784 | void bdrv_init(void) | 799 | void bdrv_init(void) |
block_int.h
| @@ -36,6 +36,7 @@ struct BlockDriver { | @@ -36,6 +36,7 @@ struct BlockDriver { | ||
| 36 | void (*bdrv_close)(BlockDriverState *bs); | 36 | void (*bdrv_close)(BlockDriverState *bs); |
| 37 | int (*bdrv_create)(const char *filename, int64_t total_sectors, | 37 | int (*bdrv_create)(const char *filename, int64_t total_sectors, |
| 38 | const char *backing_file, int flags); | 38 | const char *backing_file, int flags); |
| 39 | + void (*bdrv_flush)(BlockDriverState *bs); | ||
| 39 | int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num, | 40 | int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num, |
| 40 | int nb_sectors, int *pnum); | 41 | int nb_sectors, int *pnum); |
| 41 | int (*bdrv_set_key)(BlockDriverState *bs, const char *key); | 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,6 +1656,11 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) | ||
| 1656 | break; | 1656 | break; |
| 1657 | case WIN_FLUSH_CACHE: | 1657 | case WIN_FLUSH_CACHE: |
| 1658 | case WIN_FLUSH_CACHE_EXT: | 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 | case WIN_STANDBYNOW1: | 1664 | case WIN_STANDBYNOW1: |
| 1660 | case WIN_IDLEIMMEDIATE: | 1665 | case WIN_IDLEIMMEDIATE: |
| 1661 | s->status = READY_STAT; | 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,7 +373,7 @@ int32_t scsi_send_command(SCSIDevice *s, uint32_t tag, uint8_t *buf, int lun) | ||
| 373 | break; | 373 | break; |
| 374 | case 0x35: | 374 | case 0x35: |
| 375 | DPRINTF("Syncronise cache (sector %d, count %d)\n", lba, len); | 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 | break; | 377 | break; |
| 378 | case 0x43: | 378 | case 0x43: |
| 379 | { | 379 | { |
vl.h
| @@ -496,6 +496,8 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num, | @@ -496,6 +496,8 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num, | ||
| 496 | void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr); | 496 | void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr); |
| 497 | int bdrv_commit(BlockDriverState *bs); | 497 | int bdrv_commit(BlockDriverState *bs); |
| 498 | void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size); | 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 | #define BDRV_TYPE_HD 0 | 502 | #define BDRV_TYPE_HD 0 |
| 501 | #define BDRV_TYPE_CDROM 1 | 503 | #define BDRV_TYPE_CDROM 1 |