summaryrefslogtreecommitdiff
path: root/namedev.c
AgeCommit message (Collapse)Author
2005-04-26[PATCH] clean up block whitelist search logic a bit.greg@kroah.com
2005-04-26[PATCH] udevstart performance increaseogasawara@osdl.org
I noticed a comment in namedev.c which stated "Figure out where the device symlink is at. For char devices this will always be in the class_dev->path. But for block devices, it's different. The main block device will have the device symlink in it's path, but all partitions have the symlink in its parent directory. But we need to watch out for block devices that do not have parents, yet look like a partition (fd0, loop0, etc.). They all do not have a device symlink yet. We do a sit and spin on waiting for them right now, we should possibly have a whitelist for these devices here..." I went ahead and created a whitelist for the block devices that look like partitions (mainly by using devices.txt) and tested for any performance increase that we would see. The whitelist only impacts udevstart time depending on the state of UDEV_NO_SLEEP. Since the list was short, I just did a sequential search and ordered the list in such a way that those block devices which have more /dev entires (ex. loop0, loop1, loop2, etc) appear sooner in the list and will thus be found quicker. I've enclosed the patch and some of the performance results I saw below. Basically, as the number of block devices without device symlinks increased, the use of the whitelist improved udevstart performance compared to just sitting and spinning. I just thought it was interesting and thought I'd share. If you feel the patch is beneficial please consider for merging. Also, if you'd be interested in expanding the whitelist for other devices which are missing device symlinks and seeing if there are added performance increases let me know and I'll do what I can. Thanks, Leann Note: ex. loop represents all the loop devices (i.e. loop0, loop1, loop2, etc) block devices present with whitelist time
2005-04-26[PATCH] catchup with recent klibckay.sievers@vrfy.org
Our own implementation of the sysinfo system call is no longer needed, cause it's merged it into klibc now.
2005-04-26[PATCH] fix test regressionskay.sievers@vrfy.org
On Sat, Apr 17, 2004 at 03:30:29AM +0200, Kay Sievers wrote: > On Sat, Apr 17, 2004 at 02:04:55AM +0200, Kay Sievers wrote: > > On Fri, Apr 16, 2004 at 04:04:42PM -0700, Greg KH wrote: > > > Oh, and if you run the latest udev_test.pl, we have a bunch more tests, > > > including a few that fail, if you were looking for something to do :) > > > > Will do it. We need to change apply_format(). I tries to expand the '%%' > > with the next iteration over the string and removes the '%'. The tests are all successful now. If this patch breaks something else, we simply have too few tests :)
2005-04-26[PATCH] put config info in db for netdevkay.sievers@vrfy.org
Small change, to put the config informations for handled network interfaces into the database.
2005-04-26[PATCH] netdev - udevdb+dev.d changeskay.sievers@vrfy.org
Here is a patch to change the netdev handling in the database and for the dev.d/ calls. I applies on top of the udevd.patch, cause klibc has no sysinfo(). o netdev's are also put into our database now. I want this for the udevruler gui to get a list of all handled devices. All devices in the db are stamped with the system uptime value at the creation time. 'udevinfo -d' prints it. o the DEVPATH value is the key for udevdb, but if we rename a netdev, the name is replaced in the kernel, so we add the changed name to the db to match with the remove event. NOTE: The dev.d/ scripts still get the original name from the hotplug call. Should we replace DEVPATH with the new name too? o We now only add a device to the db, if we have successfully created the main node or successfully renamed a netdev. This is the main part of the patch, cause I needed to clean the retval passing trough all the functions used for node creation. o DEVNODE sounds a bit ugly for netdev's so I exported DEVNAME too. Can we change the name? o I've added a UDEV_NO_DEVD to possibly skip the script execution and used it in udev-test.pl. udevstart is the same horror now, if you have scripts with logging statements in dev.d/ it takes minutes to finish, can we skip the scripts here too? o The get_device_type() function is changed to be more strict, cause 'udevinfo -a -p /block/' gets a class device for it and tries to print the major/minor values. o bugfix, the RESULT value has now a working newline removal and a test for this case.
2005-04-26[PATCH] apply all_partitions rule to main block device onlykay.sievers@vrfy.org
Rules with NAME{all_partitions}= are now applied only to the parent of a block device. We no longer need to exclude the partitions or sg* devices.
2005-04-26[PATCH] hmm, handle net devices with udev?kay.sievers@vrfy.org
Hmm, Arndt Bergmann sent a patch like this one a few weeks ago and I want to bring the question back, if we want to handle net device naming with udev. With this patch it is actually possible to specify something like this in udev.rules: KERNEL="dummy*", SYSFS{address}="00:00:00:00:00:00", SYSFS{features}="0x0", NAME="blind%n" KERNEL="eth*", SYSFS{address}="00:0d:60:77:30:91", NAME="private" and you will get: [root@pim udev.kay]# cat /proc/net/dev Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed lo: 1500 30 0 0 0 0 0 0 1500 30 0 0 0 0 0 0 private: 278393 1114 0 0 0 0 0 0 153204 1468 0 0 0 0 0 0 sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 blind0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 The udevinfo program is also working: [root@pim udev.kay]# ./udevinfo -a -p /sys/class/net/private looking at class device '/sys/class/net/private': SYSFS{addr_len}="6" SYSFS{address}="00:0d:60:77:30:91" SYSFS{broadcast}="ff:ff:ff:ff:ff:ff" SYSFS{features}="0x3a9" SYSFS{flags}="0x1003" SYSFS{ifindex}="2" SYSFS{iflink}="2" SYSFS{mtu}="1500" SYSFS{tx_queue_len}="1000" SYSFS{type}="1" follow the class device's "device" looking at the device chain at '/sys/devices/pci0000:00/0000:00:1e.0/0000:02:01.0': BUS="pci" ID="0000:02:01.0" SYSFS{class}="0x020000" SYSFS{detach_state}="0" SYSFS{device}="0x101e" SYSFS{irq}="11" SYSFS{subsystem_device}="0x0549" SYSFS{subsystem_vendor}="0x1014" SYSFS{vendor}="0x8086" The matching device will be renamed to the given name. The device name will not be put into the udev database, cause the kernel renames the device and the sysfs name disappears. I like it, cause it plugs in nicely. We have all the naming features and sysfs queries and walks inside of udev. The sysfs timing races are already solved and the management tools are working for net devices too. nameif can only match the MAC address now. udev can match any sysfs value of the device tree the net device is connected to. But right, net devices do not have device nodes :)
2005-04-26[PATCH] fix build error in namedev.c caused by previous patch.greg@kroah.com
2005-04-26[PATCH] correct apply_format() for symlink only ruleskay.sievers@vrfy.org
Patch from Andrey, which restores the ability to use RESULT values in a "symlink only" rule. We need to call apply_format() directly after the matching rule, otherwise the RESULT value may be lost.
2005-04-26[PATCH] uninitialized variable for mknod and friendolh@suse.de
mknod gets an uninitialized variable, which leads to interesting file modes. the bug is in namedev, devices with no match must not use the uninitialized stuff were dev points to.
2005-04-26[PATCH] first stupid try for a rule compose guikay.sievers@vrfy.org
On Mon, Mar 15, 2004 at 09:28:17PM +0100, Kay Sievers wrote: > Here is a first simple and pretty stupid try to make a simple tool for > composing of a udev rule. > > It reads the udevdb to get all currently handled devices and presents a > list, where you can choose the device to compose the rule for. > > The composed rule is just printed out in a window, nothing else by now. > > Do we want something like this? > Nevermind, I always wanted to know, how this newt thing works :) Here is the next step, I still can't sleep and there are to many patches pending to make something useful :) Cause nobody wanted to play with me, I've made a screenshot. The device list is sorted in alphabetical order now and if there are only a few recently discovered devices, they are placed on top of the list. For those who want to have a look: http://vrfy.org/projects/udev/udevruler.png The patch applies on top of today's mmap() patch. The db format is changed to have the file and line number of the applied rule. So it should be easy to edit the matching rule with this beast. It compiles with "make all udevruler".
2005-04-26[PATCH] replace fgets() with mmap() and introduce udev_lib.[hc]kay.sievers@vrfy.org
Here we replace the various fgets() with a mmap() call for the config file reading, due to the reported performance problems with klibc. Thanks to Patrick's testing, it makes a very small, close to nothing speed gain for libc users, but a 6 times speed increase for klibc users with a 1000 line config file. I've created a udev_lib.[hc] for this and also moved all the generic stuff from udev.h in there and uninlined the functions.
2005-04-26[PATCH] "symlink only" testkay.sievers@vrfy.org
Here is a test for the "symlink only" rule. Any reason to do the apply_format() inside the loop? I've changed it.
2005-04-26[PATCH] callout part selector tweakkay.sievers@vrfy.org
Martin Schwenke <martin@meltin.net> asked for this feature and posted a patch: The following patch almost let's me have the following configuration: PROGRAM="/sbin/aliaser %b %k %n %M %m", RESULT="?*", NAME="%c{1}", SYMLINK="%c{2+}" allowing me to specify an arbitrary number of symlinks by saying "giveme the second and later words"." Here is the actual version with tests and a few words in the man page.
2005-04-26[PATCH] cleanup callout forkkay.sievers@vrfy.org
Here I change the callout fork logic. The current cersion is unable to read a pipe which is not flushed at once, Now we read until it's closed. The maximum argument count is calculated by the strlen now. We have 100 chars for our result buffer so we can't have more than 50 parameters. So it's much more clear what will happen now and not some magic boundary where we use shell behind it. Parameter can be combined to one by using apostrophes. this on works now: BUS="scsi", PROGRAM="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL="sda3", NAME="%c{7}" Two new test are also added.
2005-04-26[PATCH] allow to specify node permissions in the rulekay.sievers@vrfy.org
This allows to set the permissions along with the rule. This is not a general replacement for the permissions config, but it may be easier sometimes for the user to specify the permissions along with the rule, cause the permissions config file wants the final node name to match, which seems sometimes a bit difficult to guess, if format % chars are used in the NAME field. Any value not given in the rule is still be read from the permissions file or set to the default. This one will also work: BUS="usb", KERNEL="video*", NAME="my-%k", OWNER="$local" A few words to man page are also added and add_perm_dev() is moved into namedev_parse.c where it belongs to.
2005-04-26[PATCH] rename strn*() macros to strmaxkay.sievers@vrfy.org
Hey, I wrote the strn*() macros just 10 days ago and yesterday this trap caught me with the %c{x} bug. The names are misleading cause we all expect that the from field is limited by the size argument, but we actually limit the overall size of the destination string to prevent a overflow. Here we rename all strn*() macros to str*max(). That should be more self-explanatory.
2005-04-26[PATCH] conditional remove of trailing sysfs whitespacekay.sievers@vrfy.org
Hey, it may never happen, that one wants to distinguish attributes by trailing spaces, but we should not lose the control over it, just for being lazy :) Here we remove the trailing spaces of the sysfs attribute only if the configured value to match doesn't have any trailing spaces by itself. So if you put a attribute in a rule with spaces at the end, the sysfs attribute _must_ match exactly. Is that cool for everyone? As usual, 2 tests are added for it with a artificial sysfs file and a few words to the man page.
2005-04-26[PATCH] better fix for NAME="foo-%c{N}" gets a truncated namekay.sievers@vrfy.org
On Wed, Mar 03, 2004 at 04:56:34PM -0800, Greg KH wrote: > On Wed, Mar 03, 2004 at 03:57:04PM -0800, Patrick Mansfield wrote: > > > > Here is a patch for some new tests. > > Applied, thanks. Here is a small improvement, which looks much better. Hey Pat, thanks a lot for finding the recent bug, hope this one will not break it again :)
2005-04-26[PATCH] fix NAME="foo-%c{N}" gets a truncated namekay.sievers@vrfy.org
On Wed, Mar 03, 2004 at 02:43:34PM -0800, Patrick Mansfield wrote: > Here is a fix and a new test for the problem Atul hit, where if we have a > NAME based on a result of the form: > > NAME="foo-%c{7}" > > udev truncates the name. Without any prefix (the foo- in this example), > the rule was working OK. Here is a fix for the fix :) Sorry, I broke it yesterday.
2005-04-26[PATCH] cleanup mult field string handlingkay.sievers@vrfy.org
Here I try to cleanup our various multifield iteration over the strings. Inspired by our nice list.h we now have a macro to iterate over the string and process the parts of it: It makes the code more readable and we don't change the string while we process it like the former strsep() does. Example: foreach_strpart(dev->symlink, " ", pos, len) { if (strncmp(&dev->symlink[pos], find_name, len) != 0) continue; ... } For the callout part selector %c{2} we separate now not only by space but also newline and return characters, cause some programs may give multiline values back. A possible RESULT match must contain wildcards for these characters. Also a bug in the recent udevinfo symlink query feature is fixed.
2005-04-26[PATCH] fix stroul endptr usekay.sievers@vrfy.org
The endptr is never NULL, so here we hopefully do the right thing.
2005-04-26[PATCH] udev - fix debug info for multiple rule file configkay.sievers@vrfy.org
On Sat, Feb 28, 2004 at 09:56:32PM +0100, Kay Sievers wrote: > Andrey pointed out that we don't print the right filename in the debug > output. Here is a fix for that. It applies on top of Andrey's symlink > patch, cause we are touching the same part of the code. The copy/paste devil catched me :) Here is a fixed one.
2005-04-26[PATCH] udev - activate formt length attributekay.sievers@vrfy.org
We carried the the old callout part selector syntax for two releases now after it was replaced by the new %c{1} syntax. So here we remove the old syntax and use the code to possibly specify the maximum count of chars to insert into the string. It will work with all of our format chars. I don't know if somebody will use it, but the code is already there :) 's%3s{vendor}' returns "IBM" now, instead of "IBM-ESXS". Also added is a test for it and a few words in the man page.
2005-04-26[PATCH] Add symlink only rules supportarvidjaar@mail.ru
2005-04-26[PATCH] udev - safer sprintf() usekay.sievers@vrfy.org
Here is for now my last patch to the string handling for a rather theorethical case, where the node is very very very long. :) We have accordant to strfieldcat(to, from) now a strintcat(to, i) macro, which appends the ascii representation of a integer to a string in a safe way.
2005-04-26[PATCH] remove limit of the number of args passed to PROGRAMgreg@kroah.com
If we go over our internal limit of 7, then we call out to /bin/sh otherwise we handle it ourself without relying on a shell.
2005-04-26[PATCH] udev - safer string handling - part fourkay.sievers@vrfy.org
Mainly a cleanup of the earlier patches with a few missing pieces and some cosmetical changes. I've moved the udev_init_config() to very early init, otherwise we don't get any logging for the processing of the input. What would I do without gdb :) Greg, it's the 7th patch in your box to apply. I will stop now and wait for you :)
2005-04-26[PATCH] udev - safer string handling - part threekay.sievers@vrfy.org
Here we truncate our input strings from the environment to our defined limit. It's a bit theroretical but better check for it. It cleans up some magic length definitions and removes the code duplication in udev, udevtest and udevsend. udevd needs to be killed after installation, cause the message size is changed with this patch. Should we do this with the 'make install', like we do with the '.udevdb'?
2005-04-26[PATCH] udev - safer string handling - part twokay.sievers@vrfy.org
As promised, here is the next round. We provide in addition to the already used macros: strfieldcpy(to, from) strfieldcat(to, from) the corresponding friends, if the size of the target is not known and must be provided by the caller: strnfieldcpy(to, from, maxsize) strnfieldcat(to, from, maxsize) and switch nearly all possibly unsafe users of strcat(), strncat(), strcpy() and strncpy() to these safer macros. The last known remaining issue seems the use of sprintf() and snprintf(). I will take on it later today or tomorrow.
2005-04-26[PATCH] udev - safer string handling all over the placekay.sievers@vrfy.org
On Tue, Feb 24, 2004 at 11:50:52PM +0100, Kay Sievers wrote: > Here is the first step towards a safer string handling. > More will follow, but for now only the easy ones :) > > Thanks to all who pointed this out. strncat() isn't a nice function. We > all should remember that the destination string is not terminated if the > given lenght is shorter than the strlen of the source string. > > And shame on the various implementers of strfieldcat() I found in the > unapplied patches on this list, it's not really better than strncpy() > and hides the real problem. Hmm, bk didn't checked in one file, maybe I edited it again as root. Nevermind, here is the more complete version.
2005-04-26[PATCH] force udev to include the internal version of libsysfs and never the ↵greg@kroah.com
external one. Should fix some more build bugs...
2005-04-26[PATCH] udev use new libsysfs header file locationpatmans@us.ibm.com
Use the new location of libsysfs header files.
2005-04-26[PATCH] add support for UDEV_NO_SLEEP env variable so Gentoo people will be ↵greg@kroah.com
happy. Actually, I'm happy to, startup time is much smaller...
2005-04-26[PATCH] udev - switch callout part selector to {attribute}kay.sievers@vrfy.org
Here we change the magic callout part number selector to the new atribute syntax. The syntax to select the second part of the callout string: '%2c' is now '%c{2}' I think it's more clear and we no longer misuse the length argument. The old syntax is still supported, but we should remove it some time in the future.
2005-04-26[PATCH] udev - create all partitions of blockdevicekay.sievers@vrfy.org
Here is the first try to create all partitons of a blockdevice, since removable media devices may need to acces the expected partition to revalidate the media. It uses the attribute syntax introduced with the last %s{file} patch. I'm using this with my multi-slot-flash-card-reader: SYSFS{model}="USB Storage-SMC ", NAME{all_partitions}="smartmedia" SYSFS{model}="USB Storage-CFC ", NAME{all_partitions}="compactflash" SYSFS{model}="USB Storage-MSC ", NAME{all_partitions}="memorystick" SYSFS{model}="USB Storage-MMC ", NAME{all_partitions}="multimedia" and I get: tree /udev/ /udev/ |-- memorystick |-- memorystick1 |-- memorystick10 |-- memorystick11 |-- memorystick12 |-- memorystick13 |-- memorystick14 |-- memorystick15 |-- memorystick2 |-- memorystick3 |-- memorystick4 |-- memorystick5 |-- memorystick6 |-- memorystick7 |-- memorystick8 |-- memorystick9 |-- multimedia |-- multimedia1 |-- multimedia10 |-- multimedia11 |-- multimedia12 |-- multimedia13 |-- multimedia14 |-- multimedia15 |-- multimedia2 |-- multimedia3 |-- multimedia4 |-- multimedia5 |-- multimedia6 |-- multimedia7 |-- multimedia8 |-- multimedia9 ... If needed, we can make the number of partions to create adjustable with the attribute?
2005-04-26[PATCH] Adding '%s' format specifier to NAME and SYMLINKkay.sievers@vrfy.org
On Thu, Feb 12, 2004 at 05:34:57PM -0800, Greg KH wrote: > On Tue, Feb 10, 2004 at 09:14:20AM +0100, Hannes Reinecke wrote: > > Hi all, > > > > this patch makes the format for NAME and SYMLINK a bit more flexible: > > I've added a new format specifier '%s{<SYSFS_var>}', which allows for > > the value of any sysfs entry found for this device to be inserted. > > Example (for our S/390 fcp adapter): > > > > BUS="ccw", SYSFS_devtype="1732/03", NAME="%k" \ > > SYMLINK="zfcp-%s{hba_id}-%s{wwpn}:%s{fcp_lun}" > > > > I know this could also be done with an external program, but having this > > incorporated into udev makes life easier, especially if run from > > initramfs. Plus it makes the rules easier to follow, as the result is > > directly visible and need not to be looked up in some external program. > > > > Comments etc. welcome. > > Oops, sorry I missed this for the 017 release. I'll look at it tomorrow > and get back to you. At first glance it looks like a good thing. > > Oh, you forgot to update the documentation, that's important to do if > you want this change to make it in :) I took a part of the code and made a version that uses already implemented attribute finding logic. The parsing of the format length '%3x' and the '%x{attribute}' is a fuction now, maybe there are more possible users in the future. I've also added the test to udev-test.pl.
2005-04-26[PATCH] Fix bug where we did not use the "converted" kernel name if we had ↵greg@kroah.com
no rule. This fixes the bug with names that have a ! in them and no rule to match.
2005-04-26[PATCH] fix bug in permission handling.greg@kroah.com
2005-04-26[PATCH] fix problem where usb devices can be either the main device or the ↵greg@kroah.com
interface This fixes the bug of a long delay for mouse devices
2005-04-26[PATCH] udev add wild card compare for IDpatmans@us.ibm.com
Allow wild card comparison of the ID. Using strcmp_pattern here also means we on longer match partial values, for example, a scsi rule like this won't match anymore: BUS="scsi", ID=":0", NAME="sdfoo-short-bus_id-1" But this now works: BUS="scsi", ID="*:0", NAME="sdfoo-bus_id-wild-card-1"
2005-04-26[PATCH] udev kill extra bus_id compares in match_idpatmans@us.ibm.com
Kill the extra bus_id check in match_id. This is wrong, especially since we check for rule matches with the parent devices on a given devices path. For example, given a device path of: /sys/devices/pci0000:01/0000:01:0c.0/host5/5:0:2:0 With this patch, the following rule will no longer match: BUS="scsi", ID="host5", NAME="sd-bus_id-host5"
2005-04-26[PATCH] Handle the '!' character that some block devices have.greg@kroah.com
2005-04-26[PATCH] udev - fix "ignore method"kay.sievers@vrfy.org
On Sun, Feb 08, 2004 at 04:36:01PM +0100, Kay Sievers wrote: > We don't handle NAME="" the right way. Thanks to Emil None <emil71se@yahoo.com> > for pointing this out. Here is a fix for it and a trivial style cleanup. Changed the ignore dbg() to info().
2005-04-26[PATCH] fix possible buffer overflowkay.sievers@vrfy.org
On Tue, Jan 27, 2004 at 11:02:25AM -0800, Greg KH wrote: > On Mon, Jan 26, 2004 at 07:28:03PM -0500, Adrian Drzewiecki wrote: > > Looking over the code, I noticed something odd in > > namedev.c:strcmp_pattern() -- > > > > while (*p && (*p != ']')) > > p ++; > > return strcmp_pattern(p+1, s+1); > > > > If the pattern string is invalid, and is not terminated by a ']', then 'p' > > will point at \0 and p+1 will be beyond the string. > > Yes, I think you are correct. > > Hm, Kay, any idea of the proper way to fix this? I've attached a patch > below, but I don't think it is correct. > > while (*p && (*p != ']')) > p++; > - return strcmp_pattern(p+1, s+1); > + if (*p) > + return strcmp_pattern(p+1, s+1); > + else > + return 1; > } > } Sure, it's perfectly correct. I'm wondering how Adrian found this. We can use the return 1 at the end of the whole function, and asking for the closing ']' is more descriptive, but it does the same. - return strcmp_pattern(p+1, s+1); + if (*p == ']') + return strcmp_pattern(p+1, s+1); Patch is attached, that also replaces all the *s with s[0].
2005-04-26[PATCH] udev - trivial style cleanupkay.sievers@vrfy.org
Trivial style cleanup, to be consistent. And add chdir("/") to the daemon so one can umout its filesystem, while we are running :)
2005-04-26[PATCH] add support for figuring out which device on the sysfs "chain" the ↵greg@kroah.com
rule applies to. This should fix one of the more annoying things to me about udev, and gets rid of a TODO item.
2005-04-26[PATCH] misc code cleanups.greg@kroah.com
2005-04-26[PATCH] set default owner/group in db - updatekay.sievers@vrfy.org
I've edited the man page today, so this is alreay included :) Also a few more trivials: o added the defaults to udev.conf.in o removed class_dev from get_default_mode(), to match with Hanna's o changed size of mode_str to MODE_SIZE o changed a few char compares from from 0x00 to '\0'