mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 00:10:20 +00:00
cephfs: introduce newSnapshotOptionsFromID to generate volOpt and sid
From provided CSI volume ID this populate volumeOptions and snapshot identifier after connecting to the snapJournal. Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
parent
a4f2c5617c
commit
5a71949dcd
@ -298,12 +298,10 @@ func newVolumeOptionsFromVolID(ctx context.Context, volID string, volOpt, secret
|
||||
}
|
||||
|
||||
volOptions.ProvisionVolume = true
|
||||
|
||||
volOptions.RootPath, err = getVolumeRootPathCeph(ctx, &volOptions, cr, volumeID(vid.FsSubvolName))
|
||||
if err != nil {
|
||||
return &volOptions, &vid, err
|
||||
}
|
||||
|
||||
return &volOptions, &vid, nil
|
||||
}
|
||||
|
||||
@ -414,3 +412,62 @@ func newVolumeOptionsFromStaticVolume(volID string, options map[string]string) (
|
||||
|
||||
return &opts, &vid, nil
|
||||
}
|
||||
|
||||
// newSnapshotOptionsFromID generates a new instance of volumeOptions and snapshotIdentifier
|
||||
// from the provided CSI VolumeID.
|
||||
func newSnapshotOptionsFromID(ctx context.Context, snapID string, cr *util.Credentials) (*volumeOptions, *snapshotInfo, *snapshotIdentifier, error) {
|
||||
var (
|
||||
vi util.CSIIdentifier
|
||||
volOptions volumeOptions
|
||||
sid snapshotIdentifier
|
||||
)
|
||||
// Decode the snapID first, to detect pre-provisioned snapshot before other errors
|
||||
err := vi.DecomposeCSIID(snapID)
|
||||
if err != nil {
|
||||
return &volOptions, nil, &sid, ErrInvalidVolID
|
||||
}
|
||||
volOptions.ClusterID = vi.ClusterID
|
||||
sid.SnapshotID = snapID
|
||||
volOptions.FscID = vi.LocationID
|
||||
|
||||
if volOptions.Monitors, err = util.Mons(csiConfigFile, vi.ClusterID); err != nil {
|
||||
return &volOptions, nil, &sid, fmt.Errorf("failed to fetch monitor list using clusterID (%s): %w", vi.ClusterID, err)
|
||||
}
|
||||
|
||||
if volOptions.SubvolumeGroup, err = util.CephFSSubvolumeGroup(csiConfigFile, vi.ClusterID); err != nil {
|
||||
return &volOptions, nil, &sid, fmt.Errorf("failed to fetch subvolumegroup list using clusterID (%s): %w", vi.ClusterID, err)
|
||||
}
|
||||
|
||||
volOptions.FsName, err = getFsName(ctx, volOptions.Monitors, cr, volOptions.FscID)
|
||||
if err != nil {
|
||||
return &volOptions, nil, &sid, err
|
||||
}
|
||||
|
||||
volOptions.MetadataPool, err = getMetadataPool(ctx, volOptions.Monitors, cr, volOptions.FsName)
|
||||
if err != nil {
|
||||
return &volOptions, nil, &sid, err
|
||||
}
|
||||
|
||||
j, err := snapJournal.Connect(volOptions.Monitors, cr)
|
||||
if err != nil {
|
||||
return &volOptions, nil, &sid, err
|
||||
}
|
||||
defer j.Destroy()
|
||||
|
||||
imageAttributes, err := j.GetImageAttributes(
|
||||
ctx, volOptions.MetadataPool, vi.ObjectUUID, true)
|
||||
if err != nil {
|
||||
return &volOptions, nil, &sid, err
|
||||
}
|
||||
// storing request name in snapshotshot Identifier
|
||||
sid.RequestName = imageAttributes.RequestName
|
||||
sid.FsSnapshotName = imageAttributes.ImageName
|
||||
sid.FsSubvolName = imageAttributes.SourceName
|
||||
|
||||
info, err := getSnapshotInfo(ctx, &volOptions, cr, volumeID(sid.FsSnapshotName), volumeID(sid.FsSubvolName))
|
||||
if err != nil {
|
||||
return &volOptions, nil, &sid, err
|
||||
}
|
||||
|
||||
return &volOptions, &info, &sid, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user