netdev - udevdb+dev.d changes
PATCH 1/1 netdev - udevdb+dev.d changes
Hey, Chris fixed the udevd hole and Treeve found the timestamp bug, so there was nothing left for me at the weekend :)
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.
thanks,
Kay
===== dev_d.c 1.3 vs edited =====
dev_d.c +13 -5
@@ -64,11 +64,20 @@void dev_d_send (struct udevice *dev,char *subsystem) {char dirname[256 ]; -char devnode[NAME_SIZE ]; +char devname[NAME_SIZE ]; -strfieldcpy (devnode, udev_root); -strfieldcat (devnode, dev->name); -setenv ("DEVNODE" , devnode,1 ); +if (udev_dev_d ==0 ) +return ; + +if (dev->type =='b' || dev->type =='c' ) { +strfieldcpy (devname, udev_root); +strfieldcat (devname, dev->name); + }else if (dev->type =='n' ) { +strfieldcpy (devname, dev->name); + } +setenv ("DEVNODE" , devname,1 );/* FIXME: bad name for netif */ +setenv ("DEVNAME" , devname,1 ); +dbg ("DEVNAME='%s'" , devname);strcpy (dirname,DEVD_DIR );strfieldcat (dirname, dev->name);
@@ -81,4 +90,3 @@strcpy (dirname,DEVD_DIR "default" );call_foreach_file (run_program, dirname,DEVD_SUFFIX ); } -
===== namedev.c 1.137 vs edited =====
namedev.c +14 -12
@@ -32,6 +32,9 @@#include <time.h> #include <sys/wait.h> #include <sys/stat.h> +#ifndef __KLIBC__ +#include <sys/sysinfo.h> +#endif #include "libsysfs/sysfs/libsysfs.h" #include "list.h"
@@ -454,7 +457,7 @@ retval =-1 ; } -if (i >0 && value[i] =='\n' ) +if (i >0 && value[i-1 ] =='\n' ) i--; value[i] ='\0' ;dbg ("result is '%s'" , value);
@@ -776,6 +779,7 @@struct sysfs_device *sysfs_device =NULL ;struct config_device *dev;struct perm_device *perm; +struct sysinfo info;char *pos; udev->mode =0 ;
@@ -837,22 +841,18 @@ } } } - -/* no rule was found for the net device */ -if (udev->type =='n' ) { -dbg ("no name for net device '%s' configured" , udev->kernel_name); -return -1 ; - } -/* no rule was found so we use the kernel name */ strfieldcpy (udev->name, udev->kernel_name); - goto done; +if (udev->type =='n' ) + goto done; +else + goto perms; found:apply_format (udev, udev->name,sizeof (udev->name), class_dev, sysfs_device);if (udev->type =='n' ) -return 0 ; + goto done; udev->partitions = dev->partitions;strfieldcpy (udev->config_file, dev->config_file);
@@ -863,7 +863,7 @@ dev->owner, dev->group); -done: +perms:/* get permissions given in config file or set defaults */ perm =find_perm (udev->name);if (perm !=NULL ) {
@@ -879,8 +879,10 @@dbg ("name, '%s' is going to have owner='%s', group='%s', mode = %#o" , udev->name, udev->owner, udev->group, udev->mode); +done:/* store time of action */ - udev->config_time =time (NULL ); +sysinfo (&info); + udev->config_uptime = info.uptime;return 0 ; }
===== udev-add.c 1.67 vs edited =====
udev-add.c +59 -48
241 lines not on this page · raw message
===== udev-remove.c 1.29 vs edited =====
udev-remove.c +14 -26
@@ -137,36 +137,24 @@memset (&dev,0x00 ,sizeof (dev)); - dev.type =get_device_type (path, subsystem); - -switch (dev.type) { -case 'b' : -case 'c' : - retval =udevdb_get_dev (path, &dev); -if (retval) { -dbg ("'%s' not found in database, falling back on default name" , path); - temp =strrchr (path,'/' ); -if (temp ==NULL ) -return -ENODEV ; -strfieldcpy (dev.name, &temp[1 ]); - } - -dbg ("name='%s'" , dev.name); -udevdb_delete_dev (path); + retval =udevdb_get_dev (path, &dev); +if (retval !=0 ) { +dbg ("'%s' not found in database, falling back on default name" , path); + temp =strrchr (path,'/' ); +if (temp ==NULL ) +return -ENODEV ; +strfieldcpy (dev.name, &temp[1 ]); + } +dbg ("name='%s'" , dev.name); -dev_d_send (&dev, subsystem); + dev.type =get_device_type (path, subsystem); +dev_d_send (&dev, subsystem); +udevdb_delete_dev (path); +if (dev.type =='b' || dev.type =='c' ) retval =delete_node (&dev); -break ; - -case 'n' : +else if (dev.type =='n' ) retval =0 ; -break ; - -default : -dbg ("unknown device type '%c'" , dev.type); - retval = -EINVAL ; - }return retval; }
===== udev.h 1.55 vs edited =====
udev.h +2 -1
@@ -52,7 +52,7 @@int partitions;int config_line;char config_file[NAME_SIZE ]; -time_t config_time; +long config_uptime;/* private data that help us in building strings */ char bus_id[SYSFS_NAME_LEN ];
@@ -80,5 +80,6 @@extern char default_group_str[GROUP_SIZE ];extern int udev_log;extern int udev_sleep; +extern int udev_dev_d;#endif
===== udev_config.c 1.15 vs edited =====
udev_config.c +5 -0
@@ -51,6 +51,7 @@char default_group_str[GROUP_SIZE ];int udev_log;int udev_sleep; +int udev_dev_d;static int string_is_true (char *str)
@@ -77,6 +78,10 @@ udev_sleep =1 ;if (getenv ("UDEV_NO_SLEEP" ) !=NULL ) udev_sleep =0 ; + + udev_dev_d =1 ; +if (getenv ("UDEV_NO_DEVD" ) !=NULL ) + udev_dev_d =0 ; }#define set_var (_name, _var) \
===== udev_lib.c 1.4 vs edited =====
udev_lib.c +16 -5
@@ -86,17 +86,28 @@return subsystem; } +#define BLOCK_PATH "/block/" +#define CLASS_PATH "/class/" +#define NET_PATH "/class/net/" +char get_device_type (const char *path,const char *subsystem) { -if (strcmp (subsystem,"block" ) ==0 || -strstr (path,"/block/" ) !=NULL ) +if (strcmp (subsystem,"block" ) ==0 ) +return 'b' ; + +if (strcmp (subsystem,"net" ) ==0 ) +return 'n' ; + +if (strncmp (path,BLOCK_PATH ,strlen (BLOCK_PATH )) ==0 && +strlen (path) >strlen (BLOCK_PATH ))return 'b' ; -if (strcmp (subsystem,"net" ) ==0 || -strstr (path,"/class/net/" ) !=NULL ) +if (strncmp (path,NET_PATH ,strlen (NET_PATH )) ==0 && +strlen (path) >strlen (NET_PATH ))return 'n' ; -if (strstr (path,"/class/" ) !=NULL ) +if (strncmp (path,CLASS_PATH ,strlen (CLASS_PATH )) ==0 && +strlen (path) >strlen (CLASS_PATH ))return 'c' ;return '\0' ;
===== udevdb.c 1.28 vs edited =====
udevdb.c +1 -0
@@ -59,6 +59,7 @@ data.dptr = (void *)dev; data.dsize =UDEVICE_LEN ; +dbg ("store key '%s' for device '%s'" , path, dev->name);return tdb_store (udevdb, key, data,TDB_REPLACE ); }
===== udevinfo.c 1.22 vs edited =====
udevinfo.c +2 -1
@@ -108,13 +108,14 @@ {printf ("P: %s\n" , path);printf ("N: %s\n" , dev->name); +printf ("T: %c\n" , dev->type);printf ("M: %#o\n" , dev->mode);printf ("S: %s\n" , dev->symlink);printf ("O: %s\n" , dev->owner);printf ("G: %s\n" , dev->group);printf ("F: %s\n" , dev->config_file);printf ("L: %i\n" , dev->config_line); -printf ("T: %li\n" , dev->config_time); +printf ("U: %li\n" , dev->config_uptime);printf ("\n" );return 0 ; }
===== udevruler.c 1.2 vs edited =====
udevruler.c +7 -7
@@ -77,7 +77,7 @@char devpath[DEVPATH_SIZE ];int config_line;char config_file[NAME_SIZE ]; -time_t config_time; +long config_uptime;int added; };
@@ -106,7 +106,7 @@strfieldcpy (dev->devpath, path); dev->config_line = udev->config_line;strfieldcpy (dev->config_file, udev->config_file); - dev->config_time = udev->config_time; + dev->config_uptime = udev->config_uptime; dev->added =0 ;/* sort in lexical order */
@@ -308,7 +308,7 @@char roottext[81 ];char path[NAME_SIZE ];struct device *dev; -time_t time_last; +long time_last;int count_last;newtInit ();
@@ -332,13 +332,13 @@/* look for last discovered device */ time_last =0 ;list_for_each_entry (dev, &device_list, list) -if (dev->config_time > time_last) - time_last = dev->config_time; +if (dev->config_uptime > time_last) + time_last = dev->config_uptime;/* skip if more than 16 recent devices */ count_last =0 ;list_for_each_entry (dev, &device_list, list) { -if (dev->config_time < time_last -10 ) +if (dev->config_uptime < time_last -10 )continue ; count_last++; }
@@ -347,7 +347,7 @@if (count_last <16 ) {newtListboxAppendEntry (lbox,"--- last dicovered ---" ,NULL );list_for_each_entry (dev, &device_list, list) { -if (dev->config_time < time_last -10 ) +if (dev->config_uptime < time_last -10 )continue ;dbg ("%s %i" , dev->name, dev->config_line);
===== test/udev-test.pl 1.53 vs edited =====
test/udev-test.pl +11 -0
@@ -235,6 +235,15 @@ EOF }, { + desc => "program result substitution (newline removal)", + subsys => "block", + devpath => "/block/sda/sda3", + exp_name => "newline_removed" , + conf => <<EOF +BUS="scsi", PROGRAM="/bin/echo test", RESULT="test", NAME="newline_removed" +EOF + }, + { desc => "program result substitution", subsys => "block", devpath => "/block/sda/sda3",
@@ -580,6 +589,8 @@ $ENV{UDEV_TEST} = "yes"; $ENV{SYSFS_PATH} = $sysfs; $ENV{UDEV_CONFIG_FILE} = $main_conf; +$ENV{UDEV_NO_SLEEP} = "yes"; +$ENV{UDEV_NO_DEVD} = "yes"; sub udev {
Quoted 6 lines · Kay Sievers
Hey, Chris fixed the udevd hole and Treeve found the timestamp bug, so there was nothing left for me at the weekend :)
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().
Thanks, I've applied this now.
Quoted 4 lines
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.
nice.
Quoted 6 lines
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?
Yeah, we should.
Quoted 7 lines
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?
Can you think of a better name?
Quoted 5 lines
o I've added a
UDEV_NO_DEVDto 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?
No, a system will want to have those scripts run when udevstart is run (at boot time.) Otherwise how will devices get mounted, dbus messages, etc. ?
Quoted 3 lines
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.
I cut this out, as I had already applied it from a previous patch.
Quoted 2 lines
o bugfix, the RESULT value has now a working newline removal and a test for this case.
Nice.
thanks a lot,
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 9 lines · Greg KH
Quoted 6 lines · Kay Sievers
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?
Yeah, we should.
Ok, I will prepare a patch, now.
Quoted 9 lines
Quoted 7 lines
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?
Can you think of a better name?
I think DEVNAME sounds better for a netdev and is fine for a node too? What do you think?
thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 5 lines · Kay Sievers
Quoted 5 lines
Quoted 5 lines
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.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
o DEVNODE sounds a bit ugly for netdev's so I exported DEVNAME too. Can we change the name?
Can you think of a better name?
I think DEVNAME sounds better for a netdev and is fine for a node too? What do you think?
That's what I originally had, yet changed it to DEVNODE. But now that we have network device support, it makes more sense to call it that. Care to make a patch that does that too?
thanks,
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 9 lines · Greg KH
Quoted 8 lines · Kay Sievers
Quoted 8 lines
Quoted 7 lines
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?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Can you think of a better name?
I think DEVNAME sounds better for a netdev and is fine for a node too? What do you think?
That's what I originally had, yet changed it to DEVNODE. But now that we have network device support, it makes more sense to call it that. Care to make a patch that does that too?
Here we change the DEVPATH for netdev's in the environment of the dev.d/ scripts to the name the device is renamed to. The original name doesn't exist in the kernel after rename.
Do you have anything already done for the man page for the new dev.d/ logic? If not, I will care.
thanks,
Kay
===== dev_d.c 1.4 vs edited =====
dev_d.c +2 -2
@@ -61,7 +61,7 @@* subsystem/ * default/ */ -void dev_d_send (struct udevice *dev,char *subsystem) +void dev_d_send (struct udevice *dev,char *subsystem,char *devpath) {char dirname[256 ];char devname[NAME_SIZE ];
@@ -74,8 +74,8 @@strfieldcat (devname, dev->name); }else if (dev->type =='n' ) {strfieldcpy (devname, dev->name); +setenv ("DEVPATH" , devpath,1 ); } -setenv ("DEVNODE" , devname,1 );/* FIXME: bad name for netif */ setenv ("DEVNAME" , devname,1 );dbg ("DEVNAME='%s'" , devname);
===== udev-add.c 1.68 vs edited =====
udev-add.c +9 -8
@@ -403,7 +403,7 @@ {struct sysfs_class_device *class_dev;struct udevice dev; -char key[DEVPATH_SIZE ]; +char devpath[DEVPATH_SIZE ];char *pos;int retval;
@@ -452,10 +452,11 @@dbg ("udevdb_add_dev failed, but we are going to try " "to create the node anyway. But remove might not " "work properly for this device." ); + +dev_d_send (&dev, subsystem, path);break ;case 'n' : -strfieldcpy (key, path);if (strcmp (dev.name, dev.kernel_name) !=0 ) { retval =rename_net_if (&dev, fake);if (fake || retval !=0 )
@@ -463,19 +464,19 @@/* netif's are keyed with the configured name, cause * the original kernel name sleeps with the fishes */ - pos =strrchr (key,'/' ); +strfieldcpy (devpath, path); + pos =strrchr (devpath,'/' );if (pos !=NULL ) { pos[1 ] ='\0' ; -strfieldcat (key, dev.name); +strfieldcat (devpath, dev.name); } } -if (udevdb_add_dev (key, &dev) !=0 ) +if (udevdb_add_dev (devpath, &dev) !=0 )dbg ("udevdb_add_dev failed" ); + +dev_d_send (&dev, subsystem, devpath);break ; } - -/* execute programs in dev.d/ with the name in the environment */ -dev_d_send (&dev, subsystem); exit:sysfs_close_class_device (class_dev);
===== udev-remove.c 1.30 vs edited =====
udev-remove.c +1 -1
@@ -148,7 +148,7 @@dbg ("name='%s'" , dev.name); dev.type =get_device_type (path, subsystem); -dev_d_send (&dev, subsystem); +dev_d_send (&dev, subsystem, path);udevdb_delete_dev (path);if (dev.type =='b' || dev.type =='c' )
===== udev.h 1.56 vs edited =====
udev.h +1 -1
@@ -65,7 +65,7 @@extern int udev_remove_device (char *path,char *subsystem);extern void udev_init_config (void );extern int parse_get_pair (char **orig_string,char **left,char **right); -extern void dev_d_send (struct udevice *dev,char *subsystem); +extern void dev_d_send (struct udevice *dev,char *subsystem,char *devpath);extern char **main_argv;extern char **main_envp;
===== udev_config.c 1.16 vs edited =====
udev_config.c +3 -3
@@ -86,13 +86,13 @@#define set_var (_name, _var) \ if (strcasecmp(variable, _name) == 0) { \ - dbg_parse("%s = '%s'", _name, value); \ - strfieldcpymax(_var, value, sizeof(_var));\ + dbg_parse("%s='%s'", _name, value); \ + strfieldcpy(_var, value);\ }#define set_bool (_name, _var) \ if (strcasecmp(variable, _name) == 0) { \ - dbg_parse("%s = '%s'", _name, value); \ + dbg_parse("%s='%s'", _name, value); \ _var = string_is_true(value); \ }
===== udevd.c 1.27 vs edited =====
udevd.c +4 -2
@@ -139,8 +139,10 @@char devpath[DEVPATH_SIZE ];char *env[] = { action, devpath,NULL }; -snprintf (action,sizeof (action),"ACTION=%s" , msg->action); -snprintf (devpath,sizeof (devpath),"DEVPATH=%s" , msg->devpath); +strcpy (action,"ACTION=" ); +strfieldcat (action, msg->action); +strcpy (devpath,"DEVPATH=" ); +strfieldcat (devpath, msg->devpath); pid =fork ();switch (pid) {
===== udevstart.c 1.5 vs edited =====
udevstart.c +3 -2
@@ -33,6 +33,7 @@#include <unistd.h> #include "logging.h" +#include "udev_lib.h" #ifdef LOG
@@ -61,8 +62,8 @@char nosleep[] ="UDEV_NO_SLEEP=1" ;char *env[] = { action, devpath, nosleep,NULL }; -snprintf (devpath,MAX_PATHLEN ,"DEVPATH=%s" , path); - devpath[MAX_PATHLEN -1 ] ='\0' ; +strcpy (action,"DEVPATH=%s" ); +strfieldcat (action, path); pid =fork ();switch (pid) {
Quoted 4 lines · Kay Sievers
Here we change the DEVPATH for netdev's in the environment of the dev.d/ scripts to the name the device is renamed to. The original name doesn't exist in the kernel after rename.
Thanks, I've applied this.
Quoted 2 lines
Do you have anything already done for the man page for the new dev.d/ logic? If not, I will care.
No, I only wrote it up in the RFC-dev.d file in the docs directory.
Hm, that needs to be changed now due to this patch, I'll go do that right now...
thanks,
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel