From 4596ac19cf2ddaa210c8bb112f2e28c93d4c8590 Mon Sep 17 00:00:00 2001 From: Stephane Thiell Date: Fri, 12 Nov 2021 13:18:48 -0800 Subject: [PATCH] ses: check for supported snic diagnostic page before querying it Avoid useless driver warning messages in kernel logs when snic is not supported. --- sasutils/ses.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/sasutils/ses.py b/sasutils/ses.py index 7825e06..5c16086 100644 --- a/sasutils/ses.py +++ b/sasutils/ses.py @@ -1,5 +1,5 @@ # -# Copyright (C) 2016 +# Copyright (C) 2016, 2021 # The Board of Trustees of the Leland Stanford Junior University # Written by Stephane Thiell # @@ -31,7 +31,31 @@ def ses_get_snic_nickname(sg_name): """Get subenclosure nickname (SES-2) [snic]""" + support_snic = False + # SES nickname is not available through sysfs, use sg_ses tool instead + cmdargs = ['sg_ses', '--status', '/dev/' + sg_name] + LOGGER.debug('ses_get_snic_nickname: executing: %s', cmdargs) + try: + stdout, stderr = subprocess.Popen(cmdargs, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE).communicate() + except OSError as err: + LOGGER.warning('ses_get_snic_nickname: %s', err) + return None + + for line in stderr.decode("utf-8").splitlines(): + LOGGER.debug('ses_get_snic_nickname: sg_ses(stderr): %s', line) + + for line in stdout.decode("utf-8").splitlines(): + LOGGER.debug('ses_get_snic_nickname: sg_ses: %s', line) + if '[snic]' in line: + support_snic = True + break + + if not support_snic: + return None + cmdargs = ['sg_ses', '--page=snic', '-I0', '/dev/' + sg_name] LOGGER.debug('ses_get_snic_nickname: executing: %s', cmdargs) try: