summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2016-01-26 13:10:59 +0100
committerJan Kara <jack@suse.cz>2016-01-27 12:16:20 +0100
commit85687833434d50e3f5fd4b849e543eb505bf5a20 (patch)
tree6e38f4cdfaa916d8b24bbfae2dd314cfaaaa1d15
parent1d9542df5d2ae5c21a1e96d100f899b3d7b2f27c (diff)
downloadquota-tools-85687833434d50e3f5fd4b849e543eb505bf5a20.tar.gz
Scan dquots using Q_GETNEXTQUOTA
Check for new kernel quotactl Q_GETNEXTQUOTA and if available use it for scanning all dquot structures. Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r--quota.h14
-rw-r--r--quotaio_generic.c34
-rw-r--r--quotaio_generic.h4
-rw-r--r--quotaio_meta.c14
4 files changed, 65 insertions, 1 deletions
diff --git a/quota.h b/quota.h
index 0c38427..0607e04 100644
--- a/quota.h
+++ b/quota.h
@@ -63,6 +63,7 @@ typedef int64_t qsize_t; /* Type in which we store size limitations */
#define Q_SETINFO 0x800006 /* set information about quota files */
#define Q_GETQUOTA 0x800007 /* get user quota structure */
#define Q_SETQUOTA 0x800008 /* set user quota structure */
+#define Q_GETNEXTQUOTA 0x800009 /* get disk limits and usage >= ID */
/*
* Quota structure used for communication with userspace via quotactl
@@ -91,6 +92,19 @@ struct if_dqblk {
u_int32_t dqb_valid;
};
+struct if_nextdqblk {
+ u_int64_t dqb_bhardlimit;
+ u_int64_t dqb_bsoftlimit;
+ u_int64_t dqb_curspace;
+ u_int64_t dqb_ihardlimit;
+ u_int64_t dqb_isoftlimit;
+ u_int64_t dqb_curinodes;
+ u_int64_t dqb_btime;
+ u_int64_t dqb_itime;
+ u_int32_t dqb_valid;
+ u_int32_t dqb_id;
+};
+
/*
* Structure used for setting quota information about file via quotactl
* Following flags are used to specify which fields are valid
diff --git a/quotaio_generic.c b/quotaio_generic.c
index 5001a56..4bdf380 100644
--- a/quotaio_generic.c
+++ b/quotaio_generic.c
@@ -161,3 +161,37 @@ int generic_scan_dquots(struct quota_handle *h,
free(dquot);
return ret;
}
+
+int vfs_scan_dquots(struct quota_handle *h,
+ int (*process_dquot)(struct dquot *dquot, char *dqname))
+{
+ struct dquot *dquot = get_empty_dquot();
+ qid_t id = 0;
+ struct if_nextdqblk kdqblk;
+ int ret;
+
+ dquot->dq_h = h;
+ while (1) {
+ ret = quotactl(QCMD(Q_GETNEXTQUOTA, h->qh_type),
+ h->qh_quotadev, id, (void *)&kdqblk);
+ if (ret < 0)
+ break;
+
+ /*
+ * This is a slight hack but we know struct if_dqblk is a
+ * subset of struct if_nextdqblk
+ */
+ generic_kern2utildqblk(&dquot->dq_dqb,
+ (struct if_dqblk *)&kdqblk);
+ dquot->dq_id = kdqblk.dqb_id;
+ ret = process_dquot(dquot, NULL);
+ if (ret < 0)
+ break;
+ id = kdqblk.dqb_id + 1;
+ }
+ free(dquot);
+
+ if (errno == ENOENT)
+ return 0;
+ return ret;
+}
diff --git a/quotaio_generic.h b/quotaio_generic.h
index 5edc11c..a7930f0 100644
--- a/quotaio_generic.h
+++ b/quotaio_generic.h
@@ -27,4 +27,8 @@ int generic_scan_dquots(struct quota_handle *h,
int (*process_dquot)(struct dquot *dquot, char *dqname),
int (*get_dquot)(struct dquot *dquot));
+/* Scan all dquots using kernel quotactl to get existing ids */
+int vfs_scan_dquots(struct quota_handle *h,
+ int (*process_dquot)(struct dquot *dquot, char *dqname));
+
#endif
diff --git a/quotaio_meta.c b/quotaio_meta.c
index e52b4f4..ad6ff7a 100644
--- a/quotaio_meta.c
+++ b/quotaio_meta.c
@@ -8,6 +8,7 @@
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
#include <sys/types.h>
@@ -55,7 +56,18 @@ static int meta_commit_dquot(struct dquot *dquot, int flags)
static int meta_scan_dquots(struct quota_handle *h, int (*process_dquot)(struct dquot *dquot, char *dqname))
{
- return generic_scan_dquots(h, process_dquot, vfs_get_dquot);
+ struct if_nextdqblk kdqblk;
+ int ret;
+
+ ret = quotactl(QCMD(Q_GETNEXTQUOTA, h->qh_type), h->qh_quotadev, 0,
+ (void *)&kdqblk);
+ /*
+ * Fall back to scanning using passwd if Q_GETNEXTQUOTA is not
+ * supported
+ */
+ if (ret < 0 && (errno == ENOSYS || errno == EINVAL))
+ return generic_scan_dquots(h, process_dquot, vfs_get_dquot);
+ return vfs_scan_dquots(h, process_dquot);
}
struct quotafile_ops quotafile_ops_meta = {