2024-02-02 08:42:44 +00:00
|
|
|
/*
|
|
|
|
Copyright 2024 The Ceph-CSI Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package journal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2024-08-06 16:02:34 +00:00
|
|
|
"time"
|
2024-02-02 08:42:44 +00:00
|
|
|
|
|
|
|
"github.com/ceph/ceph-csi/internal/util"
|
|
|
|
"github.com/ceph/ceph-csi/internal/util/log"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
defaultVolumeGroupNamingPrefix string = "csi-vol-group-"
|
|
|
|
)
|
|
|
|
|
|
|
|
type VolumeGroupJournal interface {
|
|
|
|
Destroy()
|
|
|
|
CheckReservation(
|
|
|
|
ctx context.Context,
|
|
|
|
journalPool,
|
|
|
|
reqName,
|
|
|
|
namePrefix string) (*VolumeGroupData, error)
|
|
|
|
UndoReservation(
|
|
|
|
ctx context.Context,
|
|
|
|
csiJournalPool,
|
2024-06-18 09:11:33 +00:00
|
|
|
groupName,
|
2024-02-02 08:42:44 +00:00
|
|
|
reqName string) error
|
|
|
|
// GetGroupAttributes fetches all keys and their values, from a UUID directory,
|
|
|
|
// returning VolumeGroupAttributes structure.
|
|
|
|
GetVolumeGroupAttributes(
|
|
|
|
ctx context.Context,
|
|
|
|
pool,
|
|
|
|
objectUUID string) (*VolumeGroupAttributes, error)
|
|
|
|
ReserveName(
|
|
|
|
ctx context.Context,
|
2024-03-19 17:36:17 +00:00
|
|
|
journalPool,
|
2024-02-02 08:42:44 +00:00
|
|
|
reqName,
|
|
|
|
namePrefix string) (string, string, error)
|
2024-06-18 09:19:11 +00:00
|
|
|
// AddVolumesMapping adds a volumeMap map which contains volumeID's and its
|
|
|
|
// corresponding values mapping which need to be added to the UUID
|
2024-06-18 09:11:33 +00:00
|
|
|
// directory. value can be anything which needs mapping, in case of
|
2024-06-18 09:19:11 +00:00
|
|
|
// volumegroupsnapshot its a snapshotID and its empty in case of
|
|
|
|
// volumegroup.
|
|
|
|
AddVolumesMapping(
|
2024-02-02 08:42:44 +00:00
|
|
|
ctx context.Context,
|
|
|
|
pool,
|
2024-06-18 09:19:11 +00:00
|
|
|
reservedUUID string,
|
|
|
|
volumeMap map[string]string) error
|
|
|
|
// RemoveVolumesMapping removes volumeIDs mapping from the UUID directory.
|
|
|
|
RemoveVolumesMapping(
|
2024-02-02 08:42:44 +00:00
|
|
|
ctx context.Context,
|
|
|
|
pool,
|
2024-06-18 09:14:37 +00:00
|
|
|
reservedUUID string,
|
|
|
|
volumeIDs []string) error
|
2024-02-02 08:42:44 +00:00
|
|
|
}
|
|
|
|
|
2024-03-19 13:48:27 +00:00
|
|
|
// VolumeGroupJournalConfig contains the configuration.
|
|
|
|
type VolumeGroupJournalConfig struct {
|
|
|
|
Config
|
2024-08-06 16:02:34 +00:00
|
|
|
|
|
|
|
// csiCreationTimeKey can hold the key for the time a group was
|
|
|
|
// created. At least RBD groups do not provide the creation time
|
|
|
|
// through API calls.
|
|
|
|
csiCreationTimeKey string
|
2024-03-19 13:48:27 +00:00
|
|
|
}
|
|
|
|
|
2024-07-16 15:23:49 +00:00
|
|
|
type volumeGroupJournalConnection struct {
|
2024-03-19 13:48:27 +00:00
|
|
|
config *VolumeGroupJournalConfig
|
|
|
|
connection *Connection
|
2024-02-02 08:42:44 +00:00
|
|
|
}
|
|
|
|
|
2024-07-16 15:23:49 +00:00
|
|
|
// assert that volumeGroupJournalConnection implements the VolumeGroupJournal
|
|
|
|
// interface.
|
|
|
|
var _ VolumeGroupJournal = &volumeGroupJournalConnection{}
|
|
|
|
|
2024-03-14 08:27:11 +00:00
|
|
|
// NewCSIVolumeGroupJournal returns an instance of VolumeGroupJournal for groups.
|
2024-03-19 13:48:27 +00:00
|
|
|
func NewCSIVolumeGroupJournal(suffix string) VolumeGroupJournalConfig {
|
|
|
|
return VolumeGroupJournalConfig{
|
|
|
|
Config: Config{
|
2024-02-02 08:42:44 +00:00
|
|
|
csiDirectory: "csi.groups." + suffix,
|
|
|
|
csiNameKeyPrefix: "csi.volume.group.",
|
|
|
|
cephUUIDDirectoryPrefix: "csi.volume.group.",
|
|
|
|
csiImageKey: "csi.groupname",
|
|
|
|
csiNameKey: "csi.volname",
|
|
|
|
namespace: "",
|
|
|
|
},
|
2024-08-06 16:02:34 +00:00
|
|
|
csiCreationTimeKey: "csi.creationtime",
|
2024-02-02 08:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-19 13:48:27 +00:00
|
|
|
// SetNamespace sets the namespace for the journal.
|
|
|
|
func (vgc *VolumeGroupJournalConfig) SetNamespace(ns string) {
|
|
|
|
vgc.Config.namespace = ns
|
2024-02-02 08:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewCSIVolumeGroupJournalWithNamespace returns an instance of VolumeGroupJournal for
|
|
|
|
// volume groups using a predetermined namespace value.
|
2024-03-19 13:48:27 +00:00
|
|
|
func NewCSIVolumeGroupJournalWithNamespace(suffix, ns string) VolumeGroupJournalConfig {
|
2024-03-14 08:27:11 +00:00
|
|
|
j := NewCSIVolumeGroupJournal(suffix)
|
2024-02-02 08:42:44 +00:00
|
|
|
j.SetNamespace(ns)
|
|
|
|
|
|
|
|
return j
|
|
|
|
}
|
|
|
|
|
2024-03-19 13:48:27 +00:00
|
|
|
// Connect establishes a new connection to a ceph cluster for journal metadata.
|
|
|
|
func (vgc *VolumeGroupJournalConfig) Connect(
|
2024-02-02 08:42:44 +00:00
|
|
|
monitors,
|
|
|
|
namespace string,
|
|
|
|
cr *util.Credentials,
|
2024-03-19 13:48:27 +00:00
|
|
|
) (VolumeGroupJournal, error) {
|
2024-07-16 15:23:49 +00:00
|
|
|
vgjc := &volumeGroupJournalConnection{}
|
2024-03-19 13:48:27 +00:00
|
|
|
vgjc.config = &VolumeGroupJournalConfig{
|
2024-08-12 05:40:08 +00:00
|
|
|
Config: vgc.Config,
|
|
|
|
csiCreationTimeKey: vgc.csiCreationTimeKey,
|
2024-03-19 13:48:27 +00:00
|
|
|
}
|
|
|
|
conn, err := vgc.Config.Connect(monitors, namespace, cr)
|
2024-02-02 08:42:44 +00:00
|
|
|
if err != nil {
|
2024-03-19 13:48:27 +00:00
|
|
|
return nil, err
|
2024-02-02 08:42:44 +00:00
|
|
|
}
|
2024-03-19 13:48:27 +00:00
|
|
|
vgjc.connection = conn
|
2024-02-02 08:42:44 +00:00
|
|
|
|
2024-03-19 13:48:27 +00:00
|
|
|
return vgjc, nil
|
2024-02-02 08:42:44 +00:00
|
|
|
}
|
|
|
|
|
2024-03-19 13:48:27 +00:00
|
|
|
// Destroy frees any resources and invalidates the journal connection.
|
2024-07-16 15:23:49 +00:00
|
|
|
func (vgjc *volumeGroupJournalConnection) Destroy() {
|
2024-10-01 07:29:27 +00:00
|
|
|
if vgjc.connection != nil {
|
|
|
|
vgjc.connection.Destroy()
|
|
|
|
vgjc.connection = nil
|
|
|
|
}
|
2024-02-02 08:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// VolumeGroupData contains the GroupUUID and VolumeGroupAttributes for a
|
|
|
|
// volume group.
|
|
|
|
type VolumeGroupData struct {
|
|
|
|
GroupUUID string
|
|
|
|
GroupName string
|
|
|
|
VolumeGroupAttributes *VolumeGroupAttributes
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateVolumeGroupName(namePrefix, groupUUID string) string {
|
|
|
|
if namePrefix == "" {
|
|
|
|
namePrefix = defaultVolumeGroupNamingPrefix
|
|
|
|
}
|
|
|
|
|
|
|
|
return namePrefix + groupUUID
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CheckReservation checks if given request name contains a valid reservation
|
|
|
|
- If there is a valid reservation, then the corresponding VolumeGroupData for
|
|
|
|
the snapshot group is returned
|
|
|
|
- If there is a reservation that is stale (or not fully cleaned up), it is
|
|
|
|
garbage collected using the UndoReservation call, as appropriate
|
|
|
|
|
|
|
|
NOTE: As the function manipulates omaps, it should be called with a lock
|
|
|
|
against the request name held, to prevent parallel operations from modifying
|
|
|
|
the state of the omaps for this request name.
|
|
|
|
|
|
|
|
Return values:
|
|
|
|
- VolumeGroupData: which contains the GroupUUID and GroupSnapshotAttributes
|
|
|
|
that were reserved for the passed in reqName, empty if there was no
|
|
|
|
reservation found.
|
|
|
|
- error: non-nil in case of any errors.
|
|
|
|
*/
|
2024-07-16 15:23:49 +00:00
|
|
|
func (vgjc *volumeGroupJournalConnection) CheckReservation(ctx context.Context,
|
2024-02-02 08:42:44 +00:00
|
|
|
journalPool, reqName, namePrefix string,
|
|
|
|
) (*VolumeGroupData, error) {
|
|
|
|
var (
|
2024-03-19 13:48:27 +00:00
|
|
|
cj = vgjc.config
|
2024-02-02 08:42:44 +00:00
|
|
|
volGroupData = &VolumeGroupData{}
|
|
|
|
)
|
|
|
|
|
|
|
|
// check if request name is already part of the directory omap
|
|
|
|
fetchKeys := []string{
|
|
|
|
cj.csiNameKeyPrefix + reqName,
|
|
|
|
}
|
|
|
|
values, err := getOMapValues(
|
2024-03-19 13:48:27 +00:00
|
|
|
ctx, vgjc.connection, journalPool, cj.namespace, cj.csiDirectory,
|
2024-02-02 08:42:44 +00:00
|
|
|
cj.commonPrefix, fetchKeys)
|
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, util.ErrKeyNotFound) || errors.Is(err, util.ErrPoolNotFound) {
|
|
|
|
// pool or omap (oid) was not present
|
|
|
|
// stop processing but without an error for no reservation exists
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
objUUID, found := values[cj.csiNameKeyPrefix+reqName]
|
|
|
|
if !found {
|
|
|
|
// omap was read but was missing the desired key-value pair
|
|
|
|
// stop processing but without an error for no reservation exists
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
volGroupData.GroupUUID = objUUID
|
|
|
|
|
2024-03-19 13:48:27 +00:00
|
|
|
savedVolumeGroupAttributes, err := vgjc.GetVolumeGroupAttributes(ctx, journalPool,
|
2024-02-02 08:42:44 +00:00
|
|
|
objUUID)
|
|
|
|
if err != nil {
|
|
|
|
// error should specifically be not found, for image to be absent, any other error
|
|
|
|
// is not conclusive, and we should not proceed
|
|
|
|
if errors.Is(err, util.ErrKeyNotFound) {
|
2024-03-19 13:48:27 +00:00
|
|
|
err = vgjc.UndoReservation(ctx, journalPool,
|
2024-02-02 08:42:44 +00:00
|
|
|
generateVolumeGroupName(namePrefix, objUUID), reqName)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the request name in the omap matches the passed in request name
|
|
|
|
if savedVolumeGroupAttributes.RequestName != reqName {
|
|
|
|
// NOTE: This should never be possible, hence no cleanup, but log error
|
|
|
|
// and return, as cleanup may need to occur manually!
|
|
|
|
return nil, fmt.Errorf("internal state inconsistent, omap names mismatch,"+
|
|
|
|
" request name (%s) volume group UUID (%s) volume group omap name (%s)",
|
|
|
|
reqName, objUUID, savedVolumeGroupAttributes.RequestName)
|
|
|
|
}
|
|
|
|
volGroupData.GroupName = savedVolumeGroupAttributes.GroupName
|
|
|
|
volGroupData.VolumeGroupAttributes = &VolumeGroupAttributes{}
|
|
|
|
volGroupData.VolumeGroupAttributes.RequestName = savedVolumeGroupAttributes.RequestName
|
2024-06-18 09:11:33 +00:00
|
|
|
volGroupData.VolumeGroupAttributes.VolumeMap = savedVolumeGroupAttributes.VolumeMap
|
2024-08-06 16:02:34 +00:00
|
|
|
volGroupData.VolumeGroupAttributes.CreationTime = savedVolumeGroupAttributes.CreationTime
|
2024-02-02 08:42:44 +00:00
|
|
|
|
|
|
|
return volGroupData, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
UndoReservation undoes a reservation, in the reverse order of ReserveName
|
|
|
|
- The UUID directory is cleaned up before the GroupName key in the csiDirectory is cleaned up
|
|
|
|
|
|
|
|
NOTE: Ensure that the Ceph volume snapshots backing the reservation is cleaned up
|
|
|
|
prior to cleaning up the reservation
|
|
|
|
|
|
|
|
NOTE: As the function manipulates omaps, it should be called with a lock against the request name
|
|
|
|
held, to prevent parallel operations from modifying the state of the omaps for this request name.
|
|
|
|
|
|
|
|
Input arguments:
|
|
|
|
- csiJournalPool: Pool name that holds the CSI request name based journal
|
|
|
|
- groupID: ID of the volume group, generated from the UUID
|
|
|
|
- reqName: Request name for the volume group
|
|
|
|
*/
|
2024-07-16 15:23:49 +00:00
|
|
|
func (vgjc *volumeGroupJournalConnection) UndoReservation(ctx context.Context,
|
2024-02-02 08:42:44 +00:00
|
|
|
csiJournalPool, groupID, reqName string,
|
|
|
|
) error {
|
|
|
|
// delete volume UUID omap (first, inverse of create order)
|
2024-03-19 13:48:27 +00:00
|
|
|
cj := vgjc.config
|
2024-02-02 08:42:44 +00:00
|
|
|
if groupID != "" {
|
|
|
|
if len(groupID) < uuidEncodedLength {
|
|
|
|
return fmt.Errorf("unable to parse UUID from %s, too short", groupID)
|
|
|
|
}
|
|
|
|
|
|
|
|
groupUUID := groupID[len(groupID)-36:]
|
|
|
|
if _, err := uuid.Parse(groupUUID); err != nil {
|
|
|
|
return fmt.Errorf("failed parsing UUID in %s: %w", groupUUID, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err := util.RemoveObject(
|
|
|
|
ctx,
|
2024-03-19 13:48:27 +00:00
|
|
|
vgjc.connection.monitors,
|
|
|
|
vgjc.connection.cr,
|
2024-02-02 08:42:44 +00:00
|
|
|
csiJournalPool,
|
|
|
|
cj.namespace,
|
|
|
|
cj.cephUUIDDirectoryPrefix+groupUUID)
|
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, util.ErrObjectNotFound) {
|
|
|
|
log.ErrorLog(ctx, "failed removing oMap %s (%s)", cj.cephUUIDDirectoryPrefix+groupUUID, err)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete the request name key (last, inverse of create order)
|
2024-03-19 13:48:27 +00:00
|
|
|
err := removeMapKeys(ctx, vgjc.connection, csiJournalPool, cj.namespace, cj.csiDirectory,
|
2024-02-02 08:42:44 +00:00
|
|
|
[]string{cj.csiNameKeyPrefix + reqName})
|
|
|
|
if err != nil {
|
|
|
|
log.ErrorLog(ctx, "failed removing oMap key %s (%s)", cj.csiNameKeyPrefix+reqName, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ReserveName adds respective entries to the csiDirectory omaps, post generating a target
|
|
|
|
UUIDDirectory for use. Further, these functions update the UUIDDirectory omaps, to store back
|
|
|
|
pointers to the CSI generated request names.
|
|
|
|
|
|
|
|
NOTE: As the function manipulates omaps, it should be called with a lock against the request name
|
|
|
|
held, to prevent parallel operations from modifying the state of the omaps for this request name.
|
|
|
|
|
|
|
|
Input arguments:
|
|
|
|
- journalPool: Pool where the CSI journal is stored
|
|
|
|
- reqName: Name of the volumeGroupSnapshot request received
|
|
|
|
- namePrefix: Prefix to use when generating the volumeGroupName name (suffix is an auto-generated UUID)
|
|
|
|
|
|
|
|
Return values:
|
|
|
|
- string: Contains the UUID that was reserved for the passed in reqName
|
|
|
|
- string: Contains the VolumeGroup name that was reserved for the passed in reqName
|
|
|
|
- error: non-nil in case of any errors
|
|
|
|
*/
|
2024-07-16 15:23:49 +00:00
|
|
|
func (vgjc *volumeGroupJournalConnection) ReserveName(ctx context.Context,
|
2024-03-19 17:36:17 +00:00
|
|
|
journalPool, reqName, namePrefix string,
|
2024-02-02 08:42:44 +00:00
|
|
|
) (string, string, error) {
|
2024-03-19 13:48:27 +00:00
|
|
|
cj := vgjc.config
|
2024-02-02 08:42:44 +00:00
|
|
|
|
|
|
|
// Create the UUID based omap first, to reserve the same and avoid conflicts
|
|
|
|
// NOTE: If any service loss occurs post creation of the UUID directory, and before
|
|
|
|
// setting the request name key to point back to the UUID directory, the
|
|
|
|
// UUID directory key will be leaked
|
|
|
|
objUUID, err := reserveOMapName(
|
|
|
|
ctx,
|
2024-03-19 13:48:27 +00:00
|
|
|
vgjc.connection.monitors,
|
|
|
|
vgjc.connection.cr,
|
2024-02-02 08:42:44 +00:00
|
|
|
journalPool,
|
|
|
|
cj.namespace,
|
|
|
|
cj.cephUUIDDirectoryPrefix,
|
|
|
|
"")
|
|
|
|
if err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
groupName := generateVolumeGroupName(namePrefix, objUUID)
|
|
|
|
nameKeyVal := objUUID
|
|
|
|
// After generating the UUID Directory omap, we populate the csiDirectory
|
|
|
|
// omap with a key-value entry to map the request to the backend volume group:
|
|
|
|
// `csiNameKeyPrefix + reqName: nameKeyVal`
|
2024-03-19 13:48:27 +00:00
|
|
|
err = setOMapKeys(ctx, vgjc.connection, journalPool, cj.namespace, cj.csiDirectory,
|
2024-02-02 08:42:44 +00:00
|
|
|
map[string]string{cj.csiNameKeyPrefix + reqName: nameKeyVal})
|
|
|
|
if err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
log.WarningLog(ctx, "reservation failed for volume group: %s", reqName)
|
2024-03-19 13:48:27 +00:00
|
|
|
errDefer := vgjc.UndoReservation(ctx, journalPool, groupName, reqName)
|
2024-02-02 08:42:44 +00:00
|
|
|
if errDefer != nil {
|
|
|
|
log.WarningLog(ctx, "failed undoing reservation of volume group: %s (%v)", reqName, errDefer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
oid := cj.cephUUIDDirectoryPrefix + objUUID
|
|
|
|
omapValues := map[string]string{}
|
|
|
|
|
|
|
|
// Update UUID directory to store CSI request name
|
|
|
|
omapValues[cj.csiNameKey] = reqName
|
|
|
|
omapValues[cj.csiImageKey] = groupName
|
|
|
|
|
2024-08-06 16:02:34 +00:00
|
|
|
t, err := time.Now().MarshalText()
|
|
|
|
if err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
omapValues[cj.csiCreationTimeKey] = string(t)
|
|
|
|
|
2024-03-19 13:48:27 +00:00
|
|
|
err = setOMapKeys(ctx, vgjc.connection, journalPool, cj.namespace, oid, omapValues)
|
2024-02-02 08:42:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return objUUID, groupName, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// VolumeGroupAttributes contains the request name and the volumeID's and
|
|
|
|
// the corresponding snapshotID's.
|
|
|
|
type VolumeGroupAttributes struct {
|
2024-08-06 16:02:34 +00:00
|
|
|
RequestName string // Contains the request name for the passed in UUID
|
|
|
|
GroupName string // Contains the group name
|
|
|
|
CreationTime *time.Time // Contains the time of creation of the group
|
|
|
|
VolumeMap map[string]string // Contains the volumeID and the corresponding value mapping
|
2024-02-02 08:42:44 +00:00
|
|
|
}
|
|
|
|
|
2024-07-16 15:23:49 +00:00
|
|
|
func (vgjc *volumeGroupJournalConnection) GetVolumeGroupAttributes(
|
2024-02-02 08:42:44 +00:00
|
|
|
ctx context.Context,
|
|
|
|
pool, objectUUID string,
|
|
|
|
) (*VolumeGroupAttributes, error) {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
groupAttributes = &VolumeGroupAttributes{}
|
2024-03-19 13:48:27 +00:00
|
|
|
cj = vgjc.config
|
2024-02-02 08:42:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
values, err := listOMapValues(
|
2024-03-19 13:48:27 +00:00
|
|
|
ctx, vgjc.connection, pool, cj.namespace, cj.cephUUIDDirectoryPrefix+objectUUID,
|
2024-02-02 08:42:44 +00:00
|
|
|
cj.commonPrefix)
|
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, util.ErrKeyNotFound) && !errors.Is(err, util.ErrPoolNotFound) {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
log.WarningLog(ctx, "unable to read omap values: pool missing: %v", err)
|
|
|
|
}
|
|
|
|
|
2024-08-06 16:02:34 +00:00
|
|
|
t := &time.Time{}
|
|
|
|
err = t.UnmarshalText([]byte(values[cj.csiCreationTimeKey]))
|
|
|
|
if err != nil {
|
|
|
|
t = nil
|
|
|
|
}
|
|
|
|
|
2024-02-02 08:42:44 +00:00
|
|
|
groupAttributes.RequestName = values[cj.csiNameKey]
|
|
|
|
groupAttributes.GroupName = values[cj.csiImageKey]
|
2024-08-06 16:02:34 +00:00
|
|
|
groupAttributes.CreationTime = t
|
2024-02-02 08:42:44 +00:00
|
|
|
|
|
|
|
// Remove request name key and group name key from the omap, as we are
|
|
|
|
// looking for volumeID/snapshotID mapping
|
|
|
|
delete(values, cj.csiNameKey)
|
|
|
|
delete(values, cj.csiImageKey)
|
2024-08-06 16:02:34 +00:00
|
|
|
delete(values, cj.csiCreationTimeKey)
|
2024-06-18 09:11:33 +00:00
|
|
|
groupAttributes.VolumeMap = map[string]string{}
|
2024-02-02 08:42:44 +00:00
|
|
|
for k, v := range values {
|
2024-06-18 09:11:33 +00:00
|
|
|
groupAttributes.VolumeMap[k] = v
|
2024-02-02 08:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return groupAttributes, nil
|
|
|
|
}
|
|
|
|
|
2024-07-16 15:23:49 +00:00
|
|
|
func (vgjc *volumeGroupJournalConnection) AddVolumesMapping(
|
2024-02-02 08:42:44 +00:00
|
|
|
ctx context.Context,
|
|
|
|
pool,
|
2024-06-18 09:19:11 +00:00
|
|
|
reservedUUID string,
|
|
|
|
volumeMap map[string]string,
|
2024-02-02 08:42:44 +00:00
|
|
|
) error {
|
2024-03-19 13:48:27 +00:00
|
|
|
err := setOMapKeys(ctx, vgjc.connection, pool, vgjc.config.namespace, vgjc.config.cephUUIDDirectoryPrefix+reservedUUID,
|
2024-06-18 09:19:11 +00:00
|
|
|
volumeMap)
|
2024-02-02 08:42:44 +00:00
|
|
|
if err != nil {
|
2024-06-18 09:19:11 +00:00
|
|
|
log.ErrorLog(ctx, "failed to add volumeMap %v: %w ", volumeMap, err)
|
2024-02-02 08:42:44 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-07-16 15:23:49 +00:00
|
|
|
func (vgjc *volumeGroupJournalConnection) RemoveVolumesMapping(
|
2024-02-02 08:42:44 +00:00
|
|
|
ctx context.Context,
|
|
|
|
pool,
|
2024-06-18 09:14:37 +00:00
|
|
|
reservedUUID string,
|
|
|
|
volumeIDs []string,
|
2024-02-02 08:42:44 +00:00
|
|
|
) error {
|
2024-03-19 13:48:27 +00:00
|
|
|
err := removeMapKeys(ctx, vgjc.connection, pool, vgjc.config.namespace,
|
|
|
|
vgjc.config.cephUUIDDirectoryPrefix+reservedUUID,
|
2024-06-18 09:14:37 +00:00
|
|
|
volumeIDs)
|
2024-02-02 08:42:44 +00:00
|
|
|
if err != nil {
|
2024-06-18 09:14:37 +00:00
|
|
|
log.ErrorLog(ctx, "failed removing volume mapping from group: key: %q %v", volumeIDs, err)
|
2024-02-02 08:42:44 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|