mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rbd: flatten datasource image before creating volume
This commit ensures that parent image is flattened before creating volume. - If the data source is a PVC, the underlying image's parent is flattened(which would be a temp clone or snapshot). hard & soft limit is reduced by 2 to account for depth that will be added by temp & final clone. - If the data source is a Snapshot, the underlying image is itself flattened. hard & soft limit is reduced by 1 to account for depth that will be added by the clone which will be restored from the snapshot. Flattening step for resulting PVC image restored from snapshot is removed. Flattening step for temp clone & final image is removed when pvc clone is being created. Fixes: #2190 Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
@ -1440,6 +1440,47 @@ func (ri *rbdImage) getImageInfo() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// getParent returns parent image if it exists.
|
||||
func (ri *rbdImage) getParent() (*rbdImage, error) {
|
||||
err := ri.getImageInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ri.ParentName == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
parentImage := rbdImage{}
|
||||
parentImage.conn = ri.conn.Copy()
|
||||
parentImage.ClusterID = ri.ClusterID
|
||||
parentImage.Monitors = ri.Monitors
|
||||
parentImage.Pool = ri.ParentPool
|
||||
parentImage.RadosNamespace = ri.RadosNamespace
|
||||
parentImage.RbdImageName = ri.ParentName
|
||||
|
||||
err = parentImage.getImageInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &parentImage, nil
|
||||
}
|
||||
|
||||
// flattenParent flatten the given image's parent if it exists according to hard and soft
|
||||
// limits.
|
||||
func (ri *rbdImage) flattenParent(ctx context.Context, hardLimit, softLimit uint) error {
|
||||
parentImage, err := ri.getParent()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if parentImage == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return parentImage.flattenRbdImage(ctx, false, hardLimit, softLimit)
|
||||
}
|
||||
|
||||
/*
|
||||
checkSnapExists queries rbd about the snapshots of the given image and returns
|
||||
ErrImageNotFound if provided image is not found, and ErrSnapNotFound if
|
||||
|
Reference in New Issue
Block a user