From 5ca51d245b177cef40d16a7cd11722c44b93d00f Mon Sep 17 00:00:00 2001 From: Shuo Wu Date: Tue, 8 Oct 2024 12:42:52 +0800 Subject: [PATCH] fix: spdk replica lists its own lvols Longhorn 9121 Signed-off-by: Shuo Wu --- pkg/spdk/replica.go | 36 ++++++++++++++++++++++++++++++++---- pkg/spdk/types.go | 6 +++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/pkg/spdk/replica.go b/pkg/spdk/replica.go index 387f6770..e76e937a 100644 --- a/pkg/spdk/replica.go +++ b/pkg/spdk/replica.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/pkg/spdk/types.go b/pkg/spdk/types.go index 5e137ebf..d0bb3dfb 100644 --- a/pkg/spdk/types.go +++ b/pkg/spdk/types.go @@ -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 }