Skip to content

Commit 47e3ca4

Browse files
committed
rbd: delete group only if its primary
This is a work of Nikhil which need to be applied on top of this PR to test the feature. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
1 parent 5ade96f commit 47e3ca4

4 files changed

Lines changed: 67 additions & 17 deletions

File tree

internal/csi-addons/rbd/volumegroup.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/ceph/ceph-csi/internal/rbd/types"
2828
"github.com/ceph/ceph-csi/internal/util/log"
2929

30+
"github.com/csi-addons/spec/lib/go/replication"
3031
"github.com/csi-addons/spec/lib/go/volumegroup"
3132
"google.golang.org/grpc"
3233
"google.golang.org/grpc/codes"
@@ -206,27 +207,41 @@ func (vs *VolumeGroupServer) DeleteVolumeGroup(
206207

207208
log.DebugLog(ctx, "VolumeGroup %q has been found", req.GetVolumeGroupId())
208209

209-
// verify that the volume group is empty
210-
volumes, err := vg.ListVolumes(ctx)
210+
volumes, mirror, err := mgr.GetMirrorSource(ctx, req.GetVolumeGroupId(), &replication.ReplicationSource{
211+
Type: &replication.ReplicationSource_Volumegroup{
212+
Volumegroup: &replication.ReplicationSource_VolumeGroupSource{
213+
VolumeGroupId: req.GetVolumeGroupId(),
214+
},
215+
},
216+
})
211217
if err != nil {
212-
return nil, status.Errorf(
213-
codes.NotFound,
214-
"could not list volumes for voluem group %q: %s",
215-
req.GetVolumeGroupId(),
216-
err.Error())
218+
return nil, getGRPCError(err)
217219
}
220+
defer destoryVolumes(ctx, volumes)
218221

219-
log.DebugLog(ctx, "VolumeGroup %q contains %d volumes", req.GetVolumeGroupId(), len(volumes))
222+
vgrMirrorInfo, err := mirror.GetMirroringInfo(ctx)
220223

221-
if len(volumes) != 0 {
222-
return nil, status.Errorf(
223-
codes.FailedPrecondition,
224-
"rejecting to delete non-empty volume group %q",
225-
req.GetVolumeGroupId())
224+
// verify that the volume group is empty, if the group is primary
225+
if vgrMirrorInfo.IsPrimary() {
226+
volumes, err := vg.ListVolumes(ctx)
227+
if err != nil {
228+
return nil, status.Errorf(
229+
codes.NotFound,
230+
"could not list volumes for volume group %q: %s",
231+
req.GetVolumeGroupId(),
232+
err.Error())
233+
}
234+
log.DebugLog(ctx, "VolumeGroup %q contains %d volumes", req.GetVolumeGroupId(), len(volumes))
235+
if len(volumes) != 0 {
236+
return nil, status.Errorf(
237+
codes.FailedPrecondition,
238+
"rejecting to delete non-empty volume group %q",
239+
req.GetVolumeGroupId())
240+
}
226241
}
227242

228243
// delete the volume group
229-
err = vg.Delete(ctx)
244+
err = vg.Delete(ctx, vgrMirrorInfo,mirror)
230245
if err != nil {
231246
return nil, status.Errorf(codes.Internal,
232247
"failed to delete volume group %q: %s",

internal/rbd/group/volume_group.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
librbd "github.com/ceph/go-ceph/rbd"
2727
"github.com/container-storage-interface/spec/lib/go/csi"
2828
"github.com/csi-addons/spec/lib/go/volumegroup"
29+
"google.golang.org/grpc/codes"
30+
"google.golang.org/grpc/status"
2931

3032
"github.com/ceph/ceph-csi/internal/rbd/types"
3133
"github.com/ceph/ceph-csi/internal/util"
@@ -184,7 +186,7 @@ func (vg *volumeGroup) Create(ctx context.Context) error {
184186
return nil
185187
}
186188

187-
func (vg *volumeGroup) Delete(ctx context.Context) error {
189+
func (vg *volumeGroup) Delete(ctx context.Context, vgrMirrorInfo types.MirrorInfo, mirror types.Mirror) error {
188190
name, err := vg.GetName(ctx)
189191
if err != nil {
190192
return err
@@ -195,6 +197,39 @@ func (vg *volumeGroup) Delete(ctx context.Context) error {
195197
return err
196198
}
197199

200+
// Cleanup only omap data if the following condition is met
201+
// Mirroring is enabled on the group
202+
// Local group is secondary
203+
// Local group is in up+replaying state
204+
if vgrMirrorInfo != nil && vgrMirrorInfo.GetState() == librbd.MirrorGroupEnabled.String() && !vgrMirrorInfo.IsPrimary() {
205+
// If the group is in a secondary state and its up+replaying means its
206+
// an healthy secondary and the group is primary somewhere in the
207+
// remote cluster and the local group is getting replayed. Delete the
208+
// OMAP data generated as we cannot delete the secondary group. When
209+
// the group on the primary cluster gets deleted/mirroring disabled,
210+
// the group on all the remote (secondary) clusters will get
211+
// auto-deleted. This helps in garbage collecting the OMAP, VR, VGR,
212+
// VGRC, PVC and PV objects after failback operation.
213+
if mirror != nil {
214+
sts, rErr := mirror.GetGlobalMirroringStatus(ctx)
215+
if rErr != nil {
216+
return status.Error(codes.Internal, rErr.Error())
217+
}
218+
localStatus, rErr := sts.GetLocalSiteStatus()
219+
if rErr != nil {
220+
log.ErrorLog(ctx, "failed to get local status for volume group%s: %w", name, rErr)
221+
return status.Error(codes.Internal, rErr.Error())
222+
}
223+
if localStatus.IsUP() && localStatus.GetState() == librbd.MirrorGroupStatusStateReplaying.String() {
224+
return vg.commonVolumeGroup.Delete(ctx)
225+
}
226+
log.ErrorLog(ctx,
227+
"secondary group status is up=%t and state=%s",
228+
localStatus.IsUP(),
229+
localStatus.GetState())
230+
}
231+
}
232+
198233
err = librbd.GroupRemove(ioctx, name)
199234
if err != nil && !errors.Is(err, rados.ErrNotFound) {
200235
return fmt.Errorf("failed to remove volume group %q: %w", vg, err)

internal/rbd/group_controllerserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (cs *ControllerServer) CreateVolumeGroupSnapshot(
9191
// the VG should always be deleted, volumes can only belong to a single VG
9292
log.DebugLog(ctx, "removing temporary volume group %q", vg)
9393

94-
vgErr := vg.Delete(ctx)
94+
vgErr := vg.Delete(ctx, nil, nil)
9595
if vgErr != nil {
9696
log.ErrorLog(ctx, "failed to remove temporary volume group %q: %v", vg, vgErr)
9797
}

internal/rbd/types/group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type VolumeGroup interface {
5858
Create(ctx context.Context) error
5959

6060
// Delete removes the VolumeGroup from the backend storage.
61-
Delete(ctx context.Context) error
61+
Delete(ctx context.Context, vgMirrorInfo MirrorInfo, mirror Mirror) error
6262

6363
// AddVolume adds the Volume to the VolumeGroup.
6464
AddVolume(ctx context.Context, volume Volume) error

0 commit comments

Comments
 (0)