Blame SOURCES/huge_page_setup_helper-python3-convert.patch

a6de77
diff --git a/huge_page_setup_helper.py b/huge_page_setup_helper.py
a6de77
index 43c9916..7ba0c92 100755
a6de77
--- a/huge_page_setup_helper.py
a6de77
+++ b/huge_page_setup_helper.py
a6de77
@@ -1,4 +1,4 @@
a6de77
-#!/usr/bin/python
a6de77
+#!/usr/bin/env python3
a6de77
 
a6de77
 #
a6de77
 # Tool to set up Linux large page support with minimal effort
a6de77
@@ -14,13 +14,13 @@ debug = False
a6de77
 
a6de77
 # must be executed under the root to operate
a6de77
 if os.geteuid() != 0:
a6de77
-    print "You must be root to setup hugepages!"
a6de77
+    print("You must be root to setup hugepages!")
a6de77
     os._exit(1)
a6de77
 
a6de77
 # config files we need access to
a6de77
 sysctlConf = "/etc/sysctl.conf"
a6de77
 if not os.access(sysctlConf, os.W_OK):
a6de77
-    print "Cannot access %s" % sysctlConf
a6de77
+    print("Cannot access %s" % sysctlConf)
a6de77
     if debug == False:
a6de77
         os._exit(1)
a6de77
 
a6de77
@@ -41,7 +41,7 @@ for line in hugeadmexplain:
a6de77
         break
a6de77
 
a6de77
 if memTotal == 0:
a6de77
-    print "Your version of libhugetlbfs' hugeadm utility is too old!"
a6de77
+    print("Your version of libhugetlbfs' hugeadm utility is too old!")
a6de77
     os._exit(1)
a6de77
 
a6de77
 
a6de77
@@ -54,7 +54,7 @@ for line in poolList:
a6de77
         break
a6de77
 
a6de77
 if hugePageSize == 0:
a6de77
-    print "Aborting, cannot determine system huge page size!"
a6de77
+    print("Aborting, cannot determine system huge page size!")
a6de77
     os._exit(1)
a6de77
 
a6de77
 # Get initial sysctl settings
a6de77
@@ -83,22 +83,22 @@ for line in groupNames:
a6de77
 
a6de77
 
a6de77
 # dump system config as we see it before we start tweaking it
a6de77
-print "Current configuration:"
a6de77
-print " * Total System Memory......: %6d MB" % memTotal
a6de77
-print " * Shared Mem Max Mapping...: %6d MB" % (shmmax / (1024 * 1024))
a6de77
-print " * System Huge Page Size....: %6d MB" % (hugePageSize / (1024 * 1024))
a6de77
-print " * Number of Huge Pages.....: %6d"    % hugePages
a6de77
-print " * Total size of Huge Pages.: %6d MB" % (hugePages * hugePageSize / (1024 * 1024))
a6de77
-print " * Remaining System Memory..: %6d MB" % (memTotal - (hugePages * hugePageSize / (1024 * 1024)))
a6de77
-print " * Huge Page User Group.....:  %s (%d)" % (hugeGIDName, hugeGID)
a6de77
-print
a6de77
+print("Current configuration:")
a6de77
+print(" * Total System Memory......: %6d MB" % memTotal)
a6de77
+print(" * Shared Mem Max Mapping...: %6d MB" % (shmmax / (1024 * 1024)))
a6de77
+print(" * System Huge Page Size....: %6d MB" % (hugePageSize / (1024 * 1024)))
a6de77
+print(" * Number of Huge Pages.....: %6d"    % hugePages)
a6de77
+print(" * Total size of Huge Pages.: %6d MB" % (hugePages * hugePageSize / (1024 * 1024)))
a6de77
+print(" * Remaining System Memory..: %6d MB" % (memTotal - (hugePages * hugePageSize / (1024 * 1024))))
a6de77
+print(" * Huge Page User Group.....:  %s (%d)" % (hugeGIDName, hugeGID))
a6de77
+print()
a6de77
 
a6de77
 
a6de77
 # ask how memory they want to allocate for huge pages
a6de77
 userIn = None
a6de77
 while not userIn:
a6de77
     try:
