Blame SOURCES/quota-4.03-Scan-dquots-using-Q_GETNEXTQUOTA.patch

370c56
From 85687833434d50e3f5fd4b849e543eb505bf5a20 Mon Sep 17 00:00:00 2001
370c56
From: Jan Kara <jack@suse.cz>
370c56
Date: Tue, 26 Jan 2016 13:10:59 +0100
370c56
Subject: [PATCH 1/2] Scan dquots using Q_GETNEXTQUOTA
370c56
MIME-Version: 1.0
370c56
Content-Type: text/plain; charset=UTF-8
370c56
Content-Transfer-Encoding: 8bit
370c56
370c56
Check for new kernel quotactl Q_GETNEXTQUOTA and if available use it for
370c56
scanning all dquot structures.
370c56
370c56
Signed-off-by: Jan Kara <jack@suse.cz>
370c56
Signed-off-by: Petr Písař <ppisar@redhat.com>
370c56
---
370c56
 quota.h           | 14 ++++++++++++++
370c56
 quotaio_generic.c | 34 ++++++++++++++++++++++++++++++++++
370c56
 quotaio_generic.h |  4 ++++
370c56
 quotaio_meta.c    | 14 +++++++++++++-
370c56
 4 files changed, 65 insertions(+), 1 deletion(-)
370c56
370c56
diff --git a/quota.h b/quota.h
370c56
index 0c38427..0607e04 100644
370c56
--- a/quota.h
370c56
+++ b/quota.h
370c56
@@ -63,6 +63,7 @@ typedef int64_t qsize_t;	/* Type in which we store size limitations */
370c56
 #define Q_SETINFO  0x800006	/* set information about quota files */
370c56
 #define Q_GETQUOTA 0x800007	/* get user quota structure */
370c56
 #define Q_SETQUOTA 0x800008	/* set user quota structure */
370c56
+#define Q_GETNEXTQUOTA 0x800009	/* get disk limits and usage >= ID */
370c56
 
370c56
 /*
370c56
  * Quota structure used for communication with userspace via quotactl
370c56
@@ -91,6 +92,19 @@ struct if_dqblk {
370c56
 	u_int32_t dqb_valid;
370c56
 };
370c56
 
370c56
+struct if_nextdqblk {
370c56
+	u_int64_t dqb_bhardlimit;
370c56
+	u_int64_t dqb_bsoftlimit;
370c56
+	u_int64_t dqb_curspace;
370c56
+	u_int64_t dqb_ihardlimit;
370c56
+	u_int64_t dqb_isoftlimit;
370c56
+	u_int64_t dqb_curinodes;
370c56
+	u_int64_t dqb_btime;
370c56
+	u_int64_t dqb_itime;
370c56
+	u_int32_t dqb_valid;
370c56
+	u_int32_t dqb_id;
370c56
+};
370c56
+
370c56
 /*
370c56
  * Structure used for setting quota information about file via quotactl
370c56
  * Following flags are used to specify which fields are valid
370c56
diff --git a/quotaio_generic.c b/quotaio_generic.c
370c56
index 5001a56..4bdf380 100644
370c56
--- a/quotaio_generic.c
370c56
+++ b/quotaio_generic.c
370c56
@@ -161,3 +161,37 @@ int generic_scan_dquots(struct quota_handle *h,
370c56
 	free(dquot);
370c56
 	return ret;
370c56
 }
370c56
+
370c56
+int vfs_scan_dquots(struct quota_handle *h,
370c56
+		    int (*process_dquot)(struct dquot *dquot, char *dqname))
370c56
+{
370c56
+	struct dquot *dquot = get_empty_dquot();
370c56
+	qid_t id = 0;
370c56
+	struct if_nextdqblk kdqblk;
370c56
+	int ret;
370c56
+
370c56
+	dquot->dq_h = h;
370c56
+	while (1) {
370c56
+		ret = quotactl(QCMD(Q_GETNEXTQUOTA, h->qh_type),
370c56
+			       h->qh_quotadev, id, (void *)&kdqblk);
370c56
+		if (ret < 0)
370c56
+			break;
370c56
+
370c56
+		/*
370c56
+		 * This is a slight hack but we know struct if_dqblk is a
370c56
+		 * subset of struct if_nextdqblk
370c56
+		 */
370c56
+		generic_kern2utildqblk(&dquot->dq_dqb,
370c56
+				       (struct if_dqblk *)&kdqblk);
370c56
+		dquot->dq_id = kdqblk.dqb_id;
370c56
+		ret = process_dquot(dquot, NULL);
370c56
+		if (ret < 0)
370c56
+			break;
370c56
+		id = kdqblk.dqb_id + 1;
370c56
+	}
370c56
+	free(dquot);
370c56
+
370c56
+	if (errno == ENOENT)
370c56
+		return 0;
370c56
+	return ret;
370c56
+}
370c56
diff --git a/quotaio_generic.h b/quotaio_generic.h
370c56
index 5edc11c..a7930f0 100644
370c56
--- a/quotaio_generic.h
370c56
+++ b/quotaio_generic.h
370c56
@@ -27,4 +27,8 @@ int generic_scan_dquots(struct quota_handle *h,
370c56
 			int (*process_dquot)(struct dquot *dquot, char *dqname),
370c56
 			int (*get_dquot)(struct dquot *dquot));
370c56
 
370c56
+/* Scan all dquots using kernel quotactl to get existing ids */
370c56
+int vfs_scan_dquots(struct quota_handle *h,
370c56
+		    int (*process_dquot)(struct dquot *dquot, char *dqname));
370c56
+
370c56
 #endif
370c56
diff --git a/quotaio_meta.c b/quotaio_meta.c
370c56
index e52b4f4..ad6ff7a 100644
370c56
--- a/quotaio_meta.c
370c56
+++ b/quotaio_meta.c
370c56
@@ -8,6 +8,7 @@
370c56
 
370c56
 #include <string.h>
370c56
 #include <stdlib.h>
370c56
+#include <errno.h>
370c56
 
370c56
 #include <sys/types.h>
370c56
 
370c56
@@ -55,7 +56,18 @@ static int meta_commit_dquot(struct dquot *dquot, int flags)
370c56
 
370c56
 static int meta_scan_dquots(struct quota_handle *h, int (*process_dquot)(struct dquot *dquot, char *dqname))
370c56
 {
370c56
-	return generic_scan_dquots(h, process_dquot, vfs_get_dquot);
370c56
+	struct if_nextdqblk kdqblk;
370c56
+	int ret;
370c56
+
370c56
+	ret = quotactl(QCMD(Q_GETNEXTQUOTA, h->qh_type), h->qh_quotadev, 0,
370c56
+		       (void *)&kdqblk);
370c56
+	/*
370c56
+	 * Fall back to scanning using passwd if Q_GETNEXTQUOTA is not
370c56
+	 * supported
370c56
+	 */
370c56
+	if (ret < 0 && (errno == ENOSYS || errno == EINVAL))
370c56
+		return generic_scan_dquots(h, process_dquot, vfs_get_dquot);
370c56
+	return vfs_scan_dquots(h, process_dquot);
370c56
 }
370c56
 
370c56
 struct quotafile_ops quotafile_ops_meta = {
370c56
-- 
370c56
2.5.0
370c56