Whamcloud - gitweb
landing smfs.
[fs/lustre-release.git] / lustre / utils / lconf
index 2f4130b..d74fa4f 100755 (executable)
@@ -537,7 +537,7 @@ class LCTLInterface:
   quit""" % (type, name, uuid)
         self.run(cmds)
         
-    def setup(self,  name, setup = ""):
+    def setup(self, name, setup = ""):
         cmds = """
   cfg_device %s
   setup %s
@@ -783,8 +783,8 @@ def loop_base():
             panic ("can't access loop devices")
     return loop
     
-# find loop device assigned to thefile
-def find_loop(file):
+# find loop device assigned to the file
+def find_assigned_loop(file):
     loop = loop_base()
     for n in xrange(0, MAX_LOOP_DEVICES):
         dev = loop + str(n)
@@ -799,19 +799,29 @@ def find_loop(file):
     return ''
 
 # create file if necessary and assign the first free loop device
-def init_loop(file, size, fstype, journal_size, inode_size, mkfsoptions, reformat):
-    dev = find_loop(file)
+def init_loop(file, size, fstype, journal_size, inode_size, 
+              mkfsoptions, reformat, backfstype, backfile):
+    if fstype == 'smfs':
+        realfile = backfile
+        realfstype = backfstype
+    else:
+        realfile = file
+        realfstype = fstype
+            
+    dev = find_assigned_loop(realfile)
     if dev:
-        print 'WARNING file:', file, 'already mapped to', dev
+        print 'WARNING file:', realfile, 'already mapped to', dev
         return dev
-    if reformat or not os.access(file, os.R_OK | os.W_OK):
+            
+    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" % (file,size))
-        (ret, out) = run("dd if=/dev/zero bs=1k count=0 seek=%d of=%s" %(size,
-                                                                         file))
+            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:", file)
-        mkfs(file, size, fstype, journal_size, inode_size, mkfsoptions, isblock=0)
+            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
@@ -820,7 +830,7 @@ def init_loop(file, size, fstype, journal_size, inode_size, mkfsoptions, reforma
         if os.access(dev, os.R_OK):
             (stat, out) = run('losetup', dev)
             if stat:
-                run('losetup', dev, file)
+                run('losetup', dev, realfile)
                 return dev
         else:
             print "out of loop devices"
@@ -830,7 +840,7 @@ def init_loop(file, size, fstype, journal_size, inode_size, mkfsoptions, reforma
 
 # undo loop assignment
 def clean_loop(file):
-    dev = find_loop(file)
+    dev = find_assigned_loop(file)
     if dev:
         ret, out = run('losetup -d', dev)
         if ret:
@@ -844,11 +854,13 @@ def need_format(fstype, dev):
 
 # initialize a block device if needed
 def block_dev(dev, size, fstype, reformat, autoformat, journal_size,
-              inode_size, mkfsoptions):
-    if config.noexec: return dev
-    if not is_block(dev):
+              inode_size, mkfsoptions, backfstype, backdev):
+    if config.noexec: 
+        return dev
+        
+    if fstype == 'smfs' or not is_block(dev):
         dev = init_loop(dev, size, fstype, journal_size, inode_size,
-                        mkfsoptions, reformat)
+                        mkfsoptions, reformat, backfstype, backdev)
     elif reformat or (need_format(fstype, dev) and autoformat == 'yes'):
         mkfs(dev, size, fstype, journal_size, inode_size, mkfsoptions,
              isblock=0)
@@ -1350,11 +1362,14 @@ 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('backdevpath','')
         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', '')
         # 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)
@@ -1403,15 +1418,26 @@ class MDSDEV(Module):
 
         self.target_dev_uuid = self.uuid
         self.uuid = target_uuid
-        # modules
+
+        # loading modules
         self.add_lustre_module('mdc', 'mdc')
         self.add_lustre_module('osc', 'osc')
         self.add_lustre_module('lov', 'lov')
         self.add_lustre_module('mds', 'mds')
