inventory_mac: fix inventory sync
The inventory mac syncing feature was not working correctly. Fixed a
few issues with it.
1. The code waited for signals for ethernet interfaces, but those
signals were likely already emitted. We need to also scan the
existing interfaces for potential inventory lookups.
2. The code to register for inventory signals was after the
inventory lookup. This leaves a race condition where inventory
could be emitted and missed. Register the signal match before
doing the inventory lookup and cancel the match if the lookup
was successful.
3. Some places were needlessly re-reading the configuration file.
4. Some places were saving a reference to an on-stack representation
of the configuration file into a callback (for signals). Move
this to a global variable to avoid segfaults.
Tested:
Booted up in QEMU without an inventory EEPROM. Observed expected
behavior from daemon. Issued a manual inventory Notify call to create
a fake MAC address. Observed signal was reacted to appropriately.
Restarted the service and observed that 'force-sync' occurs immediately.
(trimmed duplicate journal entries from various journalctl calls)
```
root@bletchley:~# journalctl -u xyz.openbmc_project.Network
Feb 10 13:46:10 bletchley systemd[1]: Starting Phosphor Network Manager...
Feb 10 13:46:12 bletchley phosphor-network-manager[537]: Force sync enabled, check VPD for MAC
Feb 10 13:46:12 bletchley phosphor-network-manager[537]: Registering the Inventory Signals Matcher
Feb 10 13:46:15 bletchley phosphor-network-manager[537]: No Object has implemented the interface
Feb 10 13:46:15 bletchley phosphor-network-manager[537]: The operation failed internally.
Feb 10 13:46:15 bletchley phosphor-network-manager[537]: Exception occurred during getting of MAC address from Inventory
Feb 10 13:46:15 bletchley systemd[1]: Started Phosphor Network Manager.
root@bletchley:~# busctl call xyz.openbmc_project.Inventory.Manager \
/xyz/openbmc_project/inventory \
xyz.openbmc_project.Inventory.Manager Notify \
a{oa{sa{sv}}} 1 \
/xyz/openbmc_project/inventory/system/chassis/bmc/ethernet \
1 xyz.openbmc_project.Inventory.Item.NetworkInterface \
1 MACAddress s "C01850F1D796"
root@bletchley:~# journalctl -u xyz.openbmc_project.Network
Feb 10 13:48:31 bletchley phosphor-network-manager[537]: Wrote networkd file: /etc/systemd/network/00-bmc-eth0.network
Feb 10 13:48:31 bletchley phosphor-network-manager[537]: Setting MAC on eth0
root@bletchley:~# [ 185.469811] ftgmac100 1e670000.ftgmac eth0: Link is Up - 1Gbps/Full - flow control off
[ 185.471607] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
ifconfig
eth0 Link encap:Ethernet HWaddr C0:18:50:F1:D7:96
inet addr:10.0.2.16 Bcast:10.0.2.255 Mask:255.255.255.0
root@bletchley:~# systemctl restart xyz.openbmc_project.Network
root@bletchley:~# journalctl -u xyz.openbmc_project.Network
Feb 10 13:48:34 bletchley phosphor-network-manager[537]: Reloaded systemd-networkd
Feb 10 13:55:24 bletchley phosphor-network-manager[537]: Got TERM, exiting
Feb 10 13:55:24 bletchley systemd[1]: Stopping Phosphor Network Manager...
Feb 10 13:55:24 bletchley systemd[1]: xyz.openbmc_project.Network.service: Deactivated successfully.
Feb 10 13:55:24 bletchley systemd[1]: Stopped Phosphor Network Manager.
Feb 10 13:55:24 bletchley systemd[1]: Starting Phosphor Network Manager...
Feb 10 13:55:25 bletchley phosphor-network-manager[11066]: Using DHCP options from /etc/systemd/network/00-bmc-eth0.network
Feb 10 13:55:25 bletchley phosphor-network-manager[11066]: Force sync enabled, check VPD for MAC
Feb 10 13:55:25 bletchley phosphor-network-manager[11066]: Registering the Inventory Signals Matcher
Feb 10 13:55:25 bletchley phosphor-network-manager[11066]: Setting MAC on eth0
Feb 10 13:55:25 bletchley phosphor-network-manager[11066]: Removing the match for ethernet interfaces
Feb 10 13:55:25 bletchley systemd[1]: Started Phosphor Network Manager.
```
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Icf18e3d80f6d1f8c4567603fe51d774e9090334c
1 file changed