rbd: drop references to ImageFormat

librbd only supports ImageFormat 2. It is not expected that anyone has a
different version of the format in container environments.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-01-10 10:09:49 +01:00 committed by mergify[bot]
parent 8dc3600899
commit 40d0d5d291

View File

@ -42,7 +42,6 @@ import (
const ( const (
imageWatcherStr = "watcher=" imageWatcherStr = "watcher="
rbdImageFormat2 = 2
// The following three values are used for 30 seconds timeout // The following three values are used for 30 seconds timeout
// while waiting for RBD Watcher to expire. // while waiting for RBD Watcher to expire.
rbdImageWatcherInitDelay = 1 * time.Second rbdImageWatcherInitDelay = 1 * time.Second
@ -77,7 +76,6 @@ type rbdVolume struct {
Monitors string `json:"monitors"` Monitors string `json:"monitors"`
Pool string `json:"pool"` Pool string `json:"pool"`
DataPool string DataPool string
ImageFormat string `json:"imageFormat"`
ImageFeatures string `json:"imageFeatures"` ImageFeatures string `json:"imageFeatures"`
AdminID string `json:"adminId"` AdminID string `json:"adminId"`
UserID string `json:"userId"` UserID string `json:"userId"`
@ -131,30 +129,16 @@ func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er
volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(pOpts.VolSize)) volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(pOpts.VolSize))
options := librbd.NewRbdImageOptions() options := librbd.NewRbdImageOptions()
var err error logMsg := "rbd: create %s size %s (features: %s) using mon %s, pool %s "
imageFormat := rbdImageFormat2
if pOpts.ImageFormat != "" {
imageFormat, err = strconv.Atoi(pOpts.ImageFormat)
if err != nil {
return errors.Wrapf(err, "failed to convert ImageFormat (%v) to integer", pOpts.ImageFormat)
}
}
err = options.SetUint64(librbd.RbdImageOptionFormat, uint64(imageFormat))
if err != nil {
return errors.Wrapf(err, "failed to set ImageFormat to %v", imageFormat)
}
logMsg := "rbd: create %s size %s format %d (features: %s) using mon %s, pool %s "
if pOpts.DataPool != "" { if pOpts.DataPool != "" {
logMsg += fmt.Sprintf("data pool %s", pOpts.DataPool) logMsg += fmt.Sprintf("data pool %s", pOpts.DataPool)
err = options.SetString(librbd.RbdImageOptionDataPool, pOpts.DataPool) err := options.SetString(librbd.RbdImageOptionDataPool, pOpts.DataPool)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to set data pool") return errors.Wrapf(err, "failed to set data pool")
} }
} }
klog.V(4).Infof(util.Log(ctx, logMsg), klog.V(4).Infof(util.Log(ctx, logMsg),
pOpts.RbdImageName, volSzMiB, imageFormat, pOpts.ImageFeatures, pOpts.Monitors, pOpts.Pool) pOpts.RbdImageName, volSzMiB, pOpts.ImageFeatures, pOpts.Monitors, pOpts.Pool)
if pOpts.ImageFeatures != "" { if pOpts.ImageFeatures != "" {
features := imageFeaturesToUint64(ctx, pOpts.ImageFeatures) features := imageFeaturesToUint64(ctx, pOpts.ImageFeatures)
@ -328,12 +312,6 @@ func updateVolWithImageInfo(ctx context.Context, rbdVol *rbdVolume, cr *util.Cre
return err return err
} }
if imageInfo.Format != 2 {
return fmt.Errorf("unknown or unsupported image format (%d) returned for image (%s)",
imageInfo.Format, rbdVol.RbdImageName)
}
rbdVol.ImageFormat = strconv.Itoa(rbdImageFormat2)
rbdVol.VolSize = imageInfo.Size rbdVol.VolSize = imageInfo.Size
rbdVol.ImageFeatures = strings.Join(imageInfo.Features, ",") rbdVol.ImageFeatures = strings.Join(imageInfo.Features, ",")
@ -546,7 +524,7 @@ func genVolFromVolumeOptions(ctx context.Context, volOptions, credentials map[st
} }
// if no image features is provided, it results in empty string // if no image features is provided, it results in empty string
// which disable all RBD image format 2 features as we expected // which disable all RBD image features as we expected
imageFeatures, found := volOptions["imageFeatures"] imageFeatures, found := volOptions["imageFeatures"]
if found { if found {
@ -765,7 +743,6 @@ func getSnapshotMetadata(ctx context.Context, pSnapOpts *rbdSnapshot, cr *util.C
type imageInfo struct { type imageInfo struct {
ObjectUUID string `json:"name"` ObjectUUID string `json:"name"`
Size int64 `json:"size"` Size int64 `json:"size"`
Format int64 `json:"format"`
Features []string `json:"features"` Features []string `json:"features"`
CreatedAt string `json:"create_timestamp"` CreatedAt string `json:"create_timestamp"`
} }