direct-io.hg

changeset 5652:99ff7c3435b2

Fix some newline ugliness that BK wouldn't correct.
Signed-off-by: akw27@cl.cam.ac.uk
author akw27@arcadians.cl.cam.ac.uk
date Sun Jul 03 12:02:01 2005 +0000 (2005-07-03)
parents fc4e10d0455a
children abbc1d071e22
files tools/blktap/block-async.c tools/blktap/block-async.h tools/blktap/requests-async.c tools/blktap/requests-async.h
line diff
     1.1 --- a/tools/blktap/block-async.c	Sat Jul 02 22:37:55 2005 +0000
     1.2 +++ b/tools/blktap/block-async.c	Sun Jul 03 12:02:01 2005 +0000
     1.3 @@ -1,49 +1,49 @@
     1.4 -/* block-async.c
     1.5 - * 
     1.6 - * Asynchronous block wrappers for parallax.
     1.7 - */
     1.8 - 
     1.9 - 
    1.10 -#include <stdio.h>
    1.11 -#include <stdlib.h>
    1.12 -#include <string.h>
    1.13 -#include <pthread.h>
    1.14 -#include "block-async.h"
    1.15 -#include "blockstore.h"
    1.16 -#include "vdi.h"
    1.17 -
    1.18 -
    1.19 -#if 0
    1.20 -#define DPRINTF(_f, _a...) printf ( _f , ## _a )
    1.21 -#else
    1.22 -#define DPRINTF(_f, _a...) ((void)0)
    1.23 -#endif
    1.24 -
    1.25 -/* We have a queue of outstanding I/O requests implemented as a 
    1.26 - * circular producer-consumer ring with free-running buffers.
    1.27 - * to allow reordering, this ring indirects to indexes in an 
    1.28 - * ring of io_structs.
    1.29 - * 
    1.30 - * the block_* calls may either add an entry to this ring and return, 
    1.31 - * or satisfy the request immediately and call the callback directly.
    1.32 - * None of the io calls in parallax should be nested enough to worry 
    1.33 - * about stack problems with this approach.
    1.34 - */
    1.35 -
    1.36 -struct read_args {
    1.37 +/* block-async.c
    1.38 + * 
    1.39 + * Asynchronous block wrappers for parallax.
    1.40 + */
    1.41 + 
    1.42 + 
    1.43 +#include <stdio.h>
    1.44 +#include <stdlib.h>
    1.45 +#include <string.h>
    1.46 +#include <pthread.h>
    1.47 +#include "block-async.h"
    1.48 +#include "blockstore.h"
    1.49 +#include "vdi.h"
    1.50 +
    1.51 +
    1.52 +#if 0
    1.53 +#define DPRINTF(_f, _a...) printf ( _f , ## _a )
    1.54 +#else
    1.55 +#define DPRINTF(_f, _a...) ((void)0)
    1.56 +#endif
    1.57 +
    1.58 +/* We have a queue of outstanding I/O requests implemented as a 
    1.59 + * circular producer-consumer ring with free-running buffers.
    1.60 + * to allow reordering, this ring indirects to indexes in an 
    1.61 + * ring of io_structs.
    1.62 + * 
    1.63 + * the block_* calls may either add an entry to this ring and return, 
    1.64 + * or satisfy the request immediately and call the callback directly.
    1.65 + * None of the io calls in parallax should be nested enough to worry 
    1.66 + * about stack problems with this approach.
    1.67 + */
    1.68 +
    1.69 +struct read_args {
    1.70      u64 addr;
    1.71 -};
    1.72 -
    1.73 -struct write_args {
    1.74 +};
    1.75 +
    1.76 +struct write_args {
    1.77      u64   addr;
    1.78      char *block;
    1.79 -};
    1.80 -
    1.81 -struct alloc_args {
    1.82 +};
    1.83 +
    1.84 +struct alloc_args {
    1.85      char *block;
    1.86 -};
    1.87 - 
    1.88 -struct pending_io_req {
    1.89 +};
    1.90 + 
    1.91 +struct pending_io_req {
    1.92      enum {IO_READ, IO_WRITE, IO_ALLOC, IO_RWAKE, IO_WWAKE} op;
    1.93      union {
    1.94          struct read_args  r;
    1.95 @@ -52,10 +52,10 @@ struct pending_io_req {
    1.96      } u;
    1.97      io_cb_t cb;
    1.98      void *param;
    1.99 -};
   1.100 -
   1.101 -void radix_lock_init(struct radix_lock *r)
   1.102 -{
   1.103 +};
   1.104 +
   1.105 +void radix_lock_init(struct radix_lock *r)
   1.106 +{
   1.107      int i;
   1.108      
   1.109      pthread_mutex_init(&r->lock, NULL);
   1.110 @@ -64,38 +64,38 @@ void radix_lock_init(struct radix_lock *
   1.111          r->waiters[i] = NULL;
   1.112          r->state[i] = ANY;
   1.113      }
   1.114 -}
   1.115 -
   1.116 -/* maximum outstanding I/O requests issued asynchronously */
   1.117 -/* must be a power of 2.*/
   1.118 +}
   1.119 +
   1.120 +/* maximum outstanding I/O requests issued asynchronously */
   1.121 +/* must be a power of 2.*/
   1.122  #define MAX_PENDING_IO 1024
   1.123 -
   1.124 -/* how many threads to concurrently issue I/O to the disk. */
   1.125 +
   1.126 +/* how many threads to concurrently issue I/O to the disk. */
   1.127  #define IO_POOL_SIZE   10
   1.128 -
   1.129 -static struct pending_io_req pending_io_reqs[MAX_PENDING_IO];
   1.130 -static int pending_io_list[MAX_PENDING_IO];
   1.131 -static unsigned long io_prod = 0, io_cons = 0, io_free = 0;
   1.132 -#define PENDING_IO_MASK(_x) ((_x) & (MAX_PENDING_IO - 1))
   1.133 -#define PENDING_IO_IDX(_x) ((_x) - pending_io_reqs)
   1.134 -#define PENDING_IO_ENT(_x) \
   1.135 -	(&pending_io_reqs[pending_io_list[PENDING_IO_MASK(_x)]])
   1.136 -#define CAN_PRODUCE_PENDING_IO ((io_free + MAX_PENDING_IO) != io_prod)
   1.137 -#define CAN_CONSUME_PENDING_IO (io_cons != io_prod)
   1.138 -static pthread_mutex_t pending_io_lock = PTHREAD_MUTEX_INITIALIZER;
   1.139 -static pthread_cond_t  pending_io_cond = PTHREAD_COND_INITIALIZER;
   1.140 -
   1.141 -static void init_pending_io(void)
   1.142 -{
   1.143 +
   1.144 +static struct pending_io_req pending_io_reqs[MAX_PENDING_IO];
   1.145 +static int pending_io_list[MAX_PENDING_IO];
   1.146 +static unsigned long io_prod = 0, io_cons = 0, io_free = 0;
   1.147 +#define PENDING_IO_MASK(_x) ((_x) & (MAX_PENDING_IO - 1))
   1.148 +#define PENDING_IO_IDX(_x) ((_x) - pending_io_reqs)
   1.149 +#define PENDING_IO_ENT(_x) \
   1.150 +	(&pending_io_reqs[pending_io_list[PENDING_IO_MASK(_x)]])
   1.151 +#define CAN_PRODUCE_PENDING_IO ((io_free + MAX_PENDING_IO) != io_prod)
   1.152 +#define CAN_CONSUME_PENDING_IO (io_cons != io_prod)
   1.153 +static pthread_mutex_t pending_io_lock = PTHREAD_MUTEX_INITIALIZER;
   1.154 +static pthread_cond_t  pending_io_cond = PTHREAD_COND_INITIALIZER;
   1.155 +
   1.156 +static void init_pending_io(void)
   1.157 +{
   1.158      int i;
   1.159 -	
   1.160 +	
   1.161      for (i=0; i<MAX_PENDING_IO; i++)
   1.162          pending_io_list[i] = i;
   1.163 -		
   1.164 -} 
   1.165 -
   1.166 -void block_read(u64 addr, io_cb_t cb, void *param)
   1.167 -{
   1.168 +		
   1.169 +} 
   1.170 +
   1.171 +void block_read(u64 addr, io_cb_t cb, void *param)
   1.172 +{
   1.173      struct pending_io_req *req;
   1.174      
   1.175      pthread_mutex_lock(&pending_io_lock);
   1.176 @@ -108,13 +108,13 @@ void block_read(u64 addr, io_cb_t cb, vo
   1.177      req->cb = cb;
   1.178      req->param = param;
   1.179      
   1.180 -    pthread_cond_signal(&pending_io_cond);
   1.181 +    pthread_cond_signal(&pending_io_cond);
   1.182      pthread_mutex_unlock(&pending_io_lock);	
   1.183 -}
   1.184 -
   1.185 -
   1.186 -void block_write(u64 addr, char *block, io_cb_t cb, void *param)
   1.187 -{
   1.188 +}
   1.189 +
   1.190 +
   1.191 +void block_write(u64 addr, char *block, io_cb_t cb, void *param)
   1.192 +{
   1.193      struct pending_io_req *req;
   1.194      
   1.195      pthread_mutex_lock(&pending_io_lock);
   1.196 @@ -128,15 +128,15 @@ void block_write(u64 addr, char *block, 
   1.197      req->cb = cb;
   1.198      req->param = param;
   1.199      
   1.200 -    pthread_cond_signal(&pending_io_cond);
   1.201 +    pthread_cond_signal(&pending_io_cond);
   1.202      pthread_mutex_unlock(&pending_io_lock);	
   1.203 -}
   1.204 -
   1.205 -
   1.206 -void block_alloc(char *block, io_cb_t cb, void *param)
   1.207 -{
   1.208 +}
   1.209 +
   1.210 +
   1.211 +void block_alloc(char *block, io_cb_t cb, void *param)
   1.212 +{
   1.213      struct pending_io_req *req;
   1.214 -	
   1.215 +	
   1.216      pthread_mutex_lock(&pending_io_lock);
   1.217      assert(CAN_PRODUCE_PENDING_IO);
   1.218      
   1.219 @@ -146,12 +146,12 @@ void block_alloc(char *block, io_cb_t cb
   1.220      req->cb = cb;
   1.221      req->param = param;
   1.222      
   1.223 -    pthread_cond_signal(&pending_io_cond);
   1.224 +    pthread_cond_signal(&pending_io_cond);
   1.225      pthread_mutex_unlock(&pending_io_lock);	
   1.226 -}
   1.227 -
   1.228 -void block_rlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
   1.229 -{
   1.230 +}
   1.231 +
   1.232 +void block_rlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
   1.233 +{
   1.234      struct io_ret ret;
   1.235      pthread_mutex_lock(&r->lock);
   1.236      
   1.237 @@ -179,11 +179,11 @@ void block_rlock(struct radix_lock *r, i
   1.238          pthread_mutex_unlock(&r->lock);
   1.239          return;
   1.240      }
   1.241 -}
   1.242 -
   1.243 -
   1.244 -void block_wlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
   1.245 -{
   1.246 +}
   1.247 +
   1.248 +
   1.249 +void block_wlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
   1.250 +{
   1.251      struct io_ret ret;
   1.252      pthread_mutex_lock(&r->lock);
   1.253      
   1.254 @@ -212,12 +212,12 @@ void block_wlock(struct radix_lock *r, i
   1.255          pthread_mutex_unlock(&r->lock);
   1.256          return;
   1.257      }
   1.258 -	
   1.259 -}
   1.260 -
   1.261 -/* called with radix_lock locked and lock count of zero. */
   1.262 -static void wake_waiters(struct radix_lock *r, int row)
   1.263 -{
   1.264 +	
   1.265 +}
   1.266 +
   1.267 +/* called with radix_lock locked and lock count of zero. */
   1.268 +static void wake_waiters(struct radix_lock *r, int row)
   1.269 +{
   1.270      struct pending_io_req *req;
   1.271      struct radix_wait *rw;
   1.272      
   1.273 @@ -263,14 +263,14 @@ static void wake_waiters(struct radix_lo
   1.274      }	
   1.275      
   1.276      pthread_mutex_lock(&pending_io_lock);
   1.277 -    pthread_cond_signal(&pending_io_cond);
   1.278 +    pthread_cond_signal(&pending_io_cond);
   1.279      pthread_mutex_unlock(&pending_io_lock);
   1.280 -}
   1.281 -
   1.282 -void block_runlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
   1.283 -{
   1.284 +}
   1.285 +
   1.286 +void block_runlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
   1.287 +{
   1.288      struct io_ret ret;
   1.289 -	
   1.290 +	
   1.291      pthread_mutex_lock(&r->lock);
   1.292      assert(r->lines[row] > 0); /* try to catch misuse. */
   1.293      r->lines[row]--;
   1.294 @@ -280,10 +280,10 @@ void block_runlock(struct radix_lock *r,
   1.295      }
   1.296      pthread_mutex_unlock(&r->lock);
   1.297      cb(ret, param);
   1.298 -}
   1.299 -
   1.300 -void block_wunlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
   1.301 -{
   1.302 +}
   1.303 +
   1.304 +void block_wunlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
   1.305 +{
   1.306      struct io_ret ret;
   1.307      
   1.308      pthread_mutex_lock(&r->lock);
   1.309 @@ -293,11 +293,11 @@ void block_wunlock(struct radix_lock *r,
   1.310      wake_waiters(r, row);
   1.311      pthread_mutex_unlock(&r->lock);
   1.312      cb(ret, param);
   1.313 -}
   1.314 -
   1.315 -/* consumer calls */
   1.316 -static void do_next_io_req(struct pending_io_req *req)
   1.317 -{
   1.318 +}
   1.319 +
   1.320 +/* consumer calls */
   1.321 +static void do_next_io_req(struct pending_io_req *req)
   1.322 +{
   1.323      struct io_ret          ret;
   1.324      void  *param;
   1.325      
   1.326 @@ -334,60 +334,60 @@ static void do_next_io_req(struct pendin
   1.327      pthread_mutex_lock(&pending_io_lock);
   1.328      pending_io_list[PENDING_IO_MASK(io_free++)] = PENDING_IO_IDX(req);
   1.329      pthread_mutex_unlock(&pending_io_lock);
   1.330 -	
   1.331 +	
   1.332      assert(req->cb != NULL);
   1.333      req->cb(ret, param);
   1.334      
   1.335 -}
   1.336 -
   1.337 -void *io_thread(void *param) 
   1.338 -{
   1.339 +}
   1.340 +
   1.341 +void *io_thread(void *param) 
   1.342 +{
   1.343      int tid;
   1.344      struct pending_io_req *req;
   1.345      
   1.346      /* Set this thread's tid. */
   1.347 -    tid = *(int *)param;
   1.348 -    free(param);
   1.349 -    
   1.350 -start:
   1.351 -    pthread_mutex_lock(&pending_io_lock);
   1.352 -    while (io_prod == io_cons) {
   1.353 -        pthread_cond_wait(&pending_io_cond, &pending_io_lock);
   1.354 -    }
   1.355 -    
   1.356 -    if (io_prod == io_cons) {
   1.357 -        /* unnecessary wakeup. */
   1.358 -        pthread_mutex_unlock(&pending_io_lock);
   1.359 -        goto start;
   1.360 -    }
   1.361 -    
   1.362 +    tid = *(int *)param;
   1.363 +    free(param);
   1.364 +    
   1.365 +start:
   1.366 +    pthread_mutex_lock(&pending_io_lock);
   1.367 +    while (io_prod == io_cons) {
   1.368 +        pthread_cond_wait(&pending_io_cond, &pending_io_lock);
   1.369 +    }
   1.370 +    
   1.371 +    if (io_prod == io_cons) {
   1.372 +        /* unnecessary wakeup. */
   1.373 +        pthread_mutex_unlock(&pending_io_lock);
   1.374 +        goto start;
   1.375 +    }
   1.376 +    
   1.377      req = PENDING_IO_ENT(io_cons++);
   1.378      pthread_mutex_unlock(&pending_io_lock);
   1.379 -	
   1.380 -    do_next_io_req(req);
   1.381 -    
   1.382 +	
   1.383 +    do_next_io_req(req);
   1.384 +    
   1.385      goto start;
   1.386 -	
   1.387 -}
   1.388 -
   1.389 -static pthread_t io_pool[IO_POOL_SIZE];
   1.390 -void start_io_threads(void)
   1.391 -
   1.392 -{	
   1.393 +	
   1.394 +}
   1.395 +
   1.396 +static pthread_t io_pool[IO_POOL_SIZE];
   1.397 +void start_io_threads(void)
   1.398 +
   1.399 +{	
   1.400      int i, tid=0;
   1.401      
   1.402      for (i=0; i < IO_POOL_SIZE; i++) {
   1.403 -        int ret, *t;
   1.404 -        t = (int *)malloc(sizeof(int));
   1.405 -        *t = tid++;
   1.406 -        ret = pthread_create(&io_pool[i], NULL, io_thread, t);
   1.407 -        if (ret != 0) printf("Error starting thread %d\n", i);
   1.408 -    }
   1.409 -	
   1.410 -}
   1.411 -
   1.412 -void init_block_async(void)
   1.413 -{
   1.414 +        int ret, *t;
   1.415 +        t = (int *)malloc(sizeof(int));
   1.416 +        *t = tid++;
   1.417 +        ret = pthread_create(&io_pool[i], NULL, io_thread, t);
   1.418 +        if (ret != 0) printf("Error starting thread %d\n", i);
   1.419 +    }
   1.420 +	
   1.421 +}
   1.422 +
   1.423 +void init_block_async(void)
   1.424 +{
   1.425      init_pending_io();
   1.426      start_io_threads();
   1.427 -}
   1.428 +}
     2.1 --- a/tools/blktap/block-async.h	Sat Jul 02 22:37:55 2005 +0000
     2.2 +++ b/tools/blktap/block-async.h	Sun Jul 03 12:02:01 2005 +0000
     2.3 @@ -1,69 +1,69 @@
     2.4 -/* block-async.h
     2.5 - * 
     2.6 - * Asynchronous block wrappers for parallax.
     2.7 - */
     2.8 - 
     2.9 -#ifndef _BLOCKASYNC_H_
    2.10 -#define _BLOCKASYNC_H_
    2.11 -
    2.12 -#include <assert.h>
    2.13 -#include <xc.h>
    2.14 -#include "vdi.h"
    2.15 -
    2.16 -struct io_ret
    2.17 -{
    2.18 +/* block-async.h
    2.19 + * 
    2.20 + * Asynchronous block wrappers for parallax.
    2.21 + */
    2.22 + 
    2.23 +#ifndef _BLOCKASYNC_H_
    2.24 +#define _BLOCKASYNC_H_
    2.25 +
    2.26 +#include <assert.h>
    2.27 +#include <xc.h>
    2.28 +#include "vdi.h"
    2.29 +
    2.30 +struct io_ret
    2.31 +{
    2.32      enum {IO_ADDR_T, IO_BLOCK_T, IO_INT_T} type;
    2.33      union {
    2.34          u64   a;
    2.35          char *b;
    2.36          int   i;
    2.37      } u;
    2.38 -};
    2.39 -
    2.40 -typedef void (*io_cb_t)(struct io_ret r, void *param);
    2.41 -
    2.42 -/* per-vdi lock structures to make sure requests run in a safe order. */
    2.43 -struct radix_wait {
    2.44 +};
    2.45 +
    2.46 +typedef void (*io_cb_t)(struct io_ret r, void *param);
    2.47 +
    2.48 +/* per-vdi lock structures to make sure requests run in a safe order. */
    2.49 +struct radix_wait {
    2.50      enum {RLOCK, WLOCK} type;
    2.51      io_cb_t  cb;
    2.52      void    *param;
    2.53      struct radix_wait *next;
    2.54 -};
    2.55 -
    2.56 -struct radix_lock {
    2.57 +};
    2.58 +
    2.59 +struct radix_lock {
    2.60      pthread_mutex_t lock;
    2.61      int                    lines[1024];
    2.62      struct radix_wait     *waiters[1024];
    2.63      enum {ANY, READ, STOP} state[1024];
    2.64 -};
    2.65 -void radix_lock_init(struct radix_lock *r);
    2.66 -
    2.67 -void block_read(u64 addr, io_cb_t cb, void *param);
    2.68 -void block_write(u64 addr, char *block, io_cb_t cb, void *param);
    2.69 -void block_alloc(char *block, io_cb_t cb, void *param);
    2.70 -void block_rlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
    2.71 -void block_wlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
    2.72 -void block_runlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
    2.73 -void block_wunlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
    2.74 -void init_block_async(void);
    2.75 -
    2.76 -static inline u64 IO_ADDR(struct io_ret r)
    2.77 -{
    2.78 +};
    2.79 +void radix_lock_init(struct radix_lock *r);
    2.80 +
    2.81 +void block_read(u64 addr, io_cb_t cb, void *param);
    2.82 +void block_write(u64 addr, char *block, io_cb_t cb, void *param);
    2.83 +void block_alloc(char *block, io_cb_t cb, void *param);
    2.84 +void block_rlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
    2.85 +void block_wlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
    2.86 +void block_runlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
    2.87 +void block_wunlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
    2.88 +void init_block_async(void);
    2.89 +
    2.90 +static inline u64 IO_ADDR(struct io_ret r)
    2.91 +{
    2.92      assert(r.type == IO_ADDR_T);
    2.93      return r.u.a;
    2.94 -}
    2.95 -
    2.96 -static inline char *IO_BLOCK(struct io_ret r)
    2.97 -{
    2.98 +}
    2.99 +
   2.100 +static inline char *IO_BLOCK(struct io_ret r)
   2.101 +{
   2.102      assert(r.type == IO_BLOCK_T);
   2.103      return r.u.b;
   2.104 -}
   2.105 -
   2.106 -static inline int IO_INT(struct io_ret r)
   2.107 -{
   2.108 +}
   2.109 +
   2.110 +static inline int IO_INT(struct io_ret r)
   2.111 +{
   2.112      assert(r.type == IO_INT_T);
   2.113      return r.u.i;
   2.114 -}
   2.115 -
   2.116 -
   2.117 -#endif //_BLOCKASYNC_H_
   2.118 +}
   2.119 +
   2.120 +
   2.121 +#endif //_BLOCKASYNC_H_
     3.1 --- a/tools/blktap/requests-async.c	Sat Jul 02 22:37:55 2005 +0000
     3.2 +++ b/tools/blktap/requests-async.c	Sun Jul 03 12:02:01 2005 +0000
     3.3 @@ -1,55 +1,55 @@
     3.4  /* requests-async.c
     3.5 - *
     3.6 + *
     3.7   * asynchronous request dispatcher for radix access in parallax.
     3.8 - */
     3.9 -
    3.10 -#include <stdio.h>
    3.11 -#include <stdlib.h>
    3.12 -#include <string.h>
    3.13 + */
    3.14 +
    3.15 +#include <stdio.h>
    3.16 +#include <stdlib.h>
    3.17 +#include <string.h>
    3.18  #include <ctype.h>
    3.19 -#include <assert.h>
    3.20 -#include <pthread.h>
    3.21 +#include <assert.h>
    3.22 +#include <pthread.h>
    3.23  #include <err.h>
    3.24  #include <zlib.h> /* for crc32() */
    3.25 -#include "requests-async.h"
    3.26 -#include "vdi.h"
    3.27 -#include "radix.h"
    3.28 -
    3.29 -#define L1_IDX(_a) (((_a) & 0x0000000007fc0000ULL) >> 18)
    3.30 -#define L2_IDX(_a) (((_a) & 0x000000000003fe00ULL) >> 9)
    3.31 -#define L3_IDX(_a) (((_a) & 0x00000000000001ffULL))
    3.32 -
    3.33 -
    3.34 -#if 0
    3.35 -#define DPRINTF(_f, _a...) printf ( _f , ## _a )
    3.36 -#else
    3.37 -#define DPRINTF(_f, _a...) ((void)0)
    3.38 -#endif
    3.39 -
    3.40 +#include "requests-async.h"
    3.41 +#include "vdi.h"
    3.42 +#include "radix.h"
    3.43 +
    3.44 +#define L1_IDX(_a) (((_a) & 0x0000000007fc0000ULL) >> 18)
    3.45 +#define L2_IDX(_a) (((_a) & 0x000000000003fe00ULL) >> 9)
    3.46 +#define L3_IDX(_a) (((_a) & 0x00000000000001ffULL))
    3.47 +
    3.48 +
    3.49 +#if 0
    3.50 +#define DPRINTF(_f, _a...) printf ( _f , ## _a )
    3.51 +#else
    3.52 +#define DPRINTF(_f, _a...) ((void)0)
    3.53 +#endif
    3.54 +
    3.55  struct block_info {
    3.56      u32        crc;
    3.57      u32        unused;
    3.58  };
    3.59 -
    3.60 -struct io_req {
    3.61 -    enum { IO_OP_READ, IO_OP_WRITE } op;
    3.62 -    u64        root;
    3.63 -    u64        vaddr;
    3.64 -    int        state;
    3.65 -    io_cb_t    cb;
    3.66 -    void      *param;
    3.67 -    struct radix_lock *lock;
    3.68 -
    3.69 -    /* internal stuff: */
    3.70 +
    3.71 +struct io_req {
    3.72 +    enum { IO_OP_READ, IO_OP_WRITE } op;
    3.73 +    u64        root;
    3.74 +    u64        vaddr;
    3.75 +    int        state;
    3.76 +    io_cb_t    cb;
    3.77 +    void      *param;
    3.78 +    struct radix_lock *lock;
    3.79 +
    3.80 +    /* internal stuff: */
    3.81      struct io_ret     retval;/* holds the return while we unlock. */
    3.82      char             *block; /* the block to write */
    3.83      radix_tree_node   radix[3];
    3.84      u64               radix_addr[3];
    3.85      struct block_info bi;
    3.86 -};
    3.87 -
    3.88 -void clear_w_bits(radix_tree_node node) 
    3.89 -{
    3.90 +};
    3.91 +
    3.92 +void clear_w_bits(radix_tree_node node) 
    3.93 +{
    3.94      int i;
    3.95      for (i=0; i<RADIX_TREE_MAP_ENTRIES; i++)
    3.96          node[i] = node[i] & ONEMASK;
    3.97 @@ -62,111 +62,111 @@ void clear_L3_w_bits(radix_tree_node nod
    3.98      for (i=0; i<RADIX_TREE_MAP_ENTRIES; i+=2)
    3.99          node[i] = node[i] & ONEMASK;
   3.100      return;
   3.101 -}
   3.102 -
   3.103 -enum states {
   3.104 -    /* both */
   3.105 -    READ_L1,
   3.106 -    READ_L2,
   3.107 -    READ_L3,
   3.108 -
   3.109 -    /* read */
   3.110 -    READ_LOCKED,
   3.111 -    READ_DATA,
   3.112 -    READ_UNLOCKED,
   3.113 -    RETURN_ZERO,
   3.114 -
   3.115 -    /* write */
   3.116 -    WRITE_LOCKED,
   3.117 -    WRITE_DATA,
   3.118 +}
   3.119 +
   3.120 +enum states {
   3.121 +    /* both */
   3.122 +    READ_L1,
   3.123 +    READ_L2,
   3.124 +    READ_L3,
   3.125 +
   3.126 +    /* read */
   3.127 +    READ_LOCKED,
   3.128 +    READ_DATA,
   3.129 +    READ_UNLOCKED,
   3.130 +    RETURN_ZERO,
   3.131 +
   3.132 +    /* write */
   3.133 +    WRITE_LOCKED,
   3.134 +    WRITE_DATA,
   3.135      WRITE_L3,
   3.136 -    WRITE_UNLOCKED,
   3.137 -    
   3.138 -    /* L3 Zero Path */
   3.139 -    ALLOC_DATA_L3z,
   3.140 -    WRITE_L3_L3z,
   3.141 -    
   3.142 -    /* L3 Fault Path */
   3.143 -    ALLOC_DATA_L3f,
   3.144 -    WRITE_L3_L3f,
   3.145 -    
   3.146 -    /* L2 Zero Path */
   3.147 -    ALLOC_DATA_L2z,
   3.148 -    WRITE_L2_L2z,
   3.149 -    ALLOC_L3_L2z,
   3.150 -    WRITE_L2_L3z,
   3.151 -    
   3.152 -    /* L2 Fault Path */
   3.153 -    READ_L3_L2f,
   3.154 -    ALLOC_DATA_L2f,
   3.155 -    WRITE_L2_L2f,
   3.156 -    ALLOC_L3_L2f,
   3.157 -    WRITE_L2_L3f,
   3.158 -
   3.159 +    WRITE_UNLOCKED,
   3.160 +    
   3.161 +    /* L3 Zero Path */
   3.162 +    ALLOC_DATA_L3z,
   3.163 +    WRITE_L3_L3z,
   3.164 +    
   3.165 +    /* L3 Fault Path */
   3.166 +    ALLOC_DATA_L3f,
   3.167 +    WRITE_L3_L3f,
   3.168 +    
   3.169 +    /* L2 Zero Path */
   3.170 +    ALLOC_DATA_L2z,
   3.171 +    WRITE_L2_L2z,
   3.172 +    ALLOC_L3_L2z,
   3.173 +    WRITE_L2_L3z,
   3.174 +    
   3.175 +    /* L2 Fault Path */
   3.176 +    READ_L3_L2f,
   3.177 +    ALLOC_DATA_L2f,
   3.178 +    WRITE_L2_L2f,
   3.179 +    ALLOC_L3_L2f,
   3.180 +    WRITE_L2_L3f,
   3.181 +
   3.182      /* L1 Zero Path */
   3.183 -    ALLOC_DATA_L1z,
   3.184 -    ALLOC_L3_L1z,
   3.185 -    ALLOC_L2_L1z,
   3.186 -    WRITE_L1_L1z,
   3.187 -
   3.188 +    ALLOC_DATA_L1z,
   3.189 +    ALLOC_L3_L1z,
   3.190 +    ALLOC_L2_L1z,
   3.191 +    WRITE_L1_L1z,
   3.192 +
   3.193      /* L1 Fault Path */
   3.194      READ_L2_L1f,
   3.195      READ_L3_L1f,
   3.196 -    ALLOC_DATA_L1f,
   3.197 -    ALLOC_L3_L1f,
   3.198 -    ALLOC_L2_L1f,
   3.199 -    WRITE_L1_L1f,
   3.200 -    
   3.201 -};
   3.202 -
   3.203 -enum radix_offsets {
   3.204 -    L1 = 0, 
   3.205 -    L2 = 1,
   3.206 -    L3 = 2
   3.207 -};
   3.208 -
   3.209 -
   3.210 -static void read_cb(struct io_ret ret, void *param);
   3.211 -static void write_cb(struct io_ret ret, void *param);
   3.212 -
   3.213 +    ALLOC_DATA_L1f,
   3.214 +    ALLOC_L3_L1f,
   3.215 +    ALLOC_L2_L1f,
   3.216 +    WRITE_L1_L1f,
   3.217 +    
   3.218 +};
   3.219 +
   3.220 +enum radix_offsets {
   3.221 +    L1 = 0, 
   3.222 +    L2 = 1,
   3.223 +    L3 = 2
   3.224 +};
   3.225 +
   3.226 +
   3.227 +static void read_cb(struct io_ret ret, void *param);
   3.228 +static void write_cb(struct io_ret ret, void *param);
   3.229 +
   3.230  int vdi_read(vdi_t *vdi, u64 vaddr, io_cb_t cb, void *param)
   3.231 -{
   3.232 -    struct io_req *req;
   3.233 -
   3.234 +{
   3.235 +    struct io_req *req;
   3.236 +
   3.237      if (!VALID_VADDR(vaddr)) return ERR_BAD_VADDR;
   3.238      /* Every second line in the bottom-level radix tree is used to      */
   3.239      /* store crc32 values etc. We shift the vadder here to achied this. */
   3.240      vaddr <<= 1;
   3.241 -
   3.242 -    req = (struct io_req *)malloc(sizeof (struct io_req));
   3.243 +
   3.244 +    req = (struct io_req *)malloc(sizeof (struct io_req));
   3.245      if (req == NULL) return ERR_NOMEM;
   3.246 -
   3.247 +
   3.248      req->radix[0] = req->radix[1] = req->radix[2] = NULL;	
   3.249 -    req->op    = IO_OP_READ;
   3.250 -    req->root  = vdi->radix_root;
   3.251 -    req->lock  = vdi->radix_lock; 
   3.252 -    req->vaddr = vaddr;
   3.253 -    req->cb    = cb;
   3.254 -    req->param = param;
   3.255 -    req->state = READ_LOCKED;
   3.256 -
   3.257 +    req->op    = IO_OP_READ;
   3.258 +    req->root  = vdi->radix_root;
   3.259 +    req->lock  = vdi->radix_lock; 
   3.260 +    req->vaddr = vaddr;
   3.261 +    req->cb    = cb;
   3.262 +    req->param = param;
   3.263 +    req->state = READ_LOCKED;
   3.264 +
   3.265      block_rlock(req->lock, L1_IDX(vaddr), read_cb, req);
   3.266 -	
   3.267 -    return 0;
   3.268 -}
   3.269 -
   3.270 -
   3.271 +	
   3.272 +    return 0;
   3.273 +}
   3.274 +
   3.275 +
   3.276  int   vdi_write(vdi_t *vdi, u64 vaddr, char *block, 
   3.277                  io_cb_t cb, void *param)
   3.278 -{
   3.279 -    struct io_req *req;
   3.280 -
   3.281 +{
   3.282 +    struct io_req *req;
   3.283 +
   3.284      if (!VALID_VADDR(vaddr)) return ERR_BAD_VADDR;
   3.285      /* Every second line in the bottom-level radix tree is used to      */
   3.286      /* store crc32 values etc. We shift the vadder here to achied this. */
   3.287      vaddr <<= 1;
   3.288 -
   3.289 -    req = (struct io_req *)malloc(sizeof (struct io_req));
   3.290 +
   3.291 +    req = (struct io_req *)malloc(sizeof (struct io_req));
   3.292      if (req == NULL) return ERR_NOMEM; 
   3.293  
   3.294      req->radix[0] = req->radix[1] = req->radix[2] = NULL;
   3.295 @@ -180,97 +180,97 @@ int   vdi_write(vdi_t *vdi, u64 vaddr, c
   3.296      req->bi.crc = (u32) crc32(0L, Z_NULL, 0); 
   3.297      req->bi.crc = (u32) crc32(req->bi.crc, block, BLOCK_SIZE); 
   3.298      req->bi.unused = 0xdeadbeef;
   3.299 -
   3.300 +
   3.301      req->cb     = cb;
   3.302      req->param  = param;
   3.303 -    req->radix_addr[L1] = getid(req->root); /* for consistency */
   3.304 +    req->radix_addr[L1] = getid(req->root); /* for consistency */
   3.305      req->state  = WRITE_LOCKED;
   3.306 -
   3.307 +
   3.308      block_wlock(req->lock, L1_IDX(vaddr), write_cb, req);
   3.309 -
   3.310 -
   3.311 +
   3.312 +
   3.313      return 0;
   3.314 -}
   3.315 -
   3.316 +}
   3.317 +
   3.318  static void read_cb(struct io_ret ret, void *param)
   3.319 -{
   3.320 -    struct io_req *req = (struct io_req *)param;
   3.321 -    radix_tree_node node;
   3.322 -    u64 idx;
   3.323 -    char *block;
   3.324 -    void *req_param;
   3.325 -
   3.326 -    DPRINTF("read_cb\n");
   3.327 -    /* get record */
   3.328 -    switch(req->state) {
   3.329 -    	
   3.330 -    case READ_LOCKED: 
   3.331 -    
   3.332 -        DPRINTF("READ_LOCKED\n");
   3.333 -    	req->state = READ_L1;
   3.334 -    	block_read(getid(req->root), read_cb, req); 
   3.335 -    	break;
   3.336 -    	
   3.337 -    case READ_L1: /* block is the radix root */
   3.338 -
   3.339 -        DPRINTF("READ_L1\n");
   3.340 -        block = IO_BLOCK(ret);
   3.341 -        if (block == NULL) goto fail;
   3.342 -        node = (radix_tree_node) block;
   3.343 -        idx  = getid( node[L1_IDX(req->vaddr)] );
   3.344 -        free(block);
   3.345 -        if ( idx == ZERO ) {
   3.346 +{
   3.347 +    struct io_req *req = (struct io_req *)param;
   3.348 +    radix_tree_node node;
   3.349 +    u64 idx;
   3.350 +    char *block;
   3.351 +    void *req_param;
   3.352 +
   3.353 +    DPRINTF("read_cb\n");
   3.354 +    /* get record */
   3.355 +    switch(req->state) {
   3.356 +    	
   3.357 +    case READ_LOCKED: 
   3.358 +    
   3.359 +        DPRINTF("READ_LOCKED\n");
   3.360 +    	req->state = READ_L1;
   3.361 +    	block_read(getid(req->root), read_cb, req); 
   3.362 +    	break;
   3.363 +    	
   3.364 +    case READ_L1: /* block is the radix root */
   3.365 +
   3.366 +        DPRINTF("READ_L1\n");
   3.367 +        block = IO_BLOCK(ret);
   3.368 +        if (block == NULL) goto fail;
   3.369 +        node = (radix_tree_node) block;
   3.370 +        idx  = getid( node[L1_IDX(req->vaddr)] );
   3.371 +        free(block);
   3.372 +        if ( idx == ZERO ) {
   3.373              req->state = RETURN_ZERO;
   3.374              block_runlock(req->lock, L1_IDX(req->vaddr), read_cb, req);
   3.375 -        } else {
   3.376 +        } else {
   3.377              req->state = READ_L2;
   3.378              block_read(idx, read_cb, req);
   3.379 -        }
   3.380 -        break;
   3.381 -
   3.382 -    case READ_L2:
   3.383 -
   3.384 -        DPRINTF("READ_L2\n");
   3.385 -        block = IO_BLOCK(ret);
   3.386 -        if (block == NULL) goto fail;
   3.387 -        node = (radix_tree_node) block;
   3.388 -        idx  = getid( node[L2_IDX(req->vaddr)] );
   3.389 -        free(block);
   3.390 -        if ( idx == ZERO ) {
   3.391 +        }
   3.392 +        break;
   3.393 +
   3.394 +    case READ_L2:
   3.395 +
   3.396 +        DPRINTF("READ_L2\n");
   3.397 +        block = IO_BLOCK(ret);
   3.398 +        if (block == NULL) goto fail;
   3.399 +        node = (radix_tree_node) block;
   3.400 +        idx  = getid( node[L2_IDX(req->vaddr)] );
   3.401 +        free(block);
   3.402 +        if ( idx == ZERO ) {
   3.403              req->state = RETURN_ZERO;
   3.404              block_runlock(req->lock, L1_IDX(req->vaddr), read_cb, req);
   3.405 -        } else {
   3.406 +        } else {
   3.407              req->state = READ_L3;
   3.408              block_read(idx, read_cb, req);
   3.409 -        }
   3.410 -        break;
   3.411 -
   3.412 -    case READ_L3:
   3.413 +        }
   3.414 +        break;
   3.415 +
   3.416 +    case READ_L3:
   3.417      {
   3.418          struct block_info *bi;
   3.419  
   3.420 -        DPRINTF("READ_L3\n");
   3.421 -        block = IO_BLOCK(ret);
   3.422 -        if (block == NULL) goto fail;
   3.423 -        node = (radix_tree_node) block;
   3.424 -        idx  = getid( node[L3_IDX(req->vaddr)] );
   3.425 +        DPRINTF("READ_L3\n");
   3.426 +        block = IO_BLOCK(ret);
   3.427 +        if (block == NULL) goto fail;
   3.428 +        node = (radix_tree_node) block;
   3.429 +        idx  = getid( node[L3_IDX(req->vaddr)] );
   3.430          bi = (struct block_info *) &node[L3_IDX(req->vaddr) + 1];
   3.431          req->bi = *bi;
   3.432 -        free(block);
   3.433 -        if ( idx == ZERO )  {
   3.434 +        free(block);
   3.435 +        if ( idx == ZERO )  {
   3.436              req->state = RETURN_ZERO;
   3.437              block_runlock(req->lock, L1_IDX(req->vaddr), read_cb, req);
   3.438 -        } else {
   3.439 +        } else {
   3.440              req->state = READ_DATA;
   3.441              block_read(idx, read_cb, req);
   3.442 -        }
   3.443 -        break;
   3.444 +        }
   3.445 +        break;
   3.446      }
   3.447 -    case READ_DATA:
   3.448 +    case READ_DATA:
   3.449      {
   3.450          u32 crc;
   3.451  
   3.452 -        DPRINTF("READ_DATA\n");
   3.453 +        DPRINTF("READ_DATA\n");
   3.454          block = IO_BLOCK(ret);
   3.455          if (block == NULL) goto fail;
   3.456  
   3.457 @@ -301,151 +301,151 @@ static void read_cb(struct io_ret ret, v
   3.458              /* goto fail;                     */
   3.459          }
   3.460  
   3.461 -        req->retval = ret;
   3.462 -        req->state = READ_UNLOCKED;
   3.463 -        block_runlock(req->lock, L1_IDX(req->vaddr), read_cb, req);
   3.464 -        break;
   3.465 +        req->retval = ret;
   3.466 +        req->state = READ_UNLOCKED;
   3.467 +        block_runlock(req->lock, L1_IDX(req->vaddr), read_cb, req);
   3.468 +        break;
   3.469      }
   3.470 -    case READ_UNLOCKED:
   3.471 +    case READ_UNLOCKED:
   3.472      {
   3.473          struct io_ret r;
   3.474          io_cb_t cb;
   3.475 -        DPRINTF("READ_UNLOCKED\n");
   3.476 -        req_param = req->param;
   3.477 -        r         = req->retval;
   3.478 -        cb        = req->cb;
   3.479 -        free(req);
   3.480 -        cb(r, req_param);
   3.481 -        break;
   3.482 -    }
   3.483 -    
   3.484 -    case RETURN_ZERO:
   3.485 +        DPRINTF("READ_UNLOCKED\n");
   3.486 +        req_param = req->param;
   3.487 +        r         = req->retval;
   3.488 +        cb        = req->cb;
   3.489 +        free(req);
   3.490 +        cb(r, req_param);
   3.491 +        break;
   3.492 +    }
   3.493 +    
   3.494 +    case RETURN_ZERO:
   3.495      {
   3.496          struct io_ret r;
   3.497          io_cb_t cb;
   3.498          DPRINTF("RETURN_ZERO\n");
   3.499          req_param = req->param;
   3.500 -        cb        = req->cb;
   3.501 +        cb        = req->cb;
   3.502          free(req);
   3.503 -        r.type = IO_BLOCK_T;
   3.504 -        r.u.b = newblock();
   3.505 +        r.type = IO_BLOCK_T;
   3.506 +        r.u.b = newblock();
   3.507          cb(r, req_param);
   3.508          break;
   3.509      }
   3.510 -        
   3.511 -    default:
   3.512 -    	DPRINTF("*** Write: Bad state! (%d) ***\n", req->state);
   3.513 -    	goto fail;
   3.514 -    }
   3.515 - 
   3.516 -    return;
   3.517 -
   3.518 - fail:
   3.519 +        
   3.520 +    default:
   3.521 +    	DPRINTF("*** Write: Bad state! (%d) ***\n", req->state);
   3.522 +    	goto fail;
   3.523 +    }
   3.524 + 
   3.525 +    return;
   3.526 +
   3.527 + fail:
   3.528      {
   3.529          struct io_ret r;
   3.530          io_cb_t cb;
   3.531          DPRINTF("asyn_read had a read error.\n");
   3.532 -        req_param = req->param;
   3.533 -        r         = ret;
   3.534 -        cb        = req->cb;
   3.535 -        free(req);
   3.536 -        cb(r, req_param);
   3.537 +        req_param = req->param;
   3.538 +        r         = ret;
   3.539 +        cb        = req->cb;
   3.540 +        free(req);
   3.541 +        cb(r, req_param);
   3.542      }
   3.543 -
   3.544 -
   3.545 -}
   3.546 -
   3.547 +
   3.548 +
   3.549 +}
   3.550 +
   3.551  static void write_cb(struct io_ret r, void *param)
   3.552 -{
   3.553 -    struct io_req *req = (struct io_req *)param;
   3.554 -    radix_tree_node node;
   3.555 -    u64 a, addr;
   3.556 -    void *req_param;
   3.557 +{
   3.558 +    struct io_req *req = (struct io_req *)param;
   3.559 +    radix_tree_node node;
   3.560 +    u64 a, addr;
   3.561 +    void *req_param;
   3.562      struct block_info *bi;
   3.563 -
   3.564 -    switch(req->state) {
   3.565 -    	
   3.566 -    case WRITE_LOCKED:
   3.567 +
   3.568 +    switch(req->state) {
   3.569 +    	
   3.570 +    case WRITE_LOCKED:
   3.571          
   3.572 -        DPRINTF("WRITE_LOCKED (%llu)\n", L1_IDX(req->vaddr));
   3.573 -    	req->state = READ_L1;
   3.574 -    	block_read(getid(req->root), write_cb, req); 
   3.575 -    	break;
   3.576 -    	
   3.577 -    case READ_L1: /* block is the radix root */
   3.578 -
   3.579 -        DPRINTF("READ_L1\n");
   3.580 -        node = (radix_tree_node) IO_BLOCK(r);
   3.581 -        if (node == NULL) goto fail;
   3.582 -        a    = node[L1_IDX(req->vaddr)];
   3.583 -        addr = getid(a);
   3.584 -
   3.585 -        req->radix_addr[L2] = addr;
   3.586 -        req->radix[L1] = node;
   3.587 -
   3.588 -        if ( addr == ZERO ) {
   3.589 +        DPRINTF("WRITE_LOCKED (%llu)\n", L1_IDX(req->vaddr));
   3.590 +    	req->state = READ_L1;
   3.591 +    	block_read(getid(req->root), write_cb, req); 
   3.592 +    	break;
   3.593 +    	
   3.594 +    case READ_L1: /* block is the radix root */
   3.595 +
   3.596 +        DPRINTF("READ_L1\n");
   3.597 +        node = (radix_tree_node) IO_BLOCK(r);
   3.598 +        if (node == NULL) goto fail;
   3.599 +        a    = node[L1_IDX(req->vaddr)];
   3.600 +        addr = getid(a);
   3.601 +
   3.602 +        req->radix_addr[L2] = addr;
   3.603 +        req->radix[L1] = node;
   3.604 +
   3.605 +        if ( addr == ZERO ) {
   3.606              /* L1 empty subtree: */
   3.607              req->state = ALLOC_DATA_L1z;
   3.608              block_alloc( req->block, write_cb, req );
   3.609 -        } else if ( !iswritable(a) ) {
   3.610 -            /* L1 fault: */
   3.611 -            req->state = READ_L2_L1f;
   3.612 -            block_read( addr, write_cb, req );
   3.613 -        } else {
   3.614 -            req->state = READ_L2;
   3.615 -            block_read( addr, write_cb, req );
   3.616 -        }
   3.617 -        break;
   3.618 -    
   3.619 -    case READ_L2:
   3.620 -
   3.621 -        DPRINTF("READ_L2\n");
   3.622 -        node = (radix_tree_node) IO_BLOCK(r);
   3.623 -        if (node == NULL) goto fail;
   3.624 -        a    = node[L2_IDX(req->vaddr)];
   3.625 -        addr = getid(a);
   3.626 -
   3.627 -        req->radix_addr[L3] = addr;
   3.628 -        req->radix[L2] = node;
   3.629 -
   3.630 -        if ( addr == ZERO ) {
   3.631 +        } else if ( !iswritable(a) ) {
   3.632 +            /* L1 fault: */
   3.633 +            req->state = READ_L2_L1f;
   3.634 +            block_read( addr, write_cb, req );
   3.635 +        } else {
   3.636 +            req->state = READ_L2;
   3.637 +            block_read( addr, write_cb, req );
   3.638 +        }
   3.639 +        break;
   3.640 +    
   3.641 +    case READ_L2:
   3.642 +
   3.643 +        DPRINTF("READ_L2\n");
   3.644 +        node = (radix_tree_node) IO_BLOCK(r);
   3.645 +        if (node == NULL) goto fail;
   3.646 +        a    = node[L2_IDX(req->vaddr)];
   3.647 +        addr = getid(a);
   3.648 +
   3.649 +        req->radix_addr[L3] = addr;
   3.650 +        req->radix[L2] = node;
   3.651 +
   3.652 +        if ( addr == ZERO ) {
   3.653              /* L2 empty subtree: */
   3.654 -            req->state = ALLOC_DATA_L2z;
   3.655 -            block_alloc( req->block, write_cb, req );
   3.656 -        } else if ( !iswritable(a) ) {
   3.657 -            /* L2 fault: */
   3.658 -            req->state = READ_L3_L2f;
   3.659 -            block_read( addr, write_cb, req );
   3.660 -        } else {
   3.661 -            req->state = READ_L3;
   3.662 -            block_read( addr, write_cb, req );
   3.663 -        }
   3.664 -        break;
   3.665 -    
   3.666 -    case READ_L3:
   3.667 -
   3.668 -        DPRINTF("READ_L3\n");
   3.669 -        node = (radix_tree_node) IO_BLOCK(r);
   3.670 -        if (node == NULL) goto fail;
   3.671 -        a    = node[L3_IDX(req->vaddr)];
   3.672 -        addr = getid(a);
   3.673 -
   3.674 -        req->radix[L3] = node;
   3.675 -
   3.676 -        if ( addr == ZERO ) {
   3.677 -            /* L3 fault: */
   3.678 -            req->state = ALLOC_DATA_L3z;
   3.679 -            block_alloc( req->block, write_cb, req );
   3.680 -        } else if ( !iswritable(a) ) {
   3.681 -            /* L3 fault: */
   3.682 -            req->state = ALLOC_DATA_L3f;
   3.683 -            block_alloc( req->block, write_cb, req );
   3.684 -        } else {
   3.685 -            req->state = WRITE_DATA;
   3.686 -            block_write( addr, req->block, write_cb, req );
   3.687 -        }
   3.688 -        break;
   3.689 -    
   3.690 +            req->state = ALLOC_DATA_L2z;
   3.691 +            block_alloc( req->block, write_cb, req );
   3.692 +        } else if ( !iswritable(a) ) {
   3.693 +            /* L2 fault: */
   3.694 +            req->state = READ_L3_L2f;
   3.695 +            block_read( addr, write_cb, req );
   3.696 +        } else {
   3.697 +            req->state = READ_L3;
   3.698 +            block_read( addr, write_cb, req );
   3.699 +        }
   3.700 +        break;
   3.701 +    
   3.702 +    case READ_L3:
   3.703 +
   3.704 +        DPRINTF("READ_L3\n");
   3.705 +        node = (radix_tree_node) IO_BLOCK(r);
   3.706 +        if (node == NULL) goto fail;
   3.707 +        a    = node[L3_IDX(req->vaddr)];
   3.708 +        addr = getid(a);
   3.709 +
   3.710 +        req->radix[L3] = node;
   3.711 +
   3.712 +        if ( addr == ZERO ) {
   3.713 +            /* L3 fault: */
   3.714 +            req->state = ALLOC_DATA_L3z;
   3.715 +            block_alloc( req->block, write_cb, req );
   3.716 +        } else if ( !iswritable(a) ) {
   3.717 +            /* L3 fault: */
   3.718 +            req->state = ALLOC_DATA_L3f;
   3.719 +            block_alloc( req->block, write_cb, req );
   3.720 +        } else {
   3.721 +            req->state = WRITE_DATA;
   3.722 +            block_write( addr, req->block, write_cb, req );
   3.723 +        }
   3.724 +        break;
   3.725 +    
   3.726      case WRITE_DATA:
   3.727  
   3.728          DPRINTF("WRITE_DATA\n");
   3.729 @@ -459,268 +459,268 @@ static void write_cb(struct io_ret r, vo
   3.730          block_write(req->radix_addr[L3], (char*)req->radix[L3], write_cb, req);
   3.731          break;
   3.732      
   3.733 -    /* L3 Zero Path: */
   3.734 -
   3.735 -    case ALLOC_DATA_L3z:
   3.736 -
   3.737 -        DPRINTF("ALLOC_DATA_L3z\n");
   3.738 -        addr = IO_ADDR(r);
   3.739 -        a = writable(addr);
   3.740 -        req->radix[L3][L3_IDX(req->vaddr)] = a;
   3.741 +    /* L3 Zero Path: */
   3.742 +
   3.743 +    case ALLOC_DATA_L3z:
   3.744 +
   3.745 +        DPRINTF("ALLOC_DATA_L3z\n");
   3.746 +        addr = IO_ADDR(r);
   3.747 +        a = writable(addr);
   3.748 +        req->radix[L3][L3_IDX(req->vaddr)] = a;
   3.749          bi  = (struct block_info *) &req->radix[L3][L3_IDX(req->vaddr)+1];
   3.750          req->bi.unused = 102;
   3.751          *bi = req->bi;
   3.752 -        req->state = WRITE_L3_L3z;
   3.753 -        block_write(req->radix_addr[L3], (char*)req->radix[L3], write_cb, req);
   3.754 -        break;
   3.755 -    
   3.756 -    /* L3 Fault Path: */
   3.757 -
   3.758 -    case ALLOC_DATA_L3f:
   3.759 +        req->state = WRITE_L3_L3z;
   3.760 +        block_write(req->radix_addr[L3], (char*)req->radix[L3], write_cb, req);
   3.761 +        break;
   3.762      
   3.763 -        DPRINTF("ALLOC_DATA_L3f\n");
   3.764 -        addr = IO_ADDR(r);
   3.765 -        a = writable(addr);
   3.766 -        req->radix[L3][L3_IDX(req->vaddr)] = a;
   3.767 +    /* L3 Fault Path: */
   3.768 +
   3.769 +    case ALLOC_DATA_L3f:
   3.770 +    
   3.771 +        DPRINTF("ALLOC_DATA_L3f\n");
   3.772 +        addr = IO_ADDR(r);
   3.773 +        a = writable(addr);
   3.774 +        req->radix[L3][L3_IDX(req->vaddr)] = a;
   3.775          bi  = (struct block_info *) &req->radix[L3][L3_IDX(req->vaddr)+1];
   3.776          req->bi.unused = 103;
   3.777          *bi = req->bi;
   3.778 -        req->state = WRITE_L3_L3f;
   3.779 -        block_write(req->radix_addr[L3], (char*)req->radix[L3], write_cb, req);
   3.780 -        break;
   3.781 -
   3.782 -    /* L2 Zero Path: */
   3.783 -        
   3.784 -    case ALLOC_DATA_L2z:
   3.785 -
   3.786 -        DPRINTF("ALLOC_DATA_L2z\n");
   3.787 -        addr = IO_ADDR(r);
   3.788 -        a = writable(addr);
   3.789 -        req->radix[L3] = newblock();
   3.790 -        req->radix[L3][L3_IDX(req->vaddr)] = a;
   3.791 +        req->state = WRITE_L3_L3f;
   3.792 +        block_write(req->radix_addr[L3], (char*)req->radix[L3], write_cb, req);
   3.793 +        break;
   3.794 +
   3.795 +    /* L2 Zero Path: */
   3.796 +        
   3.797 +    case ALLOC_DATA_L2z:
   3.798 +
   3.799 +        DPRINTF("ALLOC_DATA_L2z\n");
   3.800 +        addr = IO_ADDR(r);
   3.801 +        a = writable(addr);
   3.802 +        req->radix[L3] = newblock();
   3.803 +        req->radix[L3][L3_IDX(req->vaddr)] = a;
   3.804          bi  = (struct block_info *) &req->radix[L3][L3_IDX(req->vaddr)+1];
   3.805          req->bi.unused = 104;
   3.806          *bi = req->bi;
   3.807 -        req->state = ALLOC_L3_L2z;
   3.808 -        block_alloc( (char*)req->radix[L3], write_cb, req );
   3.809 -        break;
   3.810 -
   3.811 -    case ALLOC_L3_L2z:
   3.812 -
   3.813 -        DPRINTF("ALLOC_L3_L2z\n");
   3.814 -        addr = IO_ADDR(r);
   3.815 -        a = writable(addr);
   3.816 -        req->radix[L2][L2_IDX(req->vaddr)] = a;
   3.817 -        req->state = WRITE_L2_L2z;
   3.818 -        block_write(req->radix_addr[L2], (char*)req->radix[L2], write_cb, req);
   3.819 -        break;
   3.820 -        
   3.821 -    /* L2 Fault Path: */
   3.822 -        
   3.823 -    case READ_L3_L2f:
   3.824 -    
   3.825 -    	DPRINTF("READ_L3_L2f\n");
   3.826 -        node = (radix_tree_node) IO_BLOCK(r);
   3.827 +        req->state = ALLOC_L3_L2z;
   3.828 +        block_alloc( (char*)req->radix[L3], write_cb, req );
   3.829 +        break;
   3.830 +
   3.831 +    case ALLOC_L3_L2z:
   3.832 +
   3.833 +        DPRINTF("ALLOC_L3_L2z\n");
   3.834 +        addr = IO_ADDR(r);
   3.835 +        a = writable(addr);
   3.836 +        req->radix[L2][L2_IDX(req->vaddr)] = a;
   3.837 +        req->state = WRITE_L2_L2z;
   3.838 +        block_write(req->radix_addr[L2], (char*)req->radix[L2], write_cb, req);
   3.839 +        break;
   3.840 +        
   3.841 +    /* L2 Fault Path: */
   3.842 +        
   3.843 +    case READ_L3_L2f:
   3.844 +    
   3.845 +    	DPRINTF("READ_L3_L2f\n");
   3.846 +        node = (radix_tree_node) IO_BLOCK(r);
   3.847          clear_L3_w_bits(node);
   3.848 -        if (node == NULL) goto fail;
   3.849 -        a    = node[L2_IDX(req->vaddr)];
   3.850 -        addr = getid(a);
   3.851 -
   3.852 -        req->radix[L3] = node;
   3.853 +        if (node == NULL) goto fail;
   3.854 +        a    = node[L2_IDX(req->vaddr)];
   3.855 +        addr = getid(a);
   3.856 +
   3.857 +        req->radix[L3] = node;
   3.858          req->state = ALLOC_DATA_L2f;
   3.859 -        block_alloc( req->block, write_cb, req );
   3.860 -        break;
   3.861 -                
   3.862 -    case ALLOC_DATA_L2f:
   3.863 -
   3.864 -        DPRINTF("ALLOC_DATA_L2f\n");
   3.865 -        addr = IO_ADDR(r);
   3.866 -        a = writable(addr);
   3.867 -        req->radix[L3][L3_IDX(req->vaddr)] = a;
   3.868 +        block_alloc( req->block, write_cb, req );
   3.869 +        break;
   3.870 +                
   3.871 +    case ALLOC_DATA_L2f:
   3.872 +
   3.873 +        DPRINTF("ALLOC_DATA_L2f\n");
   3.874 +        addr = IO_ADDR(r);
   3.875 +        a = writable(addr);
   3.876 +        req->radix[L3][L3_IDX(req->vaddr)] = a;
   3.877          bi  = (struct block_info *) &req->radix[L3][L3_IDX(req->vaddr)+1];
   3.878          req->bi.unused = 105;
   3.879          *bi = req->bi;
   3.880 -        req->state = ALLOC_L3_L2f;
   3.881 -        block_alloc( (char*)req->radix[L3], write_cb, req );
   3.882 -        break;
   3.883 -
   3.884 -    case ALLOC_L3_L2f:
   3.885 -
   3.886 -        DPRINTF("ALLOC_L3_L2f\n");
   3.887 -        addr = IO_ADDR(r);
   3.888 -        a = writable(addr);
   3.889 -        req->radix[L2][L2_IDX(req->vaddr)] = a;
   3.890 -        req->state = WRITE_L2_L2f;
   3.891 -        block_write(req->radix_addr[L2], (char*)req->radix[L2], write_cb, req);
   3.892 -        break;
   3.893 -        
   3.894 -    /* L1 Zero Path: */
   3.895 -    
   3.896 -    case ALLOC_DATA_L1z:
   3.897 -
   3.898 -        DPRINTF("ALLOC_DATA_L1z\n");
   3.899 -        addr = IO_ADDR(r);
   3.900 -        a = writable(addr);
   3.901 -        req->radix[L3] = newblock();
   3.902 -        req->radix[L3][L3_IDX(req->vaddr)] = a;
   3.903 +        req->state = ALLOC_L3_L2f;
   3.904 +        block_alloc( (char*)req->radix[L3], write_cb, req );
   3.905 +        break;
   3.906 +
   3.907 +    case ALLOC_L3_L2f:
   3.908 +
   3.909 +        DPRINTF("ALLOC_L3_L2f\n");
   3.910 +        addr = IO_ADDR(r);
   3.911 +        a = writable(addr);
   3.912 +        req->radix[L2][L2_IDX(req->vaddr)] = a;
   3.913 +        req->state = WRITE_L2_L2f;
   3.914 +        block_write(req->radix_addr[L2], (char*)req->radix[L2], write_cb, req);
   3.915 +        break;
   3.916 +        
   3.917 +    /* L1 Zero Path: */
   3.918 +    
   3.919 +    case ALLOC_DATA_L1z:
   3.920 +
   3.921 +        DPRINTF("ALLOC_DATA_L1z\n");
   3.922 +        addr = IO_ADDR(r);
   3.923 +        a = writable(addr);
   3.924 +        req->radix[L3] = newblock();
   3.925 +        req->radix[L3][L3_IDX(req->vaddr)] = a;
   3.926          bi  = (struct block_info *) &req->radix[L3][L3_IDX(req->vaddr)+1];
   3.927          req->bi.unused = 106;
   3.928          *bi = req->bi;
   3.929 -        req->state = ALLOC_L3_L1z;
   3.930 -        block_alloc( (char*)req->radix[L3], write_cb, req );
   3.931 -        break;
   3.932 +        req->state = ALLOC_L3_L1z;
   3.933 +        block_alloc( (char*)req->radix[L3], write_cb, req );
   3.934 +        break;
   3.935          
   3.936 -    case ALLOC_L3_L1z:
   3.937 -
   3.938 -        DPRINTF("ALLOC_L3_L1z\n");
   3.939 -        addr = IO_ADDR(r);
   3.940 -        a = writable(addr);
   3.941 -        req->radix[L2] = newblock();
   3.942 -        req->radix[L2][L2_IDX(req->vaddr)] = a;
   3.943 -        req->state = ALLOC_L2_L1z;
   3.944 -        block_alloc( (char*)req->radix[L2], write_cb, req );
   3.945 -        break;
   3.946 -
   3.947 -    case ALLOC_L2_L1z:
   3.948 -
   3.949 -        DPRINTF("ALLOC_L2_L1z\n");
   3.950 -        addr = IO_ADDR(r);
   3.951 -        a = writable(addr);
   3.952 -        req->radix[L1][L1_IDX(req->vaddr)] = a;
   3.953 -        req->state = WRITE_L1_L1z;
   3.954 -        block_write(req->radix_addr[L1], (char*)req->radix[L1], write_cb, req);
   3.955 -        break;
   3.956 -
   3.957 -    /* L1 Fault Path: */
   3.958 -        
   3.959 -    case READ_L2_L1f:
   3.960 -    
   3.961 -    	DPRINTF("READ_L2_L1f\n");
   3.962 -        node = (radix_tree_node) IO_BLOCK(r);
   3.963 -        clear_w_bits(node);
   3.964 -        if (node == NULL) goto fail;
   3.965 -        a    = node[L2_IDX(req->vaddr)];
   3.966 -        addr = getid(a);
   3.967 -
   3.968 -        req->radix_addr[L3] = addr;
   3.969 -        req->radix[L2] = node;
   3.970 -        
   3.971 -        if (addr == ZERO) {
   3.972 +    case ALLOC_L3_L1z:
   3.973 +
   3.974 +        DPRINTF("ALLOC_L3_L1z\n");
   3.975 +        addr = IO_ADDR(r);
   3.976 +        a = writable(addr);
   3.977 +        req->radix[L2] = newblock();
   3.978 +        req->radix[L2][L2_IDX(req->vaddr)] = a;
   3.979 +        req->state = ALLOC_L2_L1z;
   3.980 +        block_alloc( (char*)req->radix[L2], write_cb, req );
   3.981 +        break;
   3.982 +
   3.983 +    case ALLOC_L2_L1z:
   3.984 +
   3.985 +        DPRINTF("ALLOC_L2_L1z\n");
   3.986 +        addr = IO_ADDR(r);
   3.987 +        a = writable(addr);
   3.988 +        req->radix[L1][L1_IDX(req->vaddr)] = a;
   3.989 +        req->state = WRITE_L1_L1z;
   3.990 +        block_write(req->radix_addr[L1], (char*)req->radix[L1], write_cb, req);
   3.991 +        break;
   3.992 +
   3.993 +    /* L1 Fault Path: */
   3.994 +        
   3.995 +    case READ_L2_L1f:
   3.996 +    
   3.997 +    	DPRINTF("READ_L2_L1f\n");
   3.998 +        node = (radix_tree_node) IO_BLOCK(r);
   3.999 +        clear_w_bits(node);
  3.1000 +        if (node == NULL) goto fail;
  3.1001 +        a    = node[L2_IDX(req->vaddr)];
  3.1002 +        addr = getid(a);
  3.1003 +
  3.1004 +        req->radix_addr[L3] = addr;
  3.1005 +        req->radix[L2] = node;
  3.1006 +        
  3.1007 +        if (addr == ZERO) {
  3.1008              /* nothing below L2, create an empty L3 and alloc data. */
  3.1009              /* (So skip READ_L3_L1f.) */
  3.1010              req->radix[L3] = newblock();
  3.1011              req->state = ALLOC_DATA_L1f;
  3.1012              block_alloc( req->block, write_cb, req );
  3.1013 -        } else {
  3.1014 +        } else {
  3.1015              req->state = READ_L3_L1f;
  3.1016              block_read( addr, write_cb, req );
  3.1017 -        }
  3.1018 -        break;
  3.1019 -        
  3.1020 -    case READ_L3_L1f:
  3.1021 -    
  3.1022 -    	DPRINTF("READ_L3_L1f\n");
  3.1023 -        node = (radix_tree_node) IO_BLOCK(r);
  3.1024 +        }
  3.1025 +        break;
  3.1026 +        
  3.1027 +    case READ_L3_L1f:
  3.1028 +    
  3.1029 +    	DPRINTF("READ_L3_L1f\n");
  3.1030 +        node = (radix_tree_node) IO_BLOCK(r);
  3.1031          clear_L3_w_bits(node);
  3.1032 -        if (node == NULL) goto fail;
  3.1033 -        a    = node[L2_IDX(req->vaddr)];
  3.1034 -        addr = getid(a);
  3.1035 -
  3.1036 -        req->radix[L3] = node;
  3.1037 +        if (node == NULL) goto fail;
  3.1038 +        a    = node[L2_IDX(req->vaddr)];
  3.1039 +        addr = getid(a);
  3.1040 +
  3.1041 +        req->radix[L3] = node;
  3.1042          req->state = ALLOC_DATA_L1f;
  3.1043 -        block_alloc( req->block, write_cb, req );
  3.1044 -        break;
  3.1045 -                
  3.1046 -    case ALLOC_DATA_L1f:
  3.1047 -
  3.1048 -        DPRINTF("ALLOC_DATA_L1f\n");
  3.1049 -        addr = IO_ADDR(r);
  3.1050 -        a = writable(addr);
  3.1051 -        req->radix[L3][L3_IDX(req->vaddr)] = a;
  3.1052 +        block_alloc( req->block, write_cb, req );
  3.1053 +        break;
  3.1054 +                
  3.1055 +    case ALLOC_DATA_L1f:
  3.1056 +
  3.1057 +        DPRINTF("ALLOC_DATA_L1f\n");
  3.1058 +        addr = IO_ADDR(r);
  3.1059 +        a = writable(addr);
  3.1060 +        req->radix[L3][L3_IDX(req->vaddr)] = a;
  3.1061          bi  = (struct block_info *) &req->radix[L3][L3_IDX(req->vaddr)+1];
  3.1062          req->bi.unused = 107;
  3.1063          *bi = req->bi;
  3.1064 -        req->state = ALLOC_L3_L1f;
  3.1065 -        block_alloc( (char*)req->radix[L3], write_cb, req );
  3.1066 -        break;
  3.1067 -
  3.1068 -    case ALLOC_L3_L1f:
  3.1069 -
  3.1070 -        DPRINTF("ALLOC_L3_L1f\n");
  3.1071 -        addr = IO_ADDR(r);
  3.1072 -        a = writable(addr);
  3.1073 -        req->radix[L2][L2_IDX(req->vaddr)] = a;
  3.1074 -        req->state = ALLOC_L2_L1f;
  3.1075 -        block_alloc( (char*)req->radix[L2], write_cb, req );
  3.1076 -        break;
  3.1077 -
  3.1078 -    case ALLOC_L2_L1f:
  3.1079 -
  3.1080 -        DPRINTF("ALLOC_L2_L1f\n");
  3.1081 -        addr = IO_ADDR(r);
  3.1082 -        a = writable(addr);
  3.1083 -        req->radix[L1][L1_IDX(req->vaddr)] = a;
  3.1084 -        req->state = WRITE_L1_L1f;
  3.1085 -        block_write(req->radix_addr[L1], (char*)req->radix[L1], write_cb, req);
  3.1086 -        break;
  3.1087 -
  3.1088 +        req->state = ALLOC_L3_L1f;
  3.1089 +        block_alloc( (char*)req->radix[L3], write_cb, req );
  3.1090 +        break;
  3.1091 +
  3.1092 +    case ALLOC_L3_L1f:
  3.1093 +
  3.1094 +        DPRINTF("ALLOC_L3_L1f\n");
  3.1095 +        addr = IO_ADDR(r);
  3.1096 +        a = writable(addr);
  3.1097 +        req->radix[L2][L2_IDX(req->vaddr)] = a;
  3.1098 +        req->state = ALLOC_L2_L1f;
  3.1099 +        block_alloc( (char*)req->radix[L2], write_cb, req );
  3.1100 +        break;
  3.1101 +
  3.1102 +    case ALLOC_L2_L1f:
  3.1103 +
  3.1104 +        DPRINTF("ALLOC_L2_L1f\n");
  3.1105 +        addr = IO_ADDR(r);
  3.1106 +        a = writable(addr);
  3.1107 +        req->radix[L1][L1_IDX(req->vaddr)] = a;
  3.1108 +        req->state = WRITE_L1_L1f;
  3.1109 +        block_write(req->radix_addr[L1], (char*)req->radix[L1], write_cb, req);
  3.1110 +        break;
  3.1111 +
  3.1112      case WRITE_L3:
  3.1113 -    case WRITE_L3_L3z:
  3.1114 -    case WRITE_L3_L3f:
  3.1115 -    case WRITE_L2_L2z:
  3.1116 -    case WRITE_L2_L2f:
  3.1117 -    case WRITE_L1_L1z:
  3.1118 -    case WRITE_L1_L1f:
  3.1119 -    {
  3.1120 -    	int i;
  3.1121 -        DPRINTF("DONE\n");
  3.1122 -        /* free any saved node vals. */
  3.1123 -        for (i=0; i<3; i++)
  3.1124 +    case WRITE_L3_L3z:
  3.1125 +    case WRITE_L3_L3f:
  3.1126 +    case WRITE_L2_L2z:
  3.1127 +    case WRITE_L2_L2f:
  3.1128 +    case WRITE_L1_L1z:
  3.1129 +    case WRITE_L1_L1f:
  3.1130 +    {
  3.1131 +    	int i;
  3.1132 +        DPRINTF("DONE\n");
  3.1133 +        /* free any saved node vals. */
  3.1134 +        for (i=0; i<3; i++)
  3.1135              if (req->radix[i] != 0) free(req->radix[i]);
  3.1136 -        req->retval = r;
  3.1137 -        req->state = WRITE_UNLOCKED;
  3.1138 -        block_wunlock(req->lock, L1_IDX(req->vaddr), write_cb, req);
  3.1139 -        break;
  3.1140 -    }
  3.1141 -    case WRITE_UNLOCKED:
  3.1142 -    {
  3.1143 +        req->retval = r;
  3.1144 +        req->state = WRITE_UNLOCKED;
  3.1145 +        block_wunlock(req->lock, L1_IDX(req->vaddr), write_cb, req);
  3.1146 +        break;
  3.1147 +    }
  3.1148 +    case WRITE_UNLOCKED:
  3.1149 +    {
  3.1150          struct io_ret r;
  3.1151          io_cb_t cb;
  3.1152 -        DPRINTF("WRITE_UNLOCKED!\n");
  3.1153 -        req_param = req->param;
  3.1154 -        r         = req->retval;
  3.1155 -        cb        = req->cb;
  3.1156 +        DPRINTF("WRITE_UNLOCKED!\n");
  3.1157 +        req_param = req->param;
  3.1158 +        r         = req->retval;
  3.1159 +        cb        = req->cb;
  3.1160          free(req);
  3.1161 -        cb(r, req_param);
  3.1162 -        break;
  3.1163 -    }
  3.1164 -        
  3.1165 -    default:
  3.1166 -    	DPRINTF("*** Write: Bad state! (%d) ***\n", req->state);
  3.1167 -    	goto fail;
  3.1168 -    }
  3.1169 -    
  3.1170 -    return;
  3.1171 -    
  3.1172 - fail:
  3.1173 +        cb(r, req_param);
  3.1174 +        break;
  3.1175 +    }
  3.1176 +        
  3.1177 +    default:
  3.1178 +    	DPRINTF("*** Write: Bad state! (%d) ***\n", req->state);
  3.1179 +    	goto fail;
  3.1180 +    }
  3.1181 +    
  3.1182 +    return;
  3.1183 +    
  3.1184 + fail:
  3.1185      {
  3.1186          struct io_ret r;
  3.1187          io_cb_t cb;
  3.1188          int i;
  3.1189  
  3.1190          DPRINTF("asyn_write had a read error mid-way.\n");
  3.1191 -        req_param = req->param;
  3.1192 -        cb        = req->cb;
  3.1193 -        r.type = IO_INT_T;
  3.1194 -        r.u.i  = -1;
  3.1195 +        req_param = req->param;
  3.1196 +        cb        = req->cb;
  3.1197 +        r.type = IO_INT_T;
  3.1198 +        r.u.i  = -1;
  3.1199          /* free any saved node vals. */
  3.1200          for (i=0; i<3; i++)
  3.1201              if (req->radix[i] != 0) free(req->radix[i]);
  3.1202 -        free(req);
  3.1203 -        cb(r, req_param);
  3.1204 +        free(req);
  3.1205 +        cb(r, req_param);
  3.1206      }
  3.1207 -}
  3.1208 -
  3.1209 +}
  3.1210 +
  3.1211  char *vdi_read_s(vdi_t *vdi, u64 vaddr)
  3.1212  {
  3.1213      pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
     4.1 --- a/tools/blktap/requests-async.h	Sat Jul 02 22:37:55 2005 +0000
     4.2 +++ b/tools/blktap/requests-async.h	Sun Jul 03 12:02:01 2005 +0000
     4.3 @@ -1,24 +1,24 @@
     4.4 -#ifndef _REQUESTSASYNC_H_
     4.5 -#define _REQUESTSASYNC_H_
     4.6 -
     4.7 -#include "block-async.h"
     4.8 -#include "blockstore.h" /* for newblock etc. */
     4.9 -
    4.10 -/*
    4.11 -#define BLOCK_SIZE 4096
    4.12 -#define ZERO 0ULL
    4.13 -#define getid(x) (((x)>>1)&0x7fffffffffffffffLLU)
    4.14 -#define iswritable(x) (((x) & 1LLU) != 0)
    4.15 -#define writable(x) (((x) << 1) | 1LLU)
    4.16 -#define readonly(x) ((u64)((x) << 1))
    4.17 -*/
    4.18 -
    4.19 +#ifndef _REQUESTSASYNC_H_
    4.20 +#define _REQUESTSASYNC_H_
    4.21 +
    4.22 +#include "block-async.h"
    4.23 +#include "blockstore.h" /* for newblock etc. */
    4.24 +
    4.25 +/*
    4.26 +#define BLOCK_SIZE 4096
    4.27 +#define ZERO 0ULL
    4.28 +#define getid(x) (((x)>>1)&0x7fffffffffffffffLLU)
    4.29 +#define iswritable(x) (((x) & 1LLU) != 0)
    4.30 +#define writable(x) (((x) << 1) | 1LLU)
    4.31 +#define readonly(x) ((u64)((x) << 1))
    4.32 +*/
    4.33 +
    4.34  #define VADDR_MASK 0x0000000003ffffffLLU /* 26-bits = 256Gig */
    4.35  #define VALID_VADDR(x) (((x) & VADDR_MASK) == (x))
    4.36  
    4.37  int vdi_read (vdi_t *vdi, u64 vaddr, io_cb_t cb, void *param);
    4.38  int vdi_write(vdi_t *vdi, u64 vaddr, char *block, io_cb_t cb, void *param);
    4.39 -             
    4.40 +             
    4.41  /* synchronous versions: */
    4.42  char *vdi_read_s (vdi_t *vdi, u64 vaddr);
    4.43  int   vdi_write_s(vdi_t *vdi, u64 vaddr, char *block);
    4.44 @@ -26,4 +26,4 @@ int   vdi_write_s(vdi_t *vdi, u64 vaddr,
    4.45  #define ERR_BAD_VADDR  -1
    4.46  #define ERR_NOMEM      -2
    4.47  
    4.48 -#endif //_REQUESTSASYNC_H_
    4.49 +#endif //_REQUESTSASYNC_H_