xfs: y2038 conversion
Subsystems (2)
cover xfs: y2038 conversion
This is part of a longer set of changes to clean up the last remaining bits for the y2038 conversion. In XFS, three distinct problems need to be addressed:
1. The use of time_t in kernel sources -- I'm in the process of removing all of them so we can remove the definition itself, making it harder to write new y2038-unsafe code. This part is trivially done as a side-effect of the other two.
2. The use of time_t in a user API header for ioctls. When building against a new 32-bit libc with 64-bit time_t, the structures no longer match and we get incorrect data from ioctls. Unfortunately, there is no good way to fix XFS_IOC_FSBULKSTAT, I considered different approaches and in the end came up with three variants that are all part of this series. The idea is to pick just one of course.
3. On-disk timestamps hitting the y2038 limit. This applies to both inode timestamps and quota data. Both are extended to 40 bits, with the minimum timestamp still being year 1902, and the maximum getting extended from 2038 to 36744.
Please review and let me know which of ioctl API changes makes the most sense. I have not done any actual runtime testing on the patches, so this is clearly too late for the next merge window, but I hope to get it all merged for v5.6.
Arnd
Arnd Bergmann (5):
xfs: [variant A] avoid time_t in user api
xfs: [variant B] add time64 version of xfs_bstat
xfs: [variant C] avoid i386-misaligned xfs_bstat
xfs: extend inode format for 40-bit timestamps
xfs: use 40-bit quota time limits
fs/xfs/libxfs/xfs_dquot_buf.c | 6 +- fs/xfs/libxfs/xfs_format.h | 11 +- fs/xfs/libxfs/xfs_fs.h | 37 +++++- fs/xfs/libxfs/xfs_inode_buf.c | 28 +++-- fs/xfs/libxfs/xfs_inode_buf.h | 1 + fs/xfs/libxfs/xfs_log_format.h | 6 +- fs/xfs/libxfs/xfs_trans_inode.c | 3 +- fs/xfs/xfs_dquot.c | 29 +++-- fs/xfs/xfs_inode.c | 3 +- fs/xfs/xfs_inode_item.c | 10 +- fs/xfs/xfs_ioctl.c | 195 +++++++++++++++++++++++++++++++- fs/xfs/xfs_ioctl.h | 12 ++ fs/xfs/xfs_ioctl32.c | 160 +++++--------------------- fs/xfs/xfs_ioctl32.h | 26 ++--- fs/xfs/xfs_iops.c | 3 +- fs/xfs/xfs_itable.c | 2 +- fs/xfs/xfs_qm.c | 18 ++- fs/xfs/xfs_qm.h | 6 +- fs/xfs/xfs_qm_syscalls.c | 16 ++- fs/xfs/xfs_quotaops.c | 6 +- fs/xfs/xfs_super.c | 2 +- fs/xfs/xfs_trans_dquot.c | 17 ++- 22 files changed, 387 insertions(+), 210 deletions(-)
Signature · 1 line
2.20.0
RFC 1/5 xfs: [variant A] avoid time_t in user api
The ioctl definitions for XFS_IOC_SWAPEXT, XFS_IOC_FSBULKSTAT and XFS_IOC_FSBULKSTAT_SINGLE are part of libxfs and based on time_t.
The definition for time_t differs between current kernels and coming 32-bit libc variants that define it as 64-bit. For most ioctls, that means the kernel has to be able to handle two different command codes based on the different structure sizes.
The same solution could be applied for XFS_IOC_SWAPEXT, but it would not work for XFS_IOC_FSBULKSTAT and XFS_IOC_FSBULKSTAT_SINGLE because the structure with the time_t is passed through an indirect pointer, and the command number itself is based on struct xfs_fsop_bulkreq, which does not differ based on time_t.
This means any solution that can be applied requires a change of the ABI definition in the xfs_fs.h header file, as well as doing the same change in any user application that contains a copy of this header.
The usual solution would be to define a replacement structure and use conditional compilation for the ioctl command codes to use one or the other, such as
#define XFS_IOC_FSBULKSTAT_OLD _IOWR('X', 101, struct xfs_fsop_bulkreq) #define XFS_IOC_FSBULKSTAT_NEW _IOWR('X', 129, struct xfs_fsop_bulkreq) #define XFS_IOC_FSBULKSTAT ((sizeof(time_t) == sizeof(__kernel_long_t)) ? \
XFS_IOC_FSBULKSTAT_OLD : XFS_IOC_FSBULKSTAT_NEW)
After this, the kernel would be able to implement both XFS_IOC_FSBULKSTAT_OLD and XFS_IOC_FSBULKSTAT_NEW handlers on 32-bit architectures with the correct ABI for either definition of time_t.
However, as long as two observations are true, a much simpler solution can be used:
1. xfsprogs is the only user space project that has a copy of this header
2. xfsprogs already has a replacement for all three affected ioctl commands, based on the xfs_bulkstat structure to pass 64-bit timestamps regardless of the architecture
Based on those assumptions, changing xfs_bstime to use __kernel_long_t instead of time_t in both the kernel and in xfsprogs preserves the current ABI for any libc definition of time_t and solves the problem of passing 64-bit timestamps to 32-bit user space.
If either of the two assumptions is invalid, more discussion is needed for coming up with a way to fix as much of the affected user space code as possible.
--- fs/xfs/libxfs/xfs_fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/libxfs/xfs_fs.h +1 -1
@@ -324,7 +324,7 @@ typedef struct xfs_growfs_rt {* Structures returned from ioctl XFS_IOC_FSBULKSTAT & XFS_IOC_FSBULKSTAT_SINGLE */ typedef struct xfs_bstime { -time_t tv_sec;/* seconds */ +__kernel_long_t tv_sec;/* seconds */ __s32 tv_nsec;/* and nanoseconds */ }xfs_bstime_t ;
Signature · 1 line
2.20.0
Re: [RFC 1/5] xfs: [variant A] avoid time_t in user api
Quoted 4 lines · Arnd Bergmann
However, as long as two observations are true, a much simpler solution can be used:
1. xfsprogs is the only user space project that has a copy of this header
We can't guarantee that.
Quoted 3 lines
2. xfsprogs already has a replacement for all three affected ioctl commands, based on the
xfs_bulkstatstructure to pass 64-bit timestamps regardless of the architecture
XFS_IOC_BULKSTAT replaces XFS_IOC_FSBULKSTAT directly, and can replace XFS_IOC_FSBULKSTAT_SINGLE indirectly, so that is easy. Most users actually use the new one now through libfrog, although I found a user of the direct ioctl in the xfs_io tool, which could easily be fixed as well.
XFS_IOC_SWAPEXT does not have a direct replacement, but the timestamp is only used to verify that the file did not change vs the previous stat. So not being able to represent > 2038 times is not a real problem anyway.
At some point we should probably look into a file system independent defrag ioctl anyway, at which point we can deprecate XFS_IOC_SWAPEXT.
Quoted 4 lines
Based on those assumptions, changing
xfs_bstimeto use__kernel_long_tinstead oftime_tin both the kernel and in xfsprogs preserves the current ABI for any libc definition oftime_tand solves the problem of passing 64-bit timestamps to 32-bit user space.
As said above their are not entirely true, but I still think this patch is the right thing to do, if only to get the time_t out of the ABI..
Darrick J. Wong
Reviewed-byRe: [RFC 1/5] xfs: [variant A] avoid time_t in user api
Quoted 12 lines · Christoph Hellwig
Quoted 4 lines · Arnd Bergmann
However, as long as two observations are true, a much simpler solution can be used:
1. xfsprogs is the only user space project that has a copy of this header
We can't guarantee that.
Quoted 3 lines
2. xfsprogs already has a replacement for all three affected ioctl commands, based on the
xfs_bulkstatstructure to pass 64-bit timestamps regardless of the architecture
Quoted 5 lines
XFS_IOC_BULKSTATreplacesXFS_IOC_FSBULKSTATdirectly, and can replaceXFS_IOC_FSBULKSTAT_SINGLEindirectly, so that is easy. Most users actually use the new one now through libfrog, although I found a user of the direct ioctl in thexfs_iotool, which could easily be fixed as well.
Agreed, XFS_IOC_BULKSTAT is the replacement for the two FSBULKSTAT variants. The only question in my mind for the old ioctls is whether we should return EOVERFLOW if the timestamp would overflow? Or just truncate the results?
Quoted 4 lines
XFS_IOC_SWAPEXTdoes not have a direct replacement, but the timestamp is only used to verify that the file did not change vs the previous stat. So not being able to represent > 2038 times is not a real problem anyway.
Won't it become a problem when the tv_sec comparison in xfs_swap_extents is type-promoted to the larger type but lacks the upper bits?
I guess we could force the check to the lower 32 bits on the assumption that those are the most likely to change due to a file write.
I kinda want to do a SWAPEXT v5, fwiw....
Quoted 8 lines
At some point we should probably look into a file system independent defrag ioctl anyway, at which point we can deprecate
XFS_IOC_SWAPEXT.Quoted 4 lines
Based on those assumptions, changing
xfs_bstimeto use__kernel_long_tinstead oftime_tin both the kernel and in xfsprogs preserves the current ABI for any libc definition oftime_tand solves the problem of passing 64-bit timestamps to 32-bit user space.
Quoted 4 lines
As said above their are not entirely true, but I still think this patch is the right thing to do, if only to get the
time_tout of the ABI..Reviewed-by Christoph Hellwig <[email protected]>
Seconded,
--D
Re: [RFC 1/5] xfs: [variant A] avoid time_t in user api
Quoted 19 lines · Darrick J. Wong
Quoted 12 lines · Christoph Hellwig
Quoted 4 lines · Arnd Bergmann
However, as long as two observations are true, a much simpler solution can be used:
1. xfsprogs is the only user space project that has a copy of this header
We can't guarantee that.
Quoted 3 lines
2. xfsprogs already has a replacement for all three affected ioctl commands, based on the
xfs_bulkstatstructure to pass 64-bit timestamps regardless of the architectureQuoted 5 lines
XFS_IOC_BULKSTATreplacesXFS_IOC_FSBULKSTATdirectly, and can replaceXFS_IOC_FSBULKSTAT_SINGLEindirectly, so that is easy. Most users actually use the new one now through libfrog, although I found a user of the direct ioctl in thexfs_iotool, which could easily be fixed as well.
Quoted 4 lines
Agreed,
XFS_IOC_BULKSTATis the replacement for the two FSBULKSTAT variants. The only question in my mind for the old ioctls is whether we should return EOVERFLOW if the timestamp would overflow? Or just truncate the results?
I think neither of these would be particularly helpful, the result is that users see no change in behavior until it's actually too late and the timestamps have overrun.
If we take variant A and just fix the ABI to 32-bit time_t, it is important that all user space stop using these ioctls and moves to the v5 interfaces instead (including SWAPEXT I guess).
Something along the lines of this change would work:
fs/xfs/xfs_ioctl.c +25 -0
@@ -830,6 +830,23 @@ xfs_fsinumbers_fmt(return xfs_ibulk_advance (breq,sizeof (struct xfs_inogrp )); } +/* disallow y2038-unsafe ioctls with CONFIG_COMPAT_32BIT_TIME=n */ +static bool xfs_have_compat_bstat_time32 (unsigned int cmd) +{ +if (IS_ENABLED (CONFIG_COMPAT_32BIT_TIME )) +return true; + +if (IS_ENABLED (CONFIG_64BIT ) && !in_compat_syscall ()) +return true; + +if (cmd ==XFS_IOC_FSBULKSTAT_SINGLE || + cmd ==XFS_IOC_FSBULKSTAT || + cmd ==XFS_IOC_SWAPEXT ) +return false; + +return true; +} + STATIC int xfs_ioc_fsbulkstat( xfs_mount_t *mp,
@@ -850,6 +867,9 @@ xfs_ioc_fsbulkstat(if (!capable (CAP_SYS_ADMIN ))return -EPERM ; +if (!xfs_have_compat_bstat_time32 ()) +return -EINVAL ; +if (XFS_FORCED_SHUTDOWN (mp))return -EIO ;
@@ -2051,6 +2071,11 @@ xfs_ioc_swapext(struct fd f, tmp;int error =0 ; +if (xfs_have_compat_bstat_time32 (XFS_IOC_SWAPEXT )) { + error = -EINVAL +got out; + } +/* Pull information for the target fd */ f =fdget ((int )sxp->sx_fdtarget);if (!f.file) {
This way, at least users that intentionally turn off CONFIG_COMPAT_32BIT_TIME run into the broken application right away, which forces them to upgrade or fix the code to use the v5 ioctl.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Based on those assumptions, changing
xfs_bstimeto use__kernel_long_tinstead oftime_tin both the kernel and in xfsprogs preserves the current ABI for any libc definition oftime_tand solves the problem of passing 64-bit timestamps to 32-bit user space.
Quoted 7 lines
Quoted 4 lines
As said above their are not entirely true, but I still think this patch is the right thing to do, if only to get the
time_tout of the ABI..Reviewed-by Christoph Hellwig <[email protected]>Seconded,
Reviewed-by Darrick J. Wong <[email protected]>
Thanks!
Arnd
Re: [RFC 1/5] xfs: [variant A] avoid time_t in user api
Quoted 40 lines · Arnd Bergmann
Quoted 19 lines · Darrick J. Wong
Quoted 12 lines · Christoph Hellwig
Quoted 4 lines · Arnd Bergmann
However, as long as two observations are true, a much simpler solution can be used:
1. xfsprogs is the only user space project that has a copy of this header
We can't guarantee that.
Quoted 3 lines
2. xfsprogs already has a replacement for all three affected ioctl commands, based on the
xfs_bulkstatstructure to pass 64-bit timestamps regardless of the architectureQuoted 5 lines
XFS_IOC_BULKSTATreplacesXFS_IOC_FSBULKSTATdirectly, and can replaceXFS_IOC_FSBULKSTAT_SINGLEindirectly, so that is easy. Most users actually use the new one now through libfrog, although I found a user of the direct ioctl in thexfs_iotool, which could easily be fixed as well.Quoted 4 lines
Agreed,
XFS_IOC_BULKSTATis the replacement for the two FSBULKSTAT variants. The only question in my mind for the old ioctls is whether we should return EOVERFLOW if the timestamp would overflow? Or just truncate the results?I think neither of these would be particularly helpful, the result is that users see no change in behavior until it's actually too late and the timestamps have overrun.
If we take variant A and just fix the ABI to 32-bit
time_t, it is important that all user space stop using these ioctls and moves to the v5 interfaces instead (including SWAPEXT I guess).Something along the lines of this change would work:
fs/xfs/xfs_ioctl.c +0
-0
fs/xfs/xfs_ioctl.c xfs_fsinumbers_fmt( · line 835
Quoted 6 lines
fs/xfs/xfs_ioctl.c +3
-0@@ -830,6 +830,23 @@ xfs_fsinumbers_fmt(return xfs_ibulk_advance (breq,sizeof (struct xfs_inogrp )); } +/* disallow y2038-unsafe ioctls with CONFIG_COMPAT_32BIT_TIME=n */ +static bool xfs_have_compat_bstat_time32 (unsigned int cmd) +{
Wouldn't we want a test here like:
if (!xfs_sb_version_hasbigtimestamps(&mp->m_sb)) return true;
Since date overflow isn't a problem for existing xfs with 32-bit timestamps, right?
fs/xfs/xfs_ioctl.c xfs_fsinumbers_fmt( · line 836
Quoted 1 line
fs/xfs/xfs_ioctl.c +1
-0+if (IS_ENABLED (CONFIG_COMPAT_32BIT_TIME ))
Heh, I didn't know that existed.
Quoted 38 lines
fs/xfs/xfs_ioctl.c +20
-0+return true; + +if (IS_ENABLED (CONFIG_64BIT ) && !in_compat_syscall ()) +return true; +if (cmd ==XFS_IOC_FSBULKSTAT_SINGLE || + cmd ==XFS_IOC_FSBULKSTAT || + cmd ==XFS_IOC_SWAPEXT ) +return false; + +return true; +} + STATIC int xfs_ioc_fsbulkstat( xfs_mount_t *mp,@@ -850,6 +867,9 @@ xfs_ioc_fsbulkstat(if (!capable (CAP_SYS_ADMIN ))return -EPERM ; +if (!xfs_have_compat_bstat_time32 ()) +return -EINVAL ; +if (XFS_FORCED_SHUTDOWN (mp))return -EIO ;@@ -2051,6 +2071,11 @@ xfs_ioc_swapext(struct fd f, tmp;int error =0 ; +if (xfs_have_compat_bstat_time32 (XFS_IOC_SWAPEXT )) { + error = -EINVAL +got out; + } +/* Pull information for the target fd */ f =fdget ((int )sxp->sx_fdtarget);if (!f.file) {
Quoted 3 lines
This way, at least users that intentionally turn off
CONFIG_COMPAT_32BIT_TIMErun into the broken application right away, which forces them to upgrade or fix the code to use the v5 ioctl.
Sounds reasonable.
--D
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Based on those assumptions, changing
xfs_bstimeto use__kernel_long_tinstead oftime_tin both the kernel and in xfsprogs preserves the current ABI for any libc definition oftime_tand solves the problem of passing 64-bit timestamps to 32-bit user space.Quoted 7 lines
Quoted 4 lines
As said above their are not entirely true, but I still think this patch is the right thing to do, if only to get the
time_tout of the ABI..Reviewed-by Christoph Hellwig <[email protected]>Seconded,
Reviewed-by Darrick J. Wong <[email protected]>Thanks!
Arnd
Re: [RFC 1/5] xfs: [variant A] avoid time_t in user api
Quoted 18 lines · Darrick J. Wong
fs/xfs/xfs_ioctl.c xfs_fsinumbers_fmt( · line 835
Quoted 13 lines · Arnd Bergmann
Quoted 1 line · Darrick J. Wong
On Tue, Nov 12, 2019 at 03:16:00PM +0100, Christoph Hellwig wrote:
fs/xfs/xfs_ioctl.c +3
-0@@ -830,6 +830,23 @@ xfs_fsinumbers_fmt(return xfs_ibulk_advance (breq,sizeof (struct xfs_inogrp )); } +/* disallow y2038-unsafe ioctls with CONFIG_COMPAT_32BIT_TIME=n */ +static bool xfs_have_compat_bstat_time32 (unsigned int cmd) +{Wouldn't we want a test here like:
Quoted 5 lines
if (!xfs_sb_version_hasbigtimestamps(&mp->m_sb)) return true;Since date overflow isn't a problem for existing xfs with 32-bit timestamps, right?
I'd say probably not.
This would be for a kernel that intentionally only supports y2038-safe user space to ensure that we don't get any surprises later. In that configuration, I think we're still better off not allowing broken ioctls regardless of whether the file system is also broken. ;-)
Quoted 3 lines
fs/xfs/xfs_ioctl.c xfs_fsinumbers_fmt( · line 836
Quoted 1 line
fs/xfs/xfs_ioctl.c +1
-0+if (IS_ENABLED (CONFIG_COMPAT_32BIT_TIME ))Heh, I didn't know that existed.
It barely does. At the moment it is always enabled on all architectures except for 32-bit riscv, but I submitted a patch to make it user selectable last week.
Arnd
RFC 2/5 xfs: [variant B] add time64 version of xfs_bstat
In reply to Arnd BergmannThe ioctl definitions for XFS_IOC_SWAPEXT, XFS_IOC_FSBULKSTAT and XFS_IOC_FSBULKSTAT_SINGLE are part of libxfs and based on time_t.
The definition for time_t differs between current kernels and coming 32-bit libc variants that define it as 64-bit. For most ioctls, that means the kernel has to be able to handle two different command codes based on the different structure sizes.
The same solution is be applied for XFS_IOC_SWAPEXT, but it would does work for XFS_IOC_FSBULKSTAT and XFS_IOC_FSBULKSTAT_SINGLE because the structure with the time_t is passed through an indirect pointer, and the command number itself is based on struct xfs_fsop_bulkreq, which does not differ based on time_t.
The best workaround I could come up with is to change the header file to define new command numbers with the same structure and have users pick one or the other at compile-time based on the time_t definition in the C library, like:
#define XFS_IOC_FSBULKSTAT_OLD _IOWR('X', 101, struct xfs_fsop_bulkreq) #define XFS_IOC_FSBULKSTAT_NEW _IOWR('X', 129, struct xfs_fsop_bulkreq) #define XFS_IOC_FSBULKSTAT ((sizeof(time_t) == sizeof(__kernel_long_t)) ? \
XFS_IOC_FSBULKSTAT_OLD : XFS_IOC_FSBULKSTAT_NEW)
The native xfs_ioctl now handles both the time32 and the time64 version of the xfs_bstat data structure, and this gets called indirectly by the compat code implementing the xfs_fsop_bulkreq commands. For x86, we still need another implementation to deal with the broken alignment, so the existing code is left in ioctl32 but changed to now handle the misaligned time64 structure.
Based on the requirement to change the header file, a much simpler fix would be to change the time_t reference to 'long' and always keep passing the shorter timestamp as on 32-bit applications using the old ioctl, forcing code changes to use the v5 API to access post-y2038 timestamps, and still requiring the updated header when building with a new C library.
---
Note: I have not tested this patch beyond compiling it, for now this is for discussion, to decide which approach makes more sense.
--- fs/xfs/libxfs/xfs_fs.h | 19 +++- fs/xfs/xfs_ioctl.c | 195 +++++++++++++++++++++++++++++++++++++++-- fs/xfs/xfs_ioctl.h | 12 +++ fs/xfs/xfs_ioctl32.c | 82 ++++++++++------- fs/xfs/xfs_ioctl32.h | 26 +++--- 5 files changed, 278 insertions(+), 56 deletions(-)
fs/xfs/libxfs/xfs_fs.h +16 -3
@@ -324,8 +324,13 @@ typedef struct xfs_growfs_rt {* Structures returned from ioctl XFS_IOC_FSBULKSTAT & XFS_IOC_FSBULKSTAT_SINGLE */ typedef struct xfs_bstime { -__kernel_long_t tv_sec;/* seconds */ +#ifdef __KERNEL__ +__s64 tv_sec;/* seconds */ __s32 tv_nsec;/* and nanoseconds */ +#else +time_t tv_sec;/* seconds */ +__s32 tv_nsec;/* and nanoseconds */ +#endif }xfs_bstime_t ;struct xfs_bstat {
@@ -775,8 +780,8 @@ struct xfs_scrub_metadata {* ioctl commands that replace IRIX syssgi()'s */ #define XFS_IOC_FSGEOMETRY_V1 _IOR ('X', 100, struct xfs_fsop_geom_v1) -#define XFS_IOC_FSBULKSTAT _IOWR('X', 101, struct xfs_fsop_bulkreq) -#define XFS_IOC_FSBULKSTAT_SINGLE _IOWR('X', 102, struct xfs_fsop_bulkreq) +#define XFS_IOC_FSBULKSTAT_OLD _IOWR('X', 101, struct xfs_fsop_bulkreq) +#define XFS_IOC_FSBULKSTAT_SINGLE_OLD _IOWR('X', 102, struct xfs_fsop_bulkreq)#define XFS_IOC_FSINUMBERS _IOWR('X', 103, struct xfs_fsop_bulkreq)#define XFS_IOC_PATH_TO_FSHANDLE _IOWR('X', 104, struct xfs_fsop_handlereq)#define XFS_IOC_PATH_TO_HANDLE _IOWR('X', 105, struct xfs_fsop_handlereq)
@@ -805,6 +810,14 @@ struct xfs_scrub_metadata {#define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom)#define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req)#define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) +#define XFS_IOC_FSBULKSTAT_NEW _IOWR('X', 129, struct xfs_fsop_bulkreq) +#define XFS_IOC_FSBULKSTAT_SINGLE_NEW _IOWR('X', 130, struct xfs_fsop_bulkreq) + +#define XFS_IOC_FSBULKSTAT ((sizeof(time_t) == sizeof(__kernel_long_t)) ? \ + XFS_IOC_FSBULKSTAT_OLD : XFS_IOC_FSBULKSTAT_NEW) +#define XFS_IOC_FSBULKSTAT_SINGLE ((sizeof(time_t) == sizeof(__kernel_long_t)) ? \ + XFS_IOC_FSBULKSTAT_OLD : XFS_IOC_FSBULKSTAT_NEW) +/* XFS_IOC_GETFSUUID ---------- deprecated 140 */
fs/xfs/xfs_ioctl.c +189 -6
244 lines not on this page · raw message
fs/xfs/xfs_ioctl.h +12 -0
@@ -83,6 +83,18 @@ struct xfs_inogrp;int xfs_fsbulkstat_one_fmt (struct xfs_ibulk *breq,const struct xfs_bulkstat *bstat); +int xfs_fsbulkstat_time32_one_fmt (struct xfs_ibulk *breq, +const struct xfs_bulkstat *bstat);int xfs_fsinumbers_fmt (struct xfs_ibulk *breq,const struct xfs_inumbers *igrp); +/* +* On intel, even if sizes match, alignment and/or padding may differ. +*/ +#if defined(CONFIG_IA64 ) || defined(CONFIG_X86_64 ) +#define BROKEN_X86_ALIGNMENT +#define __compat_packed __attribute__((packed)) +#else +#define __compat_packed +#endif +#endif
fs/xfs/xfs_ioctl32.c +49 -33
156 lines not on this page · raw message
fs/xfs/xfs_ioctl32.h +12 -14
@@ -21,20 +21,11 @@#define XFS_IOC_SETXFLAGS_32 FS_IOC32_SETFLAGS#define XFS_IOC_GETVERSION_32 FS_IOC32_GETVERSION -/* -* On intel, even if sizes match, alignment and/or padding may differ. -*/ -#if defined(CONFIG_IA64 ) || defined(CONFIG_X86_64 ) -#define BROKEN_X86_ALIGNMENT -#define __compat_packed __attribute__((packed)) -#else -#define __compat_packed -#endif - +#ifdef BROKEN_X86_ALIGNMENT typedef struct compat_xfs_bstime { -compat_time_t tv_sec;/* seconds */ + __s64 tv_sec; /* seconds */ __s32 tv_nsec; /* and nanoseconds */ -}compat_xfs_bstime_t ; +} __compat_packed compat_xfs_bstime_t; struct compat_xfs_bstat { __u64 bs_ino; /* inode number */
@@ -62,6 +53,7 @@ struct compat_xfs_bstat {__u16 bs_dmstate;/* DMIG state info */ __u16 bs_aextents;/* attribute number of extents */ } __compat_packed; +#endif struct compat_xfs_fsop_bulkreq {compat_uptr_t lastip;/* last inode # pointer */
@@ -70,10 +62,14 @@ struct compat_xfs_fsop_bulkreq {compat_uptr_t ocount;/* output count pointer */ }; -#define XFS_IOC_FSBULKSTAT_32 \ +#define XFS_IOC_FSBULKSTAT_OLD32 \ _IOWR('X', 101, struct compat_xfs_fsop_bulkreq) -#define XFS_IOC_FSBULKSTAT_SINGLE_32 \ +#define XFS_IOC_FSBULKSTAT_SINGLE_OLD32 \ _IOWR('X', 102, struct compat_xfs_fsop_bulkreq) +#define XFS_IOC_FSBULKSTAT_NEW32 \ + _IOWR('X', 129, struct compat_xfs_fsop_bulkreq) +#define XFS_IOC_FSBULKSTAT_SINGLE_NEW32 \ + _IOWR('X', 130, struct compat_xfs_fsop_bulkreq)#define XFS_IOC_FSINUMBERS_32 \ _IOWR('X', 103, struct compat_xfs_fsop_bulkreq)
@@ -98,6 +94,7 @@ typedef struct compat_xfs_fsop_handlereq {#define XFS_IOC_READLINK_BY_HANDLE_32 \ _IOWR('X', 108, struct compat_xfs_fsop_handlereq) +#ifdef BROKEN_X86_ALIGNMENT /* The bstat field in the swapext struct needs translation */ typedef struct compat_xfs_swapext { int64_t sx_version; /* version */
@@ -110,6 +107,7 @@ typedef struct compat_xfs_swapext { } __compat_packed compat_xfs_swapext_t;#define XFS_IOC_SWAPEXT_32 _IOWR('X', 109, struct compat_xfs_swapext) +#endif typedef struct compat_xfs_fsop_attrlist_handlereq { struct compat_xfs_fsop_handlereq hreq; /* handle interface structure */
Signature · 1 line
2.20.0
RFC 3/5 xfs: [variant C] avoid i386-misaligned xfs_bstat
In reply to Arnd BergmannThe change to the ioctl commands requires updating the header file. If we do that, the alignment problem on i386 could be solved for the new format by explictly aligning all 64-bit members to time_t. This complicates the header file definition, but saves the code to deal with a third format.
The native ioctl simply deals with both the time32 and the time64 version, and the latter is the same across all 64-bit architectures and all 32-bit user space with 32-bit time_t including i386 and x32.
If we decide to do this, this change should be folded into "xfs: [variant B] add time64 version of xfs_bstat".
--- fs/xfs/libxfs/xfs_fs.h | 20 +++++-- fs/xfs/xfs_ioctl32.c | 120 +---------------------------------------- 2 files changed, 18 insertions(+), 122 deletions(-)
fs/xfs/libxfs/xfs_fs.h +16 -4
@@ -319,6 +319,17 @@ typedef struct xfs_growfs_rt {__u32 extsize;/* new realtime extent size, fsblocks */ } xfs_growfs_rt_t; +/* +* on i386, u64 has 32-bit alignment, which makes the traditional xfs_bstat +* different from other architectures. Aligning all 64-bit members to +* sizeof(time_t) means that the new version with 64-bit time_t is padded +* the same as on all other architectures. +*/ +#ifdef __i386__ +#define __TIME_ALIGN __attribute__((aligned(sizeof(time_t)))) +#else +#define __TIME_ALIGN +#endif /* * Structures returned from ioctl XFS_IOC_FSBULKSTAT & XFS_IOC_FSBULKSTAT_SINGLE
@@ -328,24 +339,24 @@ typedef struct xfs_bstime {__s64 tv_sec;/* seconds */ __s32 tv_nsec;/* and nanoseconds */ #else -time_t tv_sec;/* seconds */ + time_t tv_sec __TIME_ALIGN; /* seconds */__s32 tv_nsec;/* and nanoseconds */ #endif } xfs_bstime_t;struct xfs_bstat { -__u64 bs_ino;/* inode number */ + __u64 bs_ino __TIME_ALIGN; /* inode number */__u16 bs_mode;/* type and mode */ __u16 bs_nlink;/* number of links */ __u32 bs_uid;/* user id */ __u32 bs_gid;/* group id */ __u32 bs_rdev;/* device value */ __s32 bs_blksize;/* block size */ -__s64 bs_size;/* file size */ + __s64 bs_size __TIME_ALIGN; /* file size */xfs_bstime_t bs_atime;/* access time */ xfs_bstime_t bs_mtime;/* modify time */ xfs_bstime_t bs_ctime;/* inode change time */ -int64_t bs_blocks;/* number of blocks */ + int64_t bs_blocks __TIME_ALIGN; /* number of blocks */__u32 bs_xflags;/* extended flags */ __s32 bs_extsize;/* extent size */ __s32 bs_extents;/* number of extents */
@@ -362,6 +373,7 @@ struct xfs_bstat {__u16 bs_dmstate;/* DMIG state info */ __u16 bs_aextents;/* attribute number of extents */ }; +#undef __TIME_ALIGN/* New bulkstat structure that reports v5 features and fixes padding issues */ struct xfs_bulkstat {
fs/xfs/xfs_ioctl32.c +2 -118
148 lines not on this page · raw message
Signature · 1 line
2.20.0
RFC 4/5 xfs: extend inode format for 40-bit timestamps
In reply to Arnd BergmannXFS is the only major file system that lacks timestamps beyond year 2038, and is already being deployed in systems that may have to be supported beyond that time.
Fortunately, the inode format still has a few reserved bits that can be used to extend the current format. There are two bits in the nanosecond portion that could be used in the same way that ext4 does, extending the timestamps until year 2378, as well as 12 unused bytes after the already allocated fields.
There are four timestamps that need to be extended, so using four bytes out of the reserved space gets us all the way until year 36676, by extending the current 1902-2036 with another 255 epochs, which seems to be a reasonable range.
I am not sure whether this change to the inode format requires a new version for the inode. All existing file system images remain compatible, while mounting a file systems with extended timestamps beyond 2038 would report that timestamp incorrectly in the 1902 through 2038 range, matching the traditional Linux behavior of wrapping timestamps.
--- fs/xfs/libxfs/xfs_format.h | 6 +++++- fs/xfs/libxfs/xfs_inode_buf.c | 28 ++++++++++++++++++++-------- fs/xfs/libxfs/xfs_inode_buf.h | 1 + fs/xfs/libxfs/xfs_log_format.h | 6 +++++- fs/xfs/libxfs/xfs_trans_inode.c | 3 ++- fs/xfs/xfs_inode.c | 3 ++- fs/xfs/xfs_inode_item.c | 10 +++++++--- fs/xfs/xfs_iops.c | 3 ++- fs/xfs/xfs_itable.c | 2 +- fs/xfs/xfs_super.c | 2 +- 10 files changed, 46 insertions(+), 18 deletions(-)
fs/xfs/libxfs/xfs_format.h +5 -1
@@ -883,7 +883,11 @@ typedef struct xfs_dinode {__be64 di_lsn;/* flush sequence */ __be64 di_flags2;/* more random flags */ __be32 di_cowextsize;/* basic cow extent size for file */ -__u8 di_pad2[12 ];/* more padding for future expansion */ +__u8 di_atime_hi;/* upper 8 bits of di_atime */ +__u8 di_mtime_hi;/* upper 8 bits of di_mtime */ +__u8 di_ctime_hi;/* upper 8 bits of di_ctime */ +__u8 di_crtime_hi;/* upper 8 bits of di_crtime */ +__u8 di_pad2[8 ];/* more padding for future expansion */ /* fields only written to during inode creation */ xfs_timestamp_t di_crtime;/* time created */
fs/xfs/libxfs/xfs_inode_buf.c +20 -8
@@ -228,16 +228,19 @@ xfs_inode_from_disk( to->di_flushiter =be16_to_cpu (from->di_flushiter);/* -* Time is signed, so need to convert to signed 32 bit before -* storing in inode timestamp which may be 64 bit. Otherwise -* a time before epoch is converted to a time long after epoch -* on 64 bit systems. +* The supported time range starts at INT_MIN, corresponding to +* year 1902. With the traditional low 32 bits, this ends in +* year 2038, the extra 8 bits extend it by another 255 epochs +* of 136.1 years each, up to year 36744. */ - inode->i_atime.tv_sec = (int )be32_to_cpu (from->di_atime.t_sec); + inode->i_atime.tv_sec =be32_to_cpu (from->di_atime.t_sec) + + ((u64 )from->di_atime_hi <<32 ); inode->i_atime.tv_nsec = (int )be32_to_cpu (from->di_atime.t_nsec); - inode->i_mtime.tv_sec = (int )be32_to_cpu (from->di_mtime.t_sec); + inode->i_mtime.tv_sec = (int )be32_to_cpu (from->di_mtime.t_sec) + + ((u64 )from->di_mtime_hi <<32 ); inode->i_mtime.tv_nsec = (int )be32_to_cpu (from->di_mtime.t_nsec); - inode->i_ctime.tv_sec = (int )be32_to_cpu (from->di_ctime.t_sec); + inode->i_ctime.tv_sec = (int )be32_to_cpu (from->di_ctime.t_sec) + + ((u64 )from->di_ctime_hi <<32 ); inode->i_ctime.tv_nsec = (int )be32_to_cpu (from->di_ctime.t_nsec); inode->i_generation =be32_to_cpu (from->di_gen); inode->i_mode =be16_to_cpu (from->di_mode);
@@ -256,7 +259,8 @@ xfs_inode_from_disk(if (to->di_version ==3 ) {inode_set_iversion_queried (inode,be64_to_cpu (from->di_changecount)); - to->di_crtime.t_sec =be32_to_cpu (from->di_crtime.t_sec); + to->di_crtime.t_sec =be32_to_cpu (from->di_crtime.t_sec) + + ((u64 )from->di_crtime_hi <<32 ); to->di_crtime.t_nsec =be32_to_cpu (from->di_crtime.t_nsec); to->di_flags2 =be64_to_cpu (from->di_flags2); to->di_cowextsize =be32_to_cpu (from->di_cowextsize);
@@ -284,10 +288,13 @@ xfs_inode_to_disk(memset (to->di_pad,0 ,sizeof (to->di_pad)); to->di_atime.t_sec =cpu_to_be32 (inode->i_atime.tv_sec); + to->di_atime_hi =upper_32_bits (inode->i_atime.tv_sec); to->di_atime.t_nsec =cpu_to_be32 (inode->i_atime.tv_nsec); to->di_mtime.t_sec =cpu_to_be32 (inode->i_mtime.tv_sec); + to->di_mtime_hi =upper_32_bits (inode->i_mtime.tv_sec); to->di_mtime.t_nsec =cpu_to_be32 (inode->i_mtime.tv_nsec); to->di_ctime.t_sec =cpu_to_be32 (inode->i_ctime.tv_sec); + to->di_ctime_hi =upper_32_bits (inode->i_ctime.tv_sec); to->di_ctime.t_nsec =cpu_to_be32 (inode->i_ctime.tv_nsec); to->di_nlink =cpu_to_be32 (inode->i_nlink); to->di_gen =cpu_to_be32 (inode->i_generation);
@@ -307,6 +314,7 @@ xfs_inode_to_disk(if (from->di_version ==3 ) { to->di_changecount =cpu_to_be64 (inode_peek_iversion (inode)); to->di_crtime.t_sec =cpu_to_be32 (from->di_crtime.t_sec); + to->di_crtime_hi =upper_32_bits (from->di_crtime.t_sec); to->di_crtime.t_nsec =cpu_to_be32 (from->di_crtime.t_nsec); to->di_flags2 =cpu_to_be64 (from->di_flags2); to->di_cowextsize =cpu_to_be32 (from->di_cowextsize);
@@ -338,10 +346,13 @@ xfs_log_dinode_to_disk(memcpy (to->di_pad, from->di_pad,sizeof (to->di_pad)); to->di_atime.t_sec =cpu_to_be32 (from->di_atime.t_sec); + to->di_atime_hi = from->di_atime_hi; to->di_atime.t_nsec =cpu_to_be32 (from->di_atime.t_nsec); to->di_mtime.t_sec =cpu_to_be32 (from->di_mtime.t_sec); + to->di_mtime_hi = from->di_mtime_hi; to->di_mtime.t_nsec =cpu_to_be32 (from->di_mtime.t_nsec); to->di_ctime.t_sec =cpu_to_be32 (from->di_ctime.t_sec); + to->di_ctime_hi = from->di_ctime_hi; to->di_ctime.t_nsec =cpu_to_be32 (from->di_ctime.t_nsec); to->di_size =cpu_to_be64 (from->di_size);
@@ -359,6 +370,7 @@ xfs_log_dinode_to_disk(if (from->di_version ==3 ) { to->di_changecount =cpu_to_be64 (from->di_changecount); to->di_crtime.t_sec =cpu_to_be32 (from->di_crtime.t_sec); + to->di_crtime_hi = from->di_crtime_hi; to->di_crtime.t_nsec =cpu_to_be32 (from->di_crtime.t_nsec); to->di_flags2 =cpu_to_be64 (from->di_flags2); to->di_cowextsize =cpu_to_be32 (from->di_cowextsize);
fs/xfs/libxfs/xfs_inode_buf.h +1 -0
@@ -38,6 +38,7 @@ struct xfs_icdinode {uint32_t di_cowextsize;/* basic cow extent size for file */ xfs_ictimestamp_t di_crtime;/* time created */ +uint8_t di_crtime_hi;/* upper 8 bites of di_crtime */ };/*
fs/xfs/libxfs/xfs_log_format.h +5 -1
@@ -414,7 +414,11 @@ struct xfs_log_dinode {xfs_lsn_t di_lsn;/* flush sequence */ uint64_t di_flags2;/* more random flags */ uint32_t di_cowextsize;/* basic cow extent size for file */ -uint8_t di_pad2[12 ];/* more padding for future expansion */ +uint8_t di_atime_hi;/* upper 8 bits of di_atime */ +uint8_t di_mtime_hi;/* upper 8 bits of di_mtime */ +uint8_t di_ctime_hi;/* upper 8 bits of di_ctime */ +uint8_t di_crtime_hi;/* upper 8 bits of di_crtime */ +uint8_t di_pad2[8 ];/* more padding for future expansion */ /* fields only written to during inode creation */ xfs_ictimestamp_t di_crtime;/* time created */
fs/xfs/libxfs/xfs_trans_inode.c +2 -1
@@ -67,7 +67,8 @@ xfs_trans_ichgtime(if (flags &XFS_ICHGTIME_CHG ) inode->i_ctime = tv;if (flags &XFS_ICHGTIME_CREATE ) { - ip->i_d.di_crtime.t_sec = (int32_t )tv.tv_sec; + ip->i_d.di_crtime.t_sec =lower_32_bits (tv.tv_sec); + ip->i_d.di_crtime_hi =upper_32_bits (tv.tv_sec); ip->i_d.di_crtime.t_nsec = (int32_t )tv.tv_nsec; } }
fs/xfs/xfs_inode.c +2 -1
@@ -845,7 +845,8 @@ xfs_ialloc(inode_set_iversion (inode,1 ); ip->i_d.di_flags2 =0 ; ip->i_d.di_cowextsize =0 ; - ip->i_d.di_crtime.t_sec = (int32_t )tv.tv_sec; + ip->i_d.di_crtime.t_sec =lower_32_bits (tv.tv_sec); + ip->i_d.di_crtime_hi =upper_32_bits (tv.tv_sec); ip->i_d.di_crtime.t_nsec = (int32_t )tv.tv_nsec; }
fs/xfs/xfs_inode_item.c +7 -3
@@ -314,11 +314,14 @@ xfs_inode_to_log_dinode(memset (to->di_pad,0 ,sizeof (to->di_pad));memset (to->di_pad3,0 ,sizeof (to->di_pad3)); - to->di_atime.t_sec = inode->i_atime.tv_sec; + to->di_atime.t_sec =lower_32_bits (inode->i_atime.tv_sec); + to->di_atime_hi =upper_32_bits (inode->i_atime.tv_sec); to->di_atime.t_nsec = inode->i_atime.tv_nsec; - to->di_mtime.t_sec = inode->i_mtime.tv_sec; + to->di_mtime.t_sec =lower_32_bits (inode->i_mtime.tv_sec); + to->di_mtime_hi =upper_32_bits (inode->i_mtime.tv_sec); to->di_mtime.t_nsec = inode->i_mtime.tv_nsec; - to->di_ctime.t_sec = inode->i_ctime.tv_sec; + to->di_ctime.t_sec =lower_32_bits (inode->i_ctime.tv_sec); + to->di_ctime_hi =upper_32_bits (inode->i_ctime.tv_sec); to->di_ctime.t_nsec = inode->i_ctime.tv_nsec; to->di_nlink = inode->i_nlink; to->di_gen = inode->i_generation;
@@ -341,6 +344,7 @@ xfs_inode_to_log_dinode(if (from->di_version ==3 ) { to->di_changecount =inode_peek_iversion (inode); to->di_crtime.t_sec = from->di_crtime.t_sec; + to->di_crtime_hi = from->di_crtime_hi; to->di_crtime.t_nsec = from->di_crtime.t_nsec; to->di_flags2 = from->di_flags2; to->di_cowextsize = from->di_cowextsize;
fs/xfs/xfs_iops.c +2 -1
@@ -516,7 +516,8 @@ xfs_vn_getattr(if (ip->i_d.di_version ==3 ) {if (request_mask &STATX_BTIME ) { stat->result_mask |=STATX_BTIME ; - stat->btime.tv_sec = ip->i_d.di_crtime.t_sec; + stat->btime.tv_sec = ip->i_d.di_crtime.t_sec + + ((u64 )ip->i_d.di_crtime_hi <<32 ); stat->btime.tv_nsec = ip->i_d.di_crtime.t_nsec; } }
fs/xfs/xfs_itable.c +1 -1
@@ -97,7 +97,7 @@ xfs_bulkstat_one_int( buf->bs_mtime_nsec = inode->i_mtime.tv_nsec; buf->bs_ctime = inode->i_ctime.tv_sec; buf->bs_ctime_nsec = inode->i_ctime.tv_nsec; - buf->bs_btime = dic->di_crtime.t_sec; + buf->bs_btime = dic->di_crtime.t_sec + ((u64 )dic->di_crtime_hi <<32 ); buf->bs_btime_nsec = dic->di_crtime.t_nsec; buf->bs_gen = inode->i_generation; buf->bs_mode = inode->i_mode;
fs/xfs/xfs_super.c +1 -1
@@ -1665,7 +1665,7 @@ xfs_fs_fill_super( sb->s_max_links =XFS_MAXLINK ; sb->s_time_gran =1 ; sb->s_time_min =S32_MIN ; - sb->s_time_max =S32_MAX ; + sb->s_time_max =S32_MAX +255 *0x100000000ull ; sb->s_iflags |=SB_I_CGROUPWB ;set_posix_acl_flag (sb);
Signature · 1 line
2.20.0
Re: [RFC 4/5] xfs: extend inode format for 40-bit timestamps
Amir just send another patch dealing with the time stamps. I'd suggest you chime into the discussion in that thread.
Re: [RFC 4/5] xfs: extend inode format for 40-bit timestamps
Quoted 3 lines · Christoph Hellwig
Amir just send another patch dealing with the time stamps. I'd suggest you chime into the discussion in that thread.
That's right I just posted the ext4 style extend to 34bits yesterday [1], but I like your version so much better, so I will withdraw mine.
Sorry I did not CC you nor Deepa nor y2038 list.
I did not think you were going to actually deal with specific filesystems.
I'd also like to hear people's thoughts about migration process. Should the new feature be ro_compat as I defined it or incompat?
If all agree that Arnd's format change is preferred, I can assist with xfsprogs patches, tests or whatnot.
Thanks,
Amir.
[1] https://lore.kernel.org/linux-xfs/[email protected]/T/#mfa11ea3c035d4c21ec6a56b7c83a6dfa76e48068
Re: [Y2038] [RFC 4/5] xfs: extend inode format for 40-bit timestamps
Quoted 8 lines · Amir Goldstein
Quoted 3 lines · Christoph Hellwig
Amir just send another patch dealing with the time stamps. I'd suggest you chime into the discussion in that thread.
That's right I just posted the ext4 style extend to 34bits yesterday [1], but I like your version so much better, so I will withdraw mine.
Thanks! I guess we probably want part of both in the end. I considered adding wrappers for encoding and decoding the timestamp like yours but in the end went with open-coding that part. The difference is pretty minimal, should we leave it with the open-coded addition?
One part that I was missing (as described in my changelog) is any versioning or feature flag, including the dynamically set sb->s_time_max value. From looking at your patch, I guess this is something we want.
Quoted 2 lines
Sorry I did not CC you nor Deepa nor y2038 list.
I did not think you were going to actually deal with specific filesystems.
I was not going to, but in the process of cleaning up the remaining ioctls I came to xfs last week and thought it would be silly to extend the uapi but not the file system ;-)
Quoted 5 lines
I'd also like to hear people's thoughts about migration process. Should the new feature be
ro_compatas I defined it or incompat?If all agree that Arnd's format change is preferred, I can assist with xfsprogs patches, tests or whatnot.
Awesome, that would be great indeed!
Arnd
Re: [RFC 4/5] xfs: extend inode format for 40-bit timestamps
In reply to Arnd BergmannQuoted 15 lines · Arnd Bergmann
XFS is the only major file system that lacks timestamps beyond year 2038, and is already being deployed in systems that may have to be supported beyond that time.
Fortunately, the inode format still has a few reserved bits that can be used to extend the current format. There are two bits in the nanosecond portion that could be used in the same way that ext4 does, extending the timestamps until year 2378, as well as 12 unused bytes after the already allocated fields.
There are four timestamps that need to be extended, so using four bytes out of the reserved space gets us all the way until year 36676, by extending the current 1902-2036 with another 255 epochs, which seems to be a reasonable range.
Quoted 8 lines
I am not sure whether this change to the inode format requires a new version for the inode. All existing file system images remain compatible, while mounting a file systems with extended timestamps beyond 2038 would report that timestamp incorrectly in the 1902 through 2038 range, matching the traditional Linux behavior of wrapping timestamps.
Signed-off-by Arnd Bergmann <[email protected]>
This is basically what I proposed ~5 years or so ago and posted a patch to implement it in an early y2038 discussion with you. I jsut mentioned that very patch in my reposnse to Amir's timestamp extension patchset, pointing out that this isn't the way we want to proceed with >y2038 on-disk support.
https://lore.kernel.org/linux-xfs/[email protected]/T/#maf6b2719ed561cc2865cc5e7eb82df206b971261
I'd suggest taking the discussion there....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
RFC 5/5 xfs: use 40-bit quota time limits
In reply to Arnd BergmannThe quota handling in xfs is based around an in-memory representation of time_t, which overflows in year 2038 on 32-bit architectures, and an on-disk representation of __be32, which overflows in year 2106 based on interpreting the values as unsigned.
Extend both to allow for much longer times: the in-memory representation should just use time64_t and the on-disk representation has to live with the spare bits in struct xfs_disk_dquot. As there is an unused 32-bit field, and three time limits in it, allocating 8 bits per timeout seems appropriate.
Note: the quotactl() syscall is not affected by this, it has its own struct fs_disk_quota that may need a similar conversion.
--- fs/xfs/libxfs/xfs_dquot_buf.c | 6 +++--- fs/xfs/libxfs/xfs_format.h | 5 ++++- fs/xfs/xfs_dquot.c | 29 ++++++++++++++++++++--------- fs/xfs/xfs_qm.c | 18 ++++++++++++------ fs/xfs/xfs_qm.h | 6 +++--- fs/xfs/xfs_qm_syscalls.c | 16 +++++++++++----- fs/xfs/xfs_quotaops.c | 6 +++--- fs/xfs/xfs_trans_dquot.c | 17 +++++++++++------ 8 files changed, 67 insertions(+), 36 deletions(-)
fs/xfs/libxfs/xfs_dquot_buf.c +3 -3
@@ -75,17 +75,17 @@ xfs_dquot_verify(if (ddq->d_blk_softlimit &&be64_to_cpu (ddq->d_bcount) >be64_to_cpu (ddq->d_blk_softlimit) && - !ddq->d_btimer) + !ddq->d_btimer && !ddq->d_btimer_high)return __this_address;if (ddq->d_ino_softlimit &&be64_to_cpu (ddq->d_icount) >be64_to_cpu (ddq->d_ino_softlimit) && - !ddq->d_itimer) + !ddq->d_itimer && !ddq->d_itimer_high)return __this_address;if (ddq->d_rtb_softlimit &&be64_to_cpu (ddq->d_rtbcount) >be64_to_cpu (ddq->d_rtb_softlimit) && - !ddq->d_rtbtimer) + !ddq->d_rtbtimer && !ddq->d_rtbtimer_high)return __this_address;return NULL ;
fs/xfs/libxfs/xfs_format.h +4 -1
@@ -1168,7 +1168,10 @@ typedef struct xfs_disk_dquot {__be32 d_btimer;/* similar to above; for disk blocks */ __be16 d_iwarns;/* warnings issued wrt num inodes */ __be16 d_bwarns;/* warnings issued wrt disk blocks */ -__be32 d_pad0;/* 64 bit align */ +__u8 d_itimer_high;/* upper bits of d_itimer */ +__u8 d_btimer_high;/* upper bits of d_btimer */ +__u8 d_rtbtimer_high;/* upper bits of d_rtbtimer */ +__u8 d_pad0;/* 64 bit align */ __be64 d_rtb_hardlimit;/* absolute limit on realtime blks */ __be64 d_rtb_softlimit;/* preferred limit on RT disk blks */ __be64 d_rtbcount;/* realtime blocks owned */
fs/xfs/xfs_dquot.c +20 -9
@@ -116,6 +116,8 @@ xfs_qm_adjust_dqtimers( xfs_mount_t *mp, xfs_disk_dquot_t *d) { +time64_t timer; +ASSERT (d->d_id);#ifdef DEBUG
@@ -130,15 +132,17 @@ xfs_qm_adjust_dqtimers( be64_to_cpu(d->d_rtb_hardlimit));#endif -if (!d->d_btimer) { +if (!d->d_btimer && !d->d_btimer_high) {if ((d->d_blk_softlimit && (be64_to_cpu (d->d_bcount) >be64_to_cpu (d->d_blk_softlimit))) || (d->d_blk_hardlimit && (be64_to_cpu (d->d_bcount) >be64_to_cpu (d->d_blk_hardlimit)))) { - d->d_btimer =cpu_to_be32 (get_seconds () + - mp->m_quotainfo->qi_btimelimit); + timer =ktime_get_real_seconds () + + mp->m_quotainfo->qi_btimelimit; + d->d_btimer =cpu_to_be32 (lower_32_bits (timer)); + d->d_btimer_high = (u8 )upper_32_bits (timer); }else { d->d_bwarns =0 ; }
@@ -150,18 +154,21 @@ xfs_qm_adjust_dqtimers( (be64_to_cpu(d->d_bcount) <= be64_to_cpu(d->d_blk_hardlimit)))) { d->d_btimer =0 ; + d->d_btimer_high =0 ; } } -if (!d->d_itimer) { +if (!d->d_itimer && !d->d_itimer_high) {if ((d->d_ino_softlimit && (be64_to_cpu (d->d_icount) >be64_to_cpu (d->d_ino_softlimit))) || (d->d_ino_hardlimit && (be64_to_cpu (d->d_icount) >be64_to_cpu (d->d_ino_hardlimit)))) { - d->d_itimer =cpu_to_be32 (get_seconds () + - mp->m_quotainfo->qi_itimelimit); + timer =ktime_get_real_seconds () + + mp->m_quotainfo->qi_itimelimit; + d->d_itimer =cpu_to_be32 (lower_32_bits (timer)); + d->d_itimer_high = (u8 )upper_32_bits (timer); }else { d->d_iwarns =0 ; }
@@ -173,18 +180,21 @@ xfs_qm_adjust_dqtimers( (be64_to_cpu(d->d_icount) <= be64_to_cpu(d->d_ino_hardlimit)))) { d->d_itimer =0 ; + d->d_itimer_high =0 ; } } -if (!d->d_rtbtimer) { +if (!d->d_rtbtimer && !d->d_rtbtimer_high) {if ((d->d_rtb_softlimit && (be64_to_cpu (d->d_rtbcount) >be64_to_cpu (d->d_rtb_softlimit))) || (d->d_rtb_hardlimit && (be64_to_cpu (d->d_rtbcount) >be64_to_cpu (d->d_rtb_hardlimit)))) { - d->d_rtbtimer =cpu_to_be32 (get_seconds () + - mp->m_quotainfo->qi_rtbtimelimit); + timer =ktime_get_real_seconds () + + mp->m_quotainfo->qi_rtbtimelimit; + d->d_rtbtimer =cpu_to_be32 (lower_32_bits (timer)); + d->d_rtbtimer_high = (u8 )upper_32_bits (timer); }else { d->d_rtbwarns =0 ; }
@@ -196,6 +206,7 @@ xfs_qm_adjust_dqtimers( (be64_to_cpu(d->d_rtbcount) <= be64_to_cpu(d->d_rtb_hardlimit)))) { d->d_rtbtimer =0 ; + d->d_rtbtimer_high =0 ; } } }
fs/xfs/xfs_qm.c +12 -6
@@ -613,12 +613,15 @@ xfs_qm_init_timelimits(* a user or group before he or she can not perform any * more writing. If it is zero, a default is used. */ -if (ddqp->d_btimer) - qinf->qi_btimelimit =be32_to_cpu (ddqp->d_btimer); -if (ddqp->d_itimer) - qinf->qi_itimelimit =be32_to_cpu (ddqp->d_itimer); -if (ddqp->d_rtbtimer) - qinf->qi_rtbtimelimit =be32_to_cpu (ddqp->d_rtbtimer); +if (ddqp->d_btimer || ddqp->d_btimer_high) + qinf->qi_btimelimit =be32_to_cpu (ddqp->d_btimer) + + ((u64 )ddqp->d_btimer_high <<32 ); +if (ddqp->d_itimer || ddqp->d_itimer_high) + qinf->qi_itimelimit =be32_to_cpu (ddqp->d_itimer) + + ((u64 )ddqp->d_itimer_high <<32 ); +if (ddqp->d_rtbtimer || ddqp->d_rtbtimer_high) + qinf->qi_rtbtimelimit =be32_to_cpu (ddqp->d_rtbtimer) + + ((u64 )ddqp->d_rtbtimer_high <<32 );if (ddqp->d_bwarns) qinf->qi_bwarnlimit =be16_to_cpu (ddqp->d_bwarns);if (ddqp->d_iwarns)
@@ -867,8 +870,11 @@ xfs_qm_reset_dqcounts( ddq->d_icount =0 ; ddq->d_rtbcount =0 ; ddq->d_btimer =0 ; + ddq->d_btimer_high =0 ; ddq->d_itimer =0 ; + ddq->d_itimer_high =0 ; ddq->d_rtbtimer =0 ; + ddq->d_rtbtimer_high =0 ; ddq->d_bwarns =0 ; ddq->d_iwarns =0 ; ddq->d_rtbwarns =0 ;
fs/xfs/xfs_qm.h +3 -3
@@ -64,9 +64,9 @@ typedef struct xfs_quotainfo {struct xfs_inode *qi_pquotaip;/* project quota inode */ struct list_lru qi_lru;int qi_dquots; -time_t qi_btimelimit;/* limit for blks timer */ -time_t qi_itimelimit;/* limit for inodes timer */ -time_t qi_rtbtimelimit;/* limit for rt blks timer */ +time64_t qi_btimelimit;/* limit for blks timer */ +time64_t qi_itimelimit;/* limit for inodes timer */ +time64_t qi_rtbtimelimit;/* limit for rt blks timer */ xfs_qwarncnt_t qi_bwarnlimit;/* limit for blks warnings */ xfs_qwarncnt_t qi_iwarnlimit;/* limit for inodes warnings */ xfs_qwarncnt_t qi_rtbwarnlimit;/* limit for rt blks warnings */
fs/xfs/xfs_qm_syscalls.c +11 -5
@@ -500,15 +500,18 @@ xfs_qm_scall_setqlim(*/ if (newlim->d_fieldmask &QC_SPC_TIMER ) { q->qi_btimelimit = newlim->d_spc_timer; - ddq->d_btimer =cpu_to_be32 (newlim->d_spc_timer); + ddq->d_btimer =cpu_to_be32 (lower_32_bits (newlim->d_spc_timer)); + ddq->d_btimer_high = (u8 )upper_32_bits (newlim->d_spc_timer); }if (newlim->d_fieldmask &QC_INO_TIMER ) { q->qi_itimelimit = newlim->d_ino_timer; - ddq->d_itimer =cpu_to_be32 (newlim->d_ino_timer); + ddq->d_itimer =cpu_to_be32 (lower_32_bits (newlim->d_ino_timer)); + ddq->d_itimer_high = (u8 )upper_32_bits (newlim->d_ino_timer); }if (newlim->d_fieldmask &QC_RT_SPC_TIMER ) { q->qi_rtbtimelimit = newlim->d_rt_spc_timer; ddq->d_rtbtimer =cpu_to_be32 (newlim->d_rt_spc_timer); + ddq->d_rtbtimer_high = (u8 )upper_32_bits (newlim->d_rt_spc_timer); }if (newlim->d_fieldmask &QC_SPC_WARNS ) q->qi_bwarnlimit = newlim->d_spc_warns;
@@ -623,8 +626,10 @@ xfs_qm_scall_getquota_fill_qc( dst->d_ino_softlimit =be64_to_cpu (dqp->q_core.d_ino_softlimit); dst->d_space =XFS_FSB_TO_B (mp, dqp->q_res_bcount); dst->d_ino_count = dqp->q_res_icount; - dst->d_spc_timer =be32_to_cpu (dqp->q_core.d_btimer); - dst->d_ino_timer =be32_to_cpu (dqp->q_core.d_itimer); + dst->d_spc_timer =be32_to_cpu (dqp->q_core.d_btimer) + + ((u64 )dqp->q_core.d_btimer_high <<32 ); + dst->d_ino_timer =be32_to_cpu (dqp->q_core.d_itimer) + + ((u64 )dqp->q_core.d_itimer_high <<32 ); dst->d_ino_warns =be16_to_cpu (dqp->q_core.d_iwarns); dst->d_spc_warns =be16_to_cpu (dqp->q_core.d_bwarns); dst->d_rt_spc_hardlimit =
@@ -632,7 +637,8 @@ xfs_qm_scall_getquota_fill_qc( dst->d_rt_spc_softlimit =XFS_FSB_TO_B (mp,be64_to_cpu (dqp->q_core.d_rtb_softlimit)); dst->d_rt_space =XFS_FSB_TO_B (mp, dqp->q_res_rtbcount); - dst->d_rt_spc_timer =be32_to_cpu (dqp->q_core.d_rtbtimer); + dst->d_rt_spc_timer =be32_to_cpu (dqp->q_core.d_rtbtimer) + + ((u64 )dqp->q_core.d_rtbtimer_high <<32 ); dst->d_rt_spc_warns =be16_to_cpu (dqp->q_core.d_rtbwarns);/*
fs/xfs/xfs_quotaops.c +3 -3
@@ -37,9 +37,9 @@ xfs_qm_fill_state( tstate->flags |=QCI_SYSFILE ; tstate->blocks = ip->i_d.di_nblocks; tstate->nextents = ip->i_d.di_nextents; - tstate->spc_timelimit = q->qi_btimelimit; - tstate->ino_timelimit = q->qi_itimelimit; - tstate->rt_spc_timelimit = q->qi_rtbtimelimit; + tstate->spc_timelimit = (u32 )q->qi_btimelimit; + tstate->ino_timelimit = (u32 )q->qi_itimelimit; + tstate->rt_spc_timelimit = (u32 )q->qi_rtbtimelimit; tstate->spc_warnlimit = q->qi_bwarnlimit; tstate->ino_warnlimit = q->qi_iwarnlimit; tstate->rt_spc_warnlimit = q->qi_rtbwarnlimit;
fs/xfs/xfs_trans_dquot.c +11 -6
@@ -580,7 +580,7 @@ xfs_trans_dqresv( {xfs_qcnt_t hardlimit;xfs_qcnt_t softlimit; -time_t timer; +time64_t timer;xfs_qwarncnt_t warns;xfs_qwarncnt_t warnlimit;xfs_qcnt_t total_count;
@@ -600,7 +600,8 @@ xfs_trans_dqresv( softlimit =be64_to_cpu (dqp->q_core.d_blk_softlimit);if (!softlimit) softlimit = defq->bsoftlimit; - timer =be32_to_cpu (dqp->q_core.d_btimer); + timer =be32_to_cpu (dqp->q_core.d_btimer) + + ((u64 )dqp->q_core.d_btimer_high <<32 ); warns =be16_to_cpu (dqp->q_core.d_bwarns); warnlimit = dqp->q_mount->m_quotainfo->qi_bwarnlimit; resbcountp = &dqp->q_res_bcount;
@@ -612,7 +613,8 @@ xfs_trans_dqresv( softlimit =be64_to_cpu (dqp->q_core.d_rtb_softlimit);if (!softlimit) softlimit = defq->rtbsoftlimit; - timer =be32_to_cpu (dqp->q_core.d_rtbtimer); + timer =be32_to_cpu (dqp->q_core.d_rtbtimer) + + ((u64 )dqp->q_core.d_rtbtimer_high <<32 ); warns =be16_to_cpu (dqp->q_core.d_rtbwarns); warnlimit = dqp->q_mount->m_quotainfo->qi_rtbwarnlimit; resbcountp = &dqp->q_res_rtbcount;
@@ -635,7 +637,8 @@ xfs_trans_dqresv( goto error_return; }if (softlimit && total_count > softlimit) { -if ((timer !=0 &&get_seconds () > timer) || +if ((timer !=0 && +ktime_get_real_seconds () > timer) || (warns !=0 && warns >= warnlimit)) {xfs_quota_warn (mp, dqp,QUOTA_NL_BSOFTLONGWARN );
@@ -647,7 +650,8 @@ xfs_trans_dqresv( }if (ninos >0 ) { total_count =be64_to_cpu (dqp->q_core.d_icount) + ninos; - timer =be32_to_cpu (dqp->q_core.d_itimer); + timer =be32_to_cpu (dqp->q_core.d_itimer) + + ((u64 )dqp->q_core.d_itimer_high <<32 ); warns =be16_to_cpu (dqp->q_core.d_iwarns); warnlimit = dqp->q_mount->m_quotainfo->qi_iwarnlimit; hardlimit =be64_to_cpu (dqp->q_core.d_ino_hardlimit);
@@ -662,7 +666,8 @@ xfs_trans_dqresv( goto error_return; }if (softlimit && total_count > softlimit) { -if ((timer !=0 &&get_seconds () > timer) || +if ((timer !=0 && +ktime_get_real_seconds () > timer) || (warns !=0 && warns >= warnlimit)) {xfs_quota_warn (mp, dqp,QUOTA_NL_ISOFTLONGWARN );
Signature · 1 line
2.20.0