Skip to contentSkip to conversation

Problems with USB Mass Storage emulation

Qemu-devel Dmitri Vorobiev 2 participants 2 messages Sep 26, 2009 – Sep 28, 2009 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 1253983134.3374.12.camel@codedot

#1 lore raw

Hello,

We tried to use an emulated USB Mass Storage device with my QEMU-emulated system (Debian GNU/Linux, MIPS architecture, but the same problem is present also for a similar x86 version). fdisk(1) works fine. However, when formatting is going on or a big file is being copied into the USB-MS partition, some errors occur and the system starts working extremely slowly.

There's an example of such a session below.

Can someone please help us out with the emulated USB pendrive?

Thanks,
Dmitri

[Creating an image of one gigabyte:]

alexo@codedot:~/Projects/uniweb$ qemu-img create flash.raw 1G
Formatting 'flash.raw', fmt=raw, size=1048576 kB

[Connecting it as a USB Mass Storage device:]

(qemu) usb_add disk:format=raw:flash.raw

[Partitioning the device and trying to format it:]

uniweb:~# fdisk /dev/sda
Device contains neither a valid DOS partition table, nor Sun, SGI or
OSF disklabel
Building a new DOS disklabel with disk identifier 0x2be81509.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sda: 1073 MB, 1073741824 bytes
34 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 2074 * 512 = 1061888 bytes
Disk identifier: 0x2be81509

  Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1011, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1011, default 1011):
Using default value 1011

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

uniweb:~# mke2fs /dev/sda
sda   sda1
uniweb:~# mke2fs /dev/sda1
mke2fs 1.41.3 (12-Oct-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
65536 inodes, 262094 blocks
13104 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
       32768, 98304, 163840, 229376

Writing inode tables: done
Writing superblocks and filesystem accounting information:

[After that, in `dmesg':]

usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 sd 0:0:0:0: [sda] Unhandled error code
sd 0:0:0:0: [sda] Result: hostbyte=0x07 driverbyte=0x00 sd 0:0:0:0: [sda] CDB: cdb[0]=0x2a: 2a 00 00 00 02 55 00 00 80 00
end_request: I/O error, dev sda, sector 597
Buffer I/O error on device sda1, logical block 536
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 537
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 538
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 539
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 540
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 541
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 542
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 543
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 544
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 545
lost page write due to I/O error on sda1
usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 sd 0:0:0:0: [sda] Unhandled error code
sd 0:0:0:0: [sda] Result: hostbyte=0x07 driverbyte=0x00 sd 0:0:0:0: [sda] CDB: cdb[0]=0x2a: 2a 00 00 00 02 d5 00 00 80 00
end_request: I/O error, dev sda, sector 725 __ratelimit: 118 callbacks suppressed
Buffer I/O error on device sda1, logical block 664
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 665
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 666
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 667
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 668
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 669
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 670
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 671
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 672
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 673
lost page write due to I/O error on sda1
usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 sd 0:0:0:0: [sda] Unhandled error code
sd 0:0:0:0: [sda] Result: hostbyte=0x07 driverbyte=0x00 sd 0:0:0:0: [sda] CDB: cdb[0]=0x2a: 2a 00 00 00 01 c5 00 00 80 00
end_request: I/O error, dev sda, sector 453 __ratelimit: 118 callbacks suppressed
Buffer I/O error on device sda1, logical block 392
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 393
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 394
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 395
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 396
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 397
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 398
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 399
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 400
lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 401
lost page write due to I/O error on sda1
usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 sd 0:0:0:0: [sda] Unhandled error code
sd 0:0:0:0: [sda] Result: hostbyte=0x07 driverbyte=0x00 sd 0:0:0:0: [sda] CDB: cdb[0]=0x2a: 2a 00 00 00 02 45 00 00 18 00
end_request: I/O error, dev sda, sector 581
usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 sd 0:0:0:0: [sda] Unhandled error code
sd 0:0:0:0: [sda] Result: hostbyte=0x07 driverbyte=0x00 sd 0:0:0:0: [sda] CDB: cdb[0]=0x2a: 2a 00 00 00 04 55 00 00 80 00
end_request: I/O error, dev sda, sector 1109 __ratelimit: 142 callbacks suppressed
Buffer I/O error on device sda1, logical block 1048 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1049 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1050 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1051 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1052 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1053 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1054 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1055 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1056 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1057 lost page write due to I/O error on sda1
usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 sd 0:0:0:0: [sda] Unhandled error code
sd 0:0:0:0: [sda] Result: hostbyte=0x07 driverbyte=0x00 sd 0:0:0:0: [sda] CDB: cdb[0]=0x2a: 2a 00 00 10 04 c5 00 00 80 00
end_request: I/O error, dev sda, sector 1049797 __ratelimit: 118 callbacks suppressed
Buffer I/O error on device sda1, logical block 1049736 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1049737 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1049738 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1049739 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1049740 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1049741 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1049742 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1049743 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1049744 lost page write due to I/O error on sda1
Buffer I/O error on device sda1, logical block 1049745 lost page write due to I/O error on sda1
usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2 usb 1-2: reset full speed USB device using uhci_hcd and address 2

[Etc. until the formatting is complete (too slowly).]

#2 lore raw
Quoted 8 lines · Dmitri Vorobiev

Hello,

We tried to use an emulated USB Mass Storage device with my QEMU-emulated system (Debian GNU/Linux, MIPS architecture, but the same problem is present also for a similar x86 version). fdisk(1) works fine. However, when formatting is going on or a big file is being copied into the USB-MS partition, some errors occur and the system starts working extremely slowly.

qemu emulates usb 1.1, which *is* slow.

Attached patch gets usb-storage going for me, but I'd classify it as 'hack', not as 'fix'. Fixing it for real would be adding usb 2.0 supprt to qemu. Or fix the linux kernel to deal with usb 1.1 more sanely, which is probably just adjusting the scsi timeouts to the device speed ...

cheers,
Gerd

Quoted 1 line

From 540a948fed07ef3e686097083f078b4803939fb4 Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Tue, 8 Sep 2009 13:53:15 +0200
Subject: [PATCH] make usb 1.1 go insane fast

---
 hw/usb-uhci.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/usb-uhci.c +1 -1
index 6807413..3a770e5 100644
@@ -63,7 +63,7 @@
 #define UHCI_PORT_CSC   (1 << 1)
 #define UHCI_PORT_CCS   (1 << 0)
 
-#define FRAME_TIMER_FREQ 1000
+#define FRAME_TIMER_FREQ 100000
 
 #define FRAME_MAX_LOOPS  100
 
Signature · 1 line
1.6.2.5