On Mon, May 01, 2006 at 07:29:23PM -0400, Kyle Moffett wrote:So my question stands: What is the _recommended_ way to handle simple data types in low-bandwidth/frequency multiple-valued transactions to hardware? Examples include reading/modifying framebuffer settings (currently done through IOCTLS), s390 current state (up for discussion), etc. In these cases there needs to be an atomic snapshot or write of multiple values at the same time. Given the situation it would be _nice_ to use sysfs so the admin can do it by hand; makes things shell scriptable and reduces the number of binary compatibility issues.
I really don't know of a way to use sysfs for this currently, and hence, am not complaining too much about the different /proc files that have this kind of information in it at the moment.
If you or someone else wants to come up with some kind of solution for it, I'm sure that many people would be very happy to see it.
## Associate this process with an atomic snapshot
## of the /sys/hypervisor/s390 filesystem tree.
exec 3>/sys/hypervisor/s390/transaction
## Read data from /sys/hypervisor/s390 without
## worrying about atomicity; as that's guaranteed
## by the open FD 3.
ls /sys/hypervisor/s390/cpus
cat /sys/hypervisor/s390/some_data_file
## Create another reference in this process to the
## _same_ atomic snapshot
exec 4>&3
## Does *not* close out the atomic snapshot
exec 3>&-
## Yet another ref; still the _same_ snapshot
exec 6>/sys/hypervisor/s390/transaction
exec 4>&-
## Regardless of what has changed in the meantime,
## our filesystem tree still looks the same
ls /sys/hypervisor/s390/cpus
## Write out values
echo some_state >/sys/hypervisor/s390/statefile
## Decide we don't like the changes and abort
echo reset >&6
## Release the last copy of the snapshot and
## commit modified values
exec 6>&-
exec 3>/sys/hypervisor/s390/transaction
/bin/s390_change_hypervisor_state
## Look at new state; decide if we like it or not
if [ -z "$I_LIKE_THE_STATE" ]; then
echo reset >&3
fi
exec 3>&-