From 20e99f16bec261543715016c0a2e02587f41106f Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Wed, 19 Mar 2014 04:28:46 +0000 Subject: [PATCH] scst/README: Show how to read SCST sysfs attributes Make the behavior of SCST sysfs attributes more clear by adding examples in scst/README of code for reading and writing these attributes. Signed-off-by: Bart Van Assche git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@5340 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/README | 33 ++++++++++++++++++++++++++++++++- scst/README_in-tree | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/scst/README b/scst/README index 9e91bcc65..37c638396 100644 --- a/scst/README +++ b/scst/README @@ -460,7 +460,38 @@ following entries: complete, an management tool should poll this file. If the operation hasn't yet completed, it will also return EAGAIN. But after it's completed, it will return the result of this operation (0 for success - or -errno for error). + or -errno for error). The following two shell functions show how to do + this: + +# Read the SCST sysfs attribute $1. See also scst/README for more information. +scst_sysfs_read() { + local EAGAIN val + + EAGAIN="Resource temporarily unavailable" + while true; do + if val="$(LC_ALL=C cat "$1" 2>&1)"; then + echo -n "${val%\[key\]}" + return 0 + elif [ "${val/*: }" != "$EAGAIN" ]; then + return 1 + fi + sleep 1 + done +} + +# Write $1 into the SCST sysfs attribute $2. See also scst/README for more +# information. +scst_sysfs_write() { + local EAGAIN status + + EAGAIN="Resource temporarily unavailable" + if status="$(LC_ALL=C; (echo -n "$1" > "$2") 2>&1)"; then + return 0 + elif [ "${status/*: }" != "$EAGAIN" ]; then + return 1 + fi + scst_sysfs_read /sys/kernel/scst_tgt/last_sysfs_mgmt_res >/dev/null +} "Devices" subdirectory contains subdirectories for each SCST devices. diff --git a/scst/README_in-tree b/scst/README_in-tree index 7ff520b93..1a419af93 100644 --- a/scst/README_in-tree +++ b/scst/README_in-tree @@ -322,7 +322,38 @@ following entries: complete, an management tool should poll this file. If the operation hasn't yet completed, it will also return EAGAIN. But after it's completed, it will return the result of this operation (0 for success - or -errno for error). + or -errno for error). The following two shell functions show how to do + this: + +# Read the SCST sysfs attribute $1. See also scst/README for more information. +scst_sysfs_read() { + local EAGAIN val + + EAGAIN="Resource temporarily unavailable" + while true; do + if val="$(LC_ALL=C cat "$1" 2>&1)"; then + echo -n "${val%\[key\]}" + return 0 + elif [ "${val/*: }" != "$EAGAIN" ]; then + return 1 + fi + sleep 1 + done +} + +# Write $1 into the SCST sysfs attribute $2. See also scst/README for more +# information. +scst_sysfs_write() { + local EAGAIN status + + EAGAIN="Resource temporarily unavailable" + if status="$(LC_ALL=C; (echo -n "$1" > "$2") 2>&1)"; then + return 0 + elif [ "${status/*: }" != "$EAGAIN" ]; then + return 1 + fi + scst_sysfs_read /sys/kernel/scst_tgt/last_sysfs_mgmt_res >/dev/null +} "Devices" subdirectory contains subdirectories for each SCST devices.