]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_scrub_all: add CLI option for easier debugging
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:21:17 +0000 (14:21 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:12:35 +0000 (17:12 -0700)
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@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
scrub/xfs_scrub_all.in

index 4130a98e96a94082d87c45a7e5cf2915b8f0c139..8954b47405b2b3eb921ed8a5064b3ebca64942dc 100644 (file)
@@ -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)