openBMC 的 D-Bus & Object Mapper

9 篇文章 30 订阅

// 如果之后OpenBMC架构有改,这边不会更新

目录

OpenBMC 和 D-Bus 的关系

systemd/sd-bus

sdbusplus & sdbus++

The Object Mapper

Methods 

GetObject : 查找实现特定object path的service及其interface。

GetSubTree: 在指定的subtree中查找实现某个interface的object、service和interface。

GetSubTreePaths: 这与 GetSubTree 相同,但只返回object path 

GetAncestors: 查找实现特定interface的object的所有祖先。

Associations 


简单纪录一下我对openbmc dbus 相关repository 的理解,OpenBMC 和 D-Bus 有关的 repository 大概有以下几个

  • systemd/sd-bus
  • sdbusplus & sdbus++
  • the object mapper
  • phosphor-dbus-interfaces

OpenBMC 和 D-Bus 的关系

在OpenBMC - Wikipedia中有一段描

OpenBMC uses D-Bus as an inter-process communication (IPC).
(OpenBMC 使用 D-Bus 作为进程间通信 (IPC))

下面的图是我简单画的openBMC架构,在user space 中是由很多process (daemon)所组成的

例如sensor monitor daemon会去定期读取sensor value,使用者可以透过 redfish 来获取读值,那redfish daemon 要去哪里获取读值呢? OpenBMC 给的答案是 "D-Bus"

只要所有资料都放到D-Bus上,这样这些 daemon 就能共享资料了,那dbus 的协议和操作方法可以看官方建议的 The new sd-bus API of systemd (0pointer.net)这篇文章

操作D-Bus可以先认识几个名词

Service - A daemon attached to the dbus and providing objects. (附加到 dbus 并提供对象的守护进程。)

root@romulus:~# busctl
xyz.openbmc_project.State.BMC

Object Paths – A tree, like a file system, of paths to objects.(对象路径的树,如文件系统)

root@romulus:~# busctl  tree xyz.openbmc_project.State.BMC
└─/xyz
  └─/xyz/openbmc_project
    └─/xyz/openbmc_project/state
      └─/xyz/openbmc_project/state/bmc0

Interface – The 'class' of an object. Objects support multiple inheritance.(对象的“ class ”。 对象支持多重继承) (也有人称作a set of method and signal)

  • Property – Store values. Some can be written to (存储值。有些可以改写)
  • Method – Make method calls.(进行方法调用)
  • Signal – Inform other process about an event. (将事件通知其他进程)
root@romulus:~# busctl introspect xyz.openbmc_project.State.BMC /xyz/openbmc_project/state/bmc0
NAME                                TYPE			SIGNATURE       RESULT/VALUE                                 FLAGS
xyz.openbmc_project.State.BMC       interface		-				-                                            -
.CurrentBMCState                    property        s               "xyz.openbmc_project.State.BMC.BMCState…     emits-change writable
.LastRebootTime                     property        t               1619401752000                                emits-change writable
.RequestedBMCTransition             property		s               "xyz.openbmc_project.State.BMC.Transiti…     emits-change writable

例如PSUSensor 注册了一个Service "xyz.openbmc_project.PSUSensor"

产生一个object "/xyz/openbmc_project/sensors/power/PSU_Output_Voltage"

并且assign的其中一个interface是 "xyz.openbmc_project.Sensor.Value" 这样他应该会继承四个property (phosphor-dbus-interfaces/Value.interface.yaml at master · openbmc/phosphor-dbus-interfaces · GitHub),并且把读到的PSU_Output_Voltage放到 "Value" 中

可以透过指令get-property SERVICE OBJECT INTERFACE PROPERTY...来获得PSU_Output_Voltage的value 

~# busctl get-property xyz.openbmc_project.PSUSensor    //service
/xyz/openbmc_project/sensors/power/PSU_Output_Voltage   //object
xyz.openbmc_project.Sensor.Value                        //interface
Value                                                   //property

是的,所以IPMI 和 redfish只要到指定路径就可以拿到想要的 sensor value,或是系统资料

