软raid v0.9元数据存放区域计算

也许可以从函数load_super0查一查0.9从什么区域读取的超级块信息。

c 复制代码
|- get_dev_size(fd, devname, &dsize);	// 获取磁盘size
	|- ioctl(fd, BLKGETSIZE64, &ldsize);	// 发送一个ioctl给磁盘获取size。
|- offset = MD_NEW_SIZE_SECTORS(dsize>>9);	// 获取扇区偏移。
c 复制代码
// md_p.h
/*
 * RAID superblock.
 *
 * The RAID superblock maintains some statistics on each RAID configuration.
 * Each real device in the RAID set contains it near the end of the device.
 * Some of the ideas are copied from the ext2fs implementation.
 *
 * We currently use 4096 bytes as follows:
 *
 *	word offset	function
 *
 *	   0  -    31	Constant generic RAID device information.
 *    32  -    63   Generic state information.
 *	  64  -   127	Personality specific information.
 *	 128  -   511	12 32-words descriptors of the disks in the raid set.
 *	 512  -   911	Reserved.
 *	 912  -  1023	Disk specific descriptor.
 */

/*
 * If x is the real device size in bytes, we return an apparent size of:
 *
 *	y = (x & ~(MD_RESERVED_BYTES - 1)) - MD_RESERVED_BYTES
 *
 * and place the 4kB superblock at offset y.
 */
#define MD_RESERVED_BYTES		(64 * 1024)
#define MD_RESERVED_SECTORS		(MD_RESERVED_BYTES / 512)
#define MD_RESERVED_BLOCKS		(MD_RESERVED_BYTES / BLOCK_SIZE)

#define MD_NEW_SIZE_SECTORS(x)		((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS)
#define MD_NEW_SIZE_BLOCKS(x)		((x & ~(MD_RESERVED_BLOCKS - 1)) - MD_RESERVED_BLOCKS)

所以需要研究下元数据存放位置的计算方式?

假设设备的磁盘大小为10G,换算成字节10 * 1024 * 1024 * 1024 = 10737418240Byte,用来被保存raid superblock的总大小为64KB。

宏MD_NEW_SIZE_SECTORS用来计算元数据存放的扇区位置,传参为磁盘的扇区数x,如果磁盘大小为10G,磁盘扇区数为20971520个扇区。

MD_RESERVED_SECTORS大小为128个sectors。

(20971520- & ~(127)) - 128 = 209713921010000000000000000000000 & 0000000 - 128 = 20971392,对于磁盘大小为10G的磁盘来讲,刚好保留了最后64K用来存放软raid元数据,当然也包括bitmap相关信息。

~127的目的是为了将20971520低七位清零,形成一种64K对齐的效果,对齐之后取最后一个64KB作为元数据的存放区域,对于磁盘非64K对齐的区域软raid不进行管理。

相关推荐
不怕犯错,就怕不做7 小时前
RK3562的CPU如何降频及关闭硬件编解码
linux·驱动开发·嵌入式硬件
CoderMeijun7 小时前
Linux 文件操作详解:open/read/write/lseek 系统调用
linux·文件操作·系统调用·open·文件描述符
可可西里_X_back7 小时前
Linux学习(二)- 驱动开发步骤
linux·驱动开发·学习
Hical_W8 小时前
Hical 踩坑实录五部曲(二):MSVC / GCC / Clang 三平台 C++20 编译差异
linux·windows·经验分享·嵌入式硬件·macos·开源·c++20
活蹦乱跳酸菜鱼8 小时前
linux ATF BL2执行过程
linux
淡淡烟雨淡淡愁10 小时前
安装libreoffice
linux
蜀道山老天师10 小时前
云原生监控入门:监控基础概念 + SLI/SLO/SLA 详解 + Prometheus 从零安装配置
linux·运维·云原生·prometheus
AIDF202610 小时前
linux 服务器网络问题排查
linux·服务器·网络
楼兰公子10 小时前
br_opi5_plus_defconfig 附带uboot
linux·运维·服务器
mzhan01711 小时前
Linux: signal: SIGALRM; alarm: ITIMER_REAL
linux·运维·服务器