Skip to content

Commit 8a86e15

Browse files
YoruStarwangyuhang
and
wangyuhang
authoredJan 16, 2024
udev: even if a device is a zac device, scsi-$ID_SERIAL will be reserved for it (systemd#30459)
Co-authored-by: wangyuhang <wangyuhang27@huawei.com>
1 parent f8a6fc5 commit 8a86e15

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
 

‎rules.d/60-persistent-storage.rules.in

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ KERNEL=="vd*", ATTRS{serial}=="?*", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="di
5959

6060
# ATA
6161
KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", IMPORT{program}="ata_id --export $devnode"
62+
KERNEL=="sd*[!0-9]|sr*", ENV{ID_BUS}=="ata", ENV{ID_ATA_PERIPHERAL_DEVICE_TYPE}=="20", PROGRAM="scsi_id -u -g $devnode", \
63+
SYMLINK+="disk/by-id/scsi-$result$env{.PART_SUFFIX}"
6264

6365
# ATAPI devices (SPC-3 or later)
6466
KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{type}=="5", ATTRS{scsi_level}=="[6-9]*", IMPORT{program}="ata_id --export $devnode"

‎src/udev/ata_id/ata_id.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ static void disk_identify_fixup_uint16(uint8_t identify[512], unsigned offset_wo
298298
* non-zero with errno set.
299299
*/
300300
static int disk_identify(int fd,
301-
uint8_t out_identify[512]) {
301+
uint8_t out_identify[512],
302+
int *ret_peripheral_device_type) {
302303
uint8_t inquiry_buf[36];
303304
int peripheral_device_type, r;
304305

@@ -358,6 +359,9 @@ static int disk_identify(int fd,
358359
if (all_nul_bytes)
359360
return log_debug_errno(SYNTHETIC_ERRNO(EIO), "IDENTIFY data is all zeroes.");
360361

362+
if (ret_peripheral_device_type)
363+
*ret_peripheral_device_type = peripheral_device_type;
364+
361365
return 0;
362366
}
363367

@@ -407,7 +411,7 @@ static int run(int argc, char *argv[]) {
407411
char model[41], model_enc[256], serial[21], revision[9];
408412
_cleanup_close_ int fd = -EBADF;
409413
uint16_t word;
410-
int r;
414+
int r, peripheral_device_type = -1;
411415

412416
log_set_target(LOG_TARGET_AUTO);
413417
udev_parse_config();
@@ -422,7 +426,7 @@ static int run(int argc, char *argv[]) {
422426
if (fd < 0)
423427
return log_error_errno(errno, "Cannot open %s: %m", arg_device);
424428

425-
if (disk_identify(fd, identify.byte) >= 0) {
429+
if (disk_identify(fd, identify.byte, &peripheral_device_type) >= 0) {
426430
/*
427431
* fix up only the fields from the IDENTIFY data that we are going to
428432
* use and copy it into the hd_driveid struct for convenience
@@ -615,6 +619,9 @@ static int run(int argc, char *argv[]) {
615619
if (IN_SET(identify.wyde[0], 0x848a, 0x844a) ||
616620
(identify.wyde[83] & 0xc004) == 0x4004)
617621
printf("ID_ATA_CFA=1\n");
622+
623+
if (peripheral_device_type >= 0)
624+
printf("ID_ATA_PERIPHERAL_DEVICE_TYPE=%d\n", peripheral_device_type);
618625
} else {
619626
if (serial[0] != '\0')
620627
printf("%s_%s\n", model, serial);

0 commit comments

Comments
 (0)
Please sign in to comment.