Commit 847aac64 authored by Li Xi's avatar Li Xi Committed by Jan Kara

vfs: Add general support to enforce project quota limits

This patch adds support for a new quota type PRJQUOTA for project quota
enforcement. Also a new method get_projid() is added into dquot_operations
structure.
Signed-off-by: default avatarLi Xi <lixi@ddn.com>
Signed-off-by: default avatarDmitry Monakhov <dmonakhov@openvz.org>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 5ce1aca8
...@@ -1163,8 +1163,8 @@ static int need_print_warning(struct dquot_warn *warn) ...@@ -1163,8 +1163,8 @@ static int need_print_warning(struct dquot_warn *warn)
return uid_eq(current_fsuid(), warn->w_dq_id.uid); return uid_eq(current_fsuid(), warn->w_dq_id.uid);
case GRPQUOTA: case GRPQUOTA:
return in_group_p(warn->w_dq_id.gid); return in_group_p(warn->w_dq_id.gid);
case PRJQUOTA: /* Never taken... Just make gcc happy */ case PRJQUOTA:
return 0; return 1;
} }
return 0; return 0;
} }
...@@ -1405,6 +1405,9 @@ static void __dquot_initialize(struct inode *inode, int type) ...@@ -1405,6 +1405,9 @@ static void __dquot_initialize(struct inode *inode, int type)
/* First get references to structures we might need. */ /* First get references to structures we might need. */
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
struct kqid qid; struct kqid qid;
kprojid_t projid;
int rc;
got[cnt] = NULL; got[cnt] = NULL;
if (type != -1 && cnt != type) if (type != -1 && cnt != type)
continue; continue;
...@@ -1415,6 +1418,10 @@ static void __dquot_initialize(struct inode *inode, int type) ...@@ -1415,6 +1418,10 @@ static void __dquot_initialize(struct inode *inode, int type)
*/ */
if (dquots[cnt]) if (dquots[cnt])
continue; continue;
if (!sb_has_quota_active(sb, cnt))
continue;
init_needed = 1; init_needed = 1;
switch (cnt) { switch (cnt) {
...@@ -1424,6 +1431,12 @@ static void __dquot_initialize(struct inode *inode, int type) ...@@ -1424,6 +1431,12 @@ static void __dquot_initialize(struct inode *inode, int type)
case GRPQUOTA: case GRPQUOTA:
qid = make_kqid_gid(inode->i_gid); qid = make_kqid_gid(inode->i_gid);
break; break;
case PRJQUOTA:
rc = inode->i_sb->dq_op->get_projid(inode, &projid);
if (rc)
continue;
qid = make_kqid_projid(projid);
break;
} }
got[cnt] = dqget(sb, qid); got[cnt] = dqget(sb, qid);
} }
...@@ -2176,7 +2189,8 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id, ...@@ -2176,7 +2189,8 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,
error = -EROFS; error = -EROFS;
goto out_fmt; goto out_fmt;
} }
if (!sb->s_op->quota_write || !sb->s_op->quota_read) { if (!sb->s_op->quota_write || !sb->s_op->quota_read ||
(type == PRJQUOTA && sb->dq_op->get_projid == NULL)) {
error = -EINVAL; error = -EINVAL;
goto out_fmt; goto out_fmt;
} }
......
...@@ -13,12 +13,14 @@ ...@@ -13,12 +13,14 @@
*/ */
#define V2_INITQMAGICS {\ #define V2_INITQMAGICS {\
0xd9c01f11, /* USRQUOTA */\ 0xd9c01f11, /* USRQUOTA */\
0xd9c01927 /* GRPQUOTA */\ 0xd9c01927, /* GRPQUOTA */\
0xd9c03f14, /* PRJQUOTA */\
} }
#define V2_INITQVERSIONS {\ #define V2_INITQVERSIONS {\
1, /* USRQUOTA */\ 1, /* USRQUOTA */\
1 /* GRPQUOTA */\ 1, /* GRPQUOTA */\
1, /* PRJQUOTA */\
} }
/* First generic header */ /* First generic header */
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#undef USRQUOTA #undef USRQUOTA
#undef GRPQUOTA #undef GRPQUOTA
#undef PRJQUOTA
enum quota_type { enum quota_type {
USRQUOTA = 0, /* element used for user quotas */ USRQUOTA = 0, /* element used for user quotas */
GRPQUOTA = 1, /* element used for group quotas */ GRPQUOTA = 1, /* element used for group quotas */
...@@ -319,6 +320,7 @@ struct dquot_operations { ...@@ -319,6 +320,7 @@ struct dquot_operations {
/* get reserved quota for delayed alloc, value returned is managed by /* get reserved quota for delayed alloc, value returned is managed by
* quota code only */ * quota code only */
qsize_t *(*get_reserved_space) (struct inode *); qsize_t *(*get_reserved_space) (struct inode *);
int (*get_projid) (struct inode *, kprojid_t *);/* Get project ID */
}; };
struct path; struct path;
......
...@@ -36,11 +36,12 @@ ...@@ -36,11 +36,12 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#define __DQUOT_VERSION__ "dquot_6.5.2" #define __DQUOT_VERSION__ "dquot_6.6.0"
#define MAXQUOTAS 2 #define MAXQUOTAS 3
#define USRQUOTA 0 /* element used for user quotas */ #define USRQUOTA 0 /* element used for user quotas */
#define GRPQUOTA 1 /* element used for group quotas */ #define GRPQUOTA 1 /* element used for group quotas */
#define PRJQUOTA 2 /* element used for project quotas */
/* /*
* Definitions for the default names of the quotas files. * Definitions for the default names of the quotas files.
...@@ -48,6 +49,7 @@ ...@@ -48,6 +49,7 @@
#define INITQFNAMES { \ #define INITQFNAMES { \
"user", /* USRQUOTA */ \ "user", /* USRQUOTA */ \
"group", /* GRPQUOTA */ \ "group", /* GRPQUOTA */ \
"project", /* PRJQUOTA */ \
"undefined", \ "undefined", \
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment