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.

856 scsi_host_put(us->host);<br />

857<br />

858 /* Free the extra data and the URB */<br />

859 if (us->extra)<br />

860 kfree(us->extra);<br />

861 if (us->current_urb)<br />

862 usb_free_urb(us->current_urb);<br />

863<br />

864 }<br />

865<br />

866 /* Dissociate from the USB device */<br />

867 static void dissociate_dev(struct us_data *us)<br />

868 {<br />

869 US_DEBUGP("-- %s\n", __FUNCTION__);<br />

870<br />

871 /* Free the device-related DMA-mapped buffers */<br />

872 if (us->cr)<br />

873 usb_buffer_free(us->pusb_dev, size<strong>of</strong>(*us->cr), us->cr,<br />

874 us->cr_dma);<br />

875 if (us->iobuf)<br />

876 usb_buffer_free(us->pusb_dev, US_IOBUF_SIZE, us->iobuf,<br />

877 us->iobuf_dma);<br />

878<br />

879 /* Remove our private data from the interface */<br />

880 usb_set_intfdata(us->pusb_intf, NULL);<br />

881<br />

882 /* Free the structure itself */<br />

883 kfree(us);<br />

884 }<br />

823 行,判断us 的pid,这个pid 是哪来的?很显然,usb_stor_release_resources 和咱们前面说过的<br />

usb_stor_acquire_resources 函数是一对,us->pid 也正是来自usb_stor_acquire_resources()函<br />

数,<br />

当时在调用kernel_thread 启动usb_stor_control_thread 的时候,记下了kernel_thread()的返回值,<br />

并把她赋给了us->pid,实际上kernel_thread()对于父进程来说,返回值就是子进程的pid,也就是说当年<br />

创建的精灵进程的pid 是被记录下来了的.写代码的人老辣的编程功底可见一斑.<br />

840 行,设置us->srb 为NULL.<br />

197<br />

844 行和845 行,up(&us->sema),以及wait_for_completion(&us->notify),知道这两句干嘛的吗?<br />

还记得usb_stor_control_thread(),当初讲到down_interruptible(&us->sema),咱们就说该守护进<br />

程进入了睡眠,那么谁能把她唤醒,除了前面讲的queuecommand 之外,这里同样也是唤醒她的代码,并且<br />

这个函数在唤醒别人之后,自己执行wait_for_completion 函数来进入等待.好,再次回到那个函数<br />

吧,usb_stor_control_thread(),303 行,被up()唤醒的down_interruptible 返回0.然后312 行到<br />

316<br />

行的这个if 小段当然就会执行了,因为us->srb 这时候毫无疑问,等于NULL,所以break 会被执行,从而结

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

Saved successfully!

Ooh no, something went wrong!