mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 10:53:34 +00:00
rbd: introduce functions for comparing Volumes in a VolumeGroup
CompareVolumesInGroup() verifies that all the volumes are part of the given VolumeGroup. It does so by obtaining the VolumeGroupID for each volume with GetVolumeGroupByID(). The helper VolumesInSameGroup() verifies that all volumes belong to the same (or no) VolumeGroup. It can be called by CSI(-Addons) procedures before acting on a VolumeGroup. Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
32285c8365
commit
e489413dbd
@ -22,6 +22,7 @@ import (
|
||||
|
||||
librbd "github.com/ceph/go-ceph/rbd"
|
||||
|
||||
rbderrors "github.com/ceph/ceph-csi/internal/rbd/errors"
|
||||
"github.com/ceph/ceph-csi/internal/rbd/types"
|
||||
)
|
||||
|
||||
@ -79,6 +80,28 @@ func (rv *rbdVolume) RemoveFromGroup(ctx context.Context, vg types.VolumeGroup)
|
||||
return librbd.GroupImageRemove(ioctx, name, rv.ioctx, rv.RbdImageName)
|
||||
}
|
||||
|
||||
// GetVolumeGroupID returns the ID of the VolumeGroup where this rbdVolume
|
||||
// belongs to. If the rbdVolume does not belong to a VolumeGroup, a
|
||||
// rbderrors.ErrGroupNotFound is returned.
|
||||
func (rv *rbdVolume) GetVolumeGroupID(ctx context.Context, resolver types.VolumeGroupResolver) (string, error) {
|
||||
image, err := rv.open()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to open image %q: %w", rv, err)
|
||||
}
|
||||
defer image.Close()
|
||||
|
||||
info, err := image.GetGroup()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not get group information for image %q: %w", rv, err)
|
||||
}
|
||||
|
||||
if info.Name == "" {
|
||||
return "", fmt.Errorf("%w: image %q is not part of a volume group", rbderrors.ErrGroupNotFound, rv)
|
||||
}
|
||||
|
||||
return resolver.MakeVolumeGroupID(ctx, info.PoolID, info.Name)
|
||||
}
|
||||
|
||||
func (rv *rbdVolume) ToMirror() (types.Mirror, error) {
|
||||
return rv, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user