Skip to content

Commit

Permalink
rbd: enable expand operation for intree volumes
Browse files Browse the repository at this point in the history
This commit enable the resize operation [1] for in-tree volumes.
new helper has been introduced here to aid the enablement or to
make it clean with existing code base.

[1] https://github.com/ceph/ceph-csi/blob/devel/docs/design/proposals/intree-migrate.md?plain=1#L66

Signed-off-by: Humble Chirammal <[email protected]>
  • Loading branch information
humblec committed Dec 22, 2021
1 parent 810e285 commit 1432707
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
5 changes: 2 additions & 3 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1447,9 +1447,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
return nil, status.Error(codes.InvalidArgument, err.Error())
}
defer cr.DeleteCredentials()

rbdVol, err := GenVolFromVolID(ctx, volID, cr, req.GetSecrets())
defer rbdVol.Destroy()
rbdVol, err := genVolFromVolIDWithMigration(ctx, volID, cr, req.GetSecrets())
if err != nil {
switch {
case errors.Is(err, ErrImageNotFound):
Expand All @@ -1463,6 +1461,7 @@ func (cs *ControllerServer) ControllerExpandVolume(

return nil, err
}
defer rbdVol.Destroy()

// NodeExpansion is needed for PersistentVolumes with,
// 1. Filesystem VolumeMode with & without Encryption and
Expand Down
38 changes: 23 additions & 15 deletions internal/rbd/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,43 @@ func parseMigrationVolID(vh string) (*migrationVolID, error) {
// deleteMigratedVolume get rbd volume details from the migration volID
// and delete the volume from the cluster, return err if there was an error on the process.
func deleteMigratedVolume(ctx context.Context, parsedMigHandle *migrationVolID, cr *util.Credentials) error {
rv, err := genVolFromMigVolID(ctx, parsedMigHandle, cr)
if err != nil {
return err
}
defer rv.Destroy()
err = deleteImage(ctx, rv, cr)
if err != nil {
log.ErrorLog(ctx, "failed to delete rbd image : %s, err: %v", rv.RbdImageName, err)

return err
}

return nil
}

// genVolFromMigVolID populate rbdVol struct from the migration volID.
func genVolFromMigVolID(ctx context.Context, migVolID *migrationVolID, cr *util.Credentials) (*rbdVolume, error) {
var err error
rv := &rbdVolume{}

// fill details to rv struct from parsed migration handle
rv.RbdImageName = parsedMigHandle.imageName
rv.Pool = parsedMigHandle.poolName
rv.ClusterID = parsedMigHandle.clusterID
rv.RbdImageName = migVolID.imageName
rv.Pool = migVolID.poolName
rv.ClusterID = migVolID.clusterID
rv.Monitors, err = util.Mons(util.CsiConfigFile, rv.ClusterID)
if err != nil {
log.ErrorLog(ctx, "failed to fetch monitors using clusterID: %s, err: %v", rv.ClusterID, err)

return err
return nil, err
}

// connect to the volume.
err = rv.Connect(cr)
if err != nil {
log.ErrorLog(ctx, "failed to get connected to the rbd image : %s, err: %v", rv.RbdImageName, err)

return err
}
defer rv.Destroy()
// if connected , delete it
err = deleteImage(ctx, rv, cr)
if err != nil {
log.ErrorLog(ctx, "failed to delete rbd image : %s, err: %v", rv.RbdImageName, err)

return err
return nil, err
}

return nil
return rv, nil
}
26 changes: 26 additions & 0 deletions internal/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2071,3 +2071,29 @@ func strategicActionOnLogFile(ctx context.Context, logStrategy, logFile string)
log.ErrorLog(ctx, "unknown cephLogStrategy option %q: hint: 'remove'|'compress'|'preserve'", logStrategy)
}
}

// genVolFromVolIDWithMigration populate a rbdVol structure based on the volID format.
func genVolFromVolIDWithMigration(
ctx context.Context, volID string, cr *util.Credentials, secrets map[string]string) (*rbdVolume, error) {
var err error
var rv *rbdVolume
if isMigrationVolID(volID) {
pmVolID, pErr := parseMigrationVolID(volID)
if pErr != nil {
return nil, pErr
}
rv, pErr = genVolFromMigVolID(ctx, pmVolID, cr)
if pErr != nil {
return nil, pErr
}
} else {
rv, err = GenVolFromVolID(ctx, volID, cr, secrets)
if err != nil {
rv.Destroy()

return nil, err
}
}

return rv, nil
}

0 comments on commit 1432707

Please sign in to comment.