You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
229 /* Wait for the aborted command to finish */<br />
230 wait_for_completion(&us->notify);<br />
231<br />
232 /* Reacquire the lock and allow USB transfers to resume */<br />
233 scsi_lock(host);<br />
234 clear_bit(US_FLIDX_ABORTING, &us->flags);<br />
191<br />
235 clear_bit(US_FLIDX_TIMED_OUT, &us->flags);<br />
236 return SUCCESS;<br />
237 }<br />
既然是阻止某个命令,那么传递进来的参数当然是struct scsi_cmnd的指针了.前两行的赋值无须多说.<br />
212 行,us->srb 表示的是当前的srb,而srb 是这个函数传进来的参数,command_abort()希望的是中<br />
止当前的命令,而假如传进来的参数根本就不是当前的命令,那么肯定有问题.啥也不说了,直接返回<br />
FAILED.<br />
然后,在abort 的时刻,设置US_FLIDX_TIMED_OUT 的flag,然后如果设备没有reset,那么继续再设<br />
置另一个flag,US_FLIDX_ABORTING,然后调用usb_stor_stop_transport(),这个函数的目的很简单,<br />
阻止任何进行中的传输,这个函数定义于drivers/usb/storage/transport.c 中:<br />
730 /* Stop the current URB transfer */<br />
731 void usb_stor_stop_transport(struct us_data *us)<br />
732 {<br />
733 US_DEBUGP("%s called\n", __FUNCTION__);<br />
734<br />
735 /* If the state machine is blocked waiting for an URB,<br />
736 * let's wake it up. The test_and_clear_bit() call<br />
737 * guarantees that if a URB has just been submitted,<br />
738 * it won't be cancelled more than once. */<br />
739 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->flags)) {<br />
740 US_DEBUGP("-- cancelling URB\n");<br />
741 usb_unlink_urb(us->current_urb);<br />
742 }<br />
743<br />
744 /* If we are waiting for a scatter-gather operation, cancel it. */<br />
745 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->flags)) {<br />
746 US_DEBUGP("-- cancelling sg request\n");<br />
747 usb_sg_cancel(&us->current_sg);<br />
748 }<br />
749 }<br />
这里有两个flag,US_FLIDX_URB_ACTIVE 和US_FLIDX_SG_ACTIVE,前一个flag 咱们此前在讲<br />
storage_probe()的时候遇见过,当时咱们为了获得max lun,曾经提交过urb,而在<br />
usb_stor_msg_common()函数中,在urb 被成功提交了之后,调用set_bit()宏为us->flags 设置了这<br />
一位,于是这里就可以先判断,如果确实设置了,那么此时就可以调用usb_unlink_urb 来从urb 队列中取<br />
下<br />
来,因为没有必要再连接在上面了.<br />
而US_FLIDX_SG_ACTIVE 这个flag 咱们也不陌生,在bulk 传输里会用到.设置这个flag 的是bulk 传