From 0f9087d05e341fecdccff9319d0f4ee5f83f98a4 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Mon, 19 Oct 2020 09:08:57 +0200 Subject: [PATCH] cephfs: connect snapshot to Ceph cluster in newSnapshotOptionsFromID() Without connection, follow-up oparations on the volumeOptions object will cause a panic. This should fix a regression in CephFS testing. Signed-off-by: Niels de Vos --- internal/cephfs/controllerserver.go | 1 + internal/cephfs/volumeoptions.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/internal/cephfs/controllerserver.go b/internal/cephfs/controllerserver.go index 799766cbc..4f9a01824 100644 --- a/internal/cephfs/controllerserver.go +++ b/internal/cephfs/controllerserver.go @@ -691,6 +691,7 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS } return nil, status.Error(codes.Internal, err.Error()) } + defer volOpt.Destroy() // safeguard against parallel create or delete requests against the same // name diff --git a/internal/cephfs/volumeoptions.go b/internal/cephfs/volumeoptions.go index a0b5a82f1..f50626300 100644 --- a/internal/cephfs/volumeoptions.go +++ b/internal/cephfs/volumeoptions.go @@ -478,6 +478,19 @@ func newSnapshotOptionsFromID(ctx context.Context, snapID string, cr *util.Crede return &volOptions, nil, &sid, fmt.Errorf("failed to fetch subvolumegroup list using clusterID (%s): %w", vi.ClusterID, err) } + err = volOptions.Connect(cr) + if err != nil { + return &volOptions, nil, &sid, err + } + // in case of an error, volOptions is returned, but callers may not + // expect to need to call Destroy() on it. So, make sure to release any + // resources that may have been allocated + defer func() { + if err != nil { + volOptions.Destroy() + } + }() + volOptions.FsName, err = volOptions.getFsName(ctx) if err != nil { return &volOptions, nil, &sid, err