Opened 6 years ago

Closed 6 years ago

#1064 closed enhancement (wontfix)

RFE: add O_RDRW mode for sat/scsi/ata devices

Reported by: George Shuklin Owned by:
Priority: minor Milestone:
Component: all Version: 6.6
Keywords: linux Cc:

Description

Right now smartmontool could not gather metrics from devices without root access, because to open device with O_RDONLY mode. It is explained in source code as a way to avoid spindle spin-up when device is closed. Unfortunately this made impossible to use all SG_IO commands, as they require RDWR access to the device.

My proposal is to add device types 'scsi-rw', 'sat-rw', 'ata-rw', etc to allow to run smartmontools with limited capabilities and permissions (e.g. not from the root).

Change History (6)

in reply to:  description comment:1 by Christian Franke, 6 years ago

... Unfortunately this made impossible to use all SG_IO commands, as they require RDWR access to the device.

Which smartmontools functionality using SG_IO does not work due to missing O_RDWR access?

My proposal is to add device types 'scsi-rw', 'sat-rw', 'ata-rw', etc to allow to run smartmontools with limited capabilities and permissions (e.g. not from the root).

Why should O_RDWR access work without root permissions if O_RDONLY access already requires root permissions?

comment:2 by Christian Franke, 6 years ago

Milestone: undecided

comment:3 by Christian Franke, 6 years ago

Keywords: linux added

comment:4 by George Shuklin, 6 years ago

I apologize for premature conclusion. I've tested smartmontools with O_RDWR access and it does not help.

My issue was that I wasn't able to make smartmonctl to work under non-root user. I've tried to give that user rw access to the block device file, and to set cap_sys_rawio+ie on smartctl binary. It didn't helped.

I saw in strace that smartctl uses O_RDONLY mode and there is an article which says that sg_io can be used only in RW mode: https://www.tldp.org/HOWTO/SCSI-Generic-HOWTO/sg_io.html.

I made a mistake thinking that O_RDONLY is a source of the problem.

comment:5 by Christian Franke, 6 years ago

According to function blk_verify_command() from current kernel sources (see block/scsi_ioctl.c), O_RDONLY or O_RDWR make no difference if device was opened as root (or with CAP_SYS_RAWIO).

The SCSI commands listed in function blk_set_cmd_filter_defaults() show that some of the smartctl -d scsi functionality might work with O_RDONLY for non-root users. Some more might work with O_RDWR.

But smartctl -d sat (to access SATA devices) won't work at all because the SCSI commands ATA_12 and ATA_16 (see scsi_proto.h) are always blocked for non-root users.

comment:6 by Christian Franke, 6 years ago

Milestone: undecided
Resolution: wontfix
Status: newclosed

There is no benefit if device is opened with O_RDWR mode for SG_IO access.

Note: See TracTickets for help on using tickets.