#!/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) guest='\t' steal='\t' 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) 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 stats) stats=(rxbytes rxpackets rxerr rxdrop rfifo frame rcompressed multicast txbytes txpackets txerr txdrop tfifo collisions carrier tcompressed) for x in numdisks numvifs;do echo -en '\t' echo 'if (thisvm->'${x}' != thatvm->'${x}')' echo -en '\t' echo "{" echo -en '\t\t' echo "snprintf(temp_xs_path, sizeof(temp_xs_path),\"%s/${x/num}/${x}\",base_xs_path);" echo -en '\t\t' echo "snprintf(tmp, sizeof(tmp),\"%d\",thisvm->${x});" echo -en '\t\t' echo "log_msg(ZDEBUG,\"Updating %s from %d to %d\",temp_xs_path,thatvm->${x},thisvm->${x});" echo -en '\t\t' echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" echo -e '\t}' done for x in zsys disk partition vif;do if [ "${x}" != 'zsys' ];then echo -en '\n\t' echo "write = thisvm->${x}s;" echo -en '\t' echo "ZLIST_FOR(write, l, ${x})" echo -en '\t' echo "{" fi if [ "${x}" == 'zsys' ];then for s in `echo $(eval echo '${'${x}'[@]}')`;do 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${!i##*[0-9]}" if [ "$s" == 'system' ] || [ "$s" == 'char' ];then echo 'if (zshare_strcmp(thisvm->info->'$i',thatvm->info->'$i'))' echo -en "\t${!i##*[0-9]}" echo '{' echo -en "\t\t${!i##*[0-9]}" echo "log_msg(ZDEBUG,\"Updating %s from %s to %s\",temp_xs_path,thatvm->info->$i,thisvm->info->$i);" echo -en "\t\t${!i##*[0-9]}" echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)thisvm->info->$i,strlen(thisvm->info->$i));" else echo 'if (thisvm->info->'$i' != thatvm->info->'$i')' echo -en "\t${!i##*[0-9]}" echo '{' echo -en "\t\t${!i##*[0-9]}" 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);" echo -en "\t\t${!i##*[0-9]}" echo -n "log_msg(ZDEBUG,\"Updating %s from %" if (echo "$i"|grep -q load);then echo -n "f" else echo -n "llu" fi echo -n " to %" if (echo "$i"|grep -q load);then echo -n "f" else echo -n "llu" fi echo "\",temp_xs_path,thatvm->info->$i,thisvm->info->$i);" echo -en "\t\t${!i##*[0-9]}" echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" fi if [ "$i" == 'steal' ] || [ "$i" == 'guest' ];then echo -e '\t\t}' fi echo -e "\t}" done done else for n in "guest" "sup";do if [ "$n" == 'guest' ];then echo -en '\t\t' echo "write2 = thatvm->${x}s;" echo -en '\t\t' echo "ZLIST_FOR(write2, m, z${x})" echo -en "\t\t" echo "{" echo -en "\t\t\t" echo "if (!zshare_strcmp(${x}->name,z${x}->name))" echo -en "\t\t\t" echo "{" else echo -en "\t\t\t" echo "else if (!m->next)" echo -en "\t\t\t" echo "{" fi for s in `echo $(eval echo '${'${x}'[@]}')`;do 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 if [ "$n" == 'guest' ];then echo -en "\t\t\t\t" echo "if (${x}->$s->$i != z${x}->$s->$i)" echo -en "\t\t\t\t" echo "{" fi echo -en "\t\t\t\t${!n}" echo "snprintf(temp_xs_path, sizeof(temp_xs_path),\"%s/${x}s/%s/$s/$i\",base_xs_path,${x}->name);" echo -en "\t\t\t\t${!n}" echo "snprintf(tmp, sizeof(tmp),\"%${pf}\",${x}->$s->$i);" echo -en "\t\t\t\t${!n}" if [ "$n" != 'guest' ];then echo "log_msg(ZDEBUG,\"Adding %s with value %${pf}\",temp_xs_path,${x}->$s->$i);" else echo "log_msg(ZDEBUG,\"Updating %s from %${pf} to %${pf}\",temp_xs_path,z${x}->$s->$i,${x}->$s->$i);" fi echo -en "\t\t\t\t${!n}" echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" if [ "$n" == 'guest' ];then echo -en "\t\t\t\t" echo "}" else echo fi done else 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\t\t" if [ "$n" != 'guest' ];then echo "log_msg(ZDEBUG,\"Adding %s with value %s\",temp_xs_path,${x}->$s);" else echo "if (zshare_strcmp(${x}->$s,z${x}->$s))" echo -en "\t\t\t\t" echo "{" echo -en "\t\t\t\t${!n}" echo "log_msg(ZDEBUG,\"Updating %s from %s to %s\",temp_xs_path,z${x}->$s,${x}->$s);" fi echo -en "\t\t\t\t${!n}" echo "snprintf(temp_xs_path, sizeof(temp_xs_path),\"%s/${x}s/%s/$s\",base_xs_path,${x}->name);" echo -en "\t\t\t\t${!n}" echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)${x}->$s,strlen(${x}->$s));" else if [ "$n" == 'guest' ];then echo -en "\t\t\t\t" echo "if (${x}->$s != z${x}->$s)" echo -en "\t\t\t\t" echo "{" fi echo -en "\t\t\t\t${!n}" echo "snprintf(tmp, sizeof(tmp),\"%d\",${x}->$s);" if [ "$n" != 'guest' ];then echo -en "\t\t\t\t${!n}" echo "log_msg(ZDEBUG,\"Adding %s with value %d\",temp_xs_path,${x}->$s);" else echo -en "\t\t\t\t${!n}" echo "log_msg(ZDEBUG,\"Updating %s from %d to %d\",temp_xs_path,z${x}->$s,${x}->$s);" fi echo -en "\t\t\t\t${!n}" echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" fi if [ "$n" == 'guest' ];then echo -e "\t\t\t\t}" fi fi else if [ "$n" == 'guest' ];then echo -en "\t\t\t\t" echo "if (${x}->$s != z${x}->$s)" echo -en "\t\t\t\t" echo "{" fi echo -en "\t\t\t\t${!n}" echo "snprintf(temp_xs_path, sizeof(temp_xs_path),\"%s/${x}s/%s/$s\",base_xs_path,${x}->name);" echo -en "\t\t\t\t${!n}" echo "snprintf(tmp, sizeof(tmp),\"%llu\",${x}->$s);" if [ "$n" != 'guest' ];then echo -en "\t\t\t\t${!n}" echo "log_msg(ZDEBUG,\"Adding %s with value %llu\",temp_xs_path,${x}->$s);" else echo -en "\t\t\t\t${!n}" echo "log_msg(ZDEBUG,\"Updating %s from %llu to %llu\",temp_xs_path,z${x}->$s,${x}->$s);" fi echo -en "\t\t\t\t${!n}" echo "xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" if [ "$n" == 'guest' ];then echo -en "\t\t\t\t" echo "}" else echo fi fi done echo -en "\t\t\t\t" echo "break;" echo -e "\t\t\t}" done echo -e "\t\t}" echo -en '\t' echo '}' fi done