[VOL-2107] SIGSEGV while disabling a device
Fixed segmentation fault while
deleting a device which can not be connected.
Change-Id: I70f50d460f16d0bb8cca886b1dbfccf9525cd0c7
diff --git a/adaptercore/device_handler.go b/adaptercore/device_handler.go
index 2e19d7c..a97a37d 100644
--- a/adaptercore/device_handler.go
+++ b/adaptercore/device_handler.go
@@ -1073,20 +1073,21 @@
dh.lockDevice.Lock()
dh.adminState = "down"
dh.lockDevice.Unlock()
- if _, err := dh.Client.DisableOlt(context.Background(), new(oop.Empty)); err != nil {
- if e, ok := status.FromError(err); ok && e.Code() == codes.Internal {
- log.Errorw("failed-to-disable-olt ", log.Fields{"err": err})
- dh.lockDevice.Lock()
- dh.adminState = "up"
- dh.lockDevice.Unlock()
- return err
+ if dh.Client != nil {
+ if _, err := dh.Client.DisableOlt(context.Background(), new(oop.Empty)); err != nil {
+ if e, ok := status.FromError(err); ok && e.Code() == codes.Internal {
+ log.Errorw("failed-to-disable-olt ", log.Fields{"err": err, "deviceID": device.Id})
+ dh.lockDevice.Lock()
+ dh.adminState = "up"
+ dh.lockDevice.Unlock()
+ return err
+ }
}
-
}
- log.Debug("olt-disabled")
- dh.lockDevice.Lock()
+ log.Debugw("olt-disabled", log.Fields{"deviceID": device.Id})
/* Discovered ONUs entries need to be cleared , since on device disable the child devices goes to
- UNREACHABLE state which needs to be configured again*/
+ UNREACHABLE state which needs to be configured again*/
+ dh.lockDevice.Lock()
dh.discOnus = make(map[string]bool)
dh.onus = make(map[string]*OnuDevice)
dh.lockDevice.Unlock()
@@ -1203,6 +1204,9 @@
func (dh *DeviceHandler) clearNNIData() error {
nniUniID := -1
nniOnuID := -1
+ if dh.resourceMgr == nil {
+ return fmt.Errorf("no resource manager for deviceID %s", dh.deviceID)
+ }
flowIDs := dh.resourceMgr.GetCurrentFlowIDsForOnu(uint32(dh.nniIntfID), uint32(nniOnuID), uint32(nniUniID))
log.Debugw("Current flow ids for nni", log.Fields{"flow-ids": flowIDs})
for _, flowID := range flowIDs {
@@ -1236,20 +1240,22 @@
This clears up flow data and also resource map data for various
other pon resources like alloc_id and gemport_id
*/
- for _, onu := range dh.onus {
- if err := dh.clearUNIData(onu); err != nil {
- log.Debugw("Failed to clear data for onu", log.Fields{"onu-device": onu})
+ if dh.resourceMgr != nil {
+ for _, onu := range dh.onus {
+ if err := dh.clearUNIData(onu); err != nil {
+ log.Debugw("Failed to clear data for onu", log.Fields{"onu-device": onu})
+ }
}
- }
- /* Clear the flows from KV store associated with NNI port.
- There are mostly trap rules from NNI port (like LLDP)
- */
- if err := dh.clearNNIData(); err != nil {
- log.Debugw("Failed to clear data for NNI port", log.Fields{"device-id": dh.deviceID})
- }
+ /* Clear the flows from KV store associated with NNI port.
+ There are mostly trap rules from NNI port (like LLDP)
+ */
+ if err := dh.clearNNIData(); err != nil {
+ log.Debugw("Failed to clear data for NNI port", log.Fields{"deviceID": dh.deviceID})
+ }
- /* Clear the resource pool for each PON port in the background */
- go dh.resourceMgr.Delete()
+ /* Clear the resource pool for each PON port in the background */
+ go dh.resourceMgr.Delete()
+ }
/*Delete ONU map for the device*/
for onu := range dh.onus {
@@ -1259,9 +1265,11 @@
// Stop the Stats collector
dh.stopCollector <- true
//Reset the state
- if _, err := dh.Client.Reboot(context.Background(), new(oop.Empty)); err != nil {
- log.Errorw("Failed-to-reboot-olt ", log.Fields{"err": err})
- return err
+ if dh.Client != nil {
+ if _, err := dh.Client.Reboot(context.Background(), new(oop.Empty)); err != nil {
+ log.Errorw("Failed-to-reboot-olt ", log.Fields{"deviceID": dh.deviceID, "err": err})
+ return err
+ }
}
cloned := proto.Clone(device).(*voltha.Device)
cloned.OperStatus = voltha.OperStatus_UNKNOWN
@@ -1276,7 +1284,7 @@
//RebootDevice reboots the given device
func (dh *DeviceHandler) RebootDevice(device *voltha.Device) error {
if _, err := dh.Client.Reboot(context.Background(), new(oop.Empty)); err != nil {
- log.Errorw("Failed to reboot olt ", log.Fields{"err": err})
+ log.Errorw("Failed to reboot olt ", log.Fields{"deviceID": dh.deviceID, "err": err})
return err
}
diff --git a/adaptercore/resourcemanager/resourcemanager.go b/adaptercore/resourcemanager/resourcemanager.go
index 3757e37..e412bb6 100755
--- a/adaptercore/resourcemanager/resourcemanager.go
+++ b/adaptercore/resourcemanager/resourcemanager.go
@@ -419,7 +419,10 @@
func (RsrcMgr *OpenOltResourceMgr) GetCurrentFlowIDsForOnu(PONIntfID uint32, ONUID uint32, UNIID uint32) []uint32 {
FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID)
- return RsrcMgr.ResourceMgrs[PONIntfID].GetCurrentFlowIDsForOnu(FlowPath)
+ if mgrs, exist := RsrcMgr.ResourceMgrs[PONIntfID]; exist {
+ return mgrs.GetCurrentFlowIDsForOnu(FlowPath)
+ }
+ return nil
}
// UpdateFlowIDInfo updates flow info for the given pon interface, onu id, and uni id