systemd/sd-bus

systemd/sd-bus.h at main · systemd/systemd · GitHub

sd-bus 是最小的 D-Bus IPC C library,和systemd 一起released

sdbusplus & sdbus++

sdbusplus/README.md at master · openbmc/sdbusplus · GitHub

sdbusplus 是用于与 D-Bus 交互的 C++ library (libsdbusplus),构建在 systemd 的 sd-bus library之上,这样C++可以直接呼叫API,更方便好用

另外sdbus++是一个生成 C++ 绑定的工具,以简化基于 D-Bus 的应用程序的开发,搭配phosphor-dbus-interfaces GitHub - openbmc/phosphor-dbus-interfaces: YAML descriptors of standard dbus interfaces 使用

The Object Mapper

GitHub - openbmc/phosphor-objmgr: Phosphor Object Manager

这个很像BMC内部小型的database,主要两个功能是

  • Methods - 提供 D-Bus 发现相关功能。
  • Associations - 将两个不同的对象相互关联。

以下内容我简单翻译一下官方介绍 docs/object-mapper.md at master · openbmc/docs · GitHub

Methods 

前面有提到OpenBMC是由很多process所组成的,我们可以任意替换成自己开发的 psusensor daemon 或是 biosconfig daemon,但这样redfish 怎么知道她想要的值是哪些services所提供的?

因此object mapper会监测dbus上的动作,例如新增/删除 interface、object,或是 service rename等行为,redfish 可以透过 object mapper 查找想要的资讯,例如

GetObject : 查找实现特定object path的service及其interface。

GetSubTree: 在指定的subtree中查找实现某个interface的object、service和interface。

例如底下范例就是查找有"xyz.openbmc_project.Sensor.Threshold.Warning"这个interface的object、service和interface

GetSubTreePaths: 这与 GetSubTree 相同,但只返回object path 

GetAncestors: 查找实现特定interface的object的所有祖先。

以上这些method都是提供查找相对应的service和interface或是object path,但如果需要读值,还是要透过dbus api去读取,也是带入"service, object path, interface, property"

Associations 

关联,用一个指针指向相关联的物件,例如

  • 一条system event log, 可能是关于某个sensor的出了问题
  • 一个sensor ,可能是长在某一块板子上的

创建一个关联很简单,只要在object pathA中加入"xyz.openbmc_project.Association.Definitions"这个interface,并且新增一个tuple,[forward, reverse, object path]

这样就能在object mapper 中产生一个Association

再来个例子,大概是这样的操作,所以我们就能知道每块板子上有哪些sensor

先这样,之后有机会再补 

  • 17
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Maven-assembly-plugin是一个Maven插件,用于创建可部署的归档文件(assembly)。 在Maven项目中,可以使用maven-assembly-plugin来定义和配置自定义的归档文件。这些归档文件可以是可执行的JAR文件、WAR文件或其他自定义格式的文件。 对于mapper的问题,可能是指在使用maven-assembly-plugin时,如何配置mapper。在maven-assembly-plugin中,mapper是用来指定如何映射项目中的文件到归档文件中的位置。 你可以使用以下示例配置来定义mapper: ```xml <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.3.0</version> <configuration> <descriptors> <descriptor>assembly.xml</descriptor> </descriptors> </configuration> </plugin> ``` 然后,在`src/main/assembly`目录下创建一个`assembly.xml`文件,定义你的mapper配置。下面是一个简单的示例: ```xml <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> <id>my-assembly</id> <formats> <format>zip</format> </formats> <fileSets> <fileSet> <directory>${project.build.outputDirectory}</directory> <outputDirectory>/</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </fileSets> </assembly> ``` 在这个示例中,我们定义了一个名为`my-assembly`的归档文件,并将其格式设置为ZIP。然后,我们使用`fileSet`元素指定要包含在归档文件中的文件集。在这个例子中,我们将`${project.build.outputDirectory}`目录下的所有JAR文件包含在归档文件中。 这只是一个简单的示例,你可以根据你的需求进行更复杂的配置。希望这个回答对你有帮助!如果你还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值