Skip to content

Commit

Permalink
Fix aggressive lvRemove and vgRemove (#418)
Browse files Browse the repository at this point in the history
The default storage profile was only using the $VG_NAME, causing
lvRemove to remove all logical volumes in the volume group.
Additionally, volume groups were being removed without first checking to
see if logical volumes exist in the volume group.

While both of these issues have no real affect on the removal of the
LVs/VGs, this was causing issues with the new PreUnmount commands. The
first logical volume to run the lvRemove command was the only
fileysystem to run the PreUnmount commands, since it destroys all the
other filesystems on the rabbit in that single volume group.

With this change, the PreUnmmount command runs on each filesystem before
it is destroyed.

Signed-off-by: Blake Devcich <[email protected]>
  • Loading branch information
bdevcich authored Nov 20, 2024
1 parent 35b9db1 commit 5fbad90
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
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
}

0 comments on commit 5fbad90

Please sign in to comment.