mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rbd: do not execute rbd sparsify when volume is in use
This commit makes sure sparsify() is not run when rbd image is in use. Running rbd sparsify with workload doing io and too frequently is not desirable. When a image is in use fstrim is run and sparsify will be run only when image is not mapped. Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
@ -23,7 +23,18 @@ import (
|
||||
// Sparsify checks the size of the objects in the RBD image and calls
|
||||
// rbd_sparify() to free zero-filled blocks and reduce the storage consumption
|
||||
// of the image.
|
||||
// This function will return ErrImageInUse if the image is in use, since
|
||||
// sparsifying an image on which i/o is in progress is not optimal.
|
||||
func (ri *rbdImage) Sparsify() error {
|
||||
inUse, err := ri.isInUse()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to check if image is in use: %w", err)
|
||||
}
|
||||
if inUse {
|
||||
// if the image is in use, we should not sparsify it, return ErrImageInUse.
|
||||
return ErrImageInUse
|
||||
}
|
||||
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user