mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +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:
committed by
mergify[bot]
parent
14d6211d6d
commit
30244bf11b
@ -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.
|
||||
|
Reference in New Issue
Block a user