mdada manage device

mdadm has 7 major modes of operation:

1) Create:

This mode is used to create a new array with a superblock. It can progress in several step create-add-add-run or it can all happen with one comman.

2) Assemble:

This mode is used to assemble the parts of a previously created array into an active array. Components can be explicitly given or can be searched for. mdadm (optionally) check that the components do form a bona-fide array, and can, on request, fiddle superblock version numbers so as to assemble a faulty array.

3) Build:

This is for building legacy arrays without superblocks

4) Manage

This is for doing something to one or more devices in an array, such as add,remove,fail. run/stop/readonly/readwrite are also available

5) Misc:

This is for doing things to individual devices. They might be parts of an array so zero-superblock, examine might be appropriate. They might be md arrays so run,stop,rw,ro,detail might be appropriate. Also query will treat it as either

6) Monitor

This mode never exits but just monitors arrays and reports changes.

7) Grow

This mode allows for changing of key attributes of a raid array, such as size, number of devices, and possibly even layout. At the time if writing, there is only minimal support.

2 the architecture of mdadm

这部分将从整体结构上给出mdadm的设计。在这个过程中,将按照mdadm的7个模式给出具体调用的过程。Mdadm的结构如下图:

Fig.1 The architecture of mdadm

从以上结构图可以看出,mdadm的设计具有典型的结构化程序设计风格。其整体结构建立在功能分解的基础之上,各个功能之间的依赖性比较小;在程序的入口点处控制程序各个功能模块的分支。对于mdadm这种规模的程序,这样的设计简洁、明快,并且在一定的程度上,扩展性相对较好。

2.1 Create mode

Create mode的功能是创建disk array(磁盘阵列)。可以有多种选择来创建磁盘阵列:可以先创建一个阵列,再添加硬盘;也可以用一个命令来完成这些操作。Mdadm对这样的几种方式都给予支持。

使用mdadm创建disk array的命令大致如下:

# mdadm -Cv /dev/md0 -l5 -n3 -x1 -c128 /dev/sd[b,c,d,e]1

命令中各参数分别表示如下作用:“-C”指创建一个新的阵列;“/dev/md0”表示阵列设备名称;“-l5”表示设置阵列模式(level),可以选择0、1、4、 5、6,它们分别对应于RAID0、RAID1、RAID4、RAID5、RAID6,这里设为RAID5模式;“-n3”指设置阵列中活动设备的数目,该数目加上备用设备的数目应等于阵列中的设备总数; “-x1”设置阵列中备用设备的数目,当前阵列中含有1个备用设备;“-c128”指设置块的尺寸为128KB,缺省为64KB;“/dev/sd[b, c,d,e]1”指当前阵列中包含的所有设备标识符,也可以分开来写,中间用空格分开,其中最后一个为备用设备。

Create的操作如何实现的呢?以下将从源代码的角度进行解释。

在mdadm的main函数中,首先分析处理命令行传进来的参数。分解完这些参数之后,分别在不同的mode的情况下,调用相应的函数来处理。具体到Create操作,首先调用mdopen.c中的open_mddev函数,如下:

if (mode==MANAGE || mode == BUILD || mode == CREATE || mode == GROW || (mode == ASSEMBLE && ! scan)) 
{
......
mdfd = open_mddev(devlist->devname, autof);
.....
}

Open_mddev函数打开给定的md设备,并且对其作相应的检查。Open_mddev函数的第二个参数autof,控制是否在给定的设备不存在地情况下,创建md设备或者重新创建这个设备。其实现如下:

if (autof) { 
/* autof is set, so we need to check that the name is ok, and possibly create one if not */
/*check name*/
/*if need to create one, we will frist get a major and minor number
/*get major and minor*/

/* If it was a 'standard' name and it is in-use, then the device could already be correct */
if (stb.st_mode && major(stb.st_rdev) == major && minor(stb.st_rdev) == minor);
else {
if (mknod(dev, S_IFBLK|0600, makedev(major, minor))!= 0)
/*do other things*/
}

通过以上操作得到md设备的设备描述符,用于以下的操作。

Create操作创建一个新的RAID array。其首先,检查所需要的信息是否提供,比如level,disk数量以及具体的disk等信息;然后检查每一块disk,读取相关信息,并且按照这些信息填充关于array信息的数据结构;最后,使用SET_ARRAY_INFO &ADD_NEW_DISK等ioctrl command,设置相关的信息,如果需要通过RUN_ARRAY ioctrl command启动这个array。

其中涉及到的主要的数据结构为在md_u.h中定义的struct mdu_array_info_s。这个struce中包含了md driver和用户态交互所用到的数据。其具体定义和解释如下:

typedef struct mdu_array_info_s {

int major_version;

int minor_version;

int patch_version; //主、次、patch版本号信息

int ctime;

int level;

int size;

int nr_disks; //子设备个数

int raid_disks; //成员个数

int md_minor; //RAID设备的次设备号

int not_persistent;

int utime; /* 0 Superblock update time */

int state; /* 1 State bits (clean, ...) */

int active_disks; /* 2 Number of currently active disks */

int working_disks; /* 3 Number of working disks */

int failed_disks; /* 4 Number of failed disks */

int spare_disks; /* 5 Number of spare disks */

int layout; /* 0 the array's physical layout */

int chunk_size; /* 1 chunk size in bytes */

} mdu_array_info_t;

其中,涉及到的信息和superblock中的表示相同,关于superblock的信息可以参考东海的TM《sofeware RAID superblock位置计算、信息的解析及应用》。

2.2 other mode

其他mode的实现和Create mode大致相同,均为通过命令行传进来的参数设置相应的数据结构,然后调用md driver提供的ioctrl command,来操纵md driver,从而实现相关状态的改变等。

这些模式的具体如何使用,可参见源文件中Readme.c文件中的相关信息,当然也可以使用mdadm的运行时帮助。以下摘录几个常用的功能:

# mdadm /dev/md0 -f /dev/sdb1 #将/dev/sdb1标记为已损坏的设备

# mdadm /dev/md0 -r /dev/sdb1 #移除损坏的设备

# mdadm /dev/md0 -a /dev/sdb1 #将新设备添加到阵列中

# mdadm -As /dev/md0 #启动阵列

# mdadm -S /dev/md0 #停止阵列

# mdadm -D /dev/md0 #显示阵列详细信息

3 extend mdadm

在讨论任何功能的时候,首先应该考虑的是其实现的必要性。在storage相关的项目中,暂时还没有涉及到扩展RAID功能的需求。如果这样的需求出现,那么扩展RAID的管理程序mdadm就是必须的了。在这里将讨论一下,扩展mdadm的可能性、难易程度以及扩展的方法。

从第2节对mdadm结构的分析可以看出,扩展mdadm只需要在其集中控制程序模块分支的地方,添加适当地分支,并且实现相应的模块就是可以的。添加分支后的程序结构大致如下:

Fig.1 The architecture of extended mdadm

可以看出,扩展后的mdadm,结构和扩展前大致相同。这样的扩展在一定地复杂度是可以接受的。

相对来说,扩展mdadm不是很复杂;其复杂性主要体现在对从命令行传进来的参数的解析。这部分可以依照mdadm原来的程序逻辑来进行,但是这样的添加容易出现问题(因为其涉及到对一个逻辑块的多处修改),并且在出现问题时不易分析。但是,对于增加一两个mode而言,这样做是比较简单的。

归根结底,扩展RAID功能的复杂性,体现在扩展RAID驱动上。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值