udev: even if a device is a zac device, scsi-$ID_SERIAL will be reserved for it (#30459)

Co-authored-by: wangyuhang <wangyuhang27@huawei.com>
This commit is contained in:
我超厉害 2024-01-16 13:57:07 +08:00 committed by GitHub
parent f8a6fc51a6
commit 8a86e15f07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -59,6 +59,8 @@ KERNEL=="vd*", ATTRS{serial}=="?*", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="di
# ATA
KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", IMPORT{program}="ata_id --export $devnode"
KERNEL=="sd*[!0-9]|sr*", ENV{ID_BUS}=="ata", ENV{ID_ATA_PERIPHERAL_DEVICE_TYPE}=="20", PROGRAM="scsi_id -u -g $devnode", \
SYMLINK+="disk/by-id/scsi-$result$env{.PART_SUFFIX}"
# ATAPI devices (SPC-3 or later)
KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{type}=="5", ATTRS{scsi_level}=="[6-9]*", IMPORT{program}="ata_id --export $devnode"

View File

@ -298,7 +298,8 @@ static void disk_identify_fixup_uint16(uint8_t identify[512], unsigned offset_wo
* non-zero with errno set.
*/
static int disk_identify(int fd,
uint8_t out_identify[512]) {
uint8_t out_identify[512],
int *ret_peripheral_device_type) {
uint8_t inquiry_buf[36];
int peripheral_device_type, r;
@ -358,6 +359,9 @@ static int disk_identify(int fd,
if (all_nul_bytes)
return log_debug_errno(SYNTHETIC_ERRNO(EIO), "IDENTIFY data is all zeroes.");
if (ret_peripheral_device_type)
*ret_peripheral_device_type = peripheral_device_type;
return 0;
}
@ -407,7 +411,7 @@ static int run(int argc, char *argv[]) {
char model[41], model_enc[256], serial[21], revision[9];
_cleanup_close_ int fd = -EBADF;
uint16_t word;
int r;
int r, peripheral_device_type = -1;
log_set_target(LOG_TARGET_AUTO);
udev_parse_config();
@ -422,7 +426,7 @@ static int run(int argc, char *argv[]) {
if (fd < 0)
return log_error_errno(errno, "Cannot open %s: %m", arg_device);
if (disk_identify(fd, identify.byte) >= 0) {
if (disk_identify(fd, identify.byte, &peripheral_device_type) >= 0) {
/*
* fix up only the fields from the IDENTIFY data that we are going to
* use and copy it into the hd_driveid struct for convenience
@ -615,6 +619,9 @@ static int run(int argc, char *argv[]) {
if (IN_SET(identify.wyde[0], 0x848a, 0x844a) ||
(identify.wyde[83] & 0xc004) == 0x4004)
printf("ID_ATA_CFA=1\n");
if (peripheral_device_type >= 0)
printf("ID_ATA_PERIPHERAL_DEVICE_TYPE=%d\n", peripheral_device_type);
} else {
if (serial[0] != '\0')
printf("%s_%s\n", model, serial);