// int rbd_snap_list(rbd_image_t image, rbd_snap_info_t *snaps, int *max_snaps); // void rbd_snap_list_end(rbd_snap_info_t *snaps); func (image *Image) GetSnapshotNames() (snaps []SnapInfo, err error) { if image.image == nil { return nil, RbdErrorImageNotOpen } var c_max_snaps C.int = 0 ret := C.rbd_snap_list(image.image, nil, &c_max_snaps) c_snaps := make([]C.rbd_snap_info_t, c_max_snaps) snaps = make([]SnapInfo, c_max_snaps) ret = C.rbd_snap_list(image.image, &c_snaps[0], &c_max_snaps) if ret < 0 { return nil, RBDError(int(ret)) } for i, s := range c_snaps { snaps[i] = SnapInfo{Id: uint64(s.id), Size: uint64(s.size), Name: C.GoString(s.name)} } C.rbd_snap_list_end(&c_snaps[0]) return snaps[:len(snaps)-1], nil }
// ListSnapshots yields a list of the snapshots for the given interface. max // will yield a maximum of N items. func (img *Image) ListSnapshots(max int) ([]string, error) { snapInfo := make([]C.rbd_snap_info_t, max) list := []string{} cMax := C.int(max) action := func(image *C.rbd_image_t) error { if i, err := C.rbd_snap_list(*image, &snapInfo[0], &cMax); err != nil || i < 0 { return strerror(i) } for i := 0; i < int(cMax); i++ { if C.GoString(snapInfo[i].name) == "" { return nil } list = append(list, C.GoString(snapInfo[i].name)) } return nil } if err := img.pool.wrapOpen(img.imageName, action); err != nil { return nil, err } return list, nil }