summarylogtreecommitdiffstats
path: root/add-cpuset-prefix.patch
blob: ba79915d2d5c3cc3ecff41c10e6856cfd812fa89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
--- a/cpuset/cset.py	2010-08-01 16:19:49.000000000 -0400
+++ b/cpuset/cset.py	2015-07-07 17:53:05.712530891 -0400
@@ -32,10 +32,13 @@
 class CpuSet(object):
     # sets is a class variable dict that keeps track of all 
     # cpusets discovered such that we can link them in properly.
-    # The basepath is it's base path, the sets are indexed via
+    # The basepath is its base path, the sets are indexed via
     # a relative path from this basepath.
+    # prefix can be empty or 'cpuset.' in case the filesystem
+    # has its own namespace
     sets = {}
     basepath = ''
+    prefix = ''
 
     def __init__(self, path=None):
         log.debug("initializing CpuSet")
@@ -47,7 +50,16 @@
             log.debug("finding all cpusets")
             path = self.locate_cpusets()
             CpuSet.basepath = path
-            log.debug("creating root node at %s", path)
+            if not os.access(path + '/cpus', os.F_OK):
+                log.debug(path + "/cpus doesn't exist, trying to add the cpuset. prefix")
+                CpuSet.prefix = 'cpuset.'
+                if not os.access(path + '/cpuset.cpus', os.F_OK):
+                    # definitely not a cpuset directory
+                    str = '%s is not a cpuset directory' % (path)
+                    log.error(str)
+                    raise CpusetException(str)
+
+            log.debug("creating root node at %s with prefix '%s'", path, CpuSet.prefix)
             self.__root = True
             self.name = 'root'
             self.path = '/'
@@ -56,6 +68,7 @@
                 del CpuSet.sets
                 CpuSet.sets = {}
             CpuSet.sets[self.path] = self
+
             # bottom-up search otherwise links will not exist
             log.debug("starting bottom-up discovery walk...")
             for dir, dirs, files in os.walk(path, topdown=False):
@@ -104,12 +117,18 @@
                 log.debug("the cpuset %s already exists, skipping", path)
                 self = CpuSet.sets[path]  # questionable....
                 return
-            cpus = CpuSet.basepath + path + "/cpus"
+            cpus = CpuSet.basepath + path + '/' + CpuSet.prefix + "cpus"
             if not os.access(cpus, os.F_OK):
-                # not a cpuset directory
-                str = '%s is not a cpuset directory' % (CpuSet.basepath + path)
-                log.error(str)
-                raise CpusetException(str)
+                log.debug(cpus + " doesn't exist, trying to add the cpuset. prefix")
+                CpuSet.prefix = 'cpuset.'
+                cpus = CpuSet.basepath + path + '/' + CpuSet.prefix + "cpus"
+                if not os.access(cpus, os.F_OK):
+                    # definitely not a cpuset directory
+                    str = '%s is not a cpuset directory' % (CpuSet.basepath + path)
+                    log.error(str)
+                    raise CpusetException(str)
+                else:
+                    log.debug(cpus + " successfully found")
             self.__root = False
             self.read_cpuset(path)
             CpuSet.sets[path] = self
@@ -158,36 +177,36 @@
         raise AttributeError, "deletion of properties not allowed"
 
     def getcpus(self): 
-        f = file(CpuSet.basepath+self.path+"/cpus")
+        f = file(CpuSet.basepath+self.path+'/'+CpuSet.prefix+"cpus")
         return f.readline()[:-1]
     def setcpus(self, newval):
         cpuspec_check(newval)
-        f = file(CpuSet.basepath+self.path+"/cpus",'w')
+        f = file(CpuSet.basepath+self.path+'/'+CpuSet.prefix+"cpus",'w')
         f.write(str(newval))
         f.close()
         log.debug("-> prop_set %s.cpus = %s", self.path, newval) 
     cpus = property(fget=getcpus, fset=setcpus, fdel=delprop, doc="CPU specifier")
 
     def getmems(self): 
-        f = file(CpuSet.basepath+self.path+"/mems")
+        f = file(CpuSet.basepath+self.path+'/'+CpuSet.prefix+"mems")
         return f.readline()[:-1]
     def setmems(self, newval): 
         # FIXME: check format for correctness
-        f = file(CpuSet.basepath+self.path+"/mems",'w')
+        f = file(CpuSet.basepath+self.path+'/'+CpuSet.prefix+"mems",'w')
         f.write(str(newval))
         f.close()
         log.debug("-> prop_set %s.mems = %s", self.path, newval) 
     mems = property(getmems, setmems, delprop, "Mem node specifier")
     
     def getcpuxlsv(self): 
-        f = file(CpuSet.basepath+self.path+"/cpu_exclusive")
+        f = file(CpuSet.basepath+self.path+'/'+CpuSet.prefix+"cpu_exclusive")
         if f.readline()[:-1] == '1':
             return True
         else:
             return False
     def setcpuxlsv(self, newval):
         log.debug("-> prop_set %s.cpu_exclusive = %s", self.path, newval) 
-        f = file(CpuSet.basepath+self.path+"/cpu_exclusive",'w')
+        f = file(CpuSet.basepath+self.path+'/'+CpuSet.prefix+"cpu_exclusive",'w')
         if newval:
             f.write('1')
         else:
@@ -197,14 +216,14 @@
                              "CPU exclusive flag")
 
     def getmemxlsv(self): 
-        f = file(CpuSet.basepath+self.path+"/mem_exclusive")
+        f = file(CpuSet.basepath+self.path+'/'+CpuSet.prefix+"mem_exclusive")
         if f.readline()[:-1] == '1':
             return True
         else:
             return False
     def setmemxlsv(self, newval):
         log.debug("-> prop_set %s.mem_exclusive = %s", self.path, newval) 
-        f = file(CpuSet.basepath+self.path+"/mem_exclusive",'w')
+        f = file(CpuSet.basepath+self.path+'/'+CpuSet.prefix+"mem_exclusive",'w')
         if newval:
             f.write('1')
         else:
@@ -214,6 +233,7 @@
                              "Memory exclusive flag")
 
     def gettasks(self):
+        # 'tasks' never seem to have a possible 'cpusets.' prefix
         f = file(CpuSet.basepath+self.path+"/tasks")
         lst = []
         for task in f: lst.append(task[:-1])
@@ -229,6 +249,7 @@
             prog = False
         for task in tasklist:
             try:
+                # 'tasks' never seem to have a possible 'cpusets.' prefix
                 f = file(CpuSet.basepath+self.path+"/tasks",'w')
                 f.write(task)
                 f.close()
@@ -513,4 +534,3 @@
         print 'Found "cantfindmenoway??!? -> ', node
     except CpusetException, err:
         print 'Caught exeption for non-existant set (correctly)-> ', err
-