Skip to contentSkip to conversation

struct char_device

PATCH [email protected] 7 participants 11 messages May 22, 2001 – May 23, 2001

lore
Share & tools
lore
#0 lore raw
Quoted 1 line

They are entirely different. Too different sets of operations.

Maybe you didnt understand what I meant. both bdev and cdev take care of the correspondence device number <---> struct with operations.

The operations are different, but all bdev/cdev code is identical.

So the choice is between two uglies:
(i) have some not entirely trivial amount of code twice in the kernel (ii) have a union at the point where the struct operations is assigned.

I preferred the union.

Quoted 6 lines
Quoted 4 lines

And a second remark: don't forget that presently the point where bdev is introduced is not quite right. We must only introduce it when we really have a device, not when there only is a device number (like on a mknod call).

That's simply wrong. kdev_t is used for unopened objects quite often.

Yes, but that was my design mistake in 1995.
I think you'll find if you continue on this way,
as I found and already wrote in kdev_t.h
that it is bad to carry pointers around for unopened and unknown devices.

So, I think that the setup must be changed a tiny little bit and distinguish meaningless numbers from devices.

Andries

#1 lore raw
Quoted 16 lines · [email protected] wrote:
Quoted 2 lines

They are entirely different. Too different sets of operations.

Maybe you didnt understand what I meant. both bdev and cdev take care of the correspondence device number <---> struct with operations.

The operations are different, but all bdev/cdev code is identical.

So the choice is between two uglies:
(i) have some not entirely trivial amount of code twice in the kernel (ii) have a union at the point where the struct operations is assigned.

I preferred the union.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

And a second remark: don't forget that presently the point where bdev is introduced is not quite right. We must only introduce it when we really have a device, not when there only is a device number (like on a mknod call).

That's simply wrong. kdev_t is used for unopened objects quite often.

Yes, but that was my design mistake in 1995.

I fully agree with you. Most of the places where there kernel is passing kdev_t
would be entierly satisfied with only the knowlendge of the minor number used to
distinguish between different device ranges, which is BTW an abuse by itself as well
since minors where for encounters of instances of similiar devices in linux...
The places where this is the case are namely:

1. literally: all character devices.

2. The whole scsi stuff.

3. most of the ide stuff.

4. md/lvm and similiar culprits.

I did "discover" this by splitting the i_dev field from stuct inode into explicit i_minor and i_major fields and then actually "fixing" my particular kernel configuration until it worked again. This was *very* insigtfull, since it discovered all the places where kdev_t get's used, where it shouldn't be of any need anylonger anyway.

The remaining places where kdev_t comes into sight are mostly the places where the kernel is mounting the initial root device.

In case you would like to have a look at the resulting bit huge patch I can send it to you...

Quoted 13 lines

I think you'll find if you continue on this way,
as I found and already wrote in kdev_t.h
that it is bad to carry pointers around for unopened and unknown devices.

So, I think that the setup must be changed a tiny little bit and distinguish meaningless numbers from devices.

Andries
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 4 lines
- phone: +49 214 8656 283
- job:   eVision-Ventures AG, LEV .de (MY OPINIONS ARE MY OWN!)
- langs: de_DE.ISO8859-1, en_US, pl_PL.ISO8859-2, last ressort:
ru_RU.KOI8-R
#2 lore raw
In reply to [email protected]
Quoted 9 lines · On Tue, 22 May 2001 [email protected] wrote:

The operations are different, but all bdev/cdev code is identical.

So the choice is between two uglies:
(i) have some not entirely trivial amount of code twice in the kernel (ii) have a union at the point where the struct operations is assigned.

I preferred the union.

I would much prefer a union of pointers over a pointer to a union.

So I'd much rather have the inode have a

	union {
		struct block_device *block;
		struct char_device *char;
	} dev;

and then have people do

	cdev = inode->dev.char;

to get the right information, than to have

	union block_char_union {
		struct block_device block;
		struct char_device char;
	};

	.. with struct inode containing ..
	union block_char_union *dev;

Why? Because if you have a "struct inode", you also have enough information to decide _which_ of the two types of pointers you have, so you can do the proper dis-ambiguation of the union and properly select either 'inode->dev.char' or 'inode->dev.block' depending on other information in the inode.

In contrast, if you have a pointer to a union, you don't have information of which sub-type it is, and you'd have to carry that along some other way (for example, by having common fields at the beginning). Which I think is broken.

So my suggestion for eventual interfaces:

- have functions like

	struct block_dev *bdget(struct inode *);
	struct char_dev *cdget(struct inode *);

which populate the "inode->dev" union pointer, which in turn is _only_ a cache of the lookup. Right now we do this purely based on "dev_t", and I think that is bogus. We should never pass a "dev_t" around without an inode, I think.

And we should not depend on the "inode->dev.xxxx" pointer being valid all the time, as there is absolutely zero point in initializing the pointer every time the inode is read just because somebody does a "ls -l /dev". Thus the "cache" part above.

