1. SCSI subsystem Initialization
The SCSI subsystem is always compiled to the Linux kernel, and its initialization entry function isInit_scsiIn the drivers/SCSI. c file. It is defined using the macro subsys_initcall.
Static int _ init init_scsi (void)
{
Int error;
Error = scsi_init_queue ();
// Initialize the storage pool required for the aggregation list.
If (error)
Return Error;
Error = scsi_init_procfs (); // initialize the SCSI-related directory in the proc file system
If (error)
Goto cleanup_queue;
Error = scsi_init_devinfo (); // sets the SCSI dynamic device information list.
If (error)
Goto cleanup_procfs;
Error = scsi_init_hosts (); // register the shost_class class. This will create the scsi_host subdirectory in the SYS/class/directory.
If (error)
Goto cleanup_devlist;
Error = scsi_init_sysctl (); // register the SCSI system control table
If (error)
Goto cleanup_hosts;
Error = scsi_sysfs_register ();
// Register the SCSI bus type and sdev_class class
If (error)
Goto cleanup_sysctl;
Scsi_netlink_init ();
// Initialize the SCSI transmission Netlink interface. Netlink is a mechanism for the Linux kernel to communicate with the user space.
Printk (kern_notice "SCSI subsystem initialized \ n ");
Return 0;
Cleanup_sysctl:
Scsi_exit_sysctl ();
Cleanup_hosts:
Scsi_exit_hosts ();
Cleanup_devlist:
Scsi_exit_devinfo ();
Cleanup_procfs:
Scsi_exit_procfs ();
Cleanup_queue:
Scsi_exit_queue ();
Printk (kern_err "SCSI subsystem failed to initialize, error = % d \ n ",
-Error );
Return Error;
}
2. Exit the SCSI subsystem exit_scsi.
Static void _ exit exit_scsi (void)
{
Scsi_netlink_exit ();
Scsi_sysfs_unregister ();
Scsi_exit_sysctl ();
Scsi_exit_hosts ();
Scsi_exit_devinfo ();
Scsi_exit_procfs ();
Scsi_exit_queue ();
}