summaryrefslogtreecommitdiff
path: root/src/udev/scsi_id
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2012-04-08 16:06:20 +0200
committerKay Sievers <kay@vrfy.org>2012-04-08 16:06:20 +0200
commitbaa30fbc2c04b23209d0b8fb3c86cd15ef9ea81a (patch)
tree5a98ddb8cdebeb608526a708dbd5fcc307840a84 /src/udev/scsi_id
parent64661ee70d5a10c6208a1cb66ecd8b158e2d8bc5 (diff)
udev: switch to systemd logging functions
Diffstat (limited to 'src/udev/scsi_id')
-rw-r--r--src/udev/scsi_id/scsi_id.c49
-rw-r--r--src/udev/scsi_id/scsi_serial.c92
2 files changed, 48 insertions, 93 deletions
diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c
index 206cbfd095..dd8517ba96 100644
--- a/src/udev/scsi_id/scsi_id.c
+++ b/src/udev/scsi_id/scsi_id.c
@@ -180,14 +180,12 @@ static int get_file_options(struct udev *udev,
int c;
int retval = 0;
- dbg(udev, "vendor='%s'; model='%s'\n", vendor, model);
fd = fopen(config_file, "r");
if (fd == NULL) {
- dbg(udev, "can't open %s\n", config_file);
if (errno == ENOENT) {
return 1;
} else {
- err(udev, "can't open %s: %s\n", config_file, strerror(errno));
+ log_error("can't open %s: %s\n", config_file, strerror(errno));
return -1;
}
}
@@ -200,7 +198,7 @@ static int get_file_options(struct udev *udev,
buffer = malloc(MAX_BUFFER_LEN);
if (!buffer) {
fclose(fd);
- err(udev, "can't allocate memory\n");
+ log_error("can't allocate memory\n");
return -1;
}
@@ -214,7 +212,7 @@ static int get_file_options(struct udev *udev,
break;
lineno++;
if (buf[strlen(buffer) - 1] != '\n') {
- err(udev, "Config file line %d too long\n", lineno);
+ log_error("Config file line %d too long\n", lineno);
break;
}
@@ -229,7 +227,6 @@ static int get_file_options(struct udev *udev,
if (*buf == '#')
continue;
- dbg(udev, "lineno %d: '%s'\n", lineno, buf);
str1 = strsep(&buf, "=");
if (str1 && strcasecmp(str1, "VENDOR") == 0) {
str1 = get_value(&buf);
@@ -259,22 +256,18 @@ static int get_file_options(struct udev *udev,
}
options_in = str1;
}
- dbg(udev, "config file line %d:\n"
- " vendor '%s'; model '%s'; options '%s'\n",
- lineno, vendor_in, model_in, options_in);
+
/*
* Only allow: [vendor=foo[,model=bar]]options=stuff
*/
if (!options_in || (!vendor_in && model_in)) {
- err(udev, "Error parsing config file line %d '%s'\n", lineno, buffer);
+ log_error("Error parsing config file line %d '%s'\n", lineno, buffer);
retval = -1;
break;
}
if (vendor == NULL) {
- if (vendor_in == NULL) {
- dbg(udev, "matched global option\n");
+ if (vendor_in == NULL)
break;
- }
} else if ((vendor_in && strncmp(vendor, vendor_in,
strlen(vendor_in)) == 0) &&
(!model_in || (strncmp(model, model_in,
@@ -286,10 +279,7 @@ static int get_file_options(struct udev *udev,
* give a partial match (that is FOO
* matches FOOBAR).
*/
- dbg(udev, "matched vendor/model\n");
break;
- } else {
- dbg(udev, "no match\n");
}
}
@@ -304,7 +294,7 @@ static int get_file_options(struct udev *udev,
c = argc_count(buffer) + 2;
*newargv = calloc(c, sizeof(**newargv));
if (!*newargv) {
- err(udev, "can't allocate memory\n");
+ log_error("can't allocate memory\n");
retval = -1;
} else {
*argc = c;
@@ -346,11 +336,6 @@ static int set_options(struct udev *udev,
if (option == -1)
break;
- if (optarg)
- dbg(udev, "option '%c' arg '%s'\n", option, optarg);
- else
- dbg(udev, "option '%c'\n", option);
-
switch (option) {
case 'b':
all_good = 0;
@@ -396,7 +381,7 @@ static int set_options(struct udev *udev,
} else if (strcmp(optarg, "pre-spc3-83") == 0) {
default_page_code = PAGE_83_PRE_SPC3;
} else {
- err(udev, "Unknown page code '%s'\n", optarg);
+ log_error("Unknown page code '%s'\n", optarg);
return -1;
}
break;
@@ -404,7 +389,7 @@ static int set_options(struct udev *udev,
case 's':
sg_version = atoi(optarg);
if (sg_version < 3 || sg_version > 4) {
- err(udev, "Unknown SG version '%s'\n", optarg);
+ log_error("Unknown SG version '%s'\n", optarg);
return -1;
}
break;
@@ -456,11 +441,6 @@ static int per_dev_options(struct udev *udev,
if (option == -1)
break;
- if (optarg)
- dbg(udev, "option '%c' arg '%s'\n", option, optarg);
- else
- dbg(udev, "option '%c'\n", option);
-
switch (option) {
case 'b':
*good_bad = 0;
@@ -478,13 +458,13 @@ static int per_dev_options(struct udev *udev,
} else if (strcmp(optarg, "pre-spc3-83") == 0) {
*page_code = PAGE_83_PRE_SPC3;
} else {
- err(udev, "Unknown page code '%s'\n", optarg);
+ log_error("Unknown page code '%s'\n", optarg);
retval = -1;
}
break;
default:
- err(udev, "Unknown or bad option '%c' (0x%x)\n", option, option);
+ log_error("Unknown or bad option '%c' (0x%x)\n", option, option);
retval = -1;
break;
}
@@ -540,7 +520,6 @@ static int scsi_id(struct udev *udev, char *maj_min_dev)
/* get per device (vendor + model) options from the config file */
per_dev_options(udev, &dev_scsi, &good_dev, &page_code);
- dbg(udev, "per dev options: good %d; page code 0x%x\n", good_dev, page_code);
if (!good_dev) {
retval = 1;
goto out;
@@ -616,7 +595,7 @@ int main(int argc, char **argv)
if (udev == NULL)
goto exit;
- udev_log_init("scsi_id");
+ log_open();
udev_set_log_fn(udev, log_fn);
/*
@@ -643,7 +622,7 @@ int main(int argc, char **argv)
exit(1);
if (!dev_specified) {
- err(udev, "no device specified\n");
+ log_error("no device specified\n");
retval = 1;
goto exit;
}
@@ -652,6 +631,6 @@ int main(int argc, char **argv)
exit:
udev_unref(udev);
- udev_log_close();
+ log_close();
return retval;
}
diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c
index f1d63f40cc..6bfb7f780c 100644
--- a/src/udev/scsi_id/scsi_serial.c
+++ b/src/udev/scsi_id/scsi_serial.c
@@ -196,10 +196,8 @@ static int scsi_dump_sense(struct udev *udev,
* we'll retry the command.
*/
- dbg(udev, "got check condition\n");
-
if (sb_len < 1) {
- info(udev, "%s: sense buffer empty\n", dev_scsi->kernel);
+ log_debug("%s: sense buffer empty\n", dev_scsi->kernel);
return -1;
}
@@ -212,7 +210,7 @@ static int scsi_dump_sense(struct udev *udev,
*/
s = sense_buffer[7] + 8;
if (sb_len < s) {
- info(udev, "%s: sense buffer too small %d bytes, %d bytes too short\n",
+ log_debug("%s: sense buffer too small %d bytes, %d bytes too short\n",
dev_scsi->kernel, sb_len, s - sb_len);
return -1;
}
@@ -222,7 +220,7 @@ static int scsi_dump_sense(struct udev *udev,
/*
* Possible?
*/
- info(udev, "%s: sense result too" " small %d bytes\n",
+ log_debug("%s: sense result too" " small %d bytes\n",
dev_scsi->kernel, s);
return -1;
}
@@ -233,39 +231,38 @@ static int scsi_dump_sense(struct udev *udev,
asc = sense_buffer[2];
ascq = sense_buffer[3];
} else {
- info(udev, "%s: invalid sense code 0x%x\n",
+ log_debug("%s: invalid sense code 0x%x\n",
dev_scsi->kernel, code);
return -1;
}
- info(udev, "%s: sense key 0x%x ASC 0x%x ASCQ 0x%x\n",
+ log_debug("%s: sense key 0x%x ASC 0x%x ASCQ 0x%x\n",
dev_scsi->kernel, sense_key, asc, ascq);
} else {
if (sb_len < 4) {
- info(udev, "%s: sense buffer too small %d bytes, %d bytes too short\n",
+ log_debug("%s: sense buffer too small %d bytes, %d bytes too short\n",
dev_scsi->kernel, sb_len, 4 - sb_len);
return -1;
}
if (sense_buffer[0] < 15)
- info(udev, "%s: old sense key: 0x%x\n", dev_scsi->kernel, sense_buffer[0] & 0x0f);
+ log_debug("%s: old sense key: 0x%x\n", dev_scsi->kernel, sense_buffer[0] & 0x0f);
else
- info(udev, "%s: sense = %2x %2x\n",
+ log_debug("%s: sense = %2x %2x\n",
dev_scsi->kernel, sense_buffer[0], sense_buffer[2]);
- info(udev, "%s: non-extended sense class %d code 0x%0x\n",
+ log_debug("%s: non-extended sense class %d code 0x%0x\n",
dev_scsi->kernel, sense_class, code);
}
#ifdef DUMP_SENSE
for (i = 0, j = 0; (i < s) && (j < 254); i++) {
- dbg(udev, "i %d, j %d\n", i, j);
out_buffer[j++] = hex_str[(sense_buffer[i] & 0xf0) >> 4];
out_buffer[j++] = hex_str[sense_buffer[i] & 0x0f];
out_buffer[j++] = ' ';
}
out_buffer[j] = '\0';
- info(udev, "%s: sense dump:\n", dev_scsi->kernel);
- info(udev, "%s: %s\n", dev_scsi->kernel, out_buffer);
+ log_debug("%s: sense dump:\n", dev_scsi->kernel);
+ log_debug("%s: %s\n", dev_scsi->kernel, out_buffer);
#endif
return -1;
@@ -279,11 +276,11 @@ static int scsi_dump(struct udev *udev,
/*
* Impossible, should not be called.
*/
- info(udev, "%s: called with no error\n", __FUNCTION__);
+ log_debug("%s: called with no error\n", __FUNCTION__);
return -1;
}
- info(udev, "%s: sg_io failed status 0x%x 0x%x 0x%x 0x%x\n",
+ log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x 0x%x\n",
dev_scsi->kernel, io->driver_status, io->host_status, io->msg_status, io->status);
if (io->status == SCSI_CHECK_CONDITION)
return scsi_dump_sense(udev, dev_scsi, io->sbp, io->sb_len_wr);
@@ -299,11 +296,11 @@ static int scsi_dump_v4(struct udev *udev,
/*
* Impossible, should not be called.
*/
- info(udev, "%s: called with no error\n", __FUNCTION__);
+ log_debug("%s: called with no error\n", __FUNCTION__);
return -1;
}
- info(udev, "%s: sg_io failed status 0x%x 0x%x 0x%x\n",
+ log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x\n",
dev_scsi->kernel, io->driver_status, io->transport_status,
io->device_status);
if (io->device_status == SCSI_CHECK_CONDITION)
@@ -328,13 +325,11 @@ static int scsi_inquiry(struct udev *udev,
int retval;
if (buflen > SCSI_INQ_BUFF_LEN) {
- info(udev, "buflen %d too long\n", buflen);
+ log_debug("buflen %d too long\n", buflen);
return -1;
}
resend:
- dbg(udev, "%s evpd %d, page 0x%x\n", dev_scsi->kernel, evpd, page);
-
if (dev_scsi->use_sg == 4) {
memset(&io_v4, 0, sizeof(struct sg_io_v4));
io_v4.guard = 'Q';
@@ -367,7 +362,7 @@ resend:
dev_scsi->use_sg = 3;
goto resend;
}
- info(udev, "%s: ioctl failed: %s\n", dev_scsi->kernel, strerror(errno));
+ log_debug("%s: ioctl failed: %s\n", dev_scsi->kernel, strerror(errno));
goto error;
}
@@ -395,16 +390,14 @@ resend:
if (!retval) {
retval = buflen;
} else if (retval > 0) {
- if (--retry > 0) {
- dbg(udev, "%s: Retrying ...\n", dev_scsi->kernel);
+ if (--retry > 0)
goto resend;
- }
retval = -1;
}
error:
if (retval < 0)
- info(udev, "%s: Unable to get INQUIRY vpd %d page 0x%x.\n",
+ log_debug("%s: Unable to get INQUIRY vpd %d page 0x%x.\n",
dev_scsi->kernel, evpd, page);
return retval;
@@ -423,11 +416,11 @@ static int do_scsi_page0_inquiry(struct udev *udev,
return 1;
if (buffer[1] != 0) {
- info(udev, "%s: page 0 not available.\n", dev_scsi->kernel);
+ log_debug("%s: page 0 not available.\n", dev_scsi->kernel);
return 1;
}
if (buffer[3] > len) {
- info(udev, "%s: page 0 buffer too long %d\n", dev_scsi->kernel, buffer[3]);
+ log_debug("%s: page 0 buffer too long %d\n", dev_scsi->kernel, buffer[3]);
return 1;
}
@@ -444,7 +437,7 @@ static int do_scsi_page0_inquiry(struct udev *udev,
* invalid.
*/
if (!strncmp((char *)&buffer[VENDOR_LENGTH], dev_scsi->vendor, VENDOR_LENGTH)) {
- info(udev, "%s: invalid page0 data\n", dev_scsi->kernel);
+ log_debug("%s: invalid page0 data\n", dev_scsi->kernel);
return 1;
}
}
@@ -469,7 +462,7 @@ static int prepend_vendor_model(struct udev *udev,
* above, ind will never be too large.
*/
if (ind != (VENDOR_LENGTH + MODEL_LENGTH)) {
- info(udev, "%s: expected length %d, got length %d\n",
+ log_debug("%s: expected length %d, got length %d\n",
dev_scsi->kernel, (VENDOR_LENGTH + MODEL_LENGTH), ind);
return -1;
}
@@ -535,7 +528,7 @@ static int check_fill_0x83_id(struct udev *udev,
len += VENDOR_LENGTH + MODEL_LENGTH;
if (max_len < len) {
- info(udev, "%s: length %d too short - need %d\n",
+ log_debug("%s: length %d too short - need %d\n",
dev_scsi->kernel, max_len, len);
return 1;
}
@@ -557,10 +550,8 @@ static int check_fill_0x83_id(struct udev *udev,
* included in the identifier.
*/
if (id_search->id_type == SCSI_ID_VENDOR_SPECIFIC)
- if (prepend_vendor_model(udev, dev_scsi, &serial[1]) < 0) {
- dbg(udev, "prepend failed\n");
+ if (prepend_vendor_model(udev, dev_scsi, &serial[1]) < 0)
return 1;
- }
i = 4; /* offset to the start of the identifier */
s = j = strlen(serial);
@@ -603,7 +594,6 @@ static int check_fill_0x83_prespc3(struct udev *udev,
{
int i, j;
- dbg(udev, "using pre-spc3-83 for %s\n", dev_scsi->kernel);
serial[0] = hex_str[id_search->id_type];
/* serial has been memset to zero before */
j = strlen(serial); /* j = 1; */
@@ -639,7 +629,7 @@ static int do_scsi_page83_inquiry(struct udev *udev,
return 1;
if (page_83[1] != PAGE_83) {
- info(udev, "%s: Invalid page 0x83\n", dev_scsi->kernel);
+ log_debug("%s: Invalid page 0x83\n", dev_scsi->kernel);
return 1;
}
@@ -695,19 +685,10 @@ static int do_scsi_page83_inquiry(struct udev *udev,
serial, serial_short, len,
wwn, wwn_vendor_extension,
tgpt_group);
- dbg(udev, "%s id desc %d/%d/%d\n", dev_scsi->kernel,
- id_search_list[id_ind].id_type,
- id_search_list[id_ind].naa_type,
- id_search_list[id_ind].code_set);
- if (!retval) {
- dbg(udev, " used\n");
+ if (!retval)
return retval;
- } else if (retval < 0) {
- dbg(udev, " failed\n");
+ else if (retval < 0)
return retval;
- } else {
- dbg(udev, " not used\n");
- }
}
}
return 1;
@@ -734,7 +715,7 @@ static int do_scsi_page83_prespc3_inquiry(struct udev *udev,
return 1;
if (page_83[1] != PAGE_83) {
- info(udev, "%s: Invalid page 0x83\n", dev_scsi->kernel);
+ log_debug("%s: Invalid page 0x83\n", dev_scsi->kernel);
return 1;
}
/*
@@ -778,7 +759,6 @@ static int do_scsi_page83_prespc3_inquiry(struct udev *udev,
serial[j++] = hex_str[page_83[i] & 0x0f];
i++;
}
- dbg(udev, "using pre-spc3-83 for %s\n", dev_scsi->kernel);
return 0;
}
@@ -799,13 +779,13 @@ static int do_scsi_page80_inquiry(struct udev *udev,
return retval;
if (buf[1] != PAGE_80) {
- info(udev, "%s: Invalid page 0x80\n", dev_scsi->kernel);
+ log_debug("%s: Invalid page 0x80\n", dev_scsi->kernel);
return 1;
}
len = 1 + VENDOR_LENGTH + MODEL_LENGTH + buf[3];
if (max_len < len) {
- info(udev, "%s: length %d too short - need %d\n",
+ log_debug("%s: length %d too short - need %d\n",
dev_scsi->kernel, max_len, len);
return 1;
}
@@ -837,16 +817,15 @@ int scsi_std_inquiry(struct udev *udev,
struct stat statbuf;
int err = 0;
- dbg(udev, "opening %s\n", devname);
fd = open(devname, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
- info(udev, "scsi_id: cannot open %s: %s\n",
+ log_debug("scsi_id: cannot open %s: %s\n",
devname, strerror(errno));
return 1;
}
if (fstat(fd, &statbuf) < 0) {
- info(udev, "scsi_id: cannot stat %s: %s\n",
+ log_debug("scsi_id: cannot stat %s: %s\n",
devname, strerror(errno));
err = 2;
goto out;
@@ -884,7 +863,6 @@ int scsi_get_serial(struct udev *udev,
int retval;
memset(dev_scsi->serial, 0, len);
- dbg(udev, "opening %s\n", devname);
srand((unsigned int)getpid());
for (cnt = 20; cnt > 0; cnt--) {
struct timespec duration;
@@ -941,7 +919,7 @@ int scsi_get_serial(struct udev *udev,
goto completed;
}
} else if (page_code != 0x00) {
- info(udev, "%s: unsupported page code 0x%d\n", dev_scsi->kernel, page_code);
+ log_debug("%s: unsupported page code 0x%d\n", dev_scsi->kernel, page_code);
return 1;
}
@@ -959,8 +937,6 @@ int scsi_get_serial(struct udev *udev,
goto completed;
}
- dbg(udev, "%s: Checking page0\n", dev_scsi->kernel);
-
for (ind = 4; ind <= page0[3] + 3; ind++)
if (page0[ind] == PAGE_83)
if (!do_scsi_page83_inquiry(udev, dev_scsi, fd,