static int qcow2_mark_dirty(BlockDriverState *bs)

{

    BDRVQcowState *s = bs->opaque;

    uint64_t val;

    int ret;



    assert(s->qcow_version >= 3);



    if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) {

        return 0; /* already dirty */

    }



    val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY);

    ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, incompatible_features),

                      &val, sizeof(val));

    if (ret < 0) {

        return ret;

    }

    ret = bdrv_flush(bs->file);

    if (ret < 0) {

        return ret;

    }



    /* Only treat image as dirty if the header was updated successfully */

    s->incompatible_features |= QCOW2_INCOMPAT_DIRTY;

    return 0;

}

static int qcow2_mark_dirty(BlockDriverState *bs)

{

    BDRVQcowState *s = bs->opaque;

    uint64_t val;

    int ret;



    assert(s->qcow_version >= 3);



    if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) {

        return 0; 

    }



    val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY);

    ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, incompatible_features),

                      &val, sizeof(val));

    if (ret < 0) {

        return ret;

    }

    ret = bdrv_flush(bs->file);

    if (ret < 0) {

        return ret;

    }



    

    s->incompatible_features |= QCOW2_INCOMPAT_DIRTY;

    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0)

{

    BDRVQcowState *s = VAR_0->opaque;

    uint64_t val;

    int VAR_1;



    assert(s->qcow_version >= 3);



    if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) {

        return 0; 

    }



    val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY);

    VAR_1 = bdrv_pwrite(VAR_0->file, offsetof(QCowHeader, incompatible_features),

                      &val, sizeof(val));

    if (VAR_1 < 0) {

        return VAR_1;

    }

    VAR_1 = bdrv_flush(VAR_0->file);

    if (VAR_1 < 0) {

        return VAR_1;

    }



    

    s->incompatible_features |= QCOW2_INCOMPAT_DIRTY;

    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0)
{ BDRVQcowState *s = VAR_0->opaque; uint64_t val; int VAR_1; assert(s->qcow_version >= 3); if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) { return 0; } val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY); VAR_1 = bdrv_pwrite(VAR_0->file, offsetof(QCowHeader, incompatible_features),
&val, sizeof(val)); if (VAR_1 < 0) { return VAR_1; } VAR_1 = bdrv_flush(VAR_0->file); if (VAR_1 < 0) { return VAR_1; } s->incompatible_features |= QCOW2_INCOMPAT_DIRTY; return 0; }