Whamcloud - gitweb
- add mballoc to ldiskfs series
[fs/lustre-release.git] / lustre / utils / lconf
index ac5dc22..08cd122 100755 (executable)
@@ -23,7 +23,7 @@
 # lconf is the main driver script for starting and stopping
 # lustre filesystem services.
 #
-# Based in part on the XML obdctl modifications done by Brian Behlendorf
+# Based in part on the XML obdctl modifications done by Brian Behlendorf 
 
 import sys, getopt, types
 import string, os, stat, popen2, socket, time, random, fcntl, select
@@ -58,13 +58,13 @@ DEFAULT_PORT = 988
 # Maximum number of devices to search for.
 # (the /dev/loop* nodes need to be created beforehand)
 MAX_LOOP_DEVICES = 256
-PORTALS_DIR = 'portals'
+PORTALS_DIR = '../portals'
 
 # Needed to call lconf --record
-CONFIG_FILE = ""
+CONFIG_FILE = "" 
 
 # Please keep these in sync with the values in portals/kp30.h
-ptldebug_names = {
+ptldebug_names = { 
     "trace" :     (1 << 0),
     "inode" :     (1 << 1),
     "super" :     (1 << 2),
@@ -88,8 +88,12 @@ ptldebug_names = {
     "rpctrace" :  (1 << 20),
     "vfstrace" :  (1 << 21),
     "reada" :     (1 << 22),
-    "config" :    (1 << 23),
-    }
+    "mmap" :      (1 << 23),
+    "config" :    (1 << 24),
+    "console" :   (1 << 25),
+    "quota" :     (1 << 26),
+    "sec" :       (1 << 27),
+}
 
 subsystem_names = {
     "undefined" :    (1 << 0),
@@ -103,19 +107,21 @@ subsystem_names = {
     "rpc" :          (1 << 8),
     "mgmt" :         (1 << 9),
     "portals" :      (1 << 10),
-    "socknal" :      (1 << 11),
-    "qswnal" :       (1 << 12),
-    "pinger" :       (1 << 13),
-    "filter" :       (1 << 14),
-    "ptlbd" :        (1 << 15),
-    "echo" :         (1 << 16),
-    "ldlm" :         (1 << 17),
-    "lov" :          (1 << 18),
-    "gmnal" :        (1 << 19),
-    "ptlrouter" :    (1 << 20),
-    "cobd" :         (1 << 21),
-    "ibnal" :        (1 << 22),
-    "cmobd" :        (1 << 23),
+    "nal" :          (1 << 11),
+    "pinger" :       (1 << 12),
+    "filter" :       (1 << 13),
+    "ptlbd" :        (1 << 14),
+    "echo" :         (1 << 15),
+    "ldlm" :         (1 << 16),
+    "lov" :          (1 << 17),
+    "ptlrouter" :    (1 << 18),
+    "cobd" :         (1 << 19),
+    "sm" :           (1 << 20),
+    "asobd" :        (1 << 21),
+    "confobd" :      (1 << 22),
+    "lmv" :          (1 << 23),
+    "cmobd" :        (1 << 24),
+    "sec" :          (1 << 25),
     }
 
 
@@ -125,7 +131,7 @@ def cleanup_error(rc):
     if not first_cleanup_error:
         first_cleanup_error = rc
 
-# ============================================================
+# ============================================================ 
 # debugging and error funcs
 
 def fixme(msg = "this feature"):
@@ -215,8 +221,11 @@ class DaemonHandler:
         if self.running():
             pid = self.read_pidfile()
             try:
-                log ("killing process", pid)
-                os.kill(pid, 15)
+               if pid != 1:
+                   log ("killing process", pid)
+                   os.kill(pid, 15)
+               else:
+                   log("was unable to find pid of " + self.command)
                 #time.sleep(1) # let daemon die
             except OSError, e:
                 log("unable to kill", self.command, e)
@@ -227,7 +236,10 @@ class DaemonHandler:
         pid = self.read_pidfile()
         if pid:
             try:
-                os.kill(pid, 0)
+               if pid != 1:
+                   os.kill(pid, 0)
+               else:
+                   log("was unable to find pid of " + self.command)
             except OSError:
                 self.clean_pidfile()
             else:
@@ -237,12 +249,15 @@ class DaemonHandler:
     def read_pidfile(self):
         try:
             fp = open(self.pidfile(), 'r')
-            pid = int(fp.read())
+           val = fp.read()
+           if val == '':
+               val = '1'
+            pid = int(val)
             fp.close()
             return pid
         except IOError:
             return 0
-
+        
     def clean_pidfile(self):
         """ Remove a stale pidfile """
         log("removing stale pidfile:", self.pidfile())
@@ -250,24 +265,19 @@ class DaemonHandler:
             os.unlink(self.pidfile())
         except OSError, e:
             log(self.pidfile(), e)
-
+            
 class AcceptorHandler(DaemonHandler):
-    def __init__(self, port, net_type, send_mem, recv_mem, irq_aff):
+    def __init__(self, port, net_type):
         DaemonHandler.__init__(self, "acceptor")
         self.port = port
         self.flags = ''
-        self.send_mem = send_mem
-        self.recv_mem = recv_mem
-
-        if irq_aff:
-            self.flags = self.flags + ' -i'
 
     def pidfile(self):
         return "/var/run/%s-%d.pid" % (self.command, self.port)
 
     def command_line(self):
-        return string.join(map(str,('-s', self.send_mem, '-r', self.recv_mem, self.flags, self.port)))
-
+        return string.join(map(str,(self.flags, self.port)))
+    
 acceptors = {}
 
 # start the acceptors
@@ -287,14 +297,14 @@ def run_one_acceptor(port):
         if not daemon.running():
             daemon.start()
     else:
-         panic("run_one_acceptor: No acceptor defined for port:", port)
-
+         panic("run_one_acceptor: No acceptor defined for port:", port)   
+        
 def stop_acceptor(port):
     if acceptors.has_key(port):
         daemon = acceptors[port]
         if daemon.running():
             daemon.stop()
-
+        
 
 # ============================================================
 # handle lctl interface
@@ -319,7 +329,7 @@ class LCTLInterface:
 
     def use_save_file(self, file):
         self.save_file = file
-
+        
     def record(self, dev_name, logname):
         log("Recording log", logname, "on", dev_name)
         self.record_device = dev_name
@@ -351,7 +361,7 @@ class LCTLInterface:
     device $%s
     record %s
     %s""" % (self.record_device, self.record_log, cmds)
-
+            
         debug("+", cmd_line, cmds)
         if config.noexec: return (0, [])
 
@@ -403,7 +413,6 @@ class LCTLInterface:
             raise CommandError(self.lctl, out, rc)
         return rc, out
 
-
     def clear_log(self, dev, log):
         """ clear an existing log """
         cmds =  """
@@ -413,6 +422,13 @@ class LCTLInterface:
   quit """ % (dev, log)
         self.run(cmds)
 
+    def root_squash(self, name, uid, nid):
+        cmds = """
+  device $%s
+  root_squash %s %s
+  quit""" % (name, uid, nid)
+        self.run(cmds)
+
     def network(self, net, nid):
         """ set mynid """
         cmds =  """
@@ -421,33 +437,58 @@ class LCTLInterface:
   quit """ % (net, nid)
         self.run(cmds)
 
+    # add an interface
+    def add_interface(self, net, ip, netmask = ""):
+        """ add an interface """
+        cmds = """
+  network %s
+  add_interface %s %s
+  quit """ % (net, ip, netmask)
+        self.run(cmds)
+
+    # delete an interface
+    def del_interface(self, net, ip):
+        """ delete an interface """
+        cmds = """
+  network %s
+  del_interface %s
+  quit """ % (net, ip)
+        self.run(cmds)
+
     # create a new connection
     def add_uuid(self, net_type, uuid, nid):
         cmds = "\n  add_uuid %s %s %s" %(uuid, nid, net_type)
         self.run(cmds)
 
-    def add_autoconn(self, net_type, send_mem, recv_mem, nid, hostaddr,
-                     port, flags):
-        if net_type  in ('tcp',) and not config.lctl_dump:
+    def add_peer(self, net_type, nid, hostaddr, port):
+        if net_type  in ('tcp','openib','ra') and not config.lctl_dump:
             cmds =  """
   network %s
-  send_mem %d
-  recv_mem %d
-  add_autoconn %s %s %d %s
+  add_peer %s %s %d
   quit""" % (net_type,
-             send_mem,
-             recv_mem,
-             nid, hostaddr, port, flags )
+             nid, hostaddr, port )
             self.run(cmds)
-
+        elif net_type in ('iib',) and not config.lctl_dump:
+            cmds =  """
+  network %s
+  add_peer %s
+  quit""" % (net_type,
+             nid )
+            self.run(cmds)
+        elif net_type in ('vib',) and not config.lctl_dump:
+            cmds =  """
+  network %s
+  add_peer %s %s
+  quit""" % (net_type,
+             nid, hostaddr )
+            self.run(cmds)
+    
     def connect(self, srv):
         self.add_uuid(srv.net_type, srv.nid_uuid, srv.nid)
-        if srv.net_type  in ('tcp',) and not config.lctl_dump:
-            flags = 's'
-            if srv.irq_affinity:
-                flags = flags + 'i'
-            self.add_autoconn(srv.net_type, srv.send_mem, srv.recv_mem,
-                 srv.nid, srv.hostaddr, srv.port, flags)
+        if srv.net_type  in ('tcp','openib','iib','vib','ra') and not config.lctl_dump:
+            if srv.hostaddr[0]:
+                hostaddr = string.split(srv.hostaddr[0], '/')[0]
+            self.add_peer(srv.net_type, srv.nid, hostaddr, srv.port)
 
     # Recover a device
     def recover(self, dev_name, new_conn):
@@ -455,7 +496,7 @@ class LCTLInterface:
     device $%s
     recover %s""" %(dev_name, new_conn)
         self.run(cmds)
-
+                
     # add a route to a range
     def add_route(self, net, gw, lo, hi):
         cmds =  """
@@ -468,7 +509,7 @@ class LCTLInterface:
         except CommandError, e:
             log ("ignore: ")
             e.dump()
-
+                
     def del_route(self, net, gw, lo, hi):
         cmds =  """
   ignore_errors
@@ -502,21 +543,31 @@ class LCTLInterface:
         self.run(cmds)
 
 
-    def del_autoconn(self, net_type, nid, hostaddr):
+    def del_peer(self, net_type, nid, hostaddr):
         if net_type  in ('tcp',) and not config.lctl_dump:
                 cmds =  """
   ignore_errors
   network %s
-  del_autoconn %s %s s
+  del_peer %s %s single_share
   quit""" % (net_type,
              nid, hostaddr)
                 self.run(cmds)
-
+        elif net_type  in ('openib','iib','vib','ra') and not config.lctl_dump:
+                cmds =  """
+  ignore_errors
+  network %s
+  del_peer %s single_share
+  quit""" % (net_type,
+             nid)
+                self.run(cmds)
+        
     # disconnect one connection
     def disconnect(self, srv):
         self.del_uuid(srv.nid_uuid)
-        if srv.net_type  in ('tcp',) and not config.lctl_dump:
-            self.del_autoconn(srv.net_type, srv.nid, srv.hostaddr)
+        if srv.net_type  in ('tcp','openib','iib','vib','ra') and not config.lctl_dump:
+            if srv.hostaddr[0]:
+                hostaddr = string.split(srv.hostaddr[0], '/')[0]
+            self.del_peer(srv.net_type, srv.nid, hostaddr)
 
     def del_uuid(self, uuid):
         cmds =  """
@@ -540,24 +591,51 @@ class LCTLInterface:
   quit""" % (type, name, uuid)
         self.run(cmds)
         
+    def detach(self, name):
+        cmds = """
+  cfg_device %s
+  detach
+  quit""" % (name)
+        self.run(cmds)
+        
+    def set_security(self, name, key, value):
+        cmds = """
+  cfg_device %s
+  set_security %s %s
+  quit""" % (name, key, value)
+        self.run(cmds)
+
     def setup(self, name, setup = ""):
         cmds = """
   cfg_device %s
   setup %s
   quit""" % (name, setup)
         self.run(cmds)
+        
+    def add_conn(self, name, conn_uuid):
+        cmds = """
+  cfg_device %s
+  add_conn %s
+  quit""" % (name, conn_uuid)
+        self.run(cmds)
 
+    def start(self, name, conf_name):
+        cmds = """
+  device $%s
+  start %s
+  quit""" % (name, conf_name)
+        self.run(cmds)
 
     # create a new device with lctl
     def newdev(self, type, name, uuid, setup = ""):
-        self.attach(type, name, uuid);
+        if type != 'mds':
+            self.attach(type, name, uuid);
         try:
             self.setup(name, setup)
         except CommandError, e:
             self.cleanup(name, uuid, 0)
             raise e
-
-
+        
     # cleanup a device
     def cleanup(self, name, uuid, force, failover = 0):
         if failover: force = 1
@@ -572,11 +650,12 @@ class LCTLInterface:
 
     # create an lov
     def lov_setup(self, name, uuid, desc_uuid, stripe_cnt,
-                  stripe_sz, stripe_off, pattern):
+                  stripe_sz, stripe_off, pattern, devlist = None):
         cmds = """
   attach lov %s %s
-  lov_setup %s %d %d %d %s
-  quit""" % (name, uuid, desc_uuid, stripe_cnt, stripe_sz, stripe_off, pattern)
+  lov_setup %s %d %d %d %s %s
+  quit""" % (name, uuid, desc_uuid, stripe_cnt, stripe_sz, stripe_off,
+             pattern, devlist)
         self.run(cmds)
 
     # add an OBD to a LOV
@@ -721,17 +800,6 @@ def do_find_file(base, mod):
             if module:
                 return module
 
-def find_module(src_dir, dev_dir, modname):
-    modbase = src_dir +'/'+ dev_dir +'/'+ modname
-    for modext in '.ko', '.o':
-        module = modbase + modext
-        try:
-            if os.access(module, os.R_OK):
-                return module
-        except OSError:
-            pass
-    return None
-
 # is the path a block device?
 def is_block(path):
     s = ()
@@ -740,7 +808,20 @@ def is_block(path):
     except OSError:
         return 0
     return stat.S_ISBLK(s[stat.ST_MODE])
-    
+
+# find the journal device from mkfs options
+def jdev(opts):
+    if opts == None:
+        return ''
+    x=string.split(opts)
+    i=0
+    while i < len(x) - 1:
+        if x[i] == '-J' and x[i+1].startswith('device='):
+            str=x[i+1]
+            return str[7:]
+        i=i+1
+    return ''
+
 # build fs according to type
 # fixme: dangerous
 def mkfs(dev, devsize, fstype, jsize, isize, mkfsoptions, isblock=1):
@@ -756,23 +837,71 @@ def mkfs(dev, devsize, fstype, jsize, isize, mkfsoptions, isblock=1):
 
     if fstype in ('ext3', 'extN', 'ldiskfs'):
         # ext3 journal size is in megabytes
-        if jsize == 0:
+        # but don't set jsize if mkfsoptions indicates a separate journal device
+        if jsize == 0 and jdev(mkfsoptions) == '':
             if devsize == 0:
                 if not is_block(dev):
                     ret, out = runcmd("ls -l %s" %dev)
                     devsize = int(string.split(out[0])[4]) / 1024
                 else:
+                    # sfdisk works for symlink, hardlink, and realdev
                     ret, out = runcmd("sfdisk -s %s" %dev)
-                    devsize = int(out[0])
+                    if not ret:
+                        devsize = int(out[0])
+                    else:
+                        # sfdisk -s will fail for too large block device,
+                        # then, read the size of partition from /proc/partitions
+
+                        # get the realpath of the device
+                        # it may be the real device, such as /dev/hda7
+                        # or the hardlink created via mknod for a device
+                        if 'realpath' in dir(os.path):
+                            real_dev = os.path.realpath(dev)
+                        else:
+                            real_dev = dev
+                            link_count = 0
+                            while os.path.islink(real_dev) and (link_count < 20):
+                                link_count = link_count + 1
+                                dev_link = os.readlink(real_dev)
+                                if os.path.isabs(dev_link):
+                                    real_dev = dev_link
+                                else:
+                                    real_dev = os.path.join(os.path.dirname(real_dev), dev_link)
+                                if link_count > 19:
+                                    panic("Entountered too many symbolic links resolving block device:", dev)
+
+                        # get the major and minor number of the realpath via ls
+                        # it seems python(os.stat) does not return 
+                        # the st_rdev member of the stat structure
+                        ret, out = runcmd("ls -l %s" %real_dev)
+                        major = string.split(string.split(out[0])[4], ",")[0]
+                        minor = string.split(out[0])[5]
+
+                        # get the devsize from /proc/partitions with the major and minor number
+                        ret, out = runcmd("cat /proc/partitions")
+                        for line in out:
+                            if len(line) > 1:
+                                if string.split(line)[0] == major and string.split(line)[1] == minor:
+                                    devsize = int(string.split(line)[2])
+                                    break
+
             if devsize > 1024 * 1024:
                 jsize = ((devsize / 102400) * 4)
             if jsize > 400:
-                jsize = 400
+                jsize = 400        
         if jsize:  jopt = "-J size=%d" %(jsize,)
         if isize:  iopt = "-I %d" %(isize,)
         mkfs = 'mkfs.ext2 -j -b 4096 '
         if not isblock or config.force:
             mkfs = mkfs + ' -F '
+        if jdev(mkfsoptions) != '':
+            jmkfs = 'mkfs.ext2 -b 4096 -O journal_dev '
+            if config.force:
+                jmkfs = jmkfs + '-F '
+            jmkfs = jmkfs + jdev(mkfsoptions)                
+            (ret, out) = run (jmkfs)
+            if ret:
+                panic("Unable format journal device:", jdev(mkfsoptions), string.join(out))
     elif fstype == 'reiserfs':
         # reiserfs journal size is in blocks
         if jsize:  jopt = "--journal_size %d" %(jsize,)
@@ -815,8 +944,19 @@ def find_assigned_loop(file):
                 m = re.search(r'\((.*)\)', out[0])
                 if m and file == m.group(1):
                     return dev
-        else:
-            break
+    return ''
+
+# find free loop device
+def find_free_loop(file):
+    loop = loop_base()
+    
+    # find next free loop
+    for n in xrange(0, MAX_LOOP_DEVICES):
+        dev = loop + str(n)
+        if os.access(dev, os.R_OK):
+            (stat, out) = run('losetup', dev)
+            if stat:
+                return dev
     return ''
 
 # create file if necessary and assign the first free loop device
@@ -835,46 +975,48 @@ def init_loop(file, size, fstype, journal_size, inode_size,
             
     dev = find_assigned_loop(realfile)
     if dev:
-        print 'WARNING file:', realfile, 'already mapped to', dev
-        return dev
+        print 'WARNING: file', realfile, 'already mapped to', dev
+       return dev
             
     if reformat or not os.access(realfile, os.R_OK | os.W_OK):
-        if size < 8000:
-            panic("size of loopback file '%s' must be larger than 8MB, but is set to %s" % (realfile, size))
         (ret, out) = run("dd if=/dev/zero bs=1k count=0 seek=%d of=%s" %(size, realfile))
         if ret:
             panic("Unable to create backing store:", realfile)
-            
         mkfs(realfile, size, realfstype, journal_size, inode_size, 
              mkfsoptions, isblock=0)
 
-    loop = loop_base()
-    # find next free loop
-    for n in xrange(0, MAX_LOOP_DEVICES):
-        dev = loop + str(n)
-        if os.access(dev, os.R_OK):
-            (stat, out) = run('losetup', dev)
-            if stat:
-                run('losetup', dev, realfile)
-                return dev
-        else:
-            print "out of loop devices"
-            return ''
+    dev = find_free_loop(realfile)
+    if dev:
+       print "attach " + realfile + " <-> " + dev                  
+        run('losetup', dev, realfile)
+        return dev
+
     print "out of loop devices"
     return ''
 
 # undo loop assignment
-def clean_loop(file):
-    dev = find_assigned_loop(file)
-    if dev:
-        ret, out = run('losetup -d', dev)
-        if ret:
-            log('unable to clean loop device:', dev, 'for file:', file)
-            logall(out)
-
+def clean_loop(dev, fstype, backfstype, backdev):
+    if fstype == 'smfs':
+       realfile = backdev
+    else:
+       realfile = dev
+    if not is_block(realfile):
+       dev = find_assigned_loop(realfile)
+       if dev:
+           print "detach " + dev + " <-> " + realfile
+           ret, out = run('losetup -d', dev)
+           if ret:
+               log('unable to clean loop device', dev, 'for file', realfile)
+               logall(out)
+
+# finilizes passed device
+def clean_dev(dev, fstype, backfstype, backdev):
+    if fstype == 'smfs' or not is_block(dev):
+       clean_loop(dev, fstype, backfstype, backdev)
+       
 # determine if dev is formatted as a <fstype> filesystem
 def need_format(fstype, dev):
-    # FIXME don't know how to implement this
+    # FIXME don't know how to implement this    
     return 0
 
 # initialize a block device if needed
@@ -893,7 +1035,7 @@ def block_dev(dev, size, fstype, reformat, autoformat, journal_size,
 #        panic("device:", dev,
 #              "not prepared, and autoformat is not set.\n",
 #              "Rerun with --reformat option to format ALL filesystems")
-
+        
     return dev
 
 def if2addr(iface):
@@ -911,6 +1053,8 @@ def def_mount_options(fstype, target):
         mountfsoptions = "errors=remount-ro"
         if target == 'ost' and sys_get_branch() == '2.4':
             mountfsoptions = "%s,asyncdel" % (mountfsoptions)
+        if target == 'ost' and sys_get_branch() == '2.6':
+            mountfsoptions = "%s,extents,mballoc" % (mountfsoptions)
         return mountfsoptions
     return ""
         
@@ -931,11 +1075,11 @@ def sys_get_local_nid(net_type, wildcard, cluster_id):
     else:
         local = sys_get_local_address(net_type, wildcard, cluster_id)
     return local
-
+        
 def sys_get_local_address(net_type, wildcard, cluster_id):
     """Return the local address for the network type."""
     local = ""
-    if net_type in ('tcp',):
+    if net_type in ('tcp','openib','iib','vib','ra'):
         if  ':' in wildcard:
             iface, star = string.split(wildcard, ':')
             local = if2addr(iface)
@@ -959,12 +1103,14 @@ def sys_get_local_address(net_type, wildcard, cluster_id):
                     elan_id = a[1]
                     break
             try:
-                nid = my_int(cluster_id) + my_int(elan_id)
+                nid = my_int(cluster_id) + my_int(elan_id) 
                 local = "%d" % (nid)
             except ValueError, e:
                 local = elan_id
         except IOError, e:
             log(e)
+    elif net_type == 'lo':
+        fixme("automatic local address for loopback")
     elif net_type == 'gm':
         fixme("automatic local address for GM")
 
@@ -985,20 +1131,6 @@ def sys_get_branch():
         log(e)
     return ""
 
-
-def mod_loaded(modname):
-    """Check if a module is already loaded. Look in /proc/modules for it."""
-    try:
-        fp = open('/proc/modules')
-        lines = fp.readlines()
-        fp.close()
-        # please forgive my tired fingers for this one
-        ret = filter(lambda word, mod=modname: word == mod,
-                     map(lambda line: string.split(line)[0], lines))
-        return ret
-    except Exception, e:
-        return 0
-
 # XXX: instead of device_list, ask for $name and see what we get
 def is_prepared(name):
     """Return true if a device exists for the name"""
@@ -1017,7 +1149,7 @@ def is_prepared(name):
         e.dump()
     return 0
 
-def is_network_prepared():
+def net_is_prepared():
     """If the any device exists, then assume that all networking
        has been configured"""
     out = lctl.device_list()
@@ -1037,56 +1169,162 @@ def fs_is_mounted(path):
         log(e)
     return 0
 
+def kmod_find(src_dir, dev_dir, modname):
+    modbase = src_dir +'/'+ dev_dir +'/'+ modname
+    for modext in '.ko', '.o':
+        module = modbase + modext
+        try:
+            if os.access(module, os.R_OK):
+                return module
+        except OSError:
+               pass
+    return None
+
+def kmod_info(modname):
+    """Returns reference count for passed module name."""
+    try:
+       fp = open('/proc/modules')
+       lines = fp.readlines()
+       fp.close()
+       
+       # please forgive my tired fingers for this one
+       ret = filter(lambda word, mod = modname: word[0] == mod,
+                    map(lambda line: string.split(line), lines))
+       if not ret:
+           return ''
+       return ret[0]
+    except Exception, e:
+        return 0
 
 class kmod:
+    """Presents kernel module"""
+    def __init__(self, src_dir, dev_dir, name):
+        self.src_dir = src_dir
+        self.dev_dir = dev_dir
+        self.name = name
+
+    # FIXME we ignore the failure of loading gss module, because we might
+    # don't need it at all.
+    def load(self):
+        """Load module"""
+        log ('loading module:', self.name, 'srcdir',
+             self.src_dir, 'devdir', self.dev_dir)
+        if self.src_dir:
+            module = kmod_find(self.src_dir, self.dev_dir,
+                               self.name)
+            if not module and self.name != 'ptlrpcs_gss':
+                panic('module not found:', self.name)
+            (rc, out)  = run('/sbin/insmod', module)
+            if rc:
+                if self.name == 'ptlrpcs_gss':
+                    print "Warning: not support gss security!"
+                else:
+                    raise CommandError('insmod', out, rc)
+        else:
+            (rc, out) = run('/sbin/modprobe', self.name)
+            if rc:
+                if self.name == 'ptlrpcs_gss':
+                    print "Warning: not support gss security!"
+                else:
+                    raise CommandError('modprobe', out, rc)
+
+    def cleanup(self):
+       """Unload module"""
+        log('unloading module:', self.name)
+        (rc, out) = run('/sbin/rmmod', self.name)
+        if rc:
+            log('unable to unload module:', self.name +
+                "(" + self.refcount() + ")")
+            logall(out)
+
+    def info(self):
+        """Returns module info if any."""
+        return kmod_info(self.name)
+
+    def loaded(self):
+        """Returns 1 if module is loaded. Otherwise 0 is returned."""
+        if self.info():
+            return 1
+        else:
+            return 0
+
+    def refcount(self):
+        """Returns module refcount."""
+        info = self.info()
+        if not info:
+            return ''
+        return info[2]
+
+    def used(self):
+        """Returns 1 if module is used, otherwise 0 is returned."""
+        info = self.info()
+        if not info:
+            return 0
+        if len(info) > 3:
+            users = info[3]
+            if users and users != '(unused)' and users != '-':
+                return 1
+            else:
+                return 0
+        else:
+            return 0
+
+    def busy(self):
+        """Returns 1 if module is busy, otherwise 0 is returned."""
+        if self.loaded() and (self.used() or self.refcount() != '0'):
+            return 1
+        else:
+            return 0
+
+class kmod_manager:
     """Manage kernel modules"""
     def __init__(self, lustre_dir, portals_dir):
         self.lustre_dir = lustre_dir
         self.portals_dir = portals_dir
         self.kmodule_list = []
 
+    def find_module(self, modname):
+        """Find module by module name"""
+        for mod in self.kmodule_list:
+            if mod.name == modname:
+                return mod
+        return ''
+        
     def add_portals_module(self, dev_dir, modname):
         """Append a module to list of modules to load."""
-        self.kmodule_list.append((self.portals_dir, dev_dir, modname))
+
+        mod = self.find_module(modname)
+        if not mod:
+            mod = kmod(self.portals_dir, dev_dir, modname)
+            self.kmodule_list.append(mod)
 
     def add_lustre_module(self, dev_dir, modname):
         """Append a module to list of modules to load."""
-        self.kmodule_list.append((self.lustre_dir, dev_dir, modname))
 
-    def load_module(self):
+        mod = self.find_module(modname)
+        if not mod:
+            mod = kmod(self.lustre_dir, dev_dir, modname)
+            self.kmodule_list.append(mod)
+        
+    def load_modules(self):
         """Load all the modules in the list in the order they appear."""
-        for src_dir, dev_dir, mod in self.kmodule_list:
-            if mod_loaded(mod) and not config.noexec:
+        for mod in self.kmodule_list:
+            if mod.loaded() and not config.noexec:
                 continue
-            log ('loading module:', mod, 'srcdir', src_dir, 'devdir', dev_dir)
-            if src_dir:
-                module = find_module(src_dir, dev_dir,  mod)
-                if not module:
-                    panic('module not found:', mod)
-                (rc, out)  = run('/sbin/insmod', module)
-                if rc:
-                    raise CommandError('insmod', out, rc)
-            else:
-                (rc, out) = run('/sbin/modprobe', mod)
-                if rc:
-                    raise CommandError('modprobe', out, rc)
+            mod.load()
 
-    def cleanup_module(self):
+    def cleanup_modules(self):
         """Unload the modules in the list in reverse order."""
         rev = self.kmodule_list
         rev.reverse()
-        for src_dir, dev_dir, mod in rev:
-            if not mod_loaded(mod) and not config.noexec:
+        for mod in rev:
+            if (not mod.loaded() or mod.busy()) and not config.noexec:
                 continue
             # debug hack
-            if mod == 'portals' and config.dump:
+            if mod.name == 'portals' and config.dump:
                 lctl.dump(config.dump)
-            log('unloading module:', mod)
-            (rc, out) = run('/sbin/rmmod', mod)
-            if rc:
-                log('! unable to unload module:', mod)
-                logall(out)
-
+            mod.cleanup()
+           
 # ============================================================
 # Classes to prepare and cleanup the various objects
 #
@@ -1101,7 +1339,6 @@ class Module:
         self.uuid = self.db.getUUID()
         self._server = None
         self._connected = 0
-        self.kmod = kmod(config.lustre, config.portals)
 
     def info(self, *args):
         msg = string.join(map(str,args))
@@ -1117,29 +1354,16 @@ class Module:
             e.dump()
             cleanup_error(e.rc)
 
-    def add_portals_module(self, dev_dir, modname):
-        """Append a module to list of modules to load."""
-        self.kmod.add_portals_module(dev_dir, modname)
-
-    def add_lustre_module(self, dev_dir, modname):
-        """Append a module to list of modules to load."""
-        self.kmod.add_lustre_module(dev_dir, modname)
-
-    def load_module(self):
-        """Load all the modules in the list in the order they appear."""
-        self.kmod.load_module()
-
-    def cleanup_module(self):
-        """Unload the modules in the list in reverse order."""
-        if self.safe_to_clean():
-            self.kmod.cleanup_module()
+    def add_module(self, manager):
+        """Adds all needed modules in the order they appear."""
+        return
 
     def safe_to_clean(self):
         return 1
 
     def safe_to_clean_modules(self):
         return self.safe_to_clean()
-
+        
 class Network(Module):
     def __init__(self,db):
         Module.__init__(self, 'NETWORK', db)
@@ -1147,9 +1371,6 @@ class Network(Module):
         self.nid = self.db.get_val('nid', '*')
         self.cluster_id = self.db.get_val('clusterid', "0")
         self.port = self.db.get_val_int('port', 0)
-        self.send_mem = self.db.get_val_int('sendmem', DEFAULT_TCPBUF)
-        self.recv_mem = self.db.get_val_int('recvmem', DEFAULT_TCPBUF)
-        self.irq_affinity = self.db.get_val_int('irqaffinity', 0)
 
         if '*' in self.nid:
             self.nid = sys_get_local_nid(self.net_type, self.nid, self.cluster_id)
@@ -1161,36 +1382,56 @@ class Network(Module):
             self.generic_nid = 0
 
         self.nid_uuid = self.nid_to_uuid(self.nid)
-
-        self.hostaddr = self.db.get_val('hostaddr', self.nid)
-        if '*' in self.hostaddr:
-            self.hostaddr = sys_get_local_address(self.net_type, self.hostaddr, self.cluster_id)
-            if not self.hostaddr:
-                panic("unable to set hostaddr for", self.net_type, self.hostaddr, self.cluster_id)
-            debug("hostaddr:", self.hostaddr)
-
-        self.add_portals_module("libcfs", 'libcfs')
-        self.add_portals_module("portals", 'portals')
-        if node_needs_router():
-            self.add_portals_module("router", 'kptlrouter')
+        self.hostaddr = self.db.get_hostaddr()
+        if len(self.hostaddr) == 0:
+            self.hostaddr.append(self.nid)
+        if '*' in self.hostaddr[0]:
+            self.hostaddr[0] = sys_get_local_address(self.net_type, self.hostaddr[0], self.cluster_id)
+            if not self.hostaddr[0]:
+                panic("unable to set hostaddr for", self.net_type, self.hostaddr[0], self.cluster_id)
+            debug("hostaddr:", self.hostaddr[0])
+
+    def add_module(self, manager):
+        manager.add_portals_module("libcfs", 'libcfs')
+        manager.add_portals_module("portals", 'portals')
+        
+       if node_needs_router():
+            manager.add_portals_module("router", 'kptlrouter')
         if self.net_type == 'tcp':
-            self.add_portals_module("knals/socknal", 'ksocknal')
+            manager.add_portals_module("knals/socknal", 'ksocknal')
         if self.net_type == 'elan':
-            self.add_portals_module("knals/qswnal", 'kqswnal')
+            manager.add_portals_module("knals/qswnal", 'kqswnal')
         if self.net_type == 'gm':
-            self.add_portals_module("knals/gmnal", 'kgmnal')
+            manager.add_portals_module("knals/gmnal", 'kgmnal')
+        if self.net_type == 'openib':
+            manager.add_portals_module("knals/openibnal", 'kopenibnal')
+        if self.net_type == 'iib':
+            manager.add_portals_module("knals/iibnal", 'kiibnal')
+        if self.net_type == 'vib':
+            self.add_portals_module("knals/vibnal", 'kvibnal')
+        if self.net_type == 'lo':
+            manager.add_portals_module("knals/lonal", 'klonal')
+        if self.net_type == 'ra':
+            manager.add_portals_module("knals/ranal", 'kranal')
 
     def nid_to_uuid(self, nid):
         return "NID_%s_UUID" %(nid,)
 
     def prepare(self):
-        if not config.record and is_network_prepared():
+        if not config.record and net_is_prepared():
             return
         self.info(self.net_type, self.nid, self.port)
         if not (config.record and self.generic_nid):
             lctl.network(self.net_type, self.nid)
         if self.net_type == 'tcp':
             sys_tweak_socknal()
+            for hostaddr in self.db.get_hostaddr():
+                ip = string.split(hostaddr, '/')[0]
+                if len(string.split(hostaddr, '/')) == 2:
+                    netmask = string.split(hostaddr, '/')[1]
+                else:
+                    netmask = ""
+                lctl.add_interface(self.net_type, ip, netmask)
         if self.net_type == 'elan':
             sys_optimize_elan()
         if self.port and  node_is_router():
@@ -1225,7 +1466,7 @@ class Network(Module):
                                 cleanup_error(e.rc)
 
     def safe_to_clean(self):
-        return not is_network_prepared()
+        return not net_is_prepared()
 
     def cleanup(self):
         self.info(self.net_type, self.nid, self.port)
@@ -1233,6 +1474,10 @@ class Network(Module):
             stop_acceptor(self.port)
         if  node_is_router():
             self.disconnect_peer_gateways()
+        if self.net_type == 'tcp':
+            for hostaddr in self.db.get_hostaddr():
+                ip = string.split(hostaddr, '/')[0]
+                lctl.del_interface(self.net_type, ip)
 
     def correct_level(self, level, op=None):
         return level
@@ -1243,9 +1488,9 @@ class RouteTable(Module):
 
     def server_for_route(self, net_type, gw, gw_cluster_id, tgt_cluster_id,
                          lo, hi):
-        # only setup connections for tcp NALs
+        # only setup connections for tcp, openib, and iib NALs
         srvdb = None
-        if not net_type in ('tcp',):
+        if not net_type in ('tcp','openib','iib','vib','ra'):
             return None
 
         # connect to target if route is to single node and this node is the gw
@@ -1265,9 +1510,9 @@ class RouteTable(Module):
             return None
 
         return Network(srvdb)
-
+        
     def prepare(self):
-        if not config.record and is_network_prepared():
+        if not config.record and net_is_prepared():
             return
         self.info()
         for net_type, gw, gw_cluster_id, tgt_cluster_id, lo, hi in self.db.get_route_tbl():
@@ -1277,10 +1522,10 @@ class RouteTable(Module):
                 lctl.connect(srv)
 
     def safe_to_clean(self):
-        return not is_network_prepared()
+        return not net_is_prepared()
 
     def cleanup(self):
-        if is_network_prepared():
+        if net_is_prepared():
             # the network is still being used, don't clean it up
             return
         for net_type, gw, gw_cluster_id, tgt_cluster_id, lo, hi in self.db.get_route_tbl():
@@ -1303,10 +1548,12 @@ class RouteTable(Module):
 class Management(Module):
     def __init__(self, db):
         Module.__init__(self, 'MGMT', db)
-        self.add_lustre_module('lvfs', 'lvfs')
-        self.add_lustre_module('obdclass', 'obdclass')
-        self.add_lustre_module('ptlrpc', 'ptlrpc')
-        self.add_lustre_module('mgmt', 'mgmt_svc')
+
+    def add_module(self, manager):
+        manager.add_lustre_module('lvfs', 'lvfs')
+        manager.add_lustre_module('obdclass', 'obdclass')
+        manager.add_lustre_module('ptlrpc', 'ptlrpc')
+        manager.add_lustre_module('mgmt', 'mgmt_svc')
 
     def prepare(self):
         if not config.record and is_prepared(self.name):
@@ -1329,9 +1576,13 @@ class Management(Module):
 class LDLM(Module):
     def __init__(self,db):
         Module.__init__(self, 'LDLM', db)
-        self.add_lustre_module('lvfs', 'lvfs')
-        self.add_lustre_module('obdclass', 'obdclass')
-        self.add_lustre_module('ptlrpc', 'ptlrpc')
+
+    def add_module(self, manager):
+        manager.add_lustre_module('lvfs', 'lvfs')
+        manager.add_lustre_module('obdclass', 'obdclass')
+        manager.add_lustre_module('sec', 'ptlrpcs')
+        manager.add_lustre_module('ptlrpc', 'ptlrpc')
+       manager.add_lustre_module('sec/gss', 'ptlrpcs_gss')
 
     def prepare(self):
         return
@@ -1342,13 +1593,11 @@ class LDLM(Module):
     def correct_level(self, level, op=None):
         return level
 
-
 class LOV(Module):
     def __init__(self, db, uuid, fs_name, name_override = None, config_only = None):
         Module.__init__(self, 'LOV', db)
         if name_override != None:
             self.name = "lov_%s" % name_override
-        self.add_lustre_module('lov', 'lov')
         self.mds_uuid = self.db.get_first_ref('mds')
         self.stripe_sz = self.db.get_val_int('stripesize', 1048576)
         self.stripe_off = self.db.get_val_int('stripeoffset', 0)
@@ -1356,6 +1605,7 @@ class LOV(Module):
         self.devlist = self.db.get_lov_tgts('lov_tgt')
         self.stripe_cnt = self.db.get_val_int('stripecount', len(self.devlist))
         self.osclist = []
+       self.obdlist = []
         self.desc_uuid = self.uuid
         self.uuid = generate_client_uuid(self.name)
         self.fs_name = fs_name
@@ -1368,7 +1618,8 @@ class LOV(Module):
         for (obd_uuid, index, gen, active) in self.devlist:
             if obd_uuid == '':
                 continue
-            obd = self.db.lookup(obd_uuid)
+           self.obdlist.append(obd_uuid)
+           obd = self.db.lookup(obd_uuid)
             osc = get_osc(obd, self.uuid, fs_name)
             if osc:
                 self.osclist.append((osc, index, gen, active))
@@ -1385,7 +1636,8 @@ class LOV(Module):
                   self.stripe_off, self.pattern, self.devlist,
                   self.mds_name)
         lctl.lov_setup(self.name, self.uuid, self.desc_uuid,  self.stripe_cnt,
-                       self.stripe_sz, self.stripe_off, self.pattern)
+                       self.stripe_sz, self.stripe_off, self.pattern,
+                      string.join(self.obdlist))
         for (osc, index, gen, active) in self.osclist:
             target_uuid = osc.target_uuid
             try:
@@ -1407,22 +1659,13 @@ class LOV(Module):
         if self.config_only:
             panic("Can't clean up config_only LOV ", self.name)
 
-    def load_module(self):
+    def add_module(self, manager):
         if self.config_only:
             panic("Can't load modules for config_only LOV ", self.name)
         for (osc, index, gen, active) in self.osclist:
-            osc.load_module()
-            break
-        Module.load_module(self)
-
-    def cleanup_module(self):
-        if self.config_only:
-            panic("Can't cleanup modules for config_only LOV ", self.name)
-        Module.cleanup_module(self)
-        for (osc, index, gen, active) in self.osclist:
-            if active:
-                osc.cleanup_module()
+            osc.add_module(manager)
             break
+        manager.add_lustre_module('lov', 'lov')
 
     def correct_level(self, level, op=None):
         return level
@@ -1432,8 +1675,11 @@ class LMV(Module):
         Module.__init__(self, 'LMV', db)
         if name_override != None:
             self.name = "lmv_%s" % name_override
-        self.add_lustre_module('lmv', 'lmv')
-        self.devlist = self.db.get_refs('mds')
+           
+        self.devlist = self.db.get_lmv_tgts('lmv_tgt')
+       if self.devlist == None:
+           self.devlist = self.db.get_refs('mds')
+           
         self.mdclist = []
         self.desc_uuid = self.uuid
         self.uuid = uuid
@@ -1447,10 +1693,12 @@ class LMV(Module):
                 self.mdclist.append(mdc)
             else:
                 panic('mdc not found:', mds_uuid)
-            
+
     def prepare(self):
         if is_prepared(self.name):
             return
+           
+       self.info();
         for mdc in self.mdclist:
             try:
                 # Only ignore connect failures with --force, which
@@ -1459,6 +1707,7 @@ class LMV(Module):
             except CommandError, e:
                 print "Error preparing LMV %s\n" % mdc.uuid
                 raise e
+       
         lctl.lmv_setup(self.name, self.uuid, self.desc_uuid,
                        string.join(self.devlist))
 
@@ -1468,356 +1717,460 @@ class LMV(Module):
         if is_prepared(self.name):
             Module.cleanup(self)
 
-    def load_module(self):
+    def add_module(self, manager):
         for mdc in self.mdclist:
-            mdc.load_module()
-            break
-        Module.load_module(self)
-
-    def cleanup_module(self):
-        Module.cleanup_module(self)
-        for mds in self.mdclist:
-            mdc.cleanup_module()
+            mdc.add_module(manager)
             break
+        manager.add_lustre_module('lmv', 'lmv')
 
     def correct_level(self, level, op=None):
         return level
 
-class MDSDEV(Module):
-    def __init__(self,db):
-        Module.__init__(self, 'MDSDEV', db)
+class CONFDEV(Module):
+    def __init__(self, db, name, target_uuid, uuid):
+        Module.__init__(self, 'CONFDEV', db)
         self.devpath = self.db.get_val('devpath','')
-        self.backdevpath = self.db.get_val('backdevpath','')
+        self.backdevpath = self.db.get_val('devpath','')
         self.size = self.db.get_val_int('devsize', 0)
         self.journal_size = self.db.get_val_int('journalsize', 0)
         self.fstype = self.db.get_val('fstype', '')
         self.backfstype = self.db.get_val('backfstype', '')
-        self.nspath = self.db.get_val('nspath', '')
         self.mkfsoptions = self.db.get_val('mkfsoptions', '')
         self.mountfsoptions = self.db.get_val('mountfsoptions', '')
-        self.cachetype = self.db.get_val('cachetype', '')
-       # overwrite the orignal MDSDEV name and uuid with the MDS name and uuid
-        target_uuid = self.db.get_first_ref('target')
-        mds = self.db.lookup(target_uuid)
-        self.name = mds.getName()
-        self.filesystem_uuids = mds.get_refs('filesystem')
-       self.lmv_uuid = ''
-       self.lmv = ''
-        self.master_mds = ""
-       if not self.filesystem_uuids:
-           self.lmv_uuid = self.db.get_first_ref('lmv')
-           if not self.lmv_uuid:
-               panic("ALERT: can't find lvm uuid")
-           if self.lmv_uuid:
-               self.lmv = self.db.lookup(self.lmv_uuid)
-               if self.lmv:
-                   self.filesystem_uuids = self.lmv.get_refs('filesystem')
-                    self.master_mds = self.lmv_uuid
-        # FIXME: if fstype not set, then determine based on kernel version
-        self.format = self.db.get_val('autoformat', "no")
-        if mds.get_val('failover', 0):
-            self.failover_mds = 'f'
-        else:
-            self.failover_mds = 'n'
-        active_uuid = get_active_target(mds)
-        if not active_uuid:
-            panic("No target device found:", target_uuid)
-        if active_uuid == self.uuid:
-            self.active = 1
-        else:
-            self.active = 0
-        if self.active and config.group and config.group != mds.get_val('group'):
-            self.active = 0
-
-        self.inode_size = self.db.get_val_int('inodesize', 0)
-        if self.inode_size == 0:
-            # find the LOV for this MDS
-            lovconfig_uuid = mds.get_first_ref('lovconfig')
-            if not lovconfig_uuid:
-                if not self.lmv_uuid:
-                    panic("No LOV found for lovconfig ", lovconfig.name)
+       self.target = self.db.lookup(target_uuid)
+        self.name = "conf_%s" % self.target.getName()
+        self.client_uuids = self.target.get_refs('client')
+        self.obdtype = self.db.get_val('obdtype', '')
+       
+        self.mds_sec = self.db.get_val('mds_sec', '')
+        self.oss_sec = self.db.get_val('oss_sec', '')
+        self.deny_sec = self.db.get_val('deny_sec', '')
+
+        if config.mds_mds_sec:
+            self.mds_sec = config.mds_mds_sec
+        if config.mds_oss_sec:
+            self.oss_sec = config.mds_oss_sec
+        if config.mds_deny_sec:
+            if self.deny_sec:
+                self.deny_sec = "%s,%s" %(self.deny_sec, config.mds_deny_sec)
+            else:
+                self.deny_sec = config.mds_deny_sec
 
-               if not self.lmv:
-                   panic("No LMV initialized and not lovconfig_uuid found")
-                   
-                lovconfig_uuid = self.lmv.get_first_ref('lovconfig')
-                lovconfig = self.lmv.lookup(lovconfig_uuid)
-                lov_uuid = lovconfig.get_first_ref('lov')
-                if not lov_uuid:
-                    panic("No LOV found for lovconfig ", lovconfig.name)
-           else:
-                lovconfig = mds.lookup(lovconfig_uuid)
-                lov_uuid = lovconfig.get_first_ref('lov')
-                if not lov_uuid:
-                    panic("No LOV found for lovconfig ", lovconfig.name)
-
-               if self.lmv:
-                   lovconfig_uuid = self.lmv.get_first_ref('lovconfig')
-                   lovconfig = self.lmv.lookup(lovconfig_uuid)
-                   lov_uuid = lovconfig.get_first_ref('lov')
-
-            lov = LOV(self.db.lookup(lov_uuid), lov_uuid, 'FS_name', config_only = 1)
-
-            # default stripe count controls default inode_size
-            stripe_count = lov.stripe_cnt
-            if stripe_count > 77:
-                self.inode_size = 4096
-            elif stripe_count > 35:
-                self.inode_size = 2048
-            elif stripe_count > 13:
-                self.inode_size = 1024
-            elif stripe_count > 3:
-                self.inode_size = 512
+        if self.obdtype == None:
+            self.obdtype = 'dumb'
+       
+        self.conf_name = name
+        self.conf_uuid = uuid
+        self.realdev = self.devpath
+       
+       self.lmv = None
+        self.master = None
+       
+        lmv_uuid = self.db.get_first_ref('lmv')
+       if lmv_uuid != None:
+           self.lmv = self.db.lookup(lmv_uuid)
+           if self.lmv != None:
+                self.client_uuids = self.lmv.get_refs('client')
+
+        if self.target.get_class() == 'mds':
+           if self.target.get_val('failover', 0):
+               self.failover_mds = 'f'
+           else:
+               self.failover_mds = 'n'
+            self.format = self.db.get_val('autoformat', "no")
+        else:
+            self.format = self.db.get_val('autoformat', "yes")
+            self.osdtype = self.db.get_val('osdtype')
+            ost = self.db.lookup(target_uuid)
+            if ost.get_val('failover', 0):
+                self.failover_ost = 'f'
             else:
-                self.inode_size = 256
+                self.failover_ost = 'n'
 
-        self.target_dev_uuid = self.uuid
-        self.uuid = target_uuid
-       # setup LMV
-       if self.master_mds:
-            client_uuid = generate_client_uuid(self.name)
-           client_uuid = self.name + "_lmv_" + "UUID"
-           self.master = LMV(self.db.lookup(self.lmv_uuid), client_uuid, self.name, self.name)
-           self.master_mds = self.master.name
-
-        # modules
-        self.add_lustre_module('mdc', 'mdc')
-        self.add_lustre_module('osc', 'osc')
-        self.add_lustre_module('lov', 'lov')
-        self.add_lustre_module('lmv', 'lmv')
-        self.add_lustre_module('ost', 'ost')
-        self.add_lustre_module('mds', 'mds')
+       self.inode_size = self.get_inode_size()
 
-        if self.fstype == 'smfs':
-            self.add_lustre_module('smfs', 'smfs')
-        
-        if self.fstype == 'ldiskfs':
-            self.add_lustre_module('ldiskfs', 'ldiskfs')
+       if self.lmv != None:
+           client_uuid = self.name + "_lmv_UUID"
+           self.master = LMV(self.lmv, client_uuid, 
+                             self.conf_name, self.conf_name)
 
-        if self.fstype:
-            self.add_lustre_module('lvfs', 'fsfilt_%s' % (self.fstype))
+    def get_inode_size(self):
+        inode_size = self.db.get_val_int('inodesize', 0)
+        if inode_size == 0 and self.target.get_class() == 'mds':
+       
+           # default inode size for case when neither LOV either 
+           # LMV is accessible.
+           self.inode_size = 256
+           
+            # find the LOV for this MDS
+            lovconfig_uuid = self.target.get_first_ref('lovconfig')
+            if lovconfig_uuid or self.lmv != None:
+                if self.lmv != None:
+                    lovconfig_uuid = self.lmv.get_first_ref('lovconfig')
+                    lovconfig = self.lmv.lookup(lovconfig_uuid)
+                    lov_uuid = lovconfig.get_first_ref('lov')
+                    if lov_uuid == None:
+                        panic(self.target.getName() + ": No LOV found for lovconfig ", 
+                              lovconfig.name)
+               else:
+                    lovconfig = self.target.lookup(lovconfig_uuid)
+                    lov_uuid = lovconfig.get_first_ref('lov')
+                    if lov_uuid == None:
+                       panic(self.target.getName() + ": No LOV found for lovconfig ", 
+                             lovconfig.name)
+                   if self.lmv != None:
+                       lovconfig_uuid = self.lmv.get_first_ref('lovconfig')
+                       lovconfig = self.lmv.lookup(lovconfig_uuid)
+                       lov_uuid = lovconfig.get_first_ref('lov')
+
+                lov = LOV(self.db.lookup(lov_uuid), lov_uuid, self.name, 
+                          config_only = 1)
+
+                # default stripe count controls default inode_size
+               if lov.stripe_cnt > 0:
+                   stripe_count = lov.stripe_cnt
+               else:
+                   stripe_count = len(lov.devlist)
+                if stripe_count > 77:
+                    inode_size = 4096
+                elif stripe_count > 35:
+                    inode_size = 2048
+                elif stripe_count > 13:
+                    inode_size = 1024
+                elif stripe_count > 3:
+                    inode_size = 512
+                else:
+                    inode_size = 256
+                   
+       return inode_size
+           
+    def get_mount_options(self, blkdev):
+        options = def_mount_options(self.fstype, 
+                                   self.target.get_class())
+            
+        if config.mountfsoptions:
+            if options:
+                options = "%s,%s" %(options, config.mountfsoptions)
+            else:
+                options = config.mountfsoptions
+            if self.mountfsoptions:
+                options = "%s,%s" %(options, self.mountfsoptions)
+        else:
+            if self.mountfsoptions:
+                if options:
+                    options = "%s,%s" %(options, self.mountfsoptions)
+                else:
+                    options = self.mountfsoptions
             
-        # if fstype is smfs, then we should also take care about backing 
-        # store fs.
         if self.fstype == 'smfs':
-            self.add_lustre_module('lvfs', 'fsfilt_%s' % (self.backfstype))
-
-    def load_module(self):
-        if self.active:
-            Module.load_module(self)
+            if options:
+                options = "%s,type=%s,dev=%s" %(options, self.backfstype, 
+                                               blkdev)
+            else:
+                options = "type=%s,dev=%s" %(self.backfstype, 
+                                            blkdev)
+        
+       if self.target.get_class() == 'mds':
+           if options:
+               options = "%s,acl,user_xattr,iopen_nopriv" %(options)
+           else:
+               options = "iopen_nopriv"
+           
+       return options
 
     def prepare(self):
-        if not config.record and is_prepared(self.name):
-            return
-        if not self.active:
-            debug(self.uuid, "not active")
+        if is_prepared(self.name):
             return
-        if config.reformat:
-            # run write_conf automatically, if --reformat used
-            self.write_conf()
-        self.info(self.devpath, self.fstype, self.size, self.format)
-        run_acceptors()
-       # prepare LMV
-       if self.master_mds:
-             self.master.prepare()
-        # never reformat here
-        blkdev = block_dev(self.devpath, self.size, self.fstype, 0,
-                           self.format, self.journal_size, self.inode_size,
-                           self.mkfsoptions, self.backfstype, self.backdevpath)
         
-        if not is_prepared('MDT'):
-            lctl.newdev("mdt", 'MDT', 'MDT_UUID', setup ="")
-        try: 
-            mountfsoptions = def_mount_options(self.fstype, 'mds')
-            
-            if config.mountfsoptions:
-                if mountfsoptions:
-                    mountfsoptions = mountfsoptions + ',' + config.mountfsoptions
-                else:
-                    mountfsoptions = config.mountfsoptions
-                if self.mountfsoptions:
-                    mountfsoptions = mountfsoptions + ',' + self.mountfsoptions
-            else:
-                if self.mountfsoptions:
-                    if mountfsoptions:
-                        mountfsoptions = mountfsoptions + ',' + self.mountfsoptions
-                    else:
-                        mountfsoptions = self.mountfsoptions
-            
-            if self.fstype == 'smfs':
-                realdev = self.fstype
-                
-                if mountfsoptions:
-                    mountfsoptions = "%s,type=%s,dev=%s" % (mountfsoptions, 
-                                                            self.backfstype, 
-                                                            blkdev)
-                else:
-                    mountfsoptions = "type=%s,dev=%s" % (self.backfstype, 
-                                                         blkdev)
-            else:
-                realdev = blkdev
-                
-            print 'MDS mount options: ' + mountfsoptions
-            
-           if not self.master_mds:
-                self.master_mds = 'dumb'           
-            if not self.cachetype:
-                self.cachetype = 'dumb'
-           lctl.newdev("mds", self.name, self.uuid,
-                        setup ="%s %s %s %s %s %s" %(realdev, self.fstype, 
-                                               self.name, mountfsoptions,
-                                               self.master_mds, self.cachetype))
-        except CommandError, e:
-            if e.rc == 2:
-                panic("MDS is missing the config log. Need to run " +
-                       "lconf --write_conf.")
-            else:
-                raise e
+        blkdev = block_dev(self.devpath, self.size, self.fstype,
+                           config.reformat, self.format, self.journal_size,
+                           self.inode_size, self.mkfsoptions, self.backfstype,
+                           self.backdevpath)
 
-    def write_conf(self):
-        do_cleanup = 0
-        if not is_prepared(self.name):
-            self.info(self.devpath, self.fstype, self.format)
+        if self.fstype == 'smfs':
+            realdev = blkdev
+        else:
+            realdev = blkdev
+               
+       mountfsoptions = self.get_mount_options(blkdev)
 
-            blkdev = block_dev(self.devpath, self.size, self.fstype,
-                               config.reformat, self.format, self.journal_size,
-                               self.inode_size, self.mkfsoptions,
-                               self.backfstype, self.backdevpath)
+       self.info(self.target.get_class(), realdev, mountfsoptions, 
+                 self.fstype, self.size, self.format)
 
-            # Even for writing logs we mount mds with supplied mount options
-            # because it will not mount smfs (if used) otherwise.
+        lctl.newdev("confobd", self.name, self.uuid, 
+                   setup ="%s %s %s" %(realdev, self.fstype, 
+                                       mountfsoptions))
 
-            mountfsoptions = def_mount_options(self.fstype, 'mds')
+        self.mountfsoptions = mountfsoptions
+        self.realdev = realdev
 
-            if config.mountfsoptions:
-                if mountfsoptions:
-                    mountfsoptions = mountfsoptions + ',' + config.mountfsoptions
-                else:
-                    mountfsoptions = config.mountfsoptions
-                if self.mountfsoptions:
-                    mountfsoptions = mountfsoptions + ',' + self.mountfsoptions
-            else:
-                if self.mountfsoptions:
-                    if mountfsoptions:
-                        mountfsoptions = mountfsoptions + ',' + self.mountfsoptions
-                    else:
-                        mountfsoptions = self.mountfsoptions
+    def add_module(self, manager):
+       manager.add_lustre_module('obdclass', 'confobd')
 
-            if self.fstype == 'smfs':
-                realdev = self.fstype
-                
-                if mountfsoptions:
-                    mountfsoptions = "%s,type=%s,dev=%s" % (mountfsoptions, 
-                                                            self.backfstype, 
-                                                            blkdev)
-                else:
-                    mountfsoptions = "type=%s,dev=%s" % (self.backfstype, 
-                                                         blkdev)
-            else:
-                realdev = blkdev
-       
-                print 'MDS mount options: ' + mountfsoptions
-
-            # As mount options are passed by 4th param to config tool, we need 
-            # to pass something in 3rd param. But we do not want this 3rd param
-            # be counted as a profile name for reading log on MDS setup, thus,
-            # we pass there some predefined sign like 'dumb', which will be 
-            # checked in MDS code and skipped. Probably there is more nice way
-            # like pass empty string and check it in config tool and pass null
-            # as 4th param.
-            lctl.newdev("mds", self.name, self.uuid,
-                        setup ="%s %s %s %s" %(realdev, self.fstype, 
-                                               'dumb', mountfsoptions))
-            do_cleanup = 1
-
-        # record logs for the MDS lov
-        for uuid in self.filesystem_uuids:
-            log("recording clients for filesystem:", uuid)
-            fs = self.db.lookup(uuid)
-
-            # this is ugly, should be organized nice later.
-            target_uuid = self.db.get_first_ref('target')
-            mds = self.db.lookup(target_uuid)
-            
-            lovconfig_uuid = mds.get_first_ref('lovconfig')
-            if lovconfig_uuid:
-                lovconfig = mds.lookup(lovconfig_uuid)
-                obd_uuid = lovconfig.get_first_ref('lov')
-            else:
-                obd_uuid = fs.get_first_ref('obd')
-                
+    def write_conf(self):
+        if self.target.get_class() == 'ost':
+            config.record = 1
+            lctl.clear_log(self.name, self.target.getName() + '-conf')
+            lctl.record(self.name, self.target.getName() + '-conf')
+            lctl.newdev(self.osdtype, self.conf_name, self.conf_uuid,
+                        setup ="%s %s %s %s" %(self.realdev, self.fstype,
+                                               self.failover_ost,
+                                               self.mountfsoptions))
+            lctl.end_record()
+            lctl.clear_log(self.name, 'OSS-conf')
+            lctl.record(self.name, 'OSS-conf')
+            lctl.newdev("ost", 'OSS', 'OSS_UUID', setup ="")
+            lctl.end_record()
+            config.record = 0
+            return
+
+        if self.target.get_class() == 'mds':
+           if self.master != None:
+               master_name = self.master.name
+           else:
+               master_name = 'dumb'
+
+           config.record = 1
+            lctl.clear_log(self.name, self.target.getName() + '-conf')
+            lctl.record(self.name, self.target.getName() + '-conf')
+            lctl.attach("mds", self.conf_name, self.conf_uuid)
+            if self.mds_sec:
+                lctl.set_security(self.conf_name, "mds_sec", self.mds_sec)
+            if self.oss_sec:
+                lctl.set_security(self.conf_name, "oss_sec", self.oss_sec)
+            if self.deny_sec:
+                for flavor in string.split(self.deny_sec, ','):
+                    lctl.set_security(self.conf_name, "deny_sec", flavor)
+            lctl.newdev("mds", self.conf_name, self.conf_uuid,
+                        setup ="%s %s %s %s %s %s" %(self.realdev, self.fstype,
+                                                    self.conf_name, self.mountfsoptions,
+                                                    master_name, self.obdtype))
+            lctl.end_record()
+            config.record = 0
+
+        if not self.client_uuids:
+            return 0
+
+        for uuid in self.client_uuids:
+            log("recording client:", uuid)
             client_uuid = generate_client_uuid(self.name)
-            client = VOSC(self.db.lookup(obd_uuid), client_uuid, self.name,
-                          self.name)
+            client = VOSC(self.db.lookup(uuid), client_uuid, 
+                         self.target.getName(), self.name)
             config.record = 1
-            lctl.clear_log(self.name, self.name)
-            lctl.record(self.name, self.name)
+            lctl.clear_log(self.name, self.target.getName())
+            lctl.record(self.name, self.target.getName())
             client.prepare()
-            lctl.mount_option(self.name, client.get_name(), "")
+            lctl.mount_option(self.target.getName(), client.get_name(), "")
             lctl.end_record()
-            process_updates(self.db, self.name, self.name, client)
 
             config.cleanup = 1
-            lctl.clear_log(self.name, self.name + '-clean')
-            lctl.record(self.name, self.name + '-clean')
+            lctl.clear_log(self.name, self.target.getName() + '-clean')
+            lctl.record(self.name, self.target.getName() + '-clean')
             client.cleanup()
-            lctl.del_mount_option(self.name)
+            lctl.del_mount_option(self.target.getName())
             lctl.end_record()
-            process_updates(self.db, self.name, self.name + '-clean', client)
             config.cleanup = 0
             config.record = 0
 
-        # record logs for each client
-        if config.noexec:
-            noexec_opt = '-n'
-        else:
-            noexec_opt = ''
-        if config.ldapurl:
-            config_options = "--ldapurl " + config.ldapurl + " --config " + config.config
-        else:
-            config_options = CONFIG_FILE
+        if config.record:
+            return
+
+        # record logs for each client
+        if config.ldapurl:
+            config_options = "--ldapurl " + config.ldapurl + " --config " + config.config
+        else:
+            config_options = CONFIG_FILE
+
+        for node_db in self.db.lookup_class('node'):
+            client_name = node_db.getName()
+            for prof_uuid in node_db.get_refs('profile'):
+                prof_db = node_db.lookup(prof_uuid)
+                # refactor this into a funtion to test "clientness"
+                # of a node.
+                for ref_class, ref_uuid in prof_db.get_all_refs():
+                    if ref_class in ('mountpoint','echoclient'):
+                        debug("recording", client_name)
+                        old_noexec = config.noexec
+                        config.noexec = 0
+                        noexec_opt = ('', '-n')
+                        ret, out = run (sys.argv[0],
+                                        noexec_opt[old_noexec == 1],
+                                        " -v --record --nomod",
+                                        "--record_log", client_name,
+                                        "--record_device", self.name,
+                                        "--node", client_name,
+                                        config_options)
+                        if config.verbose:
+                            for s in out: log("record> ", string.strip(s))
+                        ret, out = run (sys.argv[0],
+                                        noexec_opt[old_noexec == 1],
+                                        "--cleanup -v --record --nomod",
+                                        "--record_log", client_name + "-clean",
+                                        "--record_device", self.name,
+                                        "--node", client_name,
+                                        config_options)
+                        if config.verbose:
+                            for s in out: log("record> ", string.strip(s))
+                        config.noexec = old_noexec
+
+    def start(self):
+         try:
+            lctl.start(self.name, self.conf_name)
+         except CommandError, e:
+            raise e
+         if self.target.get_class() == 'ost':
+             if not is_prepared('OSS'):
+                 try:
+                     lctl.start(self.name, 'OSS')
+                 except CommandError, e:
+                     raise e
+
+    def cleanup(self):
+        if is_prepared(self.name):
+            try:
+                lctl.cleanup(self.name, self.uuid, 0, 0)
+               clean_dev(self.devpath, self.fstype, 
+                         self.backfstype, self.backdevpath)
+            except CommandError, e:
+                log(self.module_name, "cleanup failed: ", self.name)
+                e.dump()
+                cleanup_error(e.rc)
+                Module.cleanup(self)
+
+class MDSDEV(Module):
+    def __init__(self,db):
+        Module.__init__(self, 'MDSDEV', db)
+        self.devpath = self.db.get_val('devpath','')
+        self.backdevpath = self.db.get_val('devpath','')
+        self.size = self.db.get_val_int('devsize', 0)
+        self.journal_size = self.db.get_val_int('journalsize', 0)
+        self.fstype = self.db.get_val('fstype', '')
+        self.backfstype = self.db.get_val('backfstype', '')
+        self.nspath = self.db.get_val('nspath', '')
+        self.mkfsoptions = self.db.get_val('mkfsoptions', '')
+        self.mountfsoptions = self.db.get_val('mountfsoptions', '')
+        self.obdtype = self.db.get_val('obdtype', '')
+        self.root_squash = self.db.get_val('root_squash', '')
+        self.no_root_squash = self.db.get_val('no_root_squash', '')
+
+        target_uuid = self.db.get_first_ref('target')
+        self.target = self.db.lookup(target_uuid)
+        self.name = self.target.getName()
+        self.master = None
+       self.lmv = None
+       
+        lmv_uuid = self.db.get_first_ref('lmv')
+       if lmv_uuid != None:
+           self.lmv = self.db.lookup(lmv_uuid)
+
+        active_uuid = get_active_target(self.target)
+        if not active_uuid:
+            panic("No target device found:", target_uuid)
+        if active_uuid == self.uuid:
+            self.active = 1
+           group = self.target.get_val('group')
+           if config.group and config.group != group:
+               self.active = 0
+        else:
+            self.active = 0
+
+        self.uuid = target_uuid
+
+       # setup LMV
+       if self.lmv != None:
+           client_uuid = self.name + "_lmv_UUID"
+           self.master = LMV(self.lmv, client_uuid, 
+                             self.name, self.name)
+                             
+        self.confobd = CONFDEV(self.db, self.name, 
+                              target_uuid, self.uuid)
+
+    def add_module(self, manager):
+        if self.active:
+            manager.add_lustre_module('mdc', 'mdc')
+            manager.add_lustre_module('osc', 'osc')
+            manager.add_lustre_module('ost', 'ost')
+            manager.add_lustre_module('lov', 'lov')
+            manager.add_lustre_module('mds', 'mds')
+
+            if self.fstype == 'smfs' or self.fstype == 'ldiskfs':
+                manager.add_lustre_module(self.fstype, self.fstype)
+               
+            if self.fstype:
+                manager.add_lustre_module('lvfs', 'fsfilt_%s' % (self.fstype))
+            
+            # if fstype is smfs, then we should also take care about backing 
+            # store fs.
+            if self.fstype == 'smfs':
+                manager.add_lustre_module(self.backfstype, self.backfstype)
+                manager.add_lustre_module('lvfs', 'fsfilt_%s' % (self.backfstype))
+
+           for option in string.split(self.mountfsoptions, ','):
+               if option == 'snap':
+                   if not self.fstype == 'smfs':
+                       panic("mountoptions has 'snap', but fstype is not smfs.")
+                   manager.add_lustre_module('lvfs', 'fsfilt_snap_%s' % (self.fstype))
+                   manager.add_lustre_module('lvfs', 'fsfilt_snap_%s' % (self.backfstype))
+
+       # add LMV modules
+       if self.master != None:
+            self.master.add_module(manager)
+       # add CONFOBD modules
+       if self.confobd != None:
+            self.confobd.add_module(manager)
+           
+    def write_conf(self):
+        if is_prepared(self.name):
+            return
+        if not self.active:
+            debug(self.uuid, "not active")
+            return
+        run_acceptors()
+        self.confobd.prepare()
+        self.confobd.write_conf()
+        self.confobd.cleanup()
+
+    def prepare(self):
+        if is_prepared(self.name):
+            return
+        if not self.active:
+            debug(self.uuid, "not active")
+            return
+        run_acceptors()
+
+        self.confobd.prepare()
+        if config.reformat:
+            self.confobd.write_conf()
 
-        for node_db in self.db.lookup_class('node'):
-            client_name = node_db.getName()
-            for prof_uuid in node_db.get_refs('profile'):
-                prof_db = node_db.lookup(prof_uuid)
-                # refactor this into a funtion to test "clientness"
-                # of a node.
-                for ref_class, ref_uuid in prof_db.get_all_refs():
-                    if ref_class in ('mountpoint','echoclient'):
-                        debug("recording", client_name)
-                        old_noexec = config.noexec
-                        config.noexec = 0
-                        ret, out = run (sys.argv[0], noexec_opt,
-                                        " -v --record --nomod",
-                                        "--record_log", client_name,
-                                        "--record_device", self.name,
-                                        "--node", client_name,
-                                        config_options)
-                        if config.verbose:
-                            for s in out: log("record> ", string.strip(s))
-                        ret, out = run (sys.argv[0], noexec_opt,
-                                        "--cleanup -v --record --nomod",
-                                        "--record_log", client_name + "-clean",
-                                        "--record_device", self.name,
-                                        "--node", client_name,
-                                        config_options)
-                        if config.verbose:
-                            for s in out: log("record> ", string.strip(s))
-                        config.noexec = old_noexec
-        if do_cleanup:
-            try:
-                lctl.cleanup(self.name, self.uuid, 0, 0)
-            except CommandError, e:
-                log(self.module_name, "cleanup failed: ", self.name)
-                e.dump()
-                cleanup_error(e.rc)
-                Module.cleanup(self)
-        
-            if self.fstype == 'smfs':
-                clean_loop(self.backdevpath)
+       # prepare LMV
+       if self.master != None:
+             self.master.prepare()
+
+       if not config.record:
+            self.confobd.start()
+       
+       if not is_prepared('MDT'):
+           lctl.newdev("mdt", 'MDT', 'MDT_UUID', setup ="")
+
+        if development_mode():
+            procentry = "/proc/fs/lustre/mds/lsd_upcall"
+            upcall = os.path.abspath(os.path.dirname(sys.argv[0]) + "/lsd_upcall")
+            if not (os.access(procentry, os.R_OK) and os.access(upcall, os.R_OK)):
+                print "MDS Warning: failed to set lsd cache upcall"
             else:
-                clean_loop(self.devpath)
+                run("echo ", upcall, " > ", procentry)
+
+       if config.root_squash == None:
+            config.root_squash = self.root_squash
+        if config.no_root_squash == None:
+            config.no_root_squash = self.no_root_squash
+        if config.root_squash:
+            if config.no_root_squash:
+                nsnid = config.no_root_squash
+            else:
+                nsnid = "0"
+            lctl.root_squash(self.name, config.root_squash, nsnid)
 
     def msd_remaining(self):
         out = lctl.device_list()
@@ -1830,7 +2183,7 @@ class MDSDEV(Module):
 
     def safe_to_clean_modules(self):
         return not self.msd_remaining()
-
+        
     def cleanup(self):
         if not self.active:
             debug(self.uuid, "not active")
@@ -1846,7 +2199,7 @@ class MDSDEV(Module):
                 cleanup_error(e.rc)
                 Module.cleanup(self)
            # cleanup LMV
-           if self.master_mds:
+           if self.master != None:
                 self.master.cleanup()
         if not self.msd_remaining() and is_prepared('MDT'):
             try:
@@ -1857,22 +2210,20 @@ class MDSDEV(Module):
                 e.dump()
                 cleanup_error(e.rc)
         
-        if self.fstype == 'smfs':
-            clean_loop(self.backdevpath)
-        else:
-            clean_loop(self.devpath)
+        if self.confobd:
+            self.confobd.cleanup()
 
     def correct_level(self, level, op=None):
-       #if self.master_mds:
+       #if self.master != None:
        #   level = level + 2
         return level
-
+       
 class OSD(Module):
     def __init__(self, db):
         Module.__init__(self, 'OSD', db)
         self.osdtype = self.db.get_val('osdtype')
         self.devpath = self.db.get_val('devpath', '')
-        self.backdevpath = self.db.get_val('backdevpath', '')
+        self.backdevpath = self.db.get_val('devpath', '')
         self.size = self.db.get_val_int('devsize', 0)
         self.journal_size = self.db.get_val_int('journalsize', 0)
         self.inode_size = self.db.get_val_int('inodesize', 0)
@@ -1890,93 +2241,96 @@ class OSD(Module):
         else:
             self.failover_ost = 'n'
 
+        self.deny_sec = self.db.get_val('deny_sec', '')
+
+        if config.ost_deny_sec:
+            if self.deny_sec:
+                self.deny_sec = "%s,%s" %(self.deny_sec, config.ost_deny_sec)
+            else:
+                self.deny_sec = config.ost_deny_sec
+
         active_uuid = get_active_target(ost)
         if not active_uuid:
             panic("No target device found:", target_uuid)
         if active_uuid == self.uuid:
             self.active = 1
+           group = ost.get_val('group')
+           if config.group and config.group != group:
+               self.active = 0
         else:
             self.active = 0
-        if self.active and config.group and config.group != ost.get_val('group'):
-            self.active = 0
 
-        self.target_dev_uuid = self.uuid
         self.uuid = target_uuid
-        # modules
-        self.add_lustre_module('ost', 'ost')
-        if self.fstype == 'smfs':
-            self.add_lustre_module('smfs', 'smfs')
-        # FIXME: should we default to ext3 here?
-        if self.fstype == 'ldiskfs':
-            self.add_lustre_module('ldiskfs', 'ldiskfs')
+        self.confobd = CONFDEV(self.db, self.name, 
+                              target_uuid, self.uuid)
+
+    def add_module(self, manager):
+        if not self.active:
+           return
+        manager.add_lustre_module('ost', 'ost')
+            
+        if self.fstype == 'smfs' or self.fstype == 'ldiskfs':
+            manager.add_lustre_module(self.fstype, self.fstype)
+               
         if self.fstype:
-            self.add_lustre_module('lvfs' , 'fsfilt_%s' % (self.fstype))
+            manager.add_lustre_module('lvfs' , 'fsfilt_%s' % (self.fstype))
+
         if self.fstype == 'smfs':
-            self.add_lustre_module('lvfs' , 'fsfilt_%s' % (self.backfstype))
+            manager.add_lustre_module(self.backfstype, self.backfstype)
+            manager.add_lustre_module('lvfs' , 'fsfilt_%s' % (self.backfstype))
 
-        self.add_lustre_module(self.osdtype, self.osdtype)
+       for option in self.mountfsoptions:
+           if option == 'snap':
+               if not self.fstype == 'smfs':
+                   panic("mountoptions with snap, but fstype is not smfs\n")
+               manager.add_lustre_module('lvfs', 'fsfilt_snap_%s' % (self.fstype))
+               manager.add_lustre_module('lvfs', 'fsfilt_snap_%s' % (self.backfstype))
 
-    def load_module(self):
-        if self.active:
-            Module.load_module(self)
+        manager.add_lustre_module(self.osdtype, self.osdtype)
+       
+       # add CONFOBD modules
+       if self.confobd != None:
+            self.confobd.add_module(manager)
 
-    # need to check /proc/mounts and /etc/mtab before
-    # formatting anything.
-    # FIXME: check if device is already formatted.
     def prepare(self):
         if is_prepared(self.name):
             return
         if not self.active:
             debug(self.uuid, "not active")
             return
-        self.info(self.osdtype, self.devpath, self.size, self.fstype,
-                  self.format, self.journal_size, self.inode_size)
+
         run_acceptors()
+
         if self.osdtype == 'obdecho':
-            blkdev = ''
-        else:
-            blkdev = block_dev(self.devpath, self.size, self.fstype,
-                               config.reformat, self.format, self.journal_size,
-                               self.inode_size, self.mkfsoptions, self.backfstype,
-                               self.backdevpath)
+            self.info(self.osdtype)
+            lctl.newdev("obdecho", self.name, self.uuid)
+            if not is_prepared('OSS'):
+                lctl.newdev("ost", 'OSS', 'OSS_UUID', setup="")
+       else:
+           self.confobd.prepare()
+           if config.reformat:
+               self.confobd.write_conf()
+           if not config.record:
+               self.confobd.start()        
 
-        mountfsoptions = def_mount_options(self.fstype, 'ost')
-            
-        if config.mountfsoptions:
-            if mountfsoptions:
-                mountfsoptions = mountfsoptions + ',' + config.mountfsoptions
-            else:
-                mountfsoptions = config.mountfsoptions
-            if self.mountfsoptions:
-                mountfsoptions = mountfsoptions + ',' + self.mountfsoptions
-        else:
-            if self.mountfsoptions:
-                if mountfsoptions:
-                    mountfsoptions = mountfsoptions + ',' + self.mountfsoptions
-                else:
-                    mountfsoptions = self.mountfsoptions
-            
-        if self.fstype == 'smfs':
-            realdev = self.fstype
-                
-            if mountfsoptions:
-                mountfsoptions = "%s,type=%s,dev=%s" % (mountfsoptions, 
-                                                        self.backfstype, 
-                                                        blkdev)
-            else:
-                mountfsoptions = "type=%s,dev=%s" % (self.backfstype, 
-                                                     blkdev)
-        else:
-            realdev = blkdev
-                
-        print 'OSD mount options: ' + mountfsoptions
-        
-        lctl.newdev(self.osdtype, self.name, self.uuid,
-                    setup ="%s %s %s %s" %(realdev, self.fstype,
-                                           self.failover_ost, 
-                                           mountfsoptions))
-        if not is_prepared('OSS'):
-            lctl.newdev("ost", 'OSS', 'OSS_UUID', setup ="")
+        if self.deny_sec:
+            for flavor in string.split(self.deny_sec, ','):
+                lctl.set_security(self.name, "deny_sec", flavor)
+
+    def write_conf(self):
+        if is_prepared(self.name):
+            return
+        if not self.active:
+            debug(self.uuid, "not active")
+            return
+                                                                                                               
+        run_acceptors()
+        if self.osdtype != 'obdecho':
+           self.confobd.prepare()
+           self.confobd.write_conf()
+           if not config.write_conf:
+               self.confobd.start()
+           self.confobd.cleanup()
 
     def osd_remaining(self):
         out = lctl.device_list()
@@ -1994,6 +2348,7 @@ class OSD(Module):
         if not self.active:
             debug(self.uuid, "not active")
             return
+           
         if is_prepared(self.name):
             self.info()
             try:
@@ -2011,39 +2366,29 @@ class OSD(Module):
                 print "cleanup failed: ", self.name
                 e.dump()
                 cleanup_error(e.rc)
-        if not self.osdtype == 'obdecho':
-            if self.fstype == 'smfs':
-                clean_loop(self.backdevpath)
-            else:
-                clean_loop(self.devpath)
+
+        if self.osdtype != 'obdecho':
+            if self.confobd:
+                self.confobd.cleanup()
 
     def correct_level(self, level, op=None):
         return level
 
-def mgmt_uuid_for_fs(mtpt_name):
-    if not mtpt_name:
-        return ''
-    mtpt_db = toplustreDB.lookup_name(mtpt_name)
-    fs_uuid = mtpt_db.get_first_ref('filesystem')
-    fs = toplustreDB.lookup(fs_uuid)
-    if not fs:
-        return ''
-    return fs.get_first_ref('mgmt')
-
 # Generic client module, used by OSC and MDC
 class Client(Module):
-    def __init__(self, tgtdb, uuid, module, fs_name, self_name=None,
-                 module_dir=None):
+    def __init__(self, tgtdb, uuid, module, fs_name, 
+                self_name=None, module_dir=None):
         self.target_name = tgtdb.getName()
         self.target_uuid = tgtdb.getUUID()
+        self.module_dir = module_dir
+        self.backup_targets = []
+       self.module = module
         self.db = tgtdb
-        self.active = 1
 
         self.tgt_dev_uuid = get_active_target(tgtdb)
         if not self.tgt_dev_uuid:
             panic("No target device found for target(1):", self.target_name)
 
-        self.kmod = kmod(config.lustre, config.portals)
         self._server = None
         self._connected = 0
 
@@ -2056,26 +2401,40 @@ class Client(Module):
             self.name = self_name
         self.uuid = uuid
         self.lookup_server(self.tgt_dev_uuid)
-        mgmt_uuid = mgmt_uuid_for_fs(fs_name)
-        if mgmt_uuid:
-            self.mgmt_name = mgmtcli_name_for_uuid(mgmt_uuid)
-        else:
-            self.mgmt_name = ''
+        self.lookup_backup_targets()
         self.fs_name = fs_name
-        if not module_dir:
-            module_dir = module
-        self.add_lustre_module(module_dir, module)
+        if not self.module_dir:
+            self.module_dir = module
+
+    def add_module(self, manager):
+        manager.add_lustre_module(self.module_dir, self.module)
 
     def lookup_server(self, srv_uuid):
         """ Lookup a server's network information """
         self._server_nets = get_ost_net(self.db, srv_uuid)
         if len(self._server_nets) == 0:
             panic ("Unable to find a server for:", srv_uuid)
+           
     def get_name(self):
         return self.name
+
     def get_servers(self):
         return self._server_nets
 
+    def lookup_backup_targets(self):
+        """ Lookup alternative network information """
+        prof_list = toplustreDB.get_refs('profile')
+        for prof_uuid in prof_list:
+            prof_db = toplustreDB.lookup(prof_uuid)
+            if not prof_db:
+                panic("profile:", prof_uuid, "not found.")
+            for ref_class, ref_uuid in prof_db.get_all_refs():
+                if ref_class in ('osd', 'mdsdev'):
+                    devdb = toplustreDB.lookup(ref_uuid)
+                    uuid = devdb.get_first_ref('target')
+                    if self.target_uuid == uuid and self.tgt_dev_uuid != ref_uuid:
+                        self.backup_targets.append(ref_uuid)
+
     def prepare(self, ignore_connect_failure = 0):
         self.info(self.target_uuid)
         if not config.record and is_prepared(self.name):
@@ -2093,16 +2452,32 @@ class Client(Module):
         except CommandError, e:
             if not ignore_connect_failure:
                 raise e
+
         if srv:
-            if self.permits_inactive() and (self.target_uuid in config.inactive or self.active == 0):
+            if self.target_uuid in config.inactive and self.permits_inactive():
                 debug("%s inactive" % self.target_uuid)
                 inactive_p = "inactive"
             else:
                 debug("%s active" % self.target_uuid)
                 inactive_p = ""
             lctl.newdev(self.module, self.name, self.uuid,
-                        setup ="%s %s %s %s" % (self.target_uuid, srv.nid_uuid,
-                                                inactive_p, self.mgmt_name))
+                        setup ="%s %s %s" % (self.target_uuid, srv.nid_uuid,
+                                                inactive_p))
+        for tgt_dev_uuid in self.backup_targets:
+            this_nets = get_ost_net(toplustreDB, tgt_dev_uuid)
+            if len(this_nets) == 0:
+                panic ("Unable to find a server for:", tgt_dev_uuid)
+            srv = choose_local_server(this_nets)
+            if srv:
+                lctl.connect(srv)
+            else:
+                routes = find_route(this_nets);
+                if len(routes) == 0:
+                    panic("no route to", tgt_dev_uuid)
+                for (srv, r) in routes:
+                    lctl.add_route_host(r[0]. srv.nid_uuid, r[1], r[3])
+            if srv:
+                lctl.add_conn(self.name, srv.nid_uuid);
 
     def cleanup(self):
         if is_prepared(self.name):
@@ -2119,6 +2494,15 @@ class Client(Module):
                 e.dump()
                 cleanup_error(e.rc)
 
+            for tgt_dev_uuid in self.backup_targets:
+                this_net = get_ost_net(toplustreDB, tgt_dev_uuid)
+                srv = choose_local_server(this_net)
+                if srv:
+                    lctl.disconnect(srv)
+                else:
+                    for (srv, r) in find_route(this_net):
+                        lctl.del_route_host(r[0]. srv.nid_uuid, r[1], r[3])
+
     def correct_level(self, level, op=None):
         return level
 
@@ -2144,181 +2528,162 @@ class OSC(Client):
     def permits_inactive(self):
         return 1
 
-def mgmtcli_name_for_uuid(uuid):
-    return 'MGMTCLI_%s' % uuid
-
-class ManagementClient(Client):
-    def __init__(self, db, uuid):
-        Client.__init__(self, db, uuid, 'mgmt_cli', '',
-                        self_name = mgmtcli_name_for_uuid(db.getUUID()),
-                        module_dir = 'mgmt')
-class VLOV(Module):
-    def __init__(self, db, uuid, fs_name, name_override = None, config_only = None):
-        Module.__init__(self, 'VLOV', db)
-        if name_override != None:
-            self.name = "lov_%s" % name_override
-        self.add_lustre_module('lov', 'lov')
-        self.stripe_sz = 65536 
-        self.stripe_off = 0 
-        self.pattern =  0
-        self.stripe_cnt = 1 
-        self.desc_uuid = self.uuid
-        self.uuid = generate_client_uuid(self.name)
-        self.fs_name = fs_name
-        self.osc = get_osc(db, self.uuid, fs_name)
-        if not self.osc:        
-           panic('osc not found:', self.uuid)
-       if config_only:
-            self.config_only = 1
-            return
-        self.config_only = None
-    def get_uuid(self):
-        return self.uuid
-    def get_name(self):
-        return self.name
-    def prepare(self):
-        if not config.record and is_prepared(self.name):
-            return
-        lctl.lov_setup(self.name, self.uuid, self.desc_uuid, self.stripe_cnt,
-                       self.stripe_sz, self.stripe_off, self.pattern)
-        target_uuid = self.osc.target_uuid
-        try:
-           self.osc.active = 1 
-            self.osc.prepare(ignore_connect_failure=0)
-        except CommandError, e:
-            print "Error preparing OSC %s\n" % osc.uuid
-            raise e
-        lctl.lov_add_obd(self.name, self.uuid, target_uuid, 0, 1)
-
-    def cleanup(self):
-        target_uuid = self.osc.target_uuid
-        self.osc.cleanup()
-        if is_prepared(self.name):
-            Module.cleanup(self)
-        if self.config_only:
-            panic("Can't clean up config_only LOV ", self.name)
-
-    def load_module(self):
-        if self.config_only:
-            panic("Can't load modules for config_only LOV ", self.name)
-        self.osc.load_module()
-        Module.load_module(self)
-
-    def cleanup_module(self):
-        if self.config_only:
-            panic("Can't cleanup modules for config_only LOV ", self.name)
-        Module.cleanup_module(self)
-        self.osc.cleanup_module()
-
-    def correct_level(self, level, op=None):
-        return level
-
 class CMOBD(Module):
