[PATCH] quotatools: support grace period expirations past y2038 in userspace

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Darrick J. Wong <darrick.wong@xxxxxxxxxx>

Add the ability to interpret the larger quota grace period expiration
timestamps that the kernel can export via struct xfs_kern_dqblk.

Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx>
---
 quotaio_xfs.c |   33 +++++++++++++++++++++++++++++----
 quotaio_xfs.h |   11 ++++++++++-
 2 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/quotaio_xfs.c b/quotaio_xfs.c
index 3333bb1..9854ec2 100644
--- a/quotaio_xfs.c
+++ b/quotaio_xfs.c
@@ -42,6 +42,29 @@ scan_dquots:	xfs_scan_dquots,
 report:		xfs_report
 };
 
+static inline time_t xfs_kern2utildqblk_ts(const struct xfs_kern_dqblk *k,
+		__s32 timer, __s8 timer_hi)
+{
+	if (k->d_fieldmask & FS_DQ_BIGTIME)
+		return (__u32)timer | (__s64)timer_hi << 32;
+	return timer;
+}
+
+static inline void xfs_util2kerndqblk_ts(const struct xfs_kern_dqblk *k,
+		__s32 *timer_lo, __s8 *timer_hi, time_t timer)
+{
+	*timer_lo = timer;
+	if (k->d_fieldmask & FS_DQ_BIGTIME)
+		*timer_hi = timer >> 32;
+	else
+		*timer_hi = 0;
+}
+
+static inline int want_bigtime(time_t timer)
+{
+	return timer > INT32_MAX || timer < INT32_MIN;
+}
+
 /*
  *	Convert XFS kernel quota format to utility format
  */
@@ -53,8 +76,8 @@ static inline void xfs_kern2utildqblk(struct util_dqblk *u, struct xfs_kern_dqbl
 	u->dqb_bsoftlimit = k->d_blk_softlimit >> 1;
 	u->dqb_curinodes = k->d_icount;
 	u->dqb_curspace = ((qsize_t)k->d_bcount) << 9;
-	u->dqb_itime = k->d_itimer;
-	u->dqb_btime = k->d_btimer;
+	u->dqb_itime = xfs_kern2utildqblk_ts(k, k->d_itimer, k->d_itimer_hi);
+	u->dqb_btime = xfs_kern2utildqblk_ts(k, k->d_btimer, k->d_btimer_hi);
 }
 
 /*
@@ -69,8 +92,10 @@ static inline void xfs_util2kerndqblk(struct xfs_kern_dqblk *k, struct util_dqbl
 	k->d_blk_softlimit = u->dqb_bsoftlimit << 1;
 	k->d_icount = u->dqb_curinodes;
 	k->d_bcount = u->dqb_curspace >> 9;
-	k->d_itimer = u->dqb_itime;
-	k->d_btimer = u->dqb_btime;
+	if (want_bigtime(u->dqb_itime) || want_bigtime(u->dqb_btime))
+		k->d_fieldmask |= FS_DQ_BIGTIME;
+	xfs_util2kerndqblk_ts(k, &k->d_itimer, &k->d_itimer_hi, u->dqb_itime);
+	xfs_util2kerndqblk_ts(k, &k->d_btimer, &k->d_btimer_hi, u->dqb_btime);
 }
 
 /*
diff --git a/quotaio_xfs.h b/quotaio_xfs.h
index be7f86f..e0c2a62 100644
--- a/quotaio_xfs.h
+++ b/quotaio_xfs.h
@@ -72,7 +72,10 @@ typedef struct fs_disk_quota {
 	__s32 d_btimer;		/* similar to above; for disk blocks */
 	__u16 d_iwarns;		/* # warnings issued wrt num inodes */
 	__u16 d_bwarns;		/* # warnings issued wrt disk blocks */
-	__s32 d_padding2;	/* padding2 - for future use */
+	__s8 d_itimer_hi;	/* upper 8 bits of timer values */
+	__s8 d_btimer_hi;
+	__s8 d_rtbtimer_hi;
+	__s8 d_padding2;	/* padding2 - for future use */
 	__u64 d_rtb_hardlimit;	/* absolute limit on realtime blks */
 	__u64 d_rtb_softlimit;	/* preferred limit on RT disk blks */
 	__u64 d_rtbcount;	/* # realtime blocks owned */
@@ -114,6 +117,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 40-bit signed integers, with the upper 8
+ * bits encoded in the _hi fields.
+ */
+#define FS_DQ_BIGTIME		(1<<15)
+
 /*
  * Various flags related to quotactl(2).  Only relevant to XFS filesystems.
  */



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux