debuggers.hg

changeset 21152:b20f897d6010

mini-os: Fix xenbus initialisation

This fixes xenbus initialization of blkfront, netfront and pcifront
by uniformizing with fbfront: after writing parameters, set state to
initialised, then wait for backend to switch to connect state, and
then only read its parameter and switch to the connect state.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Apr 06 07:13:19 2010 +0100 (2010-04-06)
parents a3f7352d83eb
children d7370232060a
files extras/mini-os/blkfront.c extras/mini-os/fbfront.c extras/mini-os/netfront.c extras/mini-os/pcifront.c
line diff
     1.1 --- a/extras/mini-os/blkfront.c	Tue Apr 06 07:13:01 2010 +0100
     1.2 +++ b/extras/mini-os/blkfront.c	Tue Apr 06 07:13:19 2010 +0100
     1.3 @@ -152,13 +152,12 @@ again:
     1.4      }
     1.5  
     1.6      snprintf(path, sizeof(path), "%s/state", nodename);
     1.7 -    err = xenbus_switch_state(xbt, path, XenbusStateConnected);
     1.8 +    err = xenbus_switch_state(xbt, path, XenbusStateInitialised);
     1.9      if (err) {
    1.10 -        message = "switching state";
    1.11 +        printk("error writing blk initialized on %s: %s\n", path, err);
    1.12          goto abort_transaction;
    1.13      }
    1.14  
    1.15 -
    1.16      err = xenbus_transaction_end(xbt, 0, &retry);
    1.17      if (err) free(err);
    1.18      if (retry) {
    1.19 @@ -189,6 +188,7 @@ done:
    1.20      {
    1.21          XenbusState state;
    1.22          char path[strlen(dev->backend) + 1 + 19 + 1];
    1.23 +        char frontpath[strlen(nodename) + 1 + 6 + 1];
    1.24          snprintf(path, sizeof(path), "%s/mode", dev->backend);
    1.25          msg = xenbus_read(XBT_NIL, path, &c);
    1.26          if (msg) {
    1.27 @@ -232,7 +232,18 @@ done:
    1.28          dev->info.flush = xenbus_read_integer(path);
    1.29  
    1.30          *info = dev->info;
    1.31 +
    1.32 +        printk("%s connected\n", dev->backend);
    1.33 +
    1.34 +        snprintf(frontpath, sizeof(frontpath), "%s/state", nodename);
    1.35 +        if((err = xenbus_switch_state(XBT_NIL, frontpath, XenbusStateConnected))
    1.36 +            != NULL) {
    1.37 +            printk("error switching state: %s\n", err);
    1.38 +            xenbus_unwatch_path_token(XBT_NIL, path, path);
    1.39 +            goto error;
    1.40 +        }
    1.41      }
    1.42 +
    1.43      unmask_evtchn(dev->evtchn);
    1.44  
    1.45      printk("%u sectors of %u bytes\n", dev->info.sectors, dev->info.sector_size);
     2.1 --- a/extras/mini-os/fbfront.c	Tue Apr 06 07:13:01 2010 +0100
     2.2 +++ b/extras/mini-os/fbfront.c	Tue Apr 06 07:13:19 2010 +0100
     2.3 @@ -126,8 +126,8 @@ again:
     2.4      snprintf(path, sizeof(path), "%s/state", nodename);
     2.5      err = xenbus_switch_state(xbt, path, XenbusStateInitialised);
     2.6      if (err) {
     2.7 -        printk("error writing initialized: %s\n", err);
     2.8 -        free(err);
     2.9 +        printk("error writing fb initialized: %s\n", err);
    2.10 +        goto abort_transaction;
    2.11      }
    2.12  
    2.13      err = xenbus_transaction_end(xbt, 0, &retry);
    2.14 @@ -189,6 +189,7 @@ done:
    2.15      printk("************************** KBDFRONT\n");
    2.16  
    2.17      return dev;
    2.18 +
    2.19  error:
    2.20      free(msg);
    2.21      free(err);
     3.1 --- a/extras/mini-os/netfront.c	Tue Apr 06 07:13:01 2010 +0100
     3.2 +++ b/extras/mini-os/netfront.c	Tue Apr 06 07:13:19 2010 +0100
     3.3 @@ -407,9 +407,9 @@ again:
     3.4      }
     3.5  
     3.6      snprintf(path, sizeof(path), "%s/state", nodename);
     3.7 -    err = xenbus_switch_state(xbt, path, XenbusStateConnected);
     3.8 +    err = xenbus_switch_state(xbt, path, XenbusStateInitialised);
     3.9      if (err) {
    3.10 -        message = "switching state";
    3.11 +        printk("error writing net initialized: %s\n", err);
    3.12          goto abort_transaction;
    3.13      }
    3.14  
    3.15 @@ -445,6 +445,7 @@ done:
    3.16      {
    3.17          XenbusState state;
    3.18          char path[strlen(dev->backend) + 1 + 5 + 1];
    3.19 +        char frontpath[strlen(nodename) + 1 + 6 + 1];
    3.20          snprintf(path, sizeof(path), "%s/state", dev->backend);
    3.21  
    3.22          xenbus_watch_path_token(XBT_NIL, path, path, &dev->events);
    3.23 @@ -463,6 +464,16 @@ done:
    3.24              snprintf(path, sizeof(path), "%s/ip", dev->backend);
    3.25              xenbus_read(XBT_NIL, path, ip);
    3.26          }
    3.27 +
    3.28 +        printk("%s connected\n", dev->backend);
    3.29 +
    3.30 +        snprintf(frontpath, sizeof(frontpath), "%s/state", nodename);
    3.31 +        if((err = xenbus_switch_state(XBT_NIL, frontpath, XenbusStateConnected))
    3.32 +            != NULL) {
    3.33 +            printk("error switching state: %s\n", err);
    3.34 +            xenbus_unwatch_path_token(XBT_NIL, path, path);
    3.35 +            goto error;
    3.36 +        }
    3.37      }
    3.38  
    3.39      printk("**************************\n");
    3.40 @@ -481,6 +492,7 @@ done:
    3.41              &rawmac[5]);
    3.42  
    3.43      return dev;
    3.44 +
    3.45  error:
    3.46      free(msg);
    3.47      free(err);
     4.1 --- a/extras/mini-os/pcifront.c	Tue Apr 06 07:13:01 2010 +0100
     4.2 +++ b/extras/mini-os/pcifront.c	Tue Apr 06 07:13:19 2010 +0100
     4.3 @@ -143,7 +143,7 @@ struct pcifront_dev *init_pcifront(char 
     4.4      char* err;
     4.5      char* message=NULL;
     4.6      int retry=0;
     4.7 -    char* msg;
     4.8 +    char* msg = NULL;
     4.9      char* nodename = _nodename ? _nodename : "device/pci/0";
    4.10      int dom;
    4.11  
    4.12 @@ -206,7 +206,7 @@ again:
    4.13      snprintf(path, sizeof(path), "%s/state", nodename);
    4.14      err = xenbus_switch_state(xbt, path, XenbusStateInitialised);
    4.15      if (err) {
    4.16 -        message = "switching state";
    4.17 +        printk("error writing pci initialized: %s\n", err);
    4.18          goto abort_transaction;
    4.19      }
    4.20  
    4.21 @@ -237,7 +237,7 @@ done:
    4.22  
    4.23      {
    4.24          char path[strlen(dev->backend) + 1 + 5 + 1];
    4.25 -        char frontpath[strlen(nodename) + 1 + 5 + 1];
    4.26 +        char frontpath[strlen(nodename) + 1 + 6 + 1];
    4.27          XenbusState state;
    4.28          snprintf(path, sizeof(path), "%s/state", dev->backend);
    4.29  
    4.30 @@ -254,9 +254,9 @@ done:
    4.31          }
    4.32  
    4.33          snprintf(frontpath, sizeof(frontpath), "%s/state", nodename);
    4.34 -        if ((err = xenbus_switch_state(XBT_NIL, frontpath, XenbusStateConnected))
    4.35 +        if((err = xenbus_switch_state(XBT_NIL, frontpath, XenbusStateConnected))
    4.36              != NULL) {
    4.37 -            printk("error switching state %s\n", err);
    4.38 +            printk("error switching state: %s\n", err);
    4.39              xenbus_unwatch_path_token(XBT_NIL, path, path);
    4.40              goto error;
    4.41          }
    4.42 @@ -271,6 +271,7 @@ done:
    4.43      return dev;
    4.44  
    4.45  error:
    4.46 +    free(msg);
    4.47      free(err);
    4.48      free_pcifront(dev);
    4.49      return NULL;