mirror of
https://github.com/ceph/go-ceph
synced 2025-02-03 20:12:14 +00:00
rados: add wrapper for rados_ioctx_snap_list() function
Signed-off-by Mudit Agarwal <muagarwa@redhat.com>
This commit is contained in:
parent
ff1ce13478
commit
62f5881485
@ -117,3 +117,35 @@ func (ioctx *IOContext) GetSnapStamp(snapID SnapID) (time.Time, error) {
|
||||
&cTime)
|
||||
return time.Unix(int64(cTime), 0), getError(ret)
|
||||
}
|
||||
|
||||
// ListSnaps returns a slice containing the SnapIDs of existing pool snapshots.
|
||||
//
|
||||
// Implements:
|
||||
// int rados_ioctx_snap_list(rados_ioctx_t io, rados_snap_t *snaps, int maxlen)
|
||||
func (ioctx *IOContext) ListSnaps() ([]SnapID, error) {
|
||||
if err := ioctx.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
snapList []SnapID
|
||||
cLen C.int
|
||||
err error
|
||||
ret C.int
|
||||
)
|
||||
retry.WithSizes(100, 1000, func(maxlen int) retry.Hint {
|
||||
cLen = C.int(maxlen)
|
||||
snapList = make([]SnapID, cLen)
|
||||
ret = C.rados_ioctx_snap_list(
|
||||
ioctx.ioctx,
|
||||
(*C.rados_snap_t)(unsafe.Pointer(&snapList[0])),
|
||||
cLen)
|
||||
err = getErrorIfNegative(ret)
|
||||
return retry.Size(int(cLen)).If(err == errRange)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return snapList[:ret], nil
|
||||
}
|
||||
|
@ -136,3 +136,54 @@ func (suite *RadosTestSuite) TestSnapshotIDFunctions() {
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func (suite *RadosTestSuite) TestListSnapshot() {
|
||||
suite.SetupConnection()
|
||||
ioctx, err := suite.conn.OpenIOContext(suite.pool)
|
||||
require.NoError(suite.T(), err)
|
||||
|
||||
snapName := []string{"snap1", "snap2", "snap3"}
|
||||
err = ioctx.CreateSnap(snapName[0])
|
||||
assert.NoError(suite.T(), err)
|
||||
defer func() {
|
||||
assert.NoError(suite.T(), ioctx.RemoveSnap(snapName[0]))
|
||||
}()
|
||||
|
||||
err = ioctx.CreateSnap(snapName[1])
|
||||
assert.NoError(suite.T(), err)
|
||||
defer func() {
|
||||
assert.NoError(suite.T(), ioctx.RemoveSnap(snapName[1]))
|
||||
}()
|
||||
|
||||
err = ioctx.CreateSnap(snapName[2])
|
||||
assert.NoError(suite.T(), err)
|
||||
defer func() {
|
||||
assert.NoError(suite.T(), ioctx.RemoveSnap(snapName[2]))
|
||||
}()
|
||||
|
||||
suite.T().Run("invalidIOContext", func(t *testing.T) {
|
||||
ioctx := &IOContext{}
|
||||
_, err := ioctx.ListSnaps()
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, err, ErrInvalidIOContext)
|
||||
})
|
||||
|
||||
snapList, err := ioctx.ListSnaps()
|
||||
assert.NoError(suite.T(), err)
|
||||
assert.NotNil(suite.T(), snapList)
|
||||
|
||||
listLen := len(snapList)
|
||||
|
||||
suite.T().Run("NumberOfSnapshots", func(t *testing.T) {
|
||||
assert.Equal(t, 3, listLen)
|
||||
})
|
||||
|
||||
suite.T().Run("MatchSnapNamesWithID", func(t *testing.T) {
|
||||
for _, id := range snapList[0 : listLen-1] {
|
||||
retName, err := ioctx.GetSnapName(id)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, retName)
|
||||
assert.Contains(t, snapName, retName)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user