mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 00:10:20 +00:00
fix nit
This commit is contained in:
parent
f0fba1240a
commit
7d90783f03
@ -108,7 +108,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
|
|||||||
}
|
}
|
||||||
|
|
||||||
snapshotID := snapshot.GetId()
|
snapshotID := snapshot.GetId()
|
||||||
if snapshotID == "" {
|
if len(snapshotID) == 0 {
|
||||||
return nil, status.Error(codes.InvalidArgument, "Volume Snapshot ID cannot be empty")
|
return nil, status.Error(codes.InvalidArgument, "Volume Snapshot ID cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
|
|||||||
if err := persistVolInfo(volumeID, path.Join(PluginFolder, "controller"), rbdVol); err != nil {
|
if err := persistVolInfo(volumeID, path.Join(PluginFolder, "controller"), rbdVol); err != nil {
|
||||||
glog.Warningf("rbd: failed to store volInfo with error: %v", err)
|
glog.Warningf("rbd: failed to store volInfo with error: %v", err)
|
||||||
}
|
}
|
||||||
rbdVolumes[volumeID] = *rbdVol
|
rbdVolumes[volumeID] = rbdVol
|
||||||
return &csi.CreateVolumeResponse{
|
return &csi.CreateVolumeResponse{
|
||||||
Volume: &csi.Volume{
|
Volume: &csi.Volume{
|
||||||
Id: volumeID,
|
Id: volumeID,
|
||||||
@ -238,7 +238,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
|
|||||||
}
|
}
|
||||||
rbdSnap.VolName = rbdVolume.VolName
|
rbdSnap.VolName = rbdVolume.VolName
|
||||||
rbdSnap.SnapName = snapName
|
rbdSnap.SnapName = snapName
|
||||||
snapshotID := "csi-rbd-snapshot-" + uniqueID
|
snapshotID := "csi-rbd-" + rbdVolume.VolName + "-snap-" + uniqueID
|
||||||
rbdSnap.SnapID = snapshotID
|
rbdSnap.SnapID = snapshotID
|
||||||
rbdSnap.SourceVolumeID = req.GetSourceVolumeId()
|
rbdSnap.SourceVolumeID = req.GetSourceVolumeId()
|
||||||
rbdSnap.SizeBytes = rbdVolume.VolSize
|
rbdSnap.SizeBytes = rbdVolume.VolSize
|
||||||
@ -280,9 +280,10 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
|
|||||||
// Storing snapInfo into a persistent file.
|
// Storing snapInfo into a persistent file.
|
||||||
if err := persistSnapInfo(snapshotID, path.Join(PluginFolder, "controller-snap"), rbdSnap); err != nil {
|
if err := persistSnapInfo(snapshotID, path.Join(PluginFolder, "controller-snap"), rbdSnap); err != nil {
|
||||||
glog.Warningf("rbd: failed to store sanpInfo with error: %v", err)
|
glog.Warningf("rbd: failed to store sanpInfo with error: %v", err)
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rbdSnapshots[snapshotID] = *rbdSnap
|
rbdSnapshots[snapshotID] = rbdSnap
|
||||||
return &csi.CreateSnapshotResponse{
|
return &csi.CreateSnapshotResponse{
|
||||||
Snapshot: &csi.Snapshot{
|
Snapshot: &csi.Snapshot{
|
||||||
SizeBytes: rbdSnap.SizeBytes,
|
SizeBytes: rbdSnap.SizeBytes,
|
||||||
@ -303,7 +304,7 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
|
|||||||
}
|
}
|
||||||
|
|
||||||
snapshotID := req.GetSnapshotId()
|
snapshotID := req.GetSnapshotId()
|
||||||
if snapshotID == "" {
|
if len(snapshotID) == 0 {
|
||||||
return nil, status.Error(codes.InvalidArgument, "Snapshot ID cannot be empty")
|
return nil, status.Error(codes.InvalidArgument, "Snapshot ID cannot be empty")
|
||||||
}
|
}
|
||||||
rbdSnap := &rbdSnapshot{}
|
rbdSnap := &rbdSnapshot{}
|
||||||
@ -344,10 +345,10 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
|
|||||||
// TODO (sngchlko) list with token
|
// TODO (sngchlko) list with token
|
||||||
|
|
||||||
// list only a specific snapshot which has snapshot ID
|
// list only a specific snapshot which has snapshot ID
|
||||||
if snapshotID := req.GetSnapshotId(); snapshotID != "" {
|
if snapshotID := req.GetSnapshotId(); len(snapshotID) != 0 {
|
||||||
if rbdSnap, ok := rbdSnapshots[snapshotID]; ok {
|
if rbdSnap, ok := rbdSnapshots[snapshotID]; ok {
|
||||||
// if source volume ID also set, check source volume id on the cache.
|
// if source volume ID also set, check source volume id on the cache.
|
||||||
if sourceVolumeId != "" && rbdSnap.SourceVolumeID != sourceVolumeId {
|
if len(sourceVolumeId) != 0 && rbdSnap.SourceVolumeID != sourceVolumeId {
|
||||||
return nil, status.Error(codes.Unknown, fmt.Sprintf("Requested Source Volume ID %s is different from %s", sourceVolumeId, rbdSnap.SourceVolumeID))
|
return nil, status.Error(codes.Unknown, fmt.Sprintf("Requested Source Volume ID %s is different from %s", sourceVolumeId, rbdSnap.SourceVolumeID))
|
||||||
}
|
}
|
||||||
return &csi.ListSnapshotsResponse{
|
return &csi.ListSnapshotsResponse{
|
||||||
@ -373,7 +374,7 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
|
|||||||
entries := []*csi.ListSnapshotsResponse_Entry{}
|
entries := []*csi.ListSnapshotsResponse_Entry{}
|
||||||
for _, rbdSnap := range rbdSnapshots {
|
for _, rbdSnap := range rbdSnapshots {
|
||||||
// if source volume ID also set, check source volume id on the cache.
|
// if source volume ID also set, check source volume id on the cache.
|
||||||
if sourceVolumeId != "" && rbdSnap.SourceVolumeID != sourceVolumeId {
|
if len(sourceVolumeId) != 0 && rbdSnap.SourceVolumeID != sourceVolumeId {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
entries = append(entries, &csi.ListSnapshotsResponse_Entry{
|
entries = append(entries, &csi.ListSnapshotsResponse_Entry{
|
||||||
|
@ -54,14 +54,14 @@ var (
|
|||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rbdVolumes map[string]rbdVolume
|
var rbdVolumes map[string]*rbdVolume
|
||||||
var rbdSnapshots map[string]rbdSnapshot
|
var rbdSnapshots map[string]*rbdSnapshot
|
||||||
|
|
||||||
// Init checks for the persistent volume file and loads all found volumes
|
// Init checks for the persistent volume file and loads all found volumes
|
||||||
// into a memory structure
|
// into a memory structure
|
||||||
func init() {
|
func init() {
|
||||||
rbdVolumes = map[string]rbdVolume{}
|
rbdVolumes = map[string]*rbdVolume{}
|
||||||
rbdSnapshots = map[string]rbdSnapshot{}
|
rbdSnapshots = map[string]*rbdSnapshot{}
|
||||||
if _, err := os.Stat(path.Join(PluginFolder, "controller")); os.IsNotExist(err) {
|
if _, err := os.Stat(path.Join(PluginFolder, "controller")); os.IsNotExist(err) {
|
||||||
glog.Infof("rbd: folder %s not found. Creating... \n", path.Join(PluginFolder, "controller"))
|
glog.Infof("rbd: folder %s not found. Creating... \n", path.Join(PluginFolder, "controller"))
|
||||||
if err := os.Mkdir(path.Join(PluginFolder, "controller"), 0755); err != nil {
|
if err := os.Mkdir(path.Join(PluginFolder, "controller"), 0755); err != nil {
|
||||||
@ -108,7 +108,7 @@ func loadExSnapshots() {
|
|||||||
fp.Close()
|
fp.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rbdSnapshots[rbdSnap.SnapID] = rbdSnap
|
rbdSnapshots[rbdSnap.SnapID] = &rbdSnap
|
||||||
}
|
}
|
||||||
glog.Infof("rbd: Loaded %d snapshots from %s", len(rbdSnapshots), path.Join(PluginFolder, "controller-snap"))
|
glog.Infof("rbd: Loaded %d snapshots from %s", len(rbdSnapshots), path.Join(PluginFolder, "controller-snap"))
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ func loadExVolumes() {
|
|||||||
fp.Close()
|
fp.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rbdVolumes[rbdVol.VolID] = rbdVol
|
rbdVolumes[rbdVol.VolID] = &rbdVol
|
||||||
}
|
}
|
||||||
glog.Infof("rbd: Loaded %d volumes from %s", len(rbdVolumes), path.Join(PluginFolder, "controller"))
|
glog.Infof("rbd: Loaded %d volumes from %s", len(rbdVolumes), path.Join(PluginFolder, "controller"))
|
||||||
}
|
}
|
||||||
|
@ -446,29 +446,29 @@ func deleteSnapInfo(snapshot string, persistentStoragePath string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRBDVolumeByID(volumeID string) (rbdVolume, error) {
|
func getRBDVolumeByID(volumeID string) (*rbdVolume, error) {
|
||||||
if rbdVol, ok := rbdVolumes[volumeID]; ok {
|
if rbdVol, ok := rbdVolumes[volumeID]; ok {
|
||||||
return rbdVol, nil
|
return rbdVol, nil
|
||||||
}
|
}
|
||||||
return rbdVolume{}, fmt.Errorf("volume id %s does not exit in the volumes list", volumeID)
|
return nil, fmt.Errorf("volume id %s does not exit in the volumes list", volumeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRBDVolumeByName(volName string) (rbdVolume, error) {
|
func getRBDVolumeByName(volName string) (*rbdVolume, error) {
|
||||||
for _, rbdVol := range rbdVolumes {
|
for _, rbdVol := range rbdVolumes {
|
||||||
if rbdVol.VolName == volName {
|
if rbdVol.VolName == volName {
|
||||||
return rbdVol, nil
|
return rbdVol, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rbdVolume{}, fmt.Errorf("volume name %s does not exit in the volumes list", volName)
|
return nil, fmt.Errorf("volume name %s does not exit in the volumes list", volName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRBDSnapshotByName(snapName string) (rbdSnapshot, error) {
|
func getRBDSnapshotByName(snapName string) (*rbdSnapshot, error) {
|
||||||
for _, rbdSnap := range rbdSnapshots {
|
for _, rbdSnap := range rbdSnapshots {
|
||||||
if rbdSnap.SnapName == snapName {
|
if rbdSnap.SnapName == snapName {
|
||||||
return rbdSnap, nil
|
return rbdSnap, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rbdSnapshot{}, fmt.Errorf("snapshot name %s does not exit in the snapshots list", snapName)
|
return nil, fmt.Errorf("snapshot name %s does not exit in the snapshots list", snapName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func protectSnapshot(pOpts *rbdSnapshot, credentials map[string]string) error {
|
func protectSnapshot(pOpts *rbdSnapshot, credentials map[string]string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user