scsi_id - EBUSY and serialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We have a customer, who misses some symlinks for some of his scsi devices. Because of limited access and debugging facilities, I could only guess a fix.

The first patch retries opening the scsi device, if it is EBUSY.
The second patch serializes access with flock.

With these patches it seems to work. I don't know if the flock patch is really necessary. Any help and comments appreciated.

Harald
>From b7d94db71475a92efc11351cfd621e081b6c8bce Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@xxxxxxxxxx>
Date: Wed, 11 Jun 2008 11:32:34 +0200
Subject: [PATCH] retry open on EBUSY

---
 extras/scsi_id/scsi_serial.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/extras/scsi_id/scsi_serial.c b/extras/scsi_id/scsi_serial.c
index c5cacfa..ec72c7d 100644
--- a/extras/scsi_id/scsi_serial.c
+++ b/extras/scsi_id/scsi_serial.c
@@ -822,10 +822,17 @@ int scsi_get_serial (struct scsi_id_device *dev_scsi, const char *devname,
 	int fd;
 	int ind;
 	int retval;
+	int cnt = 10;
 
 	memset(dev_scsi->serial, 0, len);
 	dbg("opening %s\n", devname);
-	fd = open(devname, O_RDONLY | O_NONBLOCK);
+	while (((fd = open(devname, O_RDONLY | O_NONBLOCK)) != 0) && (cnt > 0) && errno == EBUSY) {
+		info("%s: cannot open %s: %s",
+		    dev_scsi->kernel_name, devname, strerror(errno));	  	  
+		info("retrying in 0.5 seconds");
+		usleep(500000 + (rand() % 100000) );
+		cnt--;
+	}
 	if (fd < 0) {
 		info("%s: cannot open %s: %s\n",
 		    dev_scsi->kernel, devname, strerror(errno));
-- 
1.5.5.1

>From ec3abdfd0b2e4f596c4cc988d5b7e6714cdb264e Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@xxxxxxxxxx>
Date: Wed, 11 Jun 2008 11:42:00 +0200
Subject: [PATCH] serialize scsi_id access with flock

---
 extras/scsi_id/scsi_id.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c
index 5eb95e8..04ae676 100644
--- a/extras/scsi_id/scsi_id.c
+++ b/extras/scsi_id/scsi_id.c
@@ -26,6 +26,7 @@
 #include <ctype.h>
 #include <getopt.h>
 #include <sys/stat.h>
+#include <sys/file.h>
 
 #include "../../udev.h"
 #include "scsi_id.h"
@@ -601,6 +602,17 @@ static int scsi_id(char *maj_min_dev)
 	int page_code;
 	char serial_short[MAX_SERIAL_LEN] = "";
 
+ 	char flock_path[MAX_PATH_LEN];
+ 	int flock_fd = -1;
+ 
+ 	strncpy(flock_path, "/sys/", MAX_PATH_LEN-1);
+ 	strncat(flock_path, devpath, MAX_PATH_LEN-1);
+ 	flock_path[MAX_PATH_LEN-1] = 0;
+ 
+ 	flock_fd = open(flock_path, O_RDONLY);
+ 	if (flock_fd >= 0)
+ 	  flock(flock_fd, LOCK_EX);
+ 
 	set_inq_values(&dev_scsi, maj_min_dev);
 
 	/* get per device (vendor + model) options from the config file */
@@ -636,6 +648,11 @@ static int scsi_id(char *maj_min_dev)
 		retval = 0;
 	}
 
+	if (flock_fd >= 0) {
+	  flock(flock_fd, LOCK_UN);
+	  close(flock_fd);
+	}
+
 	return retval;
 }
 
-- 
1.5.5.1

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Index of Archives]     [Linux Kernel]     [Linux DVB]     [Asterisk Internet PBX]     [DCCP]     [Netdev]     [X.org]     [Util Linux NG]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux