mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-23 14:50:24 +00:00
rbd: add validation for thick restore/clone
added validation to allow only Restore of Thick PVC
snapshot to a thick clone and creation of thick clone
from thick PVC.
Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
(cherry picked from commit 7966d2e5c1
)
This commit is contained in:
parent
c5cafe3128
commit
96fce60b4e
@ -222,11 +222,21 @@ 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.isCompatibleThickProvision(rbdVol)
|
||||
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 {
|
||||
return status.Errorf(codes.InvalidArgument, "cannot clone from volume %s: %s", parentVol, err.Error())
|
||||
}
|
||||
|
||||
err = parentVol.isCompatibleThickProvision(rbdVol)
|
||||
if err != nil {
|
||||
return status.Errorf(codes.InvalidArgument, "cannot clone from volume %s: %s", parentVol, err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1550,3 +1550,19 @@ func (ri *rbdImage) isCompatibleEncryption(dst *rbdImage) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ri *rbdImage) isCompatibleThickProvision(dst *rbdVolume) error {
|
||||
thick, err := ri.isThickProvisioned()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch {
|
||||
case thick && !dst.ThickProvision:
|
||||
return fmt.Errorf("cannot create thin volume from thick volume %q", ri)
|
||||
|
||||
case !thick && dst.ThickProvision:
|
||||
return fmt.Errorf("cannot create thick volume from thin volume %q", ri)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user