Subject: Re: [PATCH] (6/6) further block_device cleanups
From: Alexander Viro <[email-masked]>
To: Andrea Arcangeli <[email-masked]>
Cc: Linus Torvalds <[email-masked]>
Date: Sat, 22 Sep 2001 03:26:35 -0400 (EDT)

On Sat, 22 Sep 2001, Andrea Arcangeli wrote:

> On Sat, Sep 22, 2001 at 02:16:41AM -0400, Alexander Viro wrote:
> > Part 6:
> 
> where's part5, btw? I wanted to include it in pre14aa1 to give it a spin
> to try to help you while I test the other stuff but I didn't checked if
> everything in part 6 is self contained or if it depends on pre5.

Went as Re: [PATCH] (3/6)...  Sorry - sent before editing the subject.

Anyway, patch is here:

diff -urN S10-pre13-blkdev_open/fs/block_dev.c S10-pre13-current/fs/block_dev.c
--- S10-pre13-blkdev_open/fs/block_dev.c	Fri Sep 21 22:34:02 2001
+++ S10-pre13-current/fs/block_dev.c	Fri Sep 21 22:37:19 2001
@@ -404,7 +404,6 @@
 		if (!inode)
 			return -ENOMEM;
 		inode->i_rdev = to_kdev_t(bdev->bd_dev);
-		atomic_inc(&bdev->bd_count);	/* will go away */
 		inode->i_bdev = bdev;
 		inode->i_data.a_ops = &def_blk_aops;
 		bdev->bd_inode = inode;
diff -urN S10-pre13-blkdev_open/fs/devfs/base.c S10-pre13-current/fs/devfs/base.c
--- S10-pre13-blkdev_open/fs/devfs/base.c	Fri Sep 21 18:59:05 2001
+++ S10-pre13-current/fs/devfs/base.c	Fri Sep 21 22:38:42 2001
@@ -2291,9 +2291,16 @@
     return 0;
 }   /*  End Function devfs_statfs  */
 
+static void devfs_clear_inode(struct inode *inode)
+{
+	if (S_ISBLK(inode->i_mode))
+		bdput(inode->i_bdev);
+}
+
 static struct super_operations devfs_sops =
 { 
     put_inode:     force_delete,
+    clear_inode:   devfs_clear_inode,
     statfs:        devfs_statfs,
 };
 
diff -urN S10-pre13-blkdev_open/fs/devices.c S10-pre13-current/fs/devices.c
--- S10-pre13-blkdev_open/fs/devices.c	Fri Sep 21 18:59:05 2001
+++ S10-pre13-current/fs/devices.c	Fri Sep 21 22:35:07 2001
@@ -207,7 +207,6 @@
 	} else if (S_ISBLK(mode)) {
 		inode->i_fop = &def_blk_fops;
 		inode->i_rdev = to_kdev_t(rdev);
-		bd_acquire(inode);
 	} else if (S_ISFIFO(mode))
 		inode->i_fop = &def_fifo_fops;
 	else if (S_ISSOCK(mode))
diff -urN S10-pre13-blkdev_open/fs/inode.c S10-pre13-current/fs/inode.c
--- S10-pre13-blkdev_open/fs/inode.c	Fri Sep 21 18:59:05 2001
+++ S10-pre13-current/fs/inode.c	Fri Sep 21 22:37:34 2001
@@ -517,11 +517,9 @@
 	DQUOT_DROP(inode);
 	if (inode->i_sb && inode->i_sb->s_op && inode->i_sb->s_op->clear_inode)
 		inode->i_sb->s_op->clear_inode(inode);
-	if (inode->i_bdev) {
-		bdput(inode->i_bdev);
+	if (inode->i_bdev)
 		bd_forget(inode);
-	}
-	if (inode->i_cdev) {
+	else if (inode->i_cdev) {
 		cdput(inode->i_cdev);
 		inode->i_cdev = NULL;
 	}