From 771470d9755a32f78a98d6831d585151f2d7b6ad Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 30 Aug 2023 11:13:03 +0200 Subject: [PATCH] cephfs: add support for RWX clone from ROX Add support to create RWX clone from the ROX clone, in ceph no subvolume clone is created when ROX clone is created from a snapshot just a internal ref counter is added. This PR allows creating a RWX clone from a ROX clone which allows users to create RW copy of PVC where cephcsi will identify the snapshot created for the ROX volume and creates a subvolume from the CephFS snapshot. updates: #3603 Signed-off-by: Madhu Rajanna --- internal/cephfs/controllerserver.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/cephfs/controllerserver.go b/internal/cephfs/controllerserver.go index ce4c19dc5..d1c126fc3 100644 --- a/internal/cephfs/controllerserver.go +++ b/internal/cephfs/controllerserver.go @@ -299,6 +299,23 @@ func (cs *ControllerServer) CreateVolume( return nil, status.Error(codes.InvalidArgument, err.Error()) } + // As we are trying to create RWX volume from backing snapshot, we need to + // retrieve the snapshot details from the backing snapshot and create a + // subvolume clone from the snapshot. + if parentVol != nil && parentVol.BackingSnapshot && !store.IsVolumeCreateRO(req.VolumeCapabilities) { + // unset pvID as we dont have real subvolume for the parent volumeID as its a backing snapshot + pvID = nil + parentVol, _, sID, err = store.NewSnapshotOptionsFromID(ctx, parentVol.BackingSnapshotID, cr, + req.GetSecrets(), cs.ClusterName, cs.SetMetadata) + if err != nil { + if errors.Is(err, cerrors.ErrSnapNotFound) { + return nil, status.Error(codes.NotFound, err.Error()) + } + + return nil, status.Error(codes.Internal, err.Error()) + } + } + vID, err := store.CheckVolExists(ctx, volOptions, parentVol, pvID, sID, cr, cs.ClusterName, cs.SetMetadata) if err != nil { if cerrors.IsCloneRetryError(err) {