Skip to contentSkip to conversation

Add release function to sd for scsi_disk structure

PATCH In review Mike Anderson 2 participants 4 messages Oct 18, 2003 – Oct 22, 2003 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add release function to sd for scsi_disk structure

This patch is against 2.6.0-test8.

This patch removes the delay in calling device_del on the sdev struct device during a surprise removal event. Reference counting functions for sd's scsi_disk structure where also added to fix issues of unregistering when a sd is open.

I have tested this patch using scsi_debug with differnt combinations of adds / removes. I mounted both partitioned and un-partitioned sd disks, remove the host, and then did a umount. The ref count debug output shows the objects staying in place prior to the umount and cleaning up once the umount is called.

-andmike
--
Michael Anderson
[email protected]

DESC
This patch fixes an issue with a delayed call of device_del on the sdev_gendev struct device.
- Remove the delayed call to device_del.
- Add kobject to sd scsi_disk structure.
- Add release function for scsi_disk kobject.
- Add get / put functions for scsi_disk and calls to these functions.
EDESC

 drivers/scsi/scsi.c       |    4 --
 drivers/scsi/scsi_sysfs.c |    3 --
 drivers/scsi/sd.c         |   63 ++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 57 insertions(+), 13 deletions(-)
drivers/scsi/scsi_sysfs.c renamed from drivers/scsi/scsi_sysfs.c~blkdev_release +1 -2
diff -puN drivers/scsi/scsi_sysfs.c~blkdev_release drivers/scsi/scsi_sysfs.c
@@ -412,8 +412,7 @@ void scsi_remove_device(struct scsi_devi
 		set_bit(SDEV_DEL, &sdev->sdev_state);
 		if (sdev->host->hostt->slave_destroy)
 			sdev->host->hostt->slave_destroy(sdev);
-		if (!atomic_read(&sdev->access_count))
-			device_del(&sdev->sdev_gendev);
+		device_del(&sdev->sdev_gendev);
 		up_write(&class->subsys.rwsem);
 	}
 
drivers/scsi/scsi.c renamed from drivers/scsi/scsi.c~blkdev_release +1 -3
diff -puN drivers/scsi/scsi.c~blkdev_release drivers/scsi/scsi.c
@@ -914,9 +914,7 @@ void scsi_device_put(struct scsi_device 
 		return;
 
 	module_put(sdev->host->hostt->module);
-	if (atomic_dec_and_test(&sdev->access_count))
-		if (test_bit(SDEV_DEL, &sdev->sdev_state))
-			device_del(&sdev->sdev_gendev);
+	atomic_dec(&sdev->access_count);
 	put_device(&sdev->sdev_gendev);
 	class_put(&sdev_class);
 }
drivers/scsi/sd.c renamed from drivers/scsi/sd.c~blkdev_release +55 -8

132 lines not on this page · raw message

_

#1 lore raw
Quoted 7 lines · Mike Anderson

This patch is against 2.6.0-test8.

This patch removes the delay in calling device_del on the sdev struct device during a surprise removal event. Reference counting functions for sd's scsi_disk structure where also added to fix issues of unregistering when a sd is open.

Quoted 5 lines

I have tested this patch using scsi_debug with differnt combinations of adds / removes. I mounted both partitioned and un-partitioned sd disks, remove the host, and then did a umount. The ref count debug output shows the objects staying in place prior to the umount and cleaning up once the umount is called.

This looks like a reasonable bandaid until the block layer is fixed.

#2 lore raw
Quoted 3 lines · Christoph Hellwig [[email protected]] wrote:

This looks like a reasonable bandaid until the block layer is fixed.

Since I do not know the extent of the block layer changes maybe my assumption is incorrect, but wouldn't will still need a release of some kind to know when it is safe to do a free?

-andmike
--
Michael Anderson
[email protected]

#3 lore raw
Quoted 8 lines · Mike Anderson
Quoted 3 lines · Christoph Hellwig [[email protected]] wrote:

This looks like a reasonable bandaid until the block layer is fixed.

Since I do not know the extent of the block layer changes maybe my assumption is incorrect, but wouldn't will still need a release of some kind to know when it is safe to do a free?

We'll have to see. My assumption would be that freeing any private data should be fine after ->remove. If that's not going to be guaranteed we should try to make your patch a bit more generic (e.g. no sd-specific ktype)