summaryrefslogtreecommitdiff
path: root/extras/scsi_id
diff options
context:
space:
mode:
authorpatmans@us.ibm.com <patmans@us.ibm.com>2004-06-26 01:18:17 -0700
committerGreg KH <gregkh@suse.de>2005-04-26 21:36:21 -0700
commit062db23d5eb303ef49d2ff805381229932f44246 (patch)
treefa4bec0bad640e27afce8f676c0647476fd31348 /extras/scsi_id
parentc59a72105d0ff8a47b31f1829dd3c166ebd859d0 (diff)
[PATCH] update udev scsi_id to scsi_id 0.5
This patch syncs the scsi_id in the udev tree to version 0.5.
Diffstat (limited to 'extras/scsi_id')
-rw-r--r--extras/scsi_id/ChangeLog39
-rw-r--r--extras/scsi_id/Makefile3
-rw-r--r--extras/scsi_id/TODO9
-rw-r--r--extras/scsi_id/gen_scsi_id_udev_rules.sh35
-rw-r--r--extras/scsi_id/release-notes49
-rw-r--r--extras/scsi_id/scsi_id.820
-rw-r--r--extras/scsi_id/scsi_id.c21
-rw-r--r--extras/scsi_id/scsi_id.config12
-rw-r--r--extras/scsi_id/scsi_id.h6
-rw-r--r--extras/scsi_id/scsi_serial.c8
10 files changed, 119 insertions, 83 deletions
diff --git a/extras/scsi_id/ChangeLog b/extras/scsi_id/ChangeLog
index 095d84f2d0..bfa353431b 100644
--- a/extras/scsi_id/ChangeLog
+++ b/extras/scsi_id/ChangeLog
@@ -1,3 +1,42 @@
+2004-jun-23:
+ * scsi_id.h: increase MAX_SERIAL_LEN from 128 to 256, as some
+ devices (maybe broken ones) are giving really long id's.
+
+2004-jun-17:
+ * Makefile: Olaf Hering add spotless target (already in udev).
+
+2004-jun-17:
+ * scsi_serial.c: Include linux/compiler.h so we can build with
+ klibc using kernel headers.
+
+2004-may-24:
+ * scsi_id.c: Rename major and minor to maj min to avoid compiler
+ warnings when compiled with -D_GNU_SOURCE.
+
+2004-mar-30:
+ * scsi_id.config: Minor wording changes
+
+2004-mar-30:
+ * scsi_id.h: Don't supply a makedev() when built under klibc.
+
+2004-mar-30:
+ * scsi_id.c: Ken Brush <ken@cgi101.com> Have the command line
+ options override generic options.
+
+2004-mar-05:
+ * scsi_serial.c: Log INQUIRY failure, including the
+ failing page code and vpd values. And add a dprintf() to
+ the scsi_inquiry function.
+
+2004-mar-02:
+ * gen_scsi_id_udev_rules.sh: Per bug report from Atul Sabharwal
+ <atul.sabharwal@intel.com> change to not require that sysfs be
+ in the mount tab (and default to "/sys"), and fix so scsi_id
+ results containing spaces work correctly.
+
+2004-mar-02:
+ * scsi_id.8: Escape '-' with '\-'.
+
2004-feb-25:
* scsi_id.8: Add verbage about usage with udev, and running via
hotplug.
diff --git a/extras/scsi_id/Makefile b/extras/scsi_id/Makefile
index 6af4d7f18e..8fe29f3647 100644
--- a/extras/scsi_id/Makefile
+++ b/extras/scsi_id/Makefile
@@ -14,7 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-SCSI_ID_VERSION=0.4
+SCSI_ID_VERSION=0.5
prefix =
etcdir = ${prefix}/etc
@@ -71,5 +71,6 @@ clean:
rm -f $(PROG) $(OBJS) $(GEN_HEADER)
spotless: clean
+
$(PROG): $(OBJS)
$(LD) $(LDFLAGS) -o $(PROG) $(CRT0) $(OBJS) $(SYSFS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
diff --git a/extras/scsi_id/TODO b/extras/scsi_id/TODO
index 4f302ea0a4..e0283cf444 100644
--- a/extras/scsi_id/TODO
+++ b/extras/scsi_id/TODO
@@ -1,6 +1,9 @@
-- Document that config file options override command line options, or fix
- the code. This means a '-b' in the config file disables any -g on the
- command line.
+- Add an option to replace blanks with spaces, so the generated id can be
+ more easily used as a /dev name.
+
+- Add a bus white/black list option. So for example, all scsi devices
+ under USB could easily be blacklisted. This should allow multiple busses
+ to be listed.
- Add code to check that SCSI commands get back enough data for their
intended usage, mainly callers of scsi_inquiry().
diff --git a/extras/scsi_id/gen_scsi_id_udev_rules.sh b/extras/scsi_id/gen_scsi_id_udev_rules.sh
index 07e21ebd50..874e94e8bb 100644
--- a/extras/scsi_id/gen_scsi_id_udev_rules.sh
+++ b/extras/scsi_id/gen_scsi_id_udev_rules.sh
@@ -27,22 +27,12 @@
prefix=disk-
scsi_id=/sbin/scsi_id
-dump_ids()
-{
- cd ${sysfs_dir}/block
- for b in sd*
- do
- echo -n "$b "
- $scsi_id -s /block/$b
- if [ $? != 0 ]
- then
- echo $0 failed for device $b >&2
- exit 1
- fi
- done
-}
-
sysfs_dir=$(mount | awk '$5 == "sysfs" {print $3}')
+if [ "$sysfs_dir" = "" ]
+then
+ sysfs_dir="/sys"
+ echo "Using sysfs mount point \"$sysfs_dir\"" >&2
+fi
c=$(ls /${sysfs_dir}/block/sd* 2>/dev/null | wc -l)
if [ $c = 0 ]
@@ -56,12 +46,17 @@ echo "# Start of autogenerated scsi_id rules. Edit the NAME portions of these"
echo "# rules to your liking."
echo "#"
first_line=yes
-dump_ids | while read in
+
+#
+cd ${sysfs_dir}/block
+for name in sd*
do
- set $in
- name=$1
- shift
- id="$*"
+ id=$($scsi_id -s /block/$name)
+ if [ $? != 0 ]
+ then
+ echo $0 failed for device $name exiting >&2
+ exit 1
+ fi
if [ $first_line = "yes" ]
then
first_line=no
diff --git a/extras/scsi_id/release-notes b/extras/scsi_id/release-notes
index a10b569c2d..2996713117 100644
--- a/extras/scsi_id/release-notes
+++ b/extras/scsi_id/release-notes
@@ -1,49 +1,42 @@
-Version 0.4 of scsi_id is available at:
+Version 0.5 of scsi_id is available at:
-http://www-124.ibm.com/storageio/scsi_id/scsi_id-0.4.tar.gz
+http://www-124.ibm.com/storageio/scsi_id/scsi_id-0.5.tar.gz
scsi_id is a program to generate a unique identifier for a given SCSI
device.
-It is primarily for use with the udev callout key. It could also be used
-for automatic multi-path configuration or device mapper configuration.
+It is primarily for use with the udev program key, or hotplug scripts that
+want persistent naming of scsi devices. It could also be used for
+automatic multi-path configuration or device mapper configuration.
-Version 0.4 requires:
+Version 0.5 requires:
- Linux kernel 2.6
- libsysfs 0.4.0
Major changes since the last release:
- - Support block device partitions
+ - Ken Brush <ken@cgi101.com> have the command line options
+ override generic options.
- - Added a script to auto-generate udev rules. The script is not
- installed but is part of the tarball.
+ - Fix the gen_scsi_id_udev_rules.sh to handle spaces in the id.
-Detailed changes:
+ - Don't supply a makedev() when built with klibc. Also, the
+ scsi_id supplied makedev() was using the old major/minor method.
- - Add man page verbage about usage with udev, and running via
- hotplug
+ - Include compiler.h so we can build against klibc, as recent sg.h
+ changes need a define for __user.
- - Disable support for -e (all output to stderr) as it cannot be
- used in any useful way, and the -c (device specific callout) as
- the code is incomplete and has no users.
+Other changes:
- - Don't print errno for NULL return from sysfs_get_classdev_device.
+ - Increase the MAX_SERIAL_LEN from 128 to 256, as some (possibly
+ broken devics) are returning very long id's
- - Get rid of dead/leftover code that checked if we are on a scsi
- bus.
+ - Add spotless target (via Olaf Hering's udev patch)
- - ":" consistently in output messages.
+ - minor wording changes in scsi_id.config
- - Add missing new lines for some error messages.
+ - Log INQUIRY failure, including the failing page code and vpd
+ values
- - open O_NONBLOCK so we handle tape drives without tapes loaded.
-
- - Remove hacks based on KLIBC define to get around problems when
- building with udev (udev libsysfs files were rearranged).
-
- - As done in udev code, support partitions via looking for a
- parent of the target path. Uses libsysfs functions to do most of
- the work, and includes changing a lot of variables to be struct
- sysfs_device instead of sysfs_class_device.
+ - Escape '-' with '\-' in the man page.
diff --git a/extras/scsi_id/scsi_id.8 b/extras/scsi_id/scsi_id.8
index db3effbc45..69dd2a998a 100644
--- a/extras/scsi_id/scsi_id.8
+++ b/extras/scsi_id/scsi_id.8
@@ -12,12 +12,12 @@ all SCSI devices that properly support page 0x80 or page 0x83.
If a result is generated it is sent to standard output, and the program
exits with a zero value. If no identifier is output, the program exits
-with a non-zero value.
+with a non\-zero value.
\fBscsi_id\fP is primarily for use by other utilities such as \fBudev\fP
that require a unique SCSI identifier.
-By default all devices are assume black listed, the \fB-g\fP option must
+By default all devices are assume black listed, the \fB\-g\fP option must
be specified on the command line or in the config file for any useful
behaviour.
@@ -58,18 +58,18 @@ mode, and expects the environment variable DEVPATH to specify the
corresponding sysfs device. See section below on usage with \fBudev\fP.
.TP
.BI \-b
-The default behaviour - treat the device as black listed, and do nothing
-unless a white listed device is found in the scsi_id config-file.
+The default behaviour \- treat the device as black listed, and do nothing
+unless a white listed device is found in the scsi_id config\-file.
.TP
.BI \-d "\| device\^"
Instead
of determining and creating a device node based on a sysfs dev
-entry as done for the \fB-s\fP, send SG_IO commands to
+entry as done for the \fB\-s\fP, send SG_IO commands to
\fBdevice\fP, such as \fB/dev/sdc\fP.
.TP
-.BI \-f "\| config-file"
+.BI \-f "\| config\-file"
Read configuration and black/white list entries from
-.B config-file
+.B config\-file
rather than the default
.B /etc/scsi_id.config
file.
@@ -89,9 +89,9 @@ Use SCSI INQUIRY VPD page code 0x80 or 0x83. The default behaviour is to
query the available VPD pages, and use page 0x83 if found, else page 0x80
if found, else nothing.
.TP
-.BI \-s "\| sysfs-device"
+.BI \-s "\| sysfs\-device"
Generate an id for the
-.B sysfs-device.
+.B sysfs\-device.
The sysfs mount point must not be included. For example, use /block/sd,
not /sys/block/sd.
.TP
@@ -113,7 +113,7 @@ and the results will likely not be as expected.
When in this mode, all errors and warnings are sent via syslog.
-To determine the specific value needed in a RESULT key, use the -s option,
+To determine the specific value needed in a RESULT key, use the \-s option,
for example:
.sp
diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c
index 1cd6981e5e..e893987868 100644
--- a/extras/scsi_id/scsi_id.c
+++ b/extras/scsi_id/scsi_id.c
@@ -111,7 +111,7 @@ int sysfs_get_attr(const char *devpath, const char *attr, char *value,
return sysfs_read_attribute_value(attr_path, value, SYSFS_NAME_LEN);
}
-static int get_major_minor(const char *devpath, int *major, int *minor)
+static int get_major_minor(const char *devpath, int *maj, int *min)
{
char dev_value[MAX_ATTR_LEN];
@@ -129,7 +129,7 @@ static int get_major_minor(const char *devpath, int *major, int *minor)
}
dprintf("dev value %s", dev_value); /* dev_value has a trailing \n */
- if (sscanf(dev_value, "%u:%u", major, minor) != 2) {
+ if (sscanf(dev_value, "%u:%u", maj, min) != 2) {
log_message(LOG_WARNING, "%s: invalid dev major/minor\n",
devpath);
return -1;
@@ -140,18 +140,18 @@ static int get_major_minor(const char *devpath, int *major, int *minor)
static int create_tmp_dev(const char *devpath, char *tmpdev, int dev_type)
{
- int major, minor;
+ int maj, min;
dprintf("(%s)\n", devpath);
- if (get_major_minor(devpath, &major, &minor))
+ if (get_major_minor(devpath, &maj, &min))
return -1;
snprintf(tmpdev, MAX_NAME_LEN, "%s/%s-maj%d-min%d-%u",
- TMP_DIR, TMP_PREFIX, major, minor, getpid());
+ TMP_DIR, TMP_PREFIX, maj, min, getpid());
dprintf("tmpdev '%s'\n", tmpdev);
- if (mknod(tmpdev, 0600 | dev_type, makedev(major, minor))) {
+ if (mknod(tmpdev, 0600 | dev_type, makedev(maj, min))) {
log_message(LOG_WARNING, "mknod failed: %s\n", strerror(errno));
return -1;
}
@@ -759,10 +759,6 @@ int main(int argc, char **argv)
strncpy(target_path, sysfs_mnt_path, MAX_NAME_LEN);
strncat(target_path, devpath, MAX_NAME_LEN);
- } else {
- if (set_options(argc, argv, short_options, target_path,
- maj_min_dev) < 0)
- exit(1);
}
/*
@@ -779,6 +775,11 @@ int main(int argc, char **argv)
exit(1);
free(newargv);
}
+ if (!hotplug_mode) {
+ if (set_options(argc, argv, short_options, target_path,
+ maj_min_dev) < 0)
+ exit(1);
+ }
if (!sys_specified) {
log_message(LOG_WARNING, "-s must be specified\n");
diff --git a/extras/scsi_id/scsi_id.config b/extras/scsi_id/scsi_id.config
index f3fc4b3fda..0567ecb7d6 100644
--- a/extras/scsi_id/scsi_id.config
+++ b/extras/scsi_id/scsi_id.config
@@ -9,12 +9,12 @@
# INQUIRY product identification field. Per the SCSI INQUIRY, the vendor
# is limited to 8 bytes, model to 16 bytes.
#
-# The first maching line found is used. Short matches match longer ones,
+# The first matching line found is used. Short matches match longer ones,
# if you do not want such a match space fill the extra bytes. If no model
# is specified, only the vendor string need match.
#
-# The "option" line is searched when scsi_id first starts up (for use with
-# hotplug during boot).
+# The "options" line is searched for when scsi_id starts up, and is
+# primarily for use with hotplug.
#
# options=<any scsi_id command line options>
#
@@ -32,12 +32,12 @@ options=-b
#
vendor=someone, model=nicedrive, options=-g
-# If you all the scsi devices are your system support valid id's, remove
-# the -b line above, and mark all devices as good:
+# If you know all the scsi devices on your system support valid id's,
+# remove the options=-b line, and mark all devices as good:
## options=-g
# Then black list any offenders. Missing entries here could be dangerous
-# if you rely on the id for naming or multi-path configuration!
+# if you rely on the id for persistent naming or multi-path configuration.
## vendor=ELBONIA, model=borken, options=-b
diff --git a/extras/scsi_id/scsi_id.h b/extras/scsi_id/scsi_id.h
index 9edb39ec49..10599ebb5f 100644
--- a/extras/scsi_id/scsi_id.h
+++ b/extras/scsi_id/scsi_id.h
@@ -37,7 +37,7 @@
* MAX_SERIAL_LEN: the maximum length of the serial number, including
* added prefixes such as vendor and product (model) strings.
*/
-#define MAX_SERIAL_LEN 128
+#define MAX_SERIAL_LEN 256
/*
* MAX_BUFFER_LEN: maximum buffer size and line length used while reading
@@ -53,10 +53,6 @@ extern int scsi_get_serial (struct sysfs_device *scsi_dev, const char
extern void log_message (int level, const char *format, ...)
__attribute__ ((format (printf, 2, 3)));
-#ifdef __KLIBC__
-#define makedev(major, minor) ((major) << 8) | (minor)
-#endif
-
#ifndef u8
typedef unsigned char u8;
#endif
diff --git a/extras/scsi_id/scsi_serial.c b/extras/scsi_id/scsi_serial.c
index ae83330c30..e0074b662d 100644
--- a/extras/scsi_id/scsi_serial.c
+++ b/extras/scsi_id/scsi_serial.c
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
+#include <linux/compiler.h> /* need __user when built via klibc */
#include <scsi/sg.h>
#include <sysfs/libsysfs.h>
#include "scsi_id.h"
@@ -312,6 +313,8 @@ static int scsi_inquiry(struct sysfs_device *scsi_dev, int fd, unsigned
buffer = inq + OFFSET;
resend:
+ dprintf("%s evpd %d, page 0x%x\n", scsi_dev->name, evpd, page);
+
memset(&io_hdr, 0, sizeof(struct sg_io_hdr));
io_hdr.interface_id = 'S';
io_hdr.cmd_len = sizeof(inq_cmd);
@@ -352,6 +355,11 @@ resend:
retval = -1;
}
+ if (retval < 0)
+ log_message(LOG_WARNING,
+ "%s: Unable to get INQUIRY vpd %d page 0x%x.\n",
+ scsi_dev->name, evpd, page);
+
free(inq);
return retval;
}