static int qemu_gluster_open(BlockDriverState *bs,  QDict *options,

                             int bdrv_flags, Error **errp)

{

    BDRVGlusterState *s = bs->opaque;

    int open_flags = O_BINARY;

    int ret = 0;

    GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));

    QemuOpts *opts;

    Error *local_err = NULL;

    const char *filename;



    opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);

    qemu_opts_absorb_qdict(opts, options, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        ret = -EINVAL;

        goto out;

    }



    filename = qemu_opt_get(opts, "filename");



    s->glfs = qemu_gluster_init(gconf, filename, errp);

    if (!s->glfs) {

        ret = -errno;

        goto out;

    }



    if (bdrv_flags & BDRV_O_RDWR) {

        open_flags |= O_RDWR;

    } else {

        open_flags |= O_RDONLY;

    }



    if ((bdrv_flags & BDRV_O_NOCACHE)) {

        open_flags |= O_DIRECT;

    }



    s->fd = glfs_open(s->glfs, gconf->image, open_flags);

    if (!s->fd) {

        ret = -errno;

    }



out:

    qemu_opts_del(opts);

    qemu_gluster_gconf_free(gconf);

    if (!ret) {

        return ret;

    }

    if (s->fd) {

        glfs_close(s->fd);

    }

    if (s->glfs) {

        glfs_fini(s->glfs);

    }

    return ret;

}

static int qemu_gluster_open(BlockDriverState *bs,  QDict *options,

                             int bdrv_flags, Error **errp)

{

    BDRVGlusterState *s = bs->opaque;

    int open_flags = O_BINARY;

    int ret = 0;

    GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));

    QemuOpts *opts;

    Error *local_err = NULL;

    const char *filename;



    opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);

    qemu_opts_absorb_qdict(opts, options, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        ret = -EINVAL;

        goto out;

    }



    filename = qemu_opt_get(opts, "filename");



    s->glfs = qemu_gluster_init(gconf, filename, errp);

    if (!s->glfs) {

        ret = -errno;

        goto out;

    }



    if (bdrv_flags & BDRV_O_RDWR) {

        open_flags |= O_RDWR;

    } else {

        open_flags |= O_RDONLY;

    }



    if ((bdrv_flags & BDRV_O_NOCACHE)) {

        open_flags |= O_DIRECT;

    }



    s->fd = glfs_open(s->glfs, gconf->image, open_flags);

    if (!s->fd) {

        ret = -errno;

    }



out:

    qemu_opts_del(opts);

    qemu_gluster_gconf_free(gconf);

    if (!ret) {

        return ret;

    }

    if (s->fd) {

        glfs_close(s->fd);

    }

    if (s->glfs) {

        glfs_fini(s->glfs);

    }

    return ret;

}

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

                             int VAR_2, Error **VAR_3)

{

    BDRVGlusterState *s = VAR_0->opaque;

    int VAR_4 = O_BINARY;

    int VAR_5 = 0;

    GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));

    QemuOpts *opts;

    Error *local_err = NULL;

    const char *VAR_6;



    opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);

    qemu_opts_absorb_qdict(opts, VAR_1, &local_err);

    if (local_err) {

        error_propagate(VAR_3, local_err);

        VAR_5 = -EINVAL;

        goto out;

    }



    VAR_6 = qemu_opt_get(opts, "VAR_6");



    s->glfs = qemu_gluster_init(gconf, VAR_6, VAR_3);

    if (!s->glfs) {

        VAR_5 = -errno;

        goto out;

    }



    if (VAR_2 & BDRV_O_RDWR) {

        VAR_4 |= O_RDWR;

    } else {

        VAR_4 |= O_RDONLY;

    }



    if ((VAR_2 & BDRV_O_NOCACHE)) {

        VAR_4 |= O_DIRECT;

    }



    s->fd = glfs_open(s->glfs, gconf->image, VAR_4);

    if (!s->fd) {

        VAR_5 = -errno;

    }



out:

    qemu_opts_del(opts);

    qemu_gluster_gconf_free(gconf);

    if (!VAR_5) {

        return VAR_5;

    }

    if (s->fd) {

        glfs_close(s->fd);

    }

    if (s->glfs) {

        glfs_fini(s->glfs);

    }

    return VAR_5;

}

static int FUNC_0(BlockDriverState *VAR_0,  QDict *VAR_1,
int VAR_2, Error **VAR_3)
{ BDRVGlusterState *s = VAR_0->opaque; int VAR_4 = O_BINARY; int VAR_5 = 0; GlusterConf *gconf = g_malloc0(sizeof(GlusterConf)); QemuOpts *opts; Error *local_err = NULL; const char *VAR_6; opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, VAR_1, &local_err); if (local_err) { error_propagate(VAR_3, local_err); VAR_5 = -EINVAL; goto out; } VAR_6 = qemu_opt_get(opts, "VAR_6"); s->glfs = qemu_gluster_init(gconf, VAR_6, VAR_3); if (!s->glfs) { VAR_5 = -errno; goto out; } if (VAR_2 & BDRV_O_RDWR) { VAR_4 |= O_RDWR; } else { VAR_4 |= O_RDONLY; } if ((VAR_2 & BDRV_O_NOCACHE)) { VAR_4 |= O_DIRECT; } s->fd = glfs_open(s->glfs, gconf->image, VAR_4); if (!s->fd) { VAR_5 = -errno; } out:
qemu_opts_del(opts); qemu_gluster_gconf_free(gconf); if (!VAR_5) { return VAR_5; } if (s->fd) { glfs_close(s->fd); } if (s->glfs) { glfs_fini(s->glfs); } return VAR_5; }