Opened 4 weeks ago

Closed 3 weeks ago

Last modified 3 weeks 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 weeks ago.

Download all attachments as: .zip

Change History (8)

Changed 4 weeks ago by rogach

comment:1 Changed 4 weeks ago by Christian Franke

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 Changed 4 weeks ago by Christian Franke

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 Changed 4 weeks ago by rogach

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 Changed 3 weeks ago by Christian Franke

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

Work is in progress.

comment:5 Changed 3 weeks ago by Christian Franke

Resolution: fixed
Status: acceptedclosed

comment:6 Changed 3 weeks ago by Christian Franke

If possible, please test r5115.

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

comment:7 Changed 3 weeks ago by rogach

Tested r5115, works flawlessly:

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

Thank you!

Last edited 3 weeks ago by rogach (previous) (diff)
Note: See TracTickets for help on using tickets.