Skip to content

Commit

Permalink
refactor: abstract replicaLvolFilter as a func
Browse files Browse the repository at this point in the history
Signed-off-by: Shuo Wu <[email protected]>
  • Loading branch information
shuo-wu committed Oct 25, 2024
1 parent d7bbc6d commit 9d3aad7
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions pkg/spdk/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,21 @@ func NewReplica(ctx context.Context, replicaName, lvsName, lvsUUID string, specS
}
}

func (r *Replica) replicaLvolFilter(bdev *spdktypes.BdevInfo) bool {
if len(bdev.Aliases) < 1 {
return false

Check warning on line 187 in pkg/spdk/replica.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/replica.go#L185-L187

Added lines #L185 - L187 were not covered by tests
}
lvolName := spdktypes.GetLvolNameFromAlias(bdev.Aliases[0])
return IsReplicaLvol(r.Name, lvolName) || (len(r.ActiveChain) > 0 && r.ActiveChain[0] != nil && r.ActiveChain[0].Name == lvolName)

Check warning on line 190 in pkg/spdk/replica.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/replica.go#L189-L190

Added lines #L189 - L190 were not covered by tests
}

func (r *Replica) Sync(spdkClient *spdkclient.Client) (err error) {
r.Lock()
defer r.Unlock()
// 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.
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)
bdevLvolMap, err := GetBdevLvolMapWithFilter(spdkClient, r.replicaLvolFilter)

Check warning on line 199 in pkg/spdk/replica.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/replica.go#L199

Added line #L199 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -825,14 +826,7 @@ func (r *Replica) Delete(spdkClient *spdkclient.Client, cleanupRequired bool, su

// Clean up the valid snapshot tree
if len(r.ActiveChain) > 1 {
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)
bdevLvolMap, err := GetBdevLvolMapWithFilter(spdkClient, r.replicaLvolFilter)

Check warning on line 829 in pkg/spdk/replica.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/replica.go#L829

Added line #L829 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -1106,14 +1100,7 @@ func (r *Replica) SnapshotRevert(spdkClient *spdkclient.Client, snapshotName str
return nil, err
}

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)
bdevLvolMap, err := GetBdevLvolMapWithFilter(spdkClient, r.replicaLvolFilter)

Check warning on line 1103 in pkg/spdk/replica.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/replica.go#L1103

Added line #L1103 was not covered by tests
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1569,14 +1556,7 @@ func (r *Replica) RebuildingDstFinish(spdkClient *spdkclient.Client) (err error)

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

Check warning on line 1557 in pkg/spdk/replica.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/replica.go#L1557

Added line #L1557 was not covered by tests

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)
bdevLvolMap, err := GetBdevLvolMapWithFilter(spdkClient, r.replicaLvolFilter)

Check warning on line 1559 in pkg/spdk/replica.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/replica.go#L1559

Added line #L1559 was not covered by tests
if err != nil {
return err
}
Expand Down

0 comments on commit 9d3aad7

Please sign in to comment.