static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,

                     Error **errp)

{

    char *buf;

    int ret;

    BDRVVmdkState *s = bs->opaque;

    uint32_t magic;



    buf = vmdk_read_desc(bs->file, 0, errp);

    if (!buf) {

        return -EINVAL;

    }



    magic = ldl_be_p(buf);

    switch (magic) {

        case VMDK3_MAGIC:

        case VMDK4_MAGIC:

            ret = vmdk_open_sparse(bs, bs->file, flags, buf, errp);

            s->desc_offset = 0x200;

            break;

        default:

            ret = vmdk_open_desc_file(bs, flags, buf, errp);

            break;

    }

    if (ret) {

        goto fail;

    }



    /* try to open parent images, if exist */

    ret = vmdk_parent_open(bs);

    if (ret) {

        goto fail;

    }

    s->cid = vmdk_read_cid(bs, 0);

    s->parent_cid = vmdk_read_cid(bs, 1);

    qemu_co_mutex_init(&s->lock);



    /* Disable migration when VMDK images are used */

    error_setg(&s->migration_blocker, "The vmdk format used by node '%s' "

               "does not support live migration",

               bdrv_get_device_or_node_name(bs));

    migrate_add_blocker(s->migration_blocker);

    g_free(buf);

    return 0;



fail:

    g_free(buf);

    g_free(s->create_type);

    s->create_type = NULL;

    vmdk_free_extents(bs);

    return ret;

}

static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,

                     Error **errp)

{

    char *buf;

    int ret;

    BDRVVmdkState *s = bs->opaque;

    uint32_t magic;



    buf = vmdk_read_desc(bs->file, 0, errp);

    if (!buf) {

        return -EINVAL;

    }



    magic = ldl_be_p(buf);

    switch (magic) {

        case VMDK3_MAGIC:

        case VMDK4_MAGIC:

            ret = vmdk_open_sparse(bs, bs->file, flags, buf, errp);

            s->desc_offset = 0x200;

            break;

        default:

            ret = vmdk_open_desc_file(bs, flags, buf, errp);

            break;

    }

    if (ret) {

        goto fail;

    }



    

    ret = vmdk_parent_open(bs);

    if (ret) {

        goto fail;

    }

    s->cid = vmdk_read_cid(bs, 0);

    s->parent_cid = vmdk_read_cid(bs, 1);

    qemu_co_mutex_init(&s->lock);



    

    error_setg(&s->migration_blocker, "The vmdk format used by node '%s' "

               "does not support live migration",

               bdrv_get_device_or_node_name(bs));

    migrate_add_blocker(s->migration_blocker);

    g_free(buf);

    return 0;



fail:

    g_free(buf);

    g_free(s->create_type);

    s->create_type = NULL;

    vmdk_free_extents(bs);

    return ret;

}

static int FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1, int VAR_2,

                     Error **VAR_3)

{

    char *VAR_4;

    int VAR_5;

    BDRVVmdkState *s = VAR_0->opaque;

    uint32_t magic;



    VAR_4 = vmdk_read_desc(VAR_0->file, 0, VAR_3);

    if (!VAR_4) {

        return -EINVAL;

    }



    magic = ldl_be_p(VAR_4);

    switch (magic) {

        case VMDK3_MAGIC:

        case VMDK4_MAGIC:

            VAR_5 = vmdk_open_sparse(VAR_0, VAR_0->file, VAR_2, VAR_4, VAR_3);

            s->desc_offset = 0x200;

            break;

        default:

            VAR_5 = vmdk_open_desc_file(VAR_0, VAR_2, VAR_4, VAR_3);

            break;

    }

    if (VAR_5) {

        goto fail;

    }



    

    VAR_5 = vmdk_parent_open(VAR_0);

    if (VAR_5) {

        goto fail;

    }

    s->cid = vmdk_read_cid(VAR_0, 0);

    s->parent_cid = vmdk_read_cid(VAR_0, 1);

    qemu_co_mutex_init(&s->lock);



    

    error_setg(&s->migration_blocker, "The vmdk format used by node '%s' "

               "does not support live migration",

               bdrv_get_device_or_node_name(VAR_0));

    migrate_add_blocker(s->migration_blocker);

    g_free(VAR_4);

    return 0;



fail:

    g_free(VAR_4);

    g_free(s->create_type);

    s->create_type = NULL;

    vmdk_free_extents(VAR_0);

    return VAR_5;

}

static int FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1, int VAR_2,
Error **VAR_3)
{ char *VAR_4; int VAR_5; BDRVVmdkState *s = VAR_0->opaque; uint32_t magic; VAR_4 = vmdk_read_desc(VAR_0->file, 0, VAR_3); if (!VAR_4) { return -EINVAL; } magic = ldl_be_p(VAR_4); switch (magic) { case VMDK3_MAGIC:
case VMDK4_MAGIC:
VAR_5 = vmdk_open_sparse(VAR_0, VAR_0->file, VAR_2, VAR_4, VAR_3); s->desc_offset = 0x200; break; default:
VAR_5 = vmdk_open_desc_file(VAR_0, VAR_2, VAR_4, VAR_3); break; } if (VAR_5) { goto fail; } VAR_5 = vmdk_parent_open(VAR_0); if (VAR_5) { goto fail; } s->cid = vmdk_read_cid(VAR_0, 0); s->parent_cid = vmdk_read_cid(VAR_0, 1); qemu_co_mutex_init(&s->lock); error_setg(&s->migration_blocker, "The vmdk format used by node '%s' "
"does not support live migration",
bdrv_get_device_or_node_name(VAR_0)); migrate_add_blocker(s->migration_blocker); g_free(VAR_4); return 0; fail:
g_free(VAR_4); g_free(s->create_type); s->create_type = NULL; vmdk_free_extents(VAR_0); return VAR_5; }