All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@sandeen.net, darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 12/18] xfs: enable bigtime for quota timers
Date: Mon, 17 Aug 2020 16:00:09 -0700	[thread overview]
Message-ID: <159770520929.3958786.2869468837745844258.stgit@magnolia> (raw)
In-Reply-To: <159770513155.3958786.16108819726679724438.stgit@magnolia>

From: Darrick J. Wong <darrick.wong@oracle.com>

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>
---
 include/xfs_mount.h     |    5 +++++
 libxfs/xfs_dquot_buf.c  |   40 ++++++++++++++++++++++++++++++++++++++++
 libxfs/xfs_format.h     |   26 +++++++++++++++++++++++++-
 libxfs/xfs_quota_defs.h |    3 ++-
 4 files changed, 72 insertions(+), 2 deletions(-)


diff --git a/include/xfs_mount.h b/include/xfs_mount.h
index 20c8bfaf4fa8..be74a922b7a1 100644
--- a/include/xfs_mount.h
+++ b/include/xfs_mount.h
@@ -184,4 +184,9 @@ 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__ */
diff --git a/libxfs/xfs_dquot_buf.c b/libxfs/xfs_dquot_buf.c
index 847b9ba5280c..e5938ef649f0 100644
--- a/libxfs/xfs_dquot_buf.c
+++ b/libxfs/xfs_dquot_buf.c
@@ -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;
 
@@ -294,6 +301,20 @@ xfs_dquot_from_disk_timestamp(
 	time64_t		*timer,
 	__be32			dtimer)
 {
+	/* Zero always means zero, regardless of encoding. */
+	if (!dtimer) {
+		*timer = 0;
+		return;
+	}
+
+	if (ddq->d_type & XFS_DQTYPE_BIGTIME) {
+		uint64_t	t;
+
+		t = be32_to_cpu(dtimer);
+		*timer = t << XFS_DQ_BIGTIME_SHIFT;
+		return;
+	}
+
 	*timer = be32_to_cpu(dtimer);
 }
 
@@ -304,5 +325,24 @@ xfs_dquot_to_disk_timestamp(
 	__be32			*dtimer,
 	time64_t		timer)
 {
+	/* Zero always means zero, regardless of encoding. */
+	if (!timer) {
+		*dtimer = cpu_to_be32(0);
+		return;
+	}
+
+	if (dqp->q_type & XFS_DQTYPE_BIGTIME) {
+		uint64_t	t = timer;
+
+		/*
+		 * Round the end of the grace period up to the nearest bigtime
+		 * interval that we support, to give users the most time to fix
+		 * the problems.
+		 */
+		t = roundup_64(t, 1U << XFS_DQ_BIGTIME_SHIFT);
+		*dtimer = cpu_to_be32(t >> XFS_DQ_BIGTIME_SHIFT);
+		return;
+	}
+
 	*dtimer = cpu_to_be32(timer);
 }
diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h
index 67303e517260..87c86a6dfb91 100644
--- a/libxfs/xfs_format.h
+++ b/libxfs/xfs_format.h
@@ -1228,13 +1228,15 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
 #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	0x08		/* 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
@@ -1271,6 +1273,28 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
 #define XFS_DQ_GRACE_MIN	((int64_t)0)
 #define XFS_DQ_GRACE_MAX	((int64_t)U32_MAX)
 
