public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@steeleye.com>
To: Jens Axboe <axboe@suse.de>
Cc: Patrick Mansfield <patmans@us.ibm.com>,
	Andrew Morton <akpm@osdl.org>,
	greg@kroah.com, linux-usb-devel@lists.sourceforge.net,
	SCSI Mailing List <linux-scsi@vger.kernel.org>
Subject: Re: bug 2400
Date: 06 Apr 2004 08:56:45 -0500	[thread overview]
Message-ID: <1081259807.1804.9.camel@mulgrave> (raw)
In-Reply-To: <20040406092244.GH28109@suse.de>

On Tue, 2004-04-06 at 04:22, Jens Axboe wrote:
> Really? It doesn't even compile :-)

Heh, I really must learn that I have to copy the file from the test
machine to the email machine *before* attaching it.  You got a stale
copy of an older incarnation, I think.

The attached (hopefully) is what I compiled and tested with.  The test,
incidentally, is simply to hold the device open and then forcibly remove
it using scsi remove-single-device before closing it.

James

===== drivers/scsi/sr.c 1.103 vs edited =====
--- 1.103/drivers/scsi/sr.c	Fri Apr  2 11:30:44 2004
+++ edited/drivers/scsi/sr.c	Tue Apr  6 08:49:30 2004
@@ -113,6 +113,28 @@
 	.generic_packet		= sr_packet,
 };
 
+static void sr_kobject_release(struct kobject *kobj);
+
+static struct kobj_type scsi_cdrom_kobj_type = {
+	.release = sr_kobject_release,
+};
+
+/*
+ * The get and put routines for the struct scsi_cd.  Note this entity
+ * has a scsi_device pointer and owns a reference to this.
+ */
+static inline int scsi_cd_get(struct scsi_cd *cd)
+{
+	if (!kobject_get(&cd->kobj))
+		return -ENODEV;
+	return 0;
+}
+
+static inline void scsi_cd_put(struct scsi_cd *cd)
+{
+	kobject_put(&cd->kobj);
+}
+
 /*
  * This function checks to see if the media has been changed in the
  * CDROM drive.  It is possible that we have already sensed a change,
@@ -424,8 +446,15 @@
 
 static int sr_block_release(struct inode *inode, struct file *file)
 {
+	int ret;
 	struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk);
-	return cdrom_release(&cd->cdi, file);
+	ret = cdrom_release(&cd->cdi, file);
+	if(ret)
+		return ret;
+	
+	scsi_cd_put(cd);
+
+	return 0;
 }
 
 static int sr_block_ioctl(struct inode *inode, struct file *file, unsigned cmd,
@@ -467,7 +496,7 @@
 	struct scsi_device *sdev = cd->device;
 	int retval;
 
-	retval = scsi_device_get(sdev);
+	retval = scsi_cd_get(cd);
 	if (retval)
 		return retval;
 	
@@ -489,7 +518,7 @@
 	return 0;
 
 error_out:
-	scsi_device_put(sdev);
+	scsi_cd_put(cd);
 	return retval;	
 }
 
@@ -500,7 +529,6 @@
 	if (cd->device->sector_size > 2048)
 		sr_set_blocklength(cd, 2048);
 
-	scsi_device_put(cd->device);
 }
 
 static int sr_probe(struct device *dev)
@@ -514,12 +542,18 @@
 	if (sdev->type != TYPE_ROM && sdev->type != TYPE_WORM)
 		goto fail;
 
+	if ((error = scsi_device_get(sdev)) != 0)
+		goto fail;
+
 	error = -ENOMEM;
 	cd = kmalloc(sizeof(*cd), GFP_KERNEL);
 	if (!cd)
-		goto fail;
+		goto fail_put_sdev;
 	memset(cd, 0, sizeof(*cd));
 
+	kobject_init(&cd->kobj);
+	cd->kobj.ktype = &scsi_cdrom_kobj_type;
+
 	disk = alloc_disk(1);
 	if (!disk)
 		goto fail_free;
@@ -588,6 +622,8 @@
 	put_disk(disk);
 fail_free:
 	kfree(cd);
+fail_put_sdev:
+	scsi_device_put(sdev);
 fail:
 	return error;
 }
@@ -863,19 +899,31 @@
 	return cgc->stat;
 }
 
-static int sr_remove(struct device *dev)
+static void sr_kobject_release(struct kobject *kobj)
 {
-	struct scsi_cd *cd = dev_get_drvdata(dev);
-
-	del_gendisk(cd->disk);
+	struct scsi_cd *cd = container_of(kobj, struct scsi_cd, kobj);
+	struct scsi_device *sdev = cd->device;
 
 	spin_lock(&sr_index_lock);
 	clear_bit(cd->disk->first_minor, sr_index_bits);
 	spin_unlock(&sr_index_lock);
 
-	put_disk(cd->disk);
 	unregister_cdrom(&cd->cdi);
+
+	put_disk(cd->disk);
+
 	kfree(cd);
+
+	scsi_device_put(sdev);
+}
+
+static int sr_remove(struct device *dev)
+{
+	struct scsi_cd *cd = dev_get_drvdata(dev);
+
+	del_gendisk(cd->disk);
+
+	scsi_cd_put(cd);
 
 	return 0;
 }



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

  reply	other threads:[~2004-04-06 13:56 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-01 21:15 bug 2400 Andrew Morton
2004-04-01 21:52 ` Matt Gulick
2004-04-01 22:08   ` Andrew Morton
2004-04-01 22:48     ` Matt Gulick
2004-04-01 22:40   ` James Bottomley
2004-04-01 22:53     ` Matt Gulick
2004-04-01 23:07 ` Matthew Dharm
2004-04-01 23:32 ` James Bottomley
2004-04-02  0:29   ` Steven Dake
2004-04-02  8:43   ` Mike Anderson
2004-04-02 15:57     ` James Bottomley
2004-04-02 16:45       ` Mike Anderson
2004-04-02 17:05         ` James Bottomley
2004-04-02 17:44           ` Mike Anderson
2004-04-02 18:13             ` James Bottomley
2004-04-02 23:40               ` Mike Anderson
2004-04-03  0:25                 ` James Bottomley
2004-04-04  1:40                   ` Alan Stern
2004-04-04 15:23                     ` James Bottomley
2004-04-04 16:46                       ` Alan Stern
2004-04-04 17:04                         ` James Bottomley
2004-04-05  3:17                           ` Alan Stern
2004-04-05 14:59                             ` Mike Anderson
2004-04-05 21:27                             ` James Bottomley
2004-04-06 14:00                               ` Alan Stern
2004-04-05 22:10                             ` Patrick Mansfield
2004-04-06 14:10                               ` Alan Stern
2004-04-08 14:09                               ` Alan Stern
2004-04-08 16:24                                 ` Matt Gulick
2004-04-08 18:33                                   ` Alan Stern
2004-04-08 19:44                                     ` Matt Gulick
2004-04-05 13:30                           ` [linux-usb-devel] " Oliver Neukum
2004-04-04 18:16                       ` David Brownell
2004-04-04 18:42                         ` James Bottomley
2004-04-05  3:54                           ` David Brownell
2004-04-05 21:44                             ` James Bottomley
2004-04-05 23:23                               ` [linux-usb-devel] " David Brownell
2004-04-06  1:19                                 ` James Bottomley
2004-04-06  6:52                                   ` Oliver Neukum
2004-04-06 14:03                                     ` James Bottomley
2004-04-07  9:19                                       ` Oliver.Neukum
2004-04-06 15:10                                   ` David Brownell
2004-04-06 15:47                                     ` James Bottomley
2004-04-06 16:16                                       ` David Brownell
2004-04-06 16:55                                       ` Alan Stern
2004-04-06 17:13                                         ` James Bottomley
2004-04-02 23:36   ` James Bottomley
2004-04-03  0:11     ` Mike Anderson
2004-04-03  0:16       ` James Bottomley
2004-04-05  4:33     ` Patrick Mansfield
2004-04-05 14:09       ` James Bottomley
2004-04-05 21:07       ` James Bottomley
2004-04-06  9:22         ` Jens Axboe
2004-04-06 13:56           ` James Bottomley [this message]
2004-04-06 14:04             ` Jens Axboe
2004-04-06 14:09               ` James Bottomley
2004-04-08 23:06         ` Greg KH
2004-04-09 11:28           ` James Bottomley
2004-04-05 14:03     ` Jens Axboe
2004-04-05 21:08       ` James Bottomley
2004-04-06  9:22         ` Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2004-04-06 15:09 Heiko Carstens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1081259807.1804.9.camel@mulgrave \
    --to=james.bottomley@steeleye.com \
    --cc=akpm@osdl.org \
    --cc=axboe@suse.de \
    --cc=greg@kroah.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=patmans@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox