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, Ric Wheeler <rwheeler@redhat.com>,
James Bottomley <jbottomley@parallels.com>,
Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 3/4] fsfreeze: add ioctl to create a fd for freeze control
Date: Wed, 27 Jul 2011 16:35:20 +0900 [thread overview]
Message-ID: <1311752120.2549.88.camel@nausicaa> (raw)
In-Reply-To: <1311751806.2549.83.camel@nausicaa>
Adds a new ioctl, FIGETFREEZEFD, which freezes the indicated filesystem and
returns a file descriptor; as long as that file descriptor is held open, the
filesystem remains open.
Signed-off-by: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
---
diff -urNp linux-3.0-orig/fs/compat_ioctl.c linux-3.0/fs/compat_ioctl.c
--- linux-3.0-orig/fs/compat_ioctl.c 2011-07-27 11:32:10.188008559 +0900
+++ linux-3.0/fs/compat_ioctl.c 2011-07-27 11:34:42.844014535 +0900
@@ -882,6 +882,7 @@ COMPATIBLE_IOCTL(FIBMAP)
COMPATIBLE_IOCTL(FIGETBSZ)
/* 'X' - originally XFS but some now in the VFS */
COMPATIBLE_IOCTL(FIFREEZE)
+COMPATIBLE_IOCTL(FIGETFREEZEFD)
COMPATIBLE_IOCTL(FITHAW)
COMPATIBLE_IOCTL(FIISFROZEN)
COMPATIBLE_IOCTL(KDGETKEYCODE)
diff -urNp linux-3.0-orig/fs/ioctl.c linux-3.0/fs/ioctl.c
--- linux-3.0-orig/fs/ioctl.c 2011-07-27 11:32:10.188008559 +0900
+++ linux-3.0/fs/ioctl.c 2011-07-27 12:24:54.116004298 +0900
@@ -14,6 +14,7 @@
#include <linux/uaccess.h>
#include <linux/writeback.h>
#include <linux/buffer_head.h>
+#include <linux/anon_inodes.h>
#include <linux/falloc.h>
#include <asm/ioctls.h>
@@ -525,6 +526,80 @@ static int ioctl_fsfreeze(struct file *f
return freeze_super(sb);
}
+struct freeze_fd_data {
+ struct super_block *sb;
+};
+
+static int freeze_fd_release(struct inode *inode, struct file *filp)
+{
+ struct freeze_fd_data *fd_data = filp->private_data;
+ struct super_block *sb = fd_data->sb;
+
+ thaw_super(sb);
+ deactivate_super(sb);
+ kfree(fd_data);
+
+ return 0;
+}
+
+static struct file_operations freeze_fd_fops = {
+ .release = freeze_fd_release,
+ .llseek = noop_llseek,
+};
+
+static int ioctl_get_freeze_fd(struct file *filp, int __user *argp)
+{
+ struct super_block *sb = filp->f_path.dentry->d_inode->i_sb;
+ int fd, ret;
+ struct file *file;
+ struct freeze_fd_data *fd_data;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ /* If filesystem doesn't support freeze feature, return. */
+ if (sb->s_op->freeze_fs == NULL)
+ return -EOPNOTSUPP;
+
+ fd_data = kmalloc(sizeof(struct freeze_fd_data), GFP_KERNEL);
+ if (!fd_data)
+ return -ENOMEM;
+
+ /* Get a file descriptor. */
+ ret = get_unused_fd_flags(O_RDWR);
+ if (ret < 0)
+ goto err_free_fd_data;
+ fd = ret;
+ fd_data->sb = sb;
+ file = anon_inode_getfile("freeze-fd",
+ &freeze_fd_fops, fd_data, O_RDWR);
+ if (IS_ERR(file)) {
+ ret = PTR_ERR(file);
+ goto err_put_fd;
+ }
+
+ /* Increment the active counter to keep the superblock around
+ * until the freeze fd is closed.
+ */
+ atomic_inc(&sb->s_active);
+
+ ret = freeze_super(sb);
+ if (ret < 0)
+ goto err_deact_super;
+
+ fd_install(fd, file);
+
+ return fd;
+
+err_deact_super:
+ deactivate_super(sb);
+err_put_fd:
+ put_unused_fd(fd);
+err_free_fd_data:
+ kfree(fd_data);
+ return ret;
+}
+
static int ioctl_fsthaw(struct file *filp)
{
struct super_block *sb = filp->f_path.dentry->d_inode->i_sb;
@@ -591,6 +666,10 @@ int do_vfs_ioctl(struct file *filp, unsi
error = ioctl_fsfreeze(filp);
break;
+ case FIGETFREEZEFD:
+ error = ioctl_get_freeze_fd(filp, argp);
+ break;
+
case FITHAW:
error = ioctl_fsthaw(filp);
break;
diff -urNp linux-3.0-orig/include/linux/fs.h linux-3.0/include/linux/fs.h
--- linux-3.0-orig/include/linux/fs.h 2011-07-27 11:32:12.700001748 +0900
+++ linux-3.0/include/linux/fs.h 2011-07-27 11:57:14.832000721 +0900
@@ -326,6 +326,7 @@ struct inodes_stat_t {
#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 FIGETFREEZEFD _IOWR('X', 123, int)
#define FS_IOC_GETFLAGS _IOR('f', 1, long)
#define FS_IOC_SETFLAGS _IOW('f', 2, long)
next prev parent reply other threads:[~2011-07-27 7:35 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 ` [PATCH 2/2] fsfreeze: add BLKISFROZEN ioctl Fernando Luis Vazquez Cao
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 ` Fernando Luis Vazquez Cao [this message]
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=1311752120.2549.88.camel@nausicaa \
--to=fernando@oss.ntt.co.jp \
--cc=hch@lst.de \
--cc=jbottomley@parallels.com \
--cc=josef@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=rwheeler@redhat.com \
--cc=sandeen@redhat.com \
--cc=tytso@mit.edu \
--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