mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-23 21:40:20 +00:00
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:
parent
f9c368f225
commit
ceafca6ddf
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user