Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbd: check parent image while mirroring of child #4513

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions internal/rbd/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,39 @@ func (ri *rbdImage) EnableImageMirroring(mode librbd.ImageMirrorMode) error {
}
defer image.Close()

parentInfo, err := image.GetParent()
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is no parent for the image this will fail with librbd.ErrNotFound error isn't it?

return fmt.Errorf("failed to get parent info of image %q: %w",
ri, err)
}

if parentInfo.Image.Trash {
return fmt.Errorf("failed to enable mirroring on image %q:"+
" parent %q is in trash",
parentInfo.Image.ImageID, ri)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning ImageID is not useful, if possible return parent name or just discard parent id or log ImageName

}

parent, err := ri.getParent()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add Trash to the rbdImage struct and make only one call getParent() (need to populate Trash value as well) which gives all the details. we don't need to call getParent multiple times.

if err != nil {
return fmt.Errorf("failed to enable mirroring on image %q:"+
" failed to get parent: %w", ri, err)
}

if parent != nil {
parentMirroringInfo, err := parent.GetImageMirroringInfo()
if err != nil {
return fmt.Errorf("failed to enable mirroring on image %q:"+
" failed to get mirroring info of parent %q: %w",
ri, parent, err)
}

if parentMirroringInfo.State != librbd.MirrorImageEnabled {
return fmt.Errorf("failed to enable mirroring on image %q:"+
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to return Invalid RPC code when parent in not mirror enabled or when the parent is in trash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/csi-addons/spec/tree/main/replication#enablevolumereplication

https://github.com/container-storage-interface/spec/blob/master/spec.md#createvolume-errors

So I'll modify csi addons spec EnableVolReplication call errors' INVALID_ARGUEMENT description to include something similar to createvolume_errors indicating we cannot enable replication on certain volumes.

"parent image %q is not enabled for mirroring",
ri, parent)
}
}

err = image.MirrorEnable(mode)
if err != nil {
return fmt.Errorf("failed to enable mirroring on %q with error: %w", ri, err)
Expand Down
Loading