So I was close. I forgot arrays start at 0 and not 1 (I should have known that!), so my arrays were off by 1.
The change would be as follows to the file:
/opt/rockstor/src/rockstor/fs/btrfs.py
In the method, scrub_status,
if len(out) > 1:
if re.search('interrupted', out[2]) is not None:
stats['status'] = 'halted'
# extract the duration from towards the end of the first line eg:
# "... 2017, interrupted after 00:00:09, not running"
dfields = out[3].split()[-3].strip(',').split(':')
stats['duration'] = ((int(dfields[0]) * 60 * 60) +
(int(dfields[1]) * 60) + int(dfields[2]))
elif re.search('running', out[2]) is not None:
stats['status'] = 'running'
elif re.search('finished', out[2]) is not None:
stats['status'] = 'finished'
# extract the duration from the end of the first line eg:
# "... 2017 and finished after 00:00:16"
dfields = out[3].split()[-1].split(':')
stats['duration'] = ((int(dfields[0]) * 60 * 60) +
(int(dfields[1]) * 60) + int(dfields[2]))
elif re.search('aborted', out[2]) is not None:
stats['status'] = 'cancelled'
# extract the duration from the end of the first line eg:
# "... 2017 and was aborted after 00:04:56"
# TODO: we have code duplication here re finished clause above.
dfields = out[3].split()[-1].split(':')
stats['duration'] = ((int(dfields[0]) * 60 * 60) +
(int(dfields[1]) * 60) + int(dfields[2]))
else:
return stats
else: # we have an unknown status as out is 0 or 1 lines long.
return stats
for l in out[4:-1]:
fields = l.strip().split(': ')
if fields[0] == 'data_bytes_scrubbed':
stats['kb_scrubbed'] = int(fields[1]) / 1024
else:
stats[fields[0]] = int(fields[1])
return stats
I’m looking to see if I can somehow detect the version of btrfs installed, and if it is less than 5.1.2, run the old code and if newer than 5.1.2 run the new code. I’ll need to read up on the links you sent over.