]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: widen ondisk quota expiration timestamps to handle y2038+
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 12 Nov 2020 21:49:42 +0000 (16:49 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 12 Nov 2020 21:49:42 +0000 (16:49 -0500)
Source kernel commit: 4ea1ff3b49681af45a4a8c14baf7f0b3d11aa74a

Enable the bigtime feature for quota timers.  We decrease the accuracy
of the timers to ~4s in exchange for being able to set timers up to the
bigtime maximum.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Allison Collins <allison.henderson@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
include/xfs_mount.h
libxfs/xfs_dquot_buf.c
libxfs/xfs_format.h
libxfs/xfs_quota_defs.h

index 20c8bfaf4fa8856aa29dfb0fdf61b6755cf288b4..36594643862045cd97cf7d09662dd20737afbca2 100644 (file)
@@ -184,4 +184,8 @@ extern xfs_mount_t  *libxfs_mount (xfs_mount_t *, xfs_sb_t *,
 int            libxfs_umount(struct xfs_mount *mp);
 extern void    libxfs_rtmount_destroy (xfs_mount_t *);
 
+/* Dummy xfs_dquot so that libxfs compiles. */
+struct xfs_dquot {
+       int             q_type;
+};
 #endif /* __XFS_MOUNT_H__ */
index 04f62e31019d0a163e1a1ad934648138a582f02e..0a5a237d2236251cbf79530edb65a12123e8e82a 100644 (file)
@@ -67,6 +67,13 @@ xfs_dquot_verify(
            ddq_type != XFS_DQTYPE_GROUP)
                return __this_address;
 
+       if ((ddq->d_type & XFS_DQTYPE_BIGTIME) &&
+           !xfs_sb_version_hasbigtime(&mp->m_sb))
+               return __this_address;
+
+       if ((ddq->d_type & XFS_DQTYPE_BIGTIME) && !ddq->d_id)
+               return __this_address;
+
        if (id != -1 && id != be32_to_cpu(ddq->d_id))
                return __this_address;
 
@@ -293,7 +300,12 @@ xfs_dquot_from_disk_ts(
        struct xfs_disk_dquot   *ddq,
        __be32                  dtimer)
 {
-       return be32_to_cpu(dtimer);
+       uint32_t                t = be32_to_cpu(dtimer);
+
+       if (t != 0 && (ddq->d_type & XFS_DQTYPE_BIGTIME))
+               return xfs_dq_bigtime_to_unix(t);
+
+       return t;
 }
 
 /* Convert an incore timer value into an on-disk timer value. */
@@ -302,5 +314,10 @@ xfs_dquot_to_disk_ts(
        struct xfs_dquot        *dqp,
        time64_t                timer)
 {
-       return cpu_to_be32(timer);
+       uint32_t                t = timer;
+
+       if (timer != 0 && (dqp->q_type & XFS_DQTYPE_BIGTIME))
+               t = xfs_dq_unix_to_bigtime(timer);
+
+       return cpu_to_be32(t);
 }
index d71228a6e06c6d1721e6949165a94b081e498e28..da37c8b234c789c208467295acc0f7aa1a657d54 100644 (file)
@@ -1262,13 +1262,15 @@ static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)
 #define XFS_DQTYPE_USER                0x01            /* user dquot record */
 #define XFS_DQTYPE_PROJ                0x02            /* project dquot record */
 #define XFS_DQTYPE_GROUP       0x04            /* group dquot record */
+#define XFS_DQTYPE_BIGTIME     0x80            /* large expiry timestamps */
 
 /* bitmask to determine if this is a user/group/project dquot */
 #define XFS_DQTYPE_REC_MASK    (XFS_DQTYPE_USER | \
                                 XFS_DQTYPE_PROJ | \
                                 XFS_DQTYPE_GROUP)
 
-#define XFS_DQTYPE_ANY         (XFS_DQTYPE_REC_MASK)
+#define XFS_DQTYPE_ANY         (XFS_DQTYPE_REC_MASK | \
+                                XFS_DQTYPE_BIGTIME)
 
 /*
  * XFS Quota Timers
@@ -1281,6 +1283,10 @@ static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)
  * ondisk min and max defined here can be used directly to constrain the incore
  * quota expiration timestamps on a Unix system.
  *
+ * When bigtime is enabled, we trade two bits of precision to expand the
+ * expiration timeout range to match that of big inode timestamps.  The min and
+ * max recorded here are the on-disk limits, not a Unix timestamp.
+ *
  * The grace period for each quota type is stored in the root dquot (id = 0)
  * and is applied to a non-root dquot when it exceeds the soft or hard limits.
  * The length of quota grace periods are unsigned 32-bit quantities measured in
@@ -1299,6 +1305,48 @@ static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)
  */
 #define XFS_DQ_LEGACY_EXPIRY_MAX       ((int64_t)U32_MAX)
 
+/*
+ * Smallest possible ondisk quota expiration value with bigtime timestamps.
+ * This corresponds (after conversion to a Unix timestamp) with the incore
+ * expiration of Jan  1 00:00:04 UTC 1970.
+ */
+#define XFS_DQ_BIGTIME_EXPIRY_MIN      (XFS_DQ_LEGACY_EXPIRY_MIN)
+
+/*
+ * Largest supported ondisk quota expiration value with bigtime timestamps.
+ * This corresponds (after conversion to a Unix timestamp) with an incore
+ * expiration of Jul  2 20:20:24 UTC 2486.
+ *
+ * The ondisk field supports values up to -1U, which corresponds to an incore
+ * expiration in 2514.  This is beyond the maximum the bigtime inode timestamp,
+ * so we cap the maximum bigtime quota expiration to the max inode timestamp.
+ */
+#define XFS_DQ_BIGTIME_EXPIRY_MAX      ((int64_t)4074815106U)
+
+/*
+ * The following conversion factors assist in converting a quota expiration
+ * timestamp between the incore and ondisk formats.
+ */
+#define XFS_DQ_BIGTIME_SHIFT   (2)
+#define XFS_DQ_BIGTIME_SLACK   ((int64_t)(1ULL << XFS_DQ_BIGTIME_SHIFT) - 1)
+
+/* Convert an incore quota expiration timestamp to an ondisk bigtime value. */
+static inline uint32_t xfs_dq_unix_to_bigtime(time64_t unix_seconds)
+{
+       /*
+        * Round the expiration timestamp up to the nearest bigtime timestamp
+        * that we can store, to give users the most time to fix problems.
+        */
+       return ((uint64_t)unix_seconds + XFS_DQ_BIGTIME_SLACK) >>
+                       XFS_DQ_BIGTIME_SHIFT;
+}
+
+/* Convert an ondisk bigtime quota expiration value to an incore timestamp. */
+static inline time64_t xfs_dq_bigtime_to_unix(uint32_t ondisk_seconds)
+{
+       return (time64_t)ondisk_seconds << XFS_DQ_BIGTIME_SHIFT;
+}
+
 /*
  * Default quota grace periods, ranging from zero (use the compiled defaults)
  * to ~136 years.  These are applied to a non-root dquot that has exceeded
index 9a99910d857e5a01a48ade6970cd323a1cf5ef33..0f0af4e35032931bf8ceee890cff030fd287d2b3 100644 (file)
@@ -23,7 +23,8 @@ typedef uint8_t               xfs_dqtype_t;
 #define XFS_DQTYPE_STRINGS \
        { XFS_DQTYPE_USER,      "USER" }, \
        { XFS_DQTYPE_PROJ,      "PROJ" }, \
-       { XFS_DQTYPE_GROUP,     "GROUP" }
+       { XFS_DQTYPE_GROUP,     "GROUP" }, \
+       { XFS_DQTYPE_BIGTIME,   "BIGTIME" }
 
 /*
  * flags for q_flags field in the dquot.