+
+        if self.fstype == 'smfs':
+            self.add_lustre_module('smfs', 'smfs')
+        
         if self.fstype == 'ldiskfs':
             self.add_lustre_module('ldiskfs', 'ldiskfs')
+
         if self.fstype:
             self.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':
+            self.add_lustre_module('lvfs', 'fsfilt_%s' % (self.backfstype))
 
     def load_module(self):
         if self.active:
@@ -1431,12 +1457,34 @@ class MDSDEV(Module):
         # never reformat here
         blkdev = block_dev(self.devpath, self.size, self.fstype, 0,
                            self.format, self.journal_size, self.inode_size,
-                           self.mkfsoptions)
+                           self.mkfsoptions, self.backfstype, self.backdevpath)
         if not is_prepared('MDT'):
             lctl.newdev("mdt", 'MDT', 'MDT_UUID', setup ="")
         try: 
-            lctl.newdev("mds", self.name, self.uuid,
-                        setup ="%s %s %s" %(blkdev, self.fstype, self.name))
+            if config.mountfsoptions != None:
+                mountfsoptions = config.mountfsoptions
+                if self.mountfsoptions != None:
+                    mountfsoptions = mountfsoptions + ' ' + self.mountfsoptions
+            else:
+                mountfsoptions = self.mountfsoptions
+            
+            # we count, that mountfsoptions is always not None for smfs    
+            if self.fstype == 'smfs':
+                realdev = self.fstype
+                mountfsoptions = "%s,type=%s,dev=%s" % (mountfsoptions, 
+                                                        self.backfstype, 
+                                                        blkdev)
+            else:
+                realdev = blkdev
+                
+            if mountfsoptions != None:
+                lctl.newdev("mds", self.name, self.uuid,
+                            setup ="%s %s %s %s" %(realdev, self.fstype, 
+                                                   self.name, mountfsoptions))
+            else:
+                lctl.newdev("mds", self.name, self.uuid,
+                            setup ="%s %s %s" %(realdev, self.fstype, 
+                                                self.name))
         except CommandError, e:
             if e.rc == 2:
                 panic("MDS is missing the config log. Need to run " +
@@ -1448,12 +1496,44 @@ class MDSDEV(Module):
         if is_prepared(self.name):
             return
         self.info(self.devpath, self.fstype, self.format)
+
         blkdev = block_dev(self.devpath, self.size, self.fstype,
                            config.reformat, self.format, self.journal_size,
-                           self.inode_size, self.mkfsoptions)
-        lctl.newdev("mds", self.name, self.uuid,
-                    setup ="%s %s" %(blkdev, self.fstype))
-                
+                           self.inode_size, self.mkfsoptions, self.backfstype,
+                           self.backdevpath)
+                          
+        if config.mountfsoptions != None:
+            mountfsoptions = config.mountfsoptions
+            if self.mountfsoptions != None:
+                mountfsoptions = mountfsoptions + ' ' + self.mountfsoptions
+        else:
+            mountfsoptions = self.mountfsoptions
+
+       # Even for writing logs we mount mds with supplied mount options
+       # because it will not mount smfs (if used) otherwise.
+       
+        # we count, that mountfsoptions is always not None for smfs    
+        if self.fstype == 'smfs':
+            realdev = self.fstype
+            mountfsoptions = "%s,type=%s,dev=%s" % (mountfsoptions, 
+                                                    self.backfstype, 
+                                                    blkdev)
+        else:
+            realdev = blkdev
+            
+       # 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 @dumb, which will be checked
+       # in MDS code and skipped.
+        if mountfsoptions != None:
+            lctl.newdev("mds", self.name, self.uuid,
+                        setup ="%s %s %s %s" %(realdev, self.fstype, 'dumb', 
+                                               mountfsoptions))
+        else:
+            lctl.newdev("mds", self.name, self.uuid,
+                        setup ="%s %s %s" %(realdev, self.fstype, 'dumb'))
+
         # record logs for the MDS lov
         for uuid in self.filesystem_uuids:
             log("recording clients for filesystem:", uuid)
