All of lore.kernel.org
 help / color / mirror / Atom feed
* Block device driver: how to terminate the block device if media disappears?
@ 2012-12-13 15:31 John Beard
  2012-12-21 18:23 ` Ezequiel Garcia
  0 siblings, 1 reply; 6+ messages in thread
From: John Beard @ 2012-12-13 15:31 UTC (permalink / raw)
  To: kernelnewbies

Hi,

I have block driver for a hot-pluggable device PCIe storage device on
kernel version 2.6.43 (which I know isn't a mainline kernel version, but
it's what I am required to build against). The driver itself is
relatively simple and implements the following block operations:

	static struct block_device_operations mydev_ops = {
        	.owner = THIS_MODULE,
        	.open = mydev_open,
        	.release = mydev_release,
        	.getgeo = mydev_getgeo,
        	.ioctl = mydev_ioctl
	};

and the following PCI driver structure:

	static struct pci_driver mydev_driver = {
		.name = DRIVER_NAME,
        	.probe = mydev_pci_init_one,
        	.remove = mydev_pci_remove_one,
        	.id_table = mydev_pci_tbl,
	};

As well as a request_fn with the following signature:

	static void mydev_submit_req(struct request_queue *q);

Whenever I get IO requests, there is the expected pattern of "open, IO,
release", and everything works OK.

However, if the device is physically removed during IO, I never seem to
get a "release", just "open, IO, hang". I believe (but I don't know),
that this is preventing del_gendisk() from completing, thus hanging the
cleanup of the driver, which is triggered by mydev_pci_remove_one() upon
the removal of the device.

I am ending all requests on the queue once an eject happens, but it
still doesn't seem to cause a release.

What is the right way to terminate requests and delete the gendisk in
the case of physically vanished PCI devices (or even devices in general)?

Thanks in advance for any pointers to a solution and apologies to the
IRC folks for annoying them with the same question!

John Beard

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Block device driver: how to terminate the block device if media disappears?
@ 2012-12-19 11:21 John Beard
  0 siblings, 0 replies; 6+ messages in thread
From: John Beard @ 2012-12-19 11:21 UTC (permalink / raw)
  To: linux-newbie

Hi,

I have block driver for a hot-pluggable device PCIe storage device.
The driver itself is relatively simple and implements the following
block operations:

	static struct block_device_operations mydev_ops = {
        	.owner = THIS_MODULE,
        	.open = mydev_open,
        	.release = mydev_release,
        	.getgeo = mydev_getgeo,
        	.ioctl = mydev_ioctl
	};

and the following PCI driver structure:

	static struct pci_driver mydev_driver = {
		.name = DRIVER_NAME,
        	.probe = mydev_pci_init_one,
        	.remove = mydev_pci_remove_one,
        	.id_table = mydev_pci_tbl,
	};

As well as a request_fn with the following signature:

	static void mydev_submit_req(struct request_queue *q);

Whenever I get IO requests, there is the expected pattern of "open, IO,
release", and everything works OK: I can mount the device and access the
filesystem.

However, if the device is physically removed during IO, I never seem to
get a "release", just "open, IO, hang". I believe (but I don't know),
that this is preventing del_gendisk() from completing, thus hanging the
cleanup of the driver, which is triggered by mydev_pci_remove_one() upon
the removal of the device.

I am ending all requests on the queue with __blk_end_request_all() once
an eject happens, but it still doesn't seem to cause a release.

What is the right way to terminate requests and delete the gendisk in
the case of physically vanished PCI devices (or even devices in
general)? I know I'd end up with a ruined transfer and corrupt data, but
that's better than a hung kernel, and if the user is going to rip out a
busy disk, those are the breaks.

Thanks in advance for any pointers to a solution, I have looked through
drivers/block, read LDD3 and asked at KernelNewbies but have been unable
to nail down my error. I'd be happy to provide more code, but I don't
want to spam with reams of code if it's not going to be helpful.

John Beard
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-01-12 17:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-13 15:31 Block device driver: how to terminate the block device if media disappears? John Beard
2012-12-21 18:23 ` Ezequiel Garcia
2013-01-07 10:49   ` John Beard
2013-01-12 17:39     ` Ezequiel Garcia
2013-01-12 17:56       ` anish kumar
  -- strict thread matches above, loose matches on Subject: below --
2012-12-19 11:21 John Beard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.