retcode = 0
terminate = False
scrub_media = False
+debug = False
def DEVNULL():
'''Return /dev/null in subprocess writable format.'''
'''Start xfs_scrub and wait for it to complete. Returns -1 if
the service was not started, 0 if it succeeded, or 1 if it
failed.'''
+ global debug
+
+ if debug:
+ print('run ', ' '.join(self.cmdline))
+
try:
self.proc = subprocess.Popen(self.cmdline)
self.proc.wait()
def stop(self):
'''Stop xfs_scrub.'''
+ global debug
+
+ if debug:
+ print('kill ', ' '.join(self.cmdline))
if self.proc is not None:
self.proc.terminate()
'''Start the service and wait for it to complete. Returns -1
if the service was not started, 0 if it succeeded, or 1 if it
failed.'''
+ global debug
+
cmd = ['systemctl', 'start', self.unitname]
try:
+ if debug:
+ print(' '.join(cmd))
proc = subprocess.Popen(cmd, stdout = DEVNULL())
proc.wait()
ret = proc.returncode
def stop(self):
'''Stop the service.'''
+ global debug
+
cmd = ['systemctl', 'stop', self.unitname]
+ if debug:
+ print(' '.join(cmd))
x = subprocess.Popen(cmd)
x.wait()
def signal_scrubs(signum, cond):
'''Handle termination signals by killing xfs_scrub children.'''
- global debug, terminate
+ global debug
+ global terminate
if debug:
print('Signal handler called with signal', signum)
def wait_for_termination(cond, killfuncs):
'''Wait for a child thread to terminate. Returns True if we should
abort the program, False otherwise.'''
- global debug, terminate
+ global debug
+ global terminate
if debug:
print('waiting for threads to terminate')
global retcode
global terminate
global scrub_media
+ global debug
parser = argparse.ArgumentParser( \
description = "Scrub all mounted XFS filesystems.")
+ parser.add_argument("--debug", help = "Enabling debugging messages.", \
+ action = "store_true")
parser.add_argument("-V", help = "Report version and exit.", \
action = "store_true")
parser.add_argument("-x", help = "Scrub file data after filesystem metadata.", \
print("xfs_scrub_all version @pkg_version@")
sys.exit(0)
+ if args.debug:
+ debug = True
+
if args.auto_media_scan_interval is not None:
try:
scrub_media = enable_automatic_media_scan(args)