mirror of https://github.com/ceph/go-ceph
Add rbd_get_parent_info
Signed-off-by: Ye Yin <eyniy@qq.com>
This commit is contained in:
parent
8f882afdc3
commit
80e3e9ea7f
19
rbd/rbd.go
19
rbd/rbd.go
|
@ -741,6 +741,25 @@ func (image *Image) GetSnapshot(snapname string) *Snapshot {
|
|||
}
|
||||
}
|
||||
|
||||
// int rbd_get_parent_info(rbd_image_t image,
|
||||
// char *parent_pool_name, size_t ppool_namelen, char *parent_name,
|
||||
// size_t pnamelen, char *parent_snap_name, size_t psnap_namelen)
|
||||
func (image *Image) GetParentInfo(p_pool, p_name, p_snapname []byte) error {
|
||||
ret := C.rbd_get_parent_info(
|
||||
image.image,
|
||||
(*C.char)(unsafe.Pointer(&p_pool[0])),
|
||||
(C.size_t)(len(p_pool)),
|
||||
(*C.char)(unsafe.Pointer(&p_name[0])),
|
||||
(C.size_t)(len(p_name)),
|
||||
(*C.char)(unsafe.Pointer(&p_snapname[0])),
|
||||
(C.size_t)(len(p_snapname)))
|
||||
if ret == 0 {
|
||||
return nil
|
||||
} else {
|
||||
return RBDError(int(ret))
|
||||
}
|
||||
}
|
||||
|
||||
// int rbd_snap_remove(rbd_image_t image, const char *snapname);
|
||||
func (snapshot *Snapshot) Remove() error {
|
||||
var c_snapname *C.char = C.CString(snapshot.name)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package rbd_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/noahdesu/go-ceph/rados"
|
||||
"github.com/noahdesu/go-ceph/rbd"
|
||||
|
@ -161,3 +162,71 @@ func TestCreateSnapshot(t *testing.T) {
|
|||
conn.DeletePool(poolname)
|
||||
conn.Shutdown()
|
||||
}
|
||||
|
||||
func TestParentInfo(t *testing.T) {
|
||||
conn, _ := rados.NewConn()
|
||||
conn.ReadDefaultConfigFile()
|
||||
conn.Connect()
|
||||
|
||||
poolname := GetUUID()
|
||||
err := conn.MakePool(poolname)
|
||||
assert.NoError(t, err)
|
||||
|
||||
ioctx, err := conn.OpenIOContext(poolname)
|
||||
assert.NoError(t, err)
|
||||
|
||||
name := "parent"
|
||||
img, err := rbd.Create(ioctx, name, 1<<22, 1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = img.Open()
|
||||
assert.NoError(t, err)
|
||||
|
||||
snapshot, err := img.CreateSnapshot("mysnap")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = snapshot.Protect()
|
||||
assert.NoError(t, err)
|
||||
|
||||
imgNew, err := img.Clone("mysnap", ioctx, "child", 1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = imgNew.Open()
|
||||
assert.NoError(t, err)
|
||||
parentPool := make([]byte, 128)
|
||||
parentName := make([]byte, 128)
|
||||
parentSnapname := make([]byte, 128)
|
||||
|
||||
err = imgNew.GetParentInfo(parentPool, parentName, parentSnapname)
|
||||
assert.NoError(t, err)
|
||||
|
||||
n := bytes.Index(parentName, []byte{0})
|
||||
pName := string(parentName[:n])
|
||||
|
||||
n = bytes.Index(parentSnapname, []byte{0})
|
||||
pSnapname := string(parentSnapname[:n])
|
||||
assert.Equal(t, pName, "parent", "they should be equal")
|
||||
assert.Equal(t, pSnapname, "mysnap", "they should be equal")
|
||||
|
||||
err = imgNew.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = imgNew.Remove()
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = snapshot.Unprotect()
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = snapshot.Remove()
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = img.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = img.Remove()
|
||||
assert.NoError(t, err)
|
||||
|
||||
ioctx.Destroy()
|
||||
conn.DeletePool(poolname)
|
||||
conn.Shutdown()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue