linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>, Eric Sandeen <sandeen@redhat.com>,
	Josef Bacik <josef@redhat.com>,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH 2/2] fsfreeze: add BLKISFROZEN ioctl
Date: Thu, 21 Jul 2011 11:41:57 +0900	[thread overview]
Message-ID: <1311216117.2763.29.camel@nausicaa> (raw)
In-Reply-To: <1311215535.2763.20.camel@nausicaa>

The FIISFROZEN ioctl can be use by HA and monitoring software to check
the freeze state of the filesystem sitting on top of a block device.
This will not work for filesystems that can handle multiple devices,
i.e. btrfs.

Signed-off-by: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
---

diff -urNp linux-3.0-rc7-orig/block/compat_ioctl.c linux-3.0-rc7/block/compat_ioctl.c
--- linux-3.0-rc7-orig/block/compat_ioctl.c	2011-05-19 13:06:34.000000000 +0900
+++ linux-3.0-rc7/block/compat_ioctl.c	2011-07-20 15:20:31.439999983 +0900
@@ -757,6 +757,13 @@ long compat_blkdev_ioctl(struct file *fi
 	case BLKTRACETEARDOWN: /* compatible */
 		ret = blk_trace_ioctl(bdev, cmd, compat_ptr(arg));
 		return ret;
+	case BLKISFROZEN:
+		if (!capable(CAP_SYS_ADMIN))
+			return -EPERM;
+		ret = isfrozen_bdev(bdev);
+		if (ret >= 0)
+			return compat_put_int(arg, ret);
+                return ret;
 	default:
 		if (disk->fops->compat_ioctl)
 			ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg);
diff -urNp linux-3.0-rc7-orig/block/ioctl.c linux-3.0-rc7/block/ioctl.c
--- linux-3.0-rc7-orig/block/ioctl.c	2011-05-19 13:06:34.000000000 +0900
+++ linux-3.0-rc7/block/ioctl.c	2011-07-20 15:20:22.140020393 +0900
@@ -322,6 +322,13 @@ int blkdev_ioctl(struct block_device *bd
 	case BLKTRACETEARDOWN:
 		ret = blk_trace_ioctl(bdev, cmd, (char __user *) arg);
 		break;
+	case BLKISFROZEN:
+		if (!capable(CAP_SYS_ADMIN))
+			return -EPERM;
+		ret = isfrozen_bdev(bdev);
+		if (ret >= 0)
+			return put_int(arg, ret);
+		return ret;
 	default:
 		ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
 	}
diff -urNp linux-3.0-rc7-orig/fs/block_dev.c linux-3.0-rc7/fs/block_dev.c
--- linux-3.0-rc7-orig/fs/block_dev.c	2011-07-12 09:55:49.656000005 +0900
+++ linux-3.0-rc7/fs/block_dev.c	2011-07-21 09:40:36.900005798 +0900
@@ -310,6 +310,25 @@ out:
 }
 EXPORT_SYMBOL(thaw_bdev);
 
+int isfrozen_bdev(struct block_device *bdev)
+{
+	int ret;
+	struct super_block *sb;
+
+	mutex_lock(&bdev->bd_fsfreeze_mutex);
+
+	ret = -EINVAL;
+	sb = get_active_super(bdev);
+	if (!sb)
+		goto out;
+	ret = isfrozen_super(sb);
+	deactivate_super(sb);
+out:
+	mutex_unlock(&bdev->bd_fsfreeze_mutex);
+
+	return ret;
+}
+
 static int blkdev_writepage(struct page *page, struct writeback_control *wbc)
 {
 	return block_write_full_page(page, blkdev_get_block, wbc);
diff -urNp linux-3.0-rc7-orig/include/linux/fs.h linux-3.0-rc7/include/linux/fs.h
--- linux-3.0-rc7-orig/include/linux/fs.h	2011-07-12 09:55:51.192000002 +0900
+++ linux-3.0-rc7/include/linux/fs.h	2011-07-20 12:27:59.443932676 +0900
@@ -317,6 +317,7 @@ struct inodes_stat_t {
 #define BLKPBSZGET _IO(0x12,123)
 #define BLKDISCARDZEROES _IO(0x12,124)
 #define BLKSECDISCARD _IO(0x12,125)
+#define BLKISFROZEN _IOR(0x12,126, int) /* get file system freeze state */
 
 #define BMAP_IOCTL 1		/* obsolete - kept for compatibility */
 #define FIBMAP	   _IO(0x00,1)	/* bmap access */
@@ -2036,6 +2039,7 @@ extern int sync_blockdev(struct block_de
 extern struct super_block *freeze_bdev(struct block_device *);
 extern void emergency_thaw_all(void);
 extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
+extern int isfrozen_bdev(struct block_device *bdev);
 extern int fsync_bdev(struct block_device *);
 #else
 static inline void bd_forget(struct inode *inode) {}
@@ -2051,6 +2055,11 @@ static inline int thaw_bdev(struct block
 {
 	return 0;
 }
+
+static int isfrozen_bdev(struct block_device *bdev)
+{
+	return 0;
+}
 #endif
 extern int sync_filesystem(struct super_block *);
 extern const struct file_operations def_blk_fops;



  parent reply	other threads:[~2011-07-21  2:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-21  2:32 [PATCH 0/2] fsfreeze: check ioctls Fernando Luis Vazquez Cao
2011-07-21  2:36 ` [PATCH 1/2] fsfreeze: add FIISFROZEN ioctl Fernando Luis Vazquez Cao
2011-07-21  2:41 ` Fernando Luis Vazquez Cao [this message]
2011-07-27  7:30 ` [RFC][PATCH 0/4] fsfreeze: new API Fernando Luis Vazquez Cao
2011-07-27  7:32   ` [PATCH 1/4] fsfreeze: add vfs ioctl to check freeze state Fernando Luis Vazquez Cao
2011-07-27  7:34   ` [PATCH 2/4] fsfreeze: add block device " Fernando Luis Vazquez Cao
2011-07-27  7:35   ` [PATCH 3/4] fsfreeze: add ioctl to create a fd for freeze control Fernando Luis Vazquez Cao
2011-07-27  7:36   ` [PATCH 4/4] fsfreeze: add freeze fd ioctls Fernando Luis Vazquez 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=1311216117.2763.29.camel@nausicaa \
    --to=fernando@oss.ntt.co.jp \
    --cc=hch@lst.de \
    --cc=josef@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=sandeen@redhat.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;
as well as URLs for NNTP newsgroup(s).