3 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
6 # convert an lmc batch file to a csv file for lustre_config
8 use strict; use warnings;
15 for (my $i = 0; $i <= $#$aref; $i++) {
16 if ($$aref[$i] eq "--" . $arg) {
17 my @foo = splice(@$aref, $i, 2);
27 for (my $i = 0; $i <= $#$aref; $i++) {
28 if ($$aref[$i] eq "--" . $arg) {
29 splice(@$aref, $i, 1);
39 $net->{"node"} = get_arg_val("node", \@_);
40 $net->{"nid"} = get_arg_val("nid", \@_);
41 $net->{"nettype"} = get_arg_val("nettype", \@_);
42 $net->{"port"} = get_arg_val("port", \@_);
43 # note that this is not standard lmc syntax. it's an extension to it
44 # to handle something that lmc never had to deal with.
45 $net->{"iface"} = get_arg_val("iface", \@_);
47 print STDERR "Unknown arguments to \"--add net\": @_\n";
55 $mds->{"node"} = get_arg_val("node", \@_);
56 $mds->{"name"} = get_arg_val("mds", \@_);
57 $mds->{"fstype"} = get_arg_val("fstype", \@_);
58 $mds->{"dev"} = get_arg_val("dev", \@_);
59 $mds->{"size"} = get_arg_val("size", \@_);
60 $mds->{"lmv"} = get_arg_val("lmv", \@_);
61 $mds->{"failover"} = get_arg("failover", \@_);
62 $mds->{"failout"} = get_arg("failout", \@_);
63 $mds->{"inode_size"} = get_arg_val("inode_size", \@_);
65 print STDERR "Unknown arguments to \"--add mds\": @_\n";
73 $lov->{"name"} = get_arg_val("lov", \@_);
74 $lov->{"mds"} = get_arg_val("mds", \@_);
75 $lov->{"lmv"} = get_arg_val("lmv", \@_);
76 $lov->{"stripe_sz"} = get_arg_val("stripe_sz", \@_);
77 $lov->{"stripe_cnt"} = get_arg_val("stripe_cnt", \@_);
78 $lov->{"stripe_pattern"} = get_arg_val("stripe_pattern", \@_);
80 print STDERR "Unknown arguments to \"--add lov\": @_\n";
88 $ost->{"node"} = get_arg_val("node", \@_);
89 $ost->{"name"} = get_arg_val("ost", \@_);
90 $ost->{"fstype"} = get_arg_val("fstype", \@_);
91 $ost->{"dev"} = get_arg_val("dev", \@_);
92 $ost->{"size"} = get_arg_val("size", \@_);
93 $ost->{"lov"} = get_arg_val("lov", \@_);
94 $ost->{"mountfsoptions"} = get_arg_val("mountfsoptions", \@_);
95 $ost->{"failover"} = get_arg("failover", \@_);
96 $ost->{"failout"} = get_arg("failout", \@_);
97 $ost->{"inode_size"} = get_arg_val("inode_size", \@_);
99 print STDERR "Unknown arguments to \"--add ost\": @_\n";
107 $mtpt->{"node"} = get_arg_val("node", \@_);
108 $mtpt->{"path"} = get_arg_val("path", \@_);
109 $mtpt->{"mds"} = get_arg_val("mds", \@_);
110 $mtpt->{"lov"} = get_arg_val("lov", \@_);
111 $mtpt->{"lmv"} = get_arg_val("lmv", \@_);
113 print STDERR "Unknown arguments to \"--add mtpt\": @_\n";
128 foreach my $obj (@objs) {
129 if (defined($obj->{$key}) && defined($value)
130 && $obj->{$key} eq $value) {
131 push(@found_objs, $obj);
141 my $networks = $net->{"nettype"};
142 if (defined($net->{"iface"})) {
143 my $iface = $net->{"iface"};
144 $networks .= "($iface)";
146 my $options_str = "options lnet networks=" . $networks .
148 if (defined($net->{"port"})) {
149 $options_str .= " accept_port=" . $net->{"port"};
160 my $MOUNTPT = "/mnt";
161 if (defined($ENV{"MOUNTPT"})) {
162 $MOUNTPT = $ENV{"MOUNTPT"};
168 for (my $i = 0; $i <= $#args; $i++) {
169 if ($args[$i] eq "--add") {
170 my $type = "$args[$i + 1]";
171 my $subref = "add_$type";
172 splice(@args, $i, 2);
173 push(@{$objs{$type}}, &$subref(@args));
177 print STDERR "I don't know how to handle @args\n";
184 foreach my $lov (@{$objs{"lov"}}) {
185 foreach my $mds (find_objs("mds", "name", $lov->{"mds"}, @{$objs{"mds"}})) {
187 $mds->{"lov"} = $lov;
190 # try via lmvs as well
191 foreach my $mds (find_objs("mds", "lmv", $lov->{"lmv"}, @{$objs{"mds"}})) {
193 $mds->{"lov"} = $lov;
198 # create lmvs and link them to mdses
199 foreach my $mds (@{$objs{"mds"}}) {
201 my @lmvs = find_objs("lmv", "name", $mds->{"lmv"}, @{$objs{"lmv"}});
204 $lmv->{"name"} = $mds->{"lmv"};
205 push(@{$objs{"lmv"}}, $lmv);
209 $mds->{"lmv"} = $lmv;
212 # link mtpts to lovs and lmvs or mdses
213 foreach my $mtpt (@{$objs{"mtpt"}}) {
214 foreach my $mds (find_objs("mds", "name", $mtpt->{"mds"}, @{$objs{"mds"}})) {
216 $mds->{"mtpt"} = $mtpt;
219 foreach my $lmv (find_objs("lmv", "name", $mtpt->{"lmv"}, @{$objs{"lmv"}})) {
221 $lmv->{"mtpt"} = $mtpt;
224 foreach my $lov (find_objs("lov", "name", $mtpt->{"lov"}, @{$objs{"lov"}})) {
226 $lov->{"mtpt"} = $mtpt;
231 # XXX could find failover pairs of osts and mdts here and link them to
232 # one another and then fill in their details in the csv generators below
234 foreach my $mds (@{$objs{"mds"}}) {
235 # find the net for this node
236 my @nets = find_objs("net", "node", $mds->{"node"}, @{$objs{"net"}});
237 my $lmv = $mds->{"lmv"};
238 my $lov = $mds->{"lov"};
241 $mtpt = $mds->{"lmv"}->{"mtpt"};
243 $mtpt = $mds->{"mtpt"};
246 if (defined($lov->{"stripe_sz"})) {
247 $fmt_options .= "lov.stripesize=" . $lov->{"stripe_sz"} . " ";
249 if (defined($lov->{"stripe_cnt"})) {
250 $fmt_options .= "lov.stripecount=" . $lov->{"stripe_cnt"} . " ";
252 if (defined($lov->{"stripe_pattern"})) {
253 $fmt_options .= "lov.stripetype=" . $lov->{"stripe_pattern"} . " ";
255 if (defined($mds->{"failover"}) & $mds->{"failover"}) {
256 $fmt_options .= "failover.mode=failover" . " ";
258 if (defined($mds->{"failout"}) & $mds->{"failout"}) {
259 $fmt_options .= "failover.mode=failout" . " ";
262 if ($fmt_options ne "") {
263 $fmt_options = " --param=\"$fmt_options\"";
267 if (defined($mds->{"inode_size"})) {
268 $mkfs_options .= "-I " . $mds->{"inode_size"} . " ";
273 my $mount_point = "$MOUNTPT/" . $mds->{"name"};
274 if (defined($mtpt->{"node"})) {
275 $fs_name = $mtpt->{"node"};
276 $mount_point .= "_" . $mtpt->{"node"};
281 printf "%s,%s,%s,%s,mgs|mdt,%s,,,--device-size=%s --noformat%s,%s,\n",
283 lnet_options($nets[0]),
291 push(@mgses, $nets[0]->{"nid"});
294 printf "%s,%s,%s,%s,mdt,%s,\"%s\",,--device-size=%s --noformat%s,%s,\n",
296 lnet_options($nets[0]),
308 foreach my $ost (@{$objs{"ost"}}) {
310 if (defined($ost->{"mountfsoptions"})) {
311 $mount_opts .= "\"" . $ost->{"mountfsoptions"} . "\"";
314 if (defined($ost->{"failover"}) & $ost->{"failover"}) {
315 $fmt_options .= "failover.mode=failover" . " ";
317 if (defined($ost->{"failout"}) & $ost->{"failout"}) {
318 $fmt_options .= "failover.mode=failout" . " ";
321 if ($fmt_options ne "") {
322 $fmt_options = " --param=\"$fmt_options\"";
326 if (defined($ost->{"inode_size"})) {
327 $mkfs_options .= "-I " . $ost->{"inode_size"} . " ";
331 $ost->{"lov"} = (find_objs("lov", "name", $ost->{"lov"}, @{$objs{"lov"}}))[0];
333 my $mount_point = "$MOUNTPT/" . $ost->{"name"},
334 my $mtpt = $ost->{"lov"}->{"mtpt"};
335 if (defined($mtpt->{"node"})) {
336 $fs_name = $mtpt->{"node"};
337 $mount_point .= "_" . $mtpt->{"node"};
339 # find the net for this node
340 my @nets = find_objs("net", "node", $ost->{"node"}, @{$objs{"net"}});
341 printf "%s,%s,%s,%s,ost,%s,\"%s\",,--device-size=%s --noformat%s,%s,%s\n",
343 lnet_options($nets[0]),