Block device driver: how to terminate the block device if media disappears?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs


[Index of Archives]     [Audio]     [Hams]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Fedora Users]

  Powered by Linux