public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Fernando Luis Vázquez Cao" <fernando@oss.ntt.co.jp>
To: Christoph Hellwig <hch@lst.de>
Cc: t-sato@yk.jp.nec.com, m-hamaguchi@ys.jp.nec.com,
	Al Viro <viro@zeniv.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Eric Sandeen <sandeen@redhat.com>
Subject: [PATCH 1/4] freeze_bdev: kill bd_mount_sem
Date: Thu, 27 Aug 2009 23:05:51 +0900	[thread overview]
Message-ID: <4A9692BF.2000400@oss.ntt.co.jp> (raw)
In-Reply-To: <4A965BD1.205@oss.ntt.co.jp>

Author: Christoph Hellwig <hch@lst.de>
Subject: [PATCH 1/4] freeze_bdev: kill bd_mount_sem

Now that we have the freeze count there is not much reason for bd_mount_sem
anymore.  The actual freeze/thaw operations are serialized using the
bd_fsfreeze_mutex, and the only other place we take bd_mount_sem is
get_sb_bdev which tries to prevent mounting a filesystem while the block
device is frozen.  Instead of add a check for bd_fsfreeze_count and
return -EBUSY if a filesystem is frozen.  While that is a change in user
visible behaviour a failing mount is much better for this case rather
than having the mount process stuck uninterruptible for a long time.


Signed-off-by: Christoph Hellwig <hch@lst.de>
---

diff -urNp linux-2.6.31-rc7-orig/fs/block_dev.c linux-2.6.31-rc7/fs/block_dev.c
--- linux-2.6.31-rc7-orig/fs/block_dev.c	2009-08-27 19:34:35.000000000 +0900
+++ linux-2.6.31-rc7/fs/block_dev.c	2009-08-27 19:36:22.000000000 +0900
@@ -216,8 +216,6 @@ EXPORT_SYMBOL(fsync_bdev);
   * freeze_bdev  --  lock a filesystem and force it into a consistent state
   * @bdev:	blockdevice to lock
   *
- * This takes the block device bd_mount_sem to make sure no new mounts
- * happen on bdev until thaw_bdev() is called.
   * If a superblock is found on this device, we take the s_umount semaphore
   * on it to make sure nobody unmounts until the snapshot creation is done.
   * The reference counter (bd_fsfreeze_count) guarantees that only the last
@@ -240,7 +238,6 @@ struct super_block *freeze_bdev(struct b
  	}
  	bdev->bd_fsfreeze_count++;

-	down(&bdev->bd_mount_sem);
  	sb = get_super(bdev);
  	if (sb && !(sb->s_flags & MS_RDONLY)) {
  		sb->s_frozen = SB_FREEZE_WRITE;
@@ -260,7 +257,6 @@ struct super_block *freeze_bdev(struct b
  					"VFS:Filesystem freeze failed\n");
  				sb->s_frozen = SB_UNFROZEN;
  				drop_super(sb);
-				up(&bdev->bd_mount_sem);
  				bdev->bd_fsfreeze_count--;
  				mutex_unlock(&bdev->bd_fsfreeze_mutex);
  				return ERR_PTR(error);
@@ -271,7 +267,7 @@ struct super_block *freeze_bdev(struct b
  	sync_blockdev(bdev);
  	mutex_unlock(&bdev->bd_fsfreeze_mutex);

-	return sb;	/* thaw_bdev releases s->s_umount and bd_mount_sem */
+	return sb;	/* thaw_bdev releases s->s_umount */
  }
  EXPORT_SYMBOL(freeze_bdev);

@@ -321,7 +317,6 @@ int thaw_bdev(struct block_device *bdev,
  		drop_super(sb);
  	}

-	up(&bdev->bd_mount_sem);
  	mutex_unlock(&bdev->bd_fsfreeze_mutex);
  	return 0;
  }
@@ -431,7 +426,6 @@ static void init_once(void *foo)

  	memset(bdev, 0, sizeof(*bdev));
  	mutex_init(&bdev->bd_mutex);
-	sema_init(&bdev->bd_mount_sem, 1);
  	INIT_LIST_HEAD(&bdev->bd_inodes);
  	INIT_LIST_HEAD(&bdev->bd_list);
  #ifdef CONFIG_SYSFS
diff -urNp linux-2.6.31-rc7-orig/fs/super.c linux-2.6.31-rc7/fs/super.c
--- linux-2.6.31-rc7-orig/fs/super.c	2009-08-27 19:34:35.000000000 +0900
+++ linux-2.6.31-rc7/fs/super.c	2009-08-27 19:36:22.000000000 +0900
@@ -740,9 +740,14 @@ int get_sb_bdev(struct file_system_type
  	 * will protect the lockfs code from trying to start a snapshot
  	 * while we are mounting
  	 */
-	down(&bdev->bd_mount_sem);
+	mutex_lock(&bdev->bd_fsfreeze_mutex);
+	if (bdev->bd_fsfreeze_count > 0) {
+		mutex_unlock(&bdev->bd_fsfreeze_mutex);
+		error = -EBUSY;
+		goto error_bdev;
+	}
  	s = sget(fs_type, test_bdev_super, set_bdev_super, bdev);
-	up(&bdev->bd_mount_sem);
+	mutex_unlock(&bdev->bd_fsfreeze_mutex);
  	if (IS_ERR(s))
  		goto error_s;

diff -urNp linux-2.6.31-rc7-orig/include/linux/fs.h linux-2.6.31-rc7/include/linux/fs.h
--- linux-2.6.31-rc7-orig/include/linux/fs.h	2009-08-27 19:34:35.000000000 +0900
+++ linux-2.6.31-rc7/include/linux/fs.h	2009-08-27 19:36:22.000000000 +0900
@@ -640,7 +640,6 @@ struct block_device {
  	struct super_block *	bd_super;
  	int			bd_openers;
  	struct mutex		bd_mutex;	/* open/close mutex */
-	struct semaphore	bd_mount_sem;
  	struct list_head	bd_inodes;
  	void *			bd_holder;
  	int			bd_holders;

  parent reply	other threads:[~2009-08-27 14:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-26  5:00 [RFC, PATCH] filesystem freeze: fix sys_umount induced perpetual freeze Fernando Luis Vázquez Cao
2009-08-26 17:38 ` Christoph Hellwig
2009-08-27 10:11   ` Fernando Luis Vázquez Cao
2009-08-27 11:54     ` Christoph Hellwig
2009-08-27 12:16       ` Fernando Luis Vázquez Cao
2009-08-27 14:05     ` Fernando Luis Vázquez Cao [this message]
2009-08-27 14:06     ` [PATCH 2/4] freeze_bdev: grab active reference to frozen superblocks Fernando Luis Vázquez Cao
2009-08-27 14:06     ` [PATCH 3/4] Do not allow umounting of frozen filesystems Fernando Luis Vázquez Cao
2009-09-22 11:07       ` Al Viro
2009-09-22 15:57         ` Eric Sandeen
2009-09-22 16:46           ` Fernando Luis Vazquez Cao
2009-09-22 16:41         ` Fernando Luis Vazquez Cao
2009-08-27 14:06 ` [PATCH 4/4] filesystem freeze: add ISFROZEN ioctl Fernando Luis Vázquez Cao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A9692BF.2000400@oss.ntt.co.jp \
    --to=fernando@oss.ntt.co.jp \
    --cc=akpm@linux-foundation.org \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m-hamaguchi@ys.jp.nec.com \
    --cc=sandeen@redhat.com \
    --cc=t-sato@yk.jp.nec.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox