rbd: disallow creating small size volume from snapshot

as per the CSI standard the size is optional parameter,
as we are allowing the restore to a bigger size
today we need to block the restore to a smaller size
as its a have side effects like data corruption.

Note:- Even though this check is present in kubernetes
sidecar as CSI is CO independent adding the check
here.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2022-01-12 14:23:40 +05:30 committed by mergify[bot]
parent f9c368f225
commit ceafca6ddf
2 changed files with 17 additions and 0 deletions

View File

@ -215,6 +215,12 @@ func checkValidCreateVolumeRequest(rbdVol, parentVol *rbdVolume, rbdSnap *rbdSna
if err != nil {
return status.Errorf(codes.InvalidArgument, "cannot restore from snapshot %s: %s", rbdSnap, err.Error())
}
err = rbdSnap.isCompabitableClone(&rbdVol.rbdImage)
if err != nil {
return status.Errorf(codes.InvalidArgument, "cannot restore from snapshot %s: %s", rbdSnap, err.Error())
}
case parentVol != nil:
err = parentVol.isCompatibleEncryption(&rbdVol.rbdImage)
if err != nil {

View File

@ -1993,6 +1993,17 @@ func (ri *rbdImage) isCompatibleEncryption(dst *rbdImage) error {
return nil
}
func (ri *rbdImage) isCompabitableClone(dst *rbdImage) error {
if dst.VolSize < ri.VolSize {
return fmt.Errorf(
"volume size %d is smaller than source volume size %d",
dst.VolSize,
ri.VolSize)
}
return nil
}
func (ri *rbdImage) isCompatibleThickProvision(dst *rbdVolume) error {
thick, err := ri.isThickProvisioned()
if err != nil {