Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add func BdevLvolGetWithFilter #151

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkg/spdk/client/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ func (c *Client) BdevLvolDelete(name string) (deleted bool, err error) {
//
// "timeout": Optional. 0 by default, meaning the method returns immediately whether the lvol bdev exists or not.
func (c *Client) BdevLvolGet(name string, timeout uint64) (bdevLvolInfoList []spdktypes.BdevInfo, err error) {
return c.BdevLvolGetWithFilter(name, timeout, func(*spdktypes.BdevInfo) bool { return true })
}

// BdevLvolGetWithFilter gets information about some specific lvol bdevs.
//
// "name": Optional. UUID or alias of a logical volume (lvol) bdev.
// The alias of a lvol bdev is <LVSTORE NAME>/<LVOL NAME>. And the name of a lvol bdev is UUID.
// If this is not specified, the function will list all lvol bdevs.
//
// "timeout": Optional. 0 by default, meaning the method returns immediately whether the lvol bdev exists or not.
//
// "filter": Only the lvol bdevs that pass the filter will be returned.
func (c *Client) BdevLvolGetWithFilter(name string, timeout uint64, filter func(*spdktypes.BdevInfo) bool) (bdevLvolInfoList []spdktypes.BdevInfo, err error) {
req := spdktypes.BdevGetBdevsRequest{
Name: name,
Timeout: timeout,
Expand All @@ -269,7 +282,9 @@ func (c *Client) BdevLvolGet(name string, timeout uint64) (bdevLvolInfoList []sp
if spdktypes.GetBdevType(&b) != spdktypes.BdevTypeLvol {
continue
}

if !filter(&b) {
continue
}
b.DriverSpecific.Lvol.Xattrs = make(map[string]string)
user_created, err := c.BdevLvolGetXattr(b.Name, UserCreated)
if err == nil {
Expand Down
23 changes: 15 additions & 8 deletions pkg/spdk/spdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,22 @@ func (s *TestSuite) TestSPDKBasic(c *C) {
c.Assert(deleted, Equals, true)
}()

lvolList, err := spdkCli.BdevLvolGet("", 0)
lvolFilter1 := func(bdev *spdktypes.BdevInfo) bool {
return bdev.DriverSpecific.Lvol != nil && bdev.UUID == lvolUUID1
}
lvolList1, err := spdkCli.BdevLvolGetWithFilter("", 0, lvolFilter1)
c.Assert(err, IsNil)
c.Assert(len(lvolList), Equals, 2)
c.Assert(len(lvolList1), Equals, 1)
c.Assert(lvolList1[0].Aliases[0], Equals, fmt.Sprintf("%s/%s", lvsName, lvolName1))
lvolFilter2 := func(bdev *spdktypes.BdevInfo) bool {
return bdev.DriverSpecific.Lvol != nil && bdev.UUID == lvolUUID2
}
lvolList2, err := spdkCli.BdevLvolGetWithFilter("", 0, lvolFilter2)
c.Assert(err, IsNil)
c.Assert(len(lvolList2), Equals, 1)
c.Assert(lvolList2[0].Aliases[0], Equals, fmt.Sprintf("%s/%s", lvsName, lvolName2))

lvolList := append(lvolList1, lvolList2...)
for _, lvol := range lvolList {
c.Assert(len(lvol.Aliases), Equals, 1)
c.Assert(uint64(lvol.BlockSize)*lvol.NumBlocks, Equals, defaultLvolSizeInMiB*types.MiB)
Expand All @@ -175,12 +188,6 @@ func (s *TestSuite) TestSPDKBasic(c *C) {
c.Assert(lvol.DriverSpecific.Lvol.Snapshot, Equals, false)
c.Assert(lvol.DriverSpecific.Lvol.Clone, Equals, false)
c.Assert(lvol.DriverSpecific.Lvol.LvolStoreUUID, Equals, lvsUUID)
if lvol.UUID == lvolUUID1 {
c.Assert(lvol.Aliases[0], Equals, fmt.Sprintf("%s/%s", lvsName, lvolName1))
}
if lvol.UUID == lvolUUID2 {
c.Assert(lvol.Aliases[0], Equals, fmt.Sprintf("%s/%s", lvsName, lvolName2))
}
c.Assert(lvol.DriverSpecific.Lvol.Xattrs[client.UserCreated], Equals, "true")
c.Assert(lvol.DriverSpecific.Lvol.Xattrs[client.SnapshotTimestamp], Equals, "")
}
Expand Down
Loading