diff options
| author | Viktor Kuzmin <kvaster@gmail.com> | 2023-08-07 00:19:41 +0300 |
|---|---|---|
| committer | Chris Lu <chrislusf@users.noreply.github.com> | 2023-08-07 10:22:05 -0700 |
| commit | b99b31a7890108edae3a6fa7672077cd5f67aaf0 (patch) | |
| tree | f9eca471d2d351277c2982785debd1edecd9d5da | |
| parent | 251eb9b4b8dc52ca55f3903b64f4f7027343fd5b (diff) | |
| download | seaweedfs-csi-driver-b99b31a7890108edae3a6fa7672077cd5f67aaf0.tar.xz seaweedfs-csi-driver-b99b31a7890108edae3a6fa7672077cd5f67aaf0.zip | |
Node and controller servers small code cleanup, some more logging
| -rw-r--r-- | pkg/driver/controllerserver.go | 53 | ||||
| -rw-r--r-- | pkg/driver/nodeserver.go | 43 |
2 files changed, 41 insertions, 55 deletions
diff --git a/pkg/driver/controllerserver.go b/pkg/driver/controllerserver.go index b90a09c..3a5abdc 100644 --- a/pkg/driver/controllerserver.go +++ b/pkg/driver/controllerserver.go @@ -17,12 +17,15 @@ import ( ) type ControllerServer struct { + csi.UnimplementedControllerServer + Driver *SeaweedFsDriver } var _ = csi.ControllerServer(&ControllerServer{}) func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { + glog.Infof("create volume req: %v", req.GetName()) volumeId := sanitizeVolumeId(req.GetName()) @@ -54,7 +57,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol return nil, fmt.Errorf("Error setting bucket metadata: %v", err) } - glog.V(4).Infof("create volume %s", volumeId) + glog.V(4).Infof("volume created %s", volumeId) return &csi.CreateVolumeResponse{ Volume: &csi.Volume{ @@ -66,6 +69,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol } func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) { + glog.Infof("delete volume req: %v", req.VolumeId) volumeId := req.VolumeId @@ -75,10 +79,10 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol } if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil { - glog.V(3).Infof("Invalid delete volume req: %v", req) + glog.V(3).Infof("invalid delete volume req: %v", req) return nil, err } - glog.V(4).Infof("Deleting volume %s", volumeId) + glog.V(4).Infof("deleting volume %s", volumeId) if err := filer_pb.Remove(cs.Driver, "/buckets", volumeId, true, true, true, false, nil); err != nil { return nil, fmt.Errorf("Error setting bucket metadata: %v", err) @@ -87,15 +91,18 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol return &csi.DeleteVolumeResponse{}, nil } +// ControllerPublishVolume we need this just only for csi-attach, but we do nothing here generally func (cs *ControllerServer) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) { + volumeId := req.VolumeId + nodeId := req.NodeId + + glog.Infof("controller publish volume req, volume: %s, node: %s", volumeId, nodeId) // Check arguments - volumeId := req.VolumeId if len(volumeId) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request") } - nodeId := req.NodeId if len(nodeId) == 0 { return nil, status.Error(codes.InvalidArgument, "Node ID missing in request") } @@ -103,10 +110,13 @@ func (cs *ControllerServer) ControllerPublishVolume(ctx context.Context, req *cs return &csi.ControllerPublishVolumeResponse{}, nil } +// ControllerUnpublishVolume we need this just only for csi-attach, but we do nothing here generally func (cs *ControllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) { + volumeId := req.VolumeId + + glog.Infof("controller unpublish volume req: %s", req.VolumeId) // Check arguments - volumeId := req.VolumeId if len(volumeId) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request") } @@ -115,6 +125,7 @@ func (cs *ControllerServer) ControllerUnpublishVolume(ctx context.Context, req * } func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) { + glog.Infof("validate volume capabilities req: %v", req.GetVolumeId()) // Check arguments if req.GetVolumeId() == "" { @@ -159,44 +170,16 @@ func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req } -func (cs *ControllerServer) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -func (cs *ControllerServer) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - // ControllerGetCapabilities implements the default GRPC callout. // Default supports all capabilities func (cs *ControllerServer) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) { - glog.V(3).Infof("Using default ControllerGetCapabilities") + glog.V(3).Infof("get capabilities req") return &csi.ControllerGetCapabilitiesResponse{ Capabilities: cs.Driver.cscap, }, nil } -func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -func (cs *ControllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -func (cs *ControllerServer) ControllerGetVolume(ctx context.Context, req *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - func sanitizeVolumeId(volumeId string) string { volumeId = strings.ToLower(volumeId) if len(volumeId) > 63 { diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index f92769d..7171d00 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -14,6 +14,8 @@ import ( ) type NodeServer struct { + csi.UnimplementedNodeServer + Driver *SeaweedFsDriver mounter mount.Interface @@ -28,7 +30,8 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol volumeID := req.GetVolumeId() // mount the fs here stagingTargetPath := req.GetStagingTargetPath() - glog.V(0).Infof("node stage volume %s to %s", volumeID, stagingTargetPath) + + glog.Infof("node stage volume %s to %s", volumeID, stagingTargetPath) // Check arguments if req.GetVolumeCapability() == nil { @@ -50,7 +53,7 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol // The volume has been staged. if _, ok := ns.volumes.Load(volumeID); ok { - glog.V(0).Infof("volume %s has been staged", volumeID) + glog.Infof("volume %s has been already staged", volumeID) return &csi.NodeStageVolumeResponse{}, nil } @@ -79,7 +82,7 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol } ns.volumes.Store(volumeID, volume) - glog.V(0).Infof("volume %s successfully staged to %s", volumeID, stagingTargetPath) + glog.Infof("volume %s successfully staged to %s", volumeID, stagingTargetPath) return &csi.NodeStageVolumeResponse{}, nil } @@ -89,7 +92,7 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis targetPath := req.GetTargetPath() stagingTargetPath := req.GetStagingTargetPath() - glog.V(0).Infof("node publish volume %s to %s", volumeID, targetPath) + glog.Infof("node publish volume %s to %s", volumeID, targetPath) // Check arguments if req.GetVolumeCapability() == nil { @@ -123,14 +126,14 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis return nil, status.Error(codes.Internal, err.Error()) } - glog.V(0).Infof("volume %s successfully published to %s", volumeID, targetPath) + glog.Infof("volume %s successfully published to %s", volumeID, targetPath) return &csi.NodePublishVolumeResponse{}, nil } func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) { volumeID := req.GetVolumeId() targetPath := req.GetTargetPath() - glog.V(0).Infof("node unpublish volume %s from %s", volumeID, targetPath) + glog.Infof("node unpublish volume %s from %s", volumeID, targetPath) if volumeID == "" { return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request") @@ -158,11 +161,13 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu return nil, status.Error(codes.Internal, err.Error()) } + glog.Infof("volume %s successfully unpublished from %s", volumeID, targetPath) + return &csi.NodeUnpublishVolumeResponse{}, nil } func (ns *NodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) { - glog.V(3).Infof("Using default NodeGetInfo: nodeID %s", ns.Driver.nodeID) + glog.V(3).Infof("node get info, node id: %s", ns.Driver.nodeID) return &csi.NodeGetInfoResponse{ NodeId: ns.Driver.nodeID, @@ -170,7 +175,7 @@ func (ns *NodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoReque } func (ns *NodeServer) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) { - glog.V(3).Infof("Using default NodeGetCapabilities") + glog.V(3).Infof("node get capabilities") return &csi.NodeGetCapabilitiesResponse{ Capabilities: []*csi.NodeServiceCapability{ @@ -184,8 +189,6 @@ func (ns *NodeServer) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetC { Type: &csi.NodeServiceCapability_Rpc{ Rpc: &csi.NodeServiceCapability_RPC{ - // Type: csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME, - //Type: csi.NodeServiceCapability_RPC_UNKNOWN, Type: csi.NodeServiceCapability_RPC_EXPAND_VOLUME, }, }, @@ -194,14 +197,11 @@ func (ns *NodeServer) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetC }, nil } -func (ns *NodeServer) NodeGetVolumeStats(ctx context.Context, in *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - func (ns *NodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) { volumeID := req.GetVolumeId() stagingTargetPath := req.GetStagingTargetPath() - glog.V(0).Infof("node unstage volume %s from %s", volumeID, stagingTargetPath) + + glog.Infof("node unstage volume %s from %s", volumeID, stagingTargetPath) // Check arguments if volumeID == "" { @@ -231,17 +231,23 @@ func (ns *NodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag // remove mutex on successfull unstage ns.volumeMutexes.RemoveMutex(volumeID) + + glog.Infof("volume %s successfully unstaged from %s", volumeID, stagingTargetPath) + return &csi.NodeUnstageVolumeResponse{}, nil } func (ns *NodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) { - volumeID := req.GetVolumeId() + volumePath := req.GetVolumePath() + requiredBytes := req.GetCapacityRange().GetRequiredBytes() + + glog.Infof("node expand volume %s to %d bytes", req.GetVolumeId(), requiredBytes) + if len(volumeID) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request") } - volumePath := req.GetVolumePath() if len(volumePath) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume path missing in request") } @@ -249,9 +255,6 @@ func (ns *NodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV // TODO Check if volume exists // TODO Check if node exists - requiredBytes := req.GetCapacityRange().GetRequiredBytes() - glog.V(0).Infof("Node expand volume %s to %d bytes", volumeID, requiredBytes) - volumeMutex := ns.getVolumeMutex(volumeID) volumeMutex.Lock() defer volumeMutex.Unlock() |
