Whamcloud - gitweb
* support for toenal
[fs/lustre-release.git] / lustre / utils / lmc
index d280452..6f34b2b 100755 (executable)
@@ -64,7 +64,7 @@ Commands:
    specifies the node to modify.
 
 --net hostname nettype [port, recv_buf, send_buf]
-   Nettype is either tcp, elan, or gm.
+   Nettype is either tcp, toe, elan, or gm.
    Requires --node
 
 --route net gw lo [hi]
@@ -78,19 +78,16 @@ Commands:
    Create a MDS using the device
    Requires --node 
 
---lov lov_name [mdc_name stripe_sz stripe_off pattern]
+--lov lov_name [mds_name stripe_sz sub_stripe_count pattern]
    Creates a logical volume
    When used with other commands, it specifics the lov to modify
 
---mdc mdc_name
-   Configures a MDC for a node.
-   Requires --node 
-
 --ost device [size]
    Creates an OBD/OST/OSC configuration triplet for a new device.
    When used on "host", the device will be initialized and the OST
    will be enabled. On client nodes, the OSC will be avaiable.
    Requires --node
+   Optional --obduuid Specifies the UUID used for the obd. 
    If --lov lov_name is used, this device is added to lov. 
 
 --mtpt /mnt/point mds_name lov_name|osc_name 
@@ -100,6 +97,9 @@ Commands:
 Options:
 --merge="xml file"  Add the new objects to an existing file
 --format            Format the partitions if unformated
+                    NB: The autoformat option has been disabled until a safe
+                    method is implemented to determine if a block device has a
+                    filesystem.
 --reformat          Reformat partitions (this should be an lconf arg,
                     I think)
 --obdtype="obdtype" Specifiy obdtype: valid ones are obdecho and obdfilter.
@@ -110,9 +110,13 @@ Options:
 
 def error(*args):
     msg = string.join(map(str,args))
-    print msg
+    print "Error: ", msg
     sys.exit(1)
     
+def warning(*args):
+    msg = string.join(map(str,args))
+    print "Warning: ", msg
+    
 #
 # manage names and uuids
 # need to initialize this by walking tree to ensure
@@ -138,7 +142,6 @@ def new_lustre(dom):
     # adding ldlm here is a bit of a hack, but one is enough.
     str = """<lustre>
     <ldlm name="%s" uuid="%s"/>
-    <ptlrouter name="PTLROUTER" uuid="PTLROUTER_UUID"/>
     </lustre>""" % (ldlm_name, ldlm_uuid)
     return dom.parseString(str)
 
@@ -198,18 +201,24 @@ class GenConfig:
         node.appendChild(new)
         return new
 
-    def network(self, name, uuid, hostname, net, port=0):
+    def network(self, name, uuid, hostname, net, port=0, tcpbuf=0):
         """create <network> node"""
         network = self.newService("network", name, uuid)
         network.setAttribute("type", net);
         self.addElement(network, "server", hostname)
         if port:
             self.addElement(network, "port", "%d" %(port))
+        if tcpbuf:
+            self.addElement(network, "send_mem", "%d" %(tcpbuf))
+            self.addElement(network, "recv_mem", "%d" %(tcpbuf))
+            
         return network
 
-    def route(self, lo, hi):
+    def route(self, net_type, gw, lo, hi):
         """ create one entry for the route table """
         ref = self.doc.createElement('route')
+        ref.setAttribute("type", net_type)
+        ref.setAttribute("gw", gw)
         ref.setAttribute("lo", lo)
         if hi:
             ref.setAttribute("hi", hi)
@@ -250,15 +259,20 @@ class GenConfig:
         ost.appendChild(self.ref("obd", obd_uuid))
         return ost
 
-    def lov(self, name, uuid, mds_uuid, stripe_sz, stripe_off, pattern):
+    def lov(self, name, uuid, mds_uuid, stripe_sz, stripe_count, pattern):
         lov = self.newService("lov", name, uuid)
         lov.appendChild(self.ref("mds", mds_uuid))
         devs = self.addElement(lov, "devices" )
         devs.setAttribute("stripesize", stripe_sz)
