lib/qemu/qemu_cxl2.0v4/block.c
/*
 * Called by a driver that can only provide a read-only image.
 *
 * Returns 0 if the node is already read-only or it could switch the node to
 * read-only because BDRV_O_AUTO_RDONLY is set.
 *
 * Returns -EACCES if the node is read-write and BDRV_O_AUTO_RDONLY is not set
 * or bdrv_can_set_read_only() forbids making the node read-only. If @errmsg
 * is not NULL, it is used as the error message for the Error object.
 */
Called by a driver that can only provide a read-only image.
Returns 0 if the node is already read-only or it could switch the node to
read-only because BDRV_O_AUTO_RDONLY is set.

EACCES if the node is read-write and BDRV_O_AUTO_RDONLY is not set
or bdrv_can_set_read_only() forbids making the node read-only. If @errmsg
is not NULL, it is used as the error message for the Error object.
Called by a driver that can only provide a read - only image . Returns 0 if the node is already read - only or it could switch the node to read - only because BDRV_O_AUTO_RDONLY is set . EACCES if the node is read - write and BDRV_O_AUTO_RDONLY is not set or bdrv_can_set_read_only () forbids making the node read - only . If @errmsg is not NULL it is used as the error message for the Error object .
int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg,
                              Error **errp)
{
    int ret = 0;
    if (!(bs->open_flags & BDRV_O_RDWR)) {
        return 0;
    }
    if (!(bs->open_flags & BDRV_O_AUTO_RDONLY)) {
        goto fail;
    }
    ret = bdrv_can_set_read_only(bs, true, false, NULL);
    if (ret < 0) {
        goto fail;
    }
    bs->read_only = true;
    bs->open_flags &= ~BDRV_O_RDWR;
    return 0;
fail:
    error_setg(errp, "%s", errmsg ?: "Image is read-only");
    return -EACCES;
}
int bdrv_apply_auto_read_only ( BlockDriverState * bs , const char * errmsg , Error * * errp ) { int ret = 0 ; if ( ! ( bs -> open_flags & BDRV_O_RDWR ) ) { return 0 ; } if ( ! ( bs -> open_flags & BDRV_O_AUTO_RDONLY ) ) { goto fail ; } ret = bdrv_can_set_read_only ( bs , true , false , NULL ) ; if ( ret < 0 ) { goto fail ; } bs -> read_only = true ; bs -> open_flags &= ~ BDRV_O_RDWR ; return 0 ; fail : error_setg ( errp , " " , errmsg ? : " " ) ; return - EACCES ; }
Called by a driver that can only provide a read-only image.
Called by a driver that can only provide a read - only image .