4 local success
= "<font color=green><strong>成功</strong></font><br>"
7 if r
=="raid0" then return "磁盘分块"
8 elseif r
== "raid1" then return "镜像冗余"
9 elseif r
== "raid5" then return "校验冗余"
10 elseif r
== "raid6" then return "双校验冗余"
11 elseif r
== "raid10" then return "分块镜像"
16 function display_current_raid()
17 local mdstat
= get_mdstat()
20 <form action = "volumes_create_raid.cgi" method = "post">
21 <table width=90%><tr><td>
22 <table cellspacing="1" cellpadding="5" border="0" width="100%">
24 <td bgcolor="#ebebeb" width=1%></td>
25 <td bgcolor="#ebebeb"><strong>Raid名称</strong></td>
26 <td bgcolor="#ebebeb"><strong>类型</strong></td>
27 <td bgcolor="#ebebeb"><strong>容量</strong></td>
28 <td bgcolor="#ebebeb"><strong>使用磁盘</strong></td>
33 for r
in pairs(mdstat
) do
34 local _td1
= string.format([[<tr bgcolor=#c6d5a8 align="left"><td>
35 <input type="radio" name="md" value="%s"></td><td>%s</td>]], r
,string.match(r
, "/dev/(%S+)"))
37 print("<td>"..raid_name(mdstat
[r
].level
).." ("..mdstat
[r
].level
..")</td>")
38 print("<td>"..mdstat
[r
].size
.."</td>")
39 print("<td>"..mdstat
[r
].devices
.."</td></tr>")
42 print([[</table></td></tr>
44 <input type="hidden" name=todo value="type">
45 <input type="submit" value="创建新阵列">
46 <input type="hidden" value="清除">
51 function display_create_raid()
53 <h3>Raid管理 - 选择Raid类型</h3>
54 <form name="select_raid" method="post" action="volumes_create_raid.cgi">
55 <table width=70%><tr><td>
56 <table cellspacing="1" cellpadding="5" border="0" width="100%">
58 <td bgcolor="#ebebeb" width=1%></td>
59 <td bgcolor="#ebebeb"><strong>Raid类型</strong></td>
60 <td bgcolor="#ebebeb"><strong>概述</strong></td>
61 <td bgcolor="#ebebeb"><strong>备注</strong></td></tr>
62 <tr class="color_table_row1"><td ><input type="radio" name="raidtype" value="0"></td>
63 <td>Raid0</td><td>磁盘分块</td><td>无冗余</td></tr>
64 <tr class="color_table_row2"><td><input type="radio" name="raidtype" value="1"></td>
65 <td>Raid1</td><td>镜像冗余</td><td></td></tr>
66 <tr class="color_table_row1"><td><input type="radio" name="raidtype" value="5"></td>
67 <td>Raid5</td><td>校验冗余</td><td>推荐</td></tr>
68 <tr class="color_table_row2"><td><input type="radio" name="raidtype" value="6"></td>
69 <td>Raid6</td><td>双校验冗余</td><td></td></tr>
70 <tr class="color_table_row1"><td><input type="radio" name="raidtype" value="10"></td>
71 <td>Raid10</td><td>分块镜像</td><td></td></tr>
73 <tr><td><input type="submit" value="选择"></td></tr></table>
74 <input type=hidden name="todo" value="disks">
79 function display_disks(qp
)
80 if not qp
.raidtype
then ui_message_err("没有选择Raid类型") return end
81 print("select: "..qp
.raidtype
)
82 local disks
= get_disks()
84 <h3>Raid管理 - 选择磁盘</h3>
85 <form name="select_raid" method="post" action="volumes_create_raid.cgi">
86 <table width=70%><tr><td>
87 <table cellspacing="1" cellpadding="5" border="0" width="100%">
89 <td bgcolor="#ebebeb" width=1%></td>
90 <td bgcolor="#ebebeb"><strong>磁盘编号</strong></td>
91 <td bgcolor="#ebebeb"><strong>容量</strong></td>
92 <td bgcolor="#ebebeb"><strong>型号</strong></td></tr>
96 for d
in pairs(disks
) do
97 if not disks
[d
].used
then
100 print([[<tr class="color_table_row]]..v
..[["><td><input type="checkbox"
101 name="dev_]]..i
..[[" value="]]..d
..[["></td><td>]]..i
..[[</td><td>]]..disks
[d
].size
..[[
102 </td><td>]]..disks
[d
].model
..[[</td></tr>]])
107 <tr><td><input type="submit" value="创建"> <input type="reset" value="清空"></td>
109 <input type=hidden name="todo" value="create">
110 <input type=hidden name="raidtype" value="]]..qp
.raidtype
..[[">
116 -- call mdadm to make a real raid and add to mdadm.conf
117 function make_raid(raid
)
119 local cmd
="sudo mdadm -C "..raid
.md
.." -l"..raid
.level
.." -n"..raid
.num
.." "..raid
.devices
.." -R"
120 local conf
="\nDEVICE "..raid
.devices
.."\nARRAY "..raid
.md
.." level=raid"..raid
.level
.." devices="..string.gsub(raid
.devices
,"%s+",",").."\n"
122 if raid
.spare
~= "" then cmd
=cmd
.." -x "..raid
.spare
end
123 for d
in string.gmatch(raid
.devices
, "(%S+)") do
124 if not do_disk(d
) then return end
127 print("正在创建磁盘阵列 ...")
128 err
, ret
= myexec(cmd
)
129 if ret
~= 0 then ui_message_err(err
) return nil else print(success
) end
131 mywrite("/etc/mdadm.conf", myread("/etc/mdadm.conf")..conf
)
134 function create_raid(qp
)
135 local raid
= {["devices"]="", ["num"]=0, ["level"] = -1, ["md"] = "", ["spare"]=""}
136 local mdstat
= get_mdstat()
138 if not qp
.raidtype
then ui_message_err("No raid type") return end
139 for k
,v
in pairs(qp
) do
140 if string.sub(k
,1,4) == "dev_" then
141 raid
.devices
= raid
.devices
.." "..qp
[k
]
142 raid
.num
= raid
.num
+ 1
145 if raid
.devices
== "" then ui_message_err("No devices") return end
146 raid
.level
= tonumber(qp
.raidtype
)
149 for md
in pairs(mdstat
) do
150 if "/dev/md"..i
~= md
then raid
.md
="/dev/md"..i
break end
152 if raid
.md
~= "" then break end
154 if not make_raid(raid
) then return nil end
158 ------------------- CGI OUTPUT ---------------------
159 local qp
= ui_getqp()
161 display_current_raid()
162 -- display_create_raid()
163 elseif qp
.todo
== "type" then
164 display_create_raid()
165 elseif qp
.todo
== "disks" then
167 elseif qp
.todo
== "create" then