-        devs.setAttribute("stripeoffset", stripe_off)
+        devs.setAttribute("stripecount", stripe_count)
         devs.setAttribute("pattern", pattern)
         return lov
 
+    def lovconfig(self, name, uuid, lov_uuid):
+        lovconfig = self.newService("lovconfig", name, uuid)
+        lovconfig.appendChild(self.ref("lov", lov_uuid))
+        return lovconfig
+
     def mds(self, name, uuid, fs, devname, format, net_uuid, node_uuid,
             failover_uuid = "", dev_size=0 ):
         mds = self.newService("mds", name, uuid)
@@ -273,14 +287,9 @@ class GenConfig:
             mds.appendChild(self.ref("failover", failover_uuid))
         return mds
 
-    def mdc(self, name, uuid, mds_uuid):
-        mdc = self.newService("mdc", name, uuid)
-        mdc.appendChild(self.ref("mds", mds_uuid))
-        return mdc
-
-    def mountpoint(self, name, uuid, mdc_uuid, osc_uuid, path):
+    def mountpoint(self, name, uuid, mds_uuid, osc_uuid, path):
         mtpt = self.newService("mountpoint", name, uuid)
-        mtpt.appendChild(self.ref("mdc", mdc_uuid))
+        mtpt.appendChild(self.ref("mds", mds_uuid))
         mtpt.appendChild(self.ref("osc", osc_uuid))
         self.addElement(mtpt, "path", path)
         return mtpt
@@ -325,11 +334,11 @@ def mds2node(lustre, mds_name):
     mds = findByName(lustre, mds_name, 'mds')
     ref = mds.getElementsByTagName('node_ref')
     if not ref:
-        error("no node found for:", mds_name)
+        error("mds2node:", "no node_ref found for", '"'+mds_name+'"')
     node_uuid = ref[0].getAttribute('uuidref')
     node = lookup(lustre, node_uuid)
     if not node:
-        error("no node found for :", mds_name)
+        error('mds2node:', "no node found for :", '"'+mds_name+'"')
     return node
 
 
@@ -337,7 +346,7 @@ def name2uuid(lustre, name, tag="",  fatal=1):
     ret = findByName(lustre, name, tag)
     if not ret:
         if fatal:
-            error('name2uuid:', name, "not found.")
+            error('name2uuid:', '"'+name+'"', tag, 'element not found.')
         else:
             return ""
     return getUUID(ret)
@@ -349,7 +358,7 @@ def get_net_uuid(lustre, node_name):
     """ get a network uuid for a node_name """
     node = findByName(lustre, node_name, "node")
     if not node:
-        error ("node not found:", node_name)
+        error ('get_net_uuid:', '"'+node_name+'"', "node element not found.")
     net = node.getElementsByTagName('network')
     if net:
         return getUUID(net[0])
@@ -385,7 +394,6 @@ def do_add_node(gen, lustre,  options, node_name):
     node_add_profile(gen, node, 'ldlm', ldlm_uuid)
     if options.has_key('router'):
         node.setAttribute('router', '1')
-        node_add_profile(gen, node, "ptlrouter", 'PTLROUTER_UUID')
     lustre.appendChild(node)
     return node
 
@@ -412,13 +420,16 @@ def add_net(gen, lustre, options, args):
     node_name = options['node']
     nid = args[0]
     net_type = args[1]
+    port = 0
+    tcpbuf = 0
 
-    if net_type == 'tcp':
+    if net_type in ('tcp', 'toe'):
         if len(args) > 2:
             port = int(args[2])
         else:
             port = DEFAULT_PORT
-        # add send, recv buffer size here
+        if options.has_key('tcpbuf'):
+            tcpbuf = int(options['tcpbuf'])
     elif net_type in ('elan', 'gm'):
         port = 0
     else:
@@ -432,7 +443,7 @@ def add_net(gen, lustre, options, args):
         node = ret
     net_name = new_name('NET_'+ node_name +'_'+ net_type)
     net_uuid = new_uuid(net_name)
