One can now specify "sysctl.x.y" attributes where x.y is a kernel variable.
authorMarc Fiuczynski <mef@cs.princeton.edu>
Wed, 5 Nov 2008 22:17:22 +0000 (22:17 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Wed, 5 Nov 2008 22:17:22 +0000 (22:17 +0000)
sm.py searches for these slice attributes and adds them to the rspec.

sliver_vs.py processes these in set_resources(), but only if the new
"setup" argument to set_resources() is set to True.  By default
setup=False and should only be set to true when setting up a vserver,
as done in util-vserver-pl/python/vserver.py:__do_chcontext().  The
reason being is that it needs to write /proc/sys/x/y while within the
setup phase of a vserver context when capability checking is disabled.

sliver_vs.py
sm.py

index 17da6d0..8eed4ea 100644 (file)
@@ -17,6 +17,7 @@ don't have to guess if there is a running process or not.
 """
 
 import errno
+import traceback
 import os, os.path
 import time
 
@@ -123,7 +124,6 @@ class Sliver_VS(accounts.Account, vserver.VServer):
             refname="default"
             arch="i386"
         except:
-            import traceback
             logger.log("%s (%s) : unexpected error follows - using 'default'"%(name,vref))
             logger.log(traceback.format_exc())
             refname="default"
@@ -192,7 +192,7 @@ class Sliver_VS(accounts.Account, vserver.VServer):
     def is_running(self): 
         return vserver.VServer.is_running(self)
 
-    def set_resources(self):
+    def set_resources(self,setup=False):
         disk_max = self.rspec['disk_max']
         logger.log('%s: setting max disk usage to %d KiB' % (self.name, disk_max))
         try:  # if the sliver is over quota, .set_disk_limit will throw an exception
@@ -229,6 +229,23 @@ class Sliver_VS(accounts.Account, vserver.VServer):
         cpu_pct = self.rspec['cpu_pct']
         cpu_share = self.rspec['cpu_share']
 
+       if setup:
+          for key in self.rspec.keys():
+            if key.find('sysctl.') == 0:
+                sysctl=key.split('.')
+                try:
+                   logger.log("%s: opening /proc/sys/%s/%s"%(self.name,sysctl[1],sysctl[2]))
+                   path="/proc/sys/%s/%s" % (sysctl[1],sysctl[2])
+                   flags = os.O_WRONLY
+                   fd = os.open(path, flags)
+                   logger.log("%s: writing %s=%s"%(self.name,key,self.rspec[key]))
+                   os.write(fd,self.rspec[key])
+                   os.close(fd)
+                except IOError, e:
+                   logger.log("%s: could not set %s=%s"%(self.name,key,self.rspec[key]))
+                   logger.log("%s: error = %s"%(self.name,e))
+
+
         if self.rspec['enabled'] > 0:
             if cpu_pct > 0:
                 logger.log('%s: setting cpu reservation to %d%%' % (self.name, cpu_pct))
diff --git a/sm.py b/sm.py
index 8fab86e..3dfed2f 100644 (file)
--- a/sm.py
+++ b/sm.py
@@ -127,6 +127,11 @@ def GetSlivers(data, fullupdate=True):
             except (KeyError, ValueError): amt = default_amt
             rspec[resname] = amt
 
+        # add in sysctl attributes into the rspec
+       for key in attr_dict.keys():
+           if key.find("sysctl.") == 0:
+               rspec[key] = attr_dict[key]
+
         database.db.deliver_record(rec)
     if fullupdate: database.db.set_min_timestamp(data['timestamp'])
     database.db.sync()