From: Thierry Vignaud Date: Wed, 16 May 2007 14:59:20 +0000 Subject: [RFC] adding --sync option to udevsettle Message-Id: MIME-Version: 1 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: To: linux-hotplug@vger.kernel.org --=-=-= (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): --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=udevsettle.diff --- ./udevsettle.c.tv 2007-05-16 16:33:34.000000000 +0200 +++ ./udevsettle.c 2007-05-16 16:39:04.000000000 +0200 @@ -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=]\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 --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- 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/ --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel --=-=-=--