From edcb2b529b0c58b924fb1ab54dc944ee9a9614f1 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 20 Dec 2021 20:44:28 +0530 Subject: [PATCH] rbd: move core fields to rbdImage struct moved ParentName, ParentPool and ImageFeatureSet fields to the rbdImage struct as these are the first citizens on the rbdImage. Signed-off-by: Madhu Rajanna --- internal/rbd/clone.go | 2 +- internal/rbd/controllerserver.go | 2 +- internal/rbd/rbd_util.go | 34 +++++++++++---------- internal/rbd/rbd_util_test.go | 2 +- internal/rbd/replicationcontrollerserver.go | 2 +- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/internal/rbd/clone.go b/internal/rbd/clone.go index 1fe0e42d8..c72dbeb8c 100644 --- a/internal/rbd/clone.go +++ b/internal/rbd/clone.go @@ -128,7 +128,7 @@ func (rv *rbdVolume) generateTempClone() *rbdVolume { tempClone.conn = rv.conn.Copy() // The temp clone image need to have deep flatten feature f := []string{librbd.FeatureNameLayering, librbd.FeatureNameDeepFlatten} - tempClone.imageFeatureSet = librbd.FeatureSetFromNames(f) + tempClone.ImageFeatureSet = librbd.FeatureSetFromNames(f) tempClone.ClusterID = rv.ClusterID tempClone.Monitors = rv.Monitors tempClone.Pool = rv.Pool diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 7f6cb93e7..1c72357a8 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -1204,7 +1204,7 @@ func (cs *ControllerServer) doSnapshotClone( defer cloneRbd.Destroy() // add image feature for cloneRbd f := []string{librbd.FeatureNameLayering, librbd.FeatureNameDeepFlatten} - cloneRbd.imageFeatureSet = librbd.FeatureSetFromNames(f) + cloneRbd.ImageFeatureSet = librbd.FeatureSetFromNames(f) err := cloneRbd.Connect(cr) if err != nil { diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 3b18c8e2c..b91fb1107 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -127,6 +127,12 @@ type rbdImage struct { RequestName string NamePrefix string + // ParentName represents the parent image name of the image. + ParentName string + // Parent Pool is the pool that contains the parent image. + ParentPool string + ImageFeatureSet librbd.FeatureSet + // encryption provides access to optional VolumeEncryption functions encryption *util.VolumeEncryption // Owner is the creator (tenant, Kubernetes Namespace) of the volume @@ -151,11 +157,7 @@ type rbdVolume struct { Topology map[string]string // DataPool is where the data for images in `Pool` are stored, this is used as the `--data-pool` // argument when the pool is created, and is not used anywhere else - DataPool string - ParentName string - // Parent Pool is the pool that contains the parent image. - ParentPool string - imageFeatureSet librbd.FeatureSet + DataPool string AdminID string UserID string Mounter string @@ -349,10 +351,10 @@ func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er } } log.DebugLog(ctx, logMsg, - pOpts, volSzMiB, pOpts.imageFeatureSet.Names(), pOpts.Monitors) + pOpts, volSzMiB, pOpts.ImageFeatureSet.Names(), pOpts.Monitors) - if pOpts.imageFeatureSet != 0 { - err := options.SetUint64(librbd.RbdImageOptionFeatures, uint64(pOpts.imageFeatureSet)) + if pOpts.ImageFeatureSet != 0 { + err := options.SetUint64(librbd.RbdImageOptionFeatures, uint64(pOpts.ImageFeatureSet)) if err != nil { return fmt.Errorf("failed to set image features: %w", err) } @@ -925,7 +927,7 @@ func (rv *rbdVolume) flatten() error { } func (rv *rbdVolume) hasFeature(feature uint64) bool { - return (uint64(rv.imageFeatureSet) & feature) == feature + return (uint64(rv.ImageFeatureSet) & feature) == feature } func (rv *rbdVolume) checkImageChainHasFeature(ctx context.Context, feature uint64) (bool, error) { @@ -1315,7 +1317,7 @@ func genVolFromVolumeOptions( ctx, "setting disableInUseChecks: %t image features: %v mounter: %s", disableInUseChecks, - rbdVol.imageFeatureSet.Names(), + rbdVol.ImageFeatureSet.Names(), rbdVol.Mounter) rbdVol.DisableInUseChecks = disableInUseChecks @@ -1353,7 +1355,7 @@ func (rv *rbdVolume) validateImageFeatures(imageFeatures string) error { return fmt.Errorf("feature %s requires rbd-nbd for mounter", f) } } - rv.imageFeatureSet = librbd.FeatureSetFromNames(arr) + rv.ImageFeatureSet = librbd.FeatureSetFromNames(arr) return nil } @@ -1386,7 +1388,7 @@ func genSnapFromOptions(ctx context.Context, rbdVol *rbdVolume, snapOptions map[ // hasSnapshotFeature checks if Layering is enabled for this image. func (rv *rbdVolume) hasSnapshotFeature() bool { - return (uint64(rv.imageFeatureSet) & librbd.FeatureLayering) == librbd.FeatureLayering + return (uint64(rv.ImageFeatureSet) & librbd.FeatureLayering) == librbd.FeatureLayering } func (rv *rbdVolume) createSnapshot(ctx context.Context, pOpts *rbdSnapshot) error { @@ -1450,10 +1452,10 @@ func (rv *rbdVolume) cloneRbdImageFromSnapshot( } log.DebugLog(ctx, logMsg, - pSnapOpts, rv, rv.imageFeatureSet.Names(), rv.Monitors) + pSnapOpts, rv, rv.ImageFeatureSet.Names(), rv.Monitors) - if rv.imageFeatureSet != 0 { - err = options.SetUint64(librbd.RbdImageOptionFeatures, uint64(rv.imageFeatureSet)) + if rv.ImageFeatureSet != 0 { + err = options.SetUint64(librbd.RbdImageOptionFeatures, uint64(rv.ImageFeatureSet)) if err != nil { return fmt.Errorf("failed to set image features: %w", err) } @@ -1527,7 +1529,7 @@ func (rv *rbdVolume) getImageInfo() error { if err != nil { return err } - rv.imageFeatureSet = librbd.FeatureSet(features) + rv.ImageFeatureSet = librbd.FeatureSet(features) // Get parent information. parentInfo, err := image.GetParent() diff --git a/internal/rbd/rbd_util_test.go b/internal/rbd/rbd_util_test.go index 2174ca2ea..6007106ba 100644 --- a/internal/rbd/rbd_util_test.go +++ b/internal/rbd/rbd_util_test.go @@ -41,7 +41,7 @@ func TestHasSnapshotFeature(t *testing.T) { rv := rbdVolume{} for _, test := range tests { - rv.imageFeatureSet = librbd.FeatureSetFromNames(strings.Split(test.features, ",")) + rv.ImageFeatureSet = librbd.FeatureSetFromNames(strings.Split(test.features, ",")) if got := rv.hasSnapshotFeature(); got != test.hasFeature { t.Errorf("hasSnapshotFeature(%s) = %t, want %t", test.features, got, test.hasFeature) } diff --git a/internal/rbd/replicationcontrollerserver.go b/internal/rbd/replicationcontrollerserver.go index d41fa7c6a..51c0ab6ac 100644 --- a/internal/rbd/replicationcontrollerserver.go +++ b/internal/rbd/replicationcontrollerserver.go @@ -324,7 +324,7 @@ func createDummyImage(ctx context.Context, rbdVol *rbdVolume) error { librbd.FeatureNameFastDiff, } features := librbd.FeatureSetFromNames(f) - dummyVol.imageFeatureSet = features + dummyVol.ImageFeatureSet = features // create 1MiB dummy image. 1MiB=1048576 bytes dummyVol.VolSize = 1048576 err = createImage(ctx, &dummyVol, dummyVol.conn.Creds)