#!/bin/bash # autogen C code for zstd # Copyright 2010 Michael Blumenkrantz zsys=(system cpu char float mem) system=(name domainname arch ostype os version modules) cpu=(numcpus userprocs nicedprocs sysprocs idle steal guest forks runprocs blockprocs entropy procs ctxt intr) char=(mhz cpuflags model iowait) float=(loads[0] loads[1] loads[2]) mem=(page_size mem_free mem_total mem_shared mem_buffered swap_free swap_total mem_active mem_inactive) loads[0]="load1" loads[1]="load5" loads[2]="load15" disk=(read_ios read_merges read_sectors read_ticks write_ios write_merges write_sectors write_ticks in_flight io_ticks time_in_queue numdisks) partition=(mode_opts dev_location mount_point partition_type statvfs) statvfs=(f_bsize f_frsize f_blocks f_bfree f_bavail f_files f_ffree f_favail f_fsid f_flag f_namemax) vif=(id mtu bridge mac ip netmask broadcast numvifs stats) stats=(rxbytes rxpackets rxerr rxdrop rfifo frame rcompressed multicast txbytes txpackets txerr txdrop tfifo collisions carrier tcompressed) for x in zsys disk partition vif;do if [ "$x" != 'zsys' ];then echo echo -en '\t' echo "write = thisvm->${x}s;" echo -en '\t' echo "ZLIST_FOR(write, l, ${x})" echo -en '\t' echo "{" fi for s in `echo $(eval echo '${'$x'[@]}')`;do if [ "$x" == 'zsys' ];then for i in `echo $(eval echo '${'$s'[@]}')`;do if [ "$i" == 'steal' ];then echo -e '\tif (rev >= 11)\n\t{' echo -en '\t' elif [ "$i" == 'guest' ];then echo -e '\tif (rev >= 24)\n\t{' echo -en '\t' fi if (echo "$i"|grep -q load);then echo -en '\t' echo "snprintf(temp_xs_path, sizeof(temp_xs_path),\"%s/cpu/${!i}\",base_xs_path);" elif [ "$s" == 'cpu' ] || [ "$s" == 'char' ] || [ "$s" == 'float' ];then echo -en '\t' echo "snprintf(temp_xs_path, sizeof(temp_xs_path),\"%s/cpu/$i\",base_xs_path);" else echo -en '\t' echo "snprintf(temp_xs_path, sizeof(temp_xs_path),\"%s/$s/$i\",base_xs_path);" fi echo -en '\t' if [ "$i" == 'steal' ] || [ "$i" == 'guest' ];then echo -en '\t' fi if [ "$s" == 'system' ] || [ "$s" == 'char' ];then echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)thisvm->info->$i,strlen(thisvm->info->$i));" else echo "" if [ "$i" == 'steal' ] || [ "$i" == 'guest' ];then echo -en '\t' fi echo -en '\t' echo -n "snprintf(tmp, sizeof(tmp),\"%" if (echo "$i"|grep -q load);then echo -n "f" else echo -n "llu" fi echo "\",thisvm->info->$i);" if [ "$i" == 'steal' ] || [ "$i" == 'guest' ];then echo -en '\t' fi echo -en '\t' echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" fi if [ "$i" == 'steal' ] || [ "$i" == 'guest' ];then echo -e '\t}' fi done else if [ "$s" == 'numdisks' ] || [ "$s" == 'numvifs' ];then echo -en '\t\t' echo "snprintf(temp_xs_path, sizeof(temp_xs_path),\"%s/${x}s/$s\",base_xs_path);" echo -en '\t\t' echo "snprintf(tmp, sizeof(tmp),\"%d\",thisvm->$s);" echo -en '\t\t' echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" else if [ "$x" == 'partition' ] || [ "$x" == 'vif' ];then if [ "$s" == 'statvfs' ] || [ "$s" == 'stats' ];then if [ "$s" == 'statvfs' ];then pf="ld" else pf="llu" fi for i in `echo $(eval echo '${'$s'[@]}')`;do echo -en '\t\t' echo "snprintf(temp_xs_path, sizeof(temp_xs_path),\"%s/${x}s/%s/$s/$i\",base_xs_path,${x}->name);" echo -en '\t\t' echo "snprintf(tmp, sizeof(tmp),\"%${pf}\",$x->$s->$i);" echo -en '\t\t' echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" done else echo -en '\t\t' echo "snprintf(temp_xs_path, sizeof(temp_xs_path),\"%s/${x}s/%s/$s\",base_xs_path,${x}->name);" if [ "$s" == 'mac' ] || [ "$s" == 'type' ] || [ "$s" == 'ip' ] || [ "$s" == 'netmask' ] || [ "$s" == 'gateway' ] || [ "$s" == 'broadcast' ] || \ [ "$s" == 'mode_opts' ] || [ "$s" == 'dev_location' ] || [ "$s" == 'mount_point' ] || [ "$s" == 'partition_type' ];then echo -en '\t\t' echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)$x->$s,strlen($x->$s));" else echo -en '\t\t' echo "snprintf(tmp, sizeof(tmp),\"%d\",${x}->$s);" echo -en '\t\t' echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" fi fi else echo -en '\t\t' echo "snprintf(temp_xs_path, sizeof(temp_xs_path),\"%s/${x}s/%s/$s\",base_xs_path,$x->name);" echo -en '\t\t' echo "snprintf(tmp, sizeof(tmp),\"%llu\",${x}->$s);" echo -en '\t\t' echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" fi fi fi done if [ "$x" != 'zsys' ];then echo -en '\t' echo '}' fi done