#!/bin/bash # autogen C code for zstd # Copyright 2009 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 iowait) char=(mhz cpuflags model) 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 numdisks) partition=(mode_opts dev_location mount_point partition_type statfs) statfs=(f_bsize f_blocks f_bfree f_bavail f_files f_ffree) vif=(id mtu bridge mac ip netmask broadcast numvifs stats) stats=(rbytes rpackets rerrs rdrop rfifo frame rcompressed multicast tbytes tpackets terrs tdrop tfifo colls carrier tcompressed) for x in zsys disk partition vif;do if [ "$x" != 'zsys' ];then echo -en '\n\t' echo "zlist *thisvm${x}s = thisvm->${x}s;" echo -en '\n\t' echo "zlist *thatvm${x}s = NULL;" echo -en '\t' echo "for (;thisvm${x}s && thisvm${x}s->data;thisvm${x}s = thisvm${x}s->next) {" 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){' echo -en '\t' elif [ "$i" == 'guest' ];then echo -e '\tif (rev >= 24){' echo -en '\t' fi if (echo "$i"|grep -q load);then echo -en '\t' echo "sprintf(temp_xs_path,\"%s/cpu/${!i}\",base_xs_path);" elif [ "$s" == 'cpu' ] || [ "$s" == 'char' ] || [ "$s" == 'float' ];then echo -en '\t' echo "sprintf(temp_xs_path,\"%s/cpu/$i\",base_xs_path);" else echo -en '\t' echo "sprintf(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\t${!i##*[0-9]}" echo "sprintf(msg,\"Updating %s from %s to %s\",temp_xs_path,thatvm->info->$i,thisvm->info->$i);" echo -en "\t\t${!i##*[0-9]}" echo "log_msg(ZDEBUG,msg);" echo -en "\t\t${!i##*[0-9]}" echo "if (cfg->DEBUG)" echo -en "\t\t\t${!i##*[0-9]}" echo "printf(\"DEBUG: %s\n\",msg);" echo -en "\t\t${!i##*[0-9]}" echo "result = 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\t${!i##*[0-9]}" echo "tmp = realloc(tmp,sizeof(char)*(MAX_STRLEN(thisvm->info->$i)+2));" echo -en "\t\t${!i##*[0-9]}" echo -n "sprintf(tmp,\"%" if (echo "$i"|grep -q load);then echo -n "f" else echo -n "u" fi echo "\",thisvm->info->$i);" echo -en "\t\t${!i##*[0-9]}" echo -n "sprintf(msg,\"Updating %s from %" if (echo "$i"|grep -q load);then echo -n "f" else echo -n "u" fi echo -n " to %" if (echo "$i"|grep -q load);then echo -n "f" else echo -n "u" fi echo "\",temp_xs_path,thatvm->info->$i,thisvm->info->$i);" echo -en "\t\t${!i##*[0-9]}" echo "log_msg(ZDEBUG,msg);" echo -en "\t\t${!i##*[0-9]}" echo "if (cfg->DEBUG)" echo -en "\t\t\t${!i##*[0-9]}" echo "printf(\"DEBUG: %s\n\",msg);" echo -en "\t\t${!i##*[0-9]}" echo "result = 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 else if [ "$s" == 'numdisks' ] || [ "$s" == 'numvifs' ];then echo -en '\t\t' echo 'if (thisvm->'$s' != thatvm->'$s'){' echo -en '\t\t\t' echo "sprintf(temp_xs_path,\"%s/${x}s/$s\",base_xs_path);" echo -en '\t\t\t' echo "tmp = realloc(tmp,sizeof(char)*(MAX_STRLEN(thisvm->$s)+2));" echo -en '\t\t\t' echo "sprintf(tmp,\"%d\",thisvm->$s);" echo -en '\t\t\t' echo "sprintf(msg,\"Updating %s from %d to %d\",temp_xs_path,thatvm->$s,thisvm->$s);" echo -en '\t\t\t' echo "log_msg(ZDEBUG,msg);" echo -en '\t\t\t' echo "if (cfg->DEBUG)" echo -en '\t\t\t\t' echo "printf(\"DEBUG: %s\n\",msg);" echo -en '\t\t\t' echo "result = xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" echo -e '\t\t}' else if [ "$x" == 'partition' ] || [ "$x" == 'vif' ];then if [ "$s" == 'statfs' ] || [ "$s" == 'stats' ];then if [ "$s" == 'statfs' ];then pf="d" else pf="u" fi for i in `echo $(eval echo '${'$s'[@]}')`;do echo -en '\t\t' echo "thatvm${x}s = thatvm->${x}s;" echo -en '\t\t' echo "for (;thatvm${x}s && thatvm${x}s->data;thatvm${x}s = thatvm${x}s->next) {" echo -en "\t\t\t" echo "if (!zshare_strcmp((($x*)(thisvm${x}s->data))->name,(($x*)(thatvm${x}s->data))->name)){" echo -en "\t\t\t\t" echo "if ((($x*)(thisvm${x}s->data))->$s->$i != (($x*)(thatvm${x}s->data))->$s->$i){" echo -en "\t\t\t\t\t" echo "sprintf(temp_xs_path,\"%s/${x}s/%s/$s/$i\",base_xs_path,((${x}*)(thisvm${x}s->data))->name);" echo -en "\t\t\t\t\t" echo "tmp = realloc(tmp,sizeof(char)*(MAX_STRLEN(((${x}*)(thisvm${x}s->data))->$s->$i)+2));" echo -en "\t\t\t\t\t" echo "sprintf(tmp,\"%${pf}\",(($x*)(thisvm${x}s->data))->$s->$i);" echo -en "\t\t\t\t\t" echo "if (zshare_strcmp((($x*)(thisvm${x}s->data))->name,(($x*)(thatvm${x}s->data))->name))" echo -en "\t\t\t\t\t\t" echo "sprintf(msg,\"Adding %s with value %${pf}\",temp_xs_path,((${x}*)(thisvm${x}s->data))->$s->$i);" echo -en "\t\t\t\t\t" echo "else" echo -en "\t\t\t\t\t\t" echo "sprintf(msg,\"Updating %s from %${pf} to %${pf}\",temp_xs_path,((${x}*)(thatvm${x}s->data))->$s->$i,((${x}*)(thisvm${x}s->data))->$s->$i);" echo -en '\t\t\t\t\t' echo "log_msg(ZDEBUG,msg);" echo -en '\t\t\t\t\t' echo "if (cfg->DEBUG)" echo -en '\t\t\t\t\t\t' echo "printf(\"DEBUG: %s\n\",msg);" echo -en '\t\t\t\t\t' echo "result = xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" echo -en '\t\t\t\t\t' echo "break;" echo -e "\t\t\t\t}" echo -e "\t\t\t}" echo -e "\t\t}" done else echo -en '\t\t' echo "thatvm${x}s = thatvm->${x}s;" echo -en '\t\t' echo "for (;thatvm${x}s && thatvm${x}s->data;thatvm${x}s = thatvm${x}s->next) {" echo -en "\t\t\t" echo "if (!zshare_strcmp((($x*)(thisvm${x}s->data))->name,(($x*)(thatvm${x}s->data))->name){" echo -en "\t\t\t\t" echo "sprintf(temp_xs_path,\"%s/${x}s/%s/$s\",base_xs_path,((${x}*)(thisvm${x}s->data))->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\t\t" echo "if (zshare_strcmp((($x*)(thisvm${x}s->data))->$s,(($x*)(thatvm${x}s->data))->$s)){" echo -en "\t\t\t\t\t" echo "if (zshare_strcmp((($x*)(thisvm${x}s->data))->name,(($x*)(thatvm${x}s->data))->name))" echo -en "\t\t\t\t\t\t" echo "sprintf(msg,\"Adding %s with value %s\",temp_xs_path,((${x}*)(thisvm${x}s->data))->$s);" echo -en "\t\t\t\t\t" echo "else" echo -en "\t\t\t\t\t\t" echo "sprintf(msg,\"Updating %s from %s to %s\",temp_xs_path,((${x}*)(thatvm${x}s->data))->$s,((${x}*)(thisvm${x}s->data))->$s);" echo -en '\t\t\t\t\t' echo "log_msg(ZDEBUG,msg);" echo -en '\t\t\t\t\t' echo "if (cfg->DEBUG)" echo -en '\t\t\t\t\t\t' echo "printf(\"DEBUG: %s\n\",msg);" echo -en '\t\t\t\t\t' echo "result = xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)(($x*)(thisvm${x}s->data))->$s,strlen((($x*)(thisvm${x}s->data))->$s));" else echo -en "\t\t\t\t" echo "if ((($x*)(thisvm${x}s->data))->$s != (($x*)(thatvm${x}s->data))->$s){" echo -en "\t\t\t\t\t" echo "tmp = realloc(tmp,sizeof(char)*(MAX_STRLEN(((${x}*)(thisvm${x}s->data))->$s)+2));" echo -en "\t\t\t\t\t" echo "sprintf(tmp,\"%d\",((${x}*)(thisvm${x}s->data))->$s);" echo -en "\t\t\t\t\t" echo "if (zshare_strcmp((($x*)(thisvm${x}s->data))->name,(($x*)(thatvm${x}s->data))->name))" echo -en "\t\t\t\t\t\t" echo "sprintf(msg,\"Adding %s with value %d\",temp_xs_path,((${x}*)(thisvm${x}s->data))->$s);" echo -en "\t\t\t\t\t" echo "else" echo -en "\t\t\t\t\t\t" echo "sprintf(msg,\"Updating %s from %d to %d\",temp_xs_path,((${x}*)(thatvm${x}s->data))->$s,((${x}*)(thisvm${x}s->data))->$s);" echo -en '\t\t\t\t\t' echo "log_msg(ZDEBUG,msg);" echo -en '\t\t\t\t\t' echo "if (cfg->DEBUG)" echo -en '\t\t\t\t\t\t' echo "printf(\"DEBUG: %s\n\",msg);" echo -en '\t\t\t\t\t' echo "result = xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" fi echo -en '\t\t\t\t\t' echo "break;" echo -e "\t\t\t\t}" echo -e "\t\t\t}" echo -e "\t\t}" fi else echo -en '\t\t' echo "thatvm${x}s = thatvm->${x}s;" echo -en '\t\t' echo "for (;thatvm${x}s && thatvm${x}s->data;thatvm${x}s = thatvm${x}s->next) {" echo -en "\t\t\t" echo "if (!zshare_strcmp((($x*)(thisvm${x}s->data))->name,(($x*)(thatvm${x}s->data))->name){" echo -en "\t\t\t\t" echo "if ((($x*)(thisvm${x}s->data))->$s != (($x*)(thatvm${x}s->data))->$s){" echo -en "\t\t\t\t\t" echo "sprintf(temp_xs_path,\"%s/${x}s/%s/$s\",base_xs_path,(($x*)(thisvm${x}s->data))->name);" echo -en '\t\t\t\t\t' echo "tmp = realloc(tmp,sizeof(char)*(MAX_STRLEN((($x*)(thisvm${x}s->data))->$s)+2));" echo -en '\t\t\t\t\t' echo "sprintf(tmp,\"%u\",((${x}*)(thisvm${x}s->data))->$s);" echo -en '\t\t\t\t\t' echo "if (zshare_strcmp((($x*)(thisvm${x}s->data))->name,(($x*)(thatvm${x}s->data))->name))" echo -en "\t\t\t\t\t\t" echo "sprintf(msg,\"Adding %s with value %u\",temp_xs_path,((${x}*)(thisvm${x}s->data))->$s);" echo -en "\t\t\t\t\t" echo "else" echo -en "\t\t\t\t\t\t" echo "sprintf(msg,\"Updating %s from %u to %u\",temp_xs_path,((${x}*)(thatvm${x}s->data))->$s,((${x}*)(thisvm${x}s->data))->$s);" echo -en '\t\t\t\t\t' echo "log_msg(ZDEBUG,msg);" echo -en '\t\t\t\t\t' echo "if (cfg->DEBUG)" echo -en '\t\t\t\t\t\t' echo "printf(\"DEBUG: %s\n\",msg);" echo -en '\t\t\t\t\t' echo "result = xs_write(xsh,XBT_NULL,temp_xs_path,(const void*)tmp,strlen(tmp));" echo -en '\t\t\t\t\t' echo "break;" echo -e "\t\t\t\t}" echo -e "\t\t\t}" echo -e "\t\t}" fi fi fi done if [ "$x" != 'zsys' ];then echo -en '\t' echo '}' fi done