Blame SOURCES/bz1900015-podman-recover-from-storage-out-of-sync.patch

030326
From 52d09b57a499ed7b3757e0e2954c2783198d5b23 Mon Sep 17 00:00:00 2001
030326
From: Damien Ciabrini <damien.ciabrini@gmail.com>
030326
Date: Mon, 9 Nov 2020 20:42:19 +0100
030326
Subject: [PATCH] podman: recover from podman's storage being out of sync
030326
030326
If a system crash while podman is stopping a container (e.g. a fencing action
030326
took place), it might happen that on reboot, podman is not able to recreate
030326
a container as requested by the resource agent.
030326
030326
When such a start operation fails, it might be because the internal storage
030326
layer still references an old container with the same name, even though podman
030326
itself thinks there is no such container. If so, purge the storage layer to try
030326
to clean the corruption and try recreating the container.
030326
---
030326
 heartbeat/podman | 29 +++++++++++++++++++++++++++--
030326
 1 file changed, 27 insertions(+), 2 deletions(-)
030326
030326
diff --git a/heartbeat/podman b/heartbeat/podman
030326
index 81b00ee6f..d4d608ca3 100755
030326
--- a/heartbeat/podman
030326
+++ b/heartbeat/podman
030326
@@ -345,6 +345,32 @@ create_transient_drop_in_dependency()
030326
 }
030326
 
030326
 
030326
+run_new_container()
030326
+{
030326
+	local opts=$1
030326
+	local image=$2
030326
+	local cmd=$3
030326
+	local rc
030326
+	
030326
+	ocf_log info "running container $CONTAINER for the first time"
030326
+	ocf_run podman run $opts $image $cmd
030326
+	rc=$?
030326
+	if [ $rc -eq 125 ]; then
030326
+		# If an internal podman error occurred, it might be because
030326
+		# the internal storage layer still references an old container
030326
+		# with the same name, even though podman itself thinks there
030326
+		# is no such container. If so, purge the storage layer to try
030326
+		# to clean the corruption and try again.
030326
+		ocf_log warn "Internal podman error while creating new container $CONTAINER. Retrying."
030326
+		ocf_run podman rm --storage $CONTAINER
030326
+		ocf_run podman run $opts $image $cmd
030326
+		rc=$?
030326
+	fi
030326
+	
030326
+	return $rc
030326
+}
030326
+
030326
+
030326
 podman_start()
030326
 {
030326
 	local cid
030326
@@ -378,8 +404,7 @@ podman_start()
030326
 		# make sure any previous container matching our container name is cleaned up first.
030326
 		# we already know at this point it wouldn't be running
030326
 		remove_container
030326
-		ocf_log info "running container $CONTAINER for the first time"
030326
-		ocf_run podman run $run_opts $OCF_RESKEY_image $OCF_RESKEY_run_cmd
030326
+		run_new_container "$run_opts" $OCF_RESKEY_image "$OCF_RESKEY_run_cmd"
030326
 	fi
030326
 	rc=$?
030326