Several fixes and enhancements for extented naming rules parameters
Hello!
Playing with udev naming rules, I notices that existing '%e' macro can't be really used in several cases (important at least for me). This 'extended' macro is quite useful if e.g. we try to build nice "human-friendly" device naming scheme and strictly separate devices names and permissions assignment (to rules.d/* and permissions.d/* respectively)
First of all, if one tries to give several names to a device (say, create additional symlinks for a CD-RW device like /dev/cdrom, /dev/cdwriter) udev ends up w/ errors.
Also I really doubt if %e w/ existing rules processing code can be used in constructions like /dev/discs/disc%e/disc and other devfs-like naming schemes.
So I decided to patch it a bit to achieve such functionality. You can find this patch in the attachment.
Also I'd like to have another macro. While %e is substituted w/ nothing for
'mydevice%e' if /dev/mydevice doesn't exist yet, this new macro always substituted w/ a non-negative number. I called it %N, but in fact these names can be changed in future. This is particularly useful for names like /dev/discs/disc%N/{.....} and allows to simplify devfs-like naming scripts.
And the last macro I have invented so far ;-) (don't be scared, I'm almost satisfied ;-)), is also about unique file names. I'd like to create entries like /dev/cdrom (i.e. only for a first CD-ROM in the system) w/o extra script work, just because udev anyway has all required info in its database. So this macro (which I called %U) just does a small subset of what %e does.
I should note, that all these three macros should be used only once per name token (currently, constructions like discs/disc%N/part%N are prohibited, I doubt this is a real limitation anyway), but the could be freely used in constructions like the following: SYMLINK="cdroms/cdrom%N cdroms/cdwriter%N cdrom/cdrom%U".
Also I made a patch for (optional) compilation of udev w/ a system-wide installed sysfs libraries. I'm not sure it's a good idea 'for everyone' but if we anyway have libsysfs and it's fresh enough to seamlessly work w/ udev, I don't see any reasons to have a separate copy right in udev source tree. Probably I make a mistake, but it worked /for me/ so far, and hey, it's optional anyway.
Hopefully, I'm not just another another wheel re-inventer, and if so, please tell me that, I'll try to be more cautious next time ;-).
In the attachments you'll find described patches (for the udev-0.50), sample rules file and scripts, mentioned in rules files. Patches should be applied in next order:
%patch -p1 -b .system_sysfs (optional)
%patch1 -p1 -b .efmt_fixes
%patch2 -p1 -b .Nfmt
%patch3 -p1 -b .Ufmt
%patch4 -p1 -b .compile_warnings (probably, also optional)
These patches probably could peacefully co-exist w/ recent Mandrake's patches for udev.
Thank you for your attention.
Sincerely yours,
Alexey Morozov.
# -*- mode: shell-script; coding: utf-8 -*-
# Configuration options for cd-names.sh
#
# DRIVETYPE_PRIO (= <string>)
# Allows to change order in which capabilities will be examined (and
# thus reported). This can lead to naming schemes with different # primary names. Possible capabilities names are: CD, DVD, CDRW and # DVDRW. CDROMs are always assumed as being capable to handle CD # (obvious :-)) # If value isn't set "DVDRW CDRW DVD" is used by default. DRIVETYPE_PRIO="DVDRW CDRW DVD"
# DO_ALL_LINKS (= 0/1)
# Report all possible names for a given device, not only one for most
# priority capability supported by the device. This can lean to e.g. # DVD-RW drive to get '/dev/cdroms/dvdwriter0' as its name and # '/dev/cdroms/dvd0', '/dev/cdroms/cdwriter0' and '/dev/cdroms/cdrom0' # as symlinks to '/dev/cdroms/dvdwriter0' # Default is to report all names #DO_ALL_LINKS=0
# DO_ROOT_LINKS (= 0/1)
# Additionally to all entries in '/dev/cdroms/' folder, make symbolic
# links to a given device right from '/dev/'. This allows to have # links like '/dev/cdrom' -> '/dev/cdroms/cdrom0' etc # Default is to do root links #DO_ROOT_LINKS=0
# PRIMARY_SUFFIX (= <udev device pattern>)
# This suffix will be appended to all device names from '/dev/cdroms/'
# folder. See 'man 8 udev' for more info. # Default value is '%N' (NOTE: '%N' requires additional patch to # udev as of version 046!) #PRIMARY_SUFFIX="%e"
# SECONDARY_SUFFIX (= <udev device pattern>)
# This suffix will be appended to all device names from '/dev/' if
# such entries are to be created (see DO_ROOT_LINKS) # Default value is '%V" (NOTE: '%U' requires additional patch to # udev as of version 046!) #SECONDARY_SUFFIX="%e"
namedev.c +42 -11
@@ -178,19 +178,13 @@return -1 ; } -/** Finds the lowest positive N such that <name>N isn't present in -* $(udevroot) either as a file or a symlink. -* -* @param name Name to check for -* @return 0 if <name> didn't exist and N otherwise. +/** Internal function used by find_free_number and +* find_free_number_zerobase */ -static int find_free_number (struct udevice *udev,const char *name,const char *tail) +static int find_free_number_internal (struct udevice *udev,const char *name,const char * tail,char *filename,int maxsize) { -char filename[NAME_SIZE ];int num =0 ;struct udevice db_udev; - -snprintf (filename,NAME_SIZE ,"%s%s" , name, tail);while (1 ) {dbg ("look for existing node '%s'" , filename);memset (&db_udev,0x00 ,sizeof (struct udevice ));
@@ -204,11 +198,36 @@info ("find_free_number gone crazy (num=%d), aborted" , num);return -1 ; } -snprintf (filename,NAME_SIZE ,"%s%d%s" , name, num, tail); - filename[NAME_SIZE -1 ] ='\0' ; +snprintf (filename, maxsize,"%s%d%s" , name, num, tail); } } +/** Finds the lowest positive N such that <name>N isn't present in +* $(udevroot) either as a file or a symlink. +* +* @param name Name to check for +* @return 0 if <name> didn't exist and N otherwise. +*/ +static int find_free_number (struct udevice *udev,const char *name,const char *tail) +{ +char filename[NAME_SIZE ]; +snprintf (filename,NAME_SIZE ,"%s%s" , name, tail); +return find_free_number_internal (udev, name, tail, filename,NAME_SIZE ); +} + +/** Finds the lowest non-negative N such that <name>N isn't present in +* $(udevroot) either as a file or a symlink. +* +* @param name Name to check for +* @return 0 if <name> didn't exist and N otherwise. +*/ +static int find_free_number_zerobase (struct udevice *udev,const char *name,const char *tail) +{ +char filename[NAME_SIZE ]; +snprintf (filename,NAME_SIZE ,"%s%d%s" , name,0 , tail); +return find_free_number_internal (udev, name, tail, filename,NAME_SIZE ); +} +static void apply_format (struct udevice *udev,char *string,size_t maxsize,struct sysfs_class_device *class_dev,struct sysfs_device *sysfs_device);
@@ -344,6 +363,18 @@ }strfieldcatmax (string, tail, maxsize);return ; +case 'N' : +if (!use_ext) { +dbg ("prohibited usage of attribute %%e" ); +break ; + } +/* prohibite "extended" attributes in tail */ +apply_format_token (udev, tail,NAME_SIZE , class_dev, sysfs_device,0 ); + next_free_number =find_free_number_zerobase (udev, string, tail); +sprintf (temp2,"%d" , next_free_number); +strfieldcatmax (string, temp2, maxsize); +strfieldcatmax (string, tail, maxsize); +return ;default :dbg ("unknown substitution type '%%%c'" , c);break ;
udev.8.in +4 -0
@@ -285,6 +285,10 @@ can be used to create compatibility symlinks and enumerate devices of the same type originating from different kernel subsystems. .TP +.B %N +Similar to %e but always substituted by a smallest non-negative number +giving an unique device node. +.TP .B %% The '%' character itself. .P
namedev.c +16 -0
@@ -375,6 +375,22 @@strfieldcatmax (string, temp2, maxsize);strfieldcatmax (string, tail, maxsize);return ; +case 'U' : +if (!use_ext) { +dbg ("prohibited usage of attribute %%e" ); +break ; + } +/* prohibite "extended" attributes in tail */ +apply_format_token (udev, tail,NAME_SIZE , class_dev, sysfs_device,0 ); + { +struct udevice db_udev; +strfieldcatmax (string, tail, maxsize); +if (0 ==udev_db_get_device_byname (&db_udev, string)) { +/* device exists */ + string[0 ] ='\0' ; + } + } +return ;default :dbg ("unknown substitution type '%%%c'" , c);break ;
udev.8.in +5 -0
@@ -289,6 +289,11 @@ similar to %e but always substituted by a smallest non-negative number giving an unique device node. .TP +.B %N +If a device node already exists with the name, the entire name is skipped. +This allows to create, say, /dev/cdrom (usually a link) but not /dev/cdrom1 +and only if /dev/cdrom doesn't exist before +.TP .B %% The '%' character itself. .P
udev_db.c +1 -0
@@ -30,6 +30,7 @@#include <string.h> #include <errno.h> #include <dirent.h> +#include <unistd.h> #include <sysfs/libsysfs.h> #include "udev.h"
extras/scsi_id/Makefile +7 -2
@@ -31,6 +31,11 @@ override CFLAGS+=-Wall -fno-builtin PROG=scsi_id + +ifeq ($(strip $(SYS_SYSFS)),) +CPPFLAGS = -I../../libsysfs +endif + SYSFS=-lsysfs #
@@ -53,7 +58,7 @@ echo $(INSTALL_DATA) -D ./scsi_id.config $(DESTDIR)$(etcdir); \ $(INSTALL_DATA) -D ./scsi_id.config $(DESTDIR)$(etcdir)/scsi_id.config; \ fi - + uninstall: -rm $(DESTDIR)$(sbindir)/$(PROG) -rm $(DESTDIR)$(mandir)/man8/scsi_id.8
@@ -73,7 +78,7 @@ spotless: clean .c.o: - $(QUIET) $(CC) $(CFLAGS) -c -o $@ $< + $(QUIET) $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< $(PROG): $(OBJS) $(QUIET) $(LD) $(LDFLAGS) -o $(PROG) $(CRT0) $(OBJS) $(SYSFS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
extras/volume_id/Makefile +11 -1
@@ -28,14 +28,24 @@ INSTALL_DATA = ${INSTALL} -m 644 INSTALL_SCRIPT = ${INSTALL_PROGRAM} +ifeq ($(strip $(SYS_SYSFS)),) +CPPFLAGS = -I../../libsysfs +endif + override CFLAGS+=-Wall -fno-builtin -Wchar-subscripts \ -Wpointer-arith -Wcast-align -Wsign-compare override CFLAGS+=-D_FILE_OFFSET_BITS=64 -OBJS = volume_id.o udev_volume_id.o dasdlabel.o $(SYSFS) +OBJS = volume_id.o udev_volume_id.o dasdlabel.o HEADERS = volume_id.h dasdlabel.h +ifeq ($(strip $(SYS_SYSFS)),) +OBJS += $(SYSFS) +else +LDFLAGS += $(SYS_SYSFS) +endif + $(OBJS): $(HEADERS) .c.o:
extras/volume_id/udev_volume_id.c +1 -1
@@ -28,7 +28,7 @@#include <ctype.h> #include <sys/ioctl.h> -#include "../../libsysfs/sysfs/libsysfs.h" +#include <sysfs/libsysfs.h> #include "../../udev_utils.h" #include "../../logging.h" #include "volume_id.h"
libsysfs/dlist.c +1 -1
@@ -27,7 +27,7 @@* delete function. Otherwise dlist will just use free. */ -#include "dlist.h" +#include "sysfs/dlist.h" /* * Return pointer to node at marker.
libsysfs/dlist.h +0 -205
205 lines not on this page · raw message
libsysfs/sysfs/dlist.h +205 -0
205 lines not on this page · raw message
libsysfs/sysfs_bus.c +1 -1
@@ -20,7 +20,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#include "libsysfs.h" +#include "sysfs/libsysfs.h" #include "sysfs.h" static void sysfs_close_dev (void *dev)
libsysfs/sysfs_class.c +1 -1
@@ -20,7 +20,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#include "libsysfs.h" +#include "sysfs/libsysfs.h" #include "sysfs.h" static void sysfs_close_cls_dev (void *dev)
libsysfs/sysfs_device.c +1 -1
@@ -20,7 +20,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#include "libsysfs.h" +#include "sysfs/libsysfs.h" #include "sysfs.h" /**
libsysfs/sysfs_dir.c +1 -1
@@ -20,7 +20,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#include "libsysfs.h" +#include "sysfs/libsysfs.h" #include "sysfs.h" /**
libsysfs/sysfs_driver.c +1 -1
@@ -20,7 +20,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#include "libsysfs.h" +#include "sysfs/libsysfs.h" #include "sysfs.h" static void sysfs_close_driver_device (void *device)
libsysfs/sysfs_utils.c +1 -1
@@ -20,7 +20,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#include "libsysfs.h" +#include "sysfs/libsysfs.h" #include "sysfs.h" static int sort_char (void *new,void *old)
Makefile +17 -13
@@ -92,7 +92,11 @@ RANLIB = $(CROSS)ranlib HOSTCC = gcc -export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0 +ifeq ($(strip $(SYS_SYSFS)),) +CPPFLAGS = -I`pwd`/libsysfs +endif + +export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0 CPPFLAGS # code taken from uClibc to determine the current arch ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
@@ -170,9 +174,6 @@ LIB_OBJS += -lselinux endif -CFLAGS += -I$(PWD)/libsysfs/sysfs \ - -I$(PWD)/libsysfs - # config files automatically generated GEN_CONFIGS = $(LOCAL_CFG_DIR)/udev.conf
@@ -182,6 +183,7 @@ $(MAKE) prefix=$(prefix) \ LD="$(LD)" \ SYSFS="$(SYSFS)" \ + SYS_SYSFS=$(SYS_SYSFS) \ KERNEL_DIR="$(KERNEL_DIR)" \ QUIET="$(QUIET)" \ -C $$target $@ ; \
@@ -227,11 +229,13 @@ namedev.o \ namedev_parse.o -OBJS = \ - libsysfs/sysfs.a \ - udev.a - +ifneq ($(strip $(SYS_SYSFS)),) +LIB_OBJS += $(SYS_SYSFS) +else SYSFS = $(PWD)/libsysfs/sysfs.a +endif + +OBJS = udev.a $(SYSFS) ifeq ($(strip $(USE_KLIBC)),true) HEADERS += \
@@ -258,7 +262,7 @@ $(QUIET) $(AR) cq $@ $(UDEV_OBJS) $(QUIET) $(RANLIB) $@ -libsysfs/sysfs.a: $(SYSFS_OBJS) +$(PWD)/libsysfs/sysfs.a: $(SYSFS_OBJS) rm -f $@ $(QUIET) $(AR) cq $@ $(SYSFS_OBJS) $(QUIET) $(RANLIB) $@
@@ -331,7 +335,7 @@ $(QUIET) $(STRIPCMD) $@ .c.o: - $(QUIET) $(CC) $(CFLAGS) -c -o $@ $< + $(QUIET) $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< clean:
@@ -342,7 +346,7 @@ $(MAKE) -C klibc SUBDIRS=klibc clean @extras="$(EXTRAS)" ; for target in $$extras ; do \ echo $$target ; \ - $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \ + $(MAKE) prefix=$(prefix) LD="$(LD)" SYS_SYSFS=$(SYS_SYSFS) SYSFS="$(SYSFS)" \ -C $$target $@ ; \ done ; \
@@ -437,7 +441,7 @@ endif @extras="$(EXTRAS)" ; for target in $$extras ; do \ echo $$target ; \ - $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \ + $(MAKE) prefix=$(prefix) LD="$(LD)" SYS_SYSFS=$(SYS_SYSFS) SYSFS="$(SYSFS)" \ -C $$target $@ ; \ done ; \
@@ -461,7 +465,7 @@ - killall $(DAEMON) @extras="$(EXTRAS)" ; for target in $$extras ; do \ echo $$target ; \ - $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \ + $(MAKE) prefix=$(prefix) LD="$(LD)" SYS_SYSFS=$(SYS_SYSFS) SYSFS="$(SYSFS)" \ -C $$target $@ ; \ done ; \
namedev.c +1 -1
@@ -32,7 +32,7 @@#include <sys/wait.h> #include <sys/stat.h> -#include "libsysfs/sysfs/libsysfs.h" +#include <sysfs/libsysfs.h> #include "list.h" #include "udev.h" #include "udev_utils.h"
udev_add.c +1 -1
@@ -36,7 +36,7 @@#include <linux/sockios.h> #include <pwd.h> -#include "libsysfs/sysfs/libsysfs.h" +#include <sysfs/libsysfs.h> #include "udev.h" #include "udev_utils.h" #include "udev_version.h"
udev.c +1 -1
@@ -31,7 +31,7 @@#include <signal.h> #include <unistd.h> -#include "libsysfs/sysfs/libsysfs.h" +#include <sysfs/libsysfs.h> #include "udev.h" #include "udev_utils.h" #include "udev_sysfs.h"
udev_config.c +1 -1
@@ -32,7 +32,7 @@#include <errno.h> #include <ctype.h> -#include "libsysfs/sysfs/libsysfs.h" +#include <sysfs/libsysfs.h> #include "udev.h" #include "udev_utils.h" #include "udev_version.h"
udev_db.c +1 -1
@@ -31,7 +31,7 @@#include <errno.h> #include <dirent.h> -#include "libsysfs/sysfs/libsysfs.h" +#include <sysfs/libsysfs.h> #include "udev.h" #include "udev_utils.h" #include "logging.h"
udev.h +1 -1
@@ -24,7 +24,7 @@#define _UDEV_H_#include <sys/param.h> -#include "libsysfs/sysfs/libsysfs.h" +#include <sysfs/libsysfs.h> #define ALARM_TIMEOUT 120#define COMMENT_CHARACTER '#'
udevinfo.c +2 -2
@@ -27,8 +27,8 @@#include <unistd.h> #include <errno.h> -#include "libsysfs/sysfs/libsysfs.h" -#include "libsysfs/dlist.h" +#include <sysfs/libsysfs.h> +#include <sysfs/dlist.h> #include "udev.h" #include "udev_utils.h" #include "udev_version.h"
udev_start.c +1 -1
@@ -33,7 +33,7 @@#include <sys/types.h> #include <unistd.h> -#include "libsysfs/sysfs/libsysfs.h" +#include <sysfs/libsysfs.h> #include "logging.h" #include "udev_utils.h" #include "list.h"
udev_sysfs.c +1 -1
@@ -28,7 +28,7 @@#include <errno.h> #include <sys/stat.h> -#include "libsysfs/sysfs/libsysfs.h" +#include <sysfs/libsysfs.h> #include "udev_version.h" #include "udev_sysfs.h" #include "udev_utils.h"
udev_sysfs.h +1 -1
@@ -22,7 +22,7 @@#ifndef _UDEV_SYSFS_H_#define _UDEV_SYSFS_H_ -#include "libsysfs/sysfs/libsysfs.h" +#include <sysfs/libsysfs.h> #define WAIT_MAX_SECONDS 5#define WAIT_LOOP_PER_SECOND 20
udevtest.c +1 -1
@@ -27,7 +27,7 @@#include <ctype.h> #include <signal.h> -#include "libsysfs/sysfs/libsysfs.h" +#include <sysfs/libsysfs.h> #include "udev.h" #include "udev_sysfs.h" #include "udev_utils.h"
namedev.c +82 -10
139 lines not on this page · raw message
Re: Several fixes and enhancements for extented naming rules
Quoted 2 lines · Alexey Morozov
Playing with udev naming rules, I notices that existing '%e' macro can't be really used in several cases (important at least for me).
Please explain the several cases!
Quoted 5 lines
This
'extended' macro is quite useful if e.g. we try to build nice "human-friendly" device naming scheme and strictly separate devices names and permissions assignment (to rules.d/* and permissions.d/* respectively)
permissions.d/ is gone. We have the permissions in the rules file form the next version on.
Quoted 3 lines
First of all, if one tries to give several names to a device (say, create additional symlinks for a CD-RW device like
/dev/cdrom,/dev/cdwriter) udev ends up w/ errors.
What kind of errors? Please explain!
Quoted 3 lines
Also I really doubt if %e w/ existing rules processing code can be used in constructions like /dev/discs/disc%e/disc and other devfs-like naming schemes.
Yes, this doesn't work, but the scripts can do this, right?
Quoted 9 lines
So I decided to patch it a bit to achieve such functionality. You can find this patch in the attachment.
Also I'd like to have another macro. While %e is substituted w/ nothing for 'mydevice%e' if
/dev/mydevicedoesn't exist yet, this new macro always substituted w/ a non-negative number. I called it %N, but in fact these names can be changed in future. This is particularly useful for names like /dev/discs/disc%N/{.....} and allows to simplify devfs-like naming scripts.
Is there really the need to move this into udev? What is the limitation of the scripts?
Quoted 6 lines
Also I made a patch for (optional) compilation of udev w/ a system-wide installed sysfs libraries. I'm not sure it's a good idea 'for everyone' but if we anyway have libsysfs and it's fresh enough to seamlessly work w/ udev, I don't see any reasons to have a separate copy right in udev source tree. Probably I make a mistake, but it worked /for me/ so far, and hey, it's optional anyway.
Does this work with the klibc build, which cannot use the system installed version of sysfs?
Kay
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 11 lines · Kay Sievers
Quoted 4 lines · Alexey Morozov
Playing with udev naming rules, I notices that existing '%e' macro can't be really used in several cases (important at least for me).
Please explain the several cases!
Well, I tried to describe them below in that letter, right? I can show you entire contents of /dev on my workstation.
Quoted 8 lines
Quoted 7 lines
This
'extended' macro is quite useful if e.g. we try to build nice "human-friendly" device naming scheme and strictly separate devices names and permissions assignment (to rules.d/* and permissions.d/* respectively)
Quoted 4 lines
permissions.d/ is gone. We have the permissions in the rules file form the next version on.
Hmm, well, maybe it's a good idea, but I doubt it can increase maintainability of udev setups. But perhaps I'm wrong, I need to think a bit about possible consequences and undestand how things change in this case.
Quoted 9 lines
Quoted 5 lines
First of all, if one tries to give several names to a device (say, create additional symlinks for a CD-RW device like
/dev/cdrom,/dev/cdwriter) udev ends up w/ errors.What kind of errors? Please explain!
Sure. Existing 'if such a name already assigned by udev to a device' code works poorly if e.g. _several_ symlinks are to be considered. It simply doesn't split entire string SYMLINK="a_name1 another_name2 ... generic_name%e" into tokens and therefore can't really check if corresponding /dev/generic_name* etc are already assigned to some devices. You may try it yourself.
Quoted 9 lines
Quoted 5 lines
Also I really doubt if %e w/ existing rules processing code can be used in constructions like /dev/discs/disc%e/disc and other devfs-like naming schemes.
Yes, this doesn't work, but the scripts can do this, right?
Please see the answer below.
Quoted 12 lines
Quoted 11 lines
So I decided to patch it a bit to achieve such functionality. You can find this patch in the attachment.
Also I'd like to have another macro. While %e is substituted w/ nothing for 'mydevice%e' if
/dev/mydevicedoesn't exist yet, this new macro always substituted w/ a non-negative number. I called it %N, but in fact these names can be changed in future. This is particularly useful for names like /dev/discs/disc%N/{.....} and allows to simplify devfs-like naming scripts.
Quoted 4 lines
Is there really the need to move this into udev? What is the limitation of the scripts?
Speed. Complexity. As you may notice, I mostly re-used existing udev code in these patches. W/ a "pure scripts" solution I would had to do all the things from scratch. I looked at existing udev supporting scripts (from debian, gentoo and Mdk) and found that they works really harder than my code to achieve corresponding or even lesser level of functionality (at least in implementing equivalents of those 'extended attributes' like '%e').
Sure namedev stuff can probably be taken out of main udev binary. But in any case a stateless script which has to calculate everything it needs to form a name each time it's launched, well, that script will be more complex and slow than a solution w/ a binary and pre-built database in a convenient format.
BTW, my current /dev/.udevdb eats ~2.8Mb of space (/dev is on tmpfs) on an ordinary workstation w/o much hardware plugged in. Is that intended result? ;-) Are there plans to change its format? Now it's a lot, ~700 files, each 40-50 bytes long. I guess smth like a berkeley db will be more appropriate in this case, but I'm not sure if it's a good idea to take even statically linked db1 to Early User Space stuff. Maybe there're some other workarounds for the problem?
There's another little problem to be considered. E.g. I noticed that sda1 creation event for my flash drive often comes when entire sda event hasn't been processed completely yet. So we have to deal w/ such concurrency, and I really believe that C provides better tools and techniques for that than bash-programming.
Quoted 8 lines
Quoted 8 lines
Also I made a patch for (optional) compilation of udev w/ a system-wide installed sysfs libraries. I'm not sure it's a good idea 'for everyone' but if we anyway have libsysfs and it's fresh enough to seamlessly work w/ udev, I don't see any reasons to have a separate copy right in udev source tree. Probably I make a mistake, but it worked /for me/ so far, and hey, it's optional anyway.
Quoted 4 lines
Does this work with the klibc build, which cannot use the system installed version of sysfs?
Well, it's just a linker flag. Instead of explicitly link libsysfs/sysfs.a, it can pass to the linker anything from $(SYS_SYSFS). It can be -lsysfs, or just a /usr/lib/libsysfs.a if one wants. So the answer is yes, it works if we build udev on a system w/ an appropriate libsysfs installed.
Yours faithfully,
Alexey Morozov
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Re: Several fixes and enhancements for extented naming
In reply to Alexey MorozovQuoted 7 lines · Alexey Morozov
Quoted 6 lines · Kay Sievers
Quoted 4 lines · Alexey Morozov
First of all, if one tries to give several names to a device (say, create additional symlinks for a CD-RW device like
/dev/cdrom,/dev/cdwriter) udev ends up w/ errors.
Quoted 8 lines
Quoted 2 lines
What kind of errors? Please explain!
Sure. Existing 'if such a name already assigned by udev to a device' code works poorly if e.g. _several_ symlinks are to be considered. It simply doesn't split entire string SYMLINK="a_name1
another_name2... generic_name%e" into tokens and therefore can't really check if corresponding/dev/generic_name*etc are already assigned to some devices. You may try it yourself.
A separate rule with only one SYMLINK works. That's not perfect, but see later in this mail.
Quoted 13 lines
Quoted 10 lines
Quoted 9 lines
So I decided to patch it a bit to achieve such functionality. You can find this patch in the attachment.
Also I'd like to have another macro. While %e is substituted w/ nothing for 'mydevice%e' if
/dev/mydevicedoesn't exist yet, this new macro always substituted w/ a non-negative number. I called it %N, but in fact these names can be changed in future. This is particularly useful for names like /dev/discs/disc%N/{.....} and allows to simplify devfs-like naming scripts.Quoted 3 lines
Is there really the need to move this into udev? What is the limitation of the scripts?
Quoted 7 lines
Speed. Complexity. As you may notice, I mostly re-used existing udev code in these patches. W/ a "pure scripts" solution I would had to do all the things from scratch. I looked at existing udev supporting scripts (from debian, gentoo and Mdk) and found that they works really harder than my code to achieve corresponding or even lesser level of functionality (at least in implementing equivalents of those 'extended attributes' like '%e').
I've never heard any complains about the speed of udev. :)
Quoted 5 lines
Sure namedev stuff can probably be taken out of main udev binary. But in any case a stateless script which has to calculate everything it needs to form a name each time it's launched, well, that script will be more complex and slow than a solution w/ a binary and pre-built database in a convenient format.
Well, the problem is that the %e is just a dirty hack to provide compatibility symlinks. It works only in the udevstart case. If driven by hotplug events, it's slippery cause of the concurrently running processes for each device. It happens, that you get the same enumeration number for multiple devices. I don't feel comfortable to move more of this conceptually broken stuff into udev.
How about creating _and_ supporting a callout in the extras/ folder, that is able to store and retrieve information from its own database stored in a dotfile in /dev? devfs scripts can use that extra and it may use a file lock to serialize the events. It is still not guaranteed that the enum is in the event order, but doubles may be avoided this way. Also the stupid reverse lookup of the udevdb is avoided this way, which needs to read all db-files every time again.
Quoted 7 lines
BTW, my current
/dev/.udevdbeats ~2.8Mb of space (/dev is on tmpfs) on an ordinary workstation w/o much hardware plugged in. Is that intended result? ;-) Are there plans to change its format? Now it's a lot, ~700 files, each 40-50 bytes long. I guess smth like a berkeley db will be more appropriate in this case, but I'm not sure if it's a good idea to take even statically linked db1 to Early User Space stuff. Maybe there're some other workarounds for the problem?
There are no plans. The only current workaround is to use a different filesystem. The db operations need to be completely lockless. We already have had a single file database but some setups got several hundred processes concurrently locking this file and waiting for a slot to write to and it failed badly...
Quoted 5 lines
There's another little problem to be considered. E.g. I noticed that sda1 creation event for my flash drive often comes when entire sda event hasn't been processed completely yet. So we have to deal w/ such concurrency, and I really believe that C provides better tools and techniques for that than bash-programming.
This should not happen. sda1 is a child of sda and these events are serialized from version 049 on. sda, sdb, ... still run in parallel.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Also I made a patch for (optional) compilation of udev w/ a system-wide installed sysfs libraries. I'm not sure it's a good idea 'for everyone' but if we anyway have libsysfs and it's fresh enough to seamlessly work w/ udev, I don't see any reasons to have a separate copy right in udev source tree. Probably I make a mistake, but it worked /for me/ so far, and hey, it's optional anyway.
Quoted 8 lines
Quoted 3 lines
Does this work with the klibc build, which cannot use the system installed version of sysfs?
Well, it's just a linker flag. Instead of explicitly link libsysfs/sysfs.a, it can pass to the linker anything from $(SYS_SYSFS). It can be -lsysfs, or just a
/usr/lib/libsysfs.aif one wants. So the answer is yes, it works if we build udev on a system w/ an appropriate libsysfs installed.
We sometimes make changes to the in-tree version and therefore we don't want to officially support a system wide version. So the system-wide compile must be the optional one which is only linked if the user asks for it.
The sources of the in-tree libsysfs should not be changed, it better matches the upstream version. Otherwise it would be nice to be able to offer this switch.
Kay
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Kay Sievers пишет:
Quoted 8 lines
Quoted 8 lines
Sure. Existing 'if such a name already assigned by udev to a device' code works poorly if e.g. _several_ symlinks are to be considered. It simply doesn't split entire string SYMLINK="a_name1
another_name2... generic_name%e" into tokens and therefore can't really check if corresponding/dev/generic_name*etc are already assigned to some devices. You may try it yourself.
Quoted 7 lines
Quoted 4 lines
Speed. Complexity. As you may notice, I mostly re-used existing udev code in these patches.
I've never heard any complains about the speed of udev. :)
I've heard indeed. Particularly about the speed of udevstart ;-). But the main worries about complexity.
Quoted 10 lines
Quoted 9 lines
Sure namedev stuff can probably be taken out of main udev binary. But in any case a stateless script which has to calculate everything it needs to form a name each time it's launched, well, that script will be more complex and slow than a solution w/ a binary and pre-built database in a convenient format.
Quoted 4 lines
Well, the problem is that the %e is just a dirty hack to provide compatibility symlinks. It works only in the udevstart case. If driven by hotplug events,
Hmm, with my patches it works everywhere ;-). Trust me ;-). At least in 'real userlevel' (haven't played w/ early userland stuff yet).
Quoted 6 lines
it's slippery cause of the concurrently running processes for each device. It happens, that you get the same enumeration number for multiple devices. I don't feel comfortable to move more of this conceptually broken stuff into udev.
Well, it's understandable.
Quoted 8 lines
How about creating _and_ supporting a callout in the extras/ folder, that is able to store and retrieve information from its own database stored in a dotfile in /dev? devfs scripts can use that extra and it may use a file lock to serialize the events. It is still not guaranteed that the enum is in the event order, but doubles may be avoided this way. Also the stupid reverse lookup of the udevdb is avoided this way, which needs to read all db-files every time again.
Quoted 6 lines
The db operations need to be completely lockless. We already have had a single file database but some setups got several hundred processes concurrently locking this file and waiting for a slot to write to and it failed badly...
Well, as I understand you propose [me] to take away [most of] namedev.* and udev_db.* stuff out of main udev binary sources and create an 'user-level' (well, even more user-level :-)) utility, which does basically the same upon a request from scrips, right? Are there any works in that direction already? Are there some sort of strict specifications for the task?
As I can see it now, any usage of 'extended substs' like '%e' will cause a need in some sort of serialized/synchronous operations (in case two hotplug events got delivered in the same time), so I just can't see a solution w/o any locks at all. Sure these locks can be, well, cheap or lightweight, 'row-locks' etc, but all my previous experience tells me there must be some serialization anyway. BTW, existing udevdb stuff seems not to be a reentrant safe at least in the udev_db_get_device_byname part.
Maybe this new utility should act like a small daemon listening a [unix-domain] socket (a FIFO? hmm) for incoming name pattern requests and responding w/ substitutions performed. This way we can avoid re-parsing device DB on each request and serialize things properly so parallel devices creation events won't be blocked for a too long time. I'm not sure about availability of corresponding kernel functionality in early userland stages. We also can avoid 'on disk' DB if needed.
Quoted 6 lines
Quoted 3 lines
BTW, my current
/dev/.udevdbeats ~2.8Mb of space (/dev is on tmpfs) onThere are no plans. The only current workaround is to use a different filesystem.
Umm... tmpfs already has useful hacks like this one:
http://www.uwsg.indiana.edu/hypermail/linux/kernel/0411.0/1568.html
I doubt it's worth to intend /dev functionality to an 'adult' filesystem w/ tail packing, resident files and other super-cool and awesome features.
Quoted 8 lines
Quoted 4 lines
E.g. I noticed that sda1 creation event for my flash drive often comes when entire sda event hasn't been processed completely yet.
This should not happen. sda1 is a child of sda and these events are serialized from version 049 on. sda, sdb, ... still run in parallel.
Well, I noticed that partition node creation script is running when the entire device node hasn't been created yet. I even had to put some ugly polling into drive-names.sh (lines 60-73), which solved the problem. Probably, it's not an udev, but e.g. tmpfs fault, but anyway it exists (at least on my 2.6.9 w/ corresponding Con Kolivas patchset applied).
Quoted 8 lines
Quoted 7 lines
Well, it's just a linker flag. Instead of explicitly link libsysfs/sysfs.a, it can pass to the linker anything from $(SYS_SYSFS). It can be -lsysfs, or just a
/usr/lib/libsysfs.aif one wants. So the answer is yes, it works if we build udev on a system w/ an appropriate libsysfs installed.
Quoted 6 lines
We sometimes make changes to the in-tree version and therefore we don't want to officially support a system wide version. So the system-wide compile must be the optional one which is only linked if the user asks for it.
It's completely optional. If you don't provide SYS_SYSFS=<smth suitable to linker> flag as a make parameter, then it goes just as w/o any patch.
That's extracts from udev.spec I use to build it for my distro:
...
# (Near the beginning of the spec):
# whether we want to use system-wide sysfs or udev local copy
# Note udev-0.50 requires a recent version of sysfs,
%def_with system_sysfs
...
%if_with system_sysfs
BuildRequires: libsysfs-devel > 1.2.0-alt2
%endif
...
%make_build \
udevdir=/dev \
...
%if_with system_sysfs
SYS_SYSFS=-lsysfs \
%endif
...-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Re: Several fixes and enhancements for extented naming rules
In reply to Alexey MorozovQuoted 7 lines · Alexey Morozov
Kay Sievers пишет:
Quoted 6 lines
Quoted 5 lines
Sure namedev stuff can probably be taken out of main udev binary. But in any case a stateless script which has to calculate everything it needs to form a name each time it's launched, well, that script will be more complex and slow than a solution w/ a binary and pre-built database in a convenient format.
Quoted 5 lines
Quoted 3 lines
Well, the problem is that the %e is just a dirty hack to provide compatibility symlinks. It works only in the udevstart case. If driven by hotplug events,
Hmm, with my patches it works everywhere ;-). Trust me ;-). At least in 'real userlevel' (haven't played w/ early userland stuff yet).
You still have the same races as the current %e used outside of udevstart.
Quoted 14 lines
Quoted 5 lines
it's slippery cause of the concurrently running processes for each device. It happens, that you get the same enumeration number for multiple devices. I don't feel comfortable to move more of this conceptually broken stuff into udev.
Well, it's understandable.
Quoted 7 lines
How about creating _and_ supporting a callout in the extras/ folder, that is able to store and retrieve information from its own database stored in a dotfile in /dev? devfs scripts can use that extra and it may use a file lock to serialize the events. It is still not guaranteed that the enum is in the event order, but doubles may be avoided this way. Also the stupid reverse lookup of the udevdb is avoided this way, which needs to read all db-files every time again.
Quoted 8 lines
Quoted 5 lines
The db operations need to be completely lockless. We already have had a single file database but some setups got several hundred processes concurrently locking this file and waiting for a slot to write to and it failed badly...
Well, as I understand you propose [me] to take away [most of] namedev.* and udev_db.* stuff out of main udev binary sources and create an 'user-level' (well, even more user-level :-)) utility,
No, only the enumeration part of namedev should be taken out, as in our current model of independent running event processes, we can't really do this inside of udev.
Quoted 4 lines
which does
basically the same upon a request from scrips, right? Are there any works in that direction already? Are there some sort of strict specifications for the task?
No, it is just an idea and was mainly a question, what you/others think.
Quoted 4 lines
As I can see it now, any usage of 'extended substs' like '%e' will cause a need in some sort of serialized/synchronous operations (in case two hotplug events got delivered in the same time), so I just can't see a solution w/o any locks at all.
Right, the callout could do this kind of serialization.
Quoted 5 lines
Sure these locks can be, well, cheap or
lightweight, 'row-locks' etc, but all my previous experience tells me there must be some serialization anyway. BTW, existing udevdb stuff seems not to be a reentrant safe at least in theudev_db_get_device_bynamepart.
What may be the reason for reentrancy here. udevd serialized the execution of events with the same devpath.
Quoted 7 lines
Maybe this new utility should act like a small daemon listening a [unix-domain] socket (a FIFO? hmm) for incoming name pattern requests and responding w/ substitutions performed. This way we can avoid re-parsing device DB on each request and serialize things properly so parallel devices creation events won't be blocked for a too long time. I'm not sure about availability of corresponding kernel functionality in early userland stages. We also can avoid 'on disk' DB if needed.
I don't know what's the best architecture for that kind of counters, but I don't think that we should replace our current udevdb with something like that.
Quoted 15 lines
Quoted 6 lines
Quoted 3 lines
BTW, my current
/dev/.udevdbeats ~2.8Mb of space (/dev is on tmpfs) onThere are no plans. The only current workaround is to use a different filesystem.
Umm... tmpfs already has useful hacks like this one:
http://www.uwsg.indiana.edu/hypermail/linux/kernel/0411.0/1568.htmlI doubt it's worth to intend /dev functionality to an 'adult' filesystem w/ tail packing, resident files and other super-cool and awesome features.
Quoted 3 lines
Quoted 3 lines
E.g. I noticed that sda1 creation event for my flash drive often comes when entire sda event hasn't been processed completely yet.
Quoted 8 lines
Quoted 3 lines
This should not happen. sda1 is a child of sda and these events are serialized from version 049 on. sda, sdb, ... still run in parallel.
Well, I noticed that partition node creation script is running when the entire device node hasn't been created yet. I even had to put some ugly polling into
drive-names.sh(lines 60-73), which solved the problem. Probably, it's not an udev, but e.g. tmpfs fault, but anyway it exists (at least on my 2.6.9 w/ corresponding Con Kolivas patchset applied).
I can't reproduce this. The partition events are delayed by udevd until the main block device event has exited. It works on my box.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Well, it's just a linker flag. Instead of explicitly link libsysfs/sysfs.a, it can pass to the linker anything from $(SYS_SYSFS). It can be -lsysfs, or just a
/usr/lib/libsysfs.aif one wants. So the answer is yes, it works if we build udev on a system w/ an appropriate libsysfs installed.
Quoted 7 lines
Quoted 5 lines
We sometimes make changes to the in-tree version and therefore we don't want to officially support a system wide version. So the system-wide compile must be the optional one which is only linked if the user asks for it.
It's completely optional. If you don't provide SYS_SYSFS=<smth suitable to linker> flag as a make parameter, then it goes just as w/o any patch.
Ok, fine. Is it possible to do the same without changing our in-tree libsysfs version?
Kay
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel