ia64/xen-unstable

changeset 14810:0d92cd901f80

Provide the use of SCSI disks in HVM domains. Currently there is a
maximum of 7 scsi disks and an ide disk must still be used to boot.

Signed-off-by: Natasha Jarymowycz <natasha@us.ibm.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Apr 11 15:43:49 2007 +0100 (2007-04-11)
parents 6cd828db1a5d
children db4fcb609383
files tools/ioemu/hw/pc.c tools/ioemu/vl.c tools/ioemu/vl.h tools/ioemu/xenstore.c
line diff
     1.1 --- a/tools/ioemu/hw/pc.c	Wed Apr 11 15:36:04 2007 +0100
     1.2 +++ b/tools/ioemu/hw/pc.c	Wed Apr 11 15:43:49 2007 +0100
     1.3 @@ -902,7 +902,6 @@ static void pc_init1(uint64_t ram_size, 
     1.4      if (pci_enabled && acpi_enabled) {
     1.5          piix4_pm_init(pci_bus, piix3_devfn + 3);
     1.6      }
     1.7 -#endif /* !CONFIG_DM */
     1.8  
     1.9  #if 0
    1.10      /* ??? Need to figure out some way for the user to
    1.11 @@ -921,6 +920,17 @@ static void pc_init1(uint64_t ram_size, 
    1.12          lsi_scsi_attach(scsi, bdrv, -1);
    1.13      }
    1.14  #endif
    1.15 +#else
    1.16 +    if (pci_enabled) {
    1.17 +        void *scsi;
    1.18 +
    1.19 +        scsi = lsi_scsi_init(pci_bus, -1);
    1.20 +        for (i = 0; i < MAX_SCSI_DISKS ; i++) {
    1.21 +            if (bs_table[i + MAX_DISKS]) 
    1.22 +                lsi_scsi_attach(scsi, bs_table[i + MAX_DISKS], -1);
    1.23 +        }
    1.24 +    }
    1.25 +#endif /* !CONFIG_DM */
    1.26      /* must be done after all PCI devices are instanciated */
    1.27      /* XXX: should be done in the Bochs BIOS */
    1.28      if (pci_enabled) {
     2.1 --- a/tools/ioemu/vl.c	Wed Apr 11 15:36:04 2007 +0100
     2.2 +++ b/tools/ioemu/vl.c	Wed Apr 11 15:43:49 2007 +0100
     2.3 @@ -116,7 +116,7 @@ char phys_ram_file[1024];
     2.4  void *ioport_opaque[MAX_IOPORTS];
     2.5  IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];
     2.6  IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];
     2.7 -BlockDriverState *bs_table[MAX_DISKS], *fd_table[MAX_FD];
     2.8 +BlockDriverState *bs_table[MAX_DISKS+MAX_SCSI_DISKS], *fd_table[MAX_FD];
     2.9  int vga_ram_size;
    2.10  int bios_size;
    2.11  static DisplayState display_state;
     3.1 --- a/tools/ioemu/vl.h	Wed Apr 11 15:36:04 2007 +0100
     3.2 +++ b/tools/ioemu/vl.h	Wed Apr 11 15:43:49 2007 +0100
     3.3 @@ -818,8 +818,9 @@ int vnc_start_viewer(int port);
     3.4  
     3.5  /* ide.c */
     3.6  #define MAX_DISKS 4
     3.7 +#define MAX_SCSI_DISKS 7
     3.8  
     3.9 -extern BlockDriverState *bs_table[MAX_DISKS];
    3.10 +extern BlockDriverState *bs_table[MAX_DISKS+MAX_SCSI_DISKS];
    3.11  
    3.12  void isa_ide_init(int iobase, int iobase2, int irq,
    3.13                    BlockDriverState *hd0, BlockDriverState *hd1);
     4.1 --- a/tools/ioemu/xenstore.c	Wed Apr 11 15:36:04 2007 +0100
     4.2 +++ b/tools/ioemu/xenstore.c	Wed Apr 11 15:43:49 2007 +0100
     4.3 @@ -30,11 +30,11 @@ static int pasprintf(char **buf, const c
     4.4      int ret = 0;
     4.5  
     4.6      if (*buf)
     4.7 -	free(*buf);
     4.8 +        free(*buf);
     4.9      va_start(ap, fmt);
    4.10      if (vasprintf(buf, fmt, ap) == -1) {
    4.11 -	buf = NULL;
    4.12 -	ret = -1;
    4.13 +        buf = NULL;
    4.14 +        ret = -1;
    4.15      }
    4.16      va_end(ap);
    4.17      return ret;
    4.18 @@ -45,11 +45,11 @@ static void insert_media(void *opaque)
    4.19      int i;
    4.20  
    4.21      for (i = 0; i < MAX_DISKS; i++) {
    4.22 -	if (media_filename[i] && bs_table[i]) {
    4.23 -	    do_change(bs_table[i]->device_name, media_filename[i]);
    4.24 -	    free(media_filename[i]);
    4.25 -	    media_filename[i] = NULL;
    4.26 -	}
    4.27 +        if (media_filename[i] && bs_table[i]) {
    4.28 +            do_change(bs_table[i]->device_name, media_filename[i]);
    4.29 +            free(media_filename[i]);
    4.30 +            media_filename[i] = NULL;
    4.31 +        }
    4.32      }
    4.33  }
    4.34  
    4.35 @@ -57,7 +57,7 @@ void xenstore_check_new_media_present(in
    4.36  {
    4.37  
    4.38      if (insert_timer == NULL)
    4.39 -	insert_timer = qemu_new_timer(rt_clock, insert_media, NULL);
    4.40 +        insert_timer = qemu_new_timer(rt_clock, insert_media, NULL);
    4.41      qemu_mod_timer(insert_timer, qemu_get_clock(rt_clock) + timeout);
    4.42  }
    4.43  
    4.44 @@ -82,8 +82,8 @@ void xenstore_parse_domain_config(int do
    4.45      char **e = NULL;
    4.46      char *buf = NULL, *path;
    4.47      char *fpath = NULL, *bpath = NULL,
    4.48 -         *dev = NULL, *params = NULL, *type = NULL;
    4.49 -    int i;
    4.50 +        *dev = NULL, *params = NULL, *type = NULL;
    4.51 +    int i, is_scsi;
    4.52      unsigned int len, num, hd_index;
    4.53  
    4.54      for(i = 0; i < MAX_DISKS; i++)
    4.55 @@ -91,8 +91,8 @@ void xenstore_parse_domain_config(int do
    4.56  
    4.57      xsh = xs_daemon_open();
    4.58      if (xsh == NULL) {
    4.59 -	fprintf(logfile, "Could not contact xenstore for domain config\n");
    4.60 -	return;
    4.61 +        fprintf(logfile, "Could not contact xenstore for domain config\n");
    4.62 +        return;
    4.63      }
    4.64  
    4.65      path = xs_get_domain_path(xsh, domid);
    4.66 @@ -102,59 +102,60 @@ void xenstore_parse_domain_config(int do
    4.67      }
    4.68  
    4.69      if (pasprintf(&buf, "%s/device/vbd", path) == -1)
    4.70 -	goto out;
    4.71 +        goto out;
    4.72  
    4.73      e = xs_directory(xsh, XBT_NULL, buf, &num);
    4.74      if (e == NULL)
    4.75 -	goto out;
    4.76 +        goto out;
    4.77  
    4.78      for (i = 0; i < num; i++) {
    4.79 -	/* read the backend path */
    4.80 -	if (pasprintf(&buf, "%s/device/vbd/%s/backend", path, e[i]) == -1)
    4.81 -	    continue;
    4.82 -	free(bpath);
    4.83 +        /* read the backend path */
    4.84 +        if (pasprintf(&buf, "%s/device/vbd/%s/backend", path, e[i]) == -1)
    4.85 +            continue;
    4.86 +        free(bpath);
    4.87          bpath = xs_read(xsh, XBT_NULL, buf, &len);
    4.88 -	if (bpath == NULL)
    4.89 -	    continue;
    4.90 -	/* read the name of the device */
    4.91 -	if (pasprintf(&buf, "%s/dev", bpath) == -1)
    4.92 -	    continue;
    4.93 -	free(dev);
    4.94 -	dev = xs_read(xsh, XBT_NULL, buf, &len);
    4.95 -	if (dev == NULL)
    4.96 -	    continue;
    4.97 -	if (strncmp(dev, "hd", 2) || strlen(dev) != 3)
    4.98 -	    continue;
    4.99 -	hd_index = dev[2] - 'a';
   4.100 -	if (hd_index >= MAX_DISKS)
   4.101 -	    continue;
   4.102 -	/* read the type of the device */
   4.103 -	if (pasprintf(&buf, "%s/device/vbd/%s/device-type", path, e[i]) == -1)
   4.104 -	    continue;
   4.105 -	free(type);
   4.106 -	type = xs_read(xsh, XBT_NULL, buf, &len);
   4.107 -	if (pasprintf(&buf, "%s/params", bpath) == -1)
   4.108 -	    continue;
   4.109 -	free(params);
   4.110 -	params = xs_read(xsh, XBT_NULL, buf, &len);
   4.111 -	if (params == NULL)
   4.112 -	    continue;
   4.113 +        if (bpath == NULL)
   4.114 +            continue;
   4.115 +        /* read the name of the device */
   4.116 +        if (pasprintf(&buf, "%s/dev", bpath) == -1)
   4.117 +            continue;
   4.118 +        free(dev);
   4.119 +        dev = xs_read(xsh, XBT_NULL, buf, &len);
   4.120 +        if (dev == NULL)
   4.121 +            continue;
   4.122 +        is_scsi = !strncmp(dev, "sd", 2);
   4.123 +        if ((strncmp(dev, "hd", 2) && !is_scsi) || strlen(dev) != 3 )
   4.124 +            continue;
   4.125 +        hd_index = dev[2] - 'a';
   4.126 +        if (hd_index >= (is_scsi ? MAX_SCSI_DISKS : MAX_DISKS))
   4.127 +            continue;
   4.128 +        /* read the type of the device */
   4.129 +        if (pasprintf(&buf, "%s/device/vbd/%s/device-type", path, e[i]) == -1)
   4.130 +            continue;
   4.131 +        free(type);
   4.132 +        type = xs_read(xsh, XBT_NULL, buf, &len);
   4.133 +        if (pasprintf(&buf, "%s/params", bpath) == -1)
   4.134 +            continue;
   4.135 +        free(params);
   4.136 +        params = xs_read(xsh, XBT_NULL, buf, &len);
   4.137 +        if (params == NULL)
   4.138 +            continue;
   4.139          /* 
   4.140           * check if device has a phantom vbd; the phantom is hooked
   4.141           * to the frontend device (for ease of cleanup), so lookup 
   4.142           * the frontend device, and see if there is a phantom_vbd
   4.143           * if there is, we will use resolution as the filename
   4.144           */
   4.145 -	if (pasprintf(&buf, "%s/device/vbd/%s/phantom_vbd", path, e[i]) == -1)
   4.146 -	    continue;
   4.147 -	free(fpath);
   4.148 +        if (pasprintf(&buf, "%s/device/vbd/%s/phantom_vbd", path, e[i]) == -1)
   4.149 +            continue;
   4.150 +        free(fpath);
   4.151          fpath = xs_read(xsh, XBT_NULL, buf, &len);
   4.152 -	if (fpath) {
   4.153 -	    if (pasprintf(&buf, "%s/dev", fpath) == -1)
   4.154 -	        continue;
   4.155 -	    free(params);
   4.156 +        if (fpath) {
   4.157 +            if (pasprintf(&buf, "%s/dev", fpath) == -1)
   4.158 +                continue;
   4.159 +            free(params);
   4.160              params = xs_read(xsh, XBT_NULL, buf , &len);
   4.161 -	    if (params) {
   4.162 +            if (params) {
   4.163                  /* 
   4.164                   * wait for device, on timeout silently fail because we will 
   4.165                   * fail to open below
   4.166 @@ -163,19 +164,20 @@ void xenstore_parse_domain_config(int do
   4.167              }
   4.168          }
   4.169  
   4.170 -	bs_table[hd_index] = bdrv_new(dev);
   4.171 -	/* check if it is a cdrom */
   4.172 -	if (type && !strcmp(type, "cdrom")) {
   4.173 -	    bdrv_set_type_hint(bs_table[hd_index], BDRV_TYPE_CDROM);
   4.174 -	    if (pasprintf(&buf, "%s/params", bpath) != -1)
   4.175 -		xs_watch(xsh, buf, dev);
   4.176 -	}
   4.177 -	/* open device now if media present */
   4.178 -	if (params[0]) {
   4.179 -            if (bdrv_open(bs_table[hd_index], params, 0 /* snapshot */) < 0)
   4.180 +        bs_table[hd_index + (is_scsi ? MAX_DISKS : 0)] = bdrv_new(dev);
   4.181 +        /* check if it is a cdrom */
   4.182 +        if (type && !strcmp(type, "cdrom")) {
   4.183 +            bdrv_set_type_hint(bs_table[hd_index], BDRV_TYPE_CDROM);
   4.184 +            if (pasprintf(&buf, "%s/params", bpath) != -1)
   4.185 +                xs_watch(xsh, buf, dev);
   4.186 +        }
   4.187 +        /* open device now if media present */
   4.188 +        if (params[0]) {
   4.189 +            if (bdrv_open(bs_table[hd_index + (is_scsi ? MAX_DISKS : 0)],
   4.190 +                          params, 0 /* snapshot */) < 0)
   4.191                  fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
   4.192                          params);
   4.193 -	}
   4.194 +        }
   4.195      }
   4.196  
   4.197      /* Set a watch for log-dirty requests from the migration tools */
   4.198 @@ -199,7 +201,7 @@ void xenstore_parse_domain_config(int do
   4.199  int xenstore_fd(void)
   4.200  {
   4.201      if (xsh)
   4.202 -	return xs_fileno(xsh);
   4.203 +        return xs_fileno(xsh);
   4.204      return -1;
   4.205  }
   4.206  
   4.207 @@ -316,7 +318,7 @@ void xenstore_process_event(void *opaque
   4.208  
   4.209      vec = xs_read_watch(xsh, &num);
   4.210      if (!vec)
   4.211 -	return;
   4.212 +        return;
   4.213  
   4.214      if (!strcmp(vec[XS_WATCH_TOKEN], "logdirty")) {
   4.215          xenstore_process_logdirty_event();
   4.216 @@ -324,23 +326,23 @@ void xenstore_process_event(void *opaque
   4.217      }
   4.218  
   4.219      if (strncmp(vec[XS_WATCH_TOKEN], "hd", 2) ||
   4.220 -	strlen(vec[XS_WATCH_TOKEN]) != 3)
   4.221 -	goto out;
   4.222 +        strlen(vec[XS_WATCH_TOKEN]) != 3)
   4.223 +        goto out;
   4.224      hd_index = vec[XS_WATCH_TOKEN][2] - 'a';
   4.225      image = xs_read(xsh, XBT_NULL, vec[XS_WATCH_PATH], &len);
   4.226      if (image == NULL || !strcmp(image, bs_table[hd_index]->filename))
   4.227 -	goto out;		/* gone or identical */
   4.228 +        goto out;  /* gone or identical */
   4.229  
   4.230      do_eject(0, vec[XS_WATCH_TOKEN]);
   4.231      bs_table[hd_index]->filename[0] = 0;
   4.232      if (media_filename[hd_index]) {
   4.233 -	free(media_filename[hd_index]);
   4.234 -	media_filename[hd_index] = NULL;
   4.235 +        free(media_filename[hd_index]);
   4.236 +        media_filename[hd_index] = NULL;
   4.237      }
   4.238  
   4.239      if (image[0]) {
   4.240 -	media_filename[hd_index] = strdup(image);
   4.241 -	xenstore_check_new_media_present(5000);
   4.242 +        media_filename[hd_index] = strdup(image);
   4.243 +        xenstore_check_new_media_present(5000);
   4.244      }
   4.245  
   4.246   out:
   4.247 @@ -354,7 +356,7 @@ void xenstore_write_vncport(int display)
   4.248      char *portstr = NULL;
   4.249  
   4.250      if (xsh == NULL)
   4.251 -	return;
   4.252 +        return;
   4.253  
   4.254      path = xs_get_domain_path(xsh, domid);
   4.255      if (path == NULL) {
   4.256 @@ -363,10 +365,10 @@ void xenstore_write_vncport(int display)
   4.257      }
   4.258  
   4.259      if (pasprintf(&buf, "%s/console/vnc-port", path) == -1)
   4.260 -	goto out;
   4.261 +        goto out;
   4.262  
   4.263      if (pasprintf(&portstr, "%d", 5900 + display) == -1)
   4.264 -	goto out;
   4.265 +        goto out;
   4.266  
   4.267      if (xs_write(xsh, XBT_NULL, buf, portstr, strlen(portstr)) == 0)
   4.268          fprintf(logfile, "xs_write() vncport failed\n");
   4.269 @@ -383,41 +385,41 @@ int xenstore_read_vncpasswd(int domid)
   4.270      unsigned int i, len, rc = 0;
   4.271  
   4.272      if (xsh == NULL) {
   4.273 -	return -1;
   4.274 +        return -1;
   4.275      }
   4.276  
   4.277      path = xs_get_domain_path(xsh, domid);
   4.278      if (path == NULL) {
   4.279 -	fprintf(logfile, "xs_get_domain_path() error. domid %d.\n", domid);
   4.280 -	return -1;
   4.281 +        fprintf(logfile, "xs_get_domain_path() error. domid %d.\n", domid);
   4.282 +        return -1;
   4.283      }
   4.284  
   4.285      pasprintf(&buf, "%s/vm", path);
   4.286      uuid = xs_read(xsh, XBT_NULL, buf, &len);
   4.287      if (uuid == NULL) {
   4.288 -	fprintf(logfile, "xs_read(): uuid get error. %s.\n", buf);
   4.289 -	free(path);
   4.290 -	return -1;
   4.291 +        fprintf(logfile, "xs_read(): uuid get error. %s.\n", buf);
   4.292 +        free(path);
   4.293 +        return -1;
   4.294      }
   4.295  
   4.296      pasprintf(&buf, "%s/vncpasswd", uuid);
   4.297      passwd = xs_read(xsh, XBT_NULL, buf, &len);
   4.298      if (passwd == NULL) {
   4.299 -	fprintf(logfile, "xs_read(): vncpasswd get error. %s.\n", buf);
   4.300 -	free(uuid);
   4.301 -	free(path);
   4.302 -	return rc;
   4.303 +        fprintf(logfile, "xs_read(): vncpasswd get error. %s.\n", buf);
   4.304 +        free(uuid);
   4.305 +        free(path);
   4.306 +        return rc;
   4.307      }
   4.308  
   4.309      for (i=0; i<len && i<63; i++) {
   4.310 -	vncpasswd[i] = passwd[i];
   4.311 -	passwd[i] = '\0';
   4.312 +        vncpasswd[i] = passwd[i];
   4.313 +        passwd[i] = '\0';
   4.314      }
   4.315      vncpasswd[len] = '\0';
   4.316      pasprintf(&buf, "%s/vncpasswd", uuid);
   4.317      if (xs_write(xsh, XBT_NULL, buf, passwd, len) == 0) {
   4.318 -	fprintf(logfile, "xs_write() vncpasswd failed.\n");
   4.319 -	rc = -1;
   4.320 +        fprintf(logfile, "xs_write() vncpasswd failed.\n");
   4.321 +        rc = -1;
   4.322      }
   4.323  
   4.324      free(passwd);
   4.325 @@ -443,7 +445,7 @@ char **xenstore_domain_get_devices(struc
   4.326          goto out;
   4.327  
   4.328      if (pasprintf(&buf, "%s/device/%s", path,devtype) == -1)
   4.329 -	goto out;
   4.330 +        goto out;
   4.331  
   4.332      e = xs_directory(handle, XBT_NULL, buf, num);
   4.333  
   4.334 @@ -496,13 +498,13 @@ char *xenstore_backend_read_variable(str
   4.335  
   4.336      buf = get_device_variable_path(devtype, inst, var);
   4.337      if (NULL == buf)
   4.338 -	goto out;
   4.339 +        goto out;
   4.340  
   4.341      value = xs_read(handle, XBT_NULL, buf, &len);
   4.342  
   4.343      free(buf);
   4.344  
   4.345 -out:
   4.346 + out:
   4.347      return value;
   4.348  }
   4.349  
   4.350 @@ -569,27 +571,27 @@ char *xenstore_vm_read(int domid, char *
   4.351      char *buf = NULL, *path = NULL, *value = NULL;
   4.352  
   4.353      if (xsh == NULL)
   4.354 -	goto out;
   4.355 +        goto out;
   4.356  
   4.357      path = xs_get_domain_path(xsh, domid);
   4.358      if (path == NULL) {
   4.359 -	fprintf(logfile, "xs_get_domain_path(%d): error\n", domid);
   4.360 -	goto out;
   4.361 +        fprintf(logfile, "xs_get_domain_path(%d): error\n", domid);
   4.362 +        goto out;
   4.363      }
   4.364  
   4.365      pasprintf(&buf, "%s/vm", path);
   4.366      free(path);
   4.367      path = xs_read(xsh, XBT_NULL, buf, NULL);
   4.368      if (path == NULL) {
   4.369 -	fprintf(logfile, "xs_read(%s): read error\n", buf);
   4.370 -	goto out;
   4.371 +        fprintf(logfile, "xs_read(%s): read error\n", buf);
   4.372 +        goto out;
   4.373      }
   4.374  
   4.375      pasprintf(&buf, "%s/%s", path, key);
   4.376      value = xs_read(xsh, XBT_NULL, buf, len);
   4.377      if (value == NULL) {
   4.378 -	fprintf(logfile, "xs_read(%s): read error\n", buf);
   4.379 -	goto out;
   4.380 +        fprintf(logfile, "xs_read(%s): read error\n", buf);
   4.381 +        goto out;
   4.382      }
   4.383  
   4.384   out:
   4.385 @@ -604,27 +606,27 @@ int xenstore_vm_write(int domid, char *k
   4.386      int rc = -1;
   4.387  
   4.388      if (xsh == NULL)
   4.389 -	goto out;
   4.390 +        goto out;
   4.391  
   4.392      path = xs_get_domain_path(xsh, domid);
   4.393      if (path == NULL) {
   4.394 -	fprintf(logfile, "xs_get_domain_path: error\n");
   4.395 -	goto out;
   4.396 +        fprintf(logfile, "xs_get_domain_path: error\n");
   4.397 +        goto out;
   4.398      }
   4.399  
   4.400      pasprintf(&buf, "%s/vm", path);
   4.401      free(path);
   4.402      path = xs_read(xsh, XBT_NULL, buf, NULL);
   4.403      if (path == NULL) {
   4.404 -	fprintf(logfile, "xs_read(%s): read error\n", buf);
   4.405 -	goto out;
   4.406 +        fprintf(logfile, "xs_read(%s): read error\n", buf);
   4.407 +        goto out;
   4.408      }
   4.409  
   4.410      pasprintf(&buf, "%s/%s", path, key);
   4.411      rc = xs_write(xsh, XBT_NULL, buf, value, strlen(value));
   4.412      if (rc) {
   4.413 -	fprintf(logfile, "xs_write(%s, %s): write error\n", buf, key);
   4.414 -	goto out;
   4.415 +        fprintf(logfile, "xs_write(%s, %s): write error\n", buf, key);
   4.416 +        goto out;
   4.417      }
   4.418  
   4.419   out: