07.06.2013 Views

Scsi - Index of

Scsi - Index of

Scsi - Index of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1040 /* Interrupt the SCSI-device-scanning thread's time delay, and<br />

1041 * wait for the thread to finish */<br />

1042 wake_up(&us->scsi_scan_wait);<br />

1043 wait_for_completion(&us->scsi_scan_done);<br />

1044<br />

1045 /* Wait for the current command to finish, then remove the host */<br />

1046 down(&us->dev_semaphore);<br />

1047 up(&us->dev_semaphore);<br />

1048 scsi_remove_host(us->host);<br />

1049<br />

1050 /* Wait for everything to become idle and release all our resources */<br />

1051 usb_stor_release_resources(us);<br />

1052 dissociate_dev(us);<br />

1053 }<br />

如果直到现在你还不知道1030 行在干嘛,那我想问一下你他妈的是不是在耍我?虽然<br />

usb_get_intfdata()这个函数的确是第一次露面,但是这里的含义已然是司马昭之心路人皆<br />

知.usb_get_infdata()我们是没有讲过,但是我们讲过usb_set_intfdata().想当年,associate_dev()<br />

中,<br />

我们调用usb_set_intfdata(intf,us),当时我们分析了,这样做的结果就是使得<br />

%intf->dev->driver_data=us,而现在我们调用usb_get_intfdata(intf)的作用就是把us 从中取出<br />

来,<br />

赋给我们这里的临时指针us.<br />

1036 行,全文中唯一一处设置US_FLIDX_DISCONNECTING 这个flag 的地方就在这里.<br />

1037 行, usb_stor_stop_transport(us),这个函数我们可是刚刚才讲过,你别说你就忘记了,就在<br />

command_abort()里调用的.目的就是停掉当前的urb 和sg,如果有的话.<br />

1038 行, wake_up(&us->dev_reset_wait),我们也已经讲过了,就是在讲device_reset()讲到的,<br />

当时在usb_stor_reset_common()中,会使用wait_event_interruptible_timeout()来进入睡眠,睡眠<br />

的目的是给6 秒钟来让设备从reset 状态恢复过来,但是如果在这期间我们要断开设备了,那么当然就没有<br />

必要再让那边继续睡眠了,设备都要断开了,还有什么恢复的意义呢?所以对于这种情况,我们回过头来看<br />

usb_stor_reset_common(),会发现之后该函数立马从睡眠中醒来,然后清除掉为reset 而设置的<br />

flag,US_FLIDX_RESETTING,然后就返回了,返回值是FAILED.<br />

1042 行, wake_up(&us->scsi_scan_wait),和上面这种情况几乎相同,不同的是这次唤醒的是<br />

usb_stor_scan_thread,这个函数里边也会因为delay_use 的设置而调用<br />

wait_event_interrruptible_timeout 去等待去睡眠,所以这里机理是一样的.而与此同时,1043 行,<br />

wait_for_completion(&us->scsi_scan_done),恰恰是是等待对方的结束,我们注意到,在<br />

usb_stor_scan_thread()中最后一句话, complete_and_exit(&us->scsi_scan_done, 0),即唤醒咱<br />

们这里这个storage_disconnect()同时结束它自己.应该说这样就实现了一个同步机制.就是说因为我们<br />

195<br />

之后马上要做的就是清理门户了,把一些不要的资源都释放掉,所以我们首先必须保证我们的进程都退出来,<br />

资源都不再被人使用,这样我们才可以放心的去做我们的清理工作.<br />

1048 行,scsi_remove_host()被调用,这是和最早的scsi_add_host 相对应的.都是调用scsi core 提<br />

供的函数.<br />

1051 行,usb_stor_release_resources(us),这个则是和我们当初那个<br />

usb_stor_acquire_resources(us)相对应.而1052 行的dissociate_dev(us)则是和当初那个

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!