adding --sync option to udevsettle
RFC 1/1 adding --sync option to udevsettle
(First, note that I'm *NOT* subscribe to this ml, so please keep in
Cc: when answering)
Hi,
While using diskdrake on a system with udev, I found out that when resizing a partition, when we rewrite it and tell the kernel about the new partitions sizes, there's a race window with udev which then delete and recreate the nodes.
I think this can happen with quite a lot of tools that have to deal with /dev/ nodes and happens to make one being indectly created by doing sg with the kernel (creating a network interface, loading a mass storage driver, ...).
OK, there's the udevsettle solution.
But it's not complete.
Eg: here we want to wait that device nodes were created in /dev (aka really a sync in the command queue by analogy with disks controlling), we do not want to wait for further commands.
The following patch add the --sync option that enables to alter udevsettle behavior not to wait for further events to be processed (in case somebody is hapilly feeding udev with events):
udevsettle.c renamed from udevsettle.c.tv +7 -0
@@ -62,6 +62,8 @@int loop;int i;int rc =1 ; +int sync_mode =0 ; +int read_done =0 ;logging_init ("udevsettle" );udev_config_init ();
@@ -84,6 +86,8 @@ }else if (strcmp (arg,"--help" ) ==0 ||strcmp (arg,"-h" ) ==0 ) {printf ("Usage: udevsettle [--help] [--timeout=<seconds>]\n" ); goto exit; + }else if (strncmp (arg,"--sync" ,6 ) ==0 ) { + sync_mode =1 ; }else {fprintf (stderr,"unrecognized option '%s'\n" , arg);err ("unrecognized option '%s'\n" , arg);
@@ -111,6 +115,8 @@ }/* read current udev seqnum */ +if (sync_mode && !read_done) { + read_done =1 ;strlcpy (filename, udev_root,sizeof (filename));strlcat (filename,"/" EVENT_SEQNUM ,sizeof (filename)); fd =open (filename,O_RDONLY );
@@ -123,6 +128,7 @@ seqnum[len] ='\0' ; seq_udev =strtoull (seqnum,NULL ,10 );info ("udev seqnum = %llu" , seq_udev); + }/* read current kernel seqnum */ strlcpy (filename, sysfs_path,sizeof (filename));
What do you think?
Will you include it?
Note that I'ven't reindented the code in the new "if { ... }" block for readibility but I can send another patch to bring indent in sync with logical flow.
See you
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 19 lines · Thierry Vignaud
(First, note that I'm *NOT* subscribe to this ml, so please keep in
Cc: when answering)Hi,
While using diskdrake on a system with udev, I found out that when resizing a partition, when we rewrite it and tell the kernel about the new partitions sizes, there's a race window with udev which then delete and recreate the nodes.
I think this can happen with quite a lot of tools that have to deal with
/dev/nodes and happens to make one being indectly created by doing sg with the kernel (creating a network interface, loading a mass storage driver, ...).OK, there's the udevsettle solution.
But it's not complete.
Quoted 7 lines
Eg: here we want to wait that device nodes were created in /dev (aka really a sync in the command queue by analogy with disks controlling), we do not want to wait for further commands.
The following patch add the --sync option that enables to alter udevsettle behavior not to wait for further events to be processed (in case somebody is hapilly feeding udev with events):
If I understand that --sync option correctly, it does only prevent another round of "wait for the queue to be empty" in the unlikely situation, that events are generated, but have not arrived at udev. If something is creating a constant stream of events (that's what you want to work around here, right?), the queue will just not become empty and the --sync option will do nothing until the timeout.
Isn't what you are looking for a "check if the queue contains events for devices with the name 'sda*'" option?
Kay
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel