Blame 0002-Recover-from-fsync-fail-on-read-only-filesystem-RhBu.patch

Marek Blaha 9d422f
From 33be80700bc594f34818ce697493c17e70430390 Mon Sep 17 00:00:00 2001
Marek Blaha 9d422f
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
Marek Blaha 9d422f
Date: Mon, 17 May 2021 08:50:25 +0200
Marek Blaha 9d422f
Subject: [PATCH] Recover from fsync fail on read-only filesystem
Marek Blaha 9d422f
 (RhBug:1956361)
Marek Blaha 9d422f
Marek Blaha 9d422f
When `fsync` fails due to the file not supporting synchronization just log
Marek Blaha 9d422f
the problem instead of failing the whole dnf run. This happens for
Marek Blaha 9d422f
example with filesystems mounted read-only in which case there is no
Marek Blaha 9d422f
point to `fsync` anyway.
Marek Blaha 9d422f
Marek Blaha 9d422f
Currently we also ignore return values from `FSETXATTR` which also fails
Marek Blaha 9d422f
on read-only filesystem (so no checksum cache is set). This is fine however
Marek Blaha 9d422f
since the checksum is recomputed when needed, dnf is just a bit slower.
Marek Blaha 9d422f
Marek Blaha 9d422f
https://bugzilla.redhat.com/show_bug.cgi?id=1956361
Marek Blaha 9d422f
---
Marek Blaha 9d422f
 librepo/checksum.c | 10 +++++++---
Marek Blaha 9d422f
 1 file changed, 7 insertions(+), 3 deletions(-)
Marek Blaha 9d422f
Marek Blaha 9d422f
diff --git a/librepo/checksum.c b/librepo/checksum.c
Marek Blaha 9d422f
index db37040..6bba53c 100644
Marek Blaha 9d422f
--- a/librepo/checksum.c
Marek Blaha 9d422f
+++ b/librepo/checksum.c
Marek Blaha 9d422f
@@ -266,9 +266,13 @@ lr_checksum_fd_compare(LrChecksumType type,
Marek Blaha 9d422f
     *matches = (strcmp(expected, checksum)) ? FALSE : TRUE;
Marek Blaha 9d422f
 
Marek Blaha 9d422f
     if (fsync(fd) != 0) {
Marek Blaha 9d422f
-        g_set_error(err, LR_CHECKSUM_ERROR, LRE_FILE,
Marek Blaha 9d422f
-                    "fsync failed: %s", strerror(errno));
Marek Blaha 9d422f
-        return FALSE;
Marek Blaha 9d422f
+        if (errno == EROFS || errno == EINVAL) {
Marek Blaha 9d422f
+            g_debug("fsync failed: %s", strerror(errno));
Marek Blaha 9d422f
+        } else {
Marek Blaha 9d422f
+            g_set_error(err, LR_CHECKSUM_ERROR, LRE_FILE,
Marek Blaha 9d422f
+                        "fsync failed: %s", strerror(errno));
Marek Blaha 9d422f
+            return FALSE;
Marek Blaha 9d422f
+        }
Marek Blaha 9d422f
     }
Marek Blaha 9d422f
 
Marek Blaha 9d422f
     if (caching && *matches && timestamp != -1) {
Marek Blaha 9d422f
-- 
Marek Blaha 9d422f
2.31.1
Marek Blaha 9d422f