From patchwork Mon Jun 20 13:17:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hamza, Muhammad" X-Patchwork-Id: 9390 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9146CC43334 for ; Mon, 20 Jun 2022 13:18:37 +0000 (UTC) Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by mx.groups.io with SMTP id smtpd.web12.30118.1655731108581725812 for ; Mon, 20 Jun 2022 06:18:28 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: mentor.com, ip: 68.232.141.98, mailfrom: muhammad_hamza@mentor.com) X-IronPort-AV: E=Sophos;i="5.92,306,1650960000"; d="scan'208";a="77537455" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 20 Jun 2022 05:18:27 -0800 IronPort-SDR: df8JcFo/9rf1oKJs95FuaAPznRKn9WW0U/2M9Z8m2d9a8OTaxQaiSHLSiv4VP7Ye4Vh2BMJlU9 EQ0J6ducGoN43wRwiAK+FrZifWesH2Fhx9DsFRyh1CiE5fFv/lJzEB+VKw8TLMjf25xtbfzSTu 0ths5UJN+8+aTx0GcCLyinKyR21b1bSoDTY+zwxXPYoRQR/FqqhffcnS6nNAKWgAqK0iIG7ZYF AYevU0ppMqyhM3qERHFsV8sR/2OJ3cWr1/RDlYFUtonR0uSzWIs3pLQzlyb1i9dPcAikBqzG0T ljM= From: Muhammad Hamza To: CC: Muhammad Hamza , Awais Belal Subject: [PATCH 1/2] udev-extraconf/mount.sh: save mount name in our tmp filecache Date: Mon, 20 Jun 2022 18:17:55 +0500 Message-ID: <20220620131756.269638-1-muhammad_hamza@mentor.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 20 Jun 2022 13:18:37 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/167106 Doing this will allow to fetch the exact name created by the auto-mounter during the remove action where depending on the scenario utilities such as the blkid might not be usable due to actual device not being present on the system. Signed-off-by: Awais Belal Signed-off-by: Muhammad Hamza --- meta/recipes-core/udev/udev-extraconf/mount.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/meta/recipes-core/udev/udev-extraconf/mount.sh b/meta/recipes-core/udev/udev-extraconf/mount.sh index 12c6a5af22..994de75b28 100644 --- a/meta/recipes-core/udev/udev-extraconf/mount.sh +++ b/meta/recipes-core/udev/udev-extraconf/mount.sh @@ -140,7 +140,10 @@ automount() { rm_dir "$MOUNT_BASE/$name" else logger "mount.sh/automount" "Auto-mount of [$MOUNT_BASE/$name] successful" - touch "/tmp/.automount-$name" + # The actual device might not be present in the remove event so blkid cannot + # be used to calculate what name was generated here. Simply save the mount + # name in our tmp file. + echo "$name" > "/tmp/.automount-$name" fi } From patchwork Mon Jun 20 13:17:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hamza, Muhammad" X-Patchwork-Id: 9391 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91440C433EF for ; Mon, 20 Jun 2022 13:18:37 +0000 (UTC) Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by mx.groups.io with SMTP id smtpd.web12.30118.1655731108581725812 for ; Mon, 20 Jun 2022 06:18:31 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: mentor.com, ip: 68.232.141.98, mailfrom: muhammad_hamza@mentor.com) X-IronPort-AV: E=Sophos;i="5.92,306,1650960000"; d="scan'208";a="77537461" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 20 Jun 2022 05:18:30 -0800 IronPort-SDR: Dv7CYDXDAArmttBAHRc+JMLrDN6cdvdJ5xGWFYqlWuie1FXfj93dXvMV0fUR3kzk9lMikJ0Zv+ P0UQg+GeSbo9K3ZyTrY7LwPUbzZizAC6V/ycKBziq9LAPpOIsvgEtnTe5k+dbySbAmPsPcscaD 8baDwS6y/UYlPjr2wMdG3nes2R7iMLPg6zP2gQdm/QfGBldPr1EFVncdPoAVlCtomEj+UJ6DAv xUVwhv8tzQXDc5x9KIh9YA0NcOG0zaZ3iut0Yw8/EJFrb6uDpIExldMSPyhegjEmwlGO+XA7aU FvU= From: Muhammad Hamza To: CC: Muhammad Hamza , Awais Belal Subject: [PATCH 2/2] udev-extraconf/mount.sh: only mount devices on hotplug Date: Mon, 20 Jun 2022 18:17:56 +0500 Message-ID: <20220620131756.269638-2-muhammad_hamza@mentor.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220620131756.269638-1-muhammad_hamza@mentor.com> References: <20220620131756.269638-1-muhammad_hamza@mentor.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 20 Jun 2022 13:18:37 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/167107 fdisk from util-linux (2.31.1) and above allows the user to manipulate an already mounted device. In order to achieve this functionality it issues a BLKRRPART (block device re-read part) ioctl and in response the kernel generates remove/change/add events if the device is not mounted (manually unmounted etc) which are caught and processed by udev. This causes our auto-mounter to remount everything because it does not keep track and things go out of control. Differentiating between types of remove events such as the one described above (generated by BLKRRPART) and one where the device is physically plugged out is only possible using the DEVPATH variable which is cleaned up only when the device is actually plugged-out. This fixes the above anomaly by only mounting a device in add event which is cleaned up properly (tmp cache deleted) in the remove event or is not present in the tmp cache while making use of the DEVPATH variable during the remove action. Signed-off-by: Awais Belal Signed-off-by: Muhammad Hamza --- .../recipes-core/udev/udev-extraconf/mount.sh | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/meta/recipes-core/udev/udev-extraconf/mount.sh b/meta/recipes-core/udev/udev-extraconf/mount.sh index 994de75b28..5195bf8dc2 100644 --- a/meta/recipes-core/udev/udev-extraconf/mount.sh +++ b/meta/recipes-core/udev/udev-extraconf/mount.sh @@ -45,6 +45,13 @@ automount_systemd() { return fi + # Only go for auto-mounting when the device has been cleaned up in remove + # or has not been identified yet + if [ -e "/tmp/.automount-$name" ]; then + logger "mount.sh/automount" "[$MOUNT_BASE/$name] is already cached" + return + fi + # Skip the partition which are already in /etc/fstab grep "^[[:space:]]*$DEVNAME" /etc/fstab && return for n in LABEL PARTLABEL UUID PARTUUID; do @@ -114,6 +121,13 @@ automount() { name="${LABEL}-${name}" fi + # Only go for auto-mounting when the device has been cleaned up in remove + # or has not been identified yet + if [ -e "/tmp/.automount-$name" ]; then + logger "mount.sh/automount" "[$MOUNT_BASE/$name] is already cached" + return + fi + ! test -d "$MOUNT_BASE/$name" && mkdir -p "$MOUNT_BASE/$name" # Silent util-linux's version of mounting auto if [ "x`readlink $MOUNT`" = "x/bin/mount.util-linux" ] ; @@ -174,12 +188,18 @@ if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && [ -n "$ID_FS_TYPE" -o "$media_t fi if [ "$ACTION" = "remove" ] || [ "$ACTION" = "change" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then - for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " ` - do - $UMOUNT $mnt - done - - # Remove empty directories from auto-mounter name="`basename "$DEVNAME"`" - test -e "/tmp/.automount-$name" && rm_dir "$MOUNT_BASE/$name" + tmpfile=`find /tmp | grep "\.automount-.*${name}$"` + if [ ! -e "/sys/$DEVPATH" -a -e "$tmpfile" ]; then + logger "mount.sh/remove" "cleaning up $DEVNAME, was mounted by the auto-mounter" + for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " ` + do + $UMOUNT $mnt + done + # Remove mount directory created by the auto-mounter + # and clean up our tmp cache file + mntdir=`cat "$tmpfile"` + rm_dir "$MOUNT_BASE/$mntdir" + rm "$tmpfile" + fi fi