/* Clears the dirty bit and flushes before if necessary. Only call this function when there are no pending requests, it does not guard against concurrent requests dirtying the image.  */
static int qcow2_mark_clean(BlockDriverState *bs)
/* Clears the dirty bit and flushes before if necessary. Only call this function when there are no pending requests, it does not guard against concurrent requests dirtying the image.  */
static int qcow2_mark_clean(BlockDriverState *bs)
{
    BDRVQcowState *s = bs->opaque;
    if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) {
        int ret;
        s->incompatible_features &= ~QCOW2_INCOMPAT_DIRTY;
        ret = bdrv_flush(bs);
        if (ret < 0) {
            return ret;
        }
        return qcow2_update_header(bs);
    }
    return 0;
}