[19/19] xfs: Add support for MAP_SYNC flag
diff mbox

Message ID 20171011200603.27442-20-jack@suse.cz
State New
Headers show

Commit Message

Jan Kara Oct. 11, 2017, 8:06 p.m. UTC
Now when everything is prepared, add support in xfs to accept MAP_SYNC
as an mmap(2) flag.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/file.c    |  1 +
 fs/xfs/xfs_file.c | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)

Comments

Dan Williams Oct. 11, 2017, 10:54 p.m. UTC | #1
On Wed, Oct 11, 2017 at 1:06 PM, Jan Kara <jack@suse.cz> wrote:
> Now when everything is prepared, add support in xfs to accept MAP_SYNC
> as an mmap(2) flag.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  fs/ext4/file.c    |  1 +
>  fs/xfs/xfs_file.c | 23 +++++++++++++++++++++++
>  2 files changed, 24 insertions(+)
>
> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
> index f013cda84b3d..6b597cc6b29d 100644
> --- a/fs/ext4/file.c
> +++ b/fs/ext4/file.c
> @@ -26,6 +26,7 @@
>  #include <linux/quotaops.h>
>  #include <linux/pagevec.h>
>  #include <linux/uio.h>
> +#include <linux/mman.h>
>  #include "ext4.h"
>  #include "ext4_jbd2.h"
>  #include "xattr.h"
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index c45f24ffab22..fb135224476d 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -44,6 +44,7 @@
>  #include <linux/falloc.h>
>  #include <linux/pagevec.h>
>  #include <linux/backing-dev.h>
> +#include <linux/mman.h>
>
>  static const struct vm_operations_struct xfs_file_vm_ops;
>
> @@ -1142,6 +1143,27 @@ xfs_file_mmap(
>         return 0;
>  }
>
> +#define XFS_MAP_SUPPORTED (LEGACY_MAP_MASK | MAP_SYNC)
> +
> +static int
> +xfs_file_mmap_validate(
> +       struct file             *filp,
> +       struct vm_area_struct   *vma,
> +       unsigned long           map_flags)
> +{
> +       if (map_flags & ~XFS_MAP_SUPPORTED)
> +               return -EOPNOTSUPP;
> +
> +       /*
> +        * We don't support synchronous mappings for non-DAX files. At least
> +        * until someone comes with a sensible use case.
> +        */
> +       if (!IS_DAX(file_inode(filp)) && (map_flags & MAP_SYNC))
> +               return -EOPNOTSUPP;

Same comment about using EPERM here. That's also what I'm returning in
the MAP_DIRECT case when the inode is a reflink inode and does not
support MAP_DIRECT.
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Williams Oct. 11, 2017, 11:02 p.m. UTC | #2
On Wed, Oct 11, 2017 at 1:06 PM, Jan Kara <jack@suse.cz> wrote:
> Now when everything is prepared, add support in xfs to accept MAP_SYNC
> as an mmap(2) flag.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  fs/ext4/file.c    |  1 +
>  fs/xfs/xfs_file.c | 23 +++++++++++++++++++++++
>  2 files changed, 24 insertions(+)
>
> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
> index f013cda84b3d..6b597cc6b29d 100644
> --- a/fs/ext4/file.c
> +++ b/fs/ext4/file.c
> @@ -26,6 +26,7 @@
>  #include <linux/quotaops.h>
>  #include <linux/pagevec.h>
>  #include <linux/uio.h>
> +#include <linux/mman.h>

I assume you wanted this change earlier in the series.
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christoph Hellwig Oct. 13, 2017, 7:28 a.m. UTC | #3
Should be merged go into the previous patch.

Also I just noticed how I misread ->mmap_validate in the first patch - it
doesn't just validate the mmap arguments but also replaces ->mmap
itself.

Which means that a) the name for it is very confusing, and b) we should
at very least have it fully replace ->mmap for file systems that
implement it, that is ext4 and xfs should not have to implement both
but just the new one.
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index f013cda84b3d..6b597cc6b29d 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -26,6 +26,7 @@ 
 #include <linux/quotaops.h>
 #include <linux/pagevec.h>
 #include <linux/uio.h>
+#include <linux/mman.h>
 #include "ext4.h"
 #include "ext4_jbd2.h"
 #include "xattr.h"
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index c45f24ffab22..fb135224476d 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -44,6 +44,7 @@ 
 #include <linux/falloc.h>
 #include <linux/pagevec.h>
 #include <linux/backing-dev.h>
+#include <linux/mman.h>
 
 static const struct vm_operations_struct xfs_file_vm_ops;
 
@@ -1142,6 +1143,27 @@  xfs_file_mmap(
 	return 0;
 }
 
+#define XFS_MAP_SUPPORTED (LEGACY_MAP_MASK | MAP_SYNC)
+
+static int
+xfs_file_mmap_validate(
+	struct file		*filp,
+	struct vm_area_struct	*vma,
+	unsigned long		map_flags)
+{
+	if (map_flags & ~XFS_MAP_SUPPORTED)
+		return -EOPNOTSUPP;
+
+	/*
+	 * We don't support synchronous mappings for non-DAX files. At least
+	 * until someone comes with a sensible use case.
+	 */
+	if (!IS_DAX(file_inode(filp)) && (map_flags & MAP_SYNC))
+		return -EOPNOTSUPP;
+
+	return xfs_file_mmap(filp, vma);
+}
+
 const struct file_operations xfs_file_operations = {
 	.llseek		= xfs_file_llseek,
 	.read_iter	= xfs_file_read_iter,
@@ -1153,6 +1175,7 @@  const struct file_operations xfs_file_operations = {
 	.compat_ioctl	= xfs_file_compat_ioctl,
 #endif
 	.mmap		= xfs_file_mmap,
+	.mmap_validate	= xfs_file_mmap_validate,
 	.open		= xfs_file_open,
 	.release	= xfs_file_release,
 	.fsync		= xfs_file_fsync,