Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1378569 > unrolled thread
| Started by | Florian Margaine <florian@margaine.com> |
|---|---|
| First post | 2016-04-14 10:00 +0200 |
| Last post | 2016-04-15 04:30 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] fs: add the FIGETFROZEN ioctl call Florian Margaine <florian@margaine.com> - 2016-04-14 10:00 +0200
Re: [PATCH] fs: add the FIGETFROZEN ioctl call Florian Margaine <florian@margaine.com> - 2016-04-14 10:10 +0200
Re: [PATCH] fs: add the FIGETFROZEN ioctl call Mateusz Guzik <mguzik@redhat.com> - 2016-04-15 03:00 +0200
Re: [PATCH] fs: add the FIGETFROZEN ioctl call Dave Chinner <david@fromorbit.com> - 2016-04-15 04:30 +0200
| From | Florian Margaine <florian@margaine.com> |
|---|---|
| Date | 2016-04-14 10:00 +0200 |
| Subject | [PATCH] fs: add the FIGETFROZEN ioctl call |
| Message-ID | <rnKlY-6Jd-27@gated-at.bofh.it> |
This lets userland get the filesystem freezing status, aka whether the
filesystem is frozen or not. This is so that an application can know if
it should freeze the filesystem or if it isn't necessary when taking a
snapshot.
---
fs/compat_ioctl.c | 1 +
fs/ioctl.c | 13 +++++++++++++
include/uapi/linux/fs.h | 1 +
3 files changed, 15 insertions(+)
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index bd01b92..d2173ab 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -918,6 +918,7 @@ COMPATIBLE_IOCTL(FIGETBSZ)
COMPATIBLE_IOCTL(FIFREEZE)
COMPATIBLE_IOCTL(FITHAW)
COMPATIBLE_IOCTL(FITRIM)
+COMPATIBLE_IOCTL(FIGETFROZEN)
COMPATIBLE_IOCTL(KDGETKEYCODE)
COMPATIBLE_IOCTL(KDSETKEYCODE)
COMPATIBLE_IOCTL(KDGKBTYPE)
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 116a333..249ed20 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -568,6 +568,16 @@ static int ioctl_fsthaw(struct file *filp)
return thaw_super(sb);
}
+static int ioctl_fsgetfrozen(struct file *filp)
+{
+ struct super_block *sb = file_inode(filp)->i_sb;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ return sb->s_writers.frozen;
+}
+
static long ioctl_file_dedupe_range(struct file *file, void __user *arg)
{
struct file_dedupe_range __user *argp = arg;
@@ -652,6 +662,9 @@ int do_vfs_ioctl(struct file *filp, unsigned int
fd, unsigned int cmd,
error = ioctl_fsthaw(filp);
break;
+ case FIGETFROZEN:
+ return put_user(ioctl_fsgetfrozen(filp), argp);
+
case FS_IOC_FIEMAP:
return ioctl_fiemap(filp, arg);
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 149bec8..d48f19c 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -230,6 +230,7 @@ struct fsxattr {
#define FIFREEZE _IOWR('X', 119, int) /* Freeze */
#define FITHAW _IOWR('X', 120, int) /* Thaw */
#define FITRIM _IOWR('X', 121, struct fstrim_range) /* Trim */
+#define FIGETFROZEN _IOWR('X', 122, int) /* Frozen status */
#define FICLONE _IOW(0x94, 9, int)
#define FICLONERANGE _IOW(0x94, 13, struct file_clone_range)
#define FIDEDUPERANGE _IOWR(0x94, 54, struct file_dedupe_range)
--
2.8.0
[toc] | [next] | [standalone]
| From | Florian Margaine <florian@margaine.com> |
|---|---|
| Date | 2016-04-14 10:10 +0200 |
| Message-ID | <rnKvF-75X-37@gated-at.bofh.it> |
| In reply to | #1378569 |
Hi,
For some reason, my email client replaced tabs with spaces in my
previous email.
Here is the patch using another client.
Regards,
Florian
From 80febe62cf5c21e0a369b64e38c82f068a416a61 Mon Sep 17 00:00:00 2001
From: Florian MARGAINE <florian@margaine.com>
Date: Sat, 19 Mar 2016 23:25:28 +0100
Subject: [PATCH] fs: add the FIGETFROZEN ioctl call
This lets userland get the filesystem freezing status, aka whether the
filesystem is frozen or not. This is so that an application can know if
it should freeze the filesystem or if it isn't necessary when taking a
snapshot.
---
fs/compat_ioctl.c | 1 +
fs/ioctl.c | 13 +++++++++++++
include/uapi/linux/fs.h | 1 +
3 files changed, 15 insertions(+)
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index bd01b92..d2173ab 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -918,6 +918,7 @@ COMPATIBLE_IOCTL(FIGETBSZ)
COMPATIBLE_IOCTL(FIFREEZE)
COMPATIBLE_IOCTL(FITHAW)
COMPATIBLE_IOCTL(FITRIM)
+COMPATIBLE_IOCTL(FIGETFROZEN)
COMPATIBLE_IOCTL(KDGETKEYCODE)
COMPATIBLE_IOCTL(KDSETKEYCODE)
COMPATIBLE_IOCTL(KDGKBTYPE)
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 116a333..249ed20 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -568,6 +568,16 @@ static int ioctl_fsthaw(struct file *filp)
return thaw_super(sb);
}
+static int ioctl_fsgetfrozen(struct file *filp)
+{
+ struct super_block *sb = file_inode(filp)->i_sb;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ return sb->s_writers.frozen;
+}
+
static long ioctl_file_dedupe_range(struct file *file, void __user
*arg)
{
struct file_dedupe_range __user *argp = arg;
@@ -652,6 +662,9 @@ int do_vfs_ioctl(struct file *filp, unsigned int
fd, unsigned int cmd,
error = ioctl_fsthaw(filp);
break;
+ case FIGETFROZEN:
+ return put_user(ioctl_fsgetfrozen(filp), argp);
+
case FS_IOC_FIEMAP:
return ioctl_fiemap(filp, arg);
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 149bec8..d48f19c 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -230,6 +230,7 @@ struct fsxattr {
#define FIFREEZE _IOWR('X', 119, int) /* Freeze */
#define FITHAW _IOWR('X', 120, int) /* Thaw */
#define FITRIM _IOWR('X', 121, struct fstrim_range)
/* Trim */
+#define FIGETFROZEN _IOWR('X', 122, int) /* Frozen
status */
#define FICLONE _IOW(0x94, 9, int)
#define FICLONERANGE _IOW(0x94, 13, struct file_clone_range)
#define FIDEDUPERANGE _IOWR(0x94, 54, struct file_dedupe_range)
--
2.8.0
[toc] | [prev] | [next] | [standalone]
| From | Mateusz Guzik <mguzik@redhat.com> |
|---|---|
| Date | 2016-04-15 03:00 +0200 |
| Message-ID | <ro0h4-2BJ-7@gated-at.bofh.it> |
| In reply to | #1378569 |
On Thu, Apr 14, 2016 at 09:57:07AM +0200, Florian Margaine wrote: > This lets userland get the filesystem freezing status, aka whether the > filesystem is frozen or not. This is so that an application can know if > it should freeze the filesystem or if it isn't necessary when taking a > snapshot. The feature may be useful in general, I don't know. However, I'm confused why programs would depend on it. If you froze a particular subsystem, you don't have to check. If you did not, what prevents whoever originaly froze it from unfreezing as you access it? As such, maybe the feature you are looking for would count how many times the fs is frozen. -- Mateusz Guzik
[toc] | [prev] | [next] | [standalone]
| From | Dave Chinner <david@fromorbit.com> |
|---|---|
| Date | 2016-04-15 04:30 +0200 |
| Message-ID | <ro1G9-3T5-3@gated-at.bofh.it> |
| In reply to | #1378569 |
On Thu, Apr 14, 2016 at 09:57:07AM +0200, Florian Margaine wrote:
> This lets userland get the filesystem freezing status, aka whether the
> filesystem is frozen or not. This is so that an application can know if
> it should freeze the filesystem or if it isn't necessary when taking a
> snapshot.
freezing nests, so there is no reason for avoiding a freeze when
doing a snapshot. Indeed, if you don't wrap freeze/thaw around a
snapshot, then if the fs is thawed while the snapshot is in progress
then you are going to get a corrupt snapshot....
And, besides, polling for frozenness from userspace is inherently
racy - by the time the syscall returns, the information may be
incorrect, so you can't rely on it for decision making purposes in
userspace.
> +static int ioctl_fsgetfrozen(struct file *filp)
> +{
> + struct super_block *sb = file_inode(filp)->i_sb;
> +
> + if (!capable(CAP_SYS_ADMIN))
> + return -EPERM;
> +
> + return sb->s_writers.frozen;
This makes the internal freeze implementation states part of the
userspace ABI. This needs an API that is separate from the internal
implementation...
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web