轻量级虚拟化技术草稿
Support Tech
ST.1 virtiofs
ST.1.1 fuse framework
引用wiki中关于fuse的定义:
Filesystem in Userspace (FUSE) is a software interface for Unix and Unix-like computer operating systems that lets non-privileged users create their own file systems without editing kernel code. This is achieved by running file system code in user space while the FUSE module provides only a bridge to the actual kernel interfaces.
其代码框架如下:
主要分为三部分:
- 内核Fuse Filsystem Client,对接Linux Kernel的VFS
- Fuse协议,其中包括了op code及其参数格式,参考GitHub - libfuse/libfuse: The reference implementation of the Linux FUSE (Filesystem in Userspace) interfaceThe reference implementation of the Linux FUSE (Filesystem in Userspace) interface - GitHub - libfuse/libfuse: The reference implementation of the Linux FUSE (Filesystem in Userspace) interface
https://github.com/libfuse/libfuse
- Fuse传输层,目前包括两种,本地char设备和virtio
参考代码:
fuse_do_readpage()
---...loff_t pos = page_offset(page);struct fuse_page_desc desc = { .length = PAGE_SIZE };struct fuse_io_args ia = {.ap.args.page_zeroing = true,.ap.args.out_pages = true,.ap.num_pages = 1,.ap.pages = &page,.ap.descs = &desc,};...fuse_wait_on_page_writeback(inode, page->index);...fuse_read_args_fill(&ia, file, pos, desc.length, FUSE_READ);res = fuse_simple_request(fm, &ia.ap.args);...SetPageUptodate(page);
---fuse_lookup_name()
---fuse_lookup_init(fm->fc, &args, nodeid, name, outarg);---args->opcode = FUSE_LOOKUP;args->nodeid = nodeid;args->in_numargs = 1;args->in_args[0].size = name->len + 1;args->in_args[0].value = name->name;args->out_numargs = 1;args->out_args[0].size = sizeof(struct fuse_entry_out);args->out_args[0].value = outarg;// fuse_entry_out.attr includes all of inode attributes, such as ino/size/blocks/atime/mtime/ctime/nlink/mode/uid/gid ...---err = fuse_simple_request(fm, &args);...*inode = fuse_iget(sb, outarg->nodeid, outarg->generation,&outarg->attr, entry_attr_timeout(outarg),attr_version);
---fuse_simple_request()
---if (args->force) {atomic_inc(&fc->num_waiting);req = fuse_request_alloc(fm, GFP_KERNEL | __GFP_NOFAIL);...__set_bit(FR_WAITING, &req->flags);__set_bit(FR_FORCE, &req->flags);} else {req = fuse_get_req(fm, false);...}...__fuse_request_send(req);...fuse_put_request(req);
---__fuse_request_send()-> spin_lock(&fiq->lock);-> queue_request_and_unlock()---list_add_tail(&req->list, &fiq->pending);fiq->ops->wake_pending_and_unlock(fiq);----> request_wait_answer()---if (!fc->no_interrupt) {/* Any signal may interrupt this */err = wait_event_interruptible(req->waitq,test_bit(FR_FINISHED, &req->flags));...}if (!test_bit(FR_FORCE, &req->flags)) {/* Only fatal signals may interrupt this */err = wait_event_killable(req->waitq,test_bit(FR_FINISHED, &req->flags));...}/** Either request is already in userspace, or it was forced.* Wait it out.*/wait_event(req->waitq, test_bit(FR_FINISHED, &req->flags));---
以上代码中列举了两个常见的文件系统操作,readpage和lookup,它们都是同步的,所以,需要request_wait_answer()。
write page的处理代码如下:
fuse_writepage_locked()
---tmp_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM);...fuse_write_args_fill(&wpa->ia, wpa->ia.ff, page_offset(page), 0);copy_highpage(tmp_page, page);wpa->ia.write.in.write_flags |= FUSE_WRITE_CACHE;wpa->next = NULL;ap->args.in_pages = true;ap->num_pages = 1;ap->pages[0] = tmp_page;ap->descs[0].offset = 0;ap->descs[0].length = PAGE_SIZE;ap->args.end = fuse_writepage_end;wpa->inode = inode;inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK);inc_node_page_state(tmp_page, NR_WRITEBACK_TEMP);spin_lock(&fi->lock);tree_insert(&fi->writepages, wpa);list_add_tail(&wpa->queue_entry, &fi->queued_writes);fuse_flush_writepages(inode);spin_unlock(&fi->lock);end_page_writeback(page);
---fuse_writepages()
---err = write_cache_pages(mapping, wbc, fuse_writepages_fill, &data);if (data.wpa) {WARN_ON(!data.wpa->ia.ap.num_pages);fuse_writepages_send(&data);}
---fuse_writepages_send()
---spin_lock(&fi->lock);list_add_tail(&wpa->queue_entry, &fi->queued_writes);fuse_flush_writepages(inode);spin_unlock(&fi->lock);for (i = 0; i < num_pages; i++)end_page_writeback(data->orig_pages[i]);
---fuse_flush_writepages()-> fuse_send_writepage()-> fuse_simple_background()-> fuse_request_queue_background()---if (likely(fc->connected)) {fc->num_background++;if (fc->num_background == fc->max_background)fc->blocked = 1;if (fc->num_background == fc->congestion_threshold && fm->sb) {set_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);set_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);}list_add_tail(&req->list, &fc->bg_queue);flush_bg_queue(fc);queued = true;}---fuse_send_writepage()
---fi->writectr++;
---fuse_writepage_end()
---fi->writectr--;fuse_writepage_finish(fm, wpa);---for (i = 0; i < ap->num_pages; i++) {dec_wb_stat(&bdi->wb, WB_WRITEBACK);dec_node_page_state(ap->pages[i], NR_WRITEBACK_TEMP);wb_writeout_inc(&bdi->wb);}wake_up(&fi->page_waitq);---
---fuse_fsync()-> file_write_and_wait_range()-> fuse_sync_writes(inode)-> fuse_set_nowrite()---spin_lock(&fi->lock);BUG_ON(fi->writectr < 0);fi->writectr += FUSE_NOWRITE;spin_unlock(&fi->lock);wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE);---
---
write page中最大的不同在于:fuse申请了一个tmp_page,然后使用这个tmp_page去承载数据,并发给对端;发出去之后,立刻就调用了end_page_writeback(),此时page cache中的数据还没有真正落盘;数据落盘的语义最终是通过fsync保证的。这样就避免了用户态fuse daemon故障导致系统dirty pages无人处理。
对与这个设计,fuse的commit的comment中做了解释:
Fuse page writeback design--------------------------fuse_writepage() allocates a new temporary page with GFP_NOFS|__GFP_HIGHMEM.It copies the contents of the original page, and queues a WRITE request to theuserspace filesystem using this temp page.The writeback is finished instantly from the MM's point of view: the page isremoved from the radix trees, and the PageDirty and PageWriteback flags arecleared.For the duration of the actual write, the NR_WRITEBACK_TEMP counter isincremented. The per-bdi writeback count is not decremented until the actualwrite completes.On dirtying the page, fuse waits for a previous write to finish beforeproceeding. This makes sure, there can only be one temporary page used at atime for one cached page.This approach is wasteful in both memory and CPU bandwidth, so why is this^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^complication needed?The basic problem is that there can be no guarantee about the time in which^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^the userspace filesystem will complete a write. It may be buggy or even^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^malicious, and fail to complete WRITE requests. We don't want unrelated partsof the system to grind to a halt in such cases.Also a filesystem may need additional resources (particularly memory) tocomplete a WRITE request. There's a great danger of a deadlock if thatallocation may wait for the writepage to finish.
相关文章:

轻量级虚拟化技术草稿
Support Tech ST.1 virtiofs ST.1.1 fuse framework 引用wiki中关于fuse的定义: Filesystem in Userspace (FUSE) is a software interface for Unix and Unix-like computer operating systems that lets non-privileged users create their own file systems w…...
bootz启动 Linux内核过程中涉及的 do_bootm_states 函数
一. bootz启动Linux uboot 启动Linux内核使用bootz命令。当然还有其它的启动命令,例如,bootm命令等等。 本文只分析 bootz命令启动 Linux内核的过程中涉及的几个重要函数。具体分析 do_bootm_states 函数执行过程。 本文继上一篇文章,地址…...

springcloud学习笔记(3)-服务管理组件Nacos
Nacos简介 在2中学习了服务治理中心eureka,而本节的nacos来自springcloud alibaba。 Nacos也是一个服务注册和管理的组件。 Nacos 支持几乎所有主流类型的“服务”的发现、配置和管理 官方文档 快速开始 | Spring Cloud Alibaba (aliyun.com) 概述 | Spring C…...
Insight h2database 更新、读写锁以及事务原理
文章基于 RegularTable 来分析和拆解更新操作。 锁模型比较简单,方便了解更新的整个流程。并发读写的实现在 MVStore 存储引擎中分析。 主要关注数据更新的实现、事务的提交和回滚。 相关概念 讨论更新操作,就需要涉及到事务隔离级别以及事务的概念。 也…...

skywalking动态配置[集成nacos/apollo/consul]
说明:以下配置仅关于的阈值规则的动态配置,其他参数也可以进行配置。 1,skywalking动态配置集成nacos 编辑application.yml nacos配置参数如下: nacos:# Nacos Server HostserverAddr: 10.10.5.145# Nacos Server Portport: 8848# Nacos Configuration Groupgroup: skywal…...

UniApp创建项目HelloWorld
浏览器预览效果镇楼 普通项目创建 点击创建完成后,就如下所示 确实和微信小程序开发差不多。只是稍微换了一个名字的概念了,这个就是开发嘛,不要过于纠结概念性东西。开发开发,开了就知道怎么发了? 或许是 反正write就…...

Qt/C++原创推流工具/支持多种流媒体服务/ZLMediaKit/srs/mediamtx等
一、前言 1.1 功能特点 支持各种本地视频文件和网络视频文件。支持各种网络视频流,网络摄像头,协议包括rtsp、rtmp、http。支持将本地摄像头设备推流,可指定分辨率和帧率等。支持将本地桌面推流,可指定屏幕区域和帧率等。自动启…...
学习黑马程序员JavaScript总结
今天注意学习了数据类型、运算符、常量、数组,这些内容接受的还是比较快的,因为前面学过C语言还有Python,比较不同的地方就是未定义类型undefined,这个类型是在只声明了变量但未赋值,而unll空类型它是赋了值但该值是空…...

浅谈高速公路服务区分布式光伏并网发电
前言 今年的国家经济工作会议提出:将“做好碳达峰、碳中和工作”作为 2021年的主要任务之一,而我国高速公路里程 15.5万公里,对能源的需求与日俱增,碳排放量增速明显。 为了实现采用减少碳排放量,采用清洁能源替代的…...
MATLAB算法实战应用案例精讲-【图像处理】机器视觉(番外篇)
目录 前言 算法原理 机器视觉检测系统工作原理 机器视觉光源分类...

塑胶材料检测对激光焊机的作用
塑胶材料的激光焊接已经普遍用于各种零配件,而塑料的透光率是焊接工艺质量的一个重要指标。针对这类塑胶材料推出这款专门检测塑胶材料近红外透光率特性的透光率检测仪,对注塑件的透光率进行全画面扫描。 全球工业致力于贯彻绿色环保、节能减排发展理念&…...
将Eureka服务注册到Eureka中心
1、在微服务的pom.xml引入依赖文件中 <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>2、在微服务的application.yml配置文件中加上…...

将网站域名访问从http升级到https(腾讯云/阿里云)
文章目录 1.前提说明2.服务器安装 docker 与 nginx2.1 安装 docker🍀 基于 centos 的安装🍀 基于ubuntu 2.2 配置阿里云国内加速器🍀 找到相应页面🍀 创建 docker 目录🍀 创建 daemon.json 文件🍀 重新加载…...

QT通过TCP协议发送结构体数据
QT通过TCP协议发送结构体数据 Chapter1 QT通过TCP协议发送结构体数据前言1. memcpy方式1.1 发送整个结构体1.2 发送部分数据 2. QDataStream2.1 符号<<2.2 wrieteRawData 总结 Chapter2 qt中操作json,读取json,写入json,转换json一、说…...
C++标准库之numeric
文章目录 一. numeric库介绍二.详解accumulate1. 计算数组中所有元素的和2. 计算数组中所有元素的乘积3. 计算数组中每个元素乘以3之后的和4.计算数组中每个元素减去3之后的和5.计算班级内学生的平均分6.拼接字符串 adjacent_differenceinner_productpartial_sumiota 三. 参考 …...
第六章:最新版零基础学习 PYTHON 教程—Python 正则表达式(第二节 - Python 中的正则表达式与示例套装)
正则表达式 (RegEx)是一种特殊的字符序列,它使用搜索模式来查找字符串或字符串集。它可以通过将文本与特定模式进行匹配来检测文本是否存在,并且还可以将模式拆分为一个或多个子模式。Python 提供了一个re模块,支持在 Python 中使用正则表达式。它的主要功能是提供搜索,其中…...

【Python】WebUI自动化—Selenium的下载和安装、基本用法、项目实战(16)
文章目录 一.介绍二.下载安装selenium三.安装浏览器驱动四.QuickStart—自动访问百度五.Selenium基本用法1.定位节点1.1.单个元素定位1.2.多个元素定位 2.控制浏览器2.1.设置浏览器窗口大小、位置2.2.浏览器前进、刷新、后退、关闭3.3.等待3.4.Frame3.5.多窗口3.6.元素定位不到…...

c++视觉处理---图像重映射
图像重映射:cv::remap cv::remap 是OpenCV中的一个函数,用于执行图像重映射,允许您通过重新映射像素的位置来变换图像。这个函数非常有用,可以用于各种图像处理任务,如校正畸变、透视变换、几何变换等。 下面是 cv::…...

基于YOLO算法的单目相机2D测量(工件尺寸和物体尺寸)
1.简介 1.1 2D测量技术 基于单目相机的2D测量技术在许多领域中具有重要的背景和意义。 工业制造:在工业制造过程中,精确测量是确保产品质量和一致性的关键。基于单目相机的2D测量技术可以用于检测和测量零件尺寸、位置、形状等参数,进而实…...
Insight h2database 执行计划评估以及 Selectivity
生成执行计划是任何一个数据库不可缺少的过程。通过本文看执行计划生成原理。 最优的执行计划就是寻找最小计算成本的过程。 本文侧重 BTree 索引的成本计算的实现 以及 基础概念选择度的分析。 寻找最优执行计划 找到最佳的索引,实现最少的遍历,得到想要…...

日语AI面试高效通关秘籍:专业解读与青柚面试智能助攻
在如今就业市场竞争日益激烈的背景下,越来越多的求职者将目光投向了日本及中日双语岗位。但是,一场日语面试往往让许多人感到步履维艰。你是否也曾因为面试官抛出的“刁钻问题”而心生畏惧?面对生疏的日语交流环境,即便提前恶补了…...
HTML 语义化
目录 HTML 语义化HTML5 新特性HTML 语义化的好处语义化标签的使用场景最佳实践 HTML 语义化 HTML5 新特性 标准答案: 语义化标签: <header>:页头<nav>:导航<main>:主要内容<article>&#x…...

Linux 文件类型,目录与路径,文件与目录管理
文件类型 后面的字符表示文件类型标志 普通文件:-(纯文本文件,二进制文件,数据格式文件) 如文本文件、图片、程序文件等。 目录文件:d(directory) 用来存放其他文件或子目录。 设备…...
C++:std::is_convertible
C++标志库中提供is_convertible,可以测试一种类型是否可以转换为另一只类型: template <class From, class To> struct is_convertible; 使用举例: #include <iostream> #include <string>using namespace std;struct A { }; struct B : A { };int main…...

Appium+python自动化(十六)- ADB命令
简介 Android 调试桥(adb)是多种用途的工具,该工具可以帮助你你管理设备或模拟器 的状态。 adb ( Android Debug Bridge)是一个通用命令行工具,其允许您与模拟器实例或连接的 Android 设备进行通信。它可为各种设备操作提供便利,如安装和调试…...
CRMEB 框架中 PHP 上传扩展开发:涵盖本地上传及阿里云 OSS、腾讯云 COS、七牛云
目前已有本地上传、阿里云OSS上传、腾讯云COS上传、七牛云上传扩展 扩展入口文件 文件目录 crmeb\services\upload\Upload.php namespace crmeb\services\upload;use crmeb\basic\BaseManager; use think\facade\Config;/*** Class Upload* package crmeb\services\upload* …...
高效线程安全的单例模式:Python 中的懒加载与自定义初始化参数
高效线程安全的单例模式:Python 中的懒加载与自定义初始化参数 在软件开发中,单例模式(Singleton Pattern)是一种常见的设计模式,确保一个类仅有一个实例,并提供一个全局访问点。在多线程环境下,实现单例模式时需要注意线程安全问题,以防止多个线程同时创建实例,导致…...

回溯算法学习
一、电话号码的字母组合 import java.util.ArrayList; import java.util.List;import javax.management.loading.PrivateClassLoader;public class letterCombinations {private static final String[] KEYPAD {"", //0"", //1"abc", //2"…...
Java + Spring Boot + Mybatis 实现批量插入
在 Java 中使用 Spring Boot 和 MyBatis 实现批量插入可以通过以下步骤完成。这里提供两种常用方法:使用 MyBatis 的 <foreach> 标签和批处理模式(ExecutorType.BATCH)。 方法一:使用 XML 的 <foreach> 标签ÿ…...

RabbitMQ入门4.1.0版本(基于java、SpringBoot操作)
RabbitMQ 一、RabbitMQ概述 RabbitMQ RabbitMQ最初由LShift和CohesiveFT于2007年开发,后来由Pivotal Software Inc.(现为VMware子公司)接管。RabbitMQ 是一个开源的消息代理和队列服务器,用 Erlang 语言编写。广泛应用于各种分布…...