Whamcloud - gitweb
The start of a script to convert lmc "batch" specifications to the CSV
authorbrian <brian>
Wed, 14 Jun 2006 22:03:42 +0000 (22:03 +0000)
committerbrian <brian>
Wed, 14 Jun 2006 22:03:42 +0000 (22:03 +0000)
format used by the lustre_config.sh script to configure lustre.
The number of lmc options the script understands currently seems to cover
ltest's lmc batch generation.
This is the "cheap way" to get ltest to do mountconf and be able to do full
testing on b1_5 and has the added benefit of testing the lustre_config.sh
scripts while it's at it.
Note, that arguably we should be parsing the XML, not lmc batch commands.
Fortunately the way the script works, changing out parsing of lmc commands
for parsing XML is easy to do and will still work with the backend CSV
generation.

lustre/scripts/lmc2csv.pl [new file with mode: 0644]

diff --git a/lustre/scripts/lmc2csv.pl b/lustre/scripts/lmc2csv.pl
new file mode 100644 (file)
index 0000000..b046928
--- /dev/null
@@ -0,0 +1,205 @@
+#!/usr/bin/perl
+
+# vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
+
+#
+# convert an lmc batch file to a csv file for lustre_config.sh
+#
+use strict; use warnings;
+
+use Data::Dumper;
+
+sub get_arg_val {
+    my $arg = shift;
+    my ($aref) = @_;
+    for (my $i = 0; $i <= $#$aref; $i++) {
+        if ($$aref[$i] eq "--" . $arg) {
+            my @foo = splice(@$aref, $i, 2);
+            return $foo[1];
+        }
+    }
+}
+
+sub get_arg {
+    my $arg = shift;
+    my ($aref) = @_;
+    for (my $i = 0; $i <= $#$aref; $i++) {
+        if ($$aref[$i] eq "--" . $arg) {
+            splice(@$aref, $i, 1);
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+sub add_net {
+    my $net = {};
+    $net->{"node"} = get_arg_val("node", \@_);
+    $net->{"nid"} = get_arg_val("nid", \@_);
+    $net->{"nettype"} = get_arg_val("nettype", \@_);
+    $net->{"port"} = get_arg_val("port", \@_);
+    if ($#_ > 0) {
+        print STDERR "Unknown arguments to \"--add net\": @_\n";
+        exit(1);
+    }
+    return $net;
+}
+
+sub add_mds {
+    my $mds = {};
+    $mds->{"node"} = get_arg_val("node", \@_);
+    $mds->{"mds"} = get_arg_val("mds", \@_);
+    $mds->{"fstype"} = get_arg_val("fstype", \@_);
+    $mds->{"dev"} = get_arg_val("dev", \@_);
+    $mds->{"size"} = get_arg_val("size", \@_);
+    if ($#_ > 0) {
+        print STDERR "Unknown arguments to \"--add mds\": @_\n";
+        exit(1);
+    }
+    return $mds;
+}
+
+sub add_lov {
+    my $lov = {};
+    $lov->{"lov"} = get_arg_val("lov", \@_);
+    $lov->{"mds"} = get_arg_val("mds", \@_);
+    $lov->{"stripe_sz"} = get_arg_val("stripe_sz", \@_);
+    $lov->{"stripe_cnt"} = get_arg_val("stripe_cnt", \@_);
+    $lov->{"stripe_pattern"} = get_arg_val("stripe_pattern", \@_);
+    if ($#_ > 0) {
+        print STDERR "Unknown arguments to \"--add lov\": @_\n";
+        exit(1);
+    }
+    return $lov;
+}
+
+sub add_ost {
+    my $ost = {};
+    $ost->{"node"} = get_arg_val("node", \@_);
+    $ost->{"ost"} = get_arg_val("ost", \@_);
+    $ost->{"fstype"} = get_arg_val("fstype", \@_);
+    $ost->{"dev"} = get_arg_val("dev", \@_);
+    $ost->{"size"} = get_arg_val("size", \@_);
+    $ost->{"lov"} = get_arg_val("lov", \@_);
+    $ost->{"mountfsoptions"} = get_arg_val("mountfsoptions", \@_);
+    $ost->{"failover"} = get_arg("failover", \@_);
+    if ($#_ > 0) {
+        print STDERR "Unknown arguments to \"--add ost\": @_\n";
+        exit(1);
+    }
+    return $ost;
+}
+
+sub add_mtpt {
+    my $mtpt = {};
+    $mtpt->{"node"} = get_arg_val("node", \@_);
+    $mtpt->{"path"} = get_arg_val("path", \@_);
+    $mtpt->{"mds"} = get_arg_val("mds", \@_);
+    $mtpt->{"lov"} = get_arg_val("lov", \@_);
+    if ($#_ > 0) {
+        print STDERR "Unknown arguments to \"--add mtpt\": @_\n";
+        exit(1);
+    }
+    return $mtpt;
+}
+
+no strict 'refs';
+
+sub find_obj {
+    my $type = shift;
+    my $key = shift;
+    my $value = shift;
+    my @objs = @_;
+
+    foreach my $obj (@objs) {
+        if ($obj->{$key} eq $value) {
+            return $obj;
+        }
+    }
+}
+
+sub lnet_options {
+    my $net = shift;
+
+    my $options_str = "options lnet networks=" . $net->{"nettype"} .
+                   " accept=all";
+    if (defined($net->{"port"})) {
+        $options_str .= " accept_port=" . $net->{"port"};
+    }
+    return $options_str;
+
+}
+
+sub main {
+    my %objs;
+    my @mgses;
+
+    while(<>) {
+        my @args = split;
+
+        for (my $i = 0; $i <= $#args; $i++) {
+            if ($args[$i] eq "--add") {
+                my $type = "$args[$i + 1]";
+                my $subref = "add_$type";
+                splice(@args, $i, 2);
+                push(@{$objs{$type}}, &$subref(@args));
+                last;
+            }
+            if ($i == $#args) {
+                print STDERR "I don't know how to handle @args\n";
+                exit(1);
+            }
+        }
+    }
+
+    # link lovs to mdses
+    foreach my $lov (@{$objs{"lov"}}) {
+        my $mds = find_obj("mds", "mds", $lov->{"mds"}, @{$objs{"mds"}});
+        $mds->{"lov"} = $lov;
+    }
+    # XXX could find failover pairs of osts and mdts here and link them to
+    # one another and then fill in their details in the csv generators below
+    foreach my $mds (@{$objs{"mds"}}) {
+        # find the net for this node
+        my $net = find_obj("net", "node", $mds->{"node"}, @{$objs{"net"}});
+        my $lov = $mds->{"lov"};
+        my $mkfs_options="";
+        if (defined($lov->{"stripe_sz"})) {
+            $mkfs_options .= "default_stripe_size=" . $lov->{"stripe_sz"} . ",";
+        }
+        if (defined($lov->{"stripe_cnt"})) {
+            $mkfs_options .= "default_stripe_count=" .
+                             $lov->{"stripe_cnt"} . ",";
+        }
+        if (defined($lov->{"stripe_pattern"})) {
+            $mkfs_options .= "default_stripe_pattern=" .
+                             $lov->{"stripe_pattern"} . ",";
+        }
+        chop($mkfs_options);
+
+        printf "%s,%s,%s,/mnt/%s,mgs|mdt,,,,--device-size=%s,\"%s\"\n", 
+            $mds->{"node"},
+            lnet_options($net),
+            $mds->{"dev"},
+            $mds->{"mds"},
+            $mds->{"size"},
+            $mkfs_options;
+        push(@mgses, $net->{"nid"});
+    }
+
+    foreach my $ost (@{$objs{"ost"}}) {
+        # find the net for this node
+        my $net = find_obj("net", "node", $ost->{"node"}, @{$objs{"net"}});
+        printf "%s,%s,%s,/mnt/%s,ost,,\"%s\",,--device-size=%s,\"%s\"\n", 
+        $ost->{"node"},
+        lnet_options($net),
+        $ost->{"dev"},
+        $ost->{"ost"},
+        join(",", @mgses),
+        $ost->{"size"},
+        $ost->{"mountfsoptions"};
+    }
+}
+
+&main;