Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bdevcich committed Nov 20, 2024
1 parent 04251c9 commit 1e4a84c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
10 changes: 3 additions & 7 deletions pkg/blockdevice/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,10 @@ func (l *Lvm) Destroy(ctx context.Context) (bool, error) {
}

// Check to ensure the VG has no LVs before removing
lvs, err := lvm.LvsListVolumes(ctx, l.VolumeGroup.Log)
if err != nil {
if count, err := l.VolumeGroup.NumLVs(ctx); err != nil {
return false, err
}
for _, lv := range lvs {
if lv.VGName == l.VolumeGroup.Name {
return false, nil
}
} else if count != 0 {
return objectDestroyed, nil
}

destroyed, err = l.VolumeGroup.Remove(ctx, l.CommandArgs.VgArgs.Remove)
Expand Down
10 changes: 5 additions & 5 deletions pkg/blockdevice/lvm/logical_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewLogicalVolume(ctx context.Context, name string, vg *VolumeGroup, size in

// Exists determines if the LV exists in the OS
func (lv *LogicalVolume) Exists(ctx context.Context) (bool, error) {
existingLVs, err := LvsListVolumes(ctx, lv.Log)
existingLVs, err := lvsListVolumes(ctx, lv.Log)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func (lv *LogicalVolume) Create(ctx context.Context, rawArgs string) (bool, erro
return false, err
}

existingLVs, err := LvsListVolumes(ctx, lv.Log)
existingLVs, err := lvsListVolumes(ctx, lv.Log)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func (lv *LogicalVolume) Remove(ctx context.Context, rawArgs string) (bool, erro
return false, err
}

existingLVs, err := LvsListVolumes(ctx, lv.Log)
existingLVs, err := lvsListVolumes(ctx, lv.Log)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func (lv *LogicalVolume) Activate(ctx context.Context, rawArgs string) (bool, er
return false, nil
}

existingLVs, err := LvsListVolumes(ctx, lv.Log)
existingLVs, err := lvsListVolumes(ctx, lv.Log)
if err != nil {
return false, err
}
Expand All @@ -189,7 +189,7 @@ func (lv *LogicalVolume) Deactivate(ctx context.Context, rawArgs string) (bool,
return false, nil
}

existingLVs, err := LvsListVolumes(ctx, lv.Log)
existingLVs, err := lvsListVolumes(ctx, lv.Log)
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/blockdevice/lvm/lvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type lvsLogicalVolume struct {
Size string `json:"lv_size"`
}

func LvsListVolumes(ctx context.Context, log logr.Logger) ([]lvsLogicalVolume, error) {
func lvsListVolumes(ctx context.Context, log logr.Logger) ([]lvsLogicalVolume, error) {
output, err := command.Run("lvs --nolock --reportformat json", log)
if err != nil {
return nil, fmt.Errorf("could not list logical volumes: %w", err)
Expand Down
18 changes: 17 additions & 1 deletion pkg/blockdevice/lvm/volume_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (vg *VolumeGroup) LockStop(ctx context.Context, rawArgs string) (bool, erro
return false, nil
}

lvs, err := LvsListVolumes(ctx, vg.Log)
lvs, err := lvsListVolumes(ctx, vg.Log)
for _, lv := range lvs {
if lv.VGName == vg.Name && lv.Attrs[4] == 'a' {
return false, nil
Expand Down Expand Up @@ -211,3 +211,19 @@ func (vg *VolumeGroup) Remove(ctx context.Context, rawArgs string) (bool, error)

return false, nil
}

func (vg *VolumeGroup) NumLVs(ctx context.Context) (int, error) {
count := 0

lvs, err := lvsListVolumes(ctx, vg.Log)
if err != nil {
return count, err
}
for _, lv := range lvs {
if lv.VGName == vg.Name {
count += 1
}
}

return count, nil
}

0 comments on commit 1e4a84c

Please sign in to comment.