a6de77
-        userIn = raw_input("How much memory would you like to allocate for huge pages? "
a6de77
+        userIn = input("How much memory would you like to allocate for huge pages? "
a6de77
                            "(input in MB, unless postfixed with GB): ")
a6de77
         if userIn[-2:] == "GB":
a6de77
             userHugePageReqMB = int(userIn[0:-2]) * 1024
a6de77
@@ -113,19 +113,19 @@ while not userIn:
a6de77
         # As a sanity safeguard, require at least 128M not be allocated to huge pages
a6de77
         if userHugePageReqMB > (memTotal - 128):
a6de77
             userIn = None
a6de77
-            print "Refusing to allocate %d, you must leave at least 128MB for the system" % userHugePageReqMB
a6de77
+            print("Refusing to allocate %d, you must leave at least 128MB for the system" % userHugePageReqMB)
a6de77
         elif userHugePageReqMB < (hugePageSize / (1024 * 1024)):
a6de77
             userIn = None
a6de77
-            print "Sorry, allocation must be at least a page's worth!"
a6de77
+            print("Sorry, allocation must be at least a page's worth!")
a6de77
         else:
a6de77
             break
a6de77
     except ValueError:
a6de77
         userIn = None
a6de77
-        print "Input must be an integer, please try again!"
a6de77
+        print("Input must be an integer, please try again!")
a6de77
 userHugePageReqKB = userHugePageReqMB * 1024
a6de77
 userHugePagesReq = userHugePageReqKB / (hugePageSize / 1024)
a6de77
-print "Okay, we'll try to allocate %d MB for huge pages..." % userHugePageReqMB
a6de77
-print
a6de77
+print("Okay, we'll try to allocate %d MB for huge pages..." % userHugePageReqMB)
a6de77
+print()
a6de77
 
a6de77
 
a6de77
 # some basic user input validation
a6de77
@@ -134,24 +134,24 @@ inputIsValid = False
a6de77
 # ask for the name of the group allowed access to huge pages
a6de77
 while inputIsValid == False:
a6de77
     foundbad = False
a6de77
-    userGroupReq = raw_input("What group should have access to the huge pages?"
a6de77
+    userGroupReq = input("What group should have access to the huge pages?"
a6de77
                              "(The group will be created, if need be) [hugepages]: ")
a6de77
     if userGroupReq is '':
a6de77
         userGroupReq = 'hugepages'
a6de77
     if userGroupReq[0].isdigit() or userGroupReq[0] == "-":
a6de77
         foundbad = True
a6de77
-        print "Group names cannot start with a number or dash, please try again!"
a6de77
+        print("Group names cannot start with a number or dash, please try again!")
a6de77
     for char in badchars:
a6de77
         if char in userGroupReq:
a6de77
             foundbad = True
a6de77
-            print "Illegal characters in group name, please try again!"
a6de77
+            print("Illegal characters in group name, please try again!")
a6de77
             break
a6de77
     if len(userGroupReq) > 16:
a6de77
         foundbad = True
a6de77
-        print "Group names can't be more than 16 characaters, please try again!"
a6de77
+        print("Group names can't be more than 16 characaters, please try again!")
a6de77
     if foundbad == False:
a6de77
         inputIsValid = True
a6de77
-print "Okay, we'll give group %s access to the huge pages" % userGroupReq
a6de77
+print("Okay, we'll give group %s access to the huge pages" % userGroupReq)
a6de77
 
a6de77
 
a6de77
 # see if group already exists, use it if it does, if not, create it
a6de77
@@ -163,20 +163,20 @@ for line in groupNames:
a6de77
         break
a6de77
 
a6de77
 if userGIDReq > -1:
a6de77
-    print "Group %s (gid %d) already exists, we'll use it" % (userGroupReq, userGIDReq)
a6de77
+    print("Group %s (gid %d) already exists, we'll use it" % (userGroupReq, userGIDReq))
a6de77
 else:
a6de77
     if debug == False:
a6de77
         os.popen("/usr/sbin/groupadd %s" % userGroupReq)
a6de77
     else:
a6de77
-        print "/usr/sbin/groupadd %s" % userGroupReq
a6de77
+        print("/usr/sbin/groupadd %s" % userGroupReq)
a6de77
     groupNames = os.popen("/usr/bin/getent group %s" % userGroupReq).readlines()
a6de77
     for line in groupNames:
a6de77
         curGroupName = line.split(":")[0]
a6de77
         if curGroupName == userGroupReq:
a6de77
             userGIDReq = int(line.split(":")[2])
a6de77
             break
a6de77
-    print "Created group %s (gid %d) for huge page use" % (userGroupReq, userGIDReq)
a6de77
-print
a6de77
+    print("Created group %s (gid %d) for huge page use" % (userGroupReq, userGIDReq))
a6de77
+print()
a6de77
 
a6de77
 
a6de77
 # basic user input validation, take 2
a6de77
@@ -186,20 +186,20 @@ inputIsValid = False
a6de77
 # ask for user(s) that should be in the huge page access group
a6de77
 while inputIsValid == False:
a6de77
     foundbad = False
a6de77
-    userUsersReq = raw_input("What user(s) should have access to the huge pages (space-delimited list, users created as needed)? ")
a6de77
+    userUsersReq = input("What user(s) should have access to the huge pages (space-delimited list, users created as needed)? ")
a6de77
     for char in badchars:
a6de77
         if char in userUsersReq:
a6de77
             foundbad = True
a6de77
-            print "Illegal characters in user name(s) or invalid list format, please try again!"
a6de77
+            print("Illegal characters in user name(s) or invalid list format, please try again!")
a6de77
             break
a6de77
     for n in userUsersReq.split():
a6de77
         if len(n) > 32:
a6de77
             foundbad = True
a6de77
-            print "User names can't be more than 32 characaters, please try again!"
a6de77
+            print("User names can't be more than 32 characaters, please try again!")
a6de77
             break
a6de77
         if n[0] == "-":
a6de77
             foundbad = True
a6de77
-            print "User names cannot start with a dash, please try again!"
a6de77
+            print("User names cannot start with a dash, please try again!")
a6de77
             break
a6de77
     if foundbad == False:
a6de77
         inputIsValid = True
a6de77
@@ -211,24 +211,24 @@ for hugeUser in hugePageUserList:
a6de77
     for line in curUserList:
a6de77
         curUser = line.split(":")[0]
a6de77
         if curUser == hugeUser:
a6de77
-            print "Adding user %s to huge page group" % hugeUser
a6de77
+            print("Adding user %s to huge page group" % hugeUser)
a6de77
             userExists = True
a6de77
             if debug == False:
a6de77
                 os.popen("/usr/sbin/usermod -a -G %s %s" % (userGroupReq, hugeUser))
a6de77
             else:
a6de77
-                print "/usr/sbin/usermod -a -G %s %s" % (userGroupReq, hugeUser)
a6de77
+                print("/usr/sbin/usermod -a -G %s %s" % (userGroupReq, hugeUser))
a6de77
         if userExists == True:
a6de77
             break
a6de77
     if userExists == False:
a6de77
-        print "Creating user %s with membership in huge page group" % hugeUser
a6de77
+        print("Creating user %s with membership in huge page group" % hugeUser)
a6de77
         if debug == False:
a6de77
             if hugeUser == userGroupReq:
a6de77
                 os.popen("/usr/sbin/useradd %s -g %s" % (hugeUser, userGroupReq))
a6de77
             else:
a6de77
                 os.popen("/usr/sbin/useradd %s -G %s" % (hugeUser, userGroupReq))
a6de77
         else:
a6de77
-            print "/usr/sbin/useradd %s -G %s" % (hugeUser, userGroupReq)
a6de77
-print
a6de77
+            print("/usr/sbin/useradd %s -G %s" % (hugeUser, userGroupReq))
a6de77
+print()
a6de77
 
a6de77
 
a6de77
 # set values for the current running environment
a6de77
@@ -238,11 +238,11 @@ if debug == False:
a6de77
     os.popen("/usr/bin/hugeadm --set-shm-group %d" % userGIDReq)
a6de77
     os.popen("/usr/bin/hugeadm --set-recommended-shmmax")
a6de77
 else:
a6de77
-    print "/usr/bin/hugeadm --pool-pages-min DEFAULT:%sM" % userHugePageReqMB
a6de77
-    print "/usr/bin/hugeadm --pool-pages-max DEFAULT:%sM" % userHugePageReqMB
a6de77
-    print "/usr/bin/hugeadm --set-shm-group %d" % userGIDReq
a6de77
-    print "/usr/bin/hugeadm --set-recommended-shmmax"
a6de77
-    print
a6de77
+    print("/usr/bin/hugeadm --pool-pages-min DEFAULT:%sM" % userHugePageReqMB)
a6de77
+    print("/usr/bin/hugeadm --pool-pages-max DEFAULT:%sM" % userHugePageReqMB)
a6de77
+    print("/usr/bin/hugeadm --set-shm-group %d" % userGIDReq)
a6de77
+    print("/usr/bin/hugeadm --set-recommended-shmmax")
a6de77
+    print()
a6de77
 
a6de77
 # figure out what that shmmax value we just set was
a6de77
 hugeadmexplain = os.popen("/usr/bin/hugeadm --explain 2>/dev/null").readlines()
a6de77
@@ -258,7 +258,7 @@ if debug == False:
a6de77
         try:
a6de77
             sysctlConfLines = open(sysctlConf).readlines()
a6de77
             os.rename(sysctlConf, sysctlConf + ".backup")
a6de77
-            print("Saved original %s as %s.backup" % (sysctlConf, sysctlConf))
a6de77
+            print(("Saved original %s as %s.backup" % (sysctlConf, sysctlConf)))
a6de77
         except:
a6de77
             pass
a6de77
 
a6de77
@@ -279,11 +279,11 @@ if debug == False:
a6de77
     fd.close()
a6de77
 
a6de77
 else:
a6de77
-    print "Add to %s:" % sysctlConf
a6de77
-    print "kernel.shmmax = %d" % shmmax
a6de77
-    print "vm.nr_hugepages = %d" % userHugePagesReq
a6de77
-    print "vm.hugetlb_shm_group = %d" % userGIDReq
a6de77
-    print
a6de77
+    print("Add to %s:" % sysctlConf)
a6de77
+    print("kernel.shmmax = %d" % shmmax)
a6de77
+    print("vm.nr_hugepages = %d" % userHugePagesReq)
a6de77
+    print("vm.hugetlb_shm_group = %d" % userGIDReq)
a6de77
+    print()
a6de77
 
a6de77
 
a6de77
 # write out limits.conf changes to persist across reboot
a6de77
@@ -293,7 +293,7 @@ if debug == False:
a6de77
         try:
a6de77
             limitsConfLines = open(limitsConf).readlines()
a6de77
             os.rename(limitsConf, limitsConf + ".backup")
a6de77
-            print("Saved original %s as %s.backup" % (limitsConf, limitsConf))
a6de77
+            print(("Saved original %s as %s.backup" % (limitsConf, limitsConf)))
a6de77
         except:
a6de77
             pass
a6de77
 
a6de77
@@ -319,25 +319,25 @@ if debug == False:
a6de77
     fd.close()
a6de77
 
a6de77
 else:
a6de77
-    print "Add to %s:" % limitsConf
a6de77
+    print("Add to %s:" % limitsConf)
a6de77
     for hugeUser in hugePageUserList:
a6de77
-        print "%s		soft	memlock		%d" % (hugeUser, userHugePageReqKB)
a6de77
-        print "%s		hard	memlock		%d" % (hugeUser, userHugePageReqKB)
a6de77
+        print("%s		soft	memlock		%d" % (hugeUser, userHugePageReqKB))
a6de77
+        print("%s		hard	memlock		%d" % (hugeUser, userHugePageReqKB))
a6de77
 
a6de77
 
a6de77
 # dump the final configuration of things now that we're done tweaking
a6de77
-print
a6de77
-print "Final configuration:"
a6de77
-print " * Total System Memory......: %6d MB" % memTotal
a6de77
+print()
a6de77
+print("Final configuration:")
a6de77
+print(" * Total System Memory......: %6d MB" % memTotal)
a6de77
 if debug == False:
a6de77
-    print " * Shared Mem Max Mapping...: %6d MB" % (shmmax / (1024 * 1024))
a6de77
+    print(" * Shared Mem Max Mapping...: %6d MB" % (shmmax / (1024 * 1024)))
a6de77
 else:
a6de77
     # This should be what we *would* have set it to, had we actually run hugeadm --set-recommended-shmmax
a6de77
-    print " * Shared Mem Max Mapping...: %6d MB" % (userHugePagesReq * hugePageSize / (1024 * 1024))
a6de77
-print " * System Huge Page Size....: %6d MB" % (hugePageSize / (1024 * 1024))
a6de77
-print " * Available Huge Pages.....: %6d"    % userHugePagesReq
a6de77
-print " * Total size of Huge Pages.: %6d MB" % (userHugePagesReq * hugePageSize / (1024 * 1024))
a6de77
-print " * Remaining System Memory..: %6d MB" % (memTotal - userHugePageReqMB)
a6de77
-print " * Huge Page User Group.....:  %s (%d)" % (userGroupReq, userGIDReq)
a6de77
-print
a6de77
+    print(" * Shared Mem Max Mapping...: %6d MB" % (userHugePagesReq * hugePageSize / (1024 * 1024)))
a6de77
+print(" * System Huge Page Size....: %6d MB" % (hugePageSize / (1024 * 1024)))
a6de77
+print(" * Available Huge Pages.....: %6d"    % userHugePagesReq)
a6de77
+print(" * Total size of Huge Pages.: %6d MB" % (userHugePagesReq * hugePageSize / (1024 * 1024)))
a6de77
+print(" * Remaining System Memory..: %6d MB" % (memTotal - userHugePageReqMB))
a6de77
+print(" * Huge Page User Group.....:  %s (%d)" % (userGroupReq, userGIDReq))
a6de77
+print()
a6de77