-    def __init__(self,db):
+    def __init__(self, db):
        Module.__init__(self, 'CMOBD', db)
        self.name = self.db.getName(); 
        self.uuid = generate_client_uuid(self.name)
        self.master_uuid = self.db.get_first_ref('masterobd')
        self.cache_uuid = self.db.get_first_ref('cacheobd')
-       self.add_lustre_module('cmobd', 'cmobd')
+
        master_obd = self.db.lookup(self.master_uuid)
        if not master_obd:
            panic('master obd not found:', self.master_uuid)
+
        cache_obd = self.db.lookup(self.cache_uuid)
        if not cache_obd:
            panic('cache obd not found:', self.cache_uuid)
-       
-       if master_obd.get_class() == 'ost':
-           self.client_uuid = generate_client_uuid(self.name) 
-           self.master= VLOV(master_obd, self.client_uuid, self.name, 
-                           "%s_master" % (self.name))
-           self.master_uuid = self.master.get_uuid()
-       else:
+           
+       self.master = None
+       self.cache = None
+            
+        master_class = master_obd.get_class()
+        cache_class = cache_obd.get_class()
+
+       if master_class == 'ost' or master_class == 'lov':
+           client_uuid = "%s_lov_master_UUID" % (self.name)
+            self.master = LOV(master_obd, client_uuid, self.name);
+        elif master_class == 'mds':
            self.master = get_mdc(db, self.name, self.master_uuid) 