@@ -1522,7 +1602,11 @@ class MDSDEV(Module):
             e.dump()
             cleanup_error(e.rc)
             Module.cleanup(self)
-        clean_loop(self.devpath)
+        
+        if self.fstype == 'smfs':
+            clean_loop(self.backdevpath)
+        else:
+            clean_loop(self.devpath)
  
     def msd_remaining(self):
         out = lctl.device_list()
@@ -1558,18 +1642,25 @@ class MDSDEV(Module):
                 print "cleanup failed: ", self.name
                 e.dump()
                 cleanup_error(e.rc)
-        clean_loop(self.devpath)
+        
+        if self.fstype == 'smfs':
+            clean_loop(self.backdevpath)
+        else:
+            clean_loop(self.devpath)
 
 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.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)
         self.mkfsoptions = self.db.get_val('mkfsoptions', '')
+        self.mountfsoptions = self.db.get_val('mountfsoptions', '')
         self.fstype = self.db.get_val('fstype', '')
+        self.backfstype = self.db.get_val('backfstype', '')
         self.nspath = self.db.get_val('nspath', '')
         target_uuid = self.db.get_first_ref('target')
         ost = self.db.lookup(target_uuid)
@@ -1594,11 +1685,16 @@ class OSD(Module):
         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')
         if self.fstype:
             self.add_lustre_module('lvfs' , 'fsfilt_%s' % (self.fstype))
+        if self.fstype == 'smfs':
+            self.add_lustre_module('lvfs' , 'fsfilt_%s' % (self.backfstype))
+
         self.add_lustre_module(self.osdtype, self.osdtype)
 
     def load_module(self):
@@ -1622,10 +1718,33 @@ class OSD(Module):
         else:
             blkdev = block_dev(self.devpath, self.size, self.fstype,
                                config.reformat, self.format, self.journal_size,
-                               self.inode_size, self.mkfsoptions)
-        lctl.newdev(self.osdtype, self.name, self.uuid,
-                    setup ="%s %s %s" %(blkdev, self.fstype,
-                                           self.failover_ost))
+                               self.inode_size, self.mkfsoptions, self.backfstype,
+                               self.backdevpath)
+        if config.mountfsoptions != None:
+            mountfsoptions = config.mountfsoptions
+            if self.mountfsoptions != None:
+                mountfsoptions = mountfsoptions + ' ' + self.mountfsoptions
+        else:
+            mountfsoptions = self.mountfsoptions
+
+        # we count, that mountfsoptions is always not None for smfs    
+        if self.fstype == 'smfs':
+            realdev = self.fstype
+            mountfsoptions = "%s,type=%s,dev=%s" % (mountfsoptions, 
+                                                    self.backfstype,
+                                                    blkdev)
+        else:
+            realdev = blkdev
+            
+        if mountfsoptions != None:
+            lctl.newdev(self.osdtype, self.name, self.uuid,
+                        setup ="%s %s %s %s" %(realdev, self.fstype,
+                                               self.failover_ost, 
+                                               mountfsoptions))
+        else:
+            lctl.newdev(self.osdtype, self.name, self.uuid,
+                        setup ="%s %s %s" %(realdev, self.fstype,
+                                            self.failover_ost))
         if not is_prepared('OSS'):
             lctl.newdev("ost", 'OSS', 'OSS_UUID', setup ="")
 
@@ -1663,7 +1782,10 @@ class OSD(Module):
                 e.dump()
                 cleanup_error(e.rc)
         if not self.osdtype == 'obdecho':
-            clean_loop(self.devpath)
+            if self.fstype == 'smfs':
+                clean_loop(self.backdevpath)
+            else:
+                clean_loop(self.devpath)
 
 def mgmt_uuid_for_fs(mtpt_name):
     if not mtpt_name:
@@ -2532,6 +2654,7 @@ lconf_options = [
     ('nosetup', "Skip device setup/cleanup step."),
     ('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),
     ('dump',  "Dump the kernel debug log to file before portals is unloaded",
                PARAM),
     ('write_conf', "Save all the client config information on mds."),