#include "vars.h" int debug = false; module_param(debug, int, 0); MODULE_PARM_DESC(debug, "Turn on debugging mode. values: 1 for yes, 0 for no, default: no"); int hash_size = 1 << HASH_SIZE; int binary_hash_size; /* Print the contents of a 4k page. used for debugging. */ void print_page(int size, u8 * data) { int x; printk(KERN_ALERT "data: size: %d: ", size); for(x = 0; x < size; x++) printk( "%c", (char) data[x]); printk("\n"); } /* Print the contents of a hashtable key */ void print_key(PageKey *pk) { printk(KERN_ALERT " Key Data: offset %lu\n", (ulong) pk->offset); } /* Function to compute a hash over a hashtable key */ ulong pagekey_hash(void * key) { /* it's really a 32-bit system for now */ ulong value = MOD(((PageKey *) key)->offset, binary_hash_size); if(debug) printk(KERN_ALERT " Hashing to bucket#: %lu \n", value); return value; } /* Determine if two keys are equal */ bool pagekey_equal(void *x, void *y) { PageKey * one = x, *two = y; bool yes = true; int z = 0; if(one->offset == two->offset) { for(; z < ETH_ALEN; z++) if(one->client_mac[z] != two->client_mac[z]) { yes = false; break; } if(yes) return true; } if(debug) { printk(KERN_ALERT "Mismatch between keys:\n"); print_key(one); print_key(two); } return false; } /* Assert a value */ void assert(void *x, char *y) { if(x) return; printk("ASSERTION FAILED: %s @ %s:%d!\n", y, __FILE__, __LINE__); BUG(); } /* Network byte order handling for the messages transmitted in our system */ void msg_ntoh(Message * m) { m->type = ntohl(m->type); m->seq = ntohl(m->seq); m->status = ntohl(m->status); m->count = ntohl(m->count); m->offset = ntohl(m->offset); m->vpid = ntohl(m->vpid); m->fragbyte = ntohl(m->fragbyte); m->fragment = ntohl(m->fragment); m->fragleft = ntohl(m->fragleft); m->fragsize = ntohl(m->fragsize); m->avail_mem = ntohl(m->avail_mem); m->total_mem = ntohl(m->total_mem); m->session_id = ntohl(m->session_id); m->server_status= ntohl(m->server_status); m->serv_internal_time = ntohl(m->serv_internal_time); } void msg_hton(Message * m) { m->type = htonl(m->type); m->seq = htonl(m->seq); m->status = htonl(m->status); m->count = htonl(m->count); m->offset = htonl(m->offset); m->vpid = htonl(m->vpid); m->fragbyte = htonl(m->fragbyte); m->fragment = htonl(m->fragment); m->fragleft = htonl(m->fragleft); m->fragsize = htonl(m->fragsize); m->avail_mem = htonl(m->avail_mem); m->total_mem = htonl(m->total_mem); m->session_id = htonl(m->session_id); m->server_status= htonl(m->server_status); m->serv_internal_time = htonl(m->serv_internal_time); }