Whamcloud - gitweb
Allow the default stripe_count to be specified in the XML config, and also
[fs/lustre-release.git] / lustre / utils / lconf
index 2133794..9138a4d 100755 (executable)
@@ -46,7 +46,7 @@ def usage():
 config.xml          Lustre configuration in xml format.
 --get <url>         URL to fetch a config file
 --node <nodename>   Load config for <nodename>
--d | --cleanup     Cleans up config. (Shutdown)
+-d | --cleanup      Cleans up config. (Shutdown)
 -v | --verbose      Print system commands as they are run
 -h | --help         Print this help 
 --gdb               Prints message after creating gdb module script
@@ -56,10 +56,10 @@ config.xml          Lustre configuration in xml format.
                     config file is doing what it should be doing. (Implies -v)
 --nomod             Skip load/unload module step.
 --nosetup           Skip device setup/cleanup step.
---reformat         Reformat all devices (without question)
+--reformat          Reformat all devices (without question)
 """
     TODO = """
---ldap server      LDAP server with lustre config database
+--ldap server       LDAP server with lustre config database
 --makeldiff         Translate xml source to LDIFF 
 This are perhaps not needed:
 --lustre="src dir"  Base directory of lustre sources. Used to search
@@ -307,6 +307,15 @@ class LCTLInterface:
   quit """ % (net, uuid, tgt, gw, tgt)
         self.run(cmds)
 
+    # add a route to a range
+    def del_route_host(self, net, uuid, gw, tgt):
+        cmds =  """
+  network %s
+  del_uuid %s
+  del_route %s
+  quit  """ % (net, uuid, tgt)
+        self.run(cmds)
+
     # disconnect one connection
     def disconnect(self, net, nid, port, servuuid):
         cmds =  """
@@ -488,7 +497,7 @@ def init_loop(file, size, fstype):
     if dev:
         print 'WARNING file:', file, 'already mapped to', dev
         return dev
-    if not os.access(file, os.R_OK | os.W_OK):
+    if config.reformat()  or not os.access(file, os.R_OK | os.W_OK):
         run("dd if=/dev/zero bs=1k count=0 seek=%d of=%s" %(size,  file))
     loop = loop_base()
     # find next free loop
@@ -534,13 +543,27 @@ def block_dev(dev, size, fstype, format):
         
     return dev
 
-def get_local_address(net_type):
+def if2addr(iface):
+    """lookup IP address for an interface"""
+    rc, out = run("/sbin/ifconfig", iface)
+    if rc or not out:
+       return None
+    addr = string.split(out[1])[1]
+    ip = string.split(addr, ':')[1]
+    return ip
+
+def get_local_address(net_type, wildcard):
     """Return the local address for the network type."""
     local = ""
     if net_type == 'tcp':
-        # host `hostname`
-        host = socket.gethostname()
-        local = socket.gethostbyname(host)
+        if  ':' in wildcard:
+            iface, star = string.split(wildcard, ':')
+            local = if2addr(iface)
+            if not local:
+                panic ("unable to determine ip for:", wildcard)
+        else:
+            host = socket.gethostname()
+            local = socket.gethostbyname(host)
     elif net_type == 'elan':
         # awk '/NodeId/ { print $2 }' '/proc/elan/device0/position'
         try:
@@ -584,6 +607,8 @@ class Module:
     def lookup_server(self, srv_uuid):
         """ Lookup a server's network information """
         net = get_ost_net(self.dom_node.parentNode, srv_uuid)
+        if not net:
+            panic ("Unable to find a server for:", srv_uuid)
         self._server = Network(net)
 
     def get_server(self):
@@ -665,14 +690,15 @@ class Network(Module):
         self.port = get_text_int(dom_node, 'port', 0)
         self.send_mem = get_text_int(dom_node, 'send_mem', DEFAULT_TCPBUF)
         self.recv_mem = get_text_int(dom_node, 'recv_mem', DEFAULT_TCPBUF)
-        if self.nid == '*':
-            self.nid = get_local_address(self.net_type)
+        if '*' in self.nid:
+            self.nid = get_local_address(self.net_type, self.nid)
             if not self.nid:
-                panic("unable to set nid for", self.net_type)
+                panic("unable to set nid for", self.net_type, self.nid)
+            debug("nid:", self.nid)
 
         self.add_module('portals/linux/oslib/', 'portals')
-       if node_needs_router():
-           self.add_module('portals/linux/router', 'kptlrouter')
+        if node_needs_router():
+            self.add_module('portals/linux/router', 'kptlrouter')
         if self.net_type == 'tcp':
             self.add_module('portals/linux/socknal', 'ksocknal')
         if self.net_type == 'elan':
@@ -685,9 +711,9 @@ class Network(Module):
     def prepare(self):
         self.info(self.net_type, self.nid, self.port)
         if self.net_type == 'tcp':
-            ret = run_daemon(TCP_ACCEPTOR, '-s', self.send_mem, '-r', self.recv_mem, self.port)
+            ret, out = run(TCP_ACCEPTOR, '-s', self.send_mem, '-r', self.recv_mem, self.port)
             if ret:
-                raise CommandError(TCP_ACCEPTOR, 'failed', ret)
+                raise CommandError(TCP_ACCEPTOR, out, ret)
         ret = self.dom_node.getElementsByTagName('route_tbl')
         for a in ret:
             for r in a.getElementsByTagName('route'):
@@ -719,14 +745,14 @@ class Network(Module):
                     if not srv:
                         panic("no server for nid", lo)
                     else:
-                       try:
+                        try:
                             lctl.disconnect(srv.net_type, srv.nid, srv.port, srv.uuid)
-                       except CommandError, e:
-                               print "disconnect failed: ", self.name
-                               e.dump()
-               try:
+                        except CommandError, e:
+                            print "disconnect failed: ", self.name
+                            e.dump()
+                try:
                     lctl.del_route(self.net_type, self.nid, lo, hi)
-               except CommandError, e:
+                except CommandError, e:
                     print "del_route failed: ", self.name
                     e.dump()
               
@@ -766,7 +792,7 @@ class LOV(Module):
             self.stripe_off = get_attr_int(dev_node, 'stripeoffset', 0)
             self.pattern = get_attr_int(dev_node, 'pattern', 0)
             self.devlist = get_all_refs(dev_node, 'osc')
-            self.stripe_cnt = len(self.devlist)
+            self.stripe_cnt = get_attr_int(dev_node, 'stripecount', len(self.devlist))
         self.add_module('lustre/mdc', 'mdc')
         self.add_module('lustre/lov', 'lov')
 
@@ -779,8 +805,8 @@ class LOV(Module):
             else:
                 panic('osc not found:', osc_uuid)
         mdc_uuid = prepare_mdc(self.dom_node.parentNode, self.mds_uuid)
-        self.info(self.mds_uuid, self.stripe_cnt, self.stripe_sz, self.stripe_off, self.pattern,
-        self.devlist, self.mds_name)
+        self.info(self.mds_uuid, self.stripe_cnt, self.stripe_sz,
+                  self.stripe_off, self.pattern, self.devlist, self.mds_name)
         lctl.newdev(attach="lov %s %s" % (self.name, self.uuid),
                     setup ="%s" % (mdc_uuid))
 
@@ -960,6 +986,17 @@ class OSC(Module):
         lctl.newdev(attach="osc %s %s" % (self.name, self.uuid),
                     setup ="%s %s" %(self.obd_uuid, srv.uuid))
 
+    def cleanup(self):
+        srv = self.get_server()
+        if local_net(srv):
+            Module.cleanup(self)
+        else:
+            self.info(self.obd_uuid, self.ost_uuid)
+            r =  find_route(srv)
+            if r:
+                lctl.del_route_host(r[0], srv.uuid, r[1], r[2])
+            Module.cleanup(self)
+            
 
 class Mountpoint(Module):
     def __init__(self,dom_node):
@@ -1234,7 +1271,7 @@ def init_route_config(lustre):
     list = lustre.getElementsByTagName('node')
     for node in list:
         if get_attr(node, 'router'):
-           router_flag = 1
+            router_flag = 1
             for (local_type, local_nid) in local_node:
                 gw = None
                 netlist = node.getElementsByTagName('network')
@@ -1353,8 +1390,8 @@ def doHost(lustreNode, hosts):
         init_node(dom_node)
         init_route_config(lustreNode)
     else:
-       global router_flag 
-       router_flag = 1
+        global router_flag 
+        router_flag = 1
 
     # Two step process: (1) load modules, (2) setup lustre
     # if not cleaning, load modules first.