From cdf70e63bed0bf04d7ffaec304882f216d8a0a0b Mon Sep 17 00:00:00 2001 From: Lukas Nykryn Date: Wed, 14 Feb 2024 15:17:59 +0100 Subject: [PATCH] cryptsetup: try to detach the device multiple times before giving up Terrible hack for RHEL8. We are missing the blockdev@.target, so we can't correctly express some dependencies. That means when systemd-cryptsetup detach can fail, because for example a filesystem is still mounted on top of the device. This can cause shutdown to hang forever. See https://issues.redhat.com/browse/RHEL-6210 So as a workaround, let's try to detach the device multiple times before giving up. Proper fix is https://github.com/systemd/systemd/commit/44b0d1fd597d7034a995feb385b41a6820f4aac0 RHEL-only Resolves: RHEL-6210 --- src/cryptsetup/cryptsetup.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index de4bc9579c..13f5c51e91 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -772,7 +772,18 @@ int main(int argc, char *argv[]) { crypt_set_log_callback(cd, cryptsetup_log_glue, NULL); - r = crypt_deactivate(cd, argv[2]); + /* Terrible hack for RHEL8. We are missing the blockdev@.target, so we can't + correctly express some dependencies. That means when systemd-cryptsetup detach + can fail, because for example a filesystem is still mounted on top of the device. + This can cause shutdown to hang forever. See https://issues.redhat.com/browse/RHEL-6210 + So as a workaround, let's try to detach the device multiple times before giving up. */ + for (int i = 0; i < 10; i++) { + r = crypt_deactivate(cd, argv[2]); + if (r == 0) + break; + sleep(1); + } + if (r < 0) { log_error_errno(r, "Failed to deactivate: %m"); goto finish;