Skip to content

Commit

Permalink
rbd: set/get correct ImageID in more places
Browse files Browse the repository at this point in the history
Signed-off-by: Niels de Vos <ndevos@ibm.com>
  • Loading branch information
nixpanic committed Nov 17, 2023
1 parent 8beeab2 commit 4db6763
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ type rbdImage struct {
NamePrefix string
// ParentName represents the parent image name of the image.
ParentName string
// ParentID represents the parent image ID of the image.
ParentID string
// Parent Pool is the pool that contains the parent image.
ParentPool string
// Cluster name
Expand Down Expand Up @@ -1614,6 +1616,11 @@ func (ri *rbdImage) getImageInfo() error {
// TODO: can rv.VolSize not be a uint64? Or initialize it to -1?
ri.VolSize = int64(imageInfo.Size)

ri.ImageID, err = image.GetId()
if err != nil {
return err
}

features, err := image.GetFeatures()
if err != nil {
return err
Expand All @@ -1627,11 +1634,13 @@ func (ri *rbdImage) getImageInfo() error {
// the parent is an error or not.
if errors.Is(err, librbd.ErrNotFound) {
ri.ParentName = ""
ri.ParentID = ""
} else {
return err
}
} else {
ri.ParentName = parentInfo.Image.ImageName
ri.ParentID = parentInfo.Image.ImageID
ri.ParentPool = parentInfo.Image.PoolName
}
// Get image creation time
Expand Down Expand Up @@ -1662,6 +1671,7 @@ func (ri *rbdImage) getParent() (*rbdImage, error) {
parentImage.Pool = ri.ParentPool
parentImage.RadosNamespace = ri.RadosNamespace
parentImage.RbdImageName = ri.ParentName
parentImage.ImageID = ri.ParentID

err = parentImage.getImageInfo()
if err != nil {
Expand Down Expand Up @@ -1718,6 +1728,7 @@ type rbdImageMetadataStash struct {
Pool string `json:"pool"`
RadosNamespace string `json:"radosNamespace"`
ImageName string `json:"image"`
ImageID string `json:"imageID"`
UnmapOptions string `json:"unmapOptions"`
NbdAccess bool `json:"accessType"`
Encrypted bool `json:"encrypted"`
Expand Down Expand Up @@ -1747,6 +1758,7 @@ func stashRBDImageMetadata(volOptions *rbdVolume, metaDataPath string) error {
Pool: volOptions.Pool,
RadosNamespace: volOptions.RadosNamespace,
ImageName: volOptions.RbdImageName,
ImageID: volOptions.ImageID,
Encrypted: volOptions.isBlockEncrypted(),
UnmapOptions: volOptions.UnmapOptions,
}
Expand Down

0 comments on commit 4db6763

Please sign in to comment.