Hi Stefano,
thanks for preparing the patch.
On Tuesday, 9 July 2024, 21:24:25 CEST, Stefano Babic wrote:
> 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 <
stefan...@swupdate.org>
> Reported-by: Christian Eggers <
ceg...@arri.de>
> ---
> handlers/ubivol_handler.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> 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
I am quite sure that the value of errno (EBUSY) can be used in this case.
> + * Simply retries in case of error if the volume
> + * was locked by another process
s/was locked/is currently accessed/
> + */
> + 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);
Additionally here should be a close() statement.
> return -1;
> --
> 2.34.1
>
>
Based on your patch, I have developed and tested a slightly improved version
(attached). Do you like to post this as v2 (please set the *-by: tags as you like)?
Now I get the following output:
...
[TRACE] : SWUPDATE running : [resize_volume] : Removed UBI Volume kernel1
[TRACE] : SWUPDATE running : [resize_volume] : Created dynamic UBI volume kernel1 of 2671473 bytes (old size 2793472)
[ 65.530992] ubi0 error: 0xc02587b9: 2 users for volume 1
[WARN ] : SWUPDATE running : [update_volume] : Not possible to lock UBI, retry
[INFO ] : SWUPDATE running : Installing image lios-fitimage-ubifs-orbiter.fitimg into volume /dev/ubi0_1(kernel1)
[TRACE] : SWUPDATE running : [update_volume] : Updating UBI : lios-fitimage-ubifs-orbiter.fitimg 2671473
[TRACE] : SWUPDATE running : [extract_files] : END INSTALLING STREAMING
[TRACE] : SWUPDATE running : [extract_files] : Found file
[TRACE] : SWUPDATE running : [extract_files] : filename lios-rootfs-release-orbiter.ubifs
[TRACE] : SWUPDATE running : [extract_files] : size 33013760 required
[TRACE] : SWUPDATE running : [extract_files] : Installing STREAM lios-rootfs-release-orbiter.ubifs, 33013760 bytes
[TRACE] : SWUPDATE running : [install_single_image] : Found installer for stream lios-rootfs-release-orbiter.ubifs ubivol
[TRACE] : SWUPDATE running : [resize_volume] : Removed UBI Volume rootfs1
[TRACE] : SWUPDATE running : [resize_volume] : Created dynamic UBI volume rootfs1 of 33013760 bytes (old size 33013760)
[ 67.583171] ubi0 error: 0xc02587b9: 2 users for volume 4
[WARN ] : SWUPDATE running : [update_volume] : Not possible to lock UBI, retry
[INFO ] : SWUPDATE running : Installing image lios-rootfs-release-orbiter.ubifs into volume /dev/ubi0_4(rootfs1)
[TRACE] : SWUPDATE running : [update_volume] : Updating UBI : lios-rootfs-release-orbiter.ubifs 33013760
[TRACE] : SWUPDATE running : [extract_files] : END INSTALLING STREAMING
...
At next I'll switch from v2023.12.1 to v2024.05.2.
regards,
Christian