-    # need to check /proc/mounts and /etc/mtab before
-    # formatting anything.
-    # FIXME: check if device is already formatted.
+        elif master_class == 'lmv':
+           #tmp fix: cobd and cmobd will use same uuid, so use const name here
+           client_uuid = "%s_lmv_master_UUID" % "master" 
+            self.master = LMV(master_obd, client_uuid, self.name);
+       else:
+           panic("unknown master obd class '%s'" %(master_class))
+           
+       if cache_class == 'ost' or cache_class == 'lov':
+           client_uuid = "%s_lov_cache_UUID" % (self.name)
+            self.cache = LOV(cache_obd, client_uuid, self.name);
+        elif cache_class == 'mds':
+           self.cache = get_mdc(db, self.name, self.cache_uuid)
+        elif cache_class == 'lmv':
+           client_uuid = "%s_lmv_cache_UUID" % (self.name) 
+            self.cache = LMV(cache_obd, client_uuid, self.name);
+       else:
+           panic("unknown cache obd class '%s'" %(cache_class))
+
     def prepare(self):
         self.master.prepare()
         if not config.record and is_prepared(self.name):
             return
         self.info(self.master_uuid, self.cache_uuid)
         lctl.newdev("cmobd", self.name, self.uuid,
-                    setup ="%s %s" %(self.master_uuid,
-                                     self.cache_uuid))
+                    setup ="%s %s" %(self.master.uuid,
+                                     self.cache.uuid))
+
+    def get_uuid(self):
+        return self.uuid
+       
+    def get_name(self):
+        return self.name
+       
+    def get_master_name(self):
+       return self.master.name
+           
+    def get_cache_name(self):
+        return self.cache.name
 
     def cleanup(self):
         if is_prepared(self.name):
             Module.cleanup(self)
