Skip to content

Commit 13f0a28

Browse files
committed
rbd: fetch the SourceVolumeId (parent) of a snapshot
Signed-off-by: Niels de Vos <[email protected]>
1 parent a7682ce commit 13f0a28

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

internal/rbd/rbd_util.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,32 @@ func updateSnapshotDetails(ctx context.Context, rbdSnap *rbdSnapshot) error {
11401140
}
11411141
rbdSnap.VolSize = vol.VolSize
11421142

1143+
// get the parent to set rbdSnap.SourceVolumeID
1144+
parent, err := rbdSnap.getParent()
1145+
if err != nil && !errors.Is(err, rbderrors.ErrImageNotFound) {
1146+
return fmt.Errorf("failed to get parent of snapshot %q: %w", rbdSnap, err)
1147+
} else if parent == nil {
1148+
// no need to set rbdSnap.SourceVolumeID
1149+
return nil
1150+
}
1151+
1152+
poolID, err := util.GetPoolID(parent.Monitors, rbdSnap.conn.Creds, parent.Pool)
1153+
if err != nil {
1154+
return fmt.Errorf("failed to get the pool if for parent %q of snapshot %q: %w", parent, rbdSnap, err)
1155+
}
1156+
1157+
rbdSnap.SourceVolumeID, err = util.GenerateVolID(
1158+
ctx,
1159+
parent.Monitors,
1160+
rbdSnap.conn.Creds,
1161+
poolID,
1162+
parent.Pool,
1163+
parent.ClusterID,
1164+
parent.ReservedID)
1165+
if err != nil {
1166+
return fmt.Errorf("failed to generate source volume-id: %w", err)
1167+
}
1168+
11431169
return nil
11441170
}
11451171

0 commit comments

Comments
 (0)