1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-10-30 14:55:26 +03:00

[PATCH] update udev scsi_id to scsi_id 0.5

This patch syncs the scsi_id in the udev tree to version 0.5.
This commit is contained in:
patmans@us.ibm.com 2004-06-26 01:18:17 -07:00 committed by Greg KH
parent c59a72105d
commit 062db23d5e
10 changed files with 119 additions and 83 deletions

View File

@ -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: 2004-feb-25:
* scsi_id.8: Add verbage about usage with udev, and running via * scsi_id.8: Add verbage about usage with udev, and running via
hotplug. hotplug.

View File

@ -14,7 +14,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
SCSI_ID_VERSION=0.4 SCSI_ID_VERSION=0.5
prefix = prefix =
etcdir = ${prefix}/etc etcdir = ${prefix}/etc
@ -71,5 +71,6 @@ clean:
rm -f $(PROG) $(OBJS) $(GEN_HEADER) rm -f $(PROG) $(OBJS) $(GEN_HEADER)
spotless: clean spotless: clean
$(PROG): $(OBJS) $(PROG): $(OBJS)
$(LD) $(LDFLAGS) -o $(PROG) $(CRT0) $(OBJS) $(SYSFS) $(LIB_OBJS) $(ARCH_LIB_OBJS) $(LD) $(LDFLAGS) -o $(PROG) $(CRT0) $(OBJS) $(SYSFS) $(LIB_OBJS) $(ARCH_LIB_OBJS)

View File

@ -1,6 +1,9 @@
- Document that config file options override command line options, or fix - Add an option to replace blanks with spaces, so the generated id can be
the code. This means a '-b' in the config file disables any -g on the more easily used as a /dev name.
command line.
- 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 - Add code to check that SCSI commands get back enough data for their
intended usage, mainly callers of scsi_inquiry(). intended usage, mainly callers of scsi_inquiry().

View File

@ -27,22 +27,12 @@
prefix=disk- prefix=disk-
scsi_id=/sbin/scsi_id 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}') 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) c=$(ls /${sysfs_dir}/block/sd* 2>/dev/null | wc -l)
if [ $c = 0 ] 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 "# rules to your liking."
echo "#" echo "#"
first_line=yes first_line=yes
dump_ids | while read in
#
cd ${sysfs_dir}/block
for name in sd*
do do
set $in id=$($scsi_id -s /block/$name)
name=$1 if [ $? != 0 ]
shift then
id="$*" echo $0 failed for device $name exiting >&2
exit 1
fi
if [ $first_line = "yes" ] if [ $first_line = "yes" ]
then then
first_line=no first_line=no

View File

