Skip to content

Commit

Permalink
Revert "rbd: use go-ceph to implement getImageInfo()"
Browse files Browse the repository at this point in the history
This reverts commit 9f135b0dbabc2a75ec01d7fdbb31d457c34e2a08.
  • Loading branch information
nixpanic committed Feb 14, 2020
1 parent a05784a commit ca44f22
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions pkg/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,14 @@ func updateSnapWithImageInfo(ctx context.Context, rbdSnap *rbdSnapshot, cr *util
// updateVolWithImageInfo updates provided rbdVolume with information from on-disk data
// regarding the same
func updateVolWithImageInfo(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error {
err := rbdVol.Connect(cr)
if err != nil {
return errors.Wrapf(err, "failed to connect to Ceph cluster")
}

err = rbdVol.getImageInfo()
imageInfo, err := getImageInfo(ctx, rbdVol.Monitors, cr, rbdVol.Pool, rbdVol.RbdImageName)
if err != nil {
return err
}

rbdVol.VolSize = imageInfo.Size
rbdVol.ImageFeatures = strings.Join(imageInfo.Features, ",")

return nil
}

Expand Down Expand Up @@ -769,35 +767,47 @@ func getSnapshotMetadata(ctx context.Context, pSnapOpts *rbdSnapshot, cr *util.C
return nil
}

// imageInfo strongly typed JSON spec for image info
type imageInfo struct {
ObjectUUID string `json:"name"`
Size int64 `json:"size"`
Features []string `json:"features"`
CreatedAt string `json:"create_timestamp"`
}

// getImageInfo queries rbd about the given image and returns its metadata, and returns
// ErrImageNotFound if provided image is not found
func (rv *rbdVolume) getImageInfo() error {
func getImageInfo(ctx context.Context, monitors string, cr *util.Credentials, poolName, imageName string) (imageInfo, error) {
// rbd --format=json info [image-spec | snap-spec]
image, err := rv.open()
if err != nil {
return errors.Wrapf(err, "failed to open image")
}
defer image.Close()

imageInfo, err := image.Stat()
if err != nil {
return errors.Wrapf(err, "failed to get stat of image")
}
// TODO: can rv.VolSize not be a uint64? Or initialize it to -1?
rv.VolSize = int64(imageInfo.Size)
var imgInfo imageInfo

features, err := image.GetFeaturesNamed()
stdout, stderr, err := util.ExecCommand(
"rbd",
"-m", monitors,
"--id", cr.ID,
"--keyfile="+cr.KeyFile,
"-c", util.CephConfigPath,
"--format="+"json",
"info", poolName+"/"+imageName)
if err != nil {
return errors.Wrapf(err, "failed to get features of image")
klog.Errorf(util.Log(ctx, "failed getting information for image (%s): (%s)"), poolName+"/"+imageName, err)
if strings.Contains(string(stderr), "rbd: error opening image "+imageName+
": (2) No such file or directory") {
return imgInfo, ErrImageNotFound{imageName, err}
}
return imgInfo, err
}

featueNames := make([]string, 0)
for _, f := range(features) {
featueNames = append(featueNames, f.GetName())
err = json.Unmarshal(stdout, &imgInfo)
if err != nil {
klog.Errorf(util.Log(ctx, "failed to parse JSON output of image info (%s): (%s)"),
poolName+"/"+imageName, err)
return imgInfo, fmt.Errorf("unmarshal failed: %+v. raw buffer response: %s",
err, string(stdout))
}
rv.ImageFeatures = strings.Join(featueNames, ",")

return nil
return imgInfo, nil
}

// snapInfo strongly typed JSON spec for snap ls rbd output
Expand Down

0 comments on commit ca44f22

Please sign in to comment.