mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-23 21:40:20 +00:00
cephfs: snapshots honor --setmetadata
option
`--setmetadata` is false by default, honoring it will keep the metadata disabled by default Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
parent
14d6211d6d
commit
30244bf11b
@ -601,13 +601,8 @@ func (cs *ControllerServer) cleanUpBackingVolume(
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
} else {
|
||||
snapClient := core.NewSnapshot(
|
||||
snapParentVolOptions.GetConnection(),
|
||||
snapID.FsSnapshotName,
|
||||
volOptions.ClusterID,
|
||||
cs.ClusterName,
|
||||
&snapParentVolOptions.SubVolume,
|
||||
)
|
||||
snapClient := core.NewSnapshot(snapParentVolOptions.GetConnection(), snapID.FsSnapshotName,
|
||||
volOptions.ClusterID, cs.ClusterName, cs.SetMetadata, &snapParentVolOptions.SubVolume)
|
||||
|
||||
err = deleteSnapshotAndUndoReservation(ctx, snapClient, snapParentVolOptions, snapID, cr)
|
||||
if err != nil {
|
||||
@ -785,7 +780,7 @@ func (cs *ControllerServer) CreateSnapshot(
|
||||
}
|
||||
defer cs.VolumeLocks.Release(sourceVolID)
|
||||
snapName := req.GetName()
|
||||
sid, snapInfo, err := store.CheckSnapExists(ctx, parentVolOptions, cephfsSnap, cs.ClusterName, cr)
|
||||
sid, snapInfo, err := store.CheckSnapExists(ctx, parentVolOptions, cephfsSnap, cs.ClusterName, cs.SetMetadata, cr)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
@ -823,12 +818,8 @@ func (cs *ControllerServer) CreateSnapshot(
|
||||
if sid != nil {
|
||||
// check snapshot is protected
|
||||
protected := true
|
||||
snapClient := core.NewSnapshot(
|
||||
parentVolOptions.GetConnection(),
|
||||
sid.FsSnapshotName,
|
||||
parentVolOptions.ClusterID,
|
||||
cs.ClusterName,
|
||||
&parentVolOptions.SubVolume)
|
||||
snapClient := core.NewSnapshot(parentVolOptions.GetConnection(), sid.FsSnapshotName,
|
||||
parentVolOptions.ClusterID, cs.ClusterName, cs.SetMetadata, &parentVolOptions.SubVolume)
|
||||
if !(snapInfo.Protected == core.SnapshotIsProtected) {
|
||||
err = snapClient.ProtectSnapshot(ctx)
|
||||
if err != nil {
|
||||
@ -872,7 +863,7 @@ func (cs *ControllerServer) CreateSnapshot(
|
||||
}
|
||||
}
|
||||
}()
|
||||
snap, err := doSnapshot(ctx, parentVolOptions, sID.FsSnapshotName, cs.ClusterName, metadata)
|
||||
snap, err := cs.doSnapshot(ctx, parentVolOptions, sID.FsSnapshotName, metadata)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
@ -888,17 +879,16 @@ func (cs *ControllerServer) CreateSnapshot(
|
||||
}, nil
|
||||
}
|
||||
|
||||
func doSnapshot(
|
||||
func (cs *ControllerServer) doSnapshot(
|
||||
ctx context.Context,
|
||||
volOpt *store.VolumeOptions,
|
||||
snapshotName,
|
||||
clusterName string,
|
||||
snapshotName string,
|
||||
metadata map[string]string,
|
||||
) (core.SnapshotInfo, error) {
|
||||
snapID := fsutil.VolumeID(snapshotName)
|
||||
snap := core.SnapshotInfo{}
|
||||
snapClient := core.NewSnapshot(volOpt.GetConnection(), snapshotName,
|
||||
volOpt.ClusterID, clusterName, &volOpt.SubVolume)
|
||||
volOpt.ClusterID, cs.ClusterName, cs.SetMetadata, &volOpt.SubVolume)
|
||||
err := snapClient.CreateSnapshot(ctx)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "failed to create snapshot %s %v", snapID, err)
|
||||
@ -1056,7 +1046,7 @@ func (cs *ControllerServer) DeleteSnapshot(
|
||||
return nil, status.Errorf(codes.FailedPrecondition, "snapshot %s has pending clones", snapshotID)
|
||||
}
|
||||
snapClient := core.NewSnapshot(volOpt.GetConnection(), sid.FsSnapshotName,
|
||||
volOpt.ClusterID, cs.ClusterName, &volOpt.SubVolume)
|
||||
volOpt.ClusterID, cs.ClusterName, cs.SetMetadata, &volOpt.SubVolume)
|
||||
if snapInfo.Protected == core.SnapshotIsProtected {
|
||||
err = snapClient.UnprotectSnapshot(ctx)
|
||||
if err != nil {
|
||||
|
@ -66,7 +66,7 @@ func (s *subVolumeClient) CreateCloneFromSubvolume(
|
||||
parentvolOpt *SubVolume,
|
||||
) error {
|
||||
snapshotID := s.VolID
|
||||
snapClient := NewSnapshot(s.conn, snapshotID, s.clusterID, s.clusterName, parentvolOpt)
|
||||
snapClient := NewSnapshot(s.conn, snapshotID, s.clusterID, s.clusterName, s.enableMetadata, parentvolOpt)
|
||||
err := snapClient.CreateSnapshot(ctx)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "failed to create snapshot %s %v", snapshotID, err)
|
||||
@ -165,7 +165,7 @@ func (s *subVolumeClient) CleanupSnapshotFromSubvolume(
|
||||
// snapshot name is same as clone name as we need a name which can be
|
||||
// identified during PVC-PVC cloning.
|
||||
snapShotID := s.VolID
|
||||
snapClient := NewSnapshot(s.conn, snapShotID, s.clusterID, s.clusterName, parentVol)
|
||||
snapClient := NewSnapshot(s.conn, snapShotID, s.clusterID, s.clusterName, s.enableMetadata, parentVol)
|
||||
snapInfo, err := snapClient.GetSnapshotInfo(ctx)
|
||||
if err != nil {
|
||||
if errors.Is(err, cerrors.ErrSnapNotFound) {
|
||||
@ -198,7 +198,7 @@ func (s *subVolumeClient) CreateCloneFromSnapshot(
|
||||
ctx context.Context, snap Snapshot,
|
||||
) error {
|
||||
snapID := snap.SnapshotID
|
||||
snapClient := NewSnapshot(s.conn, snapID, s.clusterID, s.clusterName, snap.SubVolume)
|
||||
snapClient := NewSnapshot(s.conn, snapID, s.clusterID, s.clusterName, s.enableMetadata, snap.SubVolume)
|
||||
err := snapClient.CloneSnapshot(ctx, s.SubVolume)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -61,10 +61,11 @@ type SnapshotClient interface {
|
||||
|
||||
// snapshotClient is the implementation of SnapshotClient interface.
|
||||
type snapshotClient struct {
|
||||
*Snapshot // Embedded snapshot struct.
|
||||
clusterID string // Cluster ID.
|
||||
clusterName string // Cluster Name.
|
||||
conn *util.ClusterConnection // Cluster connection.
|
||||
*Snapshot // Embedded snapshot struct.
|
||||
clusterID string // Cluster ID.
|
||||
clusterName string // Cluster Name.
|
||||
enableMetadata bool // Set metadata on volume
|
||||
conn *util.ClusterConnection // Cluster connection.
|
||||
}
|
||||
|
||||
// Snapshot represents a subvolume snapshot and its cluster information.
|
||||
@ -79,6 +80,7 @@ func NewSnapshot(
|
||||
snapshotID,
|
||||
clusterID,
|
||||
clusterName string,
|
||||
setMetadata bool,
|
||||
vol *SubVolume,
|
||||
) SnapshotClient {
|
||||
return &snapshotClient{
|
||||
@ -86,9 +88,10 @@ func NewSnapshot(
|
||||
SnapshotID: snapshotID,
|
||||
SubVolume: vol,
|
||||
},
|
||||
clusterID: clusterID,
|
||||
clusterName: clusterName,
|
||||
conn: conn,
|
||||
clusterID: clusterID,
|
||||
clusterName: clusterName,
|
||||
enableMetadata: setMetadata,
|
||||
conn: conn,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,10 @@ func (s *snapshotClient) removeSnapshotMetadata(key string) error {
|
||||
// SetAllSnapshotMetadata set all the metadata from arg parameters on
|
||||
// subvolume snapshot.
|
||||
func (s *snapshotClient) SetAllSnapshotMetadata(parameters map[string]string) error {
|
||||
if !s.enableMetadata {
|
||||
return nil
|
||||
}
|
||||
|
||||
for k, v := range parameters {
|
||||
err := s.setSnapshotMetadata(k, v)
|
||||
if err != nil {
|
||||
@ -113,6 +117,10 @@ func (s *snapshotClient) SetAllSnapshotMetadata(parameters map[string]string) er
|
||||
// UnsetAllSnapshotMetadata unset all the metadata from arg keys on subvolume
|
||||
// snapshot.
|
||||
func (s *snapshotClient) UnsetAllSnapshotMetadata(keys []string) error {
|
||||
if !s.enableMetadata {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, key := range keys {
|
||||
err := s.removeSnapshotMetadata(key)
|
||||
// TODO: replace string comparison with errno.
|
||||
|
@ -379,6 +379,7 @@ func CheckSnapExists(
|
||||
volOptions *VolumeOptions,
|
||||
snap *SnapshotOption,
|
||||
clusterName string,
|
||||
setMetadata bool,
|
||||
cr *util.Credentials,
|
||||
) (*SnapshotIdentifier, *core.SnapshotInfo, error) {
|
||||
// Connect to cephfs' default radosNamespace (csi)
|
||||
@ -400,7 +401,8 @@ func CheckSnapExists(
|
||||
snapUUID := snapData.ImageUUID
|
||||
snapID := snapData.ImageAttributes.ImageName
|
||||
sid.FsSnapshotName = snapData.ImageAttributes.ImageName
|
||||
snapClient := core.NewSnapshot(volOptions.conn, snapID, volOptions.ClusterID, clusterName, &volOptions.SubVolume)
|
||||
snapClient := core.NewSnapshot(volOptions.conn, snapID,
|
||||
volOptions.ClusterID, clusterName, setMetadata, &volOptions.SubVolume)
|
||||
snapInfo, err := snapClient.GetSnapshotInfo(ctx)
|
||||
if err != nil {
|
||||
if errors.Is(err, cerrors.ErrSnapNotFound) {
|
||||
|
@ -749,7 +749,7 @@ func NewSnapshotOptionsFromID(
|
||||
volOptions.Size = subvolInfo.BytesQuota
|
||||
volOptions.RootPath = subvolInfo.Path
|
||||
snap := core.NewSnapshot(volOptions.conn, sid.FsSnapshotName,
|
||||
volOptions.ClusterID, clusterName, &volOptions.SubVolume)
|
||||
volOptions.ClusterID, clusterName, setMetadata, &volOptions.SubVolume)
|
||||
info, err := snap.GetSnapshotInfo(ctx)
|
||||
if err != nil {
|
||||
return &volOptions, nil, &sid, err
|
||||
|
Loading…
Reference in New Issue
Block a user