-    node.appendChild(gen.network(net_name, net_uuid, nid, net_type, port))
+    node.appendChild(gen.network(net_name, net_uuid, nid, net_type, port, tcpbuf))
     node_add_profile(gen, node, "network", net_uuid)
 
 
@@ -455,14 +466,13 @@ def add_route(gen, lustre, options, args):
         error (node_name, " not found.")
     
     netlist = node.getElementsByTagName('network')
-    for net in netlist:
-        if get_attr(net, 'type') == net_type:
-            rlist = net.getElementsByTagName('route_tbl')
-            if len(rlist) > 0:
-                rtbl = rlist[0]
-            else:
-                rtbl = gen.addElement(net, 'route_tbl')
-            rtbl.appendChild(gen.route(lo, hi))
+    net = netlist[0]
+    rlist = net.getElementsByTagName('route_tbl')
+    if len(rlist) > 0:
+        rtbl = rlist[0]
+    else:
+        rtbl = gen.addElement(net, 'route_tbl')
+    rtbl.appendChild(gen.route(net_type, gw, lo, hi))
 
 
 def add_mds(gen, lustre, options, args):
@@ -475,17 +485,17 @@ def add_mds(gen, lustre, options, args):
         error("--mds requires a --node argument")
 
     mds_name = new_name(options['mds'])
+    if mds_name != options['mds']:
+        warning("name:", options['mds'], "already used. using:", mds_name)
     devname = args[0]
     if len(args) > 1:
         size = args[1]
     else:
         size = 0
 
-    mdc_name = 'MDC_' + mds_name
     mds_uuid = new_uuid(mds_name)
-    mdc_uuid = new_uuid(mdc_name)
 
-    node_uuid = name2uuid(lustre, node_name)
+    node_uuid = name2uuid(lustre, node_name, 'node')
 
     node = findByName(lustre, node_name, "node")
     node_add_profile(gen, node, "mds", mds_uuid)
@@ -496,30 +506,9 @@ def add_mds(gen, lustre, options, args):
 
     mds = gen.mds(mds_name, mds_uuid, "extN", devname, get_format_flag(options),
                   net_uuid, node_uuid, dev_size=size)
-    mdc = gen.mdc(mdc_name, mdc_uuid, mds_uuid)
     lustre.appendChild(mds)
-    lustre.appendChild(mdc)
                    
 
-def add_mdc(gen, lustre, options, args):
-    """ create mtpt on a node """
-    if len(args) < 1:
-        usage()
-
-    if options.has_key('node'):
-        node_name = options['node']
-    else:
-        error("--mdc requires a --node argument")
-
-    mdc_name = args[0]
-    mdc_uuid = name2uuid(lustre, mdc_name)
-
-    node = findByName(lustre, node_name, "node")
-    if not node:
-            error('node:',  node_name, "not found.")
-    node_add_profile(gen, node, "mdc", mdc_uuid)
-
-
 def add_ost(gen, lustre, options, args):
     lovname = ''
     obdtype = 'obdfilter'
@@ -537,7 +526,6 @@ def add_ost(gen, lustre, options, args):
 
     if options.has_key('obdtype'):
         obdtype = options['obdtype']
-
     if obdtype == 'obdecho':
         fstype = ''
     else:
@@ -550,7 +538,13 @@ def add_ost(gen, lustre, options, args):
     obdname = new_name('OBD_'+ node_name)
     oscname = new_name('OSC_'+ node_name)
     ostname = new_name('OST_'+ node_name)
-    obd_uuid = new_uuid(obdname)
+    if options.has_key('obduuid'):
+        obd_uuid = options['obduuid']
+        obd = lookup(lustre, obd_uuid)
+        if obd:
+            error("Duplicate OBD UUID:", obd_uuid)
+    else:
+        obd_uuid = new_uuid(obdname)
     ost_uuid = new_uuid(ostname)
     osc_uuid = new_uuid(oscname)
 
@@ -565,7 +559,7 @@ def add_ost(gen, lustre, options, args):
     if lovname:
         lov = findByName(lustre, lovname, "lov")
         if not lov:
-            error("LOV:", lovname, "not found.")
+            error('add_ost:', '"'+lovname+'"', "lov element not found.")
         lov_add_osc(gen, lov, osc_uuid)
 
     node = findByName(lustre, node_name, "node")
@@ -587,7 +581,7 @@ def add_osc(gen, lustre, options, args):
         node_name = options['node']
     else:
         error("--osc requires a --node argument")
-    osc_uuid = name2uuid(lustre, osc_name)
+    osc_uuid = name2uuid(lustre, osc_name) # either 'osc' or 'lov'
     node = findByName(lustre, node_name, "node")
     node_add_profile(gen, node, 'osc', osc_uuid)
 
@@ -597,10 +591,13 @@ def add_lov(gen, lustre, options, args):
     if len(args) < 4:
         usage()
 
-    name = options['lov']
+    name = new_name(options['lov'])
+    if name != options['lov']:
+        warning("name:", options['lov'], "already used. using:", name)
+
     mds_name = args[0]
     stripe_sz = args[1]
-    stripe_off = args[2]
+    stripe_count = args[2]
     pattern = args[3]
     uuid = new_uuid(name)
 
@@ -608,12 +605,18 @@ def add_lov(gen, lustre, options, args):
     if ret:
         error("LOV: ", name, " already exists.")
 
-    mds_uuid = name2uuid(lustre, mds_name)
-
-    node = mds2node(lustre, mds_name)
-    node_add_profile(gen, node, "lov", uuid)
-    lov = gen.lov(name, uuid, mds_uuid, stripe_sz, stripe_off, pattern)
+    mds_uuid = name2uuid(lustre, mds_name, 'mds')
+    lov = gen.lov(name, uuid, mds_uuid, stripe_sz, stripe_count, pattern)
     lustre.appendChild(lov)
+    
+    # add an lovconfig entry to the mds profile
+    lovconfig_name = new_name('LVCFG_' + name)
+    lovconfig_uuid = new_uuid(lovconfig_name)
+    node = mds2node(lustre, mds_name)
+    node_add_profile(gen, node, "lovconfig", lovconfig_uuid)
+    lovconfig = gen.lovconfig(lovconfig_name, lovconfig_uuid, uuid)
+    lustre.appendChild(lovconfig)
+
 
 
 def add_mtpt(gen, lustre, options, args):
@@ -629,7 +632,6 @@ def add_mtpt(gen, lustre, options, args):
     path = args[0]
     mds_name = args[1]
     lov_name = args[2]
-    mdc_name = 'MDC_' + mds_name
 
     name = new_name('MNT_'+ node_name)
 
@@ -637,18 +639,17 @@ def add_mtpt(gen, lustre, options, args):
     if ret:
         error("MOUNTPOINT: ", name, " already exists.")
 
-    mdc_uuid = name2uuid(lustre, mdc_name)
+    mds_uuid = name2uuid(lustre, mds_name, tag='mds')
     lov_uuid = name2uuid(lustre, lov_name, tag='lov', fatal=0)
     if not lov_uuid:
         lov_uuid = name2uuid(lustre, lov_name, tag='osc', fatal=1)
 
     uuid = new_uuid(name)
-    mtpt = gen.mountpoint(name, uuid, mdc_uuid, lov_uuid, path)
+    mtpt = gen.mountpoint(name, uuid, mds_uuid, lov_uuid, path)
     node = findByName(lustre, node_name, "node")
     if not node:
             error('node:',  node_name, "not found.")
     node_add_profile(gen, node, "mountpoint", uuid)
-    node_add_profile(gen, node, "mdc", mdc_uuid)
     lustre.appendChild(mtpt)
 
 
@@ -657,9 +658,9 @@ def add_mtpt(gen, lustre, options, args):
 #
 def parse_cmdline(argv):
     short_opts = "ho:i:m:"
-    long_opts = ["ost", "osc", "mtpt", "lov=", "node=", "mds=", "net",
-                 "mdc", "route", "router", "merge=", "format", "reformat", "output=",
-                 "obdtype=", "in=", "help"]
+    long_opts = ["ost", "osc", "mtpt", "lov=", "node=", "mds=", "net", "tcpbuf=",
+                 "route", "router", "merge=", "format", "reformat", "output=",
+                 "obdtype=", "obduuid=", "in=", "help", "batch="]
     opts = []
     args = []
     options = {}
@@ -670,18 +671,13 @@ def parse_cmdline(argv):
         usage()
 
     for o, a in opts:
-        if o in ("-h", "--help"):
-            usage()
-        if o in ("-o", "--output"):
-            options['output'] = a
+        # Commands to create new devices
         if o == "--ost":
             options['ost'] = 1
         if o == "--osc":
             options['osc'] = 1
         if o == "--mds":
             options['mds'] = a
-        if o == "--mdc":
-            options['mdc'] = 1
         if o == "--net":
             options['net'] = 1
         if o == "--mtpt":
@@ -694,14 +690,28 @@ def parse_cmdline(argv):
             options['router'] = 1
         if o == "--lov":
             options['lov'] = a
-        if o in ("-m", "--merge"):
-            options['merge'] = a
+
+        # Options for commands
         if o == "--obdtype":
             options['obdtype'] = a
+        if o == "--obduuid":
+            options['obduuid'] = a
+        if o == "--tcpbuf":
+            options['tcpbuf'] = a
+
+        # lmc options
+        if o in ("-h", "--help"):
+            usage()
+        if o in ("-o", "--output"):
+            options['output'] = a
+        if o in ("-m", "--merge"):
+            options['merge'] = a
         if o == "--format":
             options['format'] = 1
         if o  == "--reformat":
             options['reformat'] = 1
+        if o  == "--batch":
+            options['batch'] = a
         if o  in ("--in" , "-i"):
             options['in'] = a
             
@@ -730,6 +740,27 @@ class chrono:
 ############################################################
 # Main
 #
+def do_command(gen, lustre, options, args):
+    if options.has_key('ost'):
+        add_ost(gen, lustre, options, args)
+    elif options.has_key('osc'):
+        add_osc(gen, lustre, options, args)
+    elif options.has_key('mtpt'):
+        add_mtpt(gen, lustre, options, args)
+    elif options.has_key('mds'):
+        add_mds(gen, lustre, options, args)
+    elif options.has_key('net'):
+        add_net(gen, lustre, options, args)
+    elif options.has_key('lov'):
+        add_lov(gen, lustre, options, args)
+    elif options.has_key('route'):
+        add_route(gen, lustre, options, args)
+    elif options.has_key('node'):
+        add_node(gen, lustre, options, args)
+    else:
+        print "Missing command"
+        usage()
+
 def main():
     options, args = parse_cmdline(sys.argv[1:])
     outFile = '-'
@@ -755,27 +786,16 @@ def main():
         sys.exit(1)
 
     gen = GenConfig(doc)
-    if options.has_key('ost'):
-        add_ost(gen, lustre, options, args)
-    elif options.has_key('osc'):
-        add_osc(gen, lustre, options, args)
-    elif options.has_key('mtpt'):
-        add_mtpt(gen, lustre, options, args)
-    elif options.has_key('mds'):
-        add_mds(gen, lustre, options, args)
-    elif options.has_key('mdc'):
-        add_mdc(gen, lustre, options, args)
-    elif options.has_key('net'):
-        add_net(gen, lustre, options, args)
-    elif options.has_key('lov'):
-        add_lov(gen, lustre, options, args)
-    elif options.has_key('route'):
-        add_route(gen, lustre, options, args)
-    elif options.has_key('node'):
-        add_node(gen, lustre, options, args)
+
+    if options.has_key('batch'):
+        fp = open(options['batch'])
+        batchCommands = fp.readlines()
+        fp.close()
+        for cmd in batchCommands:
+            options, args = parse_cmdline(string.split(cmd))
+            do_command(gen, lustre, options, args)
     else:
-        print "Missing command"
-        usage()
+        do_command(gen, lustre, options, args)
 
     if outFile == '-':
         PrettyPrint(doc)