summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjkar8572 <jkar8572>2001-03-26 14:56:54 +0000
committerjkar8572 <jkar8572>2001-03-26 14:56:54 +0000
commitec1d4ef4651205d3815163d161edc538b5e4e665 (patch)
treec18081d14a33d4f2e9e6d16904f12cde2ff5bc81
parent869fe242340fefe0540fdcf51698ba4c3c8c07bb (diff)
Fixed bugs in XFS quota option detection.
-rw-r--r--quotaio_xfs.c18
-rw-r--r--quotaon_xfs.c7
-rw-r--r--quotasys.c48
3 files changed, 62 insertions, 11 deletions
diff --git a/quotaio_xfs.c b/quotaio_xfs.c
index dc20f55..73c963e 100644
--- a/quotaio_xfs.c
+++ b/quotaio_xfs.c
@@ -19,6 +19,11 @@
#include "quotasys.h"
#include "dqblk_xfs.h"
+#define XFS_USRQUOTA(h) ((h)->qh_type == USRQUOTA && \
+ (h)->qh_info.u.xfs_mdqi.qs_flags & XFS_QUOTA_UDQ_ACCT)
+#define XFS_GRPQUOTA(h) ((h)->qh_type == GRPQUOTA && \
+ (h)->qh_info.u.xfs_mdqi.qs_flags & XFS_QUOTA_GDQ_ACCT)
+
static int xfs_init_io(struct quota_handle *h);
static int xfs_write_info(struct quota_handle *h);
static struct dquot *xfs_read_dquot(struct quota_handle *h, qid_t id);
@@ -94,6 +99,9 @@ static int xfs_write_info(struct quota_handle *h)
struct xfs_kern_dqblk xdqblk;
int qcmd;
+ if (!XFS_USRQUOTA(h) && !XFS_GRPQUOTA(h))
+ return 0;
+
memset(&xdqblk, 0, sizeof(struct xfs_kern_dqblk));
xdqblk.d_btimer = h->qh_info.dqi_bgrace;
@@ -116,6 +124,10 @@ static struct dquot *xfs_read_dquot(struct quota_handle *h, qid_t id)
dquot->dq_id = id;
dquot->dq_h = h;
+
+ if (!XFS_USRQUOTA(h) && !XFS_GRPQUOTA(h))
+ return dquot;
+
qcmd = QCMD(Q_XFS_GETQUOTA, h->qh_type);
if (quotactl(qcmd, h->qh_quotadev, id, (void *)&xdqblk) < 0) {
;
@@ -138,6 +150,9 @@ static int xfs_commit_dquot(struct dquot *dquot)
qid_t id = dquot->dq_id;
int qcmd;
+ if (!XFS_USRQUOTA(h) && !XFS_GRPQUOTA(h))
+ return 0;
+
xfs_util2kerndqblk(&xdqblk, &dquot->dq_dqb);
xdqblk.d_fieldmask |= FS_DQ_LIMIT_MASK;
qcmd = QCMD(Q_XFS_SETQLIM, h->qh_type);
@@ -181,6 +196,9 @@ static int xfs_scan_dquots(struct quota_handle *h, int (*process_dquot) (struct
struct xfs_kern_dqblk d;
int rd = 0;
+ if (!XFS_USRQUOTA(h) && !XFS_GRPQUOTA(h))
+ return rd;
+
dq = get_empty_dquot();
dq->dq_h = h;
if (h->qh_type == USRQUOTA) {
diff --git a/quotaon_xfs.c b/quotaon_xfs.c
index a3c0480..4252fcf 100644
--- a/quotaon_xfs.c
+++ b/quotaon_xfs.c
@@ -122,12 +122,13 @@ static int xfs_state_check(int qcmd, int type, int flags, char *dev, int root, i
static int xfs_onoff(char *dev, int type, int flags, int rootfs, int *xopts)
{
- int qoff, qcmd;
+ int qoff, qcmd, check;
qoff = (flags & STATEFLAG_OFF);
qcmd = qoff ? Q_XFS_QUOTAOFF : Q_XFS_QUOTAON;
- if (xfs_state_check(qcmd, type, flags, dev, rootfs, xopts) < 0)
- return 1;
+ check = xfs_state_check(qcmd, type, flags, dev, rootfs, xopts);
+ if (check != 1)
+ return (check < 0);
if (quotactl(QCMD(qcmd, type), dev, 0, (void *)xopts) < 0) {
fprintf(stderr, qoff ? "quotaoff: " : "quotaon: ");
diff --git a/quotasys.c b/quotasys.c
index d4d5f80..01badd4 100644
--- a/quotasys.c
+++ b/quotasys.c
@@ -197,6 +197,38 @@ void time2str(time_t seconds, char *buf, int flags)
}
/*
+ * Check for XFS filesystem with quota accounting enabled
+ */
+static int hasxfsquota(struct mntent *mnt, int type)
+{
+ int ret = 0;
+ u_int16_t sbflags;
+ struct xfs_mem_dqinfo info;
+ int nonrootfs = strcmp(mnt->mnt_dir, "/");
+ const char *dev = get_device_name(mnt->mnt_fsname);
+
+ if (!dev)
+ return ret;
+
+ memset(&info, 0, sizeof(struct xfs_mem_dqinfo));
+ if (!quotactl(QCMD(Q_XFS_GETQSTAT, type), dev, 0, (void *)&info)) {
+ sbflags = (info.qs_flags & 0xff00) >> 8;
+ if (type == USRQUOTA && (info.qs_flags & XFS_QUOTA_UDQ_ACCT))
+ ret = 1;
+ else if (type == GRPQUOTA && (info.qs_flags & XFS_QUOTA_GDQ_ACCT))
+ ret = 1;
+ else if (nonrootfs)
+ ret = 0;
+ else if (type == USRQUOTA && (sbflags & XFS_QUOTA_UDQ_ACCT))
+ ret = 1;
+ else if (type == GRPQUOTA && (sbflags & XFS_QUOTA_GDQ_ACCT))
+ ret = 1;
+ }
+ free((char *)dev);
+ return ret;
+}
+
+/*
* Check to see if a particular quota is to be enabled (filesystem mounted with proper option)
*/
int hasquota(struct mntent *mnt, int type)
@@ -206,14 +238,14 @@ int hasquota(struct mntent *mnt, int type)
if (!CORRECT_FSTYPE(mnt->mnt_type))
return 0;
- option = hasmntopt(mnt, MNTOPT_USRQUOTA);
- if ((type == USRQUOTA) && (option || !strcmp(mnt->mnt_type, MNTTYPE_XFS)))
+ if (!strcmp(mnt->mnt_type, MNTTYPE_XFS))
+ return hasxfsquota(mnt, type);
+
+ if ((type == USRQUOTA) && (option = hasmntopt(mnt, MNTOPT_USRQUOTA)))
return 1;
- option = hasmntopt(mnt, MNTOPT_GRPQUOTA);
- if ((type == GRPQUOTA) && (option || !strcmp(mnt->mnt_type, MNTTYPE_XFS)))
+ if ((type == GRPQUOTA) && (option = hasmntopt(mnt, MNTOPT_GRPQUOTA)))
return 1;
- option = hasmntopt(mnt, MNTOPT_QUOTA);
- if ((type == USRQUOTA) && (option || !strcmp(mnt->mnt_type, MNTTYPE_XFS)))
+ if ((type == USRQUOTA) && (option = hasmntopt(mnt, MNTOPT_QUOTA)))
return 1;
return 0;
}
@@ -418,9 +450,9 @@ static int xfs_kern_quota_on(const char *dev, int type)
struct xfs_mem_dqinfo info;
if (!quotactl(QCMD(Q_XFS_GETQSTAT, type), dev, 0, (void *)&info)) {
- if (type == USRQUOTA && info.qs_flags & XFS_QUOTA_UDQ_ACCT)
+ if (type == USRQUOTA && (info.qs_flags & XFS_QUOTA_UDQ_ACCT))
return 1;
- else if (type == GRPQUOTA && info.qs_flags & XFS_QUOTA_GDQ_ACCT)
+ if (type == GRPQUOTA && (info.qs_flags & XFS_QUOTA_GDQ_ACCT))
return 1;
}
return 0;