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 <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2021-12-20 20:44:28 +05:30 committed by mergify[bot]
parent c6b288779a
commit edcb2b529b
5 changed files with 22 additions and 20 deletions

View File

@ -128,7 +128,7 @@ func (rv *rbdVolume) generateTempClone() *rbdVolume {
tempClone.conn = rv.conn.Copy() tempClone.conn = rv.conn.Copy()
// The temp clone image need to have deep flatten feature // The temp clone image need to have deep flatten feature
f := []string{librbd.FeatureNameLayering, librbd.FeatureNameDeepFlatten} f := []string{librbd.FeatureNameLayering, librbd.FeatureNameDeepFlatten}
tempClone.imageFeatureSet = librbd.FeatureSetFromNames(f) tempClone.ImageFeatureSet = librbd.FeatureSetFromNames(f)
tempClone.ClusterID = rv.ClusterID tempClone.ClusterID = rv.ClusterID
tempClone.Monitors = rv.Monitors tempClone.Monitors = rv.Monitors
tempClone.Pool = rv.Pool tempClone.Pool = rv.Pool

View File

@ -1204,7 +1204,7 @@ func (cs *ControllerServer) doSnapshotClone(
defer cloneRbd.Destroy() defer cloneRbd.Destroy()
// add image feature for cloneRbd // add image feature for cloneRbd
f := []string{librbd.FeatureNameLayering, librbd.FeatureNameDeepFlatten} f := []string{librbd.FeatureNameLayering, librbd.FeatureNameDeepFlatten}
cloneRbd.imageFeatureSet = librbd.FeatureSetFromNames(f) cloneRbd.ImageFeatureSet = librbd.FeatureSetFromNames(f)
err := cloneRbd.Connect(cr) err := cloneRbd.Connect(cr)
if err != nil { if err != nil {

View File

@ -127,6 +127,12 @@ type rbdImage struct {
RequestName string RequestName string
NamePrefix 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 provides access to optional VolumeEncryption functions
encryption *util.VolumeEncryption encryption *util.VolumeEncryption
// Owner is the creator (tenant, Kubernetes Namespace) of the volume // Owner is the creator (tenant, Kubernetes Namespace) of the volume
@ -151,11 +157,7 @@ type rbdVolume struct {
Topology map[string]string Topology map[string]string
// DataPool is where the data for images in `Pool` are stored, this is used as the `--data-pool` // 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 // argument when the pool is created, and is not used anywhere else
DataPool string DataPool string
ParentName string
// Parent Pool is the pool that contains the parent image.
ParentPool string
imageFeatureSet librbd.FeatureSet
AdminID string AdminID string
UserID string UserID string
Mounter string Mounter string
@ -349,10 +351,10 @@ func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er
} }
} }
log.DebugLog(ctx, logMsg, log.DebugLog(ctx, logMsg,
pOpts, volSzMiB, pOpts.imageFeatureSet.Names(), pOpts.Monitors) pOpts, volSzMiB, pOpts.ImageFeatureSet.Names(), pOpts.Monitors)
if pOpts.imageFeatureSet != 0 { if pOpts.ImageFeatureSet != 0 {
err := options.SetUint64(librbd.RbdImageOptionFeatures, uint64(pOpts.imageFeatureSet)) err := options.SetUint64(librbd.RbdImageOptionFeatures, uint64(pOpts.ImageFeatureSet))
if err != nil { if err != nil {
return fmt.Errorf("failed to set image features: %w", err) 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 { 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) { func (rv *rbdVolume) checkImageChainHasFeature(ctx context.Context, feature uint64) (bool, error) {
@ -1315,7 +1317,7 @@ func genVolFromVolumeOptions(
ctx, ctx,
"setting disableInUseChecks: %t image features: %v mounter: %s", "setting disableInUseChecks: %t image features: %v mounter: %s",
disableInUseChecks, disableInUseChecks,
rbdVol.imageFeatureSet.Names(), rbdVol.ImageFeatureSet.Names(),
rbdVol.Mounter) rbdVol.Mounter)
rbdVol.DisableInUseChecks = disableInUseChecks 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) return fmt.Errorf("feature %s requires rbd-nbd for mounter", f)
} }
} }
rv.imageFeatureSet = librbd.FeatureSetFromNames(arr) rv.ImageFeatureSet = librbd.FeatureSetFromNames(arr)
return nil return nil
} }
@ -1386,7 +1388,7 @@ func genSnapFromOptions(ctx context.Context, rbdVol *rbdVolume, snapOptions map[
// hasSnapshotFeature checks if Layering is enabled for this image. // hasSnapshotFeature checks if Layering is enabled for this image.
func (rv *rbdVolume) hasSnapshotFeature() bool { 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 { func (rv *rbdVolume) createSnapshot(ctx context.Context, pOpts *rbdSnapshot) error {
@ -1450,10 +1452,10 @@ func (rv *rbdVolume) cloneRbdImageFromSnapshot(
} }
log.DebugLog(ctx, logMsg, log.DebugLog(ctx, logMsg,
pSnapOpts, rv, rv.imageFeatureSet.Names(), rv.Monitors) pSnapOpts, rv, rv.ImageFeatureSet.Names(), rv.Monitors)
if rv.imageFeatureSet != 0 { if rv.ImageFeatureSet != 0 {
err = options.SetUint64(librbd.RbdImageOptionFeatures, uint64(rv.imageFeatureSet)) err = options.SetUint64(librbd.RbdImageOptionFeatures, uint64(rv.ImageFeatureSet))
if err != nil { if err != nil {
return fmt.Errorf("failed to set image features: %w", err) return fmt.Errorf("failed to set image features: %w", err)
} }
@ -1527,7 +1529,7 @@ func (rv *rbdVolume) getImageInfo() error {
if err != nil { if err != nil {
return err return err
} }
rv.imageFeatureSet = librbd.FeatureSet(features) rv.ImageFeatureSet = librbd.FeatureSet(features)
// Get parent information. // Get parent information.
parentInfo, err := image.GetParent() parentInfo, err := image.GetParent()

View File

@ -41,7 +41,7 @@ func TestHasSnapshotFeature(t *testing.T) {
rv := rbdVolume{} rv := rbdVolume{}
for _, test := range tests { 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 { if got := rv.hasSnapshotFeature(); got != test.hasFeature {
t.Errorf("hasSnapshotFeature(%s) = %t, want %t", test.features, got, test.hasFeature) t.Errorf("hasSnapshotFeature(%s) = %t, want %t", test.features, got, test.hasFeature)
} }

View File

@ -324,7 +324,7 @@ func createDummyImage(ctx context.Context, rbdVol *rbdVolume) error {
librbd.FeatureNameFastDiff, librbd.FeatureNameFastDiff,
} }
features := librbd.FeatureSetFromNames(f) features := librbd.FeatureSetFromNames(f)
dummyVol.imageFeatureSet = features dummyVol.ImageFeatureSet = features
// create 1MiB dummy image. 1MiB=1048576 bytes // create 1MiB dummy image. 1MiB=1048576 bytes
dummyVol.VolSize = 1048576 dummyVol.VolSize = 1048576
err = createImage(ctx, &dummyVol, dummyVol.conn.Creds) err = createImage(ctx, &dummyVol, dummyVol.conn.Creds)