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

rbd: pre-work for VolumeGroup support #4701

Merged
merged 4 commits into from
Jul 8, 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
2 changes: 1 addition & 1 deletion internal/cephfs/store/volumegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func ReserveVolumeGroup(
defer j.Destroy()

groupUUID, vgsi.FsVolumeGroupSnapshotName, err = j.ReserveName(
ctx, volOptions.MetadataPool, util.InvalidPoolID, volOptions.RequestName, volOptions.NamePrefix)
ctx, volOptions.MetadataPool, volOptions.RequestName, volOptions.NamePrefix)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/csi-addons/rbd/reclaimspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (rscs *ReclaimSpaceControllerServer) ControllerReclaimSpace(
if err != nil {
return nil, status.Errorf(codes.Aborted, "failed to find volume with ID %q: %s", volumeID, err.Error())
}
defer rbdVol.Destroy()
defer rbdVol.Destroy(ctx)

err = rbdVol.Sparsify()
if errors.Is(err, rbdutil.ErrImageInUse) {
Expand Down
12 changes: 6 additions & 6 deletions internal/csi-addons/rbd/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (rs *ReplicationServer) EnableVolumeReplication(ctx context.Context,
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
rbdVol.Destroy(ctx)
}
}()
if err != nil {
Expand Down Expand Up @@ -350,7 +350,7 @@ func (rs *ReplicationServer) DisableVolumeReplication(ctx context.Context,
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
rbdVol.Destroy(ctx)
}
}()
if err != nil {
Expand Down Expand Up @@ -425,7 +425,7 @@ func (rs *ReplicationServer) PromoteVolume(ctx context.Context,
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
rbdVol.Destroy(ctx)
}
}()
if err != nil {
Expand Down Expand Up @@ -525,7 +525,7 @@ func (rs *ReplicationServer) DemoteVolume(ctx context.Context,
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
rbdVol.Destroy(ctx)
}
}()
if err != nil {
Expand Down Expand Up @@ -642,7 +642,7 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
rbdVol.Destroy(ctx)
}
}()
if err != nil {
Expand Down Expand Up @@ -856,7 +856,7 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
rbdVol.Destroy(ctx)
}
}()
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions internal/journal/volumegroupjournal.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ type VolumeGroupJournal interface {
objectUUID string) (*VolumeGroupAttributes, error)
ReserveName(
ctx context.Context,
journalPool string,
journalPoolID int64,
journalPool,
reqName,
namePrefix string) (string, string, error)
// AddVolumesMapping adds a volumeMap map which contains volumeID's and its
Expand Down Expand Up @@ -296,7 +295,6 @@ held, to prevent parallel operations from modifying the state of the omaps for t

Input arguments:
- journalPool: Pool where the CSI journal is stored
- journalPoolID: pool ID of the journalPool
- reqName: Name of the volumeGroupSnapshot request received
- namePrefix: Prefix to use when generating the volumeGroupName name (suffix is an auto-generated UUID)

Expand All @@ -306,8 +304,7 @@ Return values:
- error: non-nil in case of any errors
*/
func (vgjc *VolumeGroupJournalConnection) ReserveName(ctx context.Context,
journalPool string, journalPoolID int64,
reqName, namePrefix string,
journalPool, reqName, namePrefix string,
) (string, string, error) {
cj := vgjc.config

Expand Down
8 changes: 4 additions & 4 deletions internal/rbd/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ import (
func (rv *rbdVolume) checkCloneImage(ctx context.Context, parentVol *rbdVolume) (bool, error) {
// generate temp cloned volume
tempClone := rv.generateTempClone()
defer tempClone.Destroy()
defer tempClone.Destroy(ctx)

snap := &rbdSnapshot{}
defer snap.Destroy()
defer snap.Destroy(ctx)
snap.RbdSnapName = rv.RbdImageName
snap.Pool = rv.Pool

Expand Down Expand Up @@ -141,7 +141,7 @@ func (rv *rbdVolume) createCloneFromImage(ctx context.Context, parentVol *rbdVol
defer func() {
if err != nil {
log.DebugLog(ctx, "Removing clone image %q", rv)
errDefer := rv.deleteImage(ctx)
errDefer := rv.Delete(ctx)
if errDefer != nil {
log.ErrorLog(ctx, "failed to delete clone image %q: %v", rv, errDefer)
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func (rv *rbdVolume) doSnapClone(ctx context.Context, parentVol *rbdVolume) erro

// generate temp cloned volume
tempClone := rv.generateTempClone()
defer tempClone.Destroy()
defer tempClone.Destroy(ctx)

// snapshot name is same as temporary cloned image, This helps to
// flatten the temporary cloned images as we cannot have more than 510
Expand Down
40 changes: 20 additions & 20 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (cs *ControllerServer) CreateVolume(
if err != nil {
return nil, err
}
defer rbdVol.Destroy()
defer rbdVol.Destroy(ctx)
// Existence and conflict checks
if acquired := cs.VolumeLocks.TryAcquire(req.GetName()); !acquired {
log.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, req.GetName())
Expand All @@ -349,10 +349,10 @@ func (cs *ControllerServer) CreateVolume(
return nil, err
}
if parentVol != nil {
defer parentVol.Destroy()
defer parentVol.Destroy(ctx)
}
if rbdSnap != nil {
defer rbdSnap.Destroy()
defer rbdSnap.Destroy(ctx)
}

err = updateTopologyConstraints(rbdVol, rbdSnap)
Expand Down Expand Up @@ -403,7 +403,7 @@ func (cs *ControllerServer) CreateVolume(
metadata := k8s.GetVolumeMetadata(req.GetParameters())
err = rbdVol.setAllMetadata(metadata)
if err != nil {
if deleteErr := rbdVol.deleteImage(ctx); deleteErr != nil {
if deleteErr := rbdVol.Delete(ctx); deleteErr != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v", rbdVol, deleteErr)
}

Expand Down Expand Up @@ -465,7 +465,7 @@ func flattenParentImage(
// in case of any error call Destroy for cleanup.
defer func() {
if err != nil {
rbdSnap.Destroy()
rbdSnap.Destroy(ctx)
}
}()

Expand Down Expand Up @@ -621,7 +621,7 @@ func checkFlatten(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials)
if errors.Is(err, ErrFlattenInProgress) {
return status.Error(codes.Aborted, err.Error())
}
if errDefer := rbdVol.deleteImage(ctx); errDefer != nil {
if errDefer := rbdVol.Delete(ctx); errDefer != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v", rbdVol, errDefer)

return status.Error(codes.Internal, err.Error())
Expand Down Expand Up @@ -661,14 +661,14 @@ func (cs *ControllerServer) createVolumeFromSnapshot(

return status.Error(codes.Internal, err.Error())
}
defer rbdSnap.Destroy()
defer rbdSnap.Destroy(ctx)

// update parent name(rbd image name in snapshot)
rbdSnap.RbdImageName = rbdSnap.RbdSnapName
parentVol := rbdSnap.toVolume()
// as we are operating on single cluster reuse the connection
parentVol.conn = rbdVol.conn.Copy()
defer parentVol.Destroy()
defer parentVol.Destroy(ctx)

// create clone image and delete snapshot
err = rbdVol.cloneRbdImageFromSnapshot(ctx, rbdSnap, parentVol)
Expand All @@ -681,7 +681,7 @@ func (cs *ControllerServer) createVolumeFromSnapshot(
defer func() {
if err != nil {
log.DebugLog(ctx, "Removing clone image %q", rbdVol)
errDefer := rbdVol.deleteImage(ctx)
errDefer := rbdVol.Delete(ctx)
if errDefer != nil {
log.ErrorLog(ctx, "failed to delete clone image %q: %v", rbdVol, errDefer)
}
Expand Down Expand Up @@ -764,7 +764,7 @@ func (cs *ControllerServer) createBackingImage(

defer func() {
if err != nil {
if deleteErr := rbdVol.deleteImage(ctx); deleteErr != nil {
if deleteErr := rbdVol.Delete(ctx); deleteErr != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v", rbdVol, deleteErr)
}
}
Expand Down Expand Up @@ -944,7 +944,7 @@ func (cs *ControllerServer) DeleteVolume(
rbdVol, err := GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
rbdVol.Destroy(ctx)
}
}()
if err != nil {
Expand Down Expand Up @@ -1029,7 +1029,7 @@ func cleanupRBDImage(ctx context.Context,

// Deleting rbd image
log.DebugLog(ctx, "deleting image %s", rbdVol.RbdImageName)
if err = rbdVol.deleteImage(ctx); err != nil {
if err = rbdVol.Delete(ctx); err != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v",
rbdVol, err)

Expand Down Expand Up @@ -1094,7 +1094,7 @@ func (cs *ControllerServer) CreateSnapshot(
rbdVol, err := GenVolFromVolID(ctx, req.GetSourceVolumeId(), cr, req.GetSecrets())
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
rbdVol.Destroy(ctx)
}
}()
if err != nil {
Expand Down Expand Up @@ -1188,7 +1188,7 @@ func (cs *ControllerServer) CreateSnapshot(
defer func() {
if err != nil {
log.DebugLog(ctx, "Removing clone image %q", rbdVol)
errDefer := rbdVol.deleteImage(ctx)
errDefer := rbdVol.Delete(ctx)
if errDefer != nil {
log.ErrorLog(ctx, "failed to delete clone image %q: %v", rbdVol, errDefer)
}
Expand Down Expand Up @@ -1237,7 +1237,7 @@ func cloneFromSnapshot(

return nil, status.Errorf(codes.Internal, err.Error())
}
defer vol.Destroy()
defer vol.Destroy(ctx)

err = rbdVol.copyEncryptionConfig(ctx, &vol.rbdImage, false)
if err != nil {
Expand Down Expand Up @@ -1313,7 +1313,7 @@ func (cs *ControllerServer) doSnapshotClone(
) (*rbdVolume, error) {
// generate cloned volume details from snapshot
cloneRbd := rbdSnap.toVolume()
defer cloneRbd.Destroy()
defer cloneRbd.Destroy(ctx)
// add image feature for cloneRbd
f := []string{librbd.FeatureNameLayering, librbd.FeatureNameDeepFlatten}
cloneRbd.ImageFeatureSet = librbd.FeatureSetFromNames(f)
Expand Down Expand Up @@ -1460,7 +1460,7 @@ func (cs *ControllerServer) DeleteSnapshot(

return nil, status.Error(codes.Internal, err.Error())
}
defer rbdSnap.Destroy()
defer rbdSnap.Destroy(ctx)

// safeguard against parallel create or delete requests against the same
// name
Expand All @@ -1480,7 +1480,7 @@ func (cs *ControllerServer) DeleteSnapshot(
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
defer rbdVol.Destroy()
defer rbdVol.Destroy(ctx)

rbdVol.ImageID = rbdSnap.ImageID
// update parent name to delete the snapshot
Expand Down Expand Up @@ -1510,7 +1510,7 @@ func cleanUpImageAndSnapReservation(ctx context.Context, rbdSnap *rbdSnapshot, c
if err != nil {
return status.Error(codes.Internal, err.Error())
}
defer rbdVol.Destroy()
defer rbdVol.Destroy(ctx)

err = rbdVol.openIoctx()
if err != nil {
Expand Down Expand Up @@ -1584,7 +1584,7 @@ func (cs *ControllerServer) ControllerExpandVolume(

return nil, err
}
defer rbdVol.Destroy()
defer rbdVol.Destroy(ctx)

// NodeExpansion is needed for PersistentVolumes with,
// 1. Filesystem VolumeMode with & without Encryption and
Expand Down
4 changes: 2 additions & 2 deletions internal/rbd/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func deleteMigratedVolume(ctx context.Context, parsedMigHandle *migrationVolID,
if err != nil {
return err
}
defer rv.Destroy()
err = rv.deleteImage(ctx)
defer rv.Destroy(ctx)
err = rv.Delete(ctx)
if err != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s, err: %v", rv, err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/rbd/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (ns *NodeServer) populateRbdVol(
} else {
rv, err = GenVolFromVolID(ctx, volID, cr, req.GetSecrets())
if err != nil {
rv.Destroy()
rv.Destroy(ctx)
log.ErrorLog(ctx, "error generating volume %s: %v", volID, err)

return nil, status.Errorf(codes.Internal, "error generating volume %s: %v", volID, err)
Expand All @@ -221,7 +221,7 @@ func (ns *NodeServer) populateRbdVol(
// in case of any error call Destroy for cleanup.
defer func() {
if err != nil {
rv.Destroy()
rv.Destroy(ctx)
}
}()
// get the image details from the ceph cluster.
Expand Down Expand Up @@ -345,7 +345,7 @@ func (ns *NodeServer) NodeStageVolume(
if err != nil {
return nil, err
}
defer rv.Destroy()
defer rv.Destroy(ctx)

rv.NetNamespaceFilePath, err = util.GetRBDNetNamespaceFilePath(util.CsiConfigFile, rv.ClusterID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/rbd/rbd_journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func checkSnapCloneExists(
}

vol := rbdSnap.toVolume()
defer vol.Destroy()
defer vol.Destroy(ctx)
err = vol.Connect(cr)
if err != nil {
return false, err
Expand Down
Loading