From 304bed24716fdbb7c636ea8df0462d4f979f23a0 Mon Sep 17 00:00:00 2001
From: Jan Kara <jack@suse.cz>
Date: Tue, 26 Jan 2016 14:06:59 +0100
Subject: [PATCH 2/2] Add support for scanning using Q_XGETNEXTQUOTA
Add support for scanning of all available quota structures using
Q_XGETNEXTQUOTA quotactl.
Signed-off-by: Jan Kara <jack@suse.cz>
---
quotaio_xfs.c | 42 +++++++++++++++++++++++++++++++++++++++---
quotaio_xfs.h | 1 +
2 files changed, 40 insertions(+), 3 deletions(-)
@@ -191,15 +191,51 @@ static int xfs_get_dquot(struct dquot *dq)
return 0;
}
+static int xfs_kernel_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 xfs_kern_dqblk xdqblk;
+ int ret;
+
+ dquot->dq_h = h;
+ while (1) {
+ ret = quotactl(QCMD(Q_XGETNEXTQUOTA, h->qh_type),
+ h->qh_quotadev, id, (void *)&xdqblk);
+ if (ret < 0)
+ break;
+
+ xfs_kern2utildqblk(&dquot->dq_dqb, &xdqblk);
+ dquot->dq_id = xdqblk.d_id;
+ ret = process_dquot(dquot, NULL);
+ if (ret < 0)
+ break;
+ id = xdqblk.d_id + 1;
+ }
+ free(dquot);
+
+ if (errno == ESRCH)
+ return 0;
+ return ret;
+}
+
/*
* Scan all known dquots and call callback on each
*/
static int xfs_scan_dquots(struct quota_handle *h, int (*process_dquot) (struct dquot *dquot, char *dqname))
{
- if (!XFS_USRQUOTA(h) && !XFS_GRPQUOTA(h))
- return 0;
+ int ret;
+ struct xfs_kern_dqblk xdqblk;
- return generic_scan_dquots(h, process_dquot, xfs_get_dquot);
+ ret = quotactl(QCMD(Q_XGETNEXTQUOTA, h->qh_type), h->qh_quotadev, 0,
+ (void *)&xdqblk);
+ if (ret < 0 && (errno == ENOSYS || errno == EINVAL)) {
+ if (!XFS_USRQUOTA(h) && !XFS_GRPQUOTA(h))
+ return 0;
+ return generic_scan_dquots(h, process_dquot, xfs_get_dquot);
+ }
+ return xfs_kernel_scan_dquots(h, process_dquot);
}
/*
@@ -46,6 +46,7 @@
#define Q_XSETQLIM XQM_CMD(0x4) /* set disk limits only */
#define Q_XGETQSTAT XQM_CMD(0x5) /* returns fs_quota_stat_t struct */
#define Q_XQUOTARM XQM_CMD(0x6) /* free quota files' space */
+#define Q_XGETNEXTQUOTA XQM_CMD(0x9) /* get disk limits and usage >= ID */
/*
* fs_disk_quota structure:
--
2.6.2