Skip to content

Commit

Permalink
feat(probe): add change handlers to process device updates
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Jain <aditya.jainadityajain.jain@gmail.com>
  • Loading branch information
z0marlin committed Jun 13, 2021
1 parent 6f5878e commit de8fc09
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/ndm_daemonset/probe/addhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (pe *ProbeEvent) addBlockDevice(bd blockdevice.BlockDevice, bdAPIList *apis
return nil
}
} else {
// FIXME: update controller cache after setting uuid
bd.UUID = uuid
klog.V(4).Infof("uuid: %s has been generated for device: %s", uuid, bd.DevPath)
bdAPI, err := pe.Controller.GetBlockDevice(uuid)
Expand Down
41 changes: 41 additions & 0 deletions cmd/ndm_daemonset/probe/changehandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2020 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package probe

import (
"errors"

"github.com/openebs/node-disk-manager/blockdevice"
"k8s.io/klog"
)

func (pe *ProbeEvent) changeBlockDevice(bd *blockdevice.BlockDevice) error {
pe.Controller.FillBlockDeviceDetails(bd)
if bd.UUID == "" {
uuid, ok := generateUUID(*bd)
if !ok {
klog.Error("could no generate uuid for device. aborting")
return errors.New("could not indentify device uniquely")
}
bd.UUID = uuid
}
pe.addBlockDeviceToHierarchyCache(*bd)
apiBlockdevice := pe.Controller.NewDeviceInfoFromBlockDevice(bd).ToDevice()
apiBlockdevice.SetNamespace(pe.Controller.Namespace)
klog.Info("updating bd: ", apiBlockdevice.GetName())
return pe.Controller.UpdateBlockDevice(apiBlockdevice, nil)
}
28 changes: 27 additions & 1 deletion cmd/ndm_daemonset/probe/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
// DetachEA is detach disk event name
DetachEA EventAction = libudevwrapper.UDEV_ACTION_REMOVE
// MountEA is mount-point/fs change event
MountEA EventAction = "mountch"
MountEA EventAction = "mount-change"
)

// ProbeEvent struct contain a copy of controller it will update disk resources
Expand Down Expand Up @@ -138,6 +138,28 @@ func (pe *ProbeEvent) deleteBlockDeviceEvent(msg controller.EventMessage) {
}
}

func (pe *ProbeEvent) changeBlockDeviceEvent(msg controller.EventMessage) {
var err error

if isAllBlockDevices(msg.Devices) {
for _, bd := range pe.Controller.BDHierarchy {
err = pe.changeBlockDevice(&bd)
if err != nil {
klog.Errorf("failed to update blockdevice: %v", err)
}
}
return
}

for _, bd := range msg.Devices {
err = pe.changeBlockDevice(bd)
if err != nil {
klog.Errorf("failed to update blockdevice: %v", err)
}
}

}

// isParentOrSlaveDevice check if any of the errored device is a parent / slave to the
// given blockdevice
func isParentOrSlaveDevice(bd blockdevice.BlockDevice, erroredDevices []string) bool {
Expand All @@ -151,3 +173,7 @@ func isParentOrSlaveDevice(bd blockdevice.BlockDevice, erroredDevices []string)
}
return false
}

func isAllBlockDevices(devices []*blockdevice.BlockDevice) bool {
return len(devices) == 1 && devices[0] == &blockdevice.AllBlockDevices
}
2 changes: 2 additions & 0 deletions cmd/ndm_daemonset/probe/udevprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ func (up *udevProbe) listen() {
probeEvent.addBlockDeviceEvent(msg)
case string(DetachEA):
probeEvent.deleteBlockDeviceEvent(msg)
case string(MountEA):
probeEvent.changeBlockDeviceEvent(msg)
}
}
}
Expand Down

0 comments on commit de8fc09

Please sign in to comment.