rbd: fail fast in create volume for missmatch encryption

CreateVolume will fail in below cases

* If the snapshot is encrypted and requested volume
is not encrypted
* If the snapshot is not encrypted and requested
volume is encrypted

* If the parent volume is encrypted and requested volume
is not encrypted
* If the parent volume is not encrypted and requested
volume is encrypted

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna
2021-06-01 17:03:29 +05:30
committed by mergify[bot]
parent 538e36f7a7
commit 7b5c78ec7c
2 changed files with 34 additions and 1 deletions

View File

@ -1528,3 +1528,15 @@ func (rv *rbdVolume) getOrigSnapName(snapID uint64) (string, error) {
return origSnapName, nil
}
func (ri *rbdImage) isCompatibleEncryption(dst *rbdImage) error {
switch {
case ri.isEncrypted() && !dst.isEncrypted():
return fmt.Errorf("encrypted volume %q does not match unencrypted volume %q", ri, dst)
case !ri.isEncrypted() && dst.isEncrypted():
return fmt.Errorf("unencrypted volume %q does not match encrypted volume %q", ri, dst)
}
return nil
}