-        self.master.cleanup()
+       if self.master:
+           self.master.cleanup()
 
-    def load_module(self):
-        self.master.load_module()
-        Module.load_module(self)
+    def add_module(self, manager):
+       manager.add_lustre_module('smfs', 'smfs')
+       manager.add_lustre_module('cmobd', 'cmobd')
+        self.master.add_module(manager)
 
-    def cleanup_module(self):
-        Module.cleanup_module(self)
-        self.master.cleanup_module()
-                                                                                                                                                                                                     
     def correct_level(self, level, op=None):
         return level
 
 class COBD(Module):
-    def __init__(self, db, uuid, name, type, name_override = None):
+    def __init__(self, db, uuid, name):
         Module.__init__(self, 'COBD', db)
         self.name = self.db.getName(); 
         self.uuid = generate_client_uuid(self.name)
-        self.real_uuid = self.db.get_first_ref('realobd')
+        self.master_uuid = self.db.get_first_ref('masterobd')
         self.cache_uuid = self.db.get_first_ref('cacheobd')
-        self.add_lustre_module('cobd', 'cobd')
-        real_obd = self.db.lookup(self.real_uuid)
-        if not real_obd:
-            panic('real obd not found:', self.real_uuid)
+
+        master_obd = self.db.lookup(self.master_uuid)
+        if not master_obd:
+            panic('master obd not found:', self.master_uuid)
+
         cache_obd = self.db.lookup(self.cache_uuid)
         if not cache_obd:
             panic('cache obd not found:', self.cache_uuid)
