Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/bouyer-quota2]: src/sys/ufs Reimplement quotactl commands for quota1
details: https://anonhg.NetBSD.org/src/rev/a05b0d50caef
branches: bouyer-quota2
changeset: 761147:a05b0d50caef
user: bouyer <bouyer%NetBSD.org@localhost>
date: Wed Feb 09 16:15:01 2011 +0000
description:
Reimplement quotactl commands for quota1
diffstat:
sys/ufs/files.ufs | 3 +-
sys/ufs/ufs/ufs_quota.c | 81 ++++++++++++++++++++++++++-
sys/ufs/ufs/ufs_quota.h | 5 +-
sys/ufs/ufs/ufs_quota1.c | 142 +++++++++++++++++++++++++++++++++++-----------
4 files changed, 192 insertions(+), 39 deletions(-)
diffs (truncated from 396 to 300 lines):
diff -r b9da7d281a4d -r a05b0d50caef sys/ufs/files.ufs
--- a/sys/ufs/files.ufs Wed Feb 09 16:10:18 2011 +0000
+++ b/sys/ufs/files.ufs Wed Feb 09 16:15:01 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.ufs,v 1.24.6.2 2011/02/09 11:18:29 bouyer Exp $
+# $NetBSD: files.ufs,v 1.24.6.3 2011/02/09 16:15:01 bouyer Exp $
deffs FFS
deffs EXT2FS
@@ -62,6 +62,7 @@
file ufs/ufs/ufs_quota.c (quota | quota2) & (ffs | lfs | mfs | ext2fs)
file ufs/ufs/ufs_quota1.c quota & (ffs | lfs | mfs | ext2fs)
file ufs/ufs/ufs_quota2.c quota2 & (ffs | lfs | mfs | ext2fs)
+file ufs/ufs/quota1_subr.c quota & (ffs | lfs | mfs | ext2fs)
file ufs/ufs/quota2_subr.c quota2 & (ffs | lfs | mfs | ext2fs)
file ufs/ufs/quota2_prop.c (quota | quota2) & (ffs | lfs | mfs | ext2fs)
file ufs/ufs/ufs_vfsops.c ffs | lfs | mfs | ext2fs
diff -r b9da7d281a4d -r a05b0d50caef sys/ufs/ufs/ufs_quota.c
--- a/sys/ufs/ufs/ufs_quota.c Wed Feb 09 16:10:18 2011 +0000
+++ b/sys/ufs/ufs/ufs_quota.c Wed Feb 09 16:15:01 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota.c,v 1.68.4.10 2011/02/09 11:18:30 bouyer Exp $ */
+/* $NetBSD: ufs_quota.c,v 1.68.4.11 2011/02/09 16:15:01 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.10 2011/02/09 11:18:30 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.11 2011/02/09 16:15:01 bouyer Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@@ -82,6 +82,10 @@
prop_dictionary_t, int, prop_array_t);
static int quota_handle_cmd_clear(struct mount *, struct lwp *,
prop_dictionary_t, int, prop_array_t);
+static int quota_handle_cmd_quotaon(struct mount *, struct lwp *,
+ prop_dictionary_t, int, prop_array_t);
+static int quota_handle_cmd_quotaoff(struct mount *, struct lwp *,
+ prop_dictionary_t, int, prop_array_t);
/*
* Initialize the quota fields of an inode.
*/
@@ -171,6 +175,16 @@
error = quota_handle_cmd_get_version(mp, l, cmddict, datas);
goto end;
}
+ if (strcmp(cmd, "quotaon") == 0) {
+ error = quota_handle_cmd_quotaon(mp, l, cmddict,
+ q2type, datas);
+ goto end;
+ }
+ if (strcmp(cmd, "quotaoff") == 0) {
+ error = quota_handle_cmd_quotaoff(mp, l, cmddict,
+ q2type, datas);
+ goto end;
+ }
if (strcmp(cmd, "get") == 0) {
error = quota_handle_cmd_get(mp, l, cmddict, q2type, datas);
goto end;
@@ -487,6 +501,69 @@
return error;
}
+static int
+quota_handle_cmd_quotaon(struct mount *mp, struct lwp *l,
+ prop_dictionary_t cmddict, int type, prop_array_t datas)
+{
+ prop_dictionary_t data;
+ struct ufsmount *ump = VFSTOUFS(mp);
+ int error;
+ const char *qfile;
+
+ if ((ump->um_flags & UFS_QUOTA2) != 0)
+ return EBUSY;
+
+ if (prop_array_count(datas) != 1)
+ return EINVAL;
+
+ data = prop_array_get(datas, 0);
+ if (data == NULL)
+ return ENOMEM;
+ if (!prop_dictionary_get_cstring_nocopy(data, "quotafile",
+ &qfile))
+ return EINVAL;
+
+ error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
+ KAUTH_REQ_SYSTEM_FS_QUOTA_ONOFF, mp, NULL, NULL);
+ if (error != 0) {
+ return error;
+ }
+#ifdef QUOTA
+ error = quota1_handle_cmd_quotaon(l, ump, type, qfile);
+#else
+ error = EOPNOTSUPP;
+#endif
+
+ return error;
+}
+
+static int
+quota_handle_cmd_quotaoff(struct mount *mp, struct lwp *l,
+ prop_dictionary_t cmddict, int type, prop_array_t datas)
+{
+ struct ufsmount *ump = VFSTOUFS(mp);
+ int error;
+
+ if ((ump->um_flags & UFS_QUOTA2) != 0)
+ return EOPNOTSUPP;
+
+ if (prop_array_count(datas) != 0)
+ return EINVAL;
+
+ error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
+ KAUTH_REQ_SYSTEM_FS_QUOTA_ONOFF, mp, NULL, NULL);
+ if (error != 0) {
+ return error;
+ }
+#ifdef QUOTA
+ error = quota1_handle_cmd_quotaoff(l, ump, type);
+#else
+ error = EOPNOTSUPP;
+#endif
+
+ return error;
+}
+
/*
* Initialize the quota system.
*/
diff -r b9da7d281a4d -r a05b0d50caef sys/ufs/ufs/ufs_quota.h
--- a/sys/ufs/ufs/ufs_quota.h Wed Feb 09 16:10:18 2011 +0000
+++ b/sys/ufs/ufs/ufs_quota.h Wed Feb 09 16:15:01 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota.h,v 1.1.2.8 2011/02/09 11:18:30 bouyer Exp $ */
+/* $NetBSD: ufs_quota.h,v 1.1.2.9 2011/02/09 16:15:01 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -115,6 +115,9 @@
int dq1sync(struct vnode *, struct dquot *);
int quota1_handle_cmd_get(struct ufsmount *, int, int, int, prop_array_t);
int quota1_handle_cmd_set(struct ufsmount *, int, int, int, prop_dictionary_t);
+int quota1_handle_cmd_quotaon(struct lwp *, struct ufsmount *, int,
+ const char *);
+int quota1_handle_cmd_quotaoff(struct lwp *, struct ufsmount *, int);
int chkdq2(struct inode *, int64_t, kauth_cred_t, int);
int chkiq2(struct inode *, int32_t, kauth_cred_t, int);
diff -r b9da7d281a4d -r a05b0d50caef sys/ufs/ufs/ufs_quota1.c
--- a/sys/ufs/ufs/ufs_quota1.c Wed Feb 09 16:10:18 2011 +0000
+++ b/sys/ufs/ufs/ufs_quota1.c Wed Feb 09 16:15:01 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota1.c,v 1.1.2.4 2011/02/09 12:01:20 bouyer Exp $ */
+/* $NetBSD: ufs_quota1.c,v 1.1.2.5 2011/02/09 16:15:01 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.1.2.4 2011/02/09 12:01:20 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.1.2.5 2011/02/09 16:15:01 bouyer Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -47,6 +47,7 @@
#include <sys/mount.h>
#include <sys/kauth.h>
+#include <ufs/ufs/quota2_prop.h>
#include <ufs/ufs/quota1.h>
#include <ufs/ufs/inode.h>
#include <ufs/ufs/ufsmount.h>
@@ -55,7 +56,6 @@
static int chkdqchg(struct inode *, int64_t, kauth_cred_t, int);
static int chkiqchg(struct inode *, int32_t, kauth_cred_t, int);
-static int quotaoff(struct lwp *, struct mount *, int);
/*
* Update disk usage, and take corrective action.
@@ -287,7 +287,7 @@
for (i = 0; i < MAXQUOTAS; i++) {
if (ump->um_quotas[i] != NULLVP) {
- quotaoff(l, mp, i);
+ quota1_handle_cmd_quotaoff(l, ump, i);
}
}
return 0;
@@ -297,14 +297,14 @@
* Code to process quotactl commands.
*/
-#if 0
/*
* set up a quota file for a particular file system.
*/
-static int
-quotaon(struct lwp *l, struct mount *mp, int type, void *fname)
+int
+quota1_handle_cmd_quotaon(struct lwp *l, struct ufsmount *ump, int type,
+ const char *fname)
{
- struct ufsmount *ump = VFSTOUFS(mp);
+ struct mount *mp = ump->um_mountp;
struct vnode *vp, **vpp, *mvp;
struct dquot *dq;
int error;
@@ -317,9 +317,8 @@
return (EBUSY);
}
- /* XXX XXX XXX */
if (mp->mnt_wapbl != NULL) {
- printf("%s: quotas cannot yet be used with -o log\n",
+ printf("%s: quota v1 cannot be used with -o log\n",
mp->mnt_stat.f_mntonname);
return (EOPNOTSUPP);
}
@@ -344,7 +343,7 @@
return (EACCES);
}
if (*vpp != vp)
- quotaoff(l, mp, type);
+ quota1_handle_cmd_quotaoff(l, ump, type);
mutex_enter(&dqlock);
while ((ump->umq1_qflags[type] & (QTF_CLOSING | QTF_OPENING)) != 0)
cv_wait(&dqcv, &dqlock);
@@ -414,20 +413,19 @@
ump->um_flags |= UFS_QUOTA;
mutex_exit(&dqlock);
if (error)
- quotaoff(l, mp, type);
+ quota1_handle_cmd_quotaoff(l, ump, type);
return (error);
}
-#endif
/*
* turn off disk quotas for a filesystem.
*/
-static int
-quotaoff(struct lwp *l, struct mount *mp, int type)
+int
+quota1_handle_cmd_quotaoff(struct lwp *l, struct ufsmount *ump, int type)
{
+ struct mount *mp = ump->um_mountp;
struct vnode *vp;
struct vnode *qvp, *mvp;
- struct ufsmount *ump = VFSTOUFS(mp);
struct dquot *dq;
struct inode *ip;
kauth_cred_t cred;
@@ -502,35 +500,109 @@
quota1_handle_cmd_get(struct ufsmount *ump, int type, int id,
int defaultq, prop_array_t replies)
{
- return EOPNOTSUPP;
+ struct dquot *dq;
+ struct quota2_entry q2e;
+ prop_dictionary_t dict;
+ int error;
+
+ if (ump->um_quotas[type] == NULLVP)
+ return ENODEV;
+
+ if (defaultq) { /* we want the grace period of id 0 */
+ if ((error = dqget(NULLVP, 0, ump, type, &dq)) != 0)
+ return error;
+ } else {
+ if ((error = dqget(NULLVP, id, ump, type, &dq)) != 0)
+ return error;
+ }
+ dqblk2q2e(&dq->dq_un.dq1_dqb, &q2e);
+ dqrele(NULLVP, dq);
+ if (defaultq) {
+ q2e.q2e_val[QL_BLOCK].q2v_grace = q2e.q2e_val[QL_BLOCK].q2v_time;
+ q2e.q2e_val[QL_FILE].q2v_grace = q2e.q2e_val[QL_FILE].q2v_time;
+ }
+ dict = q2etoprop(&q2e, defaultq);
+ if (dict == NULL)
+ return ENOMEM;
+ if (!prop_array_add_and_rel(replies, dict))
+ return ENOMEM;
+ return 0;
}
int
quota1_handle_cmd_set(struct ufsmount *ump, int type, int id,
int defaultq, prop_dictionary_t data)
{
- return EOPNOTSUPP;
+ struct dquot *dq;
+ struct quota2_entry q2e;
Home |
Main Index |
Thread Index |
Old Index