- NO reason to try to make "struct block_dev" and "struct char_dev" look similar. They will have some commonality for lookup purposes (that issue is similar, as Andries points out), and maybe that commonality can be separated out into a sub-structure or something. But apart from that, they have absolutely nothing to do with each other, and I'd rather not have them have even a _superficial_ connection.

Block devices will have the "request queue" pointer, and the size and partitioning information. Character devices currently would not have much more than the operations pointer and name, but who knows..

But the most important thing is to be able to do this in steps. One of the reasons Andries has had patches for a long time is that it was never very gradual. Al's patch is gradual, and I like that.

Linus

#3 lore raw
Quoted 7 lines · Linus Torvalds

I would much prefer a union of pointers over a pointer to a union.

So I'd much rather have the inode have a

	union {
		struct block_device *block;
		struct char_device *char;
		struct pipe_inode_info *pipe;
and possibly
		struct socket *socket;
Quoted 9 lines
	} dev;

	struct block_dev *bdget(struct inode *);
	struct char_dev *cdget(struct inode *);

which populate the "inode->dev" union pointer, which in turn is _only_ a cache of the lookup. Right now we do this purely based on "dev_t", and I think that is bogus. We should never pass a "dev_t" around without an inode, I think.

I doubt it. First of all, then we'd better make i_rdev dev_t. Right now we have it kdev_t and it makes absolutely no sense that way. If we only use it for stat() (when we convert it to dev_t) and for keeping the information between mknod/read_inode and open() - why bother converting it to anything? Currently it's used by drivers to identify the device. ->dev.{block,char} is perfectly fine for that and gives more information without extra lookups, etc. And that's it - nothing else cares for ->i_rdev. What you suggest is reusing it so that we had a way to get the right ->dev.{block,char} when we open. Fine, but there's no reason to tie it to kdev_t (or to have kdev_t, for that matter).

The real thing is inode->dev. Notice that for devfs (and per-device filesystems) we can set it upon inode creation, since they _know_ it from the very beginning and there is absolutely no reason to do any hash lookups. Moreover, in these cases we may have no meaningful device number at all.

Quoted 4 lines

And we should not depend on the "inode->dev.xxxx" pointer being valid all the time, as there is absolutely zero point in initializing the pointer every time the inode is read just because somebody does a "ls -l /dev". Thus the "cache" part above.

OK, but see comments above.

Quoted 6 lines

- NO reason to try to make "struct block_dev" and "struct char_dev" look similar. They will have some commonality for lookup purposes (that issue is similar, as Andries points out), and maybe that commonality can be separated out into a sub-structure or something. But apart from that, they have absolutely nothing to do with each other, and I'd rather not have them have even a _superficial_ connection.

Aye.

Quoted 2 lines

Block devices will have the "request queue" pointer, and the size and partitioning information. Character devices currently would not have

Do we really want a separate queue for each partition? I'd rather have disk_struct created when driver sees the disk and list of partitions (possibly represented by struct block_device) anchored in disk_struct and populated by grok_partitions().

Then disk_struct would keep the queue _and_ ll_rw_block could do all remapping, so that driver itself wouldn't know anything about the partitioning.

I have a half-baked patch for that (circa last Spring) and Ben LaHaise got suckere^W^Whad kindly volunteered to try porting it to current tree...

Al

#4 lore raw
Quoted 4 lines · Alexander Viro

Do we really want a separate queue for each partition? I'd rather have disk_struct created when driver sees the disk and list of partitions (possibly represented by struct block_device) anchored in disk_struct and populated by grok_partitions().

Alan recently straightened me out with "EVMS/LVM is partitions done right"

so... why not implement partitions as simply doing block remaps to the lower level device? That's what EVMS/LVM/md are doing already.

Signature · 3 lines
Jeff Garzik      | "Are you the police?"
Building 1024    | "No, ma'am.  We're musicians."
MandrakeSoft     |
#5 lore raw
Quoted 6 lines · Jeff Garzik

Alan recently straightened me out with "EVMS/LVM is partitions done right"

so... why not implement partitions as simply doing block remaps to the lower level device? That's what EVMS/LVM/md are doing already.

Because we still need the partitioning code for backwards compatibility. There's no way I'm going to use initrd to do partition setup with lvmtools etc.

Also, lvm and friends are _heavyweight_. The partitioning stuff should be _one_ add (and perhaps a range check) at bh submit time. None of this remapping crap. We don't need no steenking overhead for something we need to do anyway.

Linus

#6 lore raw
Quoted 9 lines · Linus Torvalds
Quoted 6 lines · Jeff Garzik

Alan recently straightened me out with "EVMS/LVM is partitions done right"

so... why not implement partitions as simply doing block remaps to the lower level device? That's what EVMS/LVM/md are doing already.

Quoted 8 lines

Because we still need the partitioning code for backwards compatibility. There's no way I'm going to use initrd to do partition setup with lvmtools etc.

Also, lvm and friends are _heavyweight_. The partitioning stuff should be _one_ add (and perhaps a range check) at bh submit time. None of this remapping crap. We don't need no steenking overhead for something we need to do anyway.

