Re: [PATCH V4 7/8] fs/ext4: Introduce DAX inode flag

2020-05-25 Thread Jan Kara
On Sun 24-05-20 21:39:10, Ira Weiny wrote:
> On Fri, May 22, 2020 at 01:48:48PM +0200, Jan Kara wrote:
> > And then we should check conflicts with the journal flag as well, as I
> > mentioned in reply to the first patch. There it is more complicated by the
> > fact that we should disallow setting of both EXT4_INODE_DAX_FL and
> > EXT4_JOURNAL_DATA_FL at the same time so the checks will be somewhat more
> > complicated.
> 
> I'm confused by jflag.  Why is EXT4_JOURNAL_DATA_FL stored in jflag?

It isn't just EXT4_JOURNAL_DATA_FL. It is:

jflag = flags & EXT4_JOURNAL_DATA_FL;

so it is EXT4_JOURNAL_DATA_FL if it should be set by the current ioctl and 0
otherwise. But I agree that since we mostly do

(jflag ^ oldflags) & EXT4_JOURNAL_DATA_FL

jflags is mostly useless as we could do just

(flags ^ oldflags) & EXT4_JOURNAL_DATA_FL

I guess it's mostly a relict from the past...

Honza
-- 
Jan Kara 
SUSE Labs, CR


Re: [PATCH V4 7/8] fs/ext4: Introduce DAX inode flag

2020-05-24 Thread Ira Weiny
On Fri, May 22, 2020 at 01:48:48PM +0200, Jan Kara wrote:
> On Thu 21-05-20 12:13:12, ira.we...@intel.com wrote:
> > From: Ira Weiny 
> > 
> > Add a flag to preserve FS_XFLAG_DAX in the ext4 inode.
> > 
> > Set the flag to be user visible and changeable.  Set the flag to be
> > inherited.  Allow applications to change the flag at any time with the
> > exception of if VERITY or ENCRYPT is set.
> > 
> > Disallow setting VERITY or ENCRYPT if DAX is set.
> > 
> > Finally, on regular files, flag the inode to not be cached to facilitate
> > changing S_DAX on the next creation of the inode.
> > 
> > Signed-off-by: Ira Weiny 
> 
> ...
> 
> > @@ -303,6 +318,16 @@ static int ext4_ioctl_setflags(struct inode *inode,
> > unsigned int jflag;
> > struct super_block *sb = inode->i_sb;
> >  
> > +   if (ext4_test_inode_flag(inode, EXT4_INODE_DAX)) {
> > +   if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY) ||
> > +   ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT) ||
> > +   ext4_test_inode_state(inode,
> > + EXT4_STATE_VERITY_IN_PROGRESS)) {
> > +   err = -EOPNOTSUPP;
> > +   goto flags_out;
> > +   }
> > +   }
> 
> The way this check is implemented wouldn't IMO do what we need... It
> doesn't check the flags that are being set but just the current inode
> state. I think it should rather be:

Sorry, I got confused by the flags when I wrote this.

> 
>   if ((flags ^ oldflags) & EXT4_INODE_DAX_FL) {
>   ...
>   }
> 
> And perhaps move this to a place in ext4_ioctl_setflags() where we check
> other similar conflicts.

Sure.  It seems like a ext4_setflags_prepare() helper would be in order.  I'll
see what I can do.

> 
> And then we should check conflicts with the journal flag as well, as I
> mentioned in reply to the first patch. There it is more complicated by the
> fact that we should disallow setting of both EXT4_INODE_DAX_FL and
> EXT4_JOURNAL_DATA_FL at the same time so the checks will be somewhat more
> complicated.

I'm confused by jflag.  Why is EXT4_JOURNAL_DATA_FL stored in jflag?

Ira

> 
>   Honza
> 
> > +
> > /* Is it quota file? Do not allow user to mess with it */
> > if (ext4_is_quota_file(inode))
> > goto flags_out;
> -- 
> Jan Kara 
> SUSE Labs, CR


Re: [PATCH V4 7/8] fs/ext4: Introduce DAX inode flag

2020-05-22 Thread Andreas Dilger
On May 21, 2020, at 1:13 PM, ira.we...@intel.com wrote:
> 
> From: Ira Weiny 
> 
> Add a flag to preserve FS_XFLAG_DAX in the ext4 inode.
> 
> Set the flag to be user visible and changeable.  Set the flag to be
> inherited.  Allow applications to change the flag at any time with the
> exception of if VERITY or ENCRYPT is set.
> 
> Disallow setting VERITY or ENCRYPT if DAX is set.
> 
> Finally, on regular files, flag the inode to not be cached to facilitate
> changing S_DAX on the next creation of the inode.
> 
> Signed-off-by: Ira Weiny 

Reviewed-by: Andreas Dilger 

> 
> ---
> Changes from V3:
>   Move bit to bit25 per Andreas
> 
> Change from V2:
>   Add in making verity and DAX exclusive.
>   'Squash' in making encryption and DAX exclusive.
>   Add in EXT4_INODE_DAX flag definition to be compatible with
>   ext4_[set|test]_inode_flag() bit operations
>   Use ext4_[set|test]_inode_flag() bit operations to be consistent
>   with other code.
> 
> Change from V0:
>   Add FS_DAX_FL to include/uapi/linux/fs.h
>   to be consistent
>   Move ext4_dax_dontcache() to ext4_ioctl_setflags()
>   This ensures that it is only set when the flags are going to be
>   set and not if there is an error
>   Also this sets don't cache in the FS_IOC_SETFLAGS case
> 
> Change from RFC:
>   use new d_mark_dontcache()
>   Allow caching if ALWAYS/NEVER is set
>   Rebased to latest Linus master
>   Change flag to unused 0x0100
>   update ext4_should_enable_dax()
> ---
> fs/ext4/ext4.h  | 14 ++
> fs/ext4/inode.c |  2 +-
> fs/ext4/ioctl.c | 34 +-
> fs/ext4/super.c |  3 +++
> fs/ext4/verity.c|  2 +-
> include/uapi/linux/fs.h |  1 +
> 6 files changed, 49 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 65ffb831b2b9..09b8906568d2 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -415,13 +415,16 @@ struct flex_groups {
> #define EXT4_VERITY_FL0x0010 /* Verity protected 
> inode */
> #define EXT4_EA_INODE_FL  0x0020 /* Inode used for large EA */
> /* 0x0040 was formerly EXT4_EOFBLOCKS_FL */
> +
> +#define EXT4_DAX_FL  0x0200 /* Inode is DAX */
> +
> #define EXT4_INLINE_DATA_FL   0x1000 /* Inode has inline data. */
> #define EXT4_PROJINHERIT_FL   0x2000 /* Create with parents 
> projid */
> #define EXT4_CASEFOLD_FL  0x4000 /* Casefolded file */
> #define EXT4_RESERVED_FL  0x8000 /* reserved for ext4 lib */
> 
> -#define EXT4_FL_USER_VISIBLE 0x705BDFFF /* User visible flags */
> -#define EXT4_FL_USER_MODIFIABLE  0x604BC0FF /* User modifiable 
> flags */
> +#define EXT4_FL_USER_VISIBLE 0x725BDFFF /* User visible flags */
> +#define EXT4_FL_USER_MODIFIABLE  0x624BC0FF /* User modifiable 
> flags */
> 
> /* Flags we can manipulate with through EXT4_IOC_FSSETXATTR */
> #define EXT4_FL_XFLAG_VISIBLE (EXT4_SYNC_FL | \
> @@ -429,14 +432,16 @@ struct flex_groups {
>EXT4_APPEND_FL | \
>EXT4_NODUMP_FL | \
>EXT4_NOATIME_FL | \
> -  EXT4_PROJINHERIT_FL)
> +  EXT4_PROJINHERIT_FL | \
> +  EXT4_DAX_FL)
> 
> /* Flags that should be inherited by new inodes from their parent. */
> #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\
>  EXT4_SYNC_FL | EXT4_NODUMP_FL | EXT4_NOATIME_FL |\
>  EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\
>  EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL |\
> -EXT4_PROJINHERIT_FL | EXT4_CASEFOLD_FL)
> +EXT4_PROJINHERIT_FL | EXT4_CASEFOLD_FL |\
> +EXT4_DAX_FL)
> 
> /* Flags that are appropriate for regular files (all but dir-specific ones). 
> */
> #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL | 
> EXT4_CASEFOLD_FL |\
> @@ -488,6 +493,7 @@ enum {
>   EXT4_INODE_VERITY   = 20,   /* Verity protected inode */
>   EXT4_INODE_EA_INODE = 21,   /* Inode used for large EA */
> /* 22 was formerly EXT4_INODE_EOFBLOCKS */
> + EXT4_INODE_DAX  = 25,   /* Inode is DAX */
>   EXT4_INODE_INLINE_DATA  = 28,   /* Data in inode. */
>   EXT4_INODE_PROJINHERIT  = 29,   /* Create with parents projid */
>   EXT4_INODE_RESERVED = 31,   /* reserved for ext4 lib */
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 68fac9289109..778b0dbe3da6 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4419,7 +4419,7 @@ static bool ext4_should_enable_dax(struct inode *inode)
>   if 

Re: [PATCH V4 7/8] fs/ext4: Introduce DAX inode flag

2020-05-22 Thread Jan Kara
On Thu 21-05-20 12:13:12, ira.we...@intel.com wrote:
> From: Ira Weiny 
> 
> Add a flag to preserve FS_XFLAG_DAX in the ext4 inode.
> 
> Set the flag to be user visible and changeable.  Set the flag to be
> inherited.  Allow applications to change the flag at any time with the
> exception of if VERITY or ENCRYPT is set.
> 
> Disallow setting VERITY or ENCRYPT if DAX is set.
> 
> Finally, on regular files, flag the inode to not be cached to facilitate
> changing S_DAX on the next creation of the inode.
> 
> Signed-off-by: Ira Weiny 

...

> @@ -303,6 +318,16 @@ static int ext4_ioctl_setflags(struct inode *inode,
>   unsigned int jflag;
>   struct super_block *sb = inode->i_sb;
>  
> + if (ext4_test_inode_flag(inode, EXT4_INODE_DAX)) {
> + if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY) ||
> + ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT) ||
> + ext4_test_inode_state(inode,
> +   EXT4_STATE_VERITY_IN_PROGRESS)) {
> + err = -EOPNOTSUPP;
> + goto flags_out;
> + }
> + }

The way this check is implemented wouldn't IMO do what we need... It
doesn't check the flags that are being set but just the current inode
state. I think it should rather be:

if ((flags ^ oldflags) & EXT4_INODE_DAX_FL) {
...
}

And perhaps move this to a place in ext4_ioctl_setflags() where we check
other similar conflicts.

And then we should check conflicts with the journal flag as well, as I
mentioned in reply to the first patch. There it is more complicated by the
fact that we should disallow setting of both EXT4_INODE_DAX_FL and
EXT4_JOURNAL_DATA_FL at the same time so the checks will be somewhat more
complicated.

Honza

> +
>   /* Is it quota file? Do not allow user to mess with it */
>   if (ext4_is_quota_file(inode))
>   goto flags_out;
-- 
Jan Kara 
SUSE Labs, CR


[PATCH V4 7/8] fs/ext4: Introduce DAX inode flag

2020-05-21 Thread ira . weiny
From: Ira Weiny 

Add a flag to preserve FS_XFLAG_DAX in the ext4 inode.

Set the flag to be user visible and changeable.  Set the flag to be
inherited.  Allow applications to change the flag at any time with the
exception of if VERITY or ENCRYPT is set.

Disallow setting VERITY or ENCRYPT if DAX is set.

Finally, on regular files, flag the inode to not be cached to facilitate
changing S_DAX on the next creation of the inode.

Signed-off-by: Ira Weiny 

---
Changes from V3:
Move bit to bit25 per Andreas

Change from V2:
Add in making verity and DAX exclusive.
'Squash' in making encryption and DAX exclusive.
Add in EXT4_INODE_DAX flag definition to be compatible with
ext4_[set|test]_inode_flag() bit operations
Use ext4_[set|test]_inode_flag() bit operations to be consistent
with other code.

Change from V0:
Add FS_DAX_FL to include/uapi/linux/fs.h
to be consistent
Move ext4_dax_dontcache() to ext4_ioctl_setflags()
This ensures that it is only set when the flags are going to be
set and not if there is an error
Also this sets don't cache in the FS_IOC_SETFLAGS case

Change from RFC:
use new d_mark_dontcache()
Allow caching if ALWAYS/NEVER is set
Rebased to latest Linus master
Change flag to unused 0x0100
update ext4_should_enable_dax()
---
 fs/ext4/ext4.h  | 14 ++
 fs/ext4/inode.c |  2 +-
 fs/ext4/ioctl.c | 34 +-
 fs/ext4/super.c |  3 +++
 fs/ext4/verity.c|  2 +-
 include/uapi/linux/fs.h |  1 +
 6 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 65ffb831b2b9..09b8906568d2 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -415,13 +415,16 @@ struct flex_groups {
 #define EXT4_VERITY_FL 0x0010 /* Verity protected inode */
 #define EXT4_EA_INODE_FL   0x0020 /* Inode used for large EA */
 /* 0x0040 was formerly EXT4_EOFBLOCKS_FL */
+
+#define EXT4_DAX_FL0x0200 /* Inode is DAX */
+
 #define EXT4_INLINE_DATA_FL0x1000 /* Inode has inline data. */
 #define EXT4_PROJINHERIT_FL0x2000 /* Create with parents 
projid */
 #define EXT4_CASEFOLD_FL   0x4000 /* Casefolded file */
 #define EXT4_RESERVED_FL   0x8000 /* reserved for ext4 lib */
 
-#define EXT4_FL_USER_VISIBLE   0x705BDFFF /* User visible flags */
-#define EXT4_FL_USER_MODIFIABLE0x604BC0FF /* User modifiable 
flags */
+#define EXT4_FL_USER_VISIBLE   0x725BDFFF /* User visible flags */
+#define EXT4_FL_USER_MODIFIABLE0x624BC0FF /* User modifiable 
flags */
 
 /* Flags we can manipulate with through EXT4_IOC_FSSETXATTR */
 #define EXT4_FL_XFLAG_VISIBLE  (EXT4_SYNC_FL | \
@@ -429,14 +432,16 @@ struct flex_groups {
 EXT4_APPEND_FL | \
 EXT4_NODUMP_FL | \
 EXT4_NOATIME_FL | \
-EXT4_PROJINHERIT_FL)
+EXT4_PROJINHERIT_FL | \
+EXT4_DAX_FL)
 
 /* Flags that should be inherited by new inodes from their parent. */
 #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\
   EXT4_SYNC_FL | EXT4_NODUMP_FL | EXT4_NOATIME_FL |\
   EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\
   EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL |\
-  EXT4_PROJINHERIT_FL | EXT4_CASEFOLD_FL)
+  EXT4_PROJINHERIT_FL | EXT4_CASEFOLD_FL |\
+  EXT4_DAX_FL)
 
 /* Flags that are appropriate for regular files (all but dir-specific ones). */
 #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL | EXT4_CASEFOLD_FL 
|\
@@ -488,6 +493,7 @@ enum {
EXT4_INODE_VERITY   = 20,   /* Verity protected inode */
EXT4_INODE_EA_INODE = 21,   /* Inode used for large EA */
 /* 22 was formerly EXT4_INODE_EOFBLOCKS */
+   EXT4_INODE_DAX  = 25,   /* Inode is DAX */
EXT4_INODE_INLINE_DATA  = 28,   /* Data in inode. */
EXT4_INODE_PROJINHERIT  = 29,   /* Create with parents projid */
EXT4_INODE_RESERVED = 31,   /* reserved for ext4 lib */
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 68fac9289109..778b0dbe3da6 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4419,7 +4419,7 @@ static bool ext4_should_enable_dax(struct inode *inode)
if (test_opt(inode->i_sb, DAX_ALWAYS))
return true;
 
-   return false;
+   return ext4_test_inode_flag(inode, EXT4_INODE_DAX);
 }
 
 void ext4_set_inode_flags(struct inode *inode, bool init)
diff --git