From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nigel Kukard Date: Fri, 07 Aug 2009 14:48:17 +0000 Subject: Re: udev 145, when are events fully processed? Message-Id: <4A7C3EB1.7030808@lbsd.net> MIME-Version: 1 Content-Type: multipart/mixed; boundary="------------020807000603020104060408" List-Id: References: <4A749D9E.3020709@lbsd.net> In-Reply-To: <4A749D9E.3020709@lbsd.net> To: linux-hotplug@vger.kernel.org This is a multi-part message in MIME format. --------------020807000603020104060408 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit > On 8/7/09, Nigel Kukard wrote: > >>>> Trying to figure something out here, using the following I'm seeing a >>>> delay in the creation of block devices in /dev ... >>>> >>>> # trigger the sorted events >>>> echo -e '\000\000\000\000'> /proc/sys/kernel/hotplug >>>> >>>> rm -fr /dev/.udev> /dev/null 2>&1 >>>> mkdir -p /dev/.udev> /dev/null 2>&1 >>>> /sbin/udevd >>>> >>>> # Not entirely sure what this is for >>>> /sbin/udevadm control --env=STARTUP=1 >>>> /sbin/udevadm trigger >>>> >>>> /sbin/udevadm settle >>>> >>> settle should have waited until all events have been processed >>> >> Does this mean fully processed or just received? I asked on >> #udev/irc.freenode.net and was told that settle only waits until udev >> had received them. >> > > It does wait until events are "fully processed". The problem is that > this will only apply to the events generated directly by udevadm > trigger. USB devices may turn up late to the party for various > reasons. > > Lurking on LKML it sounds like it _might_ be possible to fix the USB > issue. AFAIK no-one is working to support this for userspace though. > > >> The only reason it worked before was because of the speed improvements >> made recently. >> > > Yup. > > >>>> # Nor sure what this does >>>> /sbin/udevadm control --env=STARTUP= >>>> >>>> >>>> I think my problem is, while all the events have been sent to udevd >>>> there is a delay if I do a "fsck LABEL=root" straight on say the next >>>> line, a "ls" shows that none of the block devices exist until a second >>>> or two later. A sleep 5 before my "ls" works around this and the block >>>> devices show up. >>>> >>>> Any ideas how I can determine once all udev events have finished >>>> processing so I can continue boot? >>>> >>> check would look like: >>> /sbin/udevadm settle --timeout=0 || echo "Still not all udev events >>> processed" >>> >>> waiting should be: >>> /sbin/udevadm settle >>> >> Same result on both. >> >> I went further and wrote a small C app to wait for the udev event, this >> works 100%. I run the C app in the background before I run trigger & >> settle, then do a "wait" until it returns. >> >> -N >> > > I think everybody else just loops waiting for the device node to > appear. So technically you may have a more advanced solution :-). > > Usually you also want a timeout in case something goes wrong. > Depending on the system you can e.g. drop to an emergency shell or > just print an error message. > I have a nice C proggie I'll including in bootutils, unless you guys are interested in including it in udev?. Attached for anyone interested, with timeout support. It can wait for a device or labeled device to come up :) -N --------------020807000603020104060408 Content-Type: text/plain; name="udev-wait-for-device.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="udev-wait-for-device.c" /* * udev-wait-for-device.c - Wait for device to appear * Copyright (C) 2009, Nigel Kukard * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * -- * * Portions of code from searches on the Internet: * - Copyright (C) 2009 Andy Walls * */ #define VERSION "0.0.2" #define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE #include #include #include #include #include #include #include #include #include #include #include /* Exit handling in a sane way */ static int udev_exit; static void sig_handler(int signum) { if (signum == SIGINT || signum == SIGTERM) udev_exit = 1; } /* Print out our usage */ void printUsage(char **argv) { printf("Usage: %s \n",argv[0]); printf("\n"); printf("Options:\n"); printf(" -l, --label=