From 1ee2f3c3f96e5639a00aeea87100d7fb3681c76f Mon Sep 17 00:00:00 2001 From: jshen28 Date: Fri, 8 Oct 2021 22:55:51 +0800 Subject: Use specified tmp location for growpart (#1046) Growpart uses mktemp internally to save some date. This could lead to conflicts with tmpfile clean service during boot. This patch explicitly make it uses a tmp file under /var/tmp Signed-off-by: ushen --- cloudinit/config/cc_growpart.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/cloudinit/config/cc_growpart.py b/cloudinit/config/cc_growpart.py index 2d01175f..1ddc9dc7 100644 --- a/cloudinit/config/cc_growpart.py +++ b/cloudinit/config/cc_growpart.py @@ -72,6 +72,7 @@ import stat from cloudinit import log as logging from cloudinit.settings import PER_ALWAYS from cloudinit import subp +from cloudinit import temp_utils from cloudinit import util frequency = PER_ALWAYS @@ -145,20 +146,29 @@ class ResizeGrowPart(object): myenv = os.environ.copy() myenv['LANG'] = 'C' before = get_size(partdev) - try: - subp.subp(["growpart", '--dry-run', diskdev, partnum], env=myenv) - except subp.ProcessExecutionError as e: - if e.exit_code != 1: - util.logexc(LOG, "Failed growpart --dry-run for (%s, %s)", - diskdev, partnum) - raise ResizeFailedException(e) from e - return (before, before) - try: - subp.subp(["growpart", diskdev, partnum], env=myenv) - except subp.ProcessExecutionError as e: - util.logexc(LOG, "Failed: growpart %s %s", diskdev, partnum) - raise ResizeFailedException(e) from e + # growpart uses tmp dir to store intermediate states + # and may conflict with systemd-tmpfiles-clean + with temp_utils.tempdir(needs_exe=True) as tmpd: + growpart_tmp = os.path.join(tmpd, "growpart") + if not os.path.exists(growpart_tmp): + os.mkdir(growpart_tmp, 0o700) + myenv['TMPDIR'] = growpart_tmp + try: + subp.subp(["growpart", '--dry-run', diskdev, partnum], + env=myenv) + except subp.ProcessExecutionError as e: + if e.exit_code != 1: + util.logexc(LOG, "Failed growpart --dry-run for (%s, %s)", + diskdev, partnum) + raise ResizeFailedException(e) from e + return (before, before) + + try: + subp.subp(["growpart", diskdev, partnum], env=myenv) + except subp.ProcessExecutionError as e: + util.logexc(LOG, "Failed: growpart %s %s", diskdev, partnum) + raise ResizeFailedException(e) from e return (before, get_size(partdev)) -- cgit v1.2.3