From: Fernando Luis =?ISO-8859-1?Q?V=E1zquez?= Cao Subject: [PATCH 8/9] fsfreeze: add vfs ioctl to check freeze state Date: Fri, 14 Sep 2012 15:54:34 +0900 Message-ID: <1347605674.6868.10.camel@nexus.lab.ntt.co.jp> References: <1347605006.6868.2.camel@nexus.lab.ntt.co.jp> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: Josef Bacik , Eric Sandeen , Dave Chinner , Christoph Hellwig , Jan Kara , linux-fsdevel@vger.kernel.org, fernando@intellilink.co.jp To: Al Viro Return-path: Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]:42711 "EHLO tama500.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751512Ab2INGys (ORCPT ); Fri, 14 Sep 2012 02:54:48 -0400 In-Reply-To: <1347605006.6868.2.camel@nexus.lab.ntt.co.jp> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: The FIISFROZEN ioctl can be use by HA and monitoring software to check the freeze state of a mounted filesystem. Cc: Josef Bacik Cc: Eric Sandeen Cc: Christoph Hellwig Cc: Jan Kara Cc: Dave Chinner Signed-off-by: Fernando Luis Vazquez Cao --- diff -urNp linux-3.6-rc5-orig/fs/compat_ioctl.c linux-3.6-rc5/fs/compat_ioctl.c --- linux-3.6-rc5-orig/fs/compat_ioctl.c 2012-07-22 05:58:29.000000000 +0900 +++ linux-3.6-rc5/fs/compat_ioctl.c 2012-09-14 15:03:25.481355872 +0900 @@ -885,6 +885,7 @@ COMPATIBLE_IOCTL(FIGETBSZ) /* 'X' - originally XFS but some now in the VFS */ COMPATIBLE_IOCTL(FIFREEZE) COMPATIBLE_IOCTL(FITHAW) +COMPATIBLE_IOCTL(FIISFROZEN) COMPATIBLE_IOCTL(KDGETKEYCODE) COMPATIBLE_IOCTL(KDSETKEYCODE) COMPATIBLE_IOCTL(KDGKBTYPE) diff -urNp linux-3.6-rc5-orig/fs/ioctl.c linux-3.6-rc5/fs/ioctl.c --- linux-3.6-rc5-orig/fs/ioctl.c 2012-07-22 05:58:29.000000000 +0900 +++ linux-3.6-rc5/fs/ioctl.c 2012-09-14 15:03:25.481355872 +0900 @@ -536,6 +536,16 @@ static int ioctl_fsthaw(struct file *fil return thaw_super(sb); } +static int ioctl_fs_isfrozen(struct file *filp) +{ + struct super_block *sb = filp->f_path.dentry->d_inode->i_sb; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + return isfrozen_super(sb); +} + /* * When you add any new common ioctls to the switches above and below * please update compat_sys_ioctl() too. @@ -585,6 +595,12 @@ int do_vfs_ioctl(struct file *filp, unsi error = ioctl_fsthaw(filp); break; + case FIISFROZEN: + error = ioctl_fs_isfrozen(filp); + if (error >= 0) + return put_user(error, (int __user *)arg); + break; + case FS_IOC_FIEMAP: return ioctl_fiemap(filp, arg); diff -urNp linux-3.6-rc5-orig/fs/super.c linux-3.6-rc5/fs/super.c --- linux-3.6-rc5-orig/fs/super.c 2012-09-14 14:03:18.653312262 +0900 +++ linux-3.6-rc5/fs/super.c 2012-09-14 15:03:25.485355873 +0900 @@ -1545,3 +1545,8 @@ void emergency_thaw_all(void) schedule_work(work); } } + +int isfrozen_super(struct super_block *sb) +{ + return sb->s_writers.frozen > SB_UNFROZEN ? 1 : 0; +} diff -urNp linux-3.6-rc5-orig/include/linux/fs.h linux-3.6-rc5/include/linux/fs.h --- linux-3.6-rc5-orig/include/linux/fs.h 2012-09-14 14:03:18.993312323 +0900 +++ linux-3.6-rc5/include/linux/fs.h 2012-09-14 15:03:25.485355873 +0900 @@ -342,6 +342,7 @@ struct inodes_stat_t { #define FIFREEZE _IOWR('X', 119, int) /* Freeze */ #define FITHAW _IOWR('X', 120, int) /* Thaw */ #define FITRIM _IOWR('X', 121, struct fstrim_range) /* Trim */ +#define FIISFROZEN _IOR('X', 122, int) /* get sb freeze state */ #define FS_IOC_GETFLAGS _IOR('f', 1, long) #define FS_IOC_SETFLAGS _IOW('f', 2, long) @@ -2085,6 +2086,7 @@ extern int fd_statfs(int, struct kstatfs extern int vfs_ustat(dev_t, struct kstatfs *); extern int freeze_super(struct super_block *super); extern int thaw_super(struct super_block *super); +extern int isfrozen_super(struct super_block *sb); extern bool our_mnt(struct vfsmount *mnt); extern int current_umask(void);