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

Fix aggressive lvRemove and vgRemove #418

Merged
merged 2 commits into from
Nov 20, 2024
Merged
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
6 changes: 3 additions & 3 deletions config/examples/nnf_nnfstorageprofile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data:
lvChange:
activate: --activate ys $VG_NAME/$LV_NAME
deactivate: --activate n $VG_NAME/$LV_NAME
lvRemove: $VG_NAME
lvRemove: $VG_NAME/$LV_NAME
mkfs: -j2 -p $PROTOCOL -t $CLUSTER_NAME:$LOCK_SPACE $DEVICE
mountRabbit: $DEVICE $MOUNT_PATH
mountCompute: $DEVICE $MOUNT_PATH
Expand All @@ -70,7 +70,7 @@ data:
lvChange:
activate: --activate y $VG_NAME/$LV_NAME
deactivate: --activate n $VG_NAME/$LV_NAME
lvRemove: $VG_NAME
lvRemove: $VG_NAME/$LV_NAME
mkfs: $DEVICE
mountRabbit: $DEVICE $MOUNT_PATH
mountCompute: $DEVICE $MOUNT_PATH
Expand All @@ -90,4 +90,4 @@ data:
lvChange:
activate: --activate y $VG_NAME/$LV_NAME
deactivate: --activate n $VG_NAME/$LV_NAME
lvRemove: $VG_NAME
lvRemove: $VG_NAME/$LV_NAME
8 changes: 7 additions & 1 deletion pkg/blockdevice/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,18 @@ func (l *Lvm) Destroy(ctx context.Context) (bool, error) {
destroyed, err := l.LogicalVolume.Remove(ctx, l.CommandArgs.LvArgs.Remove)
if err != nil {
return false, err

}
if destroyed {
objectDestroyed = true
}

// Check to ensure the VG has no LVs before removing
if count, err := l.VolumeGroup.NumLVs(ctx); err != nil {
return false, err
} else if count != 0 {
return objectDestroyed, nil
}

destroyed, err = l.VolumeGroup.Remove(ctx, l.CommandArgs.VgArgs.Remove)
if err != nil {
return false, 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 @@ -174,7 +174,7 @@ func (vg *VolumeGroup) LockStop(ctx context.Context, rawArgs string) (bool, erro
return false, err
}

if exists == false {
if !exists {
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
}
Loading