]> xenbits.xen.org Git - xenclient/ioemu-pq.git/commitdiff
Trivial concurrency fix, add a required volatile
authorAndrew McNeil <andrewmcn@bob.uk.xensource.com>
Wed, 16 Sep 2009 20:56:28 +0000 (21:56 +0100)
committerAndrew McNeil <andrewmcn@bob.uk.xensource.com>
Wed, 16 Sep 2009 20:56:28 +0000 (21:56 +0100)
master/atapi-async-fix.patch

index bbca52da508cc0965978eee486220118c318ba7e..0d6298075eb53f8100a62b032eb8c1b479a1841f 100644 (file)
@@ -1,8 +1,8 @@
 diff --git a/hw/atapi-pt.c b/hw/atapi-pt.c
-index 92f2934..c2a24ec 100644
+index 92f2934..343798d 100644
 --- a/hw/atapi-pt.c
 +++ b/hw/atapi-pt.c
-@@ -1,19 +1,25 @@
+@@ -1,19 +1,23 @@
 +#include <scsi/sg.h>
  #include <utime.h>
  #include <sys/stat.h>
@@ -18,8 +18,6 @@ index 92f2934..c2a24ec 100644
  #ifdef DEBUG_IDE_ATAPI_PT
 -# define DEBUG_PRINTF(Args...) printf(Args)
 +# define DEBUG_PRINTF(Args...) do { char buf[1024]; int len; if (log_fd==-1) log_fd=open("/tmp/cdrom.log",O_WRONLY | O_CREAT | O_APPEND,0666);  len=sprintf(buf,Args); write(log_fd,buf,len); } while (1==0)
-+//#undef fprintf
-+//# define DEBUG_PRINTF(Args...) fprintf(stderr, Args)
  # define CHECK_SAME_VALUE(Val1, Val2)                                   \
      do {                                                                \
 -        if ((Val1) != (Val2))                                           \
@@ -33,7 +31,7 @@ index 92f2934..c2a24ec 100644
      } while (0)
  #else
  # define DEBUG_PRINTF(Args...)
-@@ -676,14 +682,58 @@ static void ide_atapi_pt_error(IDEState *s)
+@@ -676,14 +680,58 @@ static void ide_atapi_pt_error(IDEState *s)
      ide_set_irq(s);
  }
  
@@ -47,20 +45,20 @@ index 92f2934..c2a24ec 100644
 -    uint32_t din_desired;
 +    volatile struct sg_io_v4 *cmd;
 +    BDRVRawState *raw_state;
-+    IDEState *s = (volatile IDEState *)arg;
++    volatile IDEState *s = (volatile IDEState *)arg;
 +
 +    for(;;) {
-+      pthread_mutex_lock(&s->atapi_pt.sgio_mutex);
-+      pthread_cond_wait(&s->atapi_pt.sgio_cv, &s->atapi_pt.sgio_mutex);
++        pthread_mutex_lock(&s->atapi_pt.sgio_mutex);
++        pthread_cond_wait(&s->atapi_pt.sgio_cv, &s->atapi_pt.sgio_mutex);
 +
-+      /* Send command and wait for reply, SG_IO ioctl*/
-+      cmd = &s->atapi_pt.cmd;
-+      raw_state = s->bs->opaque;
-+      r = ioctl(raw_state->fd, 0x2285, cmd);
++        /* Send command and wait for reply, SG_IO ioctl*/
++        cmd = &s->atapi_pt.cmd;
++        raw_state = s->bs->opaque;
++        r = ioctl(raw_state->fd, 0x2285, cmd);
 +
-+      /* Unlock _before_ signalling parent */
-+      pthread_mutex_unlock(&s->atapi_pt.sgio_mutex);
-+      write(s->atapi_pt.sgio_wfd, &r, sizeof(int));
++        /* Unlock _before_ signalling parent */
++        pthread_mutex_unlock(&s->atapi_pt.sgio_mutex);
++        write(s->atapi_pt.sgio_wfd, &r, sizeof(int));
 +    }
 +}
 +
@@ -97,7 +95,7 @@ index 92f2934..c2a24ec 100644
      assert(cmd->din_xfer_len != (__u32)-1);
  
      s->atapi_pt.sense.error_code = 0;
-@@ -691,9 +741,27 @@ static void ide_atapi_pt_do_sg_io(IDEState *s)
+@@ -691,9 +739,27 @@ static void ide_atapi_pt_do_sg_io(IDEState *s)
      s->atapi_pt.sense.asc = 0;
      s->atapi_pt.sense.ascq = 0;
  
@@ -127,7 +125,11 @@ index 92f2934..c2a24ec 100644
  
      if(s->atapi_pt.request[0] == GPCMD_GET_EVENT_STATUS_NOTIFICATION)
      {
-@@ -836,12 +904,14 @@ static void ide_atapi_pt_do_sg_io(IDEState *s)
+@@ -832,16 +898,17 @@ static void ide_atapi_pt_do_sg_io(IDEState *s)
+     if(din_desired == (__u32)-1)
+         din_desired = cmd->din_xfer_len;
+-    DEBUG_PRINTF("Reply, %d in %d\n", din_desired, cmd->din_xfer_len);
      ide_atapi_cmd_reply(s, din_desired, cmd->din_xfer_len);
  }
  
@@ -143,11 +145,11 @@ index 92f2934..c2a24ec 100644
  static void ide_atapi_pt_dout_fetch_dma_done(void *opaque, int ret)
  {
      BMDMAState *bm = opaque;
-@@ -850,13 +920,15 @@ static void ide_atapi_pt_dout_fetch_dma_done(void *opaque, int ret)
+@@ -850,13 +917,15 @@ static void ide_atapi_pt_dout_fetch_dma_done(void *opaque, int ret)
  
      if (ret < 0) {
          ide_atapi_io_error(s, ret);
-+      pthread_mutex_unlock(&s->atapi_pt.sgio_mutex);
++        pthread_mutex_unlock(&s->atapi_pt.sgio_mutex);
          return;
      }
  
@@ -160,7 +162,7 @@ index 92f2934..c2a24ec 100644
  static void ide_atapi_pt_wcmd(IDEState *s)
  {
      if (s->atapi_dma)
-@@ -1005,11 +1077,20 @@ static int ide_atapi_pt_read_cd_block_size(const uint8_t *io_buffer)
+@@ -1005,11 +1074,20 @@ static int ide_atapi_pt_read_cd_block_size(const uint8_t *io_buffer)
      return block_size;
  }
  
@@ -181,7 +183,7 @@ index 92f2934..c2a24ec 100644
      memset(cmd, 0, sizeof(*cmd));
      memcpy(s->atapi_pt.request, s->io_buffer, ATAPI_PACKET_SIZE);
      cmd_code = s->atapi_pt.request[0];
-@@ -1021,6 +1102,7 @@ static void ide_atapi_pt_cmd(IDEState *s)
+@@ -1021,6 +1099,7 @@ static void ide_atapi_pt_cmd(IDEState *s)
      cmd->response         = (__u64)&s->atapi_pt.sense;
      cmd->max_response_len = sizeof(s->atapi_pt.sense);
      cmd->timeout          = 15000; // 15 seconds
@@ -189,11 +191,11 @@ index 92f2934..c2a24ec 100644
  
      s->status |= BUSY_STAT;
  
-@@ -1054,14 +1136,15 @@ static void ide_atapi_pt_cmd(IDEState *s)
+@@ -1054,14 +1133,15 @@ static void ide_atapi_pt_cmd(IDEState *s)
              ide_atapi_pt_set_error(s, SENSE_ILLEGAL_REQUEST,
                                     ASC_INV_FIELD_IN_CMD_PACKET, 0x70);
  
-+      pthread_mutex_unlock(&s->atapi_pt.sgio_mutex);
++        pthread_mutex_unlock(&s->atapi_pt.sgio_mutex);
          return;
  
      case GPCMD_BLANK: // bigger timeout while blanking
@@ -207,15 +209,15 @@ index 92f2934..c2a24ec 100644
          break;
  
      case GPCMD_WRITE_BUFFER:
-@@ -1072,6 +1155,7 @@ static void ide_atapi_pt_cmd(IDEState *s)
+@@ -1072,6 +1152,7 @@ static void ide_atapi_pt_cmd(IDEState *s)
                           s->io_buffer[1] & 7);
              ide_atapi_pt_set_error(s, SENSE_ILLEGAL_REQUEST,
                                     ASC_ILLEGAL_OPCODE, 0x70);
-+          pthread_mutex_unlock(&s->atapi_pt.sgio_mutex);
++            pthread_mutex_unlock(&s->atapi_pt.sgio_mutex);
              return;
          }
  
-@@ -1091,6 +1175,7 @@ static void ide_atapi_pt_cmd(IDEState *s)
+@@ -1091,6 +1172,7 @@ static void ide_atapi_pt_cmd(IDEState *s)
          int size = 8 + s->atapi_pt.sense.add_sense_len;
          memcpy(s->io_buffer, &s->atapi_pt.sense, sizeof (s->atapi_pt.sense));
          ide_atapi_cmd_reply(s, size, max_size);
@@ -223,15 +225,15 @@ index 92f2934..c2a24ec 100644
          return;
      }
  
-@@ -1152,6 +1237,7 @@ static void ide_atapi_pt_cmd(IDEState *s)
+@@ -1152,6 +1234,7 @@ static void ide_atapi_pt_cmd(IDEState *s)
                           s->io_buffer[10]);
              ide_atapi_pt_set_error(s, SENSE_ILLEGAL_REQUEST,
                                     ASC_ILLEGAL_OPCODE, 0x70);
-+          pthread_mutex_unlock(&s->atapi_pt.sgio_mutex);
++            pthread_mutex_unlock(&s->atapi_pt.sgio_mutex);
              return;
          }
          break;
-@@ -1169,5 +1255,5 @@ static void ide_atapi_pt_cmd(IDEState *s)
+@@ -1169,5 +1252,5 @@ static void ide_atapi_pt_cmd(IDEState *s)
          return;
      }