From: Darrick J. Wong <djwong@xxxxxxxxxx> Add a new CLI argument to make it easier to figure out what exactly the program is doing. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> Reviewed-by: Christoph Hellwig <hch@xxxxxx> --- scrub/xfs_scrub_all.in | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in index 4130a98e9..8954b4740 100644 --- a/scrub/xfs_scrub_all.in +++ b/scrub/xfs_scrub_all.in @@ -24,6 +24,7 @@ from datetime import timezone retcode = 0 terminate = False scrub_media = False +debug = False def DEVNULL(): '''Return /dev/null in subprocess writable format.''' @@ -110,6 +111,11 @@ class scrub_subprocess(scrub_control): '''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() @@ -122,6 +128,10 @@ class scrub_subprocess(scrub_control): def stop(self): '''Stop xfs_scrub.''' + global debug + + if debug: + print('kill ', ' '.join(self.cmdline)) if self.proc is not None: self.proc.terminate() @@ -182,8 +192,12 @@ class scrub_service(scrub_control): '''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 @@ -201,7 +215,11 @@ class scrub_service(scrub_control): def stop(self): '''Stop the service.''' + global debug + cmd = ['systemctl', 'stop', self.unitname] + if debug: + print(' '.join(cmd)) x = subprocess.Popen(cmd) x.wait() @@ -266,7 +284,8 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs): 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) @@ -280,7 +299,8 @@ def signal_scrubs(signum, cond): 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') @@ -371,9 +391,12 @@ def main(): 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.", \ @@ -388,6 +411,9 @@ def main(): 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)