From: Harald Hoyer <harald@redhat.com>
To: linux-hotplug@vger.kernel.org
Subject: scsi_id - EBUSY and serialization
Date: Wed, 11 Jun 2008 09:55:26 +0000 [thread overview]
Message-ID: <484FA10E.9010303@redhat.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 402 bytes --]
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
[-- Attachment #1.2: 0001-retry-open-on-EBUSY.patch --]
[-- Type: text/plain, Size: 1122 bytes --]
From b7d94db71475a92efc11351cfd621e081b6c8bce Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Wed, 11 Jun 2008 11:32:34 +0200
Subject: [PATCH] retry open on EBUSY
---
| 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
--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
[-- Attachment #1.3: 0002-serialize-scsi_id-access-with-flock.patch --]
[-- Type: text/plain, Size: 1341 bytes --]
From ec3abdfd0b2e4f596c4cc988d5b7e6714cdb264e Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Wed, 11 Jun 2008 11:42:00 +0200
Subject: [PATCH] serialize scsi_id access with flock
---
| 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
--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 #2: S/MIME Cryptographic Signature --]
[-- Type: application/x-pkcs7-signature, Size: 3636 bytes --]
next reply other threads:[~2008-06-11 9:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-11 9:55 Harald Hoyer [this message]
2008-06-11 19:26 ` scsi_id - EBUSY and serialization Kay Sievers
2008-06-11 19:35 ` Harald Hoyer
2008-06-11 21:56 ` Kay Sievers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=484FA10E.9010303@redhat.com \
--to=harald@redhat.com \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).