From 6d14eeee70b7fb99e23723fe5164cb414d4caff6 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Thu, 17 Jun 2021 18:21:28 +0530 Subject: [PATCH] rbd: use RbdSnapName to check the image details RbdSnapName holds the actual RBD image name which got created during the CreateSnapshot operation. RbdImageName holds the name of the parent from which the snapshot is created. and the parent is independent of snapshot and it can be deleted any time for the same reason using the RbdSnapName to check the rbd image details. generate a temporary volume from the snapshot which replaces the rbdImageName with RbdSnapName and use it to check the image metadata. Signed-off-by: Madhu Rajanna --- internal/rbd/rbd_util.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index ae6c769bc..a6cb3658a 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -1629,3 +1629,31 @@ func (ri *rbdImage) isCompatibleThickProvision(dst *rbdVolume) error { return nil } + +// FIXME: merge isCompatibleThickProvision of rbdSnapshot and rbdImage to a single +// function. +func (rs *rbdSnapshot) isCompatibleThickProvision(dst *rbdVolume) error { + // During CreateSnapshot the rbd image will be created with the + // snapshot name. Replacing RbdImageName with RbdSnapName so that we + // can check if the image is thick provisioned + vol := generateVolFromSnap(rs) + err := vol.Connect(rs.conn.Creds) + if err != nil { + return err + } + defer vol.Destroy() + + thick, err := vol.isThickProvisioned() + if err != nil { + return err + } + switch { + case thick && !dst.ThickProvision: + return fmt.Errorf("cannot create thin volume from thick volume %q", vol) + + case !thick && dst.ThickProvision: + return fmt.Errorf("cannot create thick volume from thin volume %q", vol) + } + + return nil +}