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

fixed all potential crashing when decoding volume ID(CSI identifier) failed #4108

Merged
merged 1 commit into from
Sep 6, 2023
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
36 changes: 30 additions & 6 deletions internal/csi-addons/rbd/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ func (rs *ReplicationServer) EnableVolumeReplication(ctx context.Context,
defer rs.VolumeLocks.Release(volumeID)

rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy()
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil {
switch {
case errors.Is(err, corerbd.ErrImageNotFound):
Expand Down Expand Up @@ -305,7 +309,11 @@ func (rs *ReplicationServer) DisableVolumeReplication(ctx context.Context,
defer rs.VolumeLocks.Release(volumeID)

rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy()
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil {
switch {
case errors.Is(err, corerbd.ErrImageNotFound):
Expand Down Expand Up @@ -376,7 +384,11 @@ func (rs *ReplicationServer) PromoteVolume(ctx context.Context,
defer rs.VolumeLocks.Release(volumeID)

rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy()
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil {
switch {
case errors.Is(err, corerbd.ErrImageNotFound):
Expand Down Expand Up @@ -472,7 +484,11 @@ func (rs *ReplicationServer) DemoteVolume(ctx context.Context,
defer rs.VolumeLocks.Release(volumeID)

rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy()
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil {
switch {
case errors.Is(err, corerbd.ErrImageNotFound):
Expand Down Expand Up @@ -585,7 +601,11 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
}
defer rs.VolumeLocks.Release(volumeID)
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy()
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil {
switch {
case errors.Is(err, corerbd.ErrImageNotFound):
Expand Down Expand Up @@ -798,7 +818,11 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
}
defer rs.VolumeLocks.Release(volumeID)
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy()
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil {
switch {
case errors.Is(err, corerbd.ErrImageNotFound):
Expand Down
6 changes: 5 additions & 1 deletion internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,11 @@ func (cs *ControllerServer) CreateSnapshot(

// Fetch source volume information
rbdVol, err := GenVolFromVolID(ctx, req.GetSourceVolumeId(), cr, req.GetSecrets())
defer rbdVol.Destroy()
defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil {
switch {
case errors.Is(err, ErrImageNotFound):
Expand Down