From 38aa57592500ec6f23b03b822938705c74a28374 Mon Sep 17 00:00:00 2001 From: Seungcheol Ko Date: Thu, 9 Aug 2018 22:07:13 +0900 Subject: [PATCH] check snapshot feature --- pkg/rbd/controllerserver.go | 4 ++++ pkg/rbd/rbd_util.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/rbd/controllerserver.go b/pkg/rbd/controllerserver.go index ca3ce0357..736ec63f9 100644 --- a/pkg/rbd/controllerserver.go +++ b/pkg/rbd/controllerserver.go @@ -236,6 +236,10 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS if err != nil { return nil, status.Error(codes.NotFound, fmt.Sprintf("Source Volume ID %s cannot found", req.GetSourceVolumeId())) } + if !hasSnapshotFeature(rbdVolume.ImageFeatures) { + return nil, fmt.Errorf("Volume(%s) has not snapshot feature(layering)", req.GetSourceVolumeId()) + } + rbdSnap.VolName = rbdVolume.VolName rbdSnap.SnapName = snapName snapshotID := "csi-rbd-" + rbdVolume.VolName + "-snap-" + uniqueID diff --git a/pkg/rbd/rbd_util.go b/pkg/rbd/rbd_util.go index 7b0c386f6..e2682b032 100644 --- a/pkg/rbd/rbd_util.go +++ b/pkg/rbd/rbd_util.go @@ -254,6 +254,16 @@ func getRBDSnapshotOptions(snapOptions map[string]string) (*rbdSnapshot, error) return rbdSnap, nil } +func hasSnapshotFeature(imageFeatures string) bool { + arr := strings.Split(imageFeatures, ",") + for _, f := range arr { + if f == "layering" { + return true + } + } + return false +} + func attachRBDImage(volOptions *rbdVolume, userId string, credentials map[string]string) (string, error) { var err error var output []byte