diff mbox series

[1/3,meta-swupdate,v1,1/3] swupdate-usb: update service to use mount points dynamically

Message ID 20220428121033.1609620-1-muhammad_hamza@mentor.com
State Changes Requested
Headers show
Series [1/3,meta-swupdate,v1,1/3] swupdate-usb: update service to use mount points dynamically | expand

Commit Message

Hamza, Muhammad April 28, 2022, 12:10 p.m. UTC
swupdate-usb service uses a fixed mount point which caters
block devices with one partition only. If a device has multiple
partitions swupdate-usb service launches for every partition and
tries to mount it at same mount point which is not a clean
way. This also results in failures during un-mounting even if
the update is performed successfully.
This is due to the fact that when multiple partitons are mounted
at same mount point, it acts like a stack and with each un-mount
the latest mounted partiton is removed. An example case is if a
USB with 3 partitions is plugged in it launches services for all,
say all partitons are mounted in sequence as sda1, sda2 and sda3.
However if only one partiton say sda2 contains the update image
it will start update from it and services for sda1 and sda3 will
exit as no image is present in them. This will cause services for
sda1 and sda3 to run umount twice on /mnt/ but second partition in
mounting sequence was sda2 which is busy and it would fail to
un-mount. Now when swupdate-usb@sda2 will exit after update it
will run umount once and one partition will still be left mounted
as corresponding umount for that service failed.

This commit introduces a change that for every partiton
a unique mount point is created, and when done, that mount
point is removed, this ensures no such conficts occur and every
service uses a mount point unique to the partiton against which
service was launched

Signed-off-by: Muhammad Hamza <muhammad_hamza@mentor.com>
---
 recipes-support/swupdate/swupdate/swupdate-usb@.service | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Stefano Babic June 5, 2022, 4:10 p.m. UTC | #1
Hi Muhammad,

sorry for late review, this series was quite lost:

On 28.04.22 14:10, Muhammad Hamza wrote:
> swupdate-usb service uses a fixed mount point which caters
> block devices with one partition only. If a device has multiple
> partitions swupdate-usb service launches for every partition and
> tries to mount it at same mount point which is not a clean
> way. This also results in failures during un-mounting even if
> the update is performed successfully.
> This is due to the fact that when multiple partitons are mounted
> at same mount point, it acts like a stack and with each un-mount
> the latest mounted partiton is removed. An example case is if a
> USB with 3 partitions is plugged in it launches services for all,
> say all partitons are mounted in sequence as sda1, sda2 and sda3.
> However if only one partiton say sda2 contains the update image
> it will start update from it and services for sda1 and sda3 will
> exit as no image is present in them. This will cause services for
> sda1 and sda3 to run umount twice on /mnt/ but second partition in
> mounting sequence was sda2 which is busy and it would fail to
> un-mount. Now when swupdate-usb@sda2 will exit after update it
> will run umount once and one partition will still be left mounted
> as corresponding umount for that service failed.
> 

Behavior is clear.

> This commit introduces a change that for every partiton
> a unique mount point is created, and when done, that mount
> point is removed, this ensures no such conficts occur and every
> service uses a mount point unique to the partiton against which
> service was launched

Theoretical a good way, but...what about if the rootfs is read-only ?

> 
> Signed-off-by: Muhammad Hamza <muhammad_hamza@mentor.com>
> ---
>   recipes-support/swupdate/swupdate/swupdate-usb@.service | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/recipes-support/swupdate/swupdate/swupdate-usb@.service b/recipes-support/swupdate/swupdate/swupdate-usb@.service
> index eda9d15..752253e 100644
> --- a/recipes-support/swupdate/swupdate/swupdate-usb@.service
> +++ b/recipes-support/swupdate/swupdate/swupdate-usb@.service
> @@ -3,6 +3,8 @@ Description=usb media swupdate service
>   Requires=swupdate-progress.service
>   
>   [Service]
> -ExecStartPre=/bin/mount /dev/%I /mnt
> -ExecStart=/bin/sh -c "swupdate-client -v /mnt/*.swu"
> -ExecStopPost=/bin/umount /mnt
> +ExecStartPre=/bin/mkdir -p /mnt/%I
> +ExecStartPre=/bin/mount /dev/%I /mnt/%I

It is not really important where it is mounted. We could maybe move it 
to /tmp instead of /mnt, and tmp is guaranteed to be writable.

> +ExecStart=/bin/sh -c "swupdate-client -v /mnt/%I/*.swu"
> +ExecStopPost=/bin/umount /mnt/%I
> +ExecStopPost=/bin/rmdir /mnt/%I

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/recipes-support/swupdate/swupdate/swupdate-usb@.service b/recipes-support/swupdate/swupdate/swupdate-usb@.service
index eda9d15..752253e 100644
--- a/recipes-support/swupdate/swupdate/swupdate-usb@.service
+++ b/recipes-support/swupdate/swupdate/swupdate-usb@.service
@@ -3,6 +3,8 @@  Description=usb media swupdate service
 Requires=swupdate-progress.service
 
 [Service]
-ExecStartPre=/bin/mount /dev/%I /mnt
-ExecStart=/bin/sh -c "swupdate-client -v /mnt/*.swu"
-ExecStopPost=/bin/umount /mnt
+ExecStartPre=/bin/mkdir -p /mnt/%I
+ExecStartPre=/bin/mount /dev/%I /mnt/%I
+ExecStart=/bin/sh -c "swupdate-client -v /mnt/%I/*.swu"
+ExecStopPost=/bin/umount /mnt/%I
+ExecStopPost=/bin/rmdir /mnt/%I