hal: Branch 'master'

David Zeuthen david at kemper.freedesktop.org
Thu Mar 22 13:36:11 PDT 2007


 hald/linux/probing/probe-storage.c |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

New commits:
diff-tree 6f117fbaa40241be557c603e531c2af30d59fabc (from 0bae506ffcaab4e64cb2c595469211df58a31dff)
Author: Kareem Dana <kareemy at gmail.com>
Date:   Thu Mar 22 16:36:11 2007 -0400

    fix probe-storage and addon-storage competing for O_EXCL on cdrom device
    
    I am attaching a quick patch I wrote based on retry code in
    hal-storage-shared.c. This patch appears to solve the problem for me,
    but I've only tested it a few times on my own machine.
    
    On 3/7/07, kareemy <kareemy at gmail.com> wrote:
    > I am trying hal 0.5.9rc1 and have had a problem where most of the times when I insert a new cdrom disk into my cdrom, no volume namespace is created for the cd. I did some debugging and found out this happens when open (device_file, ORDONLY | O_NONBLOCK | O_EXCL) fails and sets EBUSY in  probe-storage.c around line 287.
    >
    > Inside the EBUSY if conditional, hal correctly determines that the device is not mounted and then does a goto out, so it never opens the device and never setups a volume namespace or anything like that.
    >
    > I added some debugging output to probe-storage.c and addon-storage.c that prints when each one successfully opens the device and then closes it again. A lot of times on my system, addon-storage.c does a O_EXCL on the cdrom device, probe-storage attempts an O_EXCL and fails, then addon-storage closes the device.
    >
    > I'm attaching a log of hald --daemon=no --verbose=yes with my additional debugging comments that illustrates this. At the beginning of the file, it shows addon-storage polling the cdrom device every 2 seconds as usual, then once I insert a new media, addon-storage locks the cdrom, probe-storage trys to do an open, it fails, and then addon-storage closes the lock.
    >
    > I figure it is possible to have probe-storage keep trying if it gets an EBUSY error until it can open the device, but I'm not sure if that is the best solution. Ideas?
    >
    > Some more system specs:
    > Linux  2.6.19.2 SMP
    > Hal 0.5.9rc1
    > dbus 1.0.2
    >

diff --git a/hald/linux/probing/probe-storage.c b/hald/linux/probing/probe-storage.c
index 8afeb8d..c7dd691 100644
--- a/hald/linux/probing/probe-storage.c
+++ b/hald/linux/probing/probe-storage.c
@@ -99,7 +99,7 @@ out:
 int 
 main (int argc, char *argv[])
 {
-	int fd;
+	int fd, num_excl_tries = 5;
 	int ret;
 	char *udi;
 	char *device_file;
@@ -295,18 +295,25 @@ main (int argc, char *argv[])
 			 * actually is mounted. If it is we retry to open
 			 * without O_EXCL
 			 */
-			if (!is_mounted (device_file))
-				goto out;
-
-			HAL_DEBUG (("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file));
-			fd = open (device_file, O_RDONLY | O_NONBLOCK);
+            HAL_DEBUG (("Open failed - Device Busy"));
+			if (!is_mounted (device_file)) {
+                do {
+                    usleep(100 * 1000);
+                    HAL_DEBUG (("Attempting open w/ O_EXCL again"));
+                    fd = open (device_file, O_RDONLY | O_NONBLOCK | O_EXCL);
+                    num_excl_tries--;
+                } while (fd < 0 && num_excl_tries > 0);
+            } else {
+                HAL_DEBUG (("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file));
+                fd = open (device_file, O_RDONLY | O_NONBLOCK);
+            }
 		}
 
 		if (fd < 0) {
 			HAL_DEBUG (("open failed for %s: %s", device_file, strerror (errno)));
 			goto out;
 		}
-
+        HAL_DEBUG (("PROBE HAS EXCLUSIVE LOCK ON CDROM"));
 		got_media = FALSE;
 
 		/* Check if a disc is in the drive
@@ -356,6 +363,7 @@ main (int argc, char *argv[])
 		}
 
 		close (fd);
+        HAL_DEBUG (("PROBE CLOSED LOCK ON CDROM"));
 	} else {
 		struct volume_id *vid;
 		GDir *dir;


More information about the hal-commit mailing list