Am 26.08.2013 um 15:04 hat Max Reitz geschrieben: > This adds an incompatible bit indicating corruption to qcow2. Any image > with this bit set may not be written to unless for repairing (and > subsequently clearing the bit if the repair has been successful). > > Signed-off-by: Max Reitz <mre...@redhat.com> > --- > block/qcow2.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ > block/qcow2.h | 7 ++++++- > docs/specs/qcow2.txt | 7 ++++++- > include/block/block.h | 2 ++ > qemu-img.c | 2 +- > tests/qemu-iotests/031.out | 12 ++++++------ > tests/qemu-iotests/036.out | 2 +- > 7 files changed, 66 insertions(+), 10 deletions(-) > > diff --git a/block/qcow2.c b/block/qcow2.c > index 3376901..1d0d7ca 100644 > --- a/block/qcow2.c > +++ b/block/qcow2.c > @@ -272,6 +272,37 @@ static int qcow2_mark_clean(BlockDriverState *bs) > return 0; > } > > +/* > + * Marks the image as corrupt. > + */ > +int qcow2_mark_corrupt(BlockDriverState *bs) > +{ > + BDRVQcowState *s = bs->opaque; > + > + s->incompatible_features |= QCOW2_INCOMPAT_CORRUPT; > + return qcow2_update_header(bs); > +} > + > +/* > + * Marks the image as consistent, i.e., unsets the corrupt bit, and flushes > + * before if necessary. > + */ > +int qcow2_mark_consistent(BlockDriverState *bs) > +{ > + BDRVQcowState *s = bs->opaque; > + > + if (s->incompatible_features & QCOW2_INCOMPAT_CORRUPT) { > + int ret = bdrv_flush(bs); > + if (ret < 0) { > + return ret; > + } > + > + s->incompatible_features &= ~QCOW2_INCOMPAT_CORRUPT; > + return qcow2_update_header(bs); > + } > + return 0; > +} > + > static int qcow2_check(BlockDriverState *bs, BdrvCheckResult *result, > BdrvCheckMode fix) > { > @@ -402,6 +433,14 @@ static int qcow2_open(BlockDriverState *bs, QDict > *options, int flags) > goto fail; > } > > + if (s->incompatible_features & QCOW2_INCOMPAT_CORRUPT) { > + /* Corrupt images may not be written to unless they are being > repaired */ > + if ((flags & BDRV_O_RDWR) && !(flags & BDRV_O_REPAIR)) {
Isn't BDRV_O_REPAIR equivalent to BDRV_O_CHECK && BDRV_O_RDWR, or is there an advantage in using a new bit? Looks good otherwise. Kevin