Skip to content

Commit 9f07b80

Browse files
fix: stop SMGC service on SR detach to prevent orphaned systemd units
Signed-off-by: Mathieu Labourier <mathieu.labourier@vates.tech>
1 parent 3ecfefa commit 9f07b80

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

libs/sm/cleanup.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,6 +3205,7 @@ def abort(srUuid, soft=False):
32053205
"""Abort GC/coalesce if we are currently GC'ing or coalescing a VDI pair.
32063206
"""
32073207
if _abort(srUuid, soft):
3208+
stop_gc_service(srUuid)
32083209
Util.log("abort: releasing the process lock")
32093210
lockGCActive.release()
32103211
return True
@@ -3278,6 +3279,18 @@ def start_gc(session, sr_uuid):
32783279
subprocess.run([__file__, '-b', '-u', sr_uuid, '-g'],
32793280
stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
32803281

3282+
def _gc_service_cmd(sr_uuid, action, extra_args=None):
3283+
"""
3284+
Build and run the systemctl command for the GC service using util.doexec.
3285+
"""
3286+
sr_uuid_esc = sr_uuid.replace("-", "\\x2d")
3287+
cmd=["/usr/bin/systemctl", "--quiet"]
3288+
if extra_args:
3289+
cmd.extend(extra_args)
3290+
cmd += [action, f"SMGC@{sr_uuid_esc}"]
3291+
return util.doexec(cmd)
3292+
3293+
32813294
def start_gc_service(sr_uuid, wait=False):
32823295
"""
32833296
This starts the templated systemd service which runs GC on the given SR UUID.
@@ -3288,13 +3301,18 @@ def start_gc_service(sr_uuid, wait=False):
32883301
run has finished. This is used to force a run of the GC instead of just kicking it
32893302
in the background.
32903303
"""
3291-
sr_uuid_esc = sr_uuid.replace("-", "\\x2d")
32923304
util.SMlog(f"Kicking SMGC@{sr_uuid}...")
3293-
cmd=[ "/usr/bin/systemctl", "--quiet" ]
3294-
if not wait:
3295-
cmd.append("--no-block")
3296-
cmd += ["start", f"SMGC@{sr_uuid_esc}"]
3297-
subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
3305+
_gc_service_cmd(sr_uuid, "start", extra_args=None if wait else ["--no-block"])
3306+
3307+
3308+
def stop_gc_service(sr_uuid):
3309+
"""
3310+
Stops the templated systemd service which runs GC on the given SR UUID.
3311+
"""
3312+
util.SMlog(f"Stopping SMGC@{sr_uuid}...")
3313+
(rc, _stdout, stderr) = _gc_service_cmd(sr_uuid, "stop")
3314+
if rc != 0:
3315+
util.SMlog(f"Failed to stop gc service `SMGC@{sr_uuid}`: `{stderr}`")
32983316

32993317

33003318
def gc_force(session, srUuid, force=False, dryRun=False, lockSR=False):

0 commit comments

Comments
 (0)