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

Part 2:

We do bd_acquire() in get_sb_bdev().  Corresponding bdput() added on
failing exits and is mutually cancelled with atomic_inc(&bdev->bd_count)
on normal one (i.e. we either drop what we got when we fail, or leave
it as ->s_bdev if we succeed).

Balance is the same as it used to be, but we do not depend on
->i_bdev being set before we enter get_sb_bdev().

diff -urN S10-pre13-bd_acquire/fs/super.c S10-pre13-current/fs/super.c
--- S10-pre13-bd_acquire/fs/super.c	Fri Sep 21 09:45:28 2001
+++ S10-pre13-current/fs/super.c	Fri Sep 21 18:59:58 2001
@@ -925,6 +925,7 @@
 	error = -EACCES;
 	if (nd.mnt->mnt_flags & MNT_NODEV)
 		goto out;
+	bd_acquire(inode);
 	bdev = inode->i_bdev;
 	bdops = devfs_get_ops ( devfs_get_handle_from_inode (inode) );
 	if (bdops) bdev->bd_op = bdops;
@@ -933,8 +934,10 @@
 	if (!(flags & MS_RDONLY))
 		mode |= FMODE_WRITE;
 	error = blkdev_get(bdev, mode, 0, BDEV_FS);
-	if (error)
+	if (error) {
+		bdput(bdev);
 		goto out;
+	}
 	check_disk_change(dev);
 	error = -EACCES;
 	if (!(flags & MS_RDONLY) && is_read_only(dev))
@@ -964,6 +967,7 @@
 			goto restart;
 		put_super(s);
 		blkdev_put(bdev, BDEV_FS);
+		bdput(bdev);
 		path_release(&nd);
 		return old;
 	}
@@ -982,8 +986,6 @@
 	if (!fs_type->read_super(s, data, 0))
 		goto out_fail;
 	unlock_super(s);
-	/* tell bdcache that we are going to keep this one */
-	atomic_inc(&bdev->bd_count);
 	get_filesystem(fs_type);
 	path_release(&nd);
 	return s;
@@ -1001,6 +1003,7 @@
 	put_super(s);
 out1:
 	blkdev_put(bdev, BDEV_FS);
+	bdput(bdev);
 out:
 	path_release(&nd);
 	return ERR_PTR(error);