aboutsummaryrefslogtreecommitdiff
path: root/block/cow.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2010-06-18 16:31:14 +0200
committerKevin Wolf <kwolf@redhat.com>2010-06-22 14:38:02 +0200
commitb0ad5a455d7e5352d4c86ba945112011dbeadfb8 (patch)
tree8a39d9508ad5b25ddb4d9cec6957625349587958 /block/cow.c
parentf08145fe16470aca09304099888f68cfbc5d1de7 (diff)
downloadqemu-b0ad5a455d7e5352d4c86ba945112011dbeadfb8.zip
qemu-b0ad5a455d7e5352d4c86ba945112011dbeadfb8.tar.gz
qemu-b0ad5a455d7e5352d4c86ba945112011dbeadfb8.tar.bz2
cow: Use bdrv_(p)write_sync for metadata writes
Use bdrv_(p)write_sync to ensure metadata integrity in case of a crash. While at it, correct the wrong usage of errno. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/cow.c')
-rw-r--r--block/cow.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/block/cow.c b/block/cow.c
index d146434..eedcc48 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -97,17 +97,18 @@ static inline int cow_set_bit(BlockDriverState *bs, int64_t bitnum)
{
uint64_t offset = sizeof(struct cow_header_v2) + bitnum / 8;
uint8_t bitmap;
+ int ret;
- if (bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap)) !=
- sizeof(bitmap)) {
- return -errno;
+ ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
+ if (ret < 0) {
+ return ret;
}
bitmap |= (1 << (bitnum % 8));
- if (bdrv_pwrite(bs->file, offset, &bitmap, sizeof(bitmap)) !=
- sizeof(bitmap)) {
- return -errno;
+ ret = bdrv_pwrite_sync(bs->file, offset, &bitmap, sizeof(bitmap));
+ if (ret < 0) {
+ return ret;
}
return 0;
}
@@ -116,10 +117,11 @@ static inline int is_bit_set(BlockDriverState *bs, int64_t bitnum)
{
uint64_t offset = sizeof(struct cow_header_v2) + bitnum / 8;
uint8_t bitmap;
+ int ret;
- if (bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap)) !=
- sizeof(bitmap)) {
- return -errno;
+ ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
+ if (ret < 0) {
+ return ret;
}
return !!(bitmap & (1 << (bitnum % 8)));