mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 11:00:25 +00:00
rbd: use go-ceph to implement getImageInfo()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
772d1dfa77
commit
824f38daaa
@ -380,15 +380,7 @@ func updateSnapWithImageInfo(ctx context.Context, rbdSnap *rbdSnapshot, cr *util
|
|||||||
// updateVolWithImageInfo updates provided rbdVolume with information from on-disk data
|
// updateVolWithImageInfo updates provided rbdVolume with information from on-disk data
|
||||||
// regarding the same
|
// regarding the same
|
||||||
func updateVolWithImageInfo(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error {
|
func updateVolWithImageInfo(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error {
|
||||||
imageInfo, err := rbdVol.getImageInfo(ctx, rbdVol.Monitors, cr)
|
return rbdVol.getImageInfo()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
rbdVol.VolSize = imageInfo.Size
|
|
||||||
rbdVol.ImageFeatures = strings.Join(imageInfo.Features, ",")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// genSnapFromSnapID generates a rbdSnapshot structure from the provided identifier, updating
|
// genSnapFromSnapID generates a rbdSnapshot structure from the provided identifier, updating
|
||||||
@ -835,45 +827,30 @@ func getSnapshotMetadata(ctx context.Context, pSnapOpts *rbdSnapshot, cr *util.C
|
|||||||
return nil
|
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
|
// getImageInfo queries rbd about the given image and returns its metadata, and returns
|
||||||
// ErrImageNotFound if provided image is not found
|
// ErrImageNotFound if provided image is not found
|
||||||
func (rv *rbdVolume) getImageInfo(ctx context.Context, monitors string, cr *util.Credentials) (imageInfo, error) {
|
func (rv *rbdVolume) getImageInfo() error {
|
||||||
// rbd --format=json info [image-spec | snap-spec]
|
image, err := rv.open()
|
||||||
|
|
||||||
var imgInfo imageInfo
|
|
||||||
|
|
||||||
stdout, stderr, err := util.ExecCommand(
|
|
||||||
"rbd",
|
|
||||||
"-m", monitors,
|
|
||||||
"--id", cr.ID,
|
|
||||||
"--keyfile="+cr.KeyFile,
|
|
||||||
"-c", util.CephConfigPath,
|
|
||||||
"--format="+"json",
|
|
||||||
"info", rv.String())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed getting information for image (%s): (%s)"), rv, err)
|
return err
|
||||||
if strings.Contains(string(stderr), "rbd: error opening image "+rv.RbdImageName+
|
|
||||||
": (2) No such file or directory") {
|
|
||||||
return imgInfo, ErrImageNotFound{rv.String(), err}
|
|
||||||
}
|
|
||||||
return imgInfo, err
|
|
||||||
}
|
}
|
||||||
|
defer image.Close()
|
||||||
|
|
||||||
err = json.Unmarshal(stdout, &imgInfo)
|
imageInfo, err := image.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed to parse JSON output of image info (%s): (%s)"), rv, err)
|
return err
|
||||||
return imgInfo, fmt.Errorf("unmarshal failed: %+v. raw buffer response: %s", err, string(stdout))
|
|
||||||
}
|
}
|
||||||
|
// TODO: can rv.VolSize not be a uint64? Or initialize it to -1?
|
||||||
|
rv.VolSize = int64(imageInfo.Size)
|
||||||
|
|
||||||
return imgInfo, nil
|
features, err := image.GetFeatures()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fs := librbd.FeatureSet(features)
|
||||||
|
rv.ImageFeatures = strings.Join(fs.Names(), ",")
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// snapInfo strongly typed JSON spec for snap ls rbd output
|
// snapInfo strongly typed JSON spec for snap ls rbd output
|
||||||
|
Loading…
Reference in New Issue
Block a user