Skip to content

Commit

Permalink
fix: spdk replica lists its own lvols
Browse files Browse the repository at this point in the history
Longhorn 9121

Signed-off-by: Shuo Wu <[email protected]>
  • Loading branch information
shuo-wu committed Oct 8, 2024
1 parent 117e089 commit 5ca51d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
36 changes: 32 additions & 4 deletions pkg/spdk/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,14 @@ func (r *Replica) Sync(spdkClient *spdkclient.Client) (err error) {
// It's better to let the server send the update signal

// This lvol and nvmf subsystem fetch should be protected by replica lock, in case of snapshot operations happened during the sync-up.
bdevLvolMap, err := GetBdevLvolMap(spdkClient)
replicaLvolFilter := func(bdev *spdktypes.BdevInfo) bool {
var lvolName string
if len(bdev.Aliases) == 1 {
lvolName = spdktypes.GetLvolNameFromAlias(bdev.Aliases[0])
}
return IsReplicaLvol(r.Name, lvolName) || (r.ActiveChain[0] != nil && r.ActiveChain[0].Name == lvolName)
}
bdevLvolMap, err := GetBdevLvolMapWithFilter(spdkClient, replicaLvolFilter)
if err != nil {
return err
}
Expand Down Expand Up @@ -762,7 +769,14 @@ func (r *Replica) Delete(spdkClient *spdkclient.Client, cleanupRequired bool, su

// Clean up the valid snapshot tree
if len(r.ActiveChain) > 1 {
bdevLvolMap, err := GetBdevLvolMap(spdkClient)
replicaLvolFilter := func(bdev *spdktypes.BdevInfo) bool {
var lvolName string
if len(bdev.Aliases) == 1 {
lvolName = spdktypes.GetLvolNameFromAlias(bdev.Aliases[0])
}
return IsReplicaLvol(r.Name, lvolName) || (r.ActiveChain[0] != nil && r.ActiveChain[0].Name == lvolName)
}
bdevLvolMap, err := GetBdevLvolMapWithFilter(spdkClient, replicaLvolFilter)
if err != nil {
return err
}
Expand Down Expand Up @@ -1036,7 +1050,14 @@ func (r *Replica) SnapshotRevert(spdkClient *spdkclient.Client, snapshotName str
return nil, err
}

bdevLvolMap, err := GetBdevLvolMap(spdkClient)
replicaLvolFilter := func(bdev *spdktypes.BdevInfo) bool {
var lvolName string
if len(bdev.Aliases) == 1 {
lvolName = spdktypes.GetLvolNameFromAlias(bdev.Aliases[0])
}
return IsReplicaLvol(r.Name, lvolName) || (r.ActiveChain[0] != nil && r.ActiveChain[0].Name == lvolName)
}
bdevLvolMap, err := GetBdevLvolMapWithFilter(spdkClient, replicaLvolFilter)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1490,7 +1511,14 @@ func (r *Replica) RebuildingDstFinish(spdkClient *spdkclient.Client) (err error)

r.doCleanupForRebuildingDst(spdkClient, r.rebuildingDstCache.rebuildingState == types.ProgressStateError)

bdevLvolMap, err := GetBdevLvolMap(spdkClient)
replicaLvolFilter := func(bdev *spdktypes.BdevInfo) bool {
var lvolName string
if len(bdev.Aliases) == 1 {
lvolName = spdktypes.GetLvolNameFromAlias(bdev.Aliases[0])
}
return IsReplicaLvol(r.Name, lvolName) || (r.ActiveChain[0] != nil && r.ActiveChain[0].Name == lvolName)
}
bdevLvolMap, err := GetBdevLvolMapWithFilter(spdkClient, replicaLvolFilter)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/spdk/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ func GetBdevMap(cli *spdkclient.Client) (map[string]*spdktypes.BdevInfo, error)
}

func GetBdevLvolMap(cli *spdkclient.Client) (map[string]*spdktypes.BdevInfo, error) {
bdevList, err := cli.BdevLvolGet("", 0)
return GetBdevLvolMapWithFilter(cli, func(*spdktypes.BdevInfo) bool { return true })
}

func GetBdevLvolMapWithFilter(cli *spdkclient.Client, filter func(*spdktypes.BdevInfo) bool) (map[string]*spdktypes.BdevInfo, error) {
bdevList, err := cli.BdevLvolGetWithFilter("", 0, filter)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5ca51d2

Please sign in to comment.