]> git.proxmox.com Git - qemu.git/commitdiff
Merge remote-tracking branch 'bonzini/scsi-next' into staging
authorAnthony Liguori <aliguori@us.ibm.com>
Sat, 11 Aug 2012 22:11:23 +0000 (17:11 -0500)
committerAnthony Liguori <aliguori@us.ibm.com>
Sat, 11 Aug 2012 22:11:23 +0000 (17:11 -0500)
* bonzini/scsi-next:
  scsi-disk: add support for the UNMAP command
  scsi-disk: improve out-of-range LBA detection for WRITE SAME
  scsi-disk: more assertions and resets for aiocb
  virtio-scsi: do not compare 32-bit QEMU tags against 64-bit virtio-scsi tags
  iscsi: Pick default initiator-name based on the name of the VM
  iscsi: reorganize code for parse_initiator_name
  iscsi: do not leak initiator_name

1  2 
hw/scsi-disk.c
vl.c

diff --combined hw/scsi-disk.c
index c8d5edd86e25b575d724c4368688f101844c42de,e71809e09162b8276fb733bd27ce0b4e41fa012c..409f760ef78eacd392a190ef227b804f1c639b40
@@@ -175,6 -175,8 +175,8 @@@ static void scsi_aio_complete(void *opa
      SCSIDiskReq *r = (SCSIDiskReq *)opaque;
      SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
  
+     assert(r->req.aiocb != NULL);
+     r->req.aiocb = NULL;
      bdrv_acct_done(s->qdev.conf.bs, &r->acct);
  
      if (ret < 0) {
@@@ -238,10 -240,9 +240,9 @@@ static void scsi_dma_complete(void *opa
      SCSIDiskReq *r = (SCSIDiskReq *)opaque;
      SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
  
-     if (r->req.aiocb != NULL) {
-         r->req.aiocb = NULL;
-         bdrv_acct_done(s->qdev.conf.bs, &r->acct);
-     }
+     assert(r->req.aiocb != NULL);
+     r->req.aiocb = NULL;
+     bdrv_acct_done(s->qdev.conf.bs, &r->acct);
  
      if (ret < 0) {
          if (scsi_handle_rw_error(r, -ret)) {
@@@ -270,10 -271,9 +271,9 @@@ static void scsi_read_complete(void * o
      SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
      int n;
  
-     if (r->req.aiocb != NULL) {
-         r->req.aiocb = NULL;
-         bdrv_acct_done(s->qdev.conf.bs, &r->acct);
-     }
+     assert(r->req.aiocb != NULL);
+     r->req.aiocb = NULL;
+     bdrv_acct_done(s->qdev.conf.bs, &r->acct);
  
      if (ret < 0) {
          if (scsi_handle_rw_error(r, -ret)) {
@@@ -637,7 -637,7 +637,7 @@@ static int scsi_disk_emulate_inquiry(SC
          {
              buflen = 8;
              outbuf[4] = 0;
-             outbuf[5] = 0x60; /* write_same 10/16 supported */
+             outbuf[5] = 0xe0; /* unmap & write_same 10/16 all supported */
              outbuf[6] = s->qdev.conf.discard_granularity ? 2 : 1;
              outbuf[7] = 0;
              break;
@@@ -1449,6 -1449,89 +1449,89 @@@ invalid_field
      return;
  }
  
+ typedef struct UnmapCBData {
+     SCSIDiskReq *r;
+     uint8_t *inbuf;
+     int count;
+ } UnmapCBData;
+ static void scsi_unmap_complete(void *opaque, int ret)
+ {
+     UnmapCBData *data = opaque;
+     SCSIDiskReq *r = data->r;
+     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
+     uint64_t sector_num;
+     uint32 nb_sectors;
+     r->req.aiocb = NULL;
+     if (ret < 0) {
+         if (scsi_handle_rw_error(r, -ret)) {
+             goto done;
+         }
+     }
+     if (data->count > 0 && !r->req.io_canceled) {
+         sector_num = ldq_be_p(&data->inbuf[0]);
+         nb_sectors = ldl_be_p(&data->inbuf[8]) & 0xffffffffULL;
+         if (sector_num > sector_num + nb_sectors ||
+             sector_num + nb_sectors - 1 > s->qdev.max_lba) {
+             scsi_check_condition(r, SENSE_CODE(LBA_OUT_OF_RANGE));
+             goto done;
+         }
+         r->req.aiocb = bdrv_aio_discard(s->qdev.conf.bs,
+                                         sector_num * (s->qdev.blocksize / 512),
+                                         nb_sectors * (s->qdev.blocksize / 512),
+                                         scsi_unmap_complete, data);
+         data->count--;
+         data->inbuf += 16;
+         return;
+     }
+ done:
+     if (data->count == 0) {
+         scsi_req_complete(&r->req, GOOD);
+     }
+     if (!r->req.io_canceled) {
+         scsi_req_unref(&r->req);
+     }
+     g_free(data);
+ }
+ static void scsi_disk_emulate_unmap(SCSIDiskReq *r, uint8_t *inbuf)
+ {
+     uint8_t *p = inbuf;
+     int len = r->req.cmd.xfer;
+     UnmapCBData *data;
+     if (len < 8) {
+         goto invalid_param_len;
+     }
+     if (len < lduw_be_p(&p[0]) + 2) {
+         goto invalid_param_len;
+     }
+     if (len < lduw_be_p(&p[2]) + 8) {
+         goto invalid_param_len;
+     }
+     if (lduw_be_p(&p[2]) & 15) {
+         goto invalid_param_len;
+     }
+     data = g_new0(UnmapCBData, 1);
+     data->r = r;
+     data->inbuf = &p[8];
+     data->count = lduw_be_p(&p[2]) >> 4;
+     /* The matching unref is in scsi_unmap_complete, before data is freed.  */
+     scsi_req_ref(&r->req);
+     scsi_unmap_complete(data, 0);
+     return;
+ invalid_param_len:
+     scsi_check_condition(r, SENSE_CODE(INVALID_PARAM_LEN));
+     return;
+ }
  static void scsi_disk_emulate_write_data(SCSIRequest *req)
  {
      SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req);
          scsi_disk_emulate_mode_select(r, r->iov.iov_base);
          break;
  
+     case UNMAP:
+         scsi_disk_emulate_unmap(r, r->iov.iov_base);
+         break;
      default:
          abort();
      }
@@@ -1702,6 -1789,9 +1789,9 @@@ static int32_t scsi_disk_emulate_comman
      case MODE_SELECT_10:
          DPRINTF("Mode Select(10) (len %lu)\n", (long)r->req.cmd.xfer);
          break;
+     case UNMAP:
+         DPRINTF("Unmap (len %lu)\n", (long)r->req.cmd.xfer);
+         break;
      case WRITE_SAME_10:
          nb_sectors = lduw_be_p(&req->cmd.buf[7]);
          goto write_same;
              scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED));
              return 0;
          }
-         if (r->req.cmd.lba > s->qdev.max_lba) {
+         if (r->req.cmd.lba > r->req.cmd.lba + nb_sectors ||
+             r->req.cmd.lba + nb_sectors - 1 > s->qdev.max_lba) {
              goto illegal_lba;
          }
  
@@@ -1958,8 -2049,7 +2049,8 @@@ static int scsi_initfn(SCSIDevice *dev
      }
  
      blkconf_serial(&s->qdev.conf, &s->serial);
 -    if (blkconf_geometry(&dev->conf, NULL, 65535, 255, 255) < 0) {
 +    if (dev->type == TYPE_DISK
 +        && blkconf_geometry(&dev->conf, NULL, 65535, 255, 255) < 0) {
          return -1;
      }
  
@@@ -2067,6 -2157,7 +2158,7 @@@ static const SCSIReqOps *const scsi_dis
      [SEEK_10]                         = &scsi_disk_emulate_reqops,
      [MODE_SELECT]                     = &scsi_disk_emulate_reqops,
      [MODE_SELECT_10]                  = &scsi_disk_emulate_reqops,
+     [UNMAP]                           = &scsi_disk_emulate_reqops,
      [WRITE_SAME_10]                   = &scsi_disk_emulate_reqops,
      [WRITE_SAME_16]                   = &scsi_disk_emulate_reqops,
  
diff --combined vl.c
index a4a520fb7e6ce49019ddd5d440e6666784f0710f,065aec290eb02e5a7bb0974c155e5319b3008b64..ad9b03602b9bc4de423f42bf1894bcd5c14e7fd4
--- 1/vl.c
--- 2/vl.c
+++ b/vl.c
@@@ -293,6 -293,11 +293,11 @@@ static struct 
      { .driver = "qxl-vga",              .flag = &default_vga       },
  };
  
+ const char *qemu_get_vm_name(void)
+ {
+     return qemu_name;
+ }
  static void res_free(void)
  {
      if (boot_splash_filedata != NULL) {
@@@ -3345,11 -3350,6 +3350,11 @@@ int main(int argc, char **argv, char **
          ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
      }
  
 +    if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
 +        != 0) {
 +        exit(0);
 +    }
 +
      configure_accelerator();
  
      qemu_init_cpu_loop();
      }
      select_vgahw(vga_model);
  
 -    if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
 -        exit(0);
 -
      if (watchdog) {
          i = select_watchdog(watchdog);
          if (i > 0)