diff mbox series

handler: ubivol: relax accessing UBI volume

Message ID 20240709192425.2939878-1-stefano.babic@swupdate.org
State Changes Requested
Headers show
Series handler: ubivol: relax accessing UBI volume | expand

Commit Message

Stefano Babic July 9, 2024, 7:24 p.m. UTC
It could be that some race conditions happens when SWUpdate tries to
lock the UBI volume for updating, for example after creating the volume
if udev is running and it accesses for some milliseconds. This is not an
issue inside SWUpdate, but SWUpdate can retry to get exclusive access of
the volume before giving up, making the update itself more robust.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
Reported-by: Christian Eggers <ceggers@arri.de>
---
 handlers/ubivol_handler.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

--
2.34.1
diff mbox series

Patch

diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c
index 0ad0321e..6d27c89f 100644
--- a/handlers/ubivol_handler.c
+++ b/handlers/ubivol_handler.c
@@ -248,7 +248,22 @@  static int update_volume(libubi_t libubi, struct img_type *img,
 		ERROR("cannot open UBI volume \"%s\"", node);
 		return -1;
 	}
-	err = ubi_update_start(libubi, fdout, bytes);
+
+	unsigned int retries = 3;
+	do {
+		/*
+		 * libubi just returns -1, no check is possible
+		 * Simply retries in case of error if the volume
+		 * was locked by another process
+		 */
+		err = ubi_update_start(libubi, fdout, bytes);
+		retries--;
+		if (err) {
+			WARN("Not possible to lock UBI, retry");
+			sleep(1);
+		}
+	} while (err && retries > 0);
+
 	if (err) {
 		ERROR("cannot start volume \"%s\" update", node);
 		return -1;