2014-09-02 14:58:23 +02:00
|
|
|
From: Jeff Mahoney <jeffm@suse.com>
|
|
|
|
Subject: udev: add option to generate old 'buggy' serials
|
|
|
|
References: bnc#886852
|
|
|
|
|
|
|
|
Prior to udev 184, scsi_id would truncate the last character of the model
|
|
|
|
string when generating the ID_SERIAL value. If a system was installed
|
|
|
|
prior to that fix being available in udev, there may be configuration
|
|
|
|
information that refers to the truncated link.
|
|
|
|
|
|
|
|
This patch adds a --truncated-serial option and a udev rule will created
|
|
|
|
the old truncated links.
|
|
|
|
|
|
|
|
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
|
|
|
|
---
|
|
|
|
rules/60-persistent-storage.rules | 4 ++++
|
|
|
|
src/udev/scsi_id/scsi_id.c | 15 ++++++++++++++-
|
|
|
|
src/udev/scsi_id/scsi_id.h | 1 +
|
|
|
|
src/udev/scsi_id/scsi_serial.c | 19 +++++++++++++------
|
|
|
|
4 files changed, 32 insertions(+), 7 deletions(-)
|
|
|
|
|
2015-02-13 10:43:21 +01:00
|
|
|
Index: systemd-218/rules/60-persistent-storage.rules
|
|
|
|
===================================================================
|
|
|
|
--- systemd-218.orig/rules/60-persistent-storage.rules
|
|
|
|
+++ systemd-218/rules/60-persistent-storage.rules
|
2014-09-02 14:58:23 +02:00
|
|
|
@@ -46,6 +46,10 @@ KERNEL=="sd*|cciss*", ENV{DEVTYPE}=="par
|
|
|
|
KERNEL=="sd*[!0-9]", ENV{ID_BUS}=="ata", PROGRAM="scsi_id --whitelisted --replace-whitespace -p0x80 -d $devnode", RESULT=="?*", ENV{ID_SCSI_COMPAT}="$result", SYMLINK+="disk/by-id/scsi-$env{ID_SCSI_COMPAT}"
|
|
|
|
KERNEL=="sd*[0-9]", ENV{ID_SCSI_COMPAT}=="?*", SYMLINK+="disk/by-id/scsi-$env{ID_SCSI_COMPAT}-part%n"
|
|
|
|
|
|
|
|
+# scsi compat links for ATA devices (for compatibility with udev < 184)
|
|
|
|
+KERNEL=="sd*[!0-9]", ENV{ID_BUS}=="ata", PROGRAM="scsi_id --truncated-serial --whitelisted --replace-whitespace -p0x80 -d$tempnode", RESULT=="?*", ENV{ID_SCSI_COMPAT_TRUNCATED}="$result", SYMLINK+="disk/by-id/scsi-$env{ID_SCSI_COMPAT_TRUNCATED}"
|
|
|
|
+KERNEL=="sd*[0-9]", ENV{ID_SCSI_COMPAT_TRUNCATED}=="?*", SYMLINK+="disk/by-id/scsi-$env{ID_SCSI_COMPAT_TRUNCATED}-part%n"
|
|
|
|
+
|
|
|
|
# firewire
|
|
|
|
KERNEL=="sd*[!0-9]|sr*", ATTRS{ieee1394_id}=="?*", SYMLINK+="disk/by-id/ieee1394-$attr{ieee1394_id}"
|
|
|
|
KERNEL=="sd*[0-9]", ATTRS{ieee1394_id}=="?*", SYMLINK+="disk/by-id/ieee1394-$attr{ieee1394_id}-part%n"
|
2015-02-13 10:43:21 +01:00
|
|
|
Index: systemd-218/src/udev/scsi_id/scsi_id.c
|
|
|
|
===================================================================
|
|
|
|
--- systemd-218.orig/src/udev/scsi_id/scsi_id.c
|
|
|
|
+++ systemd-218/src/udev/scsi_id/scsi_id.c
|
|
|
|
@@ -43,6 +43,7 @@ static const struct option options[] = {
|
2014-09-02 14:58:23 +02:00
|
|
|
{ "replace-whitespace", no_argument, NULL, 'u' },
|
|
|
|
{ "sg-version", required_argument, NULL, 's' },
|
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
|
|
|
+ { "truncated-serial", no_argument, NULL, '9' },
|
|
|
|
{ "version", no_argument, NULL, 'V' }, /* don't advertise -V */
|
|
|
|
{ "export", no_argument, NULL, 'x' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2015-02-13 10:43:21 +01:00
|
|
|
@@ -54,6 +55,7 @@ static bool dev_specified = false;
|
|
|
|
static char config_file[MAX_PATH_LEN] = "/etc/scsi_id.config";
|
2014-09-02 14:58:23 +02:00
|
|
|
static enum page_code default_page_code = PAGE_UNSPECIFIED;
|
|
|
|
static int sg_version = 4;
|
|
|
|
+static bool compat_truncated = false;
|
|
|
|
static bool reformat_serial = false;
|
|
|
|
static bool export = false;
|
|
|
|
static char vendor_str[64];
|
2015-02-13 10:43:21 +01:00
|
|
|
@@ -313,6 +315,7 @@ static void help(void) {
|
|
|
|
" -g,--whitelisted treat device as whitelisted\n"
|
2014-09-02 14:58:23 +02:00
|
|
|
" -u,--replace-whitespace replace all whitespace by underscores\n"
|
|
|
|
" -v,--verbose verbose logging\n"
|
|
|
|
+ " --truncated-serial truncated serial for compatibility with systems configured with by-id links created by udev < 184\n"
|
|
|
|
" --version print version\n"
|
|
|
|
" -x,--export print values as environment keys\n"
|
|
|
|
" -h,--help print this help text\n\n");
|
2015-02-13 10:43:21 +01:00
|
|
|
@@ -385,6 +388,10 @@ static int set_options(struct udev *udev
|
|
|
|
log_open();
|
2014-09-02 14:58:23 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
+ case '9':
|
|
|
|
+ compat_truncated = true;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
case 'V':
|
|
|
|
printf("%s\n", VERSION);
|
|
|
|
exit(0);
|
2015-02-13 10:43:21 +01:00
|
|
|
@@ -526,6 +533,9 @@ static int scsi_id(struct udev *udev, ch
|
2014-09-02 14:58:23 +02:00
|
|
|
util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str));
|
|
|
|
util_replace_chars(serial_str, NULL);
|
|
|
|
printf("ID_SERIAL=%s\n", serial_str);
|
|
|
|
+ util_replace_whitespace(dev_scsi.serial_compat, serial_str, sizeof(serial_str));
|
|
|
|
+ util_replace_chars(serial_str, NULL);
|
|
|
|
+ printf("ID_SERIAL_COMPAT=%s\n", serial_str);
|
|
|
|
util_replace_whitespace(dev_scsi.serial_short, serial_str, sizeof(serial_str));
|
|
|
|
util_replace_chars(serial_str, NULL);
|
|
|
|
printf("ID_SERIAL_SHORT=%s\n", serial_str);
|
2015-02-13 10:43:21 +01:00
|
|
|
@@ -556,7 +566,10 @@ static int scsi_id(struct udev *udev, ch
|
2014-09-02 14:58:23 +02:00
|
|
|
if (reformat_serial) {
|
|
|
|
char serial_str[MAX_SERIAL_LEN];
|
|
|
|
|
|
|
|
- util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str));
|
|
|
|
+ if (compat_truncated)
|
|
|
|
+ util_replace_whitespace(dev_scsi.serial_compat, serial_str, sizeof(serial_str));
|
|
|
|
+ else
|
|
|
|
+ util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str));
|
|
|
|
util_replace_chars(serial_str, NULL);
|
|
|
|
printf("%s\n", serial_str);
|
|
|
|
goto out;
|
2015-02-13 10:43:21 +01:00
|
|
|
Index: systemd-218/src/udev/scsi_id/scsi_id.h
|
|
|
|
===================================================================
|
|
|
|
--- systemd-218.orig/src/udev/scsi_id/scsi_id.h
|
|
|
|
+++ systemd-218/src/udev/scsi_id/scsi_id.h
|
2014-09-02 14:58:23 +02:00
|
|
|
@@ -43,6 +43,7 @@ struct scsi_id_device {
|
|
|
|
char kernel[64];
|
|
|
|
char serial[MAX_SERIAL_LEN];
|
|
|
|
char serial_short[MAX_SERIAL_LEN];
|
|
|
|
+ char serial_compat[MAX_SERIAL_LEN];
|
|
|
|
int use_sg;
|
|
|
|
|
|
|
|
/* Always from page 0x80 e.g. 'B3G1P8500RWT' - may not be unique */
|
2015-02-13 10:43:21 +01:00
|
|
|
Index: systemd-218/src/udev/scsi_id/scsi_serial.c
|
|
|
|
===================================================================
|
|
|
|
--- systemd-218.orig/src/udev/scsi_id/scsi_serial.c
|
|
|
|
+++ systemd-218/src/udev/scsi_id/scsi_serial.c
|
|
|
|
@@ -96,7 +96,8 @@ static const char hex_str[]="0123456789a
|
2014-09-02 14:58:23 +02:00
|
|
|
|
|
|
|
static int do_scsi_page80_inquiry(struct udev *udev,
|
|
|
|
struct scsi_id_device *dev_scsi, int fd,
|
|
|
|
- char *serial, char *serial_short, int max_len);
|
|
|
|
+ char *serial, char *serial_short,
|
|
|
|
+ char *serial_compat, int max_len);
|
|
|
|
|
|
|
|
static int sg_err_category_new(struct udev *udev,
|
|
|
|
int scsi_status, int msg_status, int
|
2015-02-13 10:43:21 +01:00
|
|
|
@@ -619,7 +620,7 @@ static int do_scsi_page83_inquiry(struct
|
2014-09-02 14:58:23 +02:00
|
|
|
unsigned char page_83[SCSI_INQ_BUFF_LEN];
|
|
|
|
|
|
|
|
/* also pick up the page 80 serial number */
|
|
|
|
- do_scsi_page80_inquiry(udev, dev_scsi, fd, NULL, unit_serial_number, MAX_SERIAL_LEN);
|
|
|
|
+ do_scsi_page80_inquiry(udev, dev_scsi, fd, NULL, unit_serial_number, NULL, MAX_SERIAL_LEN);
|
|
|
|
|
|
|
|
memzero(page_83, SCSI_INQ_BUFF_LEN);
|
|
|
|
retval = scsi_inquiry(udev, dev_scsi, fd, 1, PAGE_83, page_83,
|
2015-02-13 10:43:21 +01:00
|
|
|
@@ -764,7 +765,8 @@ static int do_scsi_page83_prespc3_inquir
|
2014-09-02 14:58:23 +02:00
|
|
|
/* Get unit serial number VPD page */
|
|
|
|
static int do_scsi_page80_inquiry(struct udev *udev,
|
|
|
|
struct scsi_id_device *dev_scsi, int fd,
|
|
|
|
- char *serial, char *serial_short, int max_len)
|
|
|
|
+ char *serial, char *serial_short,
|
|
|
|
+ char *serial_compat, int max_len)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
int ser_ind;
|
2015-02-13 10:43:21 +01:00
|
|
|
@@ -798,9 +800,14 @@ static int do_scsi_page80_inquiry(struct
|
2014-09-02 14:58:23 +02:00
|
|
|
ser_ind = prepend_vendor_model(udev, dev_scsi, &serial[1]);
|
|
|
|
if (ser_ind < 0)
|
|
|
|
return 1;
|
|
|
|
+ if (serial_compat)
|
|
|
|
+ strcpy(serial_compat, serial);
|
|
|
|
ser_ind++; /* for the leading 'S' */
|
|
|
|
- for (i = 4; i < len + 4; i++, ser_ind++)
|
|
|
|
+ for (i = 4; i < len + 4; i++, ser_ind++) {
|
|
|
|
serial[ser_ind] = buf[i];
|
|
|
|
+ if (serial_compat)
|
|
|
|
+ serial_compat[ser_ind - 1] = buf[i];
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
if (serial_short != NULL) {
|
|
|
|
memcpy(serial_short, &buf[4], len);
|
2015-02-13 10:43:21 +01:00
|
|
|
@@ -876,7 +883,7 @@ int scsi_get_serial(struct udev *udev,
|
2014-09-02 14:58:23 +02:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (page_code == PAGE_80) {
|
|
|
|
- if (do_scsi_page80_inquiry(udev, dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len)) {
|
|
|
|
+ if (do_scsi_page80_inquiry(udev, dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, dev_scsi->serial_compat, len)) {
|
|
|
|
retval = 1;
|
|
|
|
goto completed;
|
|
|
|
} else {
|
2015-02-13 10:43:21 +01:00
|
|
|
@@ -950,7 +957,7 @@ int scsi_get_serial(struct udev *udev,
|
2014-09-02 14:58:23 +02:00
|
|
|
for (ind = 4; ind <= page0[3] + 3; ind++)
|
|
|
|
if (page0[ind] == PAGE_80)
|
|
|
|
if (!do_scsi_page80_inquiry(udev, dev_scsi, fd,
|
|
|
|
- dev_scsi->serial, dev_scsi->serial_short, len)) {
|
|
|
|
+ dev_scsi->serial, dev_scsi->serial_short, dev_scsi->serial_compat, len)) {
|
|
|
|
/*
|
|
|
|
* Success
|
|
|
|
*/
|