no no no. Not -that- heavyweight.

Partition support becomes a -peer- of LVM.

Imagine a tiny blkdev driver that understood MS-DOS (and other) hardware partitions, and exported N block devices, representing the underlying device (whatever it is). In fact, that might be even a -unifying-
factor: this tiny blkdev module -is- your /dev/disk. For example,

/dev/sda <-> partition_blkdev <-> /dev/disk{0,1,2,3,4} /dev/hda <-> partition_blkdev <-> /dev/disk{5,6,7}

A nice side effect: modular partition support, since its a normal blkdev just like anything yes.

YES there is overhead, but if partitions are just another remapping blkdev, you get all this stuff for free.

I do grant you that an offset at bh submit time is faster, but IMHO partitions -not- as a remapping blkdev are an ugly special case.

Remapping to an unchanging offset in the make_request_fn can be fast, too...

Signature · 3 lines
Jeff Garzik      | "Are you the police?"
Building 1024    | "No, ma'am.  We're musicians."
MandrakeSoft     |
#7 lore raw
In reply to Linus Torvalds
Quoted 2 lines · Jeff Garzik

/dev/sda <-> partition_blkdev <-> /dev/disk{0,1,2,3,4} /dev/hda <-> partition_blkdev <-> /dev/disk{5,6,7}

I also point out that handling disk partitions as a -tiny- remapping blkdev also has the advantage of making it easy to have a single request device per hardware device (a simple remap shouldn't require its own request queue, right?), while remapping devices flexibility to do their own request queue management.

Quoted 2 lines

I do grant you that an offset at bh submit time is faster, but IMHO partitions -not- as a remapping blkdev are an ugly special case.

think of the simplifications possible, when partitions are just another block device, just like anything else... No special partitions arrays in the lowlevel blkdev, etc.

#8 lore raw
In reply to Linus Torvalds
Quoted 3 lines

Because we still need the partitioning code for backwards compatibility. There's no way I'm going to use initrd to do partition setup with lvmtools etc.

The current partitioning code consists of re-reading from disk. That is code that has to be present anyway even without an initrd since it is needed for mounting other filesystems

Quoted 4 lines

Also, lvm and friends are _heavyweight_. The partitioning stuff should be _one_ add (and perhaps a range check) at bh submit time. None of this remapping crap. We don't need no steenking overhead for something we need to do anyway.

Thats the kind of LVM layer I am thinking in terms of, not a large block of LVM code. And for that matter the partition scanner and modifying code can even be seperate dynamic loaded modules.

At the moment ponder what happens if you have I/Os in flight to /dev/hda3 when you delete /dev/hda2

Alan

#9 lore raw
In reply to Alexander Viro
Quoted 2 lines · Jeff Garzik

so... why not implement partitions as simply doing block remaps to the lower level device? That's what EVMS/LVM/md are doing already.

That is indeed the plan, having partitions simply being 'just another' sector remap when submitting I/O

Signature · 1 line
Jens Axboe
#10 lore raw
In reply to Alexander Viro
Quoted 7 lines · Alexander Viro
Quoted 4 lines

which populate the "inode->dev" union pointer, which in turn is _only_ a cache of the lookup. Right now we do this purely based on "dev_t", and I think that is bogus. We should never pass a "dev_t" around without an inode, I think.

I doubt it. First of all, then we'd better make i_rdev dev_t. Right now we have it kdev_t and it makes absolutely no sense that way.

Absolutely.

In fact, the whole "kdev_t" makes no sense if we have proper char_dev and block_dev pointers.

We have "dev_t" which is what we export to user space. And if we split up char dev and block dev (which I'm an avid proponent for), kdev_t will be an anachronism.

Quoted 5 lines

The real thing is inode->dev. Notice that for devfs (and per-device filesystems) we can set it upon inode creation, since they _know_ it from the very beginning and there is absolutely no reason to do any hash lookups. Moreover, in these cases we may have no meaningful device number at all.

Sure. If something like devfs _knows_ the device pointers from the very beginning, then just do:
- increment reference count
- inode->dev.char = cdev;

Quoted 4 lines
Quoted 2 lines

Block devices will have the "request queue" pointer, and the size and partitioning information. Character devices currently would not have

Do we really want a separate queue for each partition?

No.

But the pointer is not a 1:1 thing (otherwise we'd just put the whole request queue _into_ the block device).

The block device should have a pointer to the request queue, along with the partitioning information. Why? Because that way it becomes very simple indeed to do request processing: none of the current "look up the proper queue for each request and do the partition offset magic inside each driver". Instead, the queuing function becomes:

	bh->index = bdev->index;
	bh->sector += bdev->sector_offset;
	submit_bh(bh, bdev->request_queue);

and you're done. Those three lines did both the queue lookup, the "index" for the driver, and the partitioning offset. Whoa, nelly.

And THAT is why you want to have the queue pointer in the bdev structure.

Linus