Date: Sat, 22 Sep 2001 01:58:32 -0400 (EDT)
From: Alexander Viro <viro@math.psu.edu>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Andrea Arcangeli <andrea@suse.de>
Subject: [PATCH] (2/6) further block_device cleanups
In-Reply-To: <Pine.GSO.4.21.0109220140390.11204-100000@weyl.math.psu.edu>
Message-ID: <Pine.GSO.4.21.0109220154391.11204-100000@weyl.math.psu.edu>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

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


