Skip to contentSkip to conversation

abstract out more scsi_device acess out of the low-level drivers

PATCH New Christoph Hellwig 1 participant 1 message Nov 28, 2002

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 abstract out more scsi_device acess out of the low-level drivers

Two new helpers: scsi_device_get and scsi_device_put that get/release a reference to the underlying HBA driver and increment/decrement ->access_count. Cleanup ->attach/->detach routines in the upper layer drivers a bit to consolidate the error pathes once we're cleaning them up.

->attach and ->detach in upper layer drivers are mandatory now (not having them would be rather pointless).

(note that the sd.c changes are not in this patch, it'll be part of my next, bigger patch)

drivers/scsi/osst.c +5 -8
@@ -4232,14 +4232,14 @@
 #endif
 		return (-EBUSY);
 	}
-	if (!try_module_get(STp->device->host->hostt->module)) {
+
+	if (!scsi_device_get(STp->device)) {
 		write_unlock(&os_scsi_tapes_lock);
 #if DEBUG
-                printk(OSST_DEB_MSG "%s:D: Failed try_module_get.\n", name);
+                printk(OSST_DEB_MSG "%s:D: Failed scsi_device_get.\n", name);
 #endif
 		return (-ENXIO);
 	}
-	STp->device->access_count++;
 	filp->private_data = STp;
 	STp->in_use = 1;
 	write_unlock(&os_scsi_tapes_lock);
@@ -4587,9 +4587,7 @@
 	normalize_buffer(STp->buffer);
 	STp->header_ok = 0;
 	STp->in_use = 0;
-	STp->device->access_count--;
-
-	module_put(STp->device->host->hostt->module);
+	scsi_device_put(STp->device);
 
 	return retval;
 }
@@ -4717,9 +4715,8 @@
 	write_lock(&os_scsi_tapes_lock);
 	STp->in_use = 0;
 	write_unlock(&os_scsi_tapes_lock);
-	STp->device->access_count--;
 
-	module_put(STp->device->host->hostt->module);
+	scsi_device_put(STp->device);
 
 	return result;
 }

===== drivers/scsi/scsi.c 1.75 vs edited =====

drivers/scsi/scsi.c +29 -25

85 lines not on this page · raw message

===== drivers/scsi/scsi.h 1.48 vs edited =====

drivers/scsi/scsi.h +4 -2
@@ -451,8 +451,10 @@
 extern void scsi_build_commandblocks(Scsi_Device * SDpnt);
 extern void scsi_adjust_queue_depth(Scsi_Device *, int, int);
 extern int scsi_track_queue_full(Scsi_Device *, int);
-extern int scsi_slave_attach(struct scsi_device *sdev);
-extern void scsi_slave_detach(struct scsi_device *sdev);
+extern int scsi_slave_attach(struct scsi_device *);
+extern void scsi_slave_detach(struct scsi_device *);
+extern int scsi_device_get(struct scsi_device *);
+extern void scsi_device_put(struct scsi_device *);
 extern void scsi_done(Scsi_Cmnd * SCpnt);
 extern void scsi_finish_command(Scsi_Cmnd *);
 extern int scsi_retry_command(Scsi_Cmnd *);

===== drivers/scsi/scsi_scan.c 1.45 vs edited =====

drivers/scsi/scsi_scan.c +1 -1
@@ -1419,7 +1419,7 @@
 	return SCSI_SCAN_LUN_PRESENT;
 }
 
-static int scsi_remove_lun(struct scsi_device *sdev)
+static void scsi_remove_lun(struct scsi_device *sdev)
 {
 	devfs_unregister(sdev->de);
 	device_unregister(&sdev->sdev_driverfs_dev);

===== drivers/scsi/scsi_syms.c 1.21 vs edited =====

drivers/scsi/scsi_syms.c +2 -0
@@ -81,6 +81,8 @@
 EXPORT_SYMBOL(scsi_deregister_blocked_host);
 EXPORT_SYMBOL(scsi_slave_attach);
 EXPORT_SYMBOL(scsi_slave_detach);
+EXPORT_SYMBOL(scsi_device_get);
+EXPORT_SYMBOL(scsi_device_put);
 
 /*
  * This symbol is for the highlevel drivers (e.g. sg) only.
drivers/scsi/sg.c +29 -27

126 lines not on this page · raw message

===== drivers/scsi/sr.c 1.66 vs edited =====

drivers/scsi/sr.c +33 -25

105 lines not on this page · raw message

===== drivers/scsi/st.c 1.45 vs edited =====

drivers/scsi/st.c +4 -6
@@ -991,9 +991,9 @@
 		DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); )
 		return (-EBUSY);
 	}
-	if(!try_module_get(STp->device->host->hostt->module))
+
+	if(!scsi_device_get(STp->device))
 		return (-ENXIO);
-	STp->device->access_count++;
 	STp->in_use = 1;
 	write_unlock(&st_dev_arr_lock);
 	STp->rew_at_close = STp->autorew_dev = (minor(inode->i_rdev) & 0x80) == 0;
@@ -1038,8 +1038,7 @@
  err_out:
 	normalize_buffer(STp->buffer);
 	STp->in_use = 0;
-	STp->device->access_count--;
-	module_put(STp->device->host->hostt->module);
+	scsi_device_put(STp->device);
 	return retval;
 
 }
@@ -1172,8 +1171,7 @@
 	write_lock(&st_dev_arr_lock);
 	STp->in_use = 0;
 	write_unlock(&st_dev_arr_lock);
-	STp->device->access_count--;
-	module_put(STp->device->host->hostt->module);
+	scsi_device_put(STp->device);
 
 	return result;
 }