[PATCH] fix long delay for all devices in namedev

Now we only sleep if we can't find the device file, and we have
a hack to sleep for 1 second if we are on a partition.  This will be
removed when the libsysfs change gets made...
This commit is contained in:
greg@kroah.com 2003-12-24 19:44:19 -08:00 committed by Greg KH
parent 1e5b0d2fc9
commit 07562d6ecf

View file

@ -624,57 +624,51 @@ static struct sysfs_device *get_sysfs_device(struct sysfs_class_device *class_de
struct sysfs_device *sysfs_device; struct sysfs_device *sysfs_device;
struct sysfs_class_device *class_dev_parent; struct sysfs_class_device *class_dev_parent;
int loop; int loop;
/* FIXME!!! */
/* This is needed here as we can easily out-race the placement of the
* device symlink by the kernel. The call to sleep(1); will be removed
* once libsysfs can be queried for sysfs_get_classdev_device()
* multiple times and have it return the proper information when the
* class device really shows up. For now, we live with the time
* delay...
*/
sleep(1);
#if 0 /* FIXME
Something like this could also work, but for some reason doesn't,
I also tried just stat() on the device symlink, but that still
has nasty races, I'm probably doing something stupid... :( */
loop = 10;
while (loop--) {
struct stat buf;
int retval;
char filename[SYSFS_PATH_MAX + 6]; char filename[SYSFS_PATH_MAX + 6];
int retval;
char *temp;
int partition = 0;
strcpy(filename, class_dev->path); /* Figure out where the device symlink is at. For char devices this will
strcat(filename, "/device"); * always be in the class_dev->path. But for block devices, it's different.
dbg("looking for '%s'", filename); * The main block device will have the device symlink in it's path, but
retval = stat(filename, &buf); * all partitions have the symlink in its parent directory.
if (!retval) * But we need to watch out for block devices that do not have parents, yet
break; * look like a partition (fd0, loop0, etc.) They all do not have a device
* symlink yet. We do sit and spin on waiting for them right now, we should
/* bah, let's go backwards up a level to see if the device is there, * possibly have a whitelist for these devices here...
* as block partitions don't point to the physical device. Need to fix that
* up in the kernel...
*/ */
strcpy(filename, class_dev->path);
dbg("filename = %s", filename);
if (strcmp(class_dev->classname, SYSFS_BLOCK_NAME) == 0) { if (strcmp(class_dev->classname, SYSFS_BLOCK_NAME) == 0) {
if (isdigit(class_dev->path[strlen(class_dev->path)-1])) { if (isdigit(class_dev->path[strlen(class_dev->path)-1])) {
class_dev_parent = sysfs_get_classdev_parent(class_dev); temp = strrchr(filename, '/');
if (class_dev_parent == NULL) { if (temp) {
dbg("sysfs_get_classdev_parent for class device '%s' failed", class_dev->name); partition = 1;
} else { *temp = 0x00;
strcpy(filename, class_dev_parent->path); char *temp2 = strrchr(filename, '/');
dbg("temp2 = %s", temp2);
if (temp2 && (strcmp(temp2, "/block") == 0)) {
/* oops, we have no parent block device, so go back to original directory */
strcpy(filename, class_dev->path);
partition = 0;
}
}
}
}
strcat(filename, "/device"); strcat(filename, "/device");
loop = 2;
while (loop--) {
struct stat buf;
dbg("looking for '%s'", filename); dbg("looking for '%s'", filename);
retval = stat(filename, &buf); retval = stat(filename, &buf);
if (!retval) if (!retval)
break; break;
}
}
}
/* sleep to give the kernel a chance to create the device file */ /* sleep to give the kernel a chance to create the device file */
sleep(1); sleep(1);
} }
#endif
loop = 1; /* FIXME put a real value in here for when everything is fixed... */ loop = 1; /* FIXME put a real value in here for when everything is fixed... */
while (loop--) { while (loop--) {
/* find the sysfs_device for this class device */ /* find the sysfs_device for this class device */
@ -683,13 +677,14 @@ static struct sysfs_device *get_sysfs_device(struct sysfs_class_device *class_de
if (sysfs_device != NULL) if (sysfs_device != NULL)
goto exit; goto exit;
/* bah, let's go backwards up a level to see if the device is there, /* if it's a partition, we need to get the parent device */
* as block partitions don't point to the physical device. Need to fix that if (partition) {
* up in the kernel... /* FIXME HACK HACK HACK HACK
* for some reason partitions need this extra sleep here, in order
* to wait for the device properly. Once the libsysfs code is
* fixed properly, this sleep should go away, and we can just loop above.
*/ */
if (strcmp(class_dev->classname, SYSFS_BLOCK_NAME) == 0) { sleep(1);
dbg("looking at block device");
if (isdigit(class_dev->path[strlen(class_dev->path)-1])) {
dbg("really is a partition"); dbg("really is a partition");
class_dev_parent = sysfs_get_classdev_parent(class_dev); class_dev_parent = sysfs_get_classdev_parent(class_dev);
if (class_dev_parent == NULL) { if (class_dev_parent == NULL) {
@ -701,10 +696,9 @@ static struct sysfs_device *get_sysfs_device(struct sysfs_class_device *class_de
goto exit; goto exit;
} }
} }
}
/* sleep to give the kernel a chance to create the link */ /* sleep to give the kernel a chance to create the link */
sleep(1); /* FIXME remove comment...
sleep(1); */
} }
dbg("Timed out waiting for device symlink, continuing on anyway..."); dbg("Timed out waiting for device symlink, continuing on anyway...");
exit: exit: