public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] struct char_device
@ 2001-05-23 13:34 Andries.Brouwer
  2001-05-23 17:54 ` Alexander Viro
  0 siblings, 1 reply; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-23 13:34 UTC (permalink / raw)
  To: Andries.Brouwer, helgehaf, linux-kernel

> But I don't want an initrd.

Don't be afraid of words. You wouldnt notice - it would do its
job and disappear just like piggyback today.

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-23 20:01 Andries.Brouwer
  0 siblings, 0 replies; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-23 20:01 UTC (permalink / raw)
  To: Andries.Brouwer, viro; +Cc: helgehaf, linux-kernel

> Besides, just on general principles, we'd better have clean interface
> for changing partitioning

It is not quite clear to me what you are arguing for or against.
But never mind - I'll leave few hours from now.
When the time is there I'll show you an implementation,
and if you don't like it, you'll show me a better one.

Andries

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-23 18:28 Andries.Brouwer
  2001-05-23 18:42 ` Alexander Viro
  0 siblings, 1 reply; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-23 18:28 UTC (permalink / raw)
  To: Andries.Brouwer, viro; +Cc: helgehaf, linux-kernel

> Andries, initrd code is _sick_.

Oh, but the fact that there exists a bad implementation
does not mean the idea is wrong. It is really easy to
make an elegant implementation.

Andries

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-23 15:24 Wayne.Brown
  0 siblings, 0 replies; 55+ messages in thread
From: Wayne.Brown @ 2001-05-23 15:24 UTC (permalink / raw)
  To: Andries.Brouwer; +Cc: Andries.Brouwer, helgehaf, linux-kernel








Andries.Brouwer@cwi.nl on 05/23/2001 08:34:44 AM

To:   Andries.Brouwer@cwi.nl, helgehaf@idb.hist.no, linux-kernel@vger.kernel.org
cc:    (bcc: Wayne Brown/Corporate/Altec)

Subject:  Re: [PATCH] struct char_device



>> But I don't want an initrd.
>
>Don't be afraid of words. You wouldnt notice - it would do its
>job and disappear just like piggyback today.

So nothing in the boot scripts would have to change?  (Not that it would be a
big problem if it was necessary.  However, I prefer to keep things in /etc/rc.d
as close to the distribution defaults as possible, just in case I ever need to
reinstall the distribution.)

Wayne





^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-23 12:29 Andries.Brouwer
  2001-05-23 12:30 ` Alan Cox
  2001-05-23 13:26 ` Helge Hafting
  0 siblings, 2 replies; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-23 12:29 UTC (permalink / raw)
  To: Andries.Brouwer, alan; +Cc: jgarzik, linux-kernel, torvalds, viro

    From alan@lxorguk.ukuu.org.uk Wed May 23 14:16:46 2001

    > It is entirely possible to remove all partition table handling code
    > from the kernel. User space can figure out where the partitions
    > are supposed to be and tell the kernel.
    > For the initial boot this user space can be in an initrd,
    > or it could just be a boot parameter: rootdev=/dev/hda,
    > rootpartition:offset=N,length=L, rootfstype=ext3.

    Not if you want compatibility.

I don't think compatibility is a problem.
It would go like this: at configure time you get the
choice of the default initrd or a custom initrd.
If you choose the custom one you construct it yourself.
If you choose the default one, then you get something
that comes together with the kernel image, just like
the piggyback stuff today. This default initrd does
the partition parsing that up to now the kernel did.
That way nobody need to notice a difference, except for
those who use initrd already now. They can solve their
problems.

Andries



^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-23 11:57 Andries.Brouwer
  2001-05-23 12:13 ` Alan Cox
  0 siblings, 1 reply; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-23 11:57 UTC (permalink / raw)
  To: alan, torvalds; +Cc: Andries.Brouwer, jgarzik, linux-kernel, viro

Alan writes:

    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

I am not quite sure what you are saying here.
(For example, the "even" was unexpected.)

It is entirely possible to remove all partition table handling code
from the kernel. User space can figure out where the partitions
are supposed to be and tell the kernel.
For the initial boot this user space can be in an initrd,
or it could just be a boot parameter: rootdev=/dev/hda,
rootpartition:offset=N,length=L, rootfstype=ext3.

mount does not need any partition reading code.

Andries


[I conjecture that we'll want to start moving partition parsing
out into userspace fairly soon. Indeed, soon we'll see EFI everywhere,
and there is no good reason to build knowledge about that into the kernel.]

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-23  6:47 Andries.Brouwer
  0 siblings, 0 replies; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-23  6:47 UTC (permalink / raw)
  To: Andries.Brouwer, torvalds; +Cc: jgarzik, linux-kernel, viro


    On Wed, 23 May 2001 Andries.Brouwer@cwi.nl wrote:
    >
    > > why not implement partitions as simply doing block remaps
    > 
    > Everybody agrees.

    No they don't.

We had this discussion already. We all agree.
Maybe you read in "remap" something other than a simple addition
but I don't. This is not a topic where further discussion is needed.

Andries

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-23  0:28 Andries.Brouwer
  2001-05-23  0:38 ` Alexander Viro
  0 siblings, 1 reply; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-23  0:28 UTC (permalink / raw)
  To: Andries.Brouwer, viro; +Cc: linux-kernel, torvalds

>> 	dev_t rdev;

> Reasonable.

Good. We all agree.
(But now you see what I meant in comments about mknod.)

>> 	kdev_t dev;

> Useless. If you hope that block_device will help to solve rmmod races

Yes. Why am I mistaken?

Andries

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-23  0:22 Andries.Brouwer
  2001-05-23  0:29 ` Martin Dalecki
  0 siblings, 1 reply; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-23  0:22 UTC (permalink / raw)
  To: dalecki, jgarzik; +Cc: Andries.Brouwer, axboe, linux-kernel, torvalds, viro

> IMHO it would be nice to create wrappers for accessing the block arrays

Last year Linus didnt like that at all. Maybe this year.

Andries

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-23  0:20 Andries.Brouwer
  2001-05-23  2:43 ` Linus Torvalds
  0 siblings, 1 reply; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-23  0:20 UTC (permalink / raw)
  To: jgarzik, viro; +Cc: Andries.Brouwer, linux-kernel, torvalds

> why not implement partitions as simply doing block remaps

Everybody agrees.

Andries

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-23  0:01 Andries.Brouwer
  0 siblings, 0 replies; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-23  0:01 UTC (permalink / raw)
  To: torvalds, viro; +Cc: Andries.Brouwer, linux-kernel

> Do we really want a separate queue for each partition?

No.

> I have a half-baked patch

Me too. (Not half-baked but brewed.) In principle the change
is trivial, but there are a few IDE issues that are presently
solved in a very low-level way (and incorrectly).
This makes the patch larger than expected at first sight.

Andries


^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-22 23:33 Andries.Brouwer
  2001-05-23  0:03 ` Alexander Viro
  0 siblings, 1 reply; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-22 23:33 UTC (permalink / raw)
  To: Andries.Brouwer, torvalds; +Cc: linux-kernel, viro

    From torvalds@transmeta.com Wed May 23 00:39:23 2001

    On Tue, 22 May 2001 Andries.Brouwer@cwi.nl 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.

    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.

I am not sure whether we agree or differ in opinion. I wouldn't mind

/* pairing for dev_t to bd_op/cd_op */
struct bc_device {
        struct list_head        bd_hash;
        atomic_t                bd_count;
        dev_t                   bd_dev;
        atomic_t                bd_openers;
        union {
		struct block_device_operations_and_data *bd_op;
		struct char_device_operations_and_data *cd_op;
	}
        struct semaphore        bd_sem;
};

typedef struct bc_device *kdev_t;

and in an inode

	kdev_t dev;
	dev_t rdev;

In reality we want the pair (dev_t, pointer to stuff), but then
there is all this administrative nonsense needed to make sure
that nobody uses the pointer after the module has been unloaded
that makes the pointer a bit thicker.

       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 somebody does a "ls -l /dev".

Yes, that is why I want to go back and have dev_t rdev, not kdev_t.
The lookup is done when the device is opened.

Andries

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-22 22:17 Andries.Brouwer
  2001-05-22 22:34 ` Martin Dalecki
  2001-05-22 22:47 ` Martin Dalecki
  0 siblings, 2 replies; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-22 22:17 UTC (permalink / raw)
  To: Andries.Brouwer, dalecki; +Cc: linux-kernel, torvalds, viro

Martin Dalecki writes:

> Erm... I wasn't talking about the DESIRED state of affairs!
> I was talking about the CURRENT state of affairs. OK?

Oh, but in 1995 it was quite possible to compile the kernel
with kdev_t a pointer type, and I have done it several times since.

The kernel keeps growing, so each time it is more work than
the previous time.

> At least you have admitted that you where the one responsible
> for the design of this MESS.

Thank you! However, you give me too much honour.

Andries

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-22 21:35 Andries.Brouwer
  2001-05-22 22:00 ` Martin Dalecki
  0 siblings, 1 reply; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-22 21:35 UTC (permalink / raw)
  To: Andries.Brouwer, dalecki; +Cc: linux-kernel, torvalds, viro

Martin Dalecki writes:

> I fully agree with you.

Good.

Unfortunately I do not 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.

My kdev_t is a pointer to a structure with device data
and device operations. Among the operations a routine
that produces a name. Among the data, in the case of a
block device, the size, and the sectorsize, ..

A minor gives no name, and no data.

Linus' minor is 20-bit if I recall correctly.
My minor is 32-bit. Neither of the two can be
used to index arrays.

Andries

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-22 20:54 Andries.Brouwer
  2001-05-22 21:17 ` Martin Dalecki
  2001-05-22 22:37 ` Linus Torvalds
  0 siblings, 2 replies; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-22 20:54 UTC (permalink / raw)
  To: Andries.Brouwer, viro; +Cc: linux-kernel, torvalds

> 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.

>> 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

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: [PATCH] struct char_device
@ 2001-05-22 19:52 Andries.Brouwer
  2001-05-22 20:10 ` Alexander Viro
  0 siblings, 1 reply; 55+ messages in thread
From: Andries.Brouwer @ 2001-05-22 19:52 UTC (permalink / raw)
  To: torvalds, viro; +Cc: linux-kernel

Alexander Viro writes:

> patch below adds the missing half of kdev_t -
> for block devices we already have a unique pointer
> and that adds a similar animal for character devices.

Very good.
(Of course I did precisely the same, but am a bit slower in
submitting things during a stable series or code freeze.)

One remark, repeating what I wrote on some web page:
-----
A struct block_device provides the connection between a device number
and a struct block_device_operations. 
...
Clearly, we also want to associate a struct char_device_operations
to a character device number. When we do this, all bdev code will
have to be duplicated for cdev, so there seems no point in having
bdev code - kdev, for both bdev and cdev, seems more elegant. 
-----

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).

Andries

^ permalink raw reply	[flat|nested] 55+ messages in thread
[parent not found: <Pine.GSO.4.21.0105221007460.15685-100000@weyl.math.psu.edu >]
[parent not found: <Pine.LNX.4.10.10105221050080.8984-100000@coffee.psychology.mcmaster.ca>]
* Re: [PATCH] struct char_device
@ 2001-05-22 14:40 Tommy Hallgren
  0 siblings, 0 replies; 55+ messages in thread
From: Tommy Hallgren @ 2001-05-22 14:40 UTC (permalink / raw)
  To: viro, linux-kernel

Hi Alexander!

If I'm not entirely mistaken, this:

+ if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == 
+ SLAB_CTOR_CONSTRUCTOR) 
+ { 
+ memset(cdev, 0, sizeof(*cdev)); 
+ sema_init(&cdev->sem, 1); 
+ } 
+} 

could be replaced with this:

+ if ((flags & SLAB_CTOR_CONSTRUCTOR) == SLAB_CTOR_CONSTRUCTOR) 
+ { 
+ memset(cdev, 0, sizeof(*cdev)); 
+ sema_init(&cdev->sem, 1); 
+ } 
+} 

Regards, Tommy


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

^ permalink raw reply	[flat|nested] 55+ messages in thread
* [PATCH] struct char_device
@ 2001-05-22 14:18 Alexander Viro
  0 siblings, 0 replies; 55+ messages in thread
From: Alexander Viro @ 2001-05-22 14:18 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

	Linus, patch below adds the missing half of kdev_t -
for block devices we already have a unique pointer (struct block_device *,
inode->i_bdev) and that adds a similar animal for character devices.
	That is, it adds a new structure (struct char_device) and a cache
indexed by dev_t. init_special_inode() sets ->i_cdev to corresponding
element of cache (creating it if needed).
	Result: ->i_cdev is shared by all inodes of given character device
(i.e. if we need per-device objects we can put them there), we can use
stuct char_device * as ID for character devices, we can (in 2.5) get
rid of i_rdev - it's covered by ->i_bdev and ->i_cdev now.
	Patch is pretty straightforward - cache handling is lifted from
fs/block_device, the rest is trivial.
	Please, consider applying.
							Al

diff -urN S5-pre4/fs/Makefile S5-pre4-cdev/fs/Makefile
--- S5-pre4/fs/Makefile	Thu May  3 17:13:26 2001
+++ S5-pre4-cdev/fs/Makefile	Tue May 22 09:12:11 2001
@@ -11,8 +11,8 @@
 mod-subdirs :=	nls
 
 obj-y :=	open.o read_write.o devices.o file_table.o buffer.o \
-		super.o  block_dev.o stat.o exec.o pipe.o namei.o fcntl.o \
-		ioctl.o readdir.o select.o fifo.o locks.o \
+		super.o block_dev.o char_dev.o stat.o exec.o pipe.o namei.o \
+		fcntl.o ioctl.o readdir.o select.o fifo.o locks.o \
 		dcache.o inode.o attr.o bad_inode.o file.o iobuf.o dnotify.o \
 		filesystems.o
 
diff -urN S5-pre4/fs/block_dev.c S5-pre4-cdev/fs/block_dev.c
--- S5-pre4/fs/block_dev.c	Sat May 19 22:46:35 2001
+++ S5-pre4-cdev/fs/block_dev.c	Tue May 22 08:34:44 2001
@@ -392,7 +392,7 @@
 	}
 }
 
-void __init bdev_init(void)
+void __init bdev_cache_init(void)
 {
 	int i;
 	struct list_head *head = bdev_hashtable;
diff -urN S5-pre4/fs/char_dev.c S5-pre4-cdev/fs/char_dev.c
--- S5-pre4/fs/char_dev.c	Wed Dec 31 19:00:00 1969
+++ S5-pre4-cdev/fs/char_dev.c	Tue May 22 10:03:10 2001
@@ -0,0 +1,114 @@
+/*
+ *  linux/fs/block_dev.c
+ *
+ *  Copyright (C) 1991, 1992  Linus Torvalds
+ */
+
+#include <linux/config.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+
+#define HASH_BITS	6
+#define HASH_SIZE	(1UL << HASH_BITS)
+#define HASH_MASK	(HASH_SIZE-1)
+static struct list_head cdev_hashtable[HASH_SIZE];
+static spinlock_t cdev_lock = SPIN_LOCK_UNLOCKED;
+static kmem_cache_t * cdev_cachep;
+
+#define alloc_cdev() \
+	 ((struct char_device *) kmem_cache_alloc(cdev_cachep, SLAB_KERNEL))
+#define destroy_cdev(cdev) kmem_cache_free(cdev_cachep, (cdev))
+
+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
+{
+	struct char_device * cdev = (struct char_device *) foo;
+
+	if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
+	    SLAB_CTOR_CONSTRUCTOR)
+	{
+		memset(cdev, 0, sizeof(*cdev));
+		sema_init(&cdev->sem, 1);
+	}
+}
+
+void __init cdev_cache_init(void)
+{
+	int i;
+	struct list_head *head = cdev_hashtable;
+
+	i = HASH_SIZE;
+	do {
+		INIT_LIST_HEAD(head);
+		head++;
+		i--;
+	} while (i);
+
+	cdev_cachep = kmem_cache_create("cdev_cache",
+					 sizeof(struct char_device),
+					 0, SLAB_HWCACHE_ALIGN, init_once,
+					 NULL);
+	if (!cdev_cachep)
+		panic("Cannot create cdev_cache SLAB cache");
+}
+
+/*
+ * Most likely _very_ bad one - but then it's hardly critical for small
+ * /dev and can be fixed when somebody will need really large one.
+ */
+static inline unsigned long hash(dev_t dev)
+{
+	unsigned long tmp = dev;
+	tmp = tmp + (tmp >> HASH_BITS) + (tmp >> HASH_BITS*2);
+	return tmp & HASH_MASK;
+}
+
+static struct char_device *cdfind(dev_t dev, struct list_head *head)
+{
+	struct list_head *p;
+	struct char_device *cdev;
+	for (p=head->next; p!=head; p=p->next) {
+		cdev = list_entry(p, struct char_device, hash);
+		if (cdev->dev != dev)
+			continue;
+		atomic_inc(&cdev->count);
+		return cdev;
+	}
+	return NULL;
+}
+
+struct char_device *cdget(dev_t dev)
+{
+	struct list_head * head = cdev_hashtable + hash(dev);
+	struct char_device *cdev, *new_cdev;
+	spin_lock(&cdev_lock);
+	cdev = cdfind(dev, head);
+	spin_unlock(&cdev_lock);
+	if (cdev)
+		return cdev;
+	new_cdev = alloc_cdev();
+	if (!new_cdev)
+		return NULL;
+	atomic_set(&new_cdev->count,1);
+	new_cdev->dev = dev;
+	spin_lock(&cdev_lock);
+	cdev = cdfind(dev, head);
+	if (!cdev) {
+		list_add(&new_cdev->hash, head);
+		spin_unlock(&cdev_lock);
+		return new_cdev;
+	}
+	spin_unlock(&cdev_lock);
+	destroy_cdev(new_cdev);
+	return cdev;
+}
+
+void cdput(struct char_device *cdev)
+{
+	if (atomic_dec_and_test(&cdev->count)) {
+		spin_lock(&cdev_lock);
+		list_del(&cdev->hash);
+		spin_unlock(&cdev_lock);
+		destroy_cdev(cdev);
+	}
+}
+
diff -urN S5-pre4/fs/dcache.c S5-pre4-cdev/fs/dcache.c
--- S5-pre4/fs/dcache.c	Sat Apr 28 02:12:56 2001
+++ S5-pre4-cdev/fs/dcache.c	Tue May 22 09:22:43 2001
@@ -1250,6 +1250,9 @@
 kmem_cache_t *bh_cachep;
 EXPORT_SYMBOL(bh_cachep);
 
+extern void bdev_cache_init(void);
+extern void cdev_cache_init(void);
+
 void __init vfs_caches_init(unsigned long mempages)
 {
 	bh_cachep = kmem_cache_create("buffer_head",
@@ -1279,4 +1282,7 @@
 #endif
 
 	dcache_init(mempages);
+	inode_init(mempages);
+	bdev_cache_init();
+	cdev_cache_init();
 }
diff -urN S5-pre4/fs/devfs/base.c S5-pre4-cdev/fs/devfs/base.c
--- S5-pre4/fs/devfs/base.c	Sat May 19 22:46:35 2001
+++ S5-pre4-cdev/fs/devfs/base.c	Tue May 22 08:51:03 2001
@@ -2256,6 +2256,7 @@
     {
 	inode->i_rdev = MKDEV (de->u.fcb.u.device.major,
 			       de->u.fcb.u.device.minor);
+	inode->i_cdev = cdget (kdev_t_to_nr(inode->i_rdev));
     }
     else if ( S_ISBLK (de->inode.mode) )
     {
diff -urN S5-pre4/fs/devices.c S5-pre4-cdev/fs/devices.c
--- S5-pre4/fs/devices.c	Fri Feb 16 19:00:19 2001
+++ S5-pre4-cdev/fs/devices.c	Tue May 22 08:31:04 2001
@@ -203,6 +203,7 @@
 	if (S_ISCHR(mode)) {
 		inode->i_fop = &def_chr_fops;
 		inode->i_rdev = to_kdev_t(rdev);
+		inode->i_cdev = cdget(rdev);
 	} else if (S_ISBLK(mode)) {
 		inode->i_fop = &def_blk_fops;
 		inode->i_rdev = to_kdev_t(rdev);
diff -urN S5-pre4/fs/inode.c S5-pre4-cdev/fs/inode.c
--- S5-pre4/fs/inode.c	Sat May 19 22:46:35 2001
+++ S5-pre4-cdev/fs/inode.c	Mon May 21 22:49:48 2001
@@ -497,6 +497,10 @@
 		bdput(inode->i_bdev);
 		inode->i_bdev = NULL;
 	}
+	if (inode->i_cdev) {
+		cdput(inode->i_cdev);
+		inode->i_cdev = NULL;
+	}
 	inode->i_state = I_CLEAR;
 }
 
@@ -750,6 +754,7 @@
 	memset(&inode->i_dquot, 0, sizeof(inode->i_dquot));
 	inode->i_pipe = NULL;
 	inode->i_bdev = NULL;
+	inode->i_cdev = NULL;
 	inode->i_data.a_ops = &empty_aops;
 	inode->i_data.host = inode;
 	inode->i_data.gfp_mask = GFP_HIGHUSER;
diff -urN S5-pre4/include/linux/fs.h S5-pre4-cdev/include/linux/fs.h
--- S5-pre4/include/linux/fs.h	Sat May 19 22:46:36 2001
+++ S5-pre4-cdev/include/linux/fs.h	Tue May 22 09:14:25 2001
@@ -384,6 +384,14 @@
 	int			gfp_mask;	/* how to allocate the pages */
 };
 
+struct char_device {
+	struct list_head	hash;
+	atomic_t		count;
+	dev_t			dev;
+	atomic_t		openers;
+	struct semaphore	sem;
+};
+
 struct block_device {
 	struct list_head	bd_hash;
 	atomic_t		bd_count;
@@ -426,8 +434,10 @@
 	struct address_space	*i_mapping;
 	struct address_space	i_data;	
 	struct dquot		*i_dquot[MAXQUOTAS];
+	/* These three should probably be a union */
 	struct pipe_inode_info	*i_pipe;
 	struct block_device	*i_bdev;
+	struct char_device	*i_cdev;
 
 	unsigned long		i_dnotify_mask; /* Directory notify events */
 	struct dnotify_struct	*i_dnotify; /* for directory notifications */
@@ -982,6 +992,8 @@
 extern int unregister_blkdev(unsigned int, const char *);
 extern struct block_device *bdget(dev_t);
 extern void bdput(struct block_device *);
+extern struct char_device *cdget(dev_t);
+extern void cdput(struct char_device *);
 extern int blkdev_open(struct inode *, struct file *);
 extern struct file_operations def_blk_fops;
 extern struct file_operations def_fifo_fops;
diff -urN S5-pre4/init/main.c S5-pre4-cdev/init/main.c
--- S5-pre4/init/main.c	Sat May 19 22:46:36 2001
+++ S5-pre4-cdev/init/main.c	Tue May 22 08:34:09 2001
@@ -93,7 +93,6 @@
 extern void ppc_init(void);
 extern void sysctl_init(void);
 extern void signals_init(void);
-extern void bdev_init(void);
 extern int init_pcmcia_ds(void);
 extern void net_notifier_init(void);
 
@@ -569,8 +568,6 @@
 	ccwcache_init();
 #endif
 	signals_init();
-	bdev_init();
-	inode_init(mempages);
 #ifdef CONFIG_PROC_FS
 	proc_root_init();
 #endif
diff -urN S5-pre4/kernel/ksyms.c S5-pre4-cdev/kernel/ksyms.c
--- S5-pre4/kernel/ksyms.c	Sat May 19 22:46:37 2001
+++ S5-pre4-cdev/kernel/ksyms.c	Tue May 22 09:06:47 2001
@@ -186,6 +186,8 @@
 EXPORT_SYMBOL(notify_change);
 EXPORT_SYMBOL(set_blocksize);
 EXPORT_SYMBOL(getblk);
+EXPORT_SYMBOL(cdget);
+EXPORT_SYMBOL(cdput);
 EXPORT_SYMBOL(bdget);
 EXPORT_SYMBOL(bdput);
 EXPORT_SYMBOL(bread);


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

end of thread, other threads:[~2001-05-24 11:17 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-05-23 13:34 [PATCH] struct char_device Andries.Brouwer
2001-05-23 17:54 ` Alexander Viro
2001-05-24 10:35   ` Stephen C. Tweedie
  -- strict thread matches above, loose matches on Subject: below --
2001-05-23 20:01 Andries.Brouwer
2001-05-23 18:28 Andries.Brouwer
2001-05-23 18:42 ` Alexander Viro
2001-05-23 15:24 Wayne.Brown
2001-05-23 12:29 Andries.Brouwer
2001-05-23 12:30 ` Alan Cox
2001-05-23 13:26 ` Helge Hafting
2001-05-23 11:57 Andries.Brouwer
2001-05-23 12:13 ` Alan Cox
2001-05-23  6:47 Andries.Brouwer
2001-05-23  0:28 Andries.Brouwer
2001-05-23  0:38 ` Alexander Viro
2001-05-23  0:22 Andries.Brouwer
2001-05-23  0:29 ` Martin Dalecki
2001-05-23  0:20 Andries.Brouwer
2001-05-23  2:43 ` Linus Torvalds
2001-05-23  0:01 Andries.Brouwer
2001-05-22 23:33 Andries.Brouwer
2001-05-23  0:03 ` Alexander Viro
2001-05-22 22:17 Andries.Brouwer
2001-05-22 22:34 ` Martin Dalecki
2001-05-22 22:47 ` Martin Dalecki
2001-05-23  0:02   ` Jeff Garzik
2001-05-23  0:14     ` Jens Axboe
2001-05-23  2:40     ` Linus Torvalds
2001-05-23 12:35       ` Martin Dalecki
2001-05-22 21:35 Andries.Brouwer
2001-05-22 22:00 ` Martin Dalecki
2001-05-22 20:54 Andries.Brouwer
2001-05-22 21:17 ` Martin Dalecki
2001-05-22 22:37 ` Linus Torvalds
2001-05-22 23:51   ` Alexander Viro
2001-05-23  0:06     ` Jeff Garzik
2001-05-23  0:14       ` Jens Axboe
2001-05-23  2:37       ` Linus Torvalds
2001-05-23  3:04         ` Jeff Garzik
2001-05-23  3:21           ` Jeff Garzik
2001-05-23  9:05         ` Alan Cox
2001-05-23  2:35     ` Linus Torvalds
2001-05-22 19:52 Andries.Brouwer
2001-05-22 20:10 ` Alexander Viro
     [not found] <Pine.GSO.4.21.0105221007460.15685-100000@weyl.math.psu.edu >
2001-05-22 15:26 ` Anton Altaparmakov
2001-05-22 16:08   ` Oliver Xymoron
2001-05-22 16:12     ` Alexander Viro
2001-05-22 17:30       ` Oliver Xymoron
2001-05-22 17:41         ` Alexander Viro
2001-05-22 19:22     ` Guest section DW
2001-05-22 19:25       ` Alexander Viro
2001-05-22 19:38       ` Oliver Xymoron
     [not found] <Pine.LNX.4.10.10105221050080.8984-100000@coffee.psychology.mcmaster.ca>
2001-05-22 14:59 ` Tommy Hallgren
2001-05-22 14:40 Tommy Hallgren
2001-05-22 14:18 Alexander Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox