rbd: fix snapshot deletion by resolving image names correctly

When creating a Snapshot with the new NewSnapshotByID() function, the
name of the RBD-image that is created is the same as the name of the
Snapshot. The `RbdImageName` points to the name of parent image, which
causes deleting the Snapshot to delete the parent image instead.

Correcting the `RbdImageName` and setting it to the `RbdSnapName` makes
sure that upon deletion, the Snapshot RBD-image is removed, and not the
parent image.

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos 2024-10-01 19:06:50 +02:00 committed by mergify[bot]
parent fdccba1f33
commit e011e74b9d
2 changed files with 11 additions and 1 deletions

View File

@ -212,6 +212,11 @@ func (mgr *rbdManager) GetSnapshotByID(ctx context.Context, id string) (types.Sn
} }
} }
// FIXME: The snapshot will have RbdImageName set to the image that was
// used as source. This is not correct for group snapshots images, and
// need to be fixed. See rbdVolume.NewSnapshotByID() for more details.
snapshot.RbdImageName = snapshot.RbdSnapName
return snapshot, nil return snapshot, nil
} }

View File

@ -221,7 +221,12 @@ func (rv *rbdVolume) NewSnapshotByID(
} }
}() }()
// a new snapshot image will be created, needs to have a unique name // A new snapshot image will be created, and needs to have a unique
// name.
// FIXME: the journal contains rv.RbdImageName as SourceName. When
// resolving the snapshot image, snap.RbdImageName will be set to the
// original RbdImageName/SourceName (incorrect). This is fixed-up in
// rbdManager.GetSnapshotByID(), this needs to be done cleaner.
snap.RbdImageName = snap.RbdSnapName snap.RbdImageName = snap.RbdSnapName
err = rv.Connect(cr) err = rv.Connect(cr)