mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rbd: implement rbdVolume.isInUse() with go-ceph
The new rbdVolume.isInUse() method will replace the rbdStatus() function. This removes one more rbd command execution in the DeleteVolume path. Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
9e0589cf12
commit
7afaac9c66
@ -275,6 +275,28 @@ func (rv *rbdVolume) open() (*librbd.Image, error) {
|
||||
return image, nil
|
||||
}
|
||||
|
||||
// isInUse checks if there is a watcher on the image. It returns true if there
|
||||
// is a watcher on the image, otherwise returns false.
|
||||
func (rv *rbdVolume) isInUse() (bool, error) {
|
||||
image, err := rv.open()
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrImageNotFound) || errors.Is(err, util.ErrPoolNotFound) {
|
||||
return false, err
|
||||
}
|
||||
// any error should assume something else is using the image
|
||||
return true, err
|
||||
}
|
||||
defer image.Close()
|
||||
|
||||
watchers, err := image.ListWatchers()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// because we opened the image, there is at least one watcher
|
||||
return len(watchers) != 1, nil
|
||||
}
|
||||
|
||||
// rbdStatus checks if there is watcher on the image.
|
||||
// It returns true if there is a watcher on the image, otherwise returns false.
|
||||
func rbdStatus(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) (bool, string, error) {
|
||||
|
Reference in New Issue
Block a user