diff options
author | Artur Paszkiewicz <artur.paszkiewicz@intel.com> | 2016-10-06 11:13:09 +0200 |
---|---|---|
committer | Jes Sorensen <Jes.Sorensen@redhat.com> | 2016-10-07 17:18:32 +0200 |
commit | 21e9380b26058762a0d3cb0957c5808736d21996 (patch) | |
tree | d2e4ce16ef028f1fe6a9a586edae29234408793b /sg_io.c | |
parent | Fix RAID metadata check (diff) | |
download | mdadm-21e9380b26058762a0d3cb0957c5808736d21996.tar.xz mdadm-21e9380b26058762a0d3cb0957c5808736d21996.zip |
imsm: retrieve nvme serial from sysfs
Don't rely on SCSI ioctl for reading NVMe serials - SCSI emulation for
NVMe devices can be disabled in the kernel config. Instead, try to get a
serial from /sys/block/nvme*/device/serial. If that fails for whatever
reason (i.e. no such attribute in old kernels) - fall back to the SCSI
method.
This also moves some SCSI-specific code from imsm_read_serial() to
scsi_get_serial().
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Reviewed-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Reviewed-by: Alexey Obitotskiy <aleksey.obitotskiy@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Diffstat (limited to 'sg_io.c')
-rw-r--r-- | sg_io.c | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -23,20 +23,35 @@ int scsi_get_serial(int fd, void *buf, size_t buf_len) { - unsigned char inq_cmd[] = {INQUIRY, 1, 0x80, 0, buf_len, 0}; + unsigned char rsp_buf[255]; + unsigned char inq_cmd[] = {INQUIRY, 1, 0x80, 0, sizeof(rsp_buf), 0}; unsigned char sense[32]; struct sg_io_hdr io_hdr; + int rv; + unsigned int rsp_len; memset(&io_hdr, 0, sizeof(io_hdr)); io_hdr.interface_id = 'S'; io_hdr.cmdp = inq_cmd; io_hdr.cmd_len = sizeof(inq_cmd); - io_hdr.dxferp = buf; - io_hdr.dxfer_len = buf_len; + io_hdr.dxferp = rsp_buf; + io_hdr.dxfer_len = sizeof(rsp_buf); io_hdr.dxfer_direction = SG_DXFER_FROM_DEV; io_hdr.sbp = sense; io_hdr.mx_sb_len = sizeof(sense); io_hdr.timeout = 5000; - return ioctl(fd, SG_IO, &io_hdr); + rv = ioctl(fd, SG_IO, &io_hdr); + + if (rv) + return rv; + + rsp_len = rsp_buf[3]; + + if (!rsp_len || buf_len < rsp_len) + return -1; + + memcpy(buf, &rsp_buf[4], rsp_len); + + return 0; } |