-        if type == 'obd':
-            self.real = LOV(real_obd, self.real_uuid, name, 
-                            "%s_real" % (self.name));
-            self.cache = LOV(cache_obd, self.cache_uuid, name, 
-                            "%s_cache" % (self.name));
-        else:
-            self.real = get_mdc(db,  name, self.real_uuid) 
-            self.cache = get_mdc(db, name, self.cache_uuid) 
-    # need to check /proc/mounts and /etc/mtab before
-    # formatting anything.
-    # FIXME: check if device is already formatted.
+           
+       self.master = None
+       self.cache = None
+
+        master_class = master_obd.get_class()
+        cache_class = cache_obd.get_class()
+
+       if master_class == 'ost' or master_class == 'lov':
+           client_uuid = "%s_lov_master_UUID" % (self.name)
+            self.master = LOV(master_obd, client_uuid, name);
+        elif master_class == 'mds':
+            self.master = get_mdc(db, name, self.master_uuid) 
+        elif master_class == 'lmv':
+           #tmp fix: cobd and cmobd will use same uuid, so use const name here
+           client_uuid = "%s_lmv_master_UUID" % "master" 
+            self.master = LMV(master_obd, client_uuid, self.name);
+       else:
+           panic("unknown master obd class '%s'" %(master_class))
+           
+       if cache_class == 'ost' or cache_class == 'lov':
+           client_uuid = "%s_lov_cache_UUID" % (self.name)
+            self.cache = LOV(cache_obd, client_uuid, name);
+        elif cache_class == 'mds':
+            self.cache = get_mdc(db, name, self.cache_uuid)
+        elif cache_class == 'lmv':
+           client_uuid = "%s_lmv_cache_UUID" % "cache" 
+            self.cache = LMV(cache_obd, client_uuid, self.name);
+       else:
+           panic("unknown cache obd class '%s'" %(cache_class))
+           
     def get_uuid(self):
         return self.uuid
