Exemplo n.º 1
0
// int rbd_snap_create(rbd_image_t image, const char *snapname);
func (image *Image) CreateSnapshot(snapname string) (*Snapshot, error) {
	if image.image == nil {
		return nil, RbdErrorImageNotOpen
	}

	var c_snapname *C.char = C.CString(snapname)
	defer C.free(unsafe.Pointer(c_snapname))

	ret := C.rbd_snap_create(image.image, c_snapname)
	if ret < 0 {
		return nil, RBDError(int(ret))
	}

	return &Snapshot{
		image: image,
		name:  snapname,
	}, nil
}
Exemplo n.º 2
0
// CreateSnapshot creates a named snapshot for the image provided.
func (img *Image) CreateSnapshot(snapshotName string) error {
	snapshotStr := C.CString(snapshotName)
	defer func() {
		C.free(unsafe.Pointer(snapshotStr))
	}()

	action := func(image *C.rbd_image_t) error {
		if i, err := C.rbd_snap_create(*image, snapshotStr); err != nil || i < 0 {
			if i < 0 {
				err = strerror(i)
			}

			return fmt.Errorf("Error creating snapshot: %v", err)
		}

		return nil
	}

	if err := img.pool.wrapOpen(img.imageName, action); err != nil {
		return err
	}

	return nil
}