Opened 4 years ago

Closed 4 years ago

Last modified 5 months ago

#1390 closed defect (fixed)

-d ignore doesn't work if target is a symbolic link to a device

Reported by: rogach Owned by: Christian Franke
Priority: minor Milestone: Release 7.2
Component: smartd Version:
Keywords: Cc:

Description

Setup:

$ ls -l /dev/disk/by-id/wwn-0x5000xxxx
lrwxrwxrwx 9 root 2020-10-31 15:15 /dev/disk/by-id/wwn-0x5000xxxx -> ../../sda
$ cat /etc/smartd.conf
/dev/disk/by-id/wwn-0x5000xxxx -d ignore
DEVICESCAN -a

Expected result:

Device with specified id is ignored.

Actual result:

Device (/dev/sda in this example) is not ignored.

Analysis:

This issue seems to be similar to #313.

Duplicate detection (is_duplicate_dev_idinfo) relies on populated dev_idinfo, and that is done in ATADeviceScan. But "-d ignore" bypasses any scanning altogether, thus duplicate detection is unable to deduce that /dev/sda and /dev/disk/by-id/wwn-0x5000xxxx are actually the same device.

There is another duplicate detection function (is_duplicate_device), but it relies on dev_names being exactly equal. I attempted to fix the issue by checking if dev_name is a symbolic link and resolving the link to actual file in such cases - seems to work correctly.

Please find attached for your consideration a patch that implements symlink resolution for device names (apply with patch --input=resolve_device_symlinks.patch in source directory).

Attachments (1)

resolve_device_symlinks.patch (1.0 KB ) - added by rogach 4 years ago.

Download all attachments as: .zip

Change History (10)

by rogach, 4 years ago

comment:1 by Christian Franke, 4 years ago

Component: allsmartd
Milestone: unscheduled

Thanks for the report and the patch. Of course the patch fixes this for your use case. But it assumes real POSIX path names as device names which is not always the case. It breaks Windows builds. Unconditionally resolving symlinks to devices may also have undesired effects on existing -M exec scripts. I will implement a more general approach which handles this without changing cfg.dev_name and allows platform specific hooks.

comment:2 by Christian Franke, 4 years ago

The following may also work on Linux:

/dev/disk/by-id/wwn-0x5000xxxx -d ignore
DEVICESCAN -d by-id -a

Requires smartmontools 7.0 or later. New Linux-only device scan option -d by-id is only mentioned in NEWS file, but still missing on man pages.

Try with smartctl -d by-id --scan.

comment:3 by rogach, 4 years ago

Of course the patch fixes this for your use case. But it assumes real POSIX path names as device names which is not always the case.

My mistake, I should have at least surrounded it with an ifdef. No problem, that patch was just a suggestion, of course you as a project owner are more familiar with the project specifics and architecture.

New Linux-only device scan option -d by-id

Yes, this works, thank you! One caveat: in my case I had to replace /wwn-0x00 with /ata-ST1000DM000-XXXX, because it seems id resolution prefers this form to wwn.

comment:4 by Christian Franke, 4 years ago

Milestone: unscheduledRelease 7.2
Owner: set to Christian Franke
Status: newaccepted

Work is in progress.

comment:5 by Christian Franke, 4 years ago

Resolution: fixed
Status: acceptedclosed

comment:6 by Christian Franke, 4 years ago

If possible, please test r5115.

Source tarballs and binaries are available at https://builds.smartmontools.org/.

comment:7 by rogach, 4 years ago

Tested r5115, works flawlessly:

Device: /dev/sda, same as /dev/disk/by-id/wwn-0x5000xxxx, ignored

Thank you!

Last edited 4 years ago by rogach (previous) (diff)

comment:8 by Rypi, 5 months ago

This works well for SATA drives (/dev/sdX), but not for NVME devices. Is there any change that it would get fixed?

root@nas:~# smartctl -d by-id --scan
/dev/disk/by-id/ata-ST4000NE001-3CR101_WX10EGSJ -d scsi # /dev/disk/by-id/ata-ST4000NE001-3CR101_WX10EGSJ, SCSI device
/dev/nvme0 -d nvme # /dev/nvme0, NVMe device
root@nas:~# ls -l /dev/nvme*
crw------- 1 root root 241,   0 čen  1 15:19 /dev/nvme0
brw-rw---- 1 root disk 259,   0 čen  1 15:19 /dev/nvme0n1
brw-rw---- 1 root disk 259,   2 čen  1 15:19 /dev/nvme0n1p1
brw-rw---- 1 root disk 259,   3 čen  1 15:19 /dev/nvme0n1p2
brw-rw---- 1 root disk 259,   4 čen  1 15:19 /dev/nvme0n1p3
root@nas:~# ls -l /dev/disk/by-id/nvme*
lrwxrwxrwx 1 root root 13 čen  1 15:19 /dev/disk/by-id/nvme-TS1TMTE220S_G514071565 -> ../../nvme0n1
lrwxrwxrwx 1 root root 15 čen  1 15:19 /dev/disk/by-id/nvme-TS1TMTE220S_G514071565-part1 -> ../../nvme0n1p1
lrwxrwxrwx 1 root root 15 čen  1 15:19 /dev/disk/by-id/nvme-TS1TMTE220S_G514071565-part2 -> ../../nvme0n1p2
lrwxrwxrwx 1 root root 15 čen  1 15:19 /dev/disk/by-id/nvme-TS1TMTE220S_G514071565-part3 -> ../../nvme0n1p3

comment:9 by Christian Franke, 5 months ago

NVMe is more complex due to namespaces. Please create a new ticket.

Note: See TracTickets for help on using tickets.