+/*
+ * When bigtime is enabled, we trade a few bits of precision to expand the
+ * expiration timeout range to match that of big inode timestamps.  The grace
+ * periods stored in dquot 0 are not shifted, since they record an interval,
+ * not a timestamp.
+ */
+#define XFS_DQ_BIGTIME_SHIFT		(2)
+
+/*
+ * Smallest possible quota expiration with big timestamps, which is
+ * Jan  1 00:00:01 UTC 1970.
+ */
+#define XFS_DQ_BIGTIMEOUT_MIN		(XFS_DQ_TIMEOUT_MIN)
+
+/*
+ * Largest supported quota expiration with traditional timestamps, which is
+ * the largest bigtime inode timestamp, or Jul  2 20:20:25 UTC 2486.  The field
+ * is large enough that it's possible to fit expirations up to 2514, but we
+ * want to keep the maximum timestamp in sync.
+ */
+#define XFS_DQ_BIGTIMEOUT_MAX		(XFS_INO_BIGTIME_MAX)
+
 /*
  * This is the main portion of the on-disk representation of quota information
  * for a user.  We pad this with some more expansion room to construct the on
diff --git a/libxfs/xfs_quota_defs.h b/libxfs/xfs_quota_defs.h
index b524059faab5..b9a47eae684b 100644
--- a/libxfs/xfs_quota_defs.h
+++ b/libxfs/xfs_quota_defs.h
@@ -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.


  parent reply	other threads:[~2020-08-17 23:00 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-17 22:58 [PATCH 00/18] xfsprogs: widen timestamps to deal with y2038 Darrick J. Wong
2020-08-17 22:58 ` [PATCH 01/18] libxfs: create a real struct timespec64 Darrick J. Wong
2020-08-18 14:19   ` Amir Goldstein
2020-08-17 22:59 ` [PATCH 02/18] xfs: explicitly define inode timestamp range Darrick J. Wong
2020-08-18 14:17   ` Amir Goldstein
2020-08-17 22:59 ` [PATCH 03/18] xfs: refactor quota expiration timer modification Darrick J. Wong
2020-08-18 14:21   ` Amir Goldstein
2020-08-18 15:25     ` Darrick J. Wong
2020-08-18 18:50       ` Amir Goldstein
2020-08-17 22:59 ` [PATCH 04/18] xfs: refactor default quota grace period setting code Darrick J. Wong
2020-08-18 14:23   ` Amir Goldstein
2020-08-17 22:59 ` [PATCH 05/18] xfs: remove xfs_timestamp_t Darrick J. Wong
2020-08-18 14:24   ` Amir Goldstein
2020-08-17 22:59 ` [PATCH 06/18] xfs: move xfs_log_dinode_to_disk to the log code Darrick J. Wong
2020-08-18 14:26   ` Amir Goldstein
2020-08-17 22:59 ` [PATCH 07/18] xfs: refactor inode timestamp coding Darrick J. Wong
2020-08-18 14:28   ` Amir Goldstein
2020-08-17 22:59 ` [PATCH 08/18] xfs: convert struct xfs_timestamp to union Darrick J. Wong
2020-08-18 14:29   ` Amir Goldstein
2020-08-17 22:59 ` [PATCH 09/18] libxfs: refactor NSEC_PER_SEC Darrick J. Wong
2020-08-18 14:31   ` Amir Goldstein
2020-08-17 22:59 ` [PATCH 10/18] xfs: widen ondisk timestamps to deal with y2038 problem Darrick J. Wong
2020-08-18 14:40   ` Amir Goldstein
2020-08-17 23:00 ` [PATCH 11/18] xfs: refactor quota timestamp coding Darrick J. Wong
2020-08-18 14:41   ` Amir Goldstein
2020-08-17 23:00 ` Darrick J. Wong [this message]
2020-08-17 23:00 ` [PATCH 13/18] xfs: enable big timestamps Darrick J. Wong
2020-08-18 14:42   ` Amir Goldstein
2020-08-17 23:00 ` [PATCH 14/18] xfs_db: report bigtime format timestamps Darrick J. Wong
2020-08-18 15:37   ` Darrick J. Wong
2020-08-17 23:00 ` [PATCH 15/18] xfs_db: support printing time limits Darrick J. Wong
2020-08-17 23:00 ` [PATCH 16/18] xfs_db: add bigtime upgrade path Darrick J. Wong
2020-08-18 15:17   ` Amir Goldstein
2020-08-17 23:00 ` [PATCH 17/18] xfs_repair: support bigtime Darrick J. Wong
2020-08-18 14:58   ` Amir Goldstein
2020-08-18 15:32     ` Darrick J. Wong
2020-08-17 23:00 ` [PATCH 18/18] mkfs: format bigtime filesystems Darrick J. Wong
2020-08-18 14:45   ` Amir Goldstein
2020-08-18 15:34     ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=159770520929.3958786.2869468837745844258.stgit@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.