mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
rbd: rename setImageOptions()
to constructImageOptions()
A function called `setImageOptions()` is expected to set the passed options on the volume. However, the passed options parameter is only filled with the options that should get set on the RBD-image at the time of creation. The naming of the function, and it's parameter is confusing. Rename the function to `constructImageOptions()` and return the ImageOptions to make it easier to understand. Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
parent
61c23dd4d2
commit
42fc0b6bce
@ -431,13 +431,11 @@ func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er
|
|||||||
log.DebugLog(ctx, "rbd: create %s size %s (features: %s) using mon %s",
|
log.DebugLog(ctx, "rbd: create %s size %s (features: %s) using mon %s",
|
||||||
pOpts, volSzMiB, pOpts.ImageFeatureSet.Names(), pOpts.Monitors)
|
pOpts, volSzMiB, pOpts.ImageFeatureSet.Names(), pOpts.Monitors)
|
||||||
|
|
||||||
options := librbd.NewRbdImageOptions()
|
options, err := pOpts.constructImageOptions(ctx)
|
||||||
defer options.Destroy()
|
|
||||||
|
|
||||||
err := pOpts.setImageOptions(ctx, options)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer options.Destroy()
|
||||||
|
|
||||||
err = pOpts.Connect(cr)
|
err = pOpts.Connect(cr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1494,12 +1492,11 @@ func (rv *rbdVolume) cloneRbdImageFromSnapshot(
|
|||||||
parentVol.ioctx = nil
|
parentVol.ioctx = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
options := librbd.NewRbdImageOptions()
|
options, err := rv.constructImageOptions(ctx)
|
||||||
defer options.Destroy()
|
|
||||||
err = rv.setImageOptions(ctx, options)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer options.Destroy()
|
||||||
|
|
||||||
err = options.SetUint64(librbd.ImageOptionCloneFormat, 2)
|
err = options.SetUint64(librbd.ImageOptionCloneFormat, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1545,23 +1542,30 @@ func (rv *rbdVolume) cloneRbdImageFromSnapshot(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// setImageOptions sets the image options.
|
// constructImageOptions constructs the ImageOptions that should get set on the
|
||||||
func (rv *rbdVolume) setImageOptions(ctx context.Context, options *librbd.ImageOptions) error {
|
// RBD-image at the time of its creation/cloning.
|
||||||
|
func (rv *rbdVolume) constructImageOptions(ctx context.Context) (*librbd.ImageOptions, error) {
|
||||||
var err error
|
var err error
|
||||||
|
options := librbd.NewRbdImageOptions()
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
options.Destroy()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
logMsg := fmt.Sprintf("setting image options on %s", rv)
|
logMsg := fmt.Sprintf("setting image options on %s", rv)
|
||||||
if rv.DataPool != "" {
|
if rv.DataPool != "" {
|
||||||
logMsg += ", data pool %s" + rv.DataPool
|
logMsg += ", data pool %s" + rv.DataPool
|
||||||
err = options.SetString(librbd.RbdImageOptionDataPool, rv.DataPool)
|
err = options.SetString(librbd.RbdImageOptionDataPool, rv.DataPool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to set data pool: %w", err)
|
return nil, fmt.Errorf("failed to set data pool: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 nil, fmt.Errorf("failed to set image features: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1569,11 +1573,11 @@ func (rv *rbdVolume) setImageOptions(ctx context.Context, options *librbd.ImageO
|
|||||||
logMsg += fmt.Sprintf(", stripe count %d, stripe unit %d", rv.StripeCount, rv.StripeUnit)
|
logMsg += fmt.Sprintf(", stripe count %d, stripe unit %d", rv.StripeCount, rv.StripeUnit)
|
||||||
err = options.SetUint64(librbd.RbdImageOptionStripeCount, rv.StripeCount)
|
err = options.SetUint64(librbd.RbdImageOptionStripeCount, rv.StripeCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to set stripe count: %w", err)
|
return nil, fmt.Errorf("failed to set stripe count: %w", err)
|
||||||
}
|
}
|
||||||
err = options.SetUint64(librbd.RbdImageOptionStripeUnit, rv.StripeUnit)
|
err = options.SetUint64(librbd.RbdImageOptionStripeUnit, rv.StripeUnit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to set stripe unit: %w", err)
|
return nil, fmt.Errorf("failed to set stripe unit: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1582,13 +1586,13 @@ func (rv *rbdVolume) setImageOptions(ctx context.Context, options *librbd.ImageO
|
|||||||
logMsg += fmt.Sprintf(", object size %d, order %d", rv.ObjectSize, order)
|
logMsg += fmt.Sprintf(", object size %d, order %d", rv.ObjectSize, order)
|
||||||
err = options.SetUint64(librbd.RbdImageOptionOrder, order)
|
err = options.SetUint64(librbd.RbdImageOptionOrder, order)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to set object size: %w", err)
|
return nil, fmt.Errorf("failed to set object size: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.DebugLog(ctx, logMsg)
|
log.DebugLog(ctx, logMsg)
|
||||||
|
|
||||||
return nil
|
return options, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCreationTime returns the creation time of the image. if the image
|
// GetCreationTime returns the creation time of the image. if the image
|
||||||
|
Loading…
Reference in New Issue
Block a user