|
|
f49185 |
From 06963ef0d4ff9a6736f699d1ca8ef5a0c194799b Mon Sep 17 00:00:00 2001
|
|
|
f49185 |
From: "Darrick J. Wong" <darrick.wong@oracle.com>
|
|
|
f49185 |
Date: Thu, 12 Nov 2020 16:49:42 -0500
|
|
|
f49185 |
Subject: [PATCH] xfs: widen ondisk quota expiration timestamps to handle
|
|
|
f49185 |
y2038+
|
|
|
f49185 |
|
|
|
f49185 |
Source kernel commit: 4ea1ff3b49681af45a4a8c14baf7f0b3d11aa74a
|
|
|
f49185 |
|
|
|
f49185 |
Enable the bigtime feature for quota timers. We decrease the accuracy
|
|
|
f49185 |
of the timers to ~4s in exchange for being able to set timers up to the
|
|
|
f49185 |
bigtime maximum.
|
|
|
f49185 |
|
|
|
f49185 |
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
|
|
|
f49185 |
Reviewed-by: Christoph Hellwig <hch@lst.de>
|
|
|
f49185 |
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
|
|
|
f49185 |
Reviewed-by: Dave Chinner <dchinner@redhat.com>
|
|
|
f49185 |
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
|
|
|
f49185 |
---
|
|
|
f49185 |
|
|
|
f49185 |
NOTE: Again, slightly different macro names due to lack of the
|
|
|
f49185 |
quota type/flags split.
|
|
|
f49185 |
|
|
|
f49185 |
diff --git a/include/xfs_mount.h b/include/xfs_mount.h
|
|
|
f49185 |
index 8651d6a..beb2328 100644
|
|
|
f49185 |
--- a/include/xfs_mount.h
|
|
|
f49185 |
+++ b/include/xfs_mount.h
|
|
|
f49185 |
@@ -202,4 +202,8 @@ extern xfs_mount_t *libxfs_mount (xfs_mount_t *, xfs_sb_t *,
|
|
|
f49185 |
extern void libxfs_umount (xfs_mount_t *);
|
|
|
f49185 |
extern void libxfs_rtmount_destroy (xfs_mount_t *);
|
|
|
f49185 |
|
|
|
f49185 |
+/* Dummy xfs_dquot so that libxfs compiles. */
|
|
|
f49185 |
+struct xfs_dquot {
|
|
|
f49185 |
+ int q_type;
|
|
|
f49185 |
+};
|
|
|
f49185 |
#endif /* __XFS_MOUNT_H__ */
|
|
|
f49185 |
diff --git a/libxfs/xfs_dquot_buf.c b/libxfs/xfs_dquot_buf.c
|
|
|
f49185 |
index 963f8ea..db93dda 100644
|
|
|
f49185 |
--- a/libxfs/xfs_dquot_buf.c
|
|
|
f49185 |
+++ b/libxfs/xfs_dquot_buf.c
|
|
|
f49185 |
@@ -69,6 +69,13 @@ xfs_dquot_verify(
|
|
|
f49185 |
ddq_type != XFS_DQ_GROUP)
|
|
|
f49185 |
return __this_address;
|
|
|
f49185 |
|
|
|
f49185 |
+ if ((ddq->d_flags & XFS_DQ_BIGTIME) &&
|
|
|
f49185 |
+ !xfs_sb_version_hasbigtime(&mp->m_sb))
|
|
|
f49185 |
+ return __this_address;
|
|
|
f49185 |
+
|
|
|
f49185 |
+ if ((ddq->d_flags & XFS_DQ_BIGTIME) && !ddq->d_id)
|
|
|
f49185 |
+ return __this_address;
|
|
|
f49185 |
+
|
|
|
f49185 |
if (id != -1 && id != be32_to_cpu(ddq->d_id))
|
|
|
f49185 |
return __this_address;
|
|
|
f49185 |
|
|
|
f49185 |
@@ -293,7 +300,12 @@ xfs_dquot_from_disk_ts(
|
|
|
f49185 |
struct xfs_disk_dquot *ddq,
|
|
|
f49185 |
__be32 dtimer)
|
|
|
f49185 |
{
|
|
|
f49185 |
- return be32_to_cpu(dtimer);
|
|
|
f49185 |
+ uint32_t t = be32_to_cpu(dtimer);
|
|
|
f49185 |
+
|
|
|
f49185 |
+ if (t != 0 && (ddq->d_flags & XFS_DQ_BIGTIME))
|
|
|
f49185 |
+ return xfs_dq_bigtime_to_unix(t);
|
|
|
f49185 |
+
|
|
|
f49185 |
+ return t;
|
|
|
f49185 |
}
|
|
|
f49185 |
|
|
|
f49185 |
/* Convert an incore timer value into an on-disk timer value. */
|
|
|
f49185 |
@@ -302,5 +314,10 @@ xfs_dquot_to_disk_ts(
|
|
|
f49185 |
struct xfs_dquot *dqp,
|
|
|
f49185 |
time64_t timer)
|
|
|
f49185 |
{
|
|
|
f49185 |
- return cpu_to_be32(timer);
|
|
|
f49185 |
+ uint32_t t = timer;
|
|
|
f49185 |
+
|
|
|
f49185 |
+ if (timer != 0 && (dqp->q_type & XFS_DQ_BIGTIME))
|
|
|
f49185 |
+ t = xfs_dq_unix_to_bigtime(timer);
|
|
|
f49185 |
+
|
|
|
f49185 |
+ return cpu_to_be32(t);
|
|
|
f49185 |
}
|
|
|
f49185 |
diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h
|
|
|
f49185 |
index b1f6219..9ba65e5 100644
|
|
|
f49185 |
--- a/libxfs/xfs_format.h
|
|
|
f49185 |
+++ b/libxfs/xfs_format.h
|
|
|
f49185 |
@@ -1263,6 +1263,10 @@ static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)
|
|
|
f49185 |
* ondisk min and max defined here can be used directly to constrain the incore
|
|
|
f49185 |
* quota expiration timestamps on a Unix system.
|
|
|
f49185 |
*
|
|
|
f49185 |
+ * When bigtime is enabled, we trade two bits of precision to expand the
|
|
|
f49185 |
+ * expiration timeout range to match that of big inode timestamps. The min and
|
|
|
f49185 |
+ * max recorded here are the on-disk limits, not a Unix timestamp.
|
|
|
f49185 |
+ *
|
|
|
f49185 |
* The grace period for each quota type is stored in the root dquot (id = 0)
|
|
|
f49185 |
* and is applied to a non-root dquot when it exceeds the soft or hard limits.
|
|
|
f49185 |
* The length of quota grace periods are unsigned 32-bit quantities measured in
|
|
|
f49185 |
@@ -1281,6 +1285,48 @@ static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)
|
|
|
f49185 |
*/
|
|
|
f49185 |
#define XFS_DQ_LEGACY_EXPIRY_MAX ((int64_t)U32_MAX)
|
|
|
f49185 |
|
|
|
f49185 |
+/*
|
|
|
f49185 |
+ * Smallest possible ondisk quota expiration value with bigtime timestamps.
|
|
|
f49185 |
+ * This corresponds (after conversion to a Unix timestamp) with the incore
|
|
|
f49185 |
+ * expiration of Jan 1 00:00:04 UTC 1970.
|
|
|
f49185 |
+ */
|
|
|
f49185 |
+#define XFS_DQ_BIGTIME_EXPIRY_MIN (XFS_DQ_LEGACY_EXPIRY_MIN)
|
|
|
f49185 |
+
|
|
|
f49185 |
+/*
|
|
|
f49185 |
+ * Largest supported ondisk quota expiration value with bigtime timestamps.
|
|
|
f49185 |
+ * This corresponds (after conversion to a Unix timestamp) with an incore
|
|
|
f49185 |
+ * expiration of Jul 2 20:20:24 UTC 2486.
|
|
|
f49185 |
+ *
|
|
|
f49185 |
+ * The ondisk field supports values up to -1U, which corresponds to an incore
|
|
|
f49185 |
+ * expiration in 2514. This is beyond the maximum the bigtime inode timestamp,
|
|
|
f49185 |
+ * so we cap the maximum bigtime quota expiration to the max inode timestamp.
|
|
|
f49185 |
+ */
|
|
|
f49185 |
+#define XFS_DQ_BIGTIME_EXPIRY_MAX ((int64_t)4074815106U)
|
|
|
f49185 |
+
|
|
|
f49185 |
+/*
|
|
|
f49185 |
+ * The following conversion factors assist in converting a quota expiration
|
|
|
f49185 |
+ * timestamp between the incore and ondisk formats.
|
|
|
f49185 |
+ */
|
|
|
f49185 |
+#define XFS_DQ_BIGTIME_SHIFT (2)
|
|
|
f49185 |
+#define XFS_DQ_BIGTIME_SLACK ((int64_t)(1ULL << XFS_DQ_BIGTIME_SHIFT) - 1)
|
|
|
f49185 |
+
|
|
|
f49185 |
+/* Convert an incore quota expiration timestamp to an ondisk bigtime value. */
|
|
|
f49185 |
+static inline uint32_t xfs_dq_unix_to_bigtime(time64_t unix_seconds)
|
|
|
f49185 |
+{
|
|
|
f49185 |
+ /*
|
|
|
f49185 |
+ * Round the expiration timestamp up to the nearest bigtime timestamp
|
|
|
f49185 |
+ * that we can store, to give users the most time to fix problems.
|
|
|
f49185 |
+ */
|
|
|
f49185 |
+ return ((uint64_t)unix_seconds + XFS_DQ_BIGTIME_SLACK) >>
|
|
|
f49185 |
+ XFS_DQ_BIGTIME_SHIFT;
|
|
|
f49185 |
+}
|
|
|
f49185 |
+
|
|
|
f49185 |
+/* Convert an ondisk bigtime quota expiration value to an incore timestamp. */
|
|
|
f49185 |
+static inline time64_t xfs_dq_bigtime_to_unix(uint32_t ondisk_seconds)
|
|
|
f49185 |
+{
|
|
|
f49185 |
+ return (time64_t)ondisk_seconds << XFS_DQ_BIGTIME_SHIFT;
|
|
|
f49185 |
+}
|
|
|
f49185 |
+
|
|
|
f49185 |
/*
|
|
|
f49185 |
* Default quota grace periods, ranging from zero (use the compiled defaults)
|
|
|
f49185 |
* to ~136 years. These are applied to a non-root dquot that has exceeded
|
|
|
f49185 |
diff --git a/libxfs/xfs_quota_defs.h b/libxfs/xfs_quota_defs.h
|
|
|
f49185 |
index 2f61cd3..70d89cc 100644
|
|
|
f49185 |
--- a/libxfs/xfs_quota_defs.h
|
|
|
f49185 |
+++ b/libxfs/xfs_quota_defs.h
|
|
|
f49185 |
@@ -28,17 +28,20 @@ typedef uint16_t xfs_qwarncnt_t;
|
|
|
f49185 |
#define XFS_DQ_GROUP 0x0004 /* a group quota */
|
|
|
f49185 |
#define XFS_DQ_DIRTY 0x0008 /* dquot is dirty */
|
|
|
f49185 |
#define XFS_DQ_FREEING 0x0010 /* dquot is being torn down */
|
|
|
f49185 |
+#define XFS_DQ_BIGTIME 0x0080 /* large expiry timestamps */
|
|
|
f49185 |
|
|
|
f49185 |
#define XFS_DQ_ALLTYPES (XFS_DQ_USER|XFS_DQ_PROJ|XFS_DQ_GROUP)
|
|
|
f49185 |
|
|
|
f49185 |
-#define XFS_DQTYPE_ANY (XFS_DQ_ALLTYPES)
|
|
|
f49185 |
+#define XFS_DQTYPE_ANY (XFS_DQ_ALLTYPES | \
|
|
|
f49185 |
+ XFS_DQ_BIGTIME)
|
|
|
f49185 |
|
|
|
f49185 |
#define XFS_DQ_FLAGS \
|
|
|
f49185 |
{ XFS_DQ_USER, "USER" }, \
|
|
|
f49185 |
{ XFS_DQ_PROJ, "PROJ" }, \
|
|
|
f49185 |
{ XFS_DQ_GROUP, "GROUP" }, \
|
|
|
f49185 |
{ XFS_DQ_DIRTY, "DIRTY" }, \
|
|
|
f49185 |
- { XFS_DQ_FREEING, "FREEING" }
|
|
|
f49185 |
+ { XFS_DQ_FREEING, "FREEING" }, \
|
|
|
f49185 |
+ { XFS_DQ_BIGTIME, "BIGTIME" }
|
|
|
f49185 |
|
|
|
f49185 |
/*
|
|
|
f49185 |
* We have the possibility of all three quota types being active at once, and
|