block.c (cdc6f542007a6aee0b18a5d616d031c750691e7a) | block.c (8a4266144ebffceb8fda2a5feb03d23c535923d4) |
---|---|
1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 725 unchanged lines hidden (view full) --- 734 if (bs->drv->bdrv_check == NULL) { 735 return -ENOTSUP; 736 } 737 738 memset(res, 0, sizeof(*res)); 739 return bs->drv->bdrv_check(bs, res); 740} 741 | 1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 725 unchanged lines hidden (view full) --- 734 if (bs->drv->bdrv_check == NULL) { 735 return -ENOTSUP; 736 } 737 738 memset(res, 0, sizeof(*res)); 739 return bs->drv->bdrv_check(bs, res); 740} 741 |
742#define COMMIT_BUF_SECTORS 2048 743 |
|
742/* commit COW file into the raw image */ 743int bdrv_commit(BlockDriverState *bs) 744{ 745 BlockDriver *drv = bs->drv; | 744/* commit COW file into the raw image */ 745int bdrv_commit(BlockDriverState *bs) 746{ 747 BlockDriver *drv = bs->drv; |
746 int64_t i, total_sectors; 747 int n, j, ro, open_flags; | 748 int64_t sector, total_sectors; 749 int n, ro, open_flags; |
748 int ret = 0, rw_ret = 0; | 750 int ret = 0, rw_ret = 0; |
749 unsigned char sector[BDRV_SECTOR_SIZE]; | 751 uint8_t *buf; |
750 char filename[1024]; 751 BlockDriverState *bs_rw, *bs_ro; 752 753 if (!drv) 754 return -ENOMEDIUM; 755 756 if (!bs->backing_hd) { 757 return -ENOTSUP; --- 26 unchanged lines hidden (view full) --- 784 } 785 bs->backing_hd = bs_ro; 786 return rw_ret; 787 } 788 bs->backing_hd = bs_rw; 789 } 790 791 total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; | 752 char filename[1024]; 753 BlockDriverState *bs_rw, *bs_ro; 754 755 if (!drv) 756 return -ENOMEDIUM; 757 758 if (!bs->backing_hd) { 759 return -ENOTSUP; --- 26 unchanged lines hidden (view full) --- 786 } 787 bs->backing_hd = bs_ro; 788 return rw_ret; 789 } 790 bs->backing_hd = bs_rw; 791 } 792 793 total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; |
792 for (i = 0; i < total_sectors;) { 793 if (drv->bdrv_is_allocated(bs, i, 65536, &n)) { 794 for(j = 0; j < n; j++) { 795 if (bdrv_read(bs, i, sector, 1) != 0) { 796 ret = -EIO; 797 goto ro_cleanup; 798 } | 794 buf = qemu_malloc(COMMIT_BUF_SECTORS * BDRV_SECTOR_SIZE); |
799 | 795 |
800 if (bdrv_write(bs->backing_hd, i, sector, 1) != 0) { 801 ret = -EIO; 802 goto ro_cleanup; 803 } 804 i++; 805 } 806 } else { 807 i += n; | 796 for (sector = 0; sector < total_sectors; sector += n) { 797 if (drv->bdrv_is_allocated(bs, sector, COMMIT_BUF_SECTORS, &n)) { 798 799 if (bdrv_read(bs, sector, buf, n) != 0) { 800 ret = -EIO; 801 goto ro_cleanup; 802 } 803 804 if (bdrv_write(bs->backing_hd, sector, buf, n) != 0) { 805 ret = -EIO; 806 goto ro_cleanup; 807 } |
808 } 809 } 810 811 if (drv->bdrv_make_empty) { 812 ret = drv->bdrv_make_empty(bs); 813 bdrv_flush(bs); 814 } 815 816 /* 817 * Make sure all data we wrote to the backing device is actually 818 * stable on disk. 819 */ 820 if (bs->backing_hd) 821 bdrv_flush(bs->backing_hd); 822 823ro_cleanup: | 808 } 809 } 810 811 if (drv->bdrv_make_empty) { 812 ret = drv->bdrv_make_empty(bs); 813 bdrv_flush(bs); 814 } 815 816 /* 817 * Make sure all data we wrote to the backing device is actually 818 * stable on disk. 819 */ 820 if (bs->backing_hd) 821 bdrv_flush(bs->backing_hd); 822 823ro_cleanup: |
824 qemu_free(buf); |
|
824 825 if (ro) { 826 /* re-open as RO */ 827 bdrv_delete(bs->backing_hd); 828 bs->backing_hd = NULL; 829 bs_ro = bdrv_new(""); 830 ret = bdrv_open(bs_ro, filename, open_flags & ~BDRV_O_RDWR, drv); 831 if (ret < 0) { --- 1831 unchanged lines hidden --- | 825 826 if (ro) { 827 /* re-open as RO */ 828 bdrv_delete(bs->backing_hd); 829 bs->backing_hd = NULL; 830 bs_ro = bdrv_new(""); 831 ret = bdrv_open(bs_ro, filename, open_flags & ~BDRV_O_RDWR, drv); 832 if (ret < 0) { --- 1831 unchanged lines hidden --- |