@ -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 scsi_id is a program to generate a unique identifier for a given SCSI
device. device.
It is primarily for use with the udev callout key. It could also be used It is primarily for use with the udev program key, or hotplug scripts that
for automatic multi-path configuration or device mapper configuration. 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 - Linux kernel 2.6
- libsysfs 0.4.0 - libsysfs 0.4.0
Major changes since the last release: 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 - Fix the gen_scsi_id_udev_rules.sh to handle spaces in the id.
installed but is part of the tarball.
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 - Include compiler.h so we can build against klibc, as recent sg.h
hotplug changes need a define for __user.
- Disable support for -e (all output to stderr) as it cannot be Other changes:
used in any useful way, and the -c (device specific callout) as
the code is incomplete and has no users.
- 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 - Add spotless target (via Olaf Hering's udev patch)
bus.
- ":" 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. - Escape '-' with '\-' in the man page.
- 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.

View File

@ -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 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 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 \fBscsi_id\fP is primarily for use by other utilities such as \fBudev\fP
that require a unique SCSI identifier. 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 be specified on the command line or in the config file for any useful
behaviour. 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. corresponding sysfs device. See section below on usage with \fBudev\fP.
.TP .TP
.BI \-b .BI \-b
The default behaviour - treat the device as black listed, and do nothing 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. unless a white listed device is found in the scsi_id config\-file.
.TP .TP
.BI \-d "\| device\^" .BI \-d "\| device\^"
Instead Instead
of determining and creating a device node based on a sysfs dev 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. \fBdevice\fP, such as \fB/dev/sdc\fP.
.TP .TP
.BI \-f "\| config-file" .BI \-f "\| config\-file"
Read configuration and black/white list entries from Read configuration and black/white list entries from
.B config-file .B config\-file
rather than the default rather than the default
.B /etc/scsi_id.config .B /etc/scsi_id.config
file. 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 query the available VPD pages, and use page 0x83 if found, else page 0x80
if found, else nothing. if found, else nothing.
.TP .TP
.BI \-s "\| sysfs-device" .BI \-s "\| sysfs\-device"
Generate an id for the Generate an id for the
.B sysfs-device. .B sysfs\-device.
The sysfs mount point must not be included. For example, use /block/sd, The sysfs mount point must not be included. For example, use /block/sd,
not /sys/block/sd. not /sys/block/sd.
.TP .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. 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: for example:
.sp .sp

View File

@ -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); 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]; 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 */ 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", log_message(LOG_WARNING, "%s: invalid dev major/minor\n",
devpath); devpath);
return -1; 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) static int create_tmp_dev(const char *devpath, char *tmpdev, int dev_type)
{ {
int major, minor; int maj, min;
dprintf("(%s)\n", devpath); dprintf("(%s)\n", devpath);
if (get_major_minor(devpath, &major, &minor)) if (get_major_minor(devpath, &maj, &min))
return -1; return -1;
snprintf(tmpdev, MAX_NAME_LEN, "%s/%s-maj%d-min%d-%u", 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); 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)); log_message(LOG_WARNING, "mknod failed: %s\n", strerror(errno));
return -1; return -1;
} }
@ -759,10 +759,6 @@ int main(int argc, char **argv)
strncpy(target_path, sysfs_mnt_path, MAX_NAME_LEN); strncpy(target_path, sysfs_mnt_path, MAX_NAME_LEN);
strncat(target_path, devpath, 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); exit(1);
free(newargv); free(newargv);
} }
if (!hotplug_mode) {
if (set_options(argc, argv, short_options, target_path,
maj_min_dev) < 0)
exit(1);
}
if (!sys_specified) { if (!sys_specified) {
log_message(LOG_WARNING, "-s must be specified\n"); log_message(LOG_WARNING, "-s must be specified\n");

View File

@ -9,12 +9,12 @@
# INQUIRY product identification field. Per the SCSI INQUIRY, the vendor # INQUIRY product identification field. Per the SCSI INQUIRY, the vendor
# is limited to 8 bytes, model to 16 bytes. # 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 # if you do not want such a match space fill the extra bytes. If no model
# is specified, only the vendor string need match. # is specified, only the vendor string need match.
# #
# The "option" line is searched when scsi_id first starts up (for use with # The "options" line is searched for when scsi_id starts up, and is
# hotplug during boot). # primarily for use with hotplug.
# #
# options=<any scsi_id command line options> # options=<any scsi_id command line options>
# #
@ -32,12 +32,12 @@ options=-b
# #
vendor=someone, model=nicedrive, options=-g vendor=someone, model=nicedrive, options=-g
# If you all the scsi devices are your system support valid id's, remove # If you know all the scsi devices on your system support valid id's,
# the -b line above, and mark all devices as good: # remove the options=-b line, and mark all devices as good:
## options=-g ## options=-g
# Then black list any offenders. Missing entries here could be dangerous # 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 ## vendor=ELBONIA, model=borken, options=-b

View File

@ -37,7 +37,7 @@
* MAX_SERIAL_LEN: the maximum length of the serial number, including * MAX_SERIAL_LEN: the maximum length of the serial number, including
* added prefixes such as vendor and product (model) strings. * 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 * 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, ...) extern void log_message (int level, const char *format, ...)
__attribute__ ((format (printf, 2, 3))); __attribute__ ((format (printf, 2, 3)));
#ifdef __KLIBC__
#define makedev(major, minor) ((major) << 8) | (minor)
#endif
#ifndef u8 #ifndef u8
typedef unsigned char u8; typedef unsigned char u8;
#endif #endif

View File

@ -30,6 +30,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <syslog.h> #include <syslog.h>
#include <linux/compiler.h> /* need __user when built via klibc */
#include <scsi/sg.h> #include <scsi/sg.h>
#include <sysfs/libsysfs.h> #include <sysfs/libsysfs.h>
#include "scsi_id.h" #include "scsi_id.h"
@ -312,6 +313,8 @@ static int scsi_inquiry(struct sysfs_device *scsi_dev, int fd, unsigned
buffer = inq + OFFSET; buffer = inq + OFFSET;
resend: resend:
dprintf("%s evpd %d, page 0x%x\n", scsi_dev->name, evpd, page);
memset(&io_hdr, 0, sizeof(struct sg_io_hdr)); memset(&io_hdr, 0, sizeof(struct sg_io_hdr));
io_hdr.interface_id = 'S'; io_hdr.interface_id = 'S';
io_hdr.cmd_len = sizeof(inq_cmd); io_hdr.cmd_len = sizeof(inq_cmd);
@ -352,6 +355,11 @@ resend:
retval = -1; 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); free(inq);
return retval; return retval;
} }