From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1.windriver.com (mail1.windriver.com [147.11.146.13]) by mail.openembedded.org (Postfix) with ESMTP id 8720774549 for ; Thu, 12 Apr 2018 01:45:37 +0000 (UTC) Received: from ALA-HCA.corp.ad.wrs.com ([147.11.189.40]) by mail1.windriver.com (8.15.2/8.15.1) with ESMTPS id w3C1jXMB010123 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 11 Apr 2018 18:45:34 -0700 (PDT) Received: from [128.224.162.148] (128.224.162.148) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 11 Apr 2018 18:45:32 -0700 To: Christopher Larson References: <1523258914-12621-1-git-send-email-hongzhi.song@windriver.com> From: "Hongzhi, Song" Message-ID: Date: Thu, 12 Apr 2018 09:47:31 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: X-Originating-IP: [128.224.162.148] Cc: Patches and discussions about the oe-core layer Subject: Re: [PATCH] udev-extraconf: Add systemd-mount to mount.sh X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Apr 2018 01:45:37 -0000 Content-Type: multipart/alternative; boundary="------------240BE18608E3AF900A68E146" Content-Language: en-US --------------240BE18608E3AF900A68E146 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit I am very sorry, this is my fault. My original idea is to modify udev-extraconf/mount.sh. And I will remake a patch. Sorry again. Please ignore this patch. On 2018年04月12日 09:35, Christopher Larson wrote: > Why are you adding a new mount.sh at meta/recipes-core/udev/mount.sh > rather than updating the existing one > at meta/recipes-core/udev/udev-extraconf/mount.sh? > > On Mon, Apr 9, 2018 at 12:28 AM, Hongzhi.Song > > wrote: > > This patch fixs the problem that block devices unable to be > formatted when > systemd and udev-extraconf recipes added into rootfs. > > If we add systemd and udev-extraconf recipes into rootfs: >     VIRTUAL-RUNTIME_init_manager = "systemd" >     DISTRO_FEATURES_append = " systemd" >     DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit" >     KERNEL_FEATURES_append = " cfg/systemd.scc" >     IMAGE_INSTALL_append = " udev-extraconf" >     IMAGE_FSTYPES += "tar.bz2 ext4" >     IMAGE_INSTALL_append = " e2fsprogs-mke2fs" > then systemd-udevd.service will invoke udev rules to automount > block devices > any probed under itself private namespace, this behavior results > in host space > can't format those devices. And host space can't find where the > device is used. > Such as: >     root@qemux86:~# mkfs.ext4 /dev/sda1 >     mke2fs 1.43.8 (1-Jan-2018) >     /dev/sda1 contains a ext4 file system >             last mounted on Tue Apr  3 06:22:41 2018 >     Proceed anyway? (y,N) y >     /dev/sda1 is apparently in use by the system; will not make a > filesystem here! > > Command systemd-mount recommended by systemd maintainer instead of > command mount > will fix the problem brought with private namespace. Systemd-mount > request the > mount operation to be executed by PID 1, and hence host space can > access the block > devices. > > [YOCTO #12644] > > Signed-off-by: Hongzhi.Song > > --- >  meta/recipes-core/udev/mount.sh | 141 > ++++++++++++++++++++++++++++++++++++++++ >  1 file changed, 141 insertions(+) >  create mode 100644 meta/recipes-core/udev/mount.sh > > diff --git a/meta/recipes-core/udev/mount.sh > b/meta/recipes-core/udev/mount.sh > new file mode 100644 > index 0000000..2fa2925 > --- /dev/null > +++ b/meta/recipes-core/udev/mount.sh > @@ -0,0 +1,141 @@ > +#!/bin/sh > +# > +# Called from udev > +# > +# Attempt to mount any added block devices and umount any removed > devices > + > + > +BASE_INIT="`readlink "/sbin/init"`" > +INIT_SYSTEMD="/lib/systemd/systemd" > + > +if [ "x$BASE_INIT" = "x$INIT_SYSTEMD" ];then > +       # systemd as init uses systemd-mount to mount block devices > +        MOUNT="/usr/bin/systemd-mount" > +        UMOUNT="/usr/bin/systemd-umount" > + > +        if [ -x $MOUNT ] && [ -x $UMOUNT ]; > +        then > +                logger "Using systemd-mount to finish mount" > +        else > +                logger "Linux init is using systemd, so please > install systemd-mount to finish mount" > +               exit 1 > +        fi > +else > +        MOUNT="/bin/mount" > +        UMOUNT="/bin/umount" > +fi > + > +PMOUNT="/usr/bin/pmount" > + > +for line in `grep -h -v ^# /etc/udev/mount.blacklist > /etc/udev/mount.blacklist.d/*` > +do > +       if [ ` expr match "$DEVNAME" "$line" ` -gt 0 ]; > +       then > +               logger "udev/mount.sh" "[$DEVNAME] is blacklisted, > ignoring" > +               exit 0 > +       fi > +done > + > +automount_systemd() { > +        name="`basename "$DEVNAME"`" > + > +        ! test -d "/run/media/$name" && mkdir -p "/run/media/$name" > + > +        MOUNT="$MOUNT -o silent" > + > +        # If filesystemtype is vfat, change the ownership group > to 'disk', and > +        # grant it with  w/r/x permissions. > +        case $ID_FS_TYPE in > +        vfat|fat) > +                MOUNT="$MOUNT -o umask=007,gid=`awk -F':' > '/^disk/{print $3}' /etc/group`" > +                ;; > +        # TODO > +        *) > +                ;; > +        esac > + > +        if ! $MOUNT --no-block -t auto $DEVNAME "/run/media/$name" > +        then > +                #logger "mount.sh/automount > " "$MOUNT -t auto $DEVNAME > \"/run/media/$name\" failed!" > +                rm_dir "/run/media/$name" > +        else > +                logger "mount.sh/automount > " "Auto-mount of [/run/media/$name] > successful" > +                touch "/tmp/.automount-$name" > +        fi > +} > + > +automount() { > +       name="`basename "$DEVNAME"`" > + > +       ! test -d "/run/media/$name" && mkdir -p "/run/media/$name" > +       # Silent util-linux's version of mounting auto > +       if [ "x`readlink $MOUNT`" = "x/bin/mount.util-linux" ] ; > +       then > +               MOUNT="$MOUNT -o silent" > +       fi > + > +       # If filesystem type is vfat, change the ownership group > to 'disk', and > +       # grant it with  w/r/x permissions. > +       case $ID_FS_TYPE in > +       vfat|fat) > +               MOUNT="$MOUNT -o umask=007,gid=`awk -F':' > '/^disk/{print $3}' /etc/group`" > +               ;; > +       # TODO > +       *) > +               ;; > +       esac > + > +       if ! $MOUNT -t auto $DEVNAME "/run/media/$name" > +       then > +               #logger "mount.sh/automount > " "$MOUNT -t auto $DEVNAME > \"/run/media/$name\" failed!" > +               rm_dir "/run/media/$name" > +       else > +               logger "mount.sh/automount > " "Auto-mount of [/run/media/$name] > successful" > +               touch "/tmp/.automount-$name" > +       fi > +} > + > +rm_dir() { > +       # We do not want to rm -r populated directories > +       if test "`find "$1" | wc -l | tr -d " "`" -lt 2 -a -d "$1" > +       then > +               ! test -z "$1" && rm -r "$1" > +       else > +               logger "mount.sh/automount > " "Not removing non-empty directory [$1]" > +       fi > +} > + > +# No ID_FS_TYPE for cdrom device, yet it should be mounted > +name="`basename "$DEVNAME"`" > +[ -e /sys/block/$name/device/media ] && media_type=`cat > /sys/block/$name/device/media` > + > +if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && [ -n > "$ID_FS_TYPE" -o "$media_type" = "cdrom" ]; then > +       if [ -x "$PMOUNT" ]; then > +               $PMOUNT $DEVNAME 2> /dev/null > +       elif [ -x $MOUNT ]; then > +               $MOUNT $DEVNAME 2> /dev/null > +       fi > + > +       # If the device isn't mounted at this point, it isn't > +       # configured in fstab (note the root filesystem can show up as > +       # /dev/root in /proc/mounts, so check the device number too) > +        if expr $MAJOR "*" 256 + $MINOR != `stat -c %d /`; then > +                if [ "`basename $MOUNT`" = "systemd-mount" ];then > +                        grep -q "^$DEVNAME " /proc/mounts || > automount_systemd > +                else > +                        grep -q "^$DEVNAME " /proc/mounts || > automount > +                fi > +        fi > +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 "/run/media/$name" > +fi > -- > 2.8.1 > > -- > _______________________________________________ > Openembedded-core mailing list > Openembedded-core@lists.openembedded.org > > http://lists.openembedded.org/mailman/listinfo/openembedded-core > > > > > > -- > Christopher Larson > kergoth at gmail dot com > Founder - BitBake, OpenEmbedded, OpenZaurus > Senior Software Engineer, Mentor Graphics --------------240BE18608E3AF900A68E146 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 8bit

I am very sorry, this is my fault. My original idea is to modify udev-extraconf/mount.sh.

And I will remake a patch.

Sorry again. Please ignore this patch.



On 2018年04月12日 09:35, Christopher Larson wrote:
Why are you adding a new mount.sh at meta/recipes-core/udev/mount.sh rather than updating the existing one at meta/recipes-core/udev/udev-extraconf/mount.sh?

On Mon, Apr 9, 2018 at 12:28 AM, Hongzhi.Song <hongzhi.song@windriver.com> wrote:
This patch fixs the problem that block devices unable to be formatted when
systemd and udev-extraconf recipes added into rootfs.

If we add systemd and udev-extraconf recipes into rootfs:
    VIRTUAL-RUNTIME_init_manager = "systemd"
    DISTRO_FEATURES_append = " systemd"
    DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit"
    KERNEL_FEATURES_append = " cfg/systemd.scc"
    IMAGE_INSTALL_append = " udev-extraconf"
    IMAGE_FSTYPES += "tar.bz2 ext4"
    IMAGE_INSTALL_append = " e2fsprogs-mke2fs"
then systemd-udevd.service will invoke udev rules to automount block devices
any probed under itself private namespace, this behavior results in host space
can't format those devices. And host space can't find where the device is used.
Such as:
    root@qemux86:~# mkfs.ext4 /dev/sda1
    mke2fs 1.43.8 (1-Jan-2018)
    /dev/sda1 contains a ext4 file system
            last mounted on Tue Apr  3 06:22:41 2018
    Proceed anyway? (y,N) y
    /dev/sda1 is apparently in use by the system; will not make a filesystem here!

Command systemd-mount recommended by systemd maintainer instead of command mount
will fix the problem brought with private namespace. Systemd-mount request the
mount operation to be executed by PID 1, and hence host space can access the block
devices.

[YOCTO #12644]

Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
---
 meta/recipes-core/udev/mount.sh | 141 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)
 create mode 100644 meta/recipes-core/udev/mount.sh

diff --git a/meta/recipes-core/udev/mount.sh b/meta/recipes-core/udev/mount.sh
new file mode 100644
index 0000000..2fa2925
--- /dev/null
+++ b/meta/recipes-core/udev/mount.sh
@@ -0,0 +1,141 @@
+#!/bin/sh
+#
+# Called from udev
+#
+# Attempt to mount any added block devices and umount any removed devices
+
+
+BASE_INIT="`readlink "/sbin/init"`"
+INIT_SYSTEMD="/lib/systemd/systemd"
+
+if [ "x$BASE_INIT" = "x$INIT_SYSTEMD" ];then
+       # systemd as init uses systemd-mount to mount block devices
+        MOUNT="/usr/bin/systemd-mount"
+        UMOUNT="/usr/bin/systemd-umount"
+
+        if [ -x $MOUNT ] && [ -x $UMOUNT ];
+        then
+                logger "Using systemd-mount to finish mount"
+        else
+                logger "Linux init is using systemd, so please install systemd-mount to finish mount"
+               exit 1
+        fi
+else
+        MOUNT="/bin/mount"
+        UMOUNT="/bin/umount"
+fi
+
+PMOUNT="/usr/bin/pmount"
+
+for line in `grep -h -v ^# /etc/udev/mount.blacklist /etc/udev/mount.blacklist.d/*`
+do
+       if [ ` expr match "$DEVNAME" "$line" ` -gt 0 ];
+       then
+               logger "udev/mount.sh" "[$DEVNAME] is blacklisted, ignoring"
+               exit 0
+       fi
+done
+
+automount_systemd() {
+        name="`basename "$DEVNAME"`"
+
+        ! test -d "/run/media/$name" && mkdir -p "/run/media/$name"
+
+        MOUNT="$MOUNT -o silent"
+
+        # If filesystemtype is vfat, change the ownership group to 'disk', and
+        # grant it with  w/r/x permissions.
+        case $ID_FS_TYPE in
+        vfat|fat)
+                MOUNT="$MOUNT -o umask=007,gid=`awk -F':' '/^disk/{print $3}' /etc/group`"
+                ;;
+        # TODO
+        *)
+                ;;
+        esac
+
+        if ! $MOUNT --no-block -t auto $DEVNAME "/run/media/$name"
+        then
+                #logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/run/media/$name\" failed!"
+                rm_dir "/run/media/$name"
+        else
+                logger "mount.sh/automount" "Auto-mount of [/run/media/$name] successful"
+                touch "/tmp/.automount-$name"
+        fi
+}
+
+automount() {
+       name="`basename "$DEVNAME"`"
+
+       ! test -d "/run/media/$name" && mkdir -p "/run/media/$name"
+       # Silent util-linux's version of mounting auto
+       if [ "x`readlink $MOUNT`" = "x/bin/mount.util-linux" ] ;
+       then
+               MOUNT="$MOUNT -o silent"
+       fi
+
+       # If filesystem type is vfat, change the ownership group to 'disk', and
+       # grant it with  w/r/x permissions.
+       case $ID_FS_TYPE in
+       vfat|fat)
+               MOUNT="$MOUNT -o umask=007,gid=`awk -F':' '/^disk/{print $3}' /etc/group`"
+               ;;
+       # TODO
+       *)
+               ;;
+       esac
+
+       if ! $MOUNT -t auto $DEVNAME "/run/media/$name"
+       then
+               #logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/run/media/$name\" failed!"
+               rm_dir "/run/media/$name"
+       else
+               logger "mount.sh/automount" "Auto-mount of [/run/media/$name] successful"
+               touch "/tmp/.automount-$name"
+       fi
+}
+
+rm_dir() {
+       # We do not want to rm -r populated directories
+       if test "`find "$1" | wc -l | tr -d " "`" -lt 2 -a -d "$1"
+       then
+               ! test -z "$1" && rm -r "$1"
+       else
+               logger "mount.sh/automount" "Not removing non-empty directory [$1]"
+       fi
+}
+
+# No ID_FS_TYPE for cdrom device, yet it should be mounted
+name="`basename "$DEVNAME"`"
+[ -e /sys/block/$name/device/media ] && media_type=`cat /sys/block/$name/device/media`
+
+if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && [ -n "$ID_FS_TYPE" -o "$media_type" = "cdrom" ]; then
+       if [ -x "$PMOUNT" ]; then
+               $PMOUNT $DEVNAME 2> /dev/null
+       elif [ -x $MOUNT ]; then
+               $MOUNT $DEVNAME 2> /dev/null
+       fi
+
+       # If the device isn't mounted at this point, it isn't
+       # configured in fstab (note the root filesystem can show up as
+       # /dev/root in /proc/mounts, so check the device number too)
+        if expr $MAJOR "*" 256 + $MINOR != `stat -c %d /`; then
+                if [ "`basename $MOUNT`" = "systemd-mount" ];then
+                        grep -q "^$DEVNAME " /proc/mounts || automount_systemd
+                else
+                        grep -q "^$DEVNAME " /proc/mounts || automount
+                fi
+        fi
+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 "/run/media/$name"
+fi
--
2.8.1

--
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core



--
Christopher Larson
kergoth at gmail dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Senior Software Engineer, Mentor Graphics

--------------240BE18608E3AF900A68E146--