Bug fixed:the scsi device can not complete it's writing data command

View: New views
1 Messages — Rating Filter:   Alert me  

Bug fixed:the scsi device can not complete it's writing data command

by tmys2002 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hello everyone
I have installed LFS6.3(linux kernel 2.6.22) on the Bochs(2.3.7, with USB and PCI support enabled).Linux run well.However I get trouble with the USBDisk.img when using usb1.It works well when I read the file in the USBDisk.img,but It can not write the data into it properly,linux reports there is some I/O errer.I try 2.3.5 too.There is the same problem.So I debuged the bochs,and luckly I think I found the problem(Maybe it has been fixed already).
 
diff -Naur bochs-2.3.7.origin/iodev/scsi_device.cc bochs-2.3.7/iodev/scsi_device.cc
--- bochs-2.3.7.origin/iodev/scsi_device.cc 2008-01-27 06:24:02.000000000 +0800
+++ bochs-2.3.7/iodev/scsi_device.cc 2008-09-21 22:54:17.000000000 +0800
@@ -264,14 +264,18 @@
         scsi_command_complete(r, SENSE_HARDWARE_ERROR);
       }
       ret = hdimage->write((bx_ptr_t)r->dma_buf, r->buf_len);
+     
+      r->sector += n;
+      r->sector_count -= n;
+
       if (ret < r->buf_len) {
         BX_ERROR(("could not write() hard drive image file"));
         scsi_command_complete(r, SENSE_HARDWARE_ERROR);
       } else {
         scsi_write_complete((void*)r, 0);
       }
-      r->sector += n;
-      r->sector_count -= n;
+      //r->sector += n;
+      //r->sector_count -= n;
     } else {
       scsi_write_complete(r, 0);
     }
 
I will explain it.It seemed the usb_msd_device_t can not change its mode from USB_MSDM_DATAOUT to USB_MSDM_CSW,when usb_msd_device_t finished writing data to the disk.So when The linux checked the state of USBDisk by CWS, it made USB subsystem reports I/O errer. The problem is that the scsi device can not complete it's scsi write data command when executes it.
 
in bochs2.3.7.origin/iodev/scsi_device.cc
int scsi_device_t::scsi_write_data(Bit32u tag)
.....
      ret = hdimage->write((bx_ptr_t)r->dma_buf, r->buf_len);
      if (ret < r->buf_len) {
        BX_ERROR(("could not write() hard drive image file"));
        scsi_command_complete(r, SENSE_HARDWARE_ERROR);
      } else {
        scsi_write_complete((void*)r, 0);
      }
 
      r->sector += n;
      r->sector_count -= n;
 
......
In the origin code,
on the assumption that r->sector_count = n before the execution of hdimage->write,  after hdimage->write((bx_ptr_t)r->dma_buf, r->buf_len) successfully executed, scsi_write_complete function executes first and then update r->sector_count by subtracting n. In scsi_write_complete function, the scsi device will not know r->sector_count will become 0, so it can not figure that current scsi command is over and must execute scsi_command_complete function(Maybe this is the only chance to execute scsi_command_complete(r, SENSE_NO_SENSE) for writing).This makes usb_msd_device_t can not change its mode.
 
in iodev/scsi_device.cc
void scsi_device_t::scsi_write_complete(void *req, int ret)
{
  SCSIRequest *r = (SCSIRequest *)req;
  Bit32u len;
 
  if (ret) {
    BX_ERROR(("IO error"));
    scsi_command_complete(r, SENSE_HARDWARE_ERROR);
    return;
  }
 
  if (r->sector_count == 0) {                 ////////here r->sector_count is checked                     
    scsi_command_complete(r, SENSE_NO_SENSE);
  } else {
.....
 
So I think we must update r->sector_count immediately not after scsi_command_complete(r, SENSE_HARDWARE_ERROR) or scsi_write_complete((void*)r, 0) executes. I change it like this patch.The USBDisk is work well.I think the Disk.img encounters the problem too,maybe it just ignore.
 
          Best wishes
          naiyue
          2008-9

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
bochs-developers mailing list
bochs-developers@...
https://lists.sourceforge.net/lists/listinfo/bochs-developers
LightInTheBox - Buy quality products at wholesale price!