#!/bin/sh save_ringsz() { # usage: ME [--dry-run] # It only prints what to be done if --dry-run is specified. local i dryrun [ "x$1" = "x--dry-run" ] && dryrun=yes || dryrun=no for i in /sys/class/net/e{no,ns,np,nx,th}* ; do [ -e $i ] || continue /usr/sbin/ethtool -g $(basename $i) |awk -v dev=$(basename $i) -v storage=$STORAGE -v suffix=${STORAGE_SUFFIX} -v dryrun=$dryrun ' BEGIN{ found = 0; } { if ( /Current.*settings/ ) { found = 1; next; } if ( found == 0 ) { next; } if ( $1 == "RX:" || $1 == "TX:" ) { if ( dryrun == "yes" ) { printf("%s/%s-%s%s=%s\n", storage, dev, substr($1,1,2), suffix, $2); } else { print $2 > sprintf("%s/%s-%s%s", storage, dev, substr($1,1,2), suffix); } } } ' done } show_ringsz() { save_ringsz --dry-run } set_ringsz() { # usage: ME RXBUFF [TXBUFF] local i txopt [ "$#" -lt 1 ] && return [ "$#" -eq 2 ] && txopt="tx $2" for i in /sys/class/net/e{no,ns,np,nx,th}* ; do [ -e $i ] || continue /usr/sbin/ethtool -G $(basename $i) rx $1 $txopt done } get_stored_ringsz() { # usage: ME DEVNAME [ -f "$STORAGE/$1-RX${STORAGE_SUFFIX}" -a -f "$STORAGE/$1-TX${STORAGE_SUFFIX}" ] || return RX=$(cat "$STORAGE/$1-RX${STORAGE_SUFFIX}") TX=$(cat "$STORAGE/$1-TX${STORAGE_SUFFIX}") } restore_ringsz() { local i dev for i in /sys/class/net/e{no,ns,np,nx,th}* ; do [ -e $i ] || continue dev=$(basename $i) get_stored_ringsz $dev [ "x$RX" == "x" -o "x$TX" == "x" ] && continue /usr/sbin/ethtool -G $(basename $i) rx $RX tx $TX #[ $? -eq 0 ] || continue unlink "$STORAGE/${dev}-RX${STORAGE_SUFFIX}" >/dev/null 2>&1 unlink "$STORAGE/${dev}-TX${STORAGE_SUFFIX}" >/dev/null 2>&1 done }