From eff235ee7274f0d4a9c71bf0d971d93fd5e3d339 Mon Sep 17 00:00:00 2001 From: Bogdan Dobrelya Date: Mon, 27 Jan 2020 15:46:39 +0100 Subject: [PATCH] Ensure the yum cache has at most one writer If the yum cache path exists and already mounted by someone, do not attempt writing to it, use the overlay mode instead. This still leaves a window of opportunity for another workers to RW mount the cache after the ansible check has reported a stale fact about there was no other mounts found. But this is unlikely to happen. Also, if it has to be retried in the rescue block, do not use the yum cache for the maximum data safety and clean (a scratch) cache state reasons. This drastically reduces chances to have multiple writers for the cache. Closes-bug: #1860804 Change-Id: I19491a162e5bf6d6517fd343d675aff12bdc9719 Signed-off-by: Bogdan Dobrelya --- tasks/yum_update_buildah.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tasks/yum_update_buildah.yml b/tasks/yum_update_buildah.yml index 7511bd3..84874e3 100644 --- a/tasks/yum_update_buildah.yml +++ b/tasks/yum_update_buildah.yml @@ -80,12 +80,18 @@ setype: svirt_sandbox_file_t when: not yum_cache_stat.stat.exists|default() + - name: Check if the cache path has been already mounted + command: findmnt {{ yum_cache }} + register: findmnt_result + failed_when: false + - name: Use the pre-populated non-empty cache as an overlay fs set_fact: cache_volume: "{{ yum_cache }}:{{ cache_path }}:O" when: - yum_cache_stat.stat.exists|default() - yum_cache_contents.stdout + - findmnt_result.rc != 0 - name: Define the cache populating mode otherwise set_fact: @@ -114,15 +120,12 @@ register: result rescue: - - name: Run yum_update.sh (retry) + - name: Run yum_update.sh (retry without yum cache) command: > buildah --debug run --volume {{ yum_update.path }}:/tmp/yum_update.sh --volume {{ yum_repos_dir_path }}:/etc/yum.repos.d --volume /etc/pki:/etc/pki - {% if cache_volume is defined and cache_volume %} - --volume {{ cache_volume }} - {% endif %} {% for repo in file_repos.stdout_lines %} {% if repo is exists %} --volume {{ repo }}:{{ repo }}