1
0
Fork 0

Merge pull request #219 from yarda/disk-readahaed-parser-fix

plugin_disk: fixed traceback on invalid readahead values
This commit is contained in:
Jaroslav Škarvada 2019-11-25 15:13:09 +01:00 committed by GitHub
commit 8c9df990a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -296,7 +296,10 @@ class DiskPlugin(hotplug.Plugin):
def _parse_ra(self, value):
val = str(value).split(None, 1)
v = int(val[0])
try:
v = int(val[0])
except ValueError:
return None
if len(val) > 1 and val[1][0] == "s":
# v *= 512 / 1024
v /= 2
@ -306,8 +309,11 @@ class DiskPlugin(hotplug.Plugin):
def _set_readahead(self, value, device, sim):
sys_file = self._readahead_file(device)
val = self._parse_ra(value)
if not sim:
self._cmd.write_to_file(sys_file, "%d" % val)
if val is None:
log.error("Invalid readahead value '%s' for device '%s'" % (value, device))
else:
if not sim:
self._cmd.write_to_file(sys_file, "%d" % val)
return val
@command_get("readahead")