当前位置: 首页 > news >正文

QEMU源码全解析29 —— QOM介绍(18)

接前一篇文章:QEMU源码全解析28 —— QOM介绍(17)

本文内容参考:

《趣谈Linux操作系统》 —— 刘超,极客时间

《QEMU/KVM》源码解析与应用 —— 李强,机械工业出版社

特此致谢!

前文讲解了类属性的添加接口。本文讲解类属性的设置及获取接口。

每一种类属性都有自己的add函数,如布尔(bool)、字符串(str)、enum(枚举)等。它们都在qom/object.c中,逐个来看:

ObjectProperty *
object_class_property_add_bool(ObjectClass *klass, const char *name,bool (*get)(Object *, Error **),void (*set)(Object *, bool, Error **))
{BoolProperty *prop = g_malloc0(sizeof(*prop));prop->get = get;prop->set = set;return object_class_property_add(klass, name, "bool",get ? property_get_bool : NULL,set ? property_set_bool : NULL,NULL,prop);
}
ObjectProperty *
object_class_property_add_enum(ObjectClass *klass, const char *name,const char *typename,const QEnumLookup *lookup,int (*get)(Object *, Error **),void (*set)(Object *, int, Error **))
{EnumProperty *prop = g_malloc(sizeof(*prop));prop->lookup = lookup;prop->get = get;prop->set = set;return object_class_property_add(klass, name, typename,get ? property_get_enum : NULL,set ? property_set_enum : NULL,NULL,prop);
}
ObjectProperty *
object_class_property_add_str(ObjectClass *klass, const char *name,char *(*get)(Object *, Error **),void (*set)(Object *, const char *,Error **))
{StringProperty *prop = g_malloc0(sizeof(*prop));prop->get = get;prop->set = set;return object_class_property_add(klass, name, "string",get ? property_get_str : NULL,set ? property_set_str : NULL,NULL,prop);
}

这次以str为例进行讲解。上一回已经讲过,类属性的添加是通过object_class_property_add接口完成的。而str类型属性的添加object_class_property_add_str函数则是调用了此接口。为了便于理解,再次贴出object_class_property_add函数代码,在qom/object.c中,如下:

ObjectProperty *
object_class_property_add(ObjectClass *klass,const char *name,const char *type,ObjectPropertyAccessor *get,ObjectPropertyAccessor *set,ObjectPropertyRelease *release,void *opaque)
{ObjectProperty *prop;assert(!object_class_property_find(klass, name));prop = g_malloc0(sizeof(*prop));prop->name = g_strdup(name);prop->type = g_strdup(type);prop->get = get;prop->set = set;prop->release = release;prop->opaque = opaque;g_hash_table_insert(klass->properties, prop->name, prop);return prop;
}

property_set_str和property_get_str函数在前文都已给出过,这里再贴一下,在同文件(qom/object.c)中:

static void property_set_str(Object *obj, Visitor *v, const char *name,void *opaque, Error **errp)
{StringProperty *prop = opaque;char *value;if (!visit_type_str(v, name, &value, errp)) {return;}prop->set(obj, value, errp);g_free(value);
}
static void property_get_str(Object *obj, Visitor *v, const char *name,void *opaque, Error **errp)
{StringProperty *prop = opaque;char *value;Error *err = NULL;value = prop->get(obj, &err);if (err) {error_propagate(errp, err);return;}visit_type_str(v, name, &value, errp);g_free(value);
}

从这两个函数中就可以看到,StringProperty结构的set和get成员函数为调用object_class_property_add_str函数时传入的参数,形参分别为:void (*set)(Object *, const char *, Error **))和char *(*get)(Object *, Error **)。在object_property_add_str函数中使用了上边的property_set_str和property_get_str函数。在property_set_str函数中最终调用了形参void (*set)(Object *, const char *, Error **)对应的实参,即真正类型属性的设置函数;在property_get_str函数中最终调用了形参char *(*get)(Object *, Error **)对应的实参,即真正的类型属性的获取函数。

仍以machine为例,hw/core/machine.c的machine_class_init函数代码如下:

static void machine_class_init(ObjectClass *oc, void *data)
{MachineClass *mc = MACHINE_CLASS(oc);/* Default 128 MB as guest ram size */mc->default_ram_size = 128 * MiB;mc->rom_file_has_mr = true;/* numa node memory size aligned on 8MB by default.* On Linux, each node's border has to be 8MB aligned*/mc->numa_mem_align_shift = 23;object_class_property_add_str(oc, "kernel",machine_get_kernel, machine_set_kernel);object_class_property_set_description(oc, "kernel","Linux kernel image file");object_class_property_add_str(oc, "initrd",machine_get_initrd, machine_set_initrd);object_class_property_set_description(oc, "initrd","Linux initial ramdisk file");object_class_property_add_str(oc, "append",machine_get_append, machine_set_append);object_class_property_set_description(oc, "append","Linux kernel command line");object_class_property_add_str(oc, "dtb",machine_get_dtb, machine_set_dtb);object_class_property_set_description(oc, "dtb","Linux kernel device tree file");object_class_property_add_str(oc, "dumpdtb",machine_get_dumpdtb, machine_set_dumpdtb);object_class_property_set_description(oc, "dumpdtb","Dump current dtb to a file and quit");object_class_property_add(oc, "boot", "BootConfiguration",machine_get_boot, machine_set_boot,NULL, NULL);object_class_property_set_description(oc, "boot","Boot configuration");object_class_property_add(oc, "smp", "SMPConfiguration",machine_get_smp, machine_set_smp,NULL, NULL);object_class_property_set_description(oc, "smp","CPU topology");object_class_property_add(oc, "phandle-start", "int",machine_get_phandle_start, machine_set_phandle_start,NULL, NULL);object_class_property_set_description(oc, "phandle-start","The first phandle ID we may generate dynamically");object_class_property_add_str(oc, "dt-compatible",machine_get_dt_compatible, machine_set_dt_compatible);object_class_property_set_description(oc, "dt-compatible","Overrides the \"compatible\" property of the dt root node");object_class_property_add_bool(oc, "dump-guest-core",machine_get_dump_guest_core, machine_set_dump_guest_core);object_class_property_set_description(oc, "dump-guest-core","Include guest memory in a core dump");object_class_property_add_bool(oc, "mem-merge",machine_get_mem_merge, machine_set_mem_merge);object_class_property_set_description(oc, "mem-merge","Enable/disable memory merge support");object_class_property_add_bool(oc, "usb",machine_get_usb, machine_set_usb);object_class_property_set_description(oc, "usb","Set on/off to enable/disable usb");object_class_property_add_bool(oc, "graphics",machine_get_graphics, machine_set_graphics);object_class_property_set_description(oc, "graphics","Set on/off to enable/disable graphics emulation");object_class_property_add_str(oc, "firmware",machine_get_firmware, machine_set_firmware);object_class_property_set_description(oc, "firmware","Firmware image");object_class_property_add_bool(oc, "suppress-vmdesc",machine_get_suppress_vmdesc, machine_set_suppress_vmdesc);object_class_property_set_description(oc, "suppress-vmdesc","Set on to disable self-describing migration");object_class_property_add_link(oc, "confidential-guest-support",TYPE_CONFIDENTIAL_GUEST_SUPPORT,offsetof(MachineState, cgs),machine_check_confidential_guest_support,OBJ_PROP_LINK_STRONG);object_class_property_set_description(oc, "confidential-guest-support","Set confidential guest scheme to support");/* For compatibility */object_class_property_add_str(oc, "memory-encryption",machine_get_memory_encryption, machine_set_memory_encryption);object_class_property_set_description(oc, "memory-encryption","Set memory encryption object to use");object_class_property_add_link(oc, "memory-backend", TYPE_MEMORY_BACKEND,offsetof(MachineState, memdev), object_property_allow_set_link,OBJ_PROP_LINK_STRONG);object_class_property_set_description(oc, "memory-backend","Set RAM backend""Valid value is ID of hostmem based backend");object_class_property_add(oc, "memory", "MemorySizeConfiguration",machine_get_mem, machine_set_mem,NULL, NULL);object_class_property_set_description(oc, "memory","Memory size configuration");
}

此函数中很多地方调用了object_class_property_add_str函数,以其中之一为例:

object_class_property_add_str(oc, "kernel",machine_get_kernel, machine_set_kernel);

代码中的machine_set_kernel和machine_get_kernel函数就是传入object_class_property_add_str函数的与形参对应的实参,也即对于machine类的属性进行设置和获取时实际调用的函数。

至此,QEMU中的QOM相关的内容就简要介绍完了。欲知后事如何,且看下回分解。

相关文章:

QEMU源码全解析29 —— QOM介绍(18)

接前一篇文章:QEMU源码全解析28 —— QOM介绍(17) 本文内容参考: 《趣谈Linux操作系统》 —— 刘超,极客时间 《QEMU/KVM》源码解析与应用 —— 李强,机械工业出版社 特此致谢! 前文讲解了类…...

从入门到精通——【初识网络】

文章目录 前言1.网络发展背景2.计算机网络分类3.通信协议4.协议分层5. TCP/IP协议6.网络协议支持7. 封装&分用8. 客户端&服务端 前言 计算机网络是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统…...

MySQL alter命令修改表详解

目录 ALTER TABLE 语法 ALTER TABLE 实例 添加一列 添加多列 重命名列 修改列定义 修改列名和定义 添加主键 删除列 重命名表 修改表的存储引擎 结论 在使用表的过程中,如果您需要对表进行修改,您可以使用 ALTER TABLE 语句。通过 ALTER TAB…...

Vulnhub: ColddWorld: Immersion靶机

kali:192.168.111.111 靶机:192.168.111.183 信息收集 端口扫描 nmap -A -sC -v -sV -T5 -p- --scripthttp-enum 192.168.111.183 查看login的源码发现提示:page和文件/var/carls.txt 漏洞利用 wfuzz探测account.php页面发现文件包含&am…...

Redis 总结【6.0版本的】

还差什么?【按照这个为基础,对照他的Redis路线图,冲冲冲】 Redis的常见操作和命令:Redis基本操作命令(图文详解)_redis 命令_进击小高的博客-CSDN博客 Redis的持久化,一致性:AOF&…...

状态模式(C++)

定义 允许一个对象在其内部状态改变时改变它的行为。从而使对象看起来似乎修改了其行为。 应用场景 在软件构建过程中,某些对象的状态如果改变,其行为也会随之,而发生变化,比如文档处于只读状态,其支持的行为和读写…...

承泰科技Q3再获30多个智驾项目,新增订单0.86亿!累计近11亿!

中国毫米波雷达市场正处于高速发展期,以承泰科技为代表的本土供应商在前装量产赛道上展示出加速度。 高工智能汽车研究院预测,随着L2及L2持续处于市场增长的高速期,对应毫米波雷达上车量将在2023年实现30-50%的同比增速。 根据高工智能汽车…...

以太网Ethernet通信协议

一、以太网简介 计算机网络可分为局域网(LAN)、 城域网(MAN)、广域网(WAN)、互联网(Initernet)。局域网按传输介质所使用的访问控制方法可分为:以太网(Ethernet)、光纤分布式数据接口(FDDI)、异步传输模式(ATM)、令牌环网(Token Ring)、交换网(Switching) 等&#x…...

内网横向移动—资源约束委派

内网横向移动—资源约束委派 1. 资源约束委派1.1. 基于资源的约束委派的优势1.2. 约束性委派和基于资源的约束性委派配置的差别1.3. 利用条件1.3.1. 什么用户能够修改msDS-AllowedToActOnBehalfOfOtherIdentity属性1.3.2. 将机器加入域的域用户 2. 案例操作2.1. 获取目标信息2.…...

Spring Boot Logback日志格式改为JSON

在阿里云、或者日志分析时使用JSON格式输出日志更加方便。 依赖 增加Logbak JSON解析依赖。 另外需要注意的是JSON格式输出依赖Jackson&#xff0c;根据工程情况按需添加Jackson依赖。 <!--日志--><dependency><groupId>ch.qos.logback.contrib</grou…...

Linux 块设备操作函数

和字符设备的fil_operations一样&#xff0c;块设备也有操作集&#xff0c;为结构体block_device_operations&#xff0c;此结构体定义在include/linux/blkdev.h中&#xff0c;结构体内容如下&#xff1a; struct block_device_operations {int (*open) (struct block_device …...

linux c++网络编程基础:服务端与客户端的实现

在Linux环境下,我们可以使用socket编程来实现网络通信。下面是一个简单的C++版本的客户端和服务端的示例代码。 服务端代码: #include <sys/socket.h> #include <netinet/in.h> #include <unistd.h> #include <string.h> #...

坐标转换-使用geotools读取和转换地理空间表的坐标系(sqlserver、postgresql)

前言&#xff1a; 业务上通过GIS软件将空间数据导入到数据库时&#xff0c;因为不同的数据来源和软件设置&#xff0c;可能导入到数据库的空间表坐标系是各种各样的。 如果要把数据库空间表发布到geoserver并且统一坐标系&#xff0c;只是在geoserver单纯的设置坐标系只是改了…...

JavaScript的主要应用场景有哪些?请描述一下JavaScript的基本数据类型和引用数据类型分别是哪些?

1、JavaScript的主要应用场景有哪些&#xff1f; JavaScript是一种广泛使用的编程语言&#xff0c;它主要用于Web开发、移动应用开发、游戏开发、物联网设备开发等场景。以下是JavaScript的主要应用场景&#xff1a; Web开发&#xff1a;JavaScript是Web开发中最常用的编程语…...

webpack性能优化

文章目录 1. 性能优化-分包2. 动态导入3. 自定义分包4. Prefetch和Preload5. CDN加载配置6. CSS的提取7. terser压缩7.1 Terser在webpack中配置7.2 css压缩 8. Tree Shaking 消除未使用的代码8.1 usedExports 配置8.2 sideEffects配置8.3 CSS实现Tree Shaking 9. Scope Hoistin…...

保存和读取带有透明通道的视频

保存带有透明通道的视频&#xff1a; import osimport imageio from rembg import remove as removBg,new_session from PIL import Image import numpy as np import cv2 from tqdm import tqdmclass cls_rembg():def __init__(self,model_pth):self.session new_session(mo…...

bilibili的评论ip属地显示未知

现象 出于某些原因&#xff0c;我们在日常使用中的大部分平台都开启了IP地址显示&#xff0c;一般会显示当事人所在的地址&#xff0c;这其中就有一些奇怪的地址&#xff0c;&#xff08;在此不谈魔法&#xff09;就比如我最近在刷B站的时候&#xff0c;就在评论区发现了一些显…...

[BabysqliV3.0]phar反序列化

文章目录 [BabysqliV3.0]phar反序列化 [BabysqliV3.0]phar反序列化 开始以为是sql注入 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ST1jvadM-1691302941344)(https://raw.githubusercontent.com/leekosss/photoBed/master/202308032140269.png)…...

数据库架构演变过程

&#x1f680; ShardingSphere &#x1f680; &#x1f332; 算法刷题专栏 | 面试必备算法 | 面试高频算法 &#x1f340; &#x1f332; 越难的东西,越要努力坚持&#xff0c;因为它具有很高的价值&#xff0c;算法就是这样✨ &#x1f332; 作者简介&#xff1a;硕风和炜&…...

webpack 静态模块打包工具

webpack 为什么? 把静态模块内容&#xff0c;压缩&#xff0c;整合&#xff0c;转译等(前端工程化) 把less/sass转成css代码把ES6 降级成ES5支持多种模块文件类型&#xff0c;多种模块标准语法 vite 为什么不直接学习vite 而学习webpack 因为很多项目还是基于webpack来进…...

智慧医疗能源事业线深度画像分析(上)

引言 医疗行业作为现代社会的关键基础设施,其能源消耗与环境影响正日益受到关注。随着全球"双碳"目标的推进和可持续发展理念的深入,智慧医疗能源事业线应运而生,致力于通过创新技术与管理方案,重构医疗领域的能源使用模式。这一事业线融合了能源管理、可持续发…...

Leetcode 3577. Count the Number of Computer Unlocking Permutations

Leetcode 3577. Count the Number of Computer Unlocking Permutations 1. 解题思路2. 代码实现 题目链接&#xff1a;3577. Count the Number of Computer Unlocking Permutations 1. 解题思路 这一题其实就是一个脑筋急转弯&#xff0c;要想要能够将所有的电脑解锁&#x…...

在Ubuntu中设置开机自动运行(sudo)指令的指南

在Ubuntu系统中&#xff0c;有时需要在系统启动时自动执行某些命令&#xff0c;特别是需要 sudo权限的指令。为了实现这一功能&#xff0c;可以使用多种方法&#xff0c;包括编写Systemd服务、配置 rc.local文件或使用 cron任务计划。本文将详细介绍这些方法&#xff0c;并提供…...

uniapp 开发ios, xcode 提交app store connect 和 testflight内测

uniapp 中配置 配置manifest 文档&#xff1a;manifest.json 应用配置 | uni-app官网 hbuilderx中本地打包 下载IOS最新SDK 开发环境 | uni小程序SDK hbulderx 版本号&#xff1a;4.66 对应的sdk版本 4.66 两者必须一致 本地打包的资源导入到SDK 导入资源 | uni小程序SDK …...

stm32wle5 lpuart DMA数据不接收

配置波特率9600时&#xff0c;需要使用外部低速晶振...

倒装芯片凸点成型工艺

UBM&#xff08;Under Bump Metallization&#xff09;与Bump&#xff08;焊球&#xff09;形成工艺流程。我们可以将整张流程图分为三大阶段来理解&#xff1a; &#x1f527; 一、UBM&#xff08;Under Bump Metallization&#xff09;工艺流程&#xff08;黄色区域&#xff…...

Python环境安装与虚拟环境配置详解

本文档旨在为Python开发者提供一站式的环境安装与虚拟环境配置指南&#xff0c;适用于Windows、macOS和Linux系统。无论你是初学者还是有经验的开发者&#xff0c;都能在此找到适合自己的环境搭建方法和常见问题的解决方案。 快速开始 一分钟快速安装与虚拟环境配置 # macOS/…...

Qt Quick Controls模块功能及架构

Qt Quick Controls是Qt Quick的一个附加模块&#xff0c;提供了一套用于构建完整用户界面的UI控件。在Qt 6.0中&#xff0c;这个模块经历了重大重构和改进。 一、主要功能和特点 1. 架构重构 完全重写了底层架构&#xff0c;与Qt Quick更紧密集成 移除了对Qt Widgets的依赖&…...

【向量库】Weaviate 搜索与索引技术:从基础概念到性能优化

文章目录 零、概述一、搜索技术分类1. 向量搜索&#xff1a;捕捉语义的智能检索2. 关键字搜索&#xff1a;精确匹配的传统方案3. 混合搜索&#xff1a;语义与精确的双重保障 二、向量检索技术分类1. HNSW索引&#xff1a;大规模数据的高效引擎2. Flat索引&#xff1a;小规模数据…...

timestamp时间戳转换工具

作为一名程序员&#xff0c;一款高效的 在线转换工具 &#xff08;在线时间戳转换 计算器 字节单位转换 json格式化&#xff09;必不可少&#xff01;https://jsons.top 排查问题时非常痛的点: 经常在秒级、毫秒级、字符串格式的时间单位来回转换&#xff0c;于是决定手撸一个…...