Skip to content

Commit

Permalink
rbd: remove the VolumeGroup from the journal on DeleteVolumeGroup
Browse files Browse the repository at this point in the history
Signed-off-by: Niels de Vos <ndevos@ibm.com>
  • Loading branch information
nixpanic committed Jul 19, 2024
1 parent 2a9134f commit a34d7fe
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
18 changes: 18 additions & 0 deletions internal/rbd/group/volume_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,24 @@ func (vg *volumeGroup) GetName(ctx context.Context) (string, error) {
return vg.name, nil
}

// GetPool returns the name of the pool that holds the VolumeGroup.
func (vg *volumeGroup) GetPool(ctx context.Context) (string, error) {
if vg.pool == "" {
return "", errors.New("BUG: pool is not set")
}

return vg.pool, nil
}

// GetClusterID returns the name of the pool that holds the VolumeGroup.
func (vg *volumeGroup) GetClusterID(ctx context.Context) (string, error) {
if vg.clusterID == "" {
return "", errors.New("BUG: clusterID is not set")
}

return vg.clusterID, nil
}

// ToCSI creates a CSI-Addons type for the VolumeGroup.
func (vg *volumeGroup) ToCSI(ctx context.Context) (*volumegroup.VolumeGroup, error) {
volumes, err := vg.ListVolumes(ctx)
Expand Down
41 changes: 39 additions & 2 deletions internal/rbd/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"errors"
"fmt"

"github.com/ceph/go-ceph/rados"

"github.com/ceph/ceph-csi/internal/journal"
"github.com/ceph/ceph-csi/internal/rbd/group"
rbd_group "github.com/ceph/ceph-csi/internal/rbd/group"
"github.com/ceph/ceph-csi/internal/rbd/types"
"github.com/ceph/ceph-csi/internal/util"
)
Expand Down Expand Up @@ -221,5 +223,40 @@ func (mgr *rbdManager) CreateVolumeGroup(ctx context.Context, name string) (type

func (mgr *rbdManager) DeleteVolumeGroup(ctx context.Context, vg types.VolumeGroup) error {
// TODO: remove from journal
return vg.Delete(ctx)
err := vg.Delete(ctx)
if err != nil && !errors.Is(rados.ErrNotFound, err) {
return fmt.Errorf("failed to delete volume group %q: %w", vg, err)
}

clusterID, err := vg.GetClusterID(ctx)
if err != nil {
return fmt.Errorf("failed to get cluster id for volume group %q: %w", vg, err)
}

vgJournal, err := mgr.getVolumeGroupJournal(clusterID)
if err != nil {
return err
}

name, err := vg.GetName(ctx)
if err != nil {
return fmt.Errorf("failed to get name for volume group %q: %w", vg, err)
}

csiID, err := vg.GetID(ctx)
if err != nil {
return fmt.Errorf("failed to get id for volume group %q: %w", vg, err)
}

pool, err := vg.GetPool(ctx)
if err != nil {
return fmt.Errorf("failed to get pool for volume group %q: %w", vg, err)
}

err = vgJournal.UndoReservation(ctx, pool, name, csiID)
if err != nil /* TODO? !errors.Is(..., err) */ {
return fmt.Errorf("failed to undo the reservation for volume group %q: %w", vg, err)
}

return nil
}

0 comments on commit a34d7fe

Please sign in to comment.