From: Eric Sandeen <sandeen@sandeen.net>
To: fsdevel <linux-fsdevel@vger.kernel.org>, xfs@oss.sgi.com
Cc: Jan Kara <jack@suse.cz>
Subject: [PATCH] linux-quota: wire Q_XGETQUOTA2 into generic repquota
Date: Fri, 8 Jan 2016 12:36:27 -0600 [thread overview]
Message-ID: <569001AB.5040604@sandeen.net> (raw)
In-Reply-To: <568FEA2C.6080708@redhat.com>
Here's a patch to hook Q_XGETQUOTA2 into the generic quota
tools repquota command.
Rather than looping over getpwent(), it increments the id sent
into the quotactl until it gets back ESRCH.
If Q_XGETQUOTA2 doesn't exist it falls back to the old method.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/dqblk_xfs.h b/dqblk_xfs.h
index 415e646..6c7693d 100644
--- a/dqblk_xfs.h
+++ b/dqblk_xfs.h
@@ -10,6 +10,7 @@
#define Q_XFS_QUOTAON Q_XQUOTAON
#define Q_XFS_QUOTAOFF Q_XQUOTAOFF
#define Q_XFS_GETQUOTA Q_XGETQUOTA
+#define Q_XFS_GETQUOTA2 Q_XGETQUOTA2
#define Q_XFS_SETQLIM Q_XSETQLIM
#define Q_XFS_GETQSTAT Q_XGETQSTAT
#define Q_XFS_QUOTARM Q_XQUOTARM
diff --git a/quotaio_generic.c b/quotaio_generic.c
index 5001a56..ad84cc0 100644
--- a/quotaio_generic.c
+++ b/quotaio_generic.c
@@ -161,3 +161,52 @@ int generic_scan_dquots(struct quota_handle *h,
free(dquot);
return ret;
}
+
+/* Generic quota scanning using Q_XGETQUOTA2... */
+int generic_scan_dquots2(struct quota_handle *h,
+ int (*process_dquot)(struct dquot *dquot, char *dqname),
+ int (*get_dquot)(struct dquot *dquot))
+{
+ struct dquot *dquot = get_empty_dquot();
+ char namebuf[MAXNAMELEN];
+ int ret = 0;
+
+ dquot->dq_id = 0;
+ dquot->dq_h = h;
+ if (h->qh_type == USRQUOTA) {
+ while (1) {
+ ret = scan_one_dquot(dquot, get_dquot);
+ if (ret < 0) {
+ if (errno == ESRCH)
+ ret =0;
+ break;
+ }
+ if (ret > 0)
+ continue;
+ id2name(dquot->dq_id, dquot->dq_h->qh_type, namebuf);
+ ret = process_dquot(dquot, namebuf);
+ if (ret < 0)
+ break;
+ dquot->dq_id++;
+ }
+ } else if (h->qh_type == GRPQUOTA) {
+ while (1) {
+ ret = scan_one_dquot(dquot, get_dquot);
+ if (ret < 0) {
+ if (errno == ESRCH)
+ ret =0;
+ break;
+ }
+ if (ret > 0)
+ continue;
+ id2name(dquot->dq_id, dquot->dq_h->qh_type, namebuf);
+ ret = process_dquot(dquot, namebuf);
+ if (ret < 0)
+ break;
+ dquot->dq_id++;
+ }
+ }
+ free(dquot);
+ return ret;
+}
+
diff --git a/quotaio_generic.h b/quotaio_generic.h
index 5edc11c..099a6b1 100644
--- a/quotaio_generic.h
+++ b/quotaio_generic.h
@@ -26,5 +26,9 @@ int vfs_set_dquot(struct dquot *dquot, int flags);
int generic_scan_dquots(struct quota_handle *h,
int (*process_dquot)(struct dquot *dquot, char *dqname),
int (*get_dquot)(struct dquot *dquot));
+/* Generic routine for scanning dquots when kernel can do the scanning */
+int generic_scan_dquots2(struct quota_handle *h,
+ int (*process_dquot)(struct dquot *dquot, char *dqname),
+ int (*get_dquot)(struct dquot *dquot));
#endif
diff --git a/quotaio_xfs.c b/quotaio_xfs.c
index 903c03e..a3f516b 100644
--- a/quotaio_xfs.c
+++ b/quotaio_xfs.c
@@ -192,14 +192,42 @@ static int xfs_get_dquot(struct dquot *dq)
}
/*
+ * xfs_scan_dquots helper - processes a single dquot with Q_XGETQUOTA2
+ */
+static int xfs_get_dquot2(struct dquot *dq)
+{
+ struct xfs_kern_dqblk d;
+ int qcmd = QCMD(Q_XFS_GETQUOTA2, dq->dq_h->qh_type);
+ int ret;
+
+ memset(&d, 0, sizeof(d));
+ ret = quotactl(qcmd, dq->dq_h->qh_quotadev, dq->dq_id, (void *)&d);
+ if (ret < 0) {
+ if (errno == ENOENT)
+ return 0;
+ return -1;
+ }
+ dq->dq_id = d.d_id;
+ xfs_kern2utildqblk(&dq->dq_dqb, &d);
+ return 0;
+}
+
+/*
* 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))
{
+ int ret;
+
if (!XFS_USRQUOTA(h) && !XFS_GRPQUOTA(h))
return 0;
- return generic_scan_dquots(h, process_dquot, xfs_get_dquot);
+ ret = generic_scan_dquots2(h, process_dquot, xfs_get_dquot2);
+
+ if (ret)
+ ret = generic_scan_dquots(h, process_dquot, xfs_get_dquot);
+
+ return ret;
}
/*
diff --git a/quotaio_xfs.h b/quotaio_xfs.h
index 54725b0..eabee3e 100644
--- a/quotaio_xfs.h
+++ b/quotaio_xfs.h
@@ -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_XGETQUOTA2 XQM_CMD(0x9) /* get disk limits and usage >= ID */
/*
* fs_disk_quota structure:
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2016-01-08 18:36 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-08 16:56 [PATCH 0/4] quota: add new quotactl Q_XGETQUOTA2 Eric Sandeen
2016-01-08 16:57 ` [PATCH 1/4] " Eric Sandeen
2016-01-08 16:57 ` [PATCH 2/4] xfs: get quota inode from mp & flags rather than dqp Eric Sandeen
2016-01-08 16:58 ` [PATCH 3/4] xfs: Factor xfs_seek_hole_data into helper Eric Sandeen
2016-01-08 17:07 ` [PATCH 3/4 V2] " Eric Sandeen
2016-01-11 15:57 ` [PATCH 3/4] " Jan Kara
2016-01-11 16:01 ` [PATCH 3/4 V3] " Eric Sandeen
2016-01-08 16:59 ` [PATCH 4/4] xfs: wire up Q_XGETQUOTA2 / get_dqblk2 Eric Sandeen
2016-01-08 18:36 ` Eric Sandeen [this message]
2016-01-09 7:26 ` [PATCH 0/4] quota: add new quotactl Q_XGETQUOTA2 Christoph Hellwig
2016-01-11 13:26 ` Jan Kara
2016-01-11 16:07 ` Eric Sandeen
2016-01-11 16:28 ` Jan Kara
2016-01-13 22:40 ` Eric Sandeen
2016-01-13 22:40 ` Eric Sandeen
2016-01-15 9:35 ` Jan Kara
2016-01-15 17:31 ` Eric Sandeen
2016-01-15 19:38 ` Eric Sandeen
2016-01-18 10:33 ` Jan Kara
2016-01-18 11:00 ` Christoph Hellwig
2016-01-18 15:18 ` Eric Sandeen
2016-01-18 15:40 ` Jan Kara
2016-01-19 0:31 ` Eric Sandeen
2016-01-15 22:50 ` Dave Chinner
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=569001AB.5040604@sandeen.net \
--to=sandeen@sandeen.net \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=xfs@oss.sgi.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox