Skip to content

Commit

Permalink
feat(probe): add update 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 10, 2021
1 parent d3eb371 commit a4c6a56
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
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
26 changes: 26 additions & 0 deletions cmd/ndm_daemonset/probe/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ func (pe *ProbeEvent) deleteBlockDeviceEvent(msg controller.EventMessage) {
}
}

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

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

for _, bd := range msg.Devices {
err = pe.updateBlockDevice(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.updateBlockDeviceEvent(msg)
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions cmd/ndm_daemonset/probe/updatehandler.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) updateBlockDevice(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 indetify 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)
}

0 comments on commit a4c6a56

Please sign in to comment.