quota: widen timestamps for the fs_disk_quota structure
Subsystems (3)
PATCH 1/1 quota: widen timestamps for the fs_disk_quota structure
From: Darrick J. Wong <[email protected]>
Widen the timestamp fields in struct fs_disk_quota to handle quota grace expiration times beyond 2038. Since the only filesystem that's going to use this (XFS) only supports unsigned 34-bit quantities, adding an extra 5 bits here should work fine. We can rev the structure again in 350 years.
--- fs/quota/quota.c | 40 +++++++++++++++++++++++++++++++++++++--- include/uapi/linux/dqblk_xfs.h | 13 +++++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-)
fs/quota/quota.c +37 -3
@@ -481,6 +481,14 @@ static inline u64 quota_btobb(u64 bytes)return (bytes + (1 <<XFS_BB_SHIFT ) -1 ) >>XFS_BB_SHIFT ; } +static inline s64 copy_from_xfs_dqblk_ts (const struct fs_disk_quota *d, +__s32 timer,__s8 timer_hi) +{ +if (d->d_fieldmask &FS_DQ_BIGTIME ) +return (u32 )timer | (s64 )timer_hi <<32 ; +return timer; +} +static void copy_from_xfs_dqblk (struct qc_dqblk *dst,struct fs_disk_quota *src) { dst->d_spc_hardlimit =quota_bbtob (src->d_blk_hardlimit);
@@ -489,14 +497,18 @@ static void copy_from_xfs_dqblk(struct qc_dqblk *dst, struct fs_disk_quota *src) dst->d_ino_softlimit = src->d_ino_softlimit; dst->d_space =quota_bbtob (src->d_bcount); dst->d_ino_count = src->d_icount; - dst->d_ino_timer = src->d_itimer; - dst->d_spc_timer = src->d_btimer; + dst->d_ino_timer =copy_from_xfs_dqblk_ts (src, src->d_itimer, + src->d_itimer_hi); + dst->d_spc_timer =copy_from_xfs_dqblk_ts (src, src->d_btimer, + src->d_btimer_hi); dst->d_ino_warns = src->d_iwarns; dst->d_spc_warns = src->d_bwarns; dst->d_rt_spc_hardlimit =quota_bbtob (src->d_rtb_hardlimit); dst->d_rt_spc_softlimit =quota_bbtob (src->d_rtb_softlimit); dst->d_rt_space =quota_bbtob (src->d_rtbcount); dst->d_rt_spc_timer = src->d_rtbtimer; + dst->d_rt_spc_timer =copy_from_xfs_dqblk_ts (src, src->d_rtbtimer, + src->d_rtbtimer_hi); dst->d_rt_spc_warns = src->d_rtbwarns; dst->d_fieldmask =0 ;if (src->d_fieldmask &FS_DQ_ISOFT )
@@ -588,10 +600,27 @@ static int quota_setxquota(struct super_block *sb, int type, qid_t id,return sb->s_qcop->set_dqblk (sb, qid, &qdq); } +static inline __s8 copy_to_xfs_dqblk_ts (const struct fs_disk_quota *d, +__s32 *timer_lo,s64 timer) +{ + *timer_lo = timer; +if (d->d_fieldmask &FS_DQ_BIGTIME ) +return timer >>32 ; +return 0 ; +} + +static inline bool want_bigtime (s64 timer) +{ +return timer >S32_MAX || timer <S32_MIN ; +} +static void copy_to_xfs_dqblk (struct fs_disk_quota *dst,struct qc_dqblk *src,int type,qid_t id) {memset (dst,0 ,sizeof (*dst)); +if (want_bigtime (src->d_ino_timer) ||want_bigtime (src->d_spc_timer) || +want_bigtime (src->d_rt_spc_timer)) + dst->d_fieldmask |=FS_DQ_BIGTIME ; dst->d_version =FS_DQUOT_VERSION ; dst->d_id = id;if (type ==USRQUOTA )
@@ -606,6 +635,10 @@ static void copy_to_xfs_dqblk(struct fs_disk_quota *dst, struct qc_dqblk *src, dst->d_ino_softlimit = src->d_ino_softlimit; dst->d_bcount =quota_btobb (src->d_space); dst->d_icount = src->d_ino_count; + dst->d_itimer_hi =copy_to_xfs_dqblk_ts (dst, &dst->d_itimer, + src->d_ino_timer); + dst->d_btimer_hi =copy_to_xfs_dqblk_ts (dst, &dst->d_btimer, + src->d_spc_timer); dst->d_itimer = src->d_ino_timer; dst->d_btimer = src->d_spc_timer; dst->d_iwarns = src->d_ino_warns;
@@ -613,7 +646,8 @@ static void copy_to_xfs_dqblk(struct fs_disk_quota *dst, struct qc_dqblk *src, dst->d_rtb_hardlimit =quota_btobb (src->d_rt_spc_hardlimit); dst->d_rtb_softlimit =quota_btobb (src->d_rt_spc_softlimit); dst->d_rtbcount =quota_btobb (src->d_rt_space); - dst->d_rtbtimer = src->d_rt_spc_timer; + dst->d_rtbtimer_hi =copy_to_xfs_dqblk_ts (dst, &dst->d_rtbtimer, + src->d_rt_spc_timer); dst->d_rtbwarns = src->d_rt_spc_warns; }
include/uapi/linux/dqblk_xfs.h +11 -2
@@ -71,8 +71,11 @@ typedef struct fs_disk_quota {__u64 d_rtb_softlimit;/* preferred limit on RT disk blks */ __u64 d_rtbcount;/* # realtime blocks owned */ __s32 d_rtbtimer;/* similar to above; for RT disk blks */ -__u16 d_rtbwarns;/* # warnings issued wrt RT disk blks */ -__s16 d_padding3;/* padding3 - for future use */ +__u16 d_rtbwarns;/* # warnings issued wrt RT disk blks */ + __s8 d_itimer_hi:5; /* upper 5 bits of timers */ + __s8 d_btimer_hi:5; + __s8 d_rtbtimer_hi:5; + __u8 d_padding3:1; /* padding3 - for future use */char d_padding4[8 ];/* yet more padding */ } fs_disk_quota_t;
@@ -121,6 +124,12 @@ typedef struct fs_disk_quota {#define FS_DQ_RTBCOUNT (1<<14)#define FS_DQ_ACCT_MASK (FS_DQ_BCOUNT | FS_DQ_ICOUNT | FS_DQ_RTBCOUNT) +/* +* Quota expiration timestamps are 37-bit signed integers, with the upper 5 +* bits encoded in the _hi fields. +*/ +#define FS_DQ_BIGTIME (1<<15) +/* * Various flags related to quotactl(2). */
Jan Kara
reviewerQuoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Widen the timestamp fields in struct
fs_disk_quotato handle quota grace expiration times beyond 2038. Since the only filesystem that's going to use this (XFS) only supports unsigned 34-bit quantities, adding an extra 5 bits here should work fine. We can rev the structure again in 350 years.Signed-off-by Darrick J. Wong <[email protected]>
Some comments below...
fs/quota/quota.c static int quota_setxquota(struct super_block *sb, int type, qid_t id, · line 610
Quoted 12 lines
fs/quota/quota.c +8
-0@@ -588,10 +600,27 @@ static int quota_setxquota(struct super_block *sb, int type, qid_t id,return sb->s_qcop->set_dqblk (sb, qid, &qdq); } +static inline __s8 copy_to_xfs_dqblk_ts (const struct fs_disk_quota *d, +__s32 *timer_lo,s64 timer) +{ + *timer_lo = timer; +if (d->d_fieldmask &FS_DQ_BIGTIME ) +return timer >>32 ; +return 0 ; +}
Hum, this function API looks a bit strange to me - directly store timer_lo and just return timer_hi... Why not having timer_hi as another function argument?
fs/quota/quota.c static void copy_to_xfs_dqblk(struct fs_disk_quota *dst, struct qc_dqblk *src, · line 643
Quoted 10 lines
fs/quota/quota.c +4
-0@@ -606,6 +635,10 @@ static void copy_to_xfs_dqblk(struct fs_disk_quota *dst, struct qc_dqblk *src, dst->d_ino_softlimit = src->d_ino_softlimit; dst->d_bcount =quota_btobb (src->d_space); dst->d_icount = src->d_ino_count; + dst->d_itimer_hi =copy_to_xfs_dqblk_ts (dst, &dst->d_itimer, + src->d_ino_timer); + dst->d_btimer_hi =copy_to_xfs_dqblk_ts (dst, &dst->d_btimer, + src->d_spc_timer); dst->d_itimer = src->d_ino_timer; dst->d_btimer = src->d_spc_timer;
Also it seems pointless (if not outright buggy due to sign-extension rules) to store to say d_itimer when copy_to_xfs_dqblk_ts() already did it...
Quoted 18 lines
fs/quota/quota.c +2
-1dst->d_iwarns = src->d_ino_warns;@@ -613,7 +646,8 @@ static void copy_to_xfs_dqblk(struct fs_disk_quota *dst, struct qc_dqblk *src, dst->d_rtb_hardlimit =quota_btobb (src->d_rt_spc_hardlimit); dst->d_rtb_softlimit =quota_btobb (src->d_rt_spc_softlimit); dst->d_rtbcount =quota_btobb (src->d_rt_space); - dst->d_rtbtimer = src->d_rt_spc_timer; + dst->d_rtbtimer_hi =copy_to_xfs_dqblk_ts (dst, &dst->d_rtbtimer, + src->d_rt_spc_timer); dst->d_rtbwarns = src->d_rt_spc_warns; }include/uapi/linux/dqblk_xfs.h +0
-0@@ -71,8 +71,11 @@ typedef struct fs_disk_quota {__u64 d_rtb_softlimit;/* preferred limit on RT disk blks */ __u64 d_rtbcount;/* # realtime blocks owned */
include/uapi/linux/dqblk_xfs.h typedef struct fs_disk_quota { · line 80
Quoted 10 lines
include/uapi/linux/dqblk_xfs.h +5
-2__s32 d_rtbtimer;/* similar to above; for RT disk blks */ -__u16 d_rtbwarns;/* # warnings issued wrt RT disk blks */ -__s16 d_padding3;/* padding3 - for future use */ +__u16 d_rtbwarns;/* # warnings issued wrt RT disk blks */ + __s8 d_itimer_hi:5; /* upper 5 bits of timers */ + __s8 d_btimer_hi:5; + __s8 d_rtbtimer_hi:5; + __u8 d_padding3:1; /* padding3 - for future use */char d_padding4[8 ];/* yet more padding */ } fs_disk_quota_t;
I'm a bit nervous about passing bitfields through kernel-userspace interface. It *should* work OK but I'm not sure rules for bitfield packing between different compilers are always compatible. E.g. in this case will the compiler emit three 1-byte fields (as __s8 kind of suggests), just masking 5-bits out of each or will it use 16-bit wide memory location with all four fields packed together? And if this is even defined? I didn't find anything definitive. Also I've found some notes that the order of bit fields in a word is implementation defined...
So to save us some headaches, I'd prefer to use just three times __s8 for the _hi fields and then check whether userspace didn't pass too big values (more than 5 significant bits) when copying from userspace.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 17 lines · Jan Kara
Quoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Widen the timestamp fields in struct
fs_disk_quotato handle quota grace expiration times beyond 2038. Since the only filesystem that's going to use this (XFS) only supports unsigned 34-bit quantities, adding an extra 5 bits here should work fine. We can rev the structure again in 350 years.Signed-off-by Darrick J. Wong <[email protected]>Some comments below...
Quoted 4 lines
fs/quota/quota.c +0
-0@@ -588,10 +600,27 @@ static int quota_setxquota(struct super_block *sb, int type, qid_t id,return sb->s_qcop->set_dqblk (sb, qid, &qdq); }
Quoted 12 lines
fs/quota/quota.c static int quota_setxquota(struct super_block *sb, int type, qid_t id, · line 610
Quoted 8 lines
fs/quota/quota.c +8
-0+static inline __s8 copy_to_xfs_dqblk_ts (const struct fs_disk_quota *d, +__s32 *timer_lo,s64 timer) +{ + *timer_lo = timer; +if (d->d_fieldmask &FS_DQ_BIGTIME ) +return timer >>32 ; +return 0 ; +}Hum, this function API looks a bit strange to me - directly store
timer_loand just returntimer_hi... Why not havingtimer_hias another function argument?
You can't pass pointers to a bitset. :)
Quoted 5 lines
Quoted 5 lines
fs/quota/quota.c +1
-0@@ -606,6 +635,10 @@ static void copy_to_xfs_dqblk(struct fs_disk_quota *dst, struct qc_dqblk *src, dst->d_ino_softlimit = src->d_ino_softlimit; dst->d_bcount =quota_btobb (src->d_space); dst->d_icount = src->d_ino_count; + dst->d_itimer_hi = copy_to_xfs_dqblk_ts(dst, &dst->d_itimer,
Quoted 8 lines
fs/quota/quota.c static void copy_to_xfs_dqblk(struct fs_disk_quota *dst, struct qc_dqblk *src, · line 643
Quoted 5 lines
fs/quota/quota.c +3
-0+ src->d_ino_timer); + dst->d_btimer_hi =copy_to_xfs_dqblk_ts (dst, &dst->d_btimer, + src->d_spc_timer); dst->d_itimer = src->d_ino_timer; dst->d_btimer = src->d_spc_timer;Also it seems pointless (if not outright buggy due to sign-extension rules) to store to say
d_itimerwhencopy_to_xfs_dqblk_ts()already did it...
Oops. That was a straight up bug. :(
Quoted 38 lines
Quoted 18 lines
fs/quota/quota.c +2
-1dst->d_iwarns = src->d_ino_warns;@@ -613,7 +646,8 @@ static void copy_to_xfs_dqblk(struct fs_disk_quota *dst, struct qc_dqblk *src, dst->d_rtb_hardlimit =quota_btobb (src->d_rt_spc_hardlimit); dst->d_rtb_softlimit =quota_btobb (src->d_rt_spc_softlimit); dst->d_rtbcount =quota_btobb (src->d_rt_space); - dst->d_rtbtimer = src->d_rt_spc_timer; + dst->d_rtbtimer_hi =copy_to_xfs_dqblk_ts (dst, &dst->d_rtbtimer, + src->d_rt_spc_timer); dst->d_rtbwarns = src->d_rt_spc_warns; }include/uapi/linux/dqblk_xfs.h +0
-0@@ -71,8 +71,11 @@ typedef struct fs_disk_quota {__u64 d_rtb_softlimit;/* preferred limit on RT disk blks */ __u64 d_rtbcount;/* # realtime blocks owned */ include/uapi/linux/dqblk_xfs.h typedef struct fs_disk_quota { · line 80
Quoted 10 lines
include/uapi/linux/dqblk_xfs.h +5
-2__s32 d_rtbtimer;/* similar to above; for RT disk blks */ -__u16 d_rtbwarns;/* # warnings issued wrt RT disk blks */ -__s16 d_padding3;/* padding3 - for future use */ +__u16 d_rtbwarns;/* # warnings issued wrt RT disk blks */ + __s8 d_itimer_hi:5; /* upper 5 bits of timers */ + __s8 d_btimer_hi:5; + __s8 d_rtbtimer_hi:5; + __u8 d_padding3:1; /* padding3 - for future use */char d_padding4[8 ];/* yet more padding */ } fs_disk_quota_t;I'm a bit nervous about passing bitfields through kernel-userspace interface. It *should* work OK but I'm not sure rules for bitfield packing between different compilers are always compatible. E.g. in this case will the compiler emit three 1-byte fields (as
__s8kind of suggests), just masking 5-bits out of each or will it use 16-bit wide memory location with all four fields packed together? And if this is even defined? I didn't find anything definitive. Also I've found some notes that the order of bit fields in a word is implementation defined...
Quoted 3 lines
So to save us some headaches, I'd prefer to use just three times
__s8for the_hifields and then check whether userspace didn't pass too big values (more than 5 significant bits) when copying from userspace.
Ok. I was trying to leave the u32 and u64 paddings, but I'll pick something to burn down. __s8[3] it is. :)
--D
Quoted 4 lines
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR