rpms/udev/devel udevstart2.patch, NONE, 1.1 start_udev, 1.43, 1.44 udev.rules, 1.45, 1.46 udev.spec, 1.125, 1.126

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Mon Nov 21 12:04:46 UTC 2005


Author: harald

Update of /cvs/dist/rpms/udev/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv16949

Modified Files:
	start_udev udev.rules udev.spec 
Added Files:
	udevstart2.patch 
Log Message:
speedup udev event replay with udevstart2

udevstart2.patch:
 Makefile     |    3 
 udevstart2.c |  372 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 375 insertions(+)

--- NEW FILE udevstart2.patch ---
--- /dev/null	2005-10-06 16:59:29.170954848 +0200
+++ udev-075/udevstart2.c	2005-11-21 12:04:22.000000000 +0100
@@ -0,0 +1,372 @@
+/*
+ * udevstart.c
+ *
+ * Copyright (C) 2004 Greg Kroah-Hartman <greg at kroah.com>
+ * Copyright (C) 2004 Kay Sievers <kay at vrfy.org>
+ *
+ * Quick and dirty way to populate a /dev with udev if your system
+ * does not have access to a shell.  Based originally on a patch
+ * from:
+ *	Harald Hoyer <harald at redhat.com>
+ *
+ *	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 version 2 of the License.
+ * 
+ *	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.,
+ *	675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <signal.h>
+#include <syslog.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "libsysfs/sysfs/libsysfs.h"
+#include "udev_libc_wrapper.h"
+#include "udev_sysfs.h"
+#include "udev.h"
+#include "udev_version.h"
+#include "logging.h"
+#include "udev_utils.h"
+#include "udev_rules.h"
+#include "list.h"
+
+static const char *udev_log_str;
+
+#ifdef USE_LOG
+void log_message(int priority, const char *format, ...)
+{
+	va_list args;
+
+	if (priority > udev_log_priority)
+		return;
+
+	va_start(args, format);
+	vsyslog(priority, format, args);
+	va_end(args);
+}
+#endif
+
+struct device {
+	struct list_head node;
+	char path[PATH_SIZE];
+	char subsys[NAME_SIZE];
+};
+
+/* sort files in lexical order */
+static int device_list_insert(const char *path, char *subsystem, struct list_head *device_list)
+{
+	struct device *loop_device;
+	struct device *new_device;
+	const char *devpath = &path[strlen(sysfs_path)];
+
+	dbg("insert: '%s'\n", devpath);
+
+	list_for_each_entry(loop_device, device_list, node) {
+		if (strcmp(loop_device->path, devpath) > 0) {
+			break;
+		}
+	}
+
+	new_device = malloc(sizeof(struct device));
+	if (new_device == NULL) {
+		dbg("error malloc");
+		return -ENOMEM;
+	}
+
+	strlcpy(new_device->path, devpath, sizeof(new_device->path));
+	strlcpy(new_device->subsys, subsystem, sizeof(new_device->subsys));
+	list_add_tail(&new_device->node, &loop_device->node);
+	dbg("add '%s' from subsys '%s'", new_device->path, new_device->subsys);
+	return 0;
+}
+
+/* list of devices that we should run last due to any one of a number of reasons */
+static char *last_list[] = {
+	"/block/dm",	/* on here because dm wants to have the block devices around before it */
+	NULL,
+};
+
+/* list of devices that we should run first due to any one of a number of reasons */
+static char *first_list[] = {
+	"/class/mem",
+	"/class/tty",
+	"/bus",
+	NULL,
+};
+
+static int add_device(const char *devpath, const char *subsystem)
+{
+  char filename[PATH_SIZE];
+  int fd;
+
+  snprintf(filename, sizeof(filename), "%s/%s/uevent", sysfs_path, devpath);
+  filename[sizeof(filename)-1] = '\0';
+
+  dbg("Trigger %s", filename);
+  fd = open(filename, O_WRONLY);
+  if (fd > 0) {
+    write(fd, "add\n", 4);
+    close(fd);
+  }
+  else return 1;
+  
+  return 0;
+}
+
+static void exec_list(struct list_head *device_list)
+{
+	struct device *loop_device;
+	struct device *tmp_device;
+	int i;
+
+	/* handle the "first" type devices first */
+	list_for_each_entry_safe(loop_device, tmp_device, device_list, node) {
+		for (i = 0; first_list[i] != NULL; i++) {
+			if (strncmp(loop_device->path, first_list[i], strlen(first_list[i])) == 0) {
+				add_device(loop_device->path, loop_device->subsys);
+				list_del(&loop_device->node);
+				free(loop_device);
+				break;
+			}
+		}
+	}
+
+	/* handle the devices we are allowed to, excluding the "last" type devices */
+	list_for_each_entry_safe(loop_device, tmp_device, device_list, node) {
+		int found = 0;
+		for (i = 0; last_list[i] != NULL; i++) {
+			if (strncmp(loop_device->path, last_list[i], strlen(last_list[i])) == 0) {
+				found = 1;
+				break;
+			}
+		}
+		if (found)
+			continue;
+
+		add_device(loop_device->path, loop_device->subsys);
+		list_del(&loop_device->node);
+		free(loop_device);
+	}
+
+	/* handle the rest of the devices left over, if any */
+	list_for_each_entry_safe(loop_device, tmp_device, device_list, node) {
+		add_device(loop_device->path, loop_device->subsys);
+		list_del(&loop_device->node);
+		free(loop_device);
+	}
+}
+
+static int has_devt(const char *path)
+{
+	char filename[PATH_SIZE];
+	struct stat statbuf;
+
+	snprintf(filename, sizeof(filename), "%s/uevent", path);
+	filename[sizeof(filename)-1] = '\0';
+
+	if (stat(filename, &statbuf) == 0)
+		return 1;
+
+	return 0;
+}
+
+static void udev_scan_block(struct list_head *device_list)
+{
+	char base[PATH_SIZE];
+	DIR *dir;
+	struct dirent *dent;
+
+	snprintf(base, sizeof(base), "%s/block", sysfs_path);
+	base[sizeof(base)-1] = '\0';
+
+	dir = opendir(base);
+	if (dir != NULL) {
+		for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+			char dirname[PATH_SIZE];
+			DIR *dir2;
+			struct dirent *dent2;
+
+			if (dent->d_name[0] == '.')
+				continue;
+
+			snprintf(dirname, sizeof(dirname), "%s/%s", base, dent->d_name);
+			dirname[sizeof(dirname)-1] = '\0';
+			if (has_devt(dirname))
+				device_list_insert(dirname, "block", device_list);
+			else
+				continue;
+
+			/* look for partitions */
+			dir2 = opendir(dirname);
+			if (dir2 != NULL) {
+				for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
+					char dirname2[PATH_SIZE];
+
+					if (dent2->d_name[0] == '.')
+						continue;
+
+					snprintf(dirname2, sizeof(dirname2), "%s/%s", dirname, dent2->d_name);
+					dirname2[sizeof(dirname2)-1] = '\0';
+
+					if (has_devt(dirname2))
+						device_list_insert(dirname2, "block", device_list);
+				}
+				closedir(dir2);
+			}
+		}
+		closedir(dir);
+	}
+}
+
+static void udev_scan_bus(struct list_head *device_list)
+{
+	char base[PATH_SIZE];
+	DIR *dir;
+	struct dirent *dent;
+
+	snprintf(base, sizeof(base), "%s/bus", sysfs_path);
+	base[sizeof(base)-1] = '\0';
+
+	dir = opendir(base);
+	if (dir != NULL) {
+		for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+			char dirname[PATH_SIZE];
+			DIR *dir2;
+			struct dirent *dent2;
+
+			if (dent->d_name[0] == '.')
+				continue;
+
+			snprintf(dirname, sizeof(dirname), "%s/%s/devices", base, dent->d_name);
+			dirname[sizeof(dirname)-1] = '\0';
+
+			dir2 = opendir(dirname);
+			if (dir2 != NULL) {
+				for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
+					char dirname2[PATH_SIZE];
+
+					if (dent2->d_name[0] == '.')
+						continue;
+
+					snprintf(dirname2, sizeof(dirname2), "%s/%s", dirname, dent2->d_name);
+					dirname2[sizeof(dirname2)-1] = '\0';
+
+					if (has_devt(dirname2))
+						device_list_insert(dirname2, dent->d_name, device_list);
+				}
+				closedir(dir2);
+			}
+		}
+		closedir(dir);
+	}
+}
+
+
+static void udev_scan_class(struct list_head *device_list)
+{
+	char base[PATH_SIZE];
+	DIR *dir;
+	struct dirent *dent;
+
+	snprintf(base, sizeof(base), "%s/class", sysfs_path);
+	base[sizeof(base)-1] = '\0';
+
+	dir = opendir(base);
+	if (dir != NULL) {
+		for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+			char dirname[PATH_SIZE];
+			DIR *dir2;
+			struct dirent *dent2;
+
+			if (dent->d_name[0] == '.')
+				continue;
+
+			snprintf(dirname, sizeof(dirname), "%s/%s", base, dent->d_name);
+			dirname[sizeof(dirname)-1] = '\0';
+
+			dir2 = opendir(dirname);
+			if (dir2 != NULL) {
+				for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
+					char dirname2[PATH_SIZE];
+
+					if (dent2->d_name[0] == '.')
+						continue;
+
+					snprintf(dirname2, sizeof(dirname2), "%s/%s", dirname, dent2->d_name);
+					dirname2[sizeof(dirname2)-1] = '\0';
+
+					if (has_devt(dirname2))
+						device_list_insert(dirname2, dent->d_name, device_list);
+				}
+				closedir(dir2);
+			}
+		}
+		closedir(dir);
+	}
+}
+
+static void asmlinkage sig_handler(int signum)
+{
+	switch (signum) {
+		case SIGALRM:
+			exit(1);
+		case SIGINT:
+		case SIGTERM:
+			exit(20 + signum);
+	}
+}
+
+int main(int argc, char *argv[], char *envp[])
+{
+	LIST_HEAD(device_list);
+	struct sigaction act;
+
+	logging_init("udevstart2");
+	udev_init_config();
+	dbg("version %s", UDEV_VERSION);
+
+	udev_log_str = getenv("UDEV_LOG");
+
+	/* disable all logging if not explicitely requested */
+	if (udev_log_str == NULL)
+		udev_log_priority = 0;
+
+	/* set signal handlers */
+	memset(&act, 0x00, sizeof(act));
+	act.sa_handler = (void (*) (int))sig_handler;
+	sigemptyset (&act.sa_mask);
+	act.sa_flags = 0;
+	sigaction(SIGALRM, &act, NULL);
+	sigaction(SIGINT, &act, NULL);
+	sigaction(SIGTERM, &act, NULL);
+
+	/* trigger timeout to prevent hanging processes */
+	alarm(UDEV_ALARM_TIMEOUT);
+
+	udev_scan_bus(&device_list);
+	udev_scan_class(&device_list);
+	udev_scan_block(&device_list);
+	exec_list(&device_list);
+
+	logging_close();
+	return 0;
+}
--- udev-075/Makefile.udevstart2	2005-11-10 02:20:25.000000000 +0100
+++ udev-075/Makefile	2005-11-21 11:16:40.000000000 +0100
@@ -54,6 +54,7 @@
 	udevmonitor			\
 	udevinfo			\
 	udevtest			\
+	udevstart2 			\
 	udevstart
 
 HEADERS = \
@@ -343,6 +344,7 @@
 	$(INSTALL_PROGRAM) -D udevinfo $(DESTDIR)$(usrbindir)/udevinfo
 	$(INSTALL_PROGRAM) -D udevtest $(DESTDIR)$(usrbindir)/udevtest
 	$(INSTALL_PROGRAM) -D udevstart $(DESTDIR)$(sbindir)/udevstart
+	$(INSTALL_PROGRAM) -D udevstart2 $(DESTDIR)$(sbindir)/udevstart2
 	@extras="$(EXTRAS)"; for target in $$extras; do \
 		echo $$target; \
 		$(MAKE) -C $$target $@; \
@@ -360,6 +362,7 @@
 	- rm -f $(DESTDIR)$(sbindir)/udevsend
 	- rm -f $(DESTDIR)$(sbindir)/udevcontrol
 	- rm -f $(DESTDIR)$(sbindir)/udevstart
+	- rm -f $(DESTDIR)$(sbindir)/udevstart2
 	- rm -f $(DESTDIR)$(usrsbindir)/udevmonitor
 	- rm -f $(usrbindir)/udevinfo
 	- rm -f $(DESTDIR)$(DESTDIR)$(usrbindir)/udevtest


Index: start_udev
===================================================================
RCS file: /cvs/dist/rpms/udev/devel/start_udev,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- start_udev	21 Nov 2005 07:25:27 -0000	1.43
+++ start_udev	21 Nov 2005 12:04:43 -0000	1.44
@@ -190,40 +190,18 @@
 }
 
 event_replay () {
-	# generate events with the sysfs trigger
-	list="$(find_f /sys/bus uevent) $(find_f /sys/class uevent) $(find_f /sys/block uevent)"
-
-	for i in $list; do
-		case "$i" in
-		*/device/uevent)
-			# skip followed device symlinks
-			continue
-			;;
-		*/class/mem/*|*/class/tty/*)
-			first="$first $i"
-			;;
-		*/block/md*)
-			last="$last $i"
-			;;
-		*/*)
-		default="$default $i"
-			;;
-		esac
-	done
-
-	if [ -n "$first" -o -n "$default" -o -n "$last" ]; then
+	if [ -f "/sys/class/tty/console/uevent" ]; then
 		# trigger the sorted events
-		set $first $default $last
-		echo -e '\000' > /proc/sys/kernel/hotplug
-		for i in $@; do
-			echo "add" > "$i"
-		done
+		echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
+		/sbin/udevstart2
+		return $?
 	else
+	        sysctl -w kernel.hotplug="/sbin/udevsend" >/dev/null 2>&1
 		scsi_replay > "$udev_root/null" 2>&1
 		ide_scan > "$udev_root/null" 2>&1
-		return /sbin/udevstart 
+		/sbin/udevstart 
+		return $?
 	fi
-	return 0
 }
 
 
@@ -259,6 +237,7 @@
 	ret=$[$ret + $?]
 }
 rm -fr "$udev_db"
+mkdir "$udev_db"
 make_extra_nodes
 kill_udevd > "$udev_root/null" 2>&1
 udevd -d


Index: udev.rules
===================================================================
RCS file: /cvs/dist/rpms/udev/devel/udev.rules,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- udev.rules	14 Nov 2005 17:42:04 -0000	1.45
+++ udev.rules	21 Nov 2005 12:04:44 -0000	1.46
@@ -11,6 +11,7 @@
 
 # console devices
 KERNEL=="tty",			MODE="0666", OPTIONS="last_rule"
+KERNEL=="console",		MODE="0600", OPTIONS="last_rule"
 KERNEL=="tty[0-9]",		GROUP="tty", MODE="0660", OPTIONS="last_rule"
 KERNEL=="tty[0-9][0-9]*",	GROUP="tty", MODE="0660", OPTIONS="last_rule"
 KERNEL=="vc/[0-9]*",		GROUP="tty", MODE="0660", OPTIONS="last_rule"
@@ -38,21 +39,21 @@
 KERNEL=="tts/USB[0-9]*",	GROUP="uucp", MODE="0660"
 
 # vc devices
-KERNEL=="vcs",			OWNER="vcsa", GROUP="tty"
-KERNEL=="vcs[0-9]*",		OWNER="vcsa", GROUP="tty"
-KERNEL=="vcsa",			OWNER="vcsa", GROUP="tty"
-KERNEL=="vcsa[0-9]*",		OWNER="vcsa", GROUP="tty"
-KERNEL=="vcc/*",		OWNER="vcsa", GROUP="tty"
+KERNEL=="vcs",			OWNER="vcsa", GROUP="tty", OPTIONS="last_rule"
+KERNEL=="vcs[0-9]*",		OWNER="vcsa", GROUP="tty", OPTIONS="last_rule"
+KERNEL=="vcsa",			OWNER="vcsa", GROUP="tty", OPTIONS="last_rule"
+KERNEL=="vcsa[0-9]*",		OWNER="vcsa", GROUP="tty", OPTIONS="last_rule"
+KERNEL=="vcc/*",		OWNER="vcsa", GROUP="tty", OPTIONS="last_rule"
 
 # memory devices
-KERNEL=="random",		MODE="0666"
-KERNEL=="urandom",		MODE="0444"
-KERNEL=="mem",			GROUP="kmem", MODE="0640"
-KERNEL=="kmem",			GROUP="kmem", MODE="0640"
-KERNEL=="port",			GROUP="kmem", MODE="0640"
-KERNEL=="full",			MODE="0666"
-KERNEL=="null",			MODE="0666"
-KERNEL=="zero",			MODE="0666"
+KERNEL=="random",		MODE="0666", OPTIONS="last_rule"
+KERNEL=="urandom",		MODE="0444", OPTIONS="last_rule"
+KERNEL=="mem",			GROUP="kmem", MODE="0640", OPTIONS="last_rule"
+KERNEL=="kmem",			GROUP="kmem", MODE="0640", OPTIONS="last_rule"
+KERNEL=="port",			GROUP="kmem", MODE="0640", OPTIONS="last_rule"
+KERNEL=="full",			MODE="0666", OPTIONS="last_rule"
+KERNEL=="null",			MODE="0666", OPTIONS="last_rule"
+KERNEL=="zero",			MODE="0666", OPTIONS="last_rule"
 
 # misc devices
 KERNEL=="nvram",		MODE="0660"


Index: udev.spec
===================================================================
RCS file: /cvs/dist/rpms/udev/devel/udev.spec,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -r1.125 -r1.126
--- udev.spec	21 Nov 2005 07:25:27 -0000	1.125
+++ udev.spec	21 Nov 2005 12:04:44 -0000	1.126
@@ -5,7 +5,7 @@
 Summary: A userspace implementation of devfs
 Name: udev
 Version: 075
-Release: 3
+Release: 4
 License: GPL
 Group: System Environment/Base
 Provides: udev-persistent = 0:%{version}-%{release}
@@ -33,6 +33,7 @@
 Source30: firmware_helper.c
 
 Patch1: udev-075-inc.patch
+Patch2: udevstart2.patch
 
 ExclusiveOS: Linux
 URL: http://kernel.org/pub/linux/utils/kernel/hotplug/
@@ -59,6 +60,7 @@
 %prep
 %setup -q  
 %patch1 -p1 -b .incl
+%patch2 -p1 -b .udevstart2
 
 cp %{SOURCE21} .
 
@@ -85,7 +87,6 @@
 
 mv udev udev.static
 mv udevd udevd.static
-mv udevstart udevstart.static
 mv extras/scsi_id/scsi_id extras/scsi_id/scsi_id.static
 mv extras/ata_id/ata_id extras/ata_id/ata_id.static
 mv extras/edd_id/edd_id extras/edd_id/edd_id.static
@@ -155,13 +156,12 @@
 
 install -m 0644 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/50-udev.rules
 # Backwards compat
-install -m 0644 %{SOURCE10} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/hotplug.rules
+install -m 0644 %{SOURCE10} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/51-hotplug.rules
 
 install -m 0644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/udev/udev.conf
 
 install -m 0755 udev.static $RPM_BUILD_ROOT/sbin/udev.static
 install -m 0755 udevd.static $RPM_BUILD_ROOT/sbin/udevd.static
-install -m 0755 udevstart.static $RPM_BUILD_ROOT/sbin/udevstart.static
 #install -m 0755 extras/scsi_id/scsi_id.static $RPM_BUILD_ROOT/sbin/scsi_id.static
 #install -m 0755 extras/ata_id/ata_id.static $RPM_BUILD_ROOT/sbin/ata_id.static
 #install -m 0755 extras/edd_id/edd_id.static $RPM_BUILD_ROOT/sbin/edd_id.static
@@ -240,7 +240,7 @@
 %attr(0755,root,root) /sbin/udevsend
 %attr(0755,root,root) /sbin/udevd
 %attr(0755,root,root) /sbin/udevstart
-%attr(0755,root,root) /sbin/udevstart.static
+%attr(0755,root,root) /sbin/udevstart2
 %attr(0755,root,root) /sbin/start_udev
 #%attr(755,root,root) /sbin/udev_volume_id
 %attr(0755,root,root) /sbin/udev_run_devd
@@ -289,7 +289,7 @@
 
 %config %attr(0644,root,root) %{_sysconfdir}/udev/udev.conf
 %config %attr(0644,root,root) %{_sysconfdir}/udev/rules.d/50-udev.rules
-%config %attr(0644,root,root) %{_sysconfdir}/udev/rules.d/hotplug.rules
+%config %attr(0644,root,root) %{_sysconfdir}/udev/rules.d/51-hotplug.rules
 %config %attr(0644,root,root) %dir %{_sysconfdir}/udev/makedev.d/50-udev.nodes
 
 #%config(missingok) %{_sysconfdir}/hotplug.d/default/10-udev.hotplug
@@ -303,6 +303,9 @@
 %attr(0644,root,root) %{_mandir}/man8/vol_id*.8*
 
 %changelog
+* Mon Nov 21 2005 Harald Hoyer <harald at redhat.com> - 075-4
+- speedup udev event replay with udevstart2 
+
 * Fri Nov 18 2005 Harald Hoyer <harald at redhat.com> - 075-3
 - refined start_udev for old kernels
 




More information about the fedora-cvs-commits mailing list