mirror of
https://github.com/qemu/qemu.git
synced 2024-11-25 03:43:37 +08:00
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>
This commit is contained in:
parent
f08145fe16
commit
b0ad5a455d
20
block/cow.c
20
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)));
|
||||
|
Loading…
Reference in New Issue
Block a user