nova的pci 设备白名单

本文介绍了Nova项目中PCI设备白名单的实现原理。通过解析配置文件加载白名单,并验证其有效性,确保只有指定的guest能够使用PCI设备。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

并不是所有的guest可以使用pci设备,在E:\nova\nova\pci\whitelist.py 中定义了白名单决定
哪些guest可以使用pci device
在class Whitelist(object)这个class的__init__ 中会调用_parse_white_list_from_config 来
从配置文件中将guest使用pci设备的白名单加载进来

    @staticmethod
    def _parse_white_list_from_config(whitelists):
        """Parse and validate the pci whitelist from the nova config."""
        specs = []
        for jsonspec in whitelists:
            try:
#将whitelists 反序列化后形成dict 存到dev_spec 这个dict
                dev_spec = jsonutils.loads(jsonspec)
            except ValueError:
                raise exception.PciConfigInvalidWhitelist(
                          reason=_("Invalid entry: '%s'") % jsonspec)
            if isinstance(dev_spec, dict):
                dev_spec = [dev_spec]
            elif not isinstance(dev_spec, list):
                raise exception.PciConfigInvalidWhitelist(
                          reason=_("Invalid entry: '%s'; "
                                   "Expecting list or dict") % jsonspec)

            for ds in dev_spec:
                if not isinstance(ds, dict):
                    raise exception.PciConfigInvalidWhitelist(
                              reason=_("Invalid entry: '%s'; "
                                       "Expecting dict") % ds)

                spec = devspec.PciDeviceSpec(ds)
                specs.append(spec)

        return specs

同样Whitelist提供了device_assignable 来判断guest是否可以使用pci设备
    def device_assignable(self, dev):
#遍历specs list,看dev是否在白名单中,如果在的话,则返回true,则表示可以此dev可以使用pci设备

        for spec in self.specs:
            if spec.match(dev):
                return True
        return False

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值