+
     def get_name(self):
         return self.name
-    def get_real_name(self):
-        return self.real.name
+
+    def get_master_name(self):
+        return self.master.name
+
     def get_cache_name(self):
         return self.cache.name
+
     def prepare(self):
-        self.real.prepare()
-        self.cache.prepare()
         if not config.record and is_prepared(self.name):
             return
-        self.info(self.real_uuid, self.cache_uuid)
+       self.master.prepare()
+        self.cache.prepare()
+        self.info(self.master_uuid, self.cache_uuid)
         lctl.newdev("cobd", self.name, self.uuid,
-                    setup ="%s %s" %(self.real.name,
+                    setup ="%s %s" %(self.master.name,
                                      self.cache.name))
 
     def cleanup(self):
         if is_prepared(self.name):
             Module.cleanup(self)
-        self.real.cleanup()
+        self.master.cleanup()
         self.cache.cleanup()
 
-    def load_module(self):
-        self.real.load_module()
-        Module.load_module(self)
-
-    def cleanup_module(self):
-        Module.cleanup_module(self)
-        self.real.cleanup_module()
+    def add_module(self, manager):
+        manager.add_lustre_module('cobd', 'cobd')
+        self.master.add_module(manager)
 
 # virtual interface for  OSC and LOV
 class VOSC(Module):
@@ -2328,23 +2693,27 @@ class VOSC(Module):
             self.osc = LOV(db, client_uuid, name, name_override)
             self.type = 'lov'
         elif db.get_class() == 'cobd':
-            self.osc = COBD(db, client_uuid, name, 'obd')
+            self.osc = COBD(db, client_uuid, name)
             self.type = 'cobd'
         else:
             self.osc = OSC(db, client_uuid, name)
             self.type = 'osc'
+           
     def get_uuid(self):
         return self.osc.get_uuid()
+
     def get_name(self):
         return self.osc.get_name()
+
     def prepare(self):
         self.osc.prepare()
+       
     def cleanup(self):
         self.osc.cleanup()
-    def load_module(self):
-        self.osc.load_module()
-    def cleanup_module(self):
-        self.osc.cleanup_module()
+       
+    def add_module(self, manager):
+        self.osc.add_module(manager)
+       
     def correct_level(self, level, op=None):
         return self.osc.correct_level(level, op)
 
@@ -2353,30 +2722,33 @@ class VMDC(Module):
     def __init__(self, db, client_uuid, name, name_override = None):
         Module.__init__(self, 'VMDC', db)
         if db.get_class() == 'lmv':
-            self.mdc = LMV(db, client_uuid, name)
+            self.mdc = LMV(db, client_uuid, name, name_override)
         elif db.get_class() == 'cobd':
-            self.mdc = COBD(db, client_uuid, name, 'mds')
+            self.mdc = COBD(db, client_uuid, name)
         else:
             self.mdc = MDC(db, client_uuid, name)
+           
     def get_uuid(self):
         return self.mdc.uuid
+
     def get_name(self):
         return self.mdc.name
+
     def prepare(self):
         self.mdc.prepare()
+       
     def cleanup(self):
         self.mdc.cleanup()
-    def load_module(self):
-        self.mdc.load_module()
-    def cleanup_module(self):
-        self.mdc.cleanup_module()
+       
+    def add_module(self, manager):
+        self.mdc.add_module(manager)
+       
     def correct_level(self, level, op=None):
         return self.mdc.correct_level(level, op)
 
 class ECHO_CLIENT(Module):
     def __init__(self,db):
         Module.__init__(self, 'ECHO_CLIENT', db)
-        self.add_lustre_module('obdecho', 'obdecho')
         self.obd_uuid = self.db.get_first_ref('obd')
         obd = self.db.lookup(self.obd_uuid)
         self.uuid = generate_client_uuid(self.name)
@@ -2397,13 +2769,9 @@ class ECHO_CLIENT(Module):
             Module.cleanup(self)
         self.osc.cleanup()
 
-    def load_module(self):
-        self.osc.load_module()
-        Module.load_module(self)
-
-    def cleanup_module(self):
-        Module.cleanup_module(self)
-        self.osc.cleanup_module()
+    def add_module(self, manager):
+        self.osc.add_module(manager)
+        manager.add_lustre_module('obdecho', 'obdecho')
 
     def correct_level(self, level, op=None):
         return level
@@ -2419,15 +2787,22 @@ class Mountpoint(Module):
     def __init__(self,db):
         Module.__init__(self, 'MTPT', db)
         self.path = self.db.get_val('path')
+        self.clientoptions = self.db.get_val('clientoptions', '')
         self.fs_uuid = self.db.get_first_ref('filesystem')
         fs = self.db.lookup(self.fs_uuid)
         self.mds_uuid = fs.get_first_ref('lmv')
        if not self.mds_uuid:
            self.mds_uuid = fs.get_first_ref('mds')
         self.obd_uuid = fs.get_first_ref('obd')
-        self.mgmt_uuid = fs.get_first_ref('mgmt')
         client_uuid = generate_client_uuid(self.name)
 
+        self.oss_sec = self.db.get_val('oss_sec','null')
+        self.mds_sec = self.db.get_val('mds_sec','null')
+        if config.mds_sec:
+            self.mds_sec = config.mds_sec
+        if config.oss_sec:
+            self.oss_sec = config.oss_sec
+
         ost = self.db.lookup(self.obd_uuid)
         if not ost:
             panic("no ost: ", self.obd_uuid)
@@ -2436,36 +2811,38 @@ class Mountpoint(Module):
        if not mds:
            panic("no mds: ", self.mds_uuid)
        
-        self.add_lustre_module('mdc', 'mdc')
-        self.add_lustre_module('lmv', 'lmv')
-        self.add_lustre_module('llite', 'llite')
+        self.vosc = VOSC(ost, client_uuid, self.name, self.name)
+       self.vmdc = VMDC(mds, client_uuid, self.name, self.name)
         
-        self.vosc = VOSC(ost, client_uuid, self.name)
-       self.vmdc = VMDC(mds, client_uuid, self.name)
-        
-        if self.mgmt_uuid:
-            self.mgmtcli = ManagementClient(db.lookup(self.mgmt_uuid),
-                                            client_uuid)
-        else:
-            self.mgmtcli = None
-
     def prepare(self):
         if not config.record and fs_is_mounted(self.path):
             log(self.path, "already mounted.")
             return
         run_acceptors()
-        if self.mgmtcli:
-            self.mgmtcli.prepare()
-        self.vosc.prepare()
+
+       self.vosc.prepare()
         self.vmdc.prepare()
-        vmdc_name = self.vmdc.get_name()
 
         self.info(self.path, self.mds_uuid, self.obd_uuid)
         if config.record or config.lctl_dump:
-            lctl.mount_option(local_node_name, self.vosc.get_name(), vmdc_name)
+            lctl.mount_option(local_node_name, self.vosc.get_name(), 
+                             self.vmdc.get_name())
             return
-        cmd = "mount -t lustre_lite -o osc=%s,mdc=%s %s %s" % \
-              (self.vosc.get_name(), vmdc_name, config.config, self.path)
+
+        if config.clientoptions:
+            if self.clientoptions:
+                self.clientoptions = self.clientoptions + ',' + config.clientoptions
+            else:
+                self.clientoptions = config.clientoptions
+        if self.clientoptions:
+            self.clientoptions = ',' + self.clientoptions
+            # Linux kernel will deal with async and not pass it to ll_fill_super,
+            # so replace it with Lustre async
+            self.clientoptions = string.replace(self.clientoptions, "async", "lasync")
+
+        cmd = "mount -t lustre_lite -o osc=%s,mdc=%s,mds_sec=%s,oss_sec=%s%s %s %s" % \
+              (self.vosc.get_name(), self.vmdc.get_name(), self.mds_sec,
+              self.oss_sec, self.clientoptions, config.config, self.path)
         run("mkdir", self.path)
         ret, val = run(cmd)
         if ret:
@@ -2492,20 +2869,11 @@ class Mountpoint(Module):
 
         self.vmdc.cleanup()
         self.vosc.cleanup()
-        if self.mgmtcli:
-            self.mgmtcli.cleanup()
 
-    def load_module(self):
-        if self.mgmtcli:
-            self.mgmtcli.load_module()
-        self.vosc.load_module()
-        Module.load_module(self)
-
-    def cleanup_module(self):
-        Module.cleanup_module(self)
-        self.vosc.cleanup_module()
-        if self.mgmtcli:
-            self.mgmtcli.cleanup_module()
+    def add_module(self, manager):
+        self.vosc.add_module(manager)
+        self.vmdc.add_module(manager)
+        manager.add_lustre_module('llite', 'llite')
 
     def correct_level(self, level, op=None):
         return level
@@ -2528,8 +2896,7 @@ def get_ost_net(self, osd_uuid):
         srv_list.append(Network(db))
     return srv_list
 
-
-# the order of iniitailization is based on level.
+# the order of iniitailization is based on level. 
 def getServiceLevel(self):
     type = self.get_class()
     ret=0;
@@ -2539,18 +2906,16 @@ def getServiceLevel(self):
         ret = 6
     elif type in ('ldlm',):
         ret = 20
-    elif type in ('mgmt',):
-        ret = 25
     elif type in ('osd', 'cobd'):
         ret = 30
     elif type in ('mdsdev',):
         ret = 40
     elif type in ('lmv',):
         ret = 45
-    elif type in ('cmobd',):
-        ret = 50 
     elif type in ('mountpoint', 'echoclient'):
-        ret = 70
+        ret = 60
+    elif type in ('cmobd',):
+        ret = 70 
     else:
         panic("Unknown type: ", type)
 
@@ -2595,6 +2960,7 @@ def get_mdc(db, fs_name, mds_uuid):
 
 ############################################################
 # routing ("rooting")
+
 # list of (nettype, cluster_id, nid)
 local_clusters = []
 
@@ -2606,11 +2972,8 @@ def find_local_clusters(node_db):
         debug("add_local", netuuid)
         local_clusters.append((srv.net_type, srv.cluster_id, srv.nid))
         if srv.port > 0:
-            if acceptors.has_key(srv.port):
-                panic("duplicate port:", srv.port)
-            acceptors[srv.port] = AcceptorHandler(srv.port, srv.net_type,
-                                                  srv.send_mem, srv.recv_mem,
-                                                  srv.irq_affinity)
+            if not acceptors.has_key(srv.port):
+                acceptors[srv.port] = AcceptorHandler(srv.port, srv.net_type)
 
 # This node is a gateway.
 is_router = 0
@@ -2686,7 +3049,7 @@ def find_route(srv_list):
             if  (r[3] <= to and to <= r[4]) and cluster_id == r[2]:
                 result.append((srv, r))
     return result
-
+           
 def get_active_target(db):
     target_uuid = db.getUUID()
     target_name = db.getName()
@@ -2702,7 +3065,7 @@ def get_server_by_nid_uuid(db,  nid_uuid):
         net = Network(n)
         if net.nid_uuid == nid_uuid:
             return net
-
+        
 
 ############################################################
 # lconf level logic
@@ -2731,8 +3094,6 @@ def newService(db):
         n = Mountpoint(db)
     elif type == 'echoclient':
         n = ECHO_CLIENT(db)
-    elif type == 'mgmt':
-        n = Management(db)
     elif type == 'lmv':
         n = LMV(db)
     else:
@@ -2741,7 +3102,7 @@ def newService(db):
 
 #
 # Prepare the system to run lustre using a particular profile
-# in a the configuration.
+# in a the configuration. 
 #  * load & the modules
 #  * setup networking for the current node
 #  * make sure partitions are in place and prepared
@@ -2751,7 +3112,7 @@ def for_each_profile(db, prof_list, operation):
     for prof_uuid in prof_list:
         prof_db = db.lookup(prof_uuid)
         if not prof_db:
-            panic("profile:", profile, "not found.")
+            panic("profile:", prof_uuid, "not found.")
         services = getServices(prof_db)
         operation(services)
 
@@ -2893,9 +3254,10 @@ def doWriteconf(services):
     #if config.nosetup:
     #    return
     for s in services:
-        if s[1].get_class() == 'mdsdev':
+        if s[1].get_class() == 'mdsdev' or s[1].get_class() == 'osd':
             n = newService(s[1])
             n.write_conf()
+            n.cleanup()
 
 def doSetup(services):
     if config.nosetup:
@@ -2913,17 +3275,36 @@ def doSetup(services):
     for n in nlist:
         n[1].prepare()
 
-def doModules(services):
+def doLoadModules(services):
+    if config.nomod:
+        return
+       
+    # adding all needed modules from all services
+    for s in services:
+        n = newService(s[1])
+        n.add_module(mod_manager)
+    
+    # loading all registered modules
+    mod_manager.load_modules()
+
+def doUnloadModules(services):
     if config.nomod:
         return
+        
+    # adding all needed modules from all services
     for s in services:
         n = newService(s[1])
-        n.load_module()
+        if n.safe_to_clean_modules():
+            n.add_module(mod_manager)
+    
+    # unloading all registered modules
+    mod_manager.cleanup_modules()
 
 def doCleanup(services):
     if config.nosetup:
         return
     slist = []
+
     for s in services:
         n = newService(s[1])
        n.level = s[0]
@@ -2934,21 +3315,13 @@ def doCleanup(services):
        nlist.append((nl, n[1]))
     nlist.sort()
     nlist.reverse()
+
     for n in nlist:
         if n[1].safe_to_clean():
             n[1].cleanup()
 
-def doUnloadModules(services):
-    if config.nomod:
-        return
-    services.reverse()
-    for s in services:
-        n = newService(s[1])
-        if n.safe_to_clean_modules():
-            n.cleanup_module()
-
 #
-# Load profile for
+# Load profile for 
 def doHost(lustreDB, hosts):
     global is_router, local_node_name
     node_db = None
@@ -2966,7 +3339,7 @@ def doHost(lustreDB, hosts):
     timeout = node_db.get_val_int('timeout', 0)
     ptldebug = node_db.get_val('ptldebug', '')
     subsystem = node_db.get_val('subsystem', '')
-
+    
     find_local_clusters(node_db)
     if not is_router:
         find_local_routes(lustreDB)
@@ -2976,11 +3349,11 @@ def doHost(lustreDB, hosts):
     prof_list = node_db.get_refs('profile')
 
     if config.write_conf:
-        lustreDB.close()
-        for_each_profile(node_db, prof_list, doModules)
+        for_each_profile(node_db, prof_list, doLoadModules)
         sys_make_devices()
         for_each_profile(node_db, prof_list, doWriteconf)
         for_each_profile(node_db, prof_list, doUnloadModules)
+        lustreDB.close()
 
     elif config.recover:
         if not (config.tgt_uuid and config.client_uuid and config.conn_uuid):
@@ -3019,7 +3392,7 @@ def doHost(lustreDB, hosts):
         sys_set_netmem_max('/proc/sys/net/core/rmem_max', MAXTCPBUF)
         sys_set_netmem_max('/proc/sys/net/core/wmem_max', MAXTCPBUF)
 
-        for_each_profile(node_db, prof_list, doModules)
+        for_each_profile(node_db, prof_list, doLoadModules)
 
         sys_set_debug_path()
         sys_set_ptldebug(ptldebug)
@@ -3073,7 +3446,7 @@ def setupModulePath(cmd, portals_dir = PORTALS_DIR):
     base = os.path.dirname(cmd)
     if development_mode():
         if not config.lustre:
-            debug('using objdir module paths')
+            debug('using objdir module paths')            
             config.lustre = (os.path.join(base, ".."))
         # normalize the portals dir, using command line arg if set
         if config.portals:
@@ -3083,7 +3456,7 @@ def setupModulePath(cmd, portals_dir = PORTALS_DIR):
         debug('config.portals', config.portals)
     elif config.lustre and config.portals:
         # production mode
-        # if --lustre and --portals, normalize portals
+        # if --lustre and --portals, normalize portals 
         # can ignore POTRALS_DIR here, since it is probly useless here
         config.portals = os.path.join(config.lustre, config.portals)
         debug('config.portals B', config.portals)
@@ -3129,6 +3502,23 @@ def sys_set_timeout(timeout):
         lctl.set_timeout(timeout)
 
 def sys_tweak_socknal ():
+    # reserve at least 8MB, or we run out of RAM in skb_alloc under read
+    if sys_get_branch() == '2.6':
+        fp = open('/proc/meminfo')
+        lines = fp.readlines()
+        fp.close()
+        memtotal = 131072
+        for l in lines:
+            a = string.split(l)
+            if a[0] == 'MemTotal:':
+                memtotal = a[1]
+               debug("memtotal" + memtotal)
+       if int(memtotal) < 262144:
+           minfree = int(memtotal) / 16
+       else:
+           minfree = 32768
+       debug("+ minfree ", minfree)
+        sysctl("vm/min_free_kbytes", minfree)
     if config.single_socket:
         sysctl("socknal/typed", 0)
 
@@ -3137,7 +3527,7 @@ def sys_optimize_elan ():
                  "/proc/qsnet/elan3/config/eventint_punt_loops",
                  "/proc/qsnet/elan4/config/elan4_mainint_punt_loops"]
     for p in procfiles:
