@@ -4021,6 +4021,18 @@ def start_gc(session, sr_uuid):
40214021 subprocess .run ([__file__ , '-b' , '-u' , sr_uuid , '-g' ],
40224022 stdout = subprocess .PIPE , stderr = subprocess .PIPE , close_fds = True )
40234023
4024+ def _gc_service_cmd (sr_uuid , action , extra_args = None ):
4025+ """
4026+ Build and run the systemctl command for the GC service using util.doexec.
4027+ """
4028+ sr_uuid_esc = sr_uuid .replace ("-" , "\\ x2d" )
4029+ cmd = [ "/usr/bin/systemctl" , "--quiet" ]
4030+ if extra_args :
4031+ cmd .extend (extra_args )
4032+ cmd += [action , f"SMGC@{ sr_uuid_esc } " ]
4033+ return util .doexec (cmd )
4034+
4035+
40244036def start_gc_service (sr_uuid , wait = False ):
40254037 """
40264038 This starts the templated systemd service which runs GC on the given SR UUID.
@@ -4031,26 +4043,18 @@ def start_gc_service(sr_uuid, wait=False):
40314043 run has finished. This is used to force a run of the GC instead of just kicking it
40324044 in the background.
40334045 """
4034- sr_uuid_esc = sr_uuid .replace ("-" , "\\ x2d" )
40354046 util .SMlog (f"Kicking SMGC@{ sr_uuid } ..." )
4036- cmd = [ "/usr/bin/systemctl" , "--quiet" ]
4037- if not wait :
4038- cmd .append ("--no-block" )
4039- cmd += ["start" , f"SMGC@{ sr_uuid_esc } " ]
4040- subprocess .run (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , close_fds = True )
4047+ _gc_service_cmd (sr_uuid , "start" , extra_args = None if wait else ["--no-block" ])
40414048
40424049
40434050def stop_gc_service (sr_uuid ):
40444051 """
40454052 Stops the templated systemd service which runs GC on the given SR UUID.
40464053 """
4047- sr_uuid_esc = sr_uuid .replace ("-" , "\\ x2d" )
40484054 util .SMlog (f"Stopping SMGC@{ sr_uuid } ..." )
4049- cmd = ["/usr/bin/systemctl" , "--quiet" , "stop" , f"SMGC@{ sr_uuid_esc } " ]
4050- try :
4051- subprocess .run (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , close_fds = True , check = True )
4052- except subprocess .CalledProcessError as e :
4053- util .SMlog (f"Failed to stop gc service `SMGC@{ sr_uuid_esc } `: `{ e .stderr .decode ().strip ()} `" )
4055+ (rc , _stdout , stderr ) = _gc_service_cmd (sr_uuid , "stop" )
4056+ if rc != 0 :
4057+ util .SMlog (f"Failed to stop gc service `SMGC@{ sr_uuid } `: `{ stderr } `" )
40544058
40554059def gc_force (session , srUuid , force = False , dryRun = False , lockSR = False ):
40564060 """Garbage collect all deleted VDIs in SR "srUuid". The caller must ensure
0 commit comments