static int qemu_rbd_snap_list(BlockDriverState *bs,

                              QEMUSnapshotInfo **psn_tab)

{

    BDRVRBDState *s = bs->opaque;

    QEMUSnapshotInfo *sn_info, *sn_tab = NULL;

    int i, snap_count;

    rbd_snap_info_t *snaps;

    int max_snaps = RBD_MAX_SNAPS;



    do {

        snaps = g_malloc(sizeof(*snaps) * max_snaps);

        snap_count = rbd_snap_list(s->image, snaps, &max_snaps);

        if (snap_count < 0) {

            g_free(snaps);

        }

    } while (snap_count == -ERANGE);



    if (snap_count <= 0) {

        return snap_count;

    }



    sn_tab = g_malloc0(snap_count * sizeof(QEMUSnapshotInfo));



    for (i = 0; i < snap_count; i++) {

        const char *snap_name = snaps[i].name;



        sn_info = sn_tab + i;

        pstrcpy(sn_info->id_str, sizeof(sn_info->id_str), snap_name);

        pstrcpy(sn_info->name, sizeof(sn_info->name), snap_name);



        sn_info->vm_state_size = snaps[i].size;

        sn_info->date_sec = 0;

        sn_info->date_nsec = 0;

        sn_info->vm_clock_nsec = 0;

    }

    rbd_snap_list_end(snaps);



    *psn_tab = sn_tab;

    return snap_count;

}

static int qemu_rbd_snap_list(BlockDriverState *bs,

                              QEMUSnapshotInfo **psn_tab)

{

    BDRVRBDState *s = bs->opaque;

    QEMUSnapshotInfo *sn_info, *sn_tab = NULL;

    int i, snap_count;

    rbd_snap_info_t *snaps;

    int max_snaps = RBD_MAX_SNAPS;



    do {

        snaps = g_malloc(sizeof(*snaps) * max_snaps);

        snap_count = rbd_snap_list(s->image, snaps, &max_snaps);

        if (snap_count < 0) {

            g_free(snaps);

        }

    } while (snap_count == -ERANGE);



    if (snap_count <= 0) {

        return snap_count;

    }



    sn_tab = g_malloc0(snap_count * sizeof(QEMUSnapshotInfo));



    for (i = 0; i < snap_count; i++) {

        const char *snap_name = snaps[i].name;



        sn_info = sn_tab + i;

        pstrcpy(sn_info->id_str, sizeof(sn_info->id_str), snap_name);

        pstrcpy(sn_info->name, sizeof(sn_info->name), snap_name);



        sn_info->vm_state_size = snaps[i].size;

        sn_info->date_sec = 0;

        sn_info->date_nsec = 0;

        sn_info->vm_clock_nsec = 0;

    }

    rbd_snap_list_end(snaps);



    *psn_tab = sn_tab;

    return snap_count;

}

static int FUNC_0(BlockDriverState *VAR_0,

                              QEMUSnapshotInfo **VAR_1)

{

    BDRVRBDState *s = VAR_0->opaque;

    QEMUSnapshotInfo *sn_info, *sn_tab = NULL;

    int VAR_2, VAR_3;

    rbd_snap_info_t *snaps;

    int VAR_4 = RBD_MAX_SNAPS;



    do {

        snaps = g_malloc(sizeof(*snaps) * VAR_4);

        VAR_3 = rbd_snap_list(s->image, snaps, &VAR_4);

        if (VAR_3 < 0) {

            g_free(snaps);

        }

    } while (VAR_3 == -ERANGE);



    if (VAR_3 <= 0) {

        return VAR_3;

    }



    sn_tab = g_malloc0(VAR_3 * sizeof(QEMUSnapshotInfo));



    for (VAR_2 = 0; VAR_2 < VAR_3; VAR_2++) {

        const char *VAR_5 = snaps[VAR_2].name;



        sn_info = sn_tab + VAR_2;

        pstrcpy(sn_info->id_str, sizeof(sn_info->id_str), VAR_5);

        pstrcpy(sn_info->name, sizeof(sn_info->name), VAR_5);



        sn_info->vm_state_size = snaps[VAR_2].size;

        sn_info->date_sec = 0;

        sn_info->date_nsec = 0;

        sn_info->vm_clock_nsec = 0;

    }

    rbd_snap_list_end(snaps);



    *VAR_1 = sn_tab;

    return VAR_3;

}

static int FUNC_0(BlockDriverState *VAR_0,
QEMUSnapshotInfo **VAR_1)
{ BDRVRBDState *s = VAR_0->opaque; QEMUSnapshotInfo *sn_info, *sn_tab = NULL; int VAR_2, VAR_3; rbd_snap_info_t *snaps; int VAR_4 = RBD_MAX_SNAPS; do { snaps = g_malloc(sizeof(*snaps) * VAR_4); VAR_3 = rbd_snap_list(s->image, snaps, &VAR_4); if (VAR_3 < 0) { g_free(snaps); } } while (VAR_3 == -ERANGE); if (VAR_3 <= 0) { return VAR_3; } sn_tab = g_malloc0(VAR_3 * sizeof(QEMUSnapshotInfo)); for (VAR_2 = 0; VAR_2 < VAR_3; VAR_2++) { const char *VAR_5 = snaps[VAR_2].name; sn_info = sn_tab + VAR_2; pstrcpy(sn_info->id_str, sizeof(sn_info->id_str), VAR_5); pstrcpy(sn_info->name, sizeof(sn_info->name), VAR_5); sn_info->vm_state_size = snaps[VAR_2].size; sn_info->date_sec = 0; sn_info->date_nsec = 0; sn_info->vm_clock_nsec = 0; } rbd_snap_list_end(snaps); *VAR_1 = sn_tab; return VAR_3; }