mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 14:20:19 +00:00
rbd: set image metadata in isThickProvisioned
setting metadata in isThickProvisioned method helps us to avoid checking thick metakey and deprecated metakey for both thick and thin provisioned images and also this will easily help us to migrated the deprecated key to new key. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
77135599ac
commit
dd0884310f
@ -64,6 +64,11 @@ const (
|
||||
// 'thickProvisionMetaKey' to set image metadata.
|
||||
deprecatedthickProvisionMetaKey = ".rbd.csi.ceph.com/thick-provisioned"
|
||||
thickProvisionMetaKey = "rbd.csi.ceph.com/thick-provisioned"
|
||||
|
||||
// these are the metadata set on the image to identify the image is
|
||||
// thick provisioned or thin provisioned.
|
||||
thickProvisionMetaData = "true"
|
||||
thinProvisionMetaData = "false"
|
||||
)
|
||||
|
||||
// rbdImage contains common attributes and methods for the rbdVolume and
|
||||
@ -1525,7 +1530,7 @@ func (ri *rbdImage) SetMetadata(key, value string) error {
|
||||
// setThickProvisioned records in the image metadata that it has been
|
||||
// thick-provisioned.
|
||||
func (ri *rbdImage) setThickProvisioned() error {
|
||||
err := ri.SetMetadata(thickProvisionMetaKey, "true")
|
||||
err := ri.SetMetadata(thickProvisionMetaKey, thickProvisionMetaData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set metadata %q for %q: %w", thickProvisionMetaKey, ri, err)
|
||||
}
|
||||
@ -1533,6 +1538,17 @@ func (ri *rbdImage) setThickProvisioned() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// setThinProvisioned records in the image metadata that it has been
|
||||
// thin-provisioned.
|
||||
func (ri *rbdImage) setThinProvisioned() error {
|
||||
err := ri.SetMetadata(thickProvisionMetaKey, thinProvisionMetaData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set metadata %q for %q: %w", thinProvisionMetaData, ri, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// isThickProvisioned checks in the image metadata if the image has been marked
|
||||
// as thick-provisioned. This can be used while expanding the image, so that
|
||||
// the expansion can be allocated too.
|
||||
@ -1544,6 +1560,17 @@ func (ri *rbdImage) isThickProvisioned() (bool, error) {
|
||||
if err == librbd.ErrNotFound {
|
||||
return false, nil
|
||||
}
|
||||
// If we reach here means the image has deprecated metakey set. Set the
|
||||
// new metakey so that we dont need to check for deprecated key again.
|
||||
if value == thickProvisionMetaData {
|
||||
err = ri.setThickProvisioned()
|
||||
} else {
|
||||
value = thinProvisionMetaData
|
||||
// If we reach here means the image is thin provisioned. Set thin
|
||||
// provisioned metadata on the image so that we dont need to check
|
||||
// for thick metakey or deprecated thick metakey.
|
||||
err = ri.setThinProvisioned()
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to get metadata %q for %q: %w", thickProvisionMetaKey, ri, err)
|
||||
|
Loading…
Reference in New Issue
Block a user