func (p *Pool) wrapOpen(imageName string, action func(*C.rbd_image_t) error) error { image := C.make_image() imageStr := C.CString(imageName) defer func() { C.free(unsafe.Pointer(image)) C.free(unsafe.Pointer(imageStr)) }() if i, err := C.rbd_open(p.ioctx, imageStr, image, nil); err != nil || i < 0 { if i < 0 { err = strerror(i) } return fmt.Errorf("Error creating snapshot: %v", err) } defer func() error { if i, err := C.rbd_close(*image); err != nil || i < 0 { if i < 0 { err = strerror(i) } return fmt.Errorf("Error creating snapshot: %v", err) } return nil }() if err := action(image); err != nil { return err } return nil }
// int rbd_close(rbd_image_t image); func (image *Image) Close() error { if image.image == nil { return RbdErrorImageNotOpen } ret := C.rbd_close(image.image) if ret != 0 { return RBDError(ret) } image.image = nil return nil }