summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatmans@us.ibm.com <patmans@us.ibm.com>2004-01-16 22:03:50 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:13:17 -0700
commite996d97835c8d0728a9d4880e9e1f8f285cadf4b (patch)
tree24d013eae9c4a84ee5cbaf3bb28d6270a0bd6cc7
parenteb7a964a7c66e5aff8147026a60c99258454b612 (diff)
[PATCH] update udev scsi_id to scsi_id 0.3
-rw-r--r--extras/scsi_id/ChangeLog39
-rw-r--r--extras/scsi_id/Makefile29
-rw-r--r--extras/scsi_id/README7
-rw-r--r--extras/scsi_id/TODO2
-rw-r--r--extras/scsi_id/release-notes39
-rw-r--r--extras/scsi_id/scsi_id.c57
-rw-r--r--extras/scsi_id/scsi_id.config7
-rw-r--r--extras/scsi_id/scsi_id.h21
-rw-r--r--extras/scsi_id/scsi_serial.c21
9 files changed, 147 insertions, 75 deletions
diff --git a/extras/scsi_id/ChangeLog b/extras/scsi_id/ChangeLog
index 7f2317723d..7032dfd07f 100644
--- a/extras/scsi_id/ChangeLog
+++ b/extras/scsi_id/ChangeLog
@@ -1,3 +1,36 @@
+2004-jan-15:
+ * Makefile: Version 0.3
+
+2004-jan-13:
+ * scsi_id.c, Makefile: Fix prefix usage with scsi_id.config.
+
+2004-jan-13:
+ * scsi_id.config: Clean up some comment entries.
+
+2004-jan-13:
+ * Makefile: Install the sample scsi_id.config file.
+
+2004-jan-13:
+ * Makefile: Use DESTDIR in all install/uninstall rules, per
+ problem reported by Svetoslav Slavtchev.
+
+2004-jan-12:
+ * scsi_id.h, scsi_id.c, scsi_serial.c: Fix to work with current
+ sysfs 0.4, based on patch from Dan Stekloff, but uses
+ sysfs_read_attribute_value instead of
+ sysfs_get_value_from_attributes.
+
+2004-jan-08:
+ * scsi_id.c: SYSFS_BUS_DIR was replaced with SYSFS_BUS_NAME.
+
+2004-jan-08:
+ * scsi_id.c: Must now use sysfs_open_class_device_path instead of the
+ previous sysfs_open_class_device.
+
+2003-dec-07:
+ * Makefile: patch from Olaf Hering <olh@suse.de> remove DEBUG and
+ add --fno-builtin
+
2003-dec-05:
* Makefile, scsi_id.8: Add a man page.
@@ -53,12 +86,12 @@
is no support for that in klibc.
2003-nov-17:
- * scsi_id.c: Patch from Brian King: check result of setting model,
- not vendor in per_dev_options.
+ * scsi_id.c: Patch from Brian King <brking@us.ibm.com>: check
+ result of setting model, not vendor in per_dev_options.
2003-nov-03:
* scsi_id.c, scsi_serial.c: Use new and correct path to libsysfs.h.
2003-nov-03:
- * scsi_id.h: Fix scsi_id.h so var args in marcros works ok with
+ * scsi_id.h: Fix scsi_id.h so var args in macros works ok with
older gcc.
diff --git a/extras/scsi_id/Makefile b/extras/scsi_id/Makefile
index ead205682a..abf48895ad 100644
--- a/extras/scsi_id/Makefile
+++ b/extras/scsi_id/Makefile
@@ -14,9 +14,10 @@
# 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.2
+SCSI_ID_VERSION=0.3
prefix =
+etcdir = ${prefix}/etc
sbindir = ${prefix}/sbin
mandir = ${prefix}/usr/share/man
@@ -27,7 +28,7 @@ INSTALL_DATA = ${INSTALL} -m 644
# Note some of the variables used here are set when built under udev, and
# otherwise might not be set.
-override CFLAGS+=-DSCSI_ID_VERSION=\"$(SCSI_ID_VERSION)\" $(DEBUG) -Wall
+override CFLAGS+=-Wall -fno-builtin
PROG=scsi_id
SYSFS=-lsysfs
@@ -39,25 +40,35 @@ SYSFS=-lsysfs
# LDFLAGS=$(STRIP)
LD=$(CC)
-OBJS= scsi_id.o \
- scsi_serial.o \
+OBJS= scsi_id.o scsi_serial.o
all: $(PROG)
# XXX use a compressed man page?
install: all
- $(INSTALL_PROGRAM) -D $(PROG) $(sbindir)/$(PROG)
+ $(INSTALL_PROGRAM) -D $(PROG) $(DESTDIR)$(sbindir)/$(PROG)
$(INSTALL_DATA) -D scsi_id.8 $(DESTDIR)$(mandir)/man8/scsi_id.8
+ @if [ ! -r $(DESTDIR)$(etcdir)/scsi_id.config ]; then \
+ echo $(INSTALL_DATA) -D ./scsi_id.config $(DESTDIR)$(etcdir); \
+ $(INSTALL_DATA) -D ./scsi_id.config $(DESTDIR)$(etcdir)/scsi_id.config; \
+ fi
uninstall:
- -rm $(sbindir)/$(PROG)
- -rm $(mandir)/man8/scsi_id.8
+ -rm $(DESTDIR)$(sbindir)/$(PROG)
+ -rm $(DESTDIR)$(mandir)/man8/scsi_id.8
+ -rm $(DESTDIR)$(etcdir)/scsi_id.config
-$(OBJS): scsi_id.h scsi.h
+GEN_HEADER=scsi_id_version.h
+
+scsi_id_version.h:
+ @echo "/* This file is auto-generated by the Makefile */" > $@
+ @echo \#define SCSI_ID_VERSION \"$(SCSI_ID_VERSION)\" >> $@
+ @echo \#define SCSI_ID_CONFIG_FILE \"$(etcdir)/scsi_id.config\" >> $@
+$(OBJS): scsi_id.h scsi.h scsi_id_version.h
clean:
- rm -f $(PROG) $(OBJS)
+ rm -f $(PROG) $(OBJS) $(GEN_HEADER)
$(PROG): $(OBJS)
$(LD) $(LDFLAGS) -o $(PROG) $(CRT0) $(OBJS) $(SYSFS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
diff --git a/extras/scsi_id/README b/extras/scsi_id/README
index 4281c318a2..97af517304 100644
--- a/extras/scsi_id/README
+++ b/extras/scsi_id/README
@@ -7,12 +7,7 @@ Requires:
- Linux kernel 2.6
- - libsysfs
-
-No man page yet.
-
-libsysfs 0_2_0 was not installing libsysfs.h or dlist.h, manually copy
-those files to /usr/include/sys before compiling.
+ - sysfsutils 0.4
Build via make and make install.
diff --git a/extras/scsi_id/TODO b/extras/scsi_id/TODO
index 5d020c276a..dde5c84a67 100644
--- a/extras/scsi_id/TODO
+++ b/extras/scsi_id/TODO
@@ -1,4 +1,4 @@
-- add information abou the config file to the man page
+- add information about the config file to the man page
- change so non-KLIBC builds under udev don't use /usr/include/sysfs,
but instead use the sysfs included with udev (needs udev change and/or
diff --git a/extras/scsi_id/release-notes b/extras/scsi_id/release-notes
new file mode 100644
index 0000000000..7ef12a25db
--- /dev/null
+++ b/extras/scsi_id/release-notes
@@ -0,0 +1,39 @@
+Version 0.3 of scsi_id is available at:
+
+http://www-124.ibm.com/storageio/scsi_id/scsi_id-0.3.tar.gz
+
+scsi_id is a program to generate a SCSI unique identifier for a given SCSI
+device.
+
+It is primarily for use with udev callout config entries. It can also be
+used for automatic multi-path configuration or device mapper configuration.
+
+Version 0.3 requires:
+
+- Linux kernel 2.6
+- libsysfs 0.4.0
+
+Major changes since the last release:
+
+ - Changes to work with libsysfs 0.4.0
+
+All changes:
+
+ - fix "prefix" usage for path to scsi_id.config
+
+ - install the sample scsi_id.config file.
+
+ - Use DESTDIR in all install/uninstall rules, per problem reported
+ by Svetoslav Slavtchev.
+
+ - Fix to work with current sysfs 0.4, based on patch from Dan
+ Stekloff, but uses sysfs_read_attribute_value instead of
+ sysfs_get_value_from_attributes.
+
+ - SYSFS_BUS_DIR was replaced with SYSFS_BUS_NAME.
+
+ - Must now use sysfs_open_class_device_path instead of the
+ previous sysfs_open_class_device.
+
+ - patch from Olaf Hering <olh@suse.de> remove DEBUG and
+ add --fno-builtin
diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c
index 6bb41132de..75a342bb12 100644
--- a/extras/scsi_id/scsi_id.c
+++ b/extras/scsi_id/scsi_id.c
@@ -40,6 +40,7 @@
#else
#include <sysfs/libsysfs.h>
#endif
+#include "scsi_id_version.h"
#include "scsi_id.h"
#ifndef SCSI_ID_VERSION
@@ -53,8 +54,6 @@
#define TMP_DIR "/tmp"
#define TMP_PREFIX "scsi"
-#define CONFIG_FILE "/etc/scsi_id.config"
-
static const char short_options[] = "bc:d:ef:gip:s:vV";
/*
* Just duplicate per dev options.
@@ -67,7 +66,7 @@ static int all_good;
static char *default_callout;
static int dev_specified;
static int sys_specified;
-static char config_file[MAX_NAME_LEN] = CONFIG_FILE;
+static char config_file[MAX_NAME_LEN] = SCSI_ID_CONFIG_FILE;
static int display_bus_id;
static int default_page_code;
static int use_stderr;
@@ -102,6 +101,18 @@ void log_message (int level, const char *format, ...)
return;
}
+int sysfs_get_attr(const char *devpath, const char *attr, char *value,
+ size_t bufsize)
+{
+ char attr_path[SYSFS_PATH_MAX];
+
+ strncpy(attr_path, devpath, SYSFS_PATH_MAX);
+ strncat(attr_path, "/", SYSFS_PATH_MAX);
+ strncat(attr_path, attr, SYSFS_PATH_MAX);
+ dprintf("%s\n", attr_path);
+ return sysfs_read_attribute_value(attr_path, value, SYSFS_NAME_LEN);
+}
+
static int sysfs_get_actual_dev(const char *sysfs_path, char *dev, int len)
{
dprintf("%s\n", sysfs_path);
@@ -153,34 +164,22 @@ static int sysfs_is_bus(const char *sysfs_path, const char *bus)
static int get_major_minor(const char *devpath, int *major, int *minor)
{
- struct sysfs_class_device *class_dev;
- char dev_value[SYSFS_NAME_LEN];
- char *dev;
-
- dprintf("%s\n", devpath);
- class_dev = sysfs_open_class_device_path(devpath);
- if (!class_dev) {
- log_message(LOG_WARNING, "open class %s failed: %s\n", devpath,
- strerror(errno));
- return -1;
- }
+ char dev_value[MAX_ATTR_LEN];
- dev = sysfs_get_attr(class_dev, "dev");
- if (dev)
- strncpy(dev_value, dev, SYSFS_NAME_LEN);
- sysfs_close_class_device(class_dev);
- if (!dev) {
+ if (sysfs_get_attr(devpath, "dev", dev_value, MAX_ATTR_LEN)) {
/*
* XXX This happens a lot, since sg has no dev attr.
- * Someday change this back to a LOG_WARNING.
+ * And now sysfsutils does not set a meaningful errno
+ * value. Someday change this back to a LOG_WARNING.
+ * And if sysfsutils changes, check for ENOENT and handle
+ * it separately.
*/
log_message(LOG_DEBUG, "%s could not get dev attribute: %s\n",
devpath, strerror(errno));
return -1;
}
- dev = NULL;
- dprintf("dev %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) {
log_message(LOG_WARNING, "%s: invalid dev major/minor\n",
devpath);
@@ -547,8 +546,8 @@ static int per_dev_options(struct sysfs_class_device *scsi_dev, int *good_bad,
int retval;
int newargc;
char **newargv = NULL;
- char *vendor;
- char *model;
+ char vendor[MAX_ATTR_LEN];
+ char model[MAX_ATTR_LEN];
int option;
*good_bad = all_good;
@@ -558,16 +557,14 @@ static int per_dev_options(struct sysfs_class_device *scsi_dev, int *good_bad,
else
callout[0] = '\0';
- vendor = sysfs_get_attr(scsi_dev, "vendor");
- if (!vendor) {
- log_message(LOG_WARNING, "%s: no vendor attribute\n",
+ if (sysfs_get_attr(scsi_dev->path, "vendor", vendor, MAX_ATTR_LEN)) {
+ log_message(LOG_WARNING, "%s: cannot get vendor attribute\n",
scsi_dev->name);
return -1;
}
- model = sysfs_get_attr(scsi_dev, "model");
- if (!model) {
- log_message(LOG_WARNING, "%s: no model attribute\n",
+ if (sysfs_get_attr(scsi_dev->path, "model", model, MAX_ATTR_LEN)) {
+ log_message(LOG_WARNING, "%s: cannot get model attribute\n",
scsi_dev->name);
return -1;
}
diff --git a/extras/scsi_id/scsi_id.config b/extras/scsi_id/scsi_id.config
index 4fdb89e28a..f3fc4b3fda 100644
--- a/extras/scsi_id/scsi_id.config
+++ b/extras/scsi_id/scsi_id.config
@@ -21,7 +21,9 @@
# vendor=string[,model=string],options=<per-device scsi_id options>
#
-# If you normally don't need id's, black list everyone:
+# If you normally don't need scsi id's, or might be attaching devices of
+# an unknown functionality, black list everyone. This is the default
+# behaviour (if no -b or -g is specified).
#
options=-b
@@ -30,7 +32,8 @@ options=-b
#
vendor=someone, model=nicedrive, options=-g
-# If you have all good devices on your system use, mark all as good:
+# If you all the scsi devices are your system support valid id's, remove
+# the -b line above, and mark all devices as good:
## options=-g
diff --git a/extras/scsi_id/scsi_id.h b/extras/scsi_id/scsi_id.h
index cb27e88a5f..573a2b60d7 100644
--- a/extras/scsi_id/scsi_id.h
+++ b/extras/scsi_id/scsi_id.h
@@ -28,6 +28,12 @@
#define OFFSET (2 * sizeof(unsigned int))
/*
+ * MAX_ATTR_LEN: maximum length of the result of reading a sysfs
+ * attribute.
+ */
+#define MAX_ATTR_LEN 256
+
+/*
* MAX_SERIAL_LEN: the maximum length of the serial number, including
* added prefixes such as vendor and product (model) strings.
*/
@@ -39,19 +45,8 @@
*/
#define MAX_BUFFER_LEN 256
-static inline char *sysfs_get_attr(struct sysfs_class_device *dev,
- const char *attr)
-{
- struct dlist *attributes = NULL;
-
- attributes = sysfs_get_classdev_attributes(dev);
-
- if (attributes == NULL)
- return NULL;
-
- return sysfs_get_value_from_attributes(attributes, attr);
-}
-
+extern int sysfs_get_attr(const char *devpath, const char *attr, char *value,
+ size_t bufsize);
extern int scsi_get_serial (struct sysfs_class_device *scsi_dev,
const char *devname, int page_code, char *serial,
int len);
diff --git a/extras/scsi_id/scsi_serial.c b/extras/scsi_id/scsi_serial.c
index 18cd290817..80a1d51635 100644
--- a/extras/scsi_id/scsi_serial.c
+++ b/extras/scsi_id/scsi_serial.c
@@ -385,7 +385,7 @@ static int do_scsi_page0_inquiry(struct sysfs_class_device *scsi_dev, int fd,
char *buffer, int len)
{
int retval;
- char *vendor;
+ char vendor[MAX_ATTR_LEN];
memset(buffer, 0, len);
retval = scsi_inquiry(scsi_dev, fd, 1, 0x0, buffer, len);
@@ -415,9 +415,10 @@ static int do_scsi_page0_inquiry(struct sysfs_class_device *scsi_dev, int fd,
* If the vendor id appears in the page assume the page is
* invalid.
*/
- vendor = sysfs_get_attr(scsi_dev, "vendor");
- if (!vendor) {
- log_message(LOG_WARNING, "%s: no vendor attribute\n",
+ if (sysfs_get_attr(scsi_dev->path, "vendor", vendor,
+ MAX_ATTR_LEN)) {
+ log_message(LOG_WARNING,
+ "%s: cannot get model attribute\n",
scsi_dev->name);
return 1;
}
@@ -437,12 +438,11 @@ static int do_scsi_page0_inquiry(struct sysfs_class_device *scsi_dev, int fd,
static int prepend_vendor_model(struct sysfs_class_device *scsi_dev,
char *serial)
{
- char *attr;
+ char attr[MAX_ATTR_LEN];
int ind;
- attr = sysfs_get_attr(scsi_dev, "vendor");
- if (!attr) {
- log_message(LOG_WARNING, "%s: no vendor attribute\n",
+ if (sysfs_get_attr(scsi_dev->path, "vendor", attr, MAX_ATTR_LEN)) {
+ log_message(LOG_WARNING, "%s: cannot get vendor attribute\n",
scsi_dev->name);
return 1;
}
@@ -454,9 +454,8 @@ static int prepend_vendor_model(struct sysfs_class_device *scsi_dev,
if (serial[ind] == '\n')
serial[ind] = '\0';
- attr = sysfs_get_attr(scsi_dev, "model");
- if (!attr) {
- log_message(LOG_WARNING, "%s: no model attribute\n",
+ if (sysfs_get_attr(scsi_dev->path, "model", attr, MAX_ATTR_LEN)) {
+ log_message(LOG_WARNING, "%s: cannot get model attribute\n",
scsi_dev->name);
return 1;
}