-        if os.access(p, os.R_OK):
+        if os.access(p, os.W_OK):
             run ("echo 1 > " + p)
 
 def sys_set_ptldebug(ptldebug):
@@ -3146,7 +3536,7 @@ def sys_set_ptldebug(ptldebug):
     if ptldebug:
         try:
             val = eval(ptldebug, ptldebug_names)
-            val = "0x%x" % (val)
+            val = "0x%x" % (val & 0xffffffffL)
             sysctl('portals/debug', val)
         except NameError, e:
             panic(str(e))
@@ -3157,7 +3547,7 @@ def sys_set_subsystem(subsystem):
     if subsystem:
         try:
             val = eval(subsystem, subsystem_names)
-            val = "0x%x" % (val)
+            val = "0x%x" % (val & 0xffffffffL)
             sysctl('portals/subsystem_debug', val)
         except NameError, e:
             panic(str(e))
@@ -3174,22 +3564,20 @@ def sys_set_netmem_max(path, max):
         fp = open(path, 'w')
         fp.write('%d\n' %(max))
         fp.close()
-
-
+    
 def sys_make_devices():
     if not os.access('/dev/portals', os.R_OK):
         run('mknod /dev/portals c 10 240')
     if not os.access('/dev/obd', os.R_OK):
         run('mknod /dev/obd c 10 241')
 
-
 # Add dir to the global PATH, if not already there.
 def add_to_path(new_dir):
     syspath = string.split(os.environ['PATH'], ':')
     if new_dir in syspath:
         return
     os.environ['PATH'] = os.environ['PATH'] + ':' + new_dir
-
+    
 def default_debug_path():
     path = '/tmp/lustre-log'
     if os.path.isdir('/r'):
@@ -3204,7 +3592,6 @@ def default_gdb_script():
     else:
         return script
 
-
 DEFAULT_PATH = ('/sbin', '/usr/sbin', '/bin', '/usr/bin')
 # ensure basic elements are in the system path
 def sanitise_path():
@@ -3238,6 +3625,13 @@ lconf_options = [
     ('config', "Cluster config name used for LDAP query", PARAM),
     ('select', "service=nodeA,service2=nodeB ", PARAMLIST),
     ('node',   "Load config for <nodename>", PARAM),
+    ('sec',"security flavor <null|krb5i|krb5p> between this client with mds", PARAM),
+    ('mds_sec',"security flavor <null|krb5i|krb5p> between this client with mds", PARAM),
+    ('oss_sec',"security flavor <null|krb5i|krb5p> between this client with ost", PARAM),
+    ('mds_mds_sec',"security flavor <null|krb5i|krb5p> between this mds with other mds", PARAM),
+    ('mds_oss_sec',"security flavor <null|krb5i|krb5p> between this mds with ost", PARAM),
+    ('mds_deny_sec', "security flavor <null|krb5i|krb5p> denied by this mds", PARAM),
+    ('ost_deny_sec', "security flavor <null|krb5i|krb5p> denied by this ost", PARAM),
     ('cleanup,d', "Cleans up config. (Shutdown)"),
     ('force,f', "Forced unmounting and/or obd detach during cleanup",
                FLAG, 0),
@@ -3258,6 +3652,7 @@ lconf_options = [
     ('reformat', "Reformat all devices (without question)"),
     ('mkfsoptions', "Additional options for the mk*fs command line", PARAM),
     ('mountfsoptions', "Additional options for mount fs command line", PARAM),
+    ('clientoptions', "Additional options for Lustre", PARAM),
     ('dump',  "Dump the kernel debug log to file before portals is unloaded",
                PARAM),
     ('write_conf', "Save all the client config information on mds."),
@@ -3265,9 +3660,13 @@ lconf_options = [
     ('record_log', "Name of config record log.", PARAM),
     ('record_device', "MDS device name that will record the config commands",
               PARAM),
+    ('root_squash', "MDS squash root to appointed uid",
+              PARAM),
+    ('no_root_squash', "Don't squash root for appointed nid",
+              PARAM),
     ('minlevel', "Minimum level of services to configure/cleanup",
                  INTPARAM, 0),
-    ('maxlevel', """Maximum level of services to configure/cleanup
+    ('maxlevel', """Maximum level of services to configure/cleanup 
                     Levels are aproximatly like:
                             10 - netwrk
                             20 - device, ldlm
@@ -3298,14 +3697,14 @@ lconf_options = [
     ('inactive', """The name of an inactive service, to be ignored during
                     mounting (currently OST-only). Can be repeated.""",
                 PARAMLIST),
-    ]
+    ]      
 
 def main():
-    global lctl, config, toplustreDB, CONFIG_FILE
+    global lctl, config, toplustreDB, CONFIG_FILE, mod_manager
 
     # in the upcall this is set to SIG_IGN
     signal.signal(signal.SIGCHLD, signal.SIG_DFL)
-
+    
     cl = Lustre.Options("lconf", "config.xml", lconf_options)
     try:
         config, args = cl.parse(sys.argv[1:])
@@ -3328,7 +3727,7 @@ def main():
     random.seed(seed)
 
     sanitise_path()
-
+    
     init_select(config.select)
 
     if len(args) > 0:
@@ -3408,6 +3807,9 @@ def main():
         lctl.clear_log(config.record_device, config.record_log)
         lctl.record(config.record_device, config.record_log)
 
+    # init module manager
+    mod_manager = kmod_manager(config.lustre, config.portals)
+
     doHost(lustreDB, node_list)
 
     if not config.record:
@@ -3415,7 +3817,7 @@ def main():
 
     lctl.end_record()
 
-    process_updates(db, config.record_device, config.record_log)
+    process_updates(lustreDB, config.record_device, config.record_log)
 
 if __name__ == "__main__":
     try: