usb: gadget: mass_storage: support multi-luns with different logic block size
authorYuping Luo <Yuping.Luo@csr.com>
Wed, 26 Oct 2011 02:13:10 +0000 (19:13 -0700)
committerFelipe Balbi <balbi@ti.com>
Mon, 12 Dec 2011 09:44:59 +0000 (11:44 +0200)
commit144974e7f9e32b53b02f6c8632be45d8f43d6ab5
treedd7df00f65b13f79ed028bbed2cffd83769faab5
parentb4fcea2a71cafc59a749fa3ef88e51af8c2e3b37
usb: gadget: mass_storage: support multi-luns with different logic block size

With Peiyu's patch "gadget: mass_storage: adapt logic block size to bound block
devices" (http://www.spinics.net/lists/linux-usb/msg50791.html), now mass storage
can adjust logic block size dynamically based on real devices.
Then there is one issue caused by it, if two luns have different logic block size,
mass storage can't work.
Let's check the current software flow:
1. get_next_command(): call received_cbw();
2. received_cbw(): update common->lun = cbw->Lun, but common->curlen is not updated;
3. do_scsi_command(): in READ_X and WRITE_X commands, common->data_size_from_cmnd is
updated by common->curlun->blkbits;
4. check_command(): update common->curlun according to common->lun
As you can see, the step 3 uses wrong common->curlun, then wrong common->curlun->blkbits.
If the two luns have same blkbits, there isn't issue. Otherwise, both will fail.
This patch moves the common->curlun update to step 1, then make sure step 3 gets right
blkbits and data_size_from_cmnd.

Cc: Peiyu Li <peiyu.li@csr.com>
Signed-off-by: YuPing Luo <yuping.luo@csr.com>
Signed-off-by: Barry Song <Baohua.Song@csr.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/f_mass_storage.c
drivers/usb/gadget/file_storage.c