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 1 commit
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
12 changes: 11 additions & 1 deletion pkg/blockdevice/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,22 @@ 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
lvs, err := lvm.LvsListVolumes(ctx, l.VolumeGroup.Log)
if err != nil {
return false, err
}
for _, lv := range lvs {
if lv.VGName == l.VolumeGroup.Name {
return false, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be true since it destroyed the LV?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, hitting this line means that there is another LV that is still using the VG. This LV is now gone, but there are still others.

Do I have that wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. But because we removed the block device associated with this allocation (the logical volume), I think we should return true here. The last allocation to remove the LV will clean up the VG and PVs as well, but I don't think the caller of this function should care about that distinction.

I didn't verify, but probably everywhere Destroy() is called, the ran return value probably just controls whether a log message is printed. So either way the stakes are low :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you're saying now. I'll change that.

This got me thinking though: if we remove all the LVs and then somehow on the last one we don't remove the VG because lvs is stale or something. A. is that possible and B. are we going to leave around a VG in that scenario?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can trust lvs. Even if something weird does happen, we'll still delete the NVMe namespaces, so we won't really be stranding any space. LVM will be a little confused because the block devices got torn down underneath it, but even that will eventually get cleaned up.

}
}

destroyed, err = l.VolumeGroup.Remove(ctx, l.CommandArgs.VgArgs.Remove)
if err != nil {
return false, err
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to make this public so lvm.go could use it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also make a receiver function for the VolumeGroup (LogicalVolumeCount() or something) so you don't have to make this public. Not a big deal though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's way better/cleaner. I'll do that.

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
4 changes: 2 additions & 2 deletions pkg/blockdevice/lvm/volume_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ func (vg *VolumeGroup) LockStop(ctx context.Context, rawArgs string) (bool, erro
return false, err
}

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