def set_tunable(self, disk, name, path, val): """ Given a disk name, a path to a tunable value under _TUNE_PATH and the new value for the parameter, set the value and verify that the value has been successfully set. """ fpath = partition.get_iosched_path(disk, path) # Things might go wrong so we'll catch exceptions try: step = "open tunable path" tunef = open(fpath, 'w', buffering=-1) step = "write new tunable value" tunef.write(val) step = "close the tunable path" tunef.close() step = "read back new tunable value" nval = open(fpath, 'r', buffering=-1).read().strip() # For 'scheduler' we need to fish out the bracketed value if name == "scheduler": nval = re.match(".*\[(.*)\].*", nval).group(1) except IOError as info: # Special case: for some reason 'max_sectors_kb' often doesn't work # with large values; try '128' if we haven't tried it already. if name == "max_sectors_kb" and info.errno == 22 and val != '128': self.set_tunable(disk, name, path, '128') return # Something went wrong, probably a 'config' problem of some kind raise Exception("Unable to set tunable value '" + name + "' at step '" + step + "': " + str(info)) except Exception: # We should only ever see 'IOError' above, but just in case ... raise Exception("Unable to set tunable value for " + name) # Make sure the new value is what we expected if nval != val: raise Exception("Unable to correctly set tunable value for " + name + ": desired " + val + ", but found " + nval) return
def set_tunable(self, disk, name, path, val): """ Given a disk name, a path to a tunable value under _TUNE_PATH and the new value for the parameter, set the value and verify that the value has been successfully set. """ fpath = partition.get_iosched_path(disk, path) # Things might go wrong so we'll catch exceptions try: step = "open tunable path" tunef = open(fpath, 'w', buffering=-1) step = "write new tunable value" tunef.write(val) step = "close the tunable path" tunef.close() step = "read back new tunable value" nval = open(fpath, 'r', buffering=-1).read().strip() # For 'scheduler' we need to fish out the bracketed value if name == "scheduler": nval = re.match(".*\[(.*)\].*", nval).group(1) except IOError, info: # Special case: for some reason 'max_sectors_kb' often doesn't work # with large values; try '128' if we haven't tried it already. if name == "max_sectors_kb" and info.errno == 22 and val != '128': self.set_tunable(disk, name, path, '128') return # Something went wrong, probably a 'config' problem of some kind raise Exception("Unable to set tunable value '" + name + "' at step '" + step + "': " + str(info))