mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-03 03:30:19 +00:00
rbd: set/get correct ImageID in more places
In some places the ImageID is used as the ID of the parent. That is very confusing and prone to errors. Instead, fetch the right ImageID where possible, and set ParentID for referencing to parent images. Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
parent
58573a1d14
commit
b872914a6e
@ -1173,6 +1173,7 @@ func (cs *ControllerServer) CreateSnapshot(
|
|||||||
|
|
||||||
// Update the metadata on snapshot not on the original image
|
// Update the metadata on snapshot not on the original image
|
||||||
rbdVol.RbdImageName = rbdSnap.RbdSnapName
|
rbdVol.RbdImageName = rbdSnap.RbdSnapName
|
||||||
|
rbdVol.ImageID = vol.ImageID
|
||||||
rbdVol.ClusterName = cs.ClusterName
|
rbdVol.ClusterName = cs.ClusterName
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -114,6 +114,8 @@ type rbdImage struct {
|
|||||||
NamePrefix string
|
NamePrefix string
|
||||||
// ParentName represents the parent image name of the image.
|
// ParentName represents the parent image name of the image.
|
||||||
ParentName string
|
ParentName string
|
||||||
|
// ParentID represents the parent image ID of the image.
|
||||||
|
ParentID string
|
||||||
// Parent Pool is the pool that contains the parent image.
|
// Parent Pool is the pool that contains the parent image.
|
||||||
ParentPool string
|
ParentPool string
|
||||||
// Cluster name
|
// Cluster name
|
||||||
@ -711,6 +713,7 @@ func (ri *rbdImage) getCloneDepth(ctx context.Context) (uint, error) {
|
|||||||
vol.Pool = ri.Pool
|
vol.Pool = ri.Pool
|
||||||
vol.Monitors = ri.Monitors
|
vol.Monitors = ri.Monitors
|
||||||
vol.RbdImageName = ri.RbdImageName
|
vol.RbdImageName = ri.RbdImageName
|
||||||
|
vol.ImageID = ri.ImageID
|
||||||
vol.RadosNamespace = ri.RadosNamespace
|
vol.RadosNamespace = ri.RadosNamespace
|
||||||
vol.conn = ri.conn.Copy()
|
vol.conn = ri.conn.Copy()
|
||||||
|
|
||||||
@ -743,6 +746,7 @@ func (ri *rbdImage) getCloneDepth(ctx context.Context) (uint, error) {
|
|||||||
depth++
|
depth++
|
||||||
}
|
}
|
||||||
vol.RbdImageName = vol.ParentName
|
vol.RbdImageName = vol.ParentName
|
||||||
|
vol.ImageID = vol.ParentID
|
||||||
vol.Pool = vol.ParentPool
|
vol.Pool = vol.ParentPool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -882,6 +886,9 @@ func (ri *rbdImage) getParentName() (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ri.ParentName = parentInfo.Image.ImageName
|
||||||
|
ri.ParentID = parentInfo.Image.ImageID
|
||||||
|
|
||||||
return parentInfo.Image.ImageName, nil
|
return parentInfo.Image.ImageName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1595,6 +1602,11 @@ func (ri *rbdImage) getImageInfo() error {
|
|||||||
// TODO: can rv.VolSize not be a uint64? Or initialize it to -1?
|
// TODO: can rv.VolSize not be a uint64? Or initialize it to -1?
|
||||||
ri.VolSize = int64(imageInfo.Size)
|
ri.VolSize = int64(imageInfo.Size)
|
||||||
|
|
||||||
|
ri.ImageID, err = image.GetId()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
features, err := image.GetFeatures()
|
features, err := image.GetFeatures()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1608,11 +1620,13 @@ func (ri *rbdImage) getImageInfo() error {
|
|||||||
// the parent is an error or not.
|
// the parent is an error or not.
|
||||||
if errors.Is(err, librbd.ErrNotFound) {
|
if errors.Is(err, librbd.ErrNotFound) {
|
||||||
ri.ParentName = ""
|
ri.ParentName = ""
|
||||||
|
ri.ParentID = ""
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ri.ParentName = parentInfo.Image.ImageName
|
ri.ParentName = parentInfo.Image.ImageName
|
||||||
|
ri.ParentID = parentInfo.Image.ImageID
|
||||||
ri.ParentPool = parentInfo.Image.PoolName
|
ri.ParentPool = parentInfo.Image.PoolName
|
||||||
}
|
}
|
||||||
// Get image creation time
|
// Get image creation time
|
||||||
@ -1643,6 +1657,7 @@ func (ri *rbdImage) getParent() (*rbdImage, error) {
|
|||||||
parentImage.Pool = ri.ParentPool
|
parentImage.Pool = ri.ParentPool
|
||||||
parentImage.RadosNamespace = ri.RadosNamespace
|
parentImage.RadosNamespace = ri.RadosNamespace
|
||||||
parentImage.RbdImageName = ri.ParentName
|
parentImage.RbdImageName = ri.ParentName
|
||||||
|
parentImage.ImageID = ri.ParentID
|
||||||
|
|
||||||
err = parentImage.getImageInfo()
|
err = parentImage.getImageInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1699,6 +1714,7 @@ type rbdImageMetadataStash struct {
|
|||||||
Pool string `json:"pool"`
|
Pool string `json:"pool"`
|
||||||
RadosNamespace string `json:"radosNamespace"`
|
RadosNamespace string `json:"radosNamespace"`
|
||||||
ImageName string `json:"image"`
|
ImageName string `json:"image"`
|
||||||
|
ImageID string `json:"imageID"`
|
||||||
UnmapOptions string `json:"unmapOptions"`
|
UnmapOptions string `json:"unmapOptions"`
|
||||||
NbdAccess bool `json:"accessType"`
|
NbdAccess bool `json:"accessType"`
|
||||||
Encrypted bool `json:"encrypted"`
|
Encrypted bool `json:"encrypted"`
|
||||||
@ -1728,6 +1744,7 @@ func stashRBDImageMetadata(volOptions *rbdVolume, metaDataPath string) error {
|
|||||||
Pool: volOptions.Pool,
|
Pool: volOptions.Pool,
|
||||||
RadosNamespace: volOptions.RadosNamespace,
|
RadosNamespace: volOptions.RadosNamespace,
|
||||||
ImageName: volOptions.RbdImageName,
|
ImageName: volOptions.RbdImageName,
|
||||||
|
ImageID: volOptions.ImageID,
|
||||||
Encrypted: volOptions.isBlockEncrypted(),
|
Encrypted: volOptions.isBlockEncrypted(),
|
||||||
UnmapOptions: volOptions.UnmapOptions,
|
UnmapOptions: volOptions.UnmapOptions,
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,8 @@ func generateVolFromSnap(rbdSnap *rbdSnapshot) *rbdVolume {
|
|||||||
vol.JournalPool = rbdSnap.JournalPool
|
vol.JournalPool = rbdSnap.JournalPool
|
||||||
vol.RadosNamespace = rbdSnap.RadosNamespace
|
vol.RadosNamespace = rbdSnap.RadosNamespace
|
||||||
vol.RbdImageName = rbdSnap.RbdSnapName
|
vol.RbdImageName = rbdSnap.RbdSnapName
|
||||||
|
vol.ParentName = rbdSnap.ParentName
|
||||||
|
vol.ParentID = rbdSnap.ParentID
|
||||||
|
|
||||||
// /!\ WARNING /!\
|
// /!\ WARNING /!\
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user