quota: RFC add extend quota types
Subsystems (4)
cover quota: RFC add extend quota types
Jens, and other people who are interesting in quota please take a look and comment the patch series.
Currently only USER/GROUP quota are supported bu linux quota But sometimes it is reasonable to have other types of quota For example:
1) project_id in XFS
2) container_id in container(chroot) solutions.
This patch series is aimed to extend quota interface to support different quota types. Last patch add the TREE quota type. This patch series does not contain fs-related part of tree-quota-type support, i've done this in order to not overweight the series.
I'll add fs-related patches in the series on next round.
PATCH 1/3 quota: generalize quota transfer interface
Current quota transfer interface support only uid/gid. This patch extend interface in order to support various quotas types The goal is accomplished without changes in most frequently used vfs_dq_transfer() func.
--- fs/quota/dquot.c | 32 ++++++++++++++++++++------------ include/linux/quota.h | 2 +- include/linux/quotaops.h | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-)
fs/quota/dquot.c +20 -12
@@ -1638,15 +1638,13 @@ EXPORT_SYMBOL(dquot_free_inode);* This operation can block, but only after everything is updated * A transaction must be started when entering this function. */ -int dquot_transfer (struct inode *inode,struct iattr *iattr) +int dquot_transfer (struct inode *inode,qid_t *chid,unsigned long mask) {qsize_t space, cur_space;qsize_t rsv_space =0 ;struct dquot *transfer_from[MAXQUOTAS ];struct dquot *transfer_to[MAXQUOTAS ];int cnt, ret =QUOTA_OK ; -int chuid = iattr->ia_valid &ATTR_UID && inode->i_uid != iattr->ia_uid, - chgid = iattr->ia_valid &ATTR_GID && inode->i_gid != iattr->ia_gid;char warntype_to[MAXQUOTAS ];char warntype_from_inodes[MAXQUOTAS ], warntype_from_space[MAXQUOTAS ];
@@ -1660,13 +1658,10 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr) transfer_to[cnt] =NULL ; warntype_to[cnt] =QUOTA_NL_NOWARN ; } -if (chuid) - transfer_to[USRQUOTA ] =dqget (inode->i_sb, iattr->ia_uid, -USRQUOTA ); -if (chgid) - transfer_to[GRPQUOTA ] =dqget (inode->i_sb, iattr->ia_gid, -GRPQUOTA ); - +for (cnt =0 ; cnt <MAXQUOTAS ; cnt++) { +if (mask & (1 << cnt)) + transfer_to[cnt] =dqget (inode->i_sb, chid[cnt], cnt); + }down_write (&sb_dqopt (inode->i_sb)->dqptr_sem);if (IS_NOQUOTA (inode)) {/* File without quota accounting? */ up_write (&sb_dqopt (inode->i_sb)->dqptr_sem);
@@ -1742,12 +1737,25 @@ over_quota: }EXPORT_SYMBOL (dquot_transfer); -/* Wrapper for transferring ownership of an inode */ +/* Wrapper for transferring ownership of an inode for uid/gid only +* Called from FSXXX_setattr() +*/ int vfs_dq_transfer (struct inode *inode,struct iattr *iattr) { +qid_t chid[MAXQUOTAS ]; +unsigned long mask =0 ; + +if (iattr->ia_valid &ATTR_UID && iattr->ia_uid != inode->i_uid) { + mask |=1 <<USRQUOTA ; + chid[USRQUOTA ] = iattr->ia_uid; + } +if (iattr->ia_valid &ATTR_GID && iattr->ia_gid != inode->i_gid) { + mask |=1 <<GRPQUOTA ; + chid[GRPQUOTA ] = iattr->ia_gid; + }if (sb_any_quota_active (inode->i_sb) && !IS_NOQUOTA (inode)) {vfs_dq_init (inode); -if (inode->i_sb->dq_op->transfer (inode, iattr) ==NO_QUOTA ) +if (inode->i_sb->dq_op->transfer (inode, chid, mask) ==NO_QUOTA )return 1 ; }return 0 ;
include/linux/quota.h +1 -1
@@ -301,7 +301,7 @@ struct dquot_operations {int (*alloc_inode) (const struct inode *,qsize_t );int (*free_space) (struct inode *,qsize_t );int (*free_inode) (const struct inode *,qsize_t ); -int (*transfer) (struct inode *,struct iattr *); +int (*transfer) (struct inode *,qid_t *,unsigned long );int (*write_dquot) (struct dquot *);/* Ordinary dquot write */ struct dquot *(*alloc_dquot)(struct super_block *,int );/* Allocate memory for new dquot */ void (*destroy_dquot)(struct dquot *);/* Free memory for dquot */
include/linux/quotaops.h +1 -1
@@ -47,7 +47,7 @@ qsize_t dquot_get_reserved_space(struct inode *inode);int dquot_free_space (struct inode *inode,qsize_t number);int dquot_free_inode (const struct inode *inode,qsize_t number); -int dquot_transfer (struct inode *inode,struct iattr *iattr); +int dquot_transfer (struct inode *inode,qid_t *chid,unsigned long mask);int dquot_commit (struct dquot *dquot);int dquot_acquire (struct dquot *dquot);int dquot_release (struct dquot *dquot);
Signature · 1 line
1.6.3.3
PATCH 2/3 quota: introduce get_id callback
During some quota oparations we have to determine quota_id for given inode according to quota_type. But only USRQUOTA/GRPQUOTA id are intermediately accessible from generic vfs-inode. This patch introduce new per_sb quota operation for this purpose.
--- fs/ext3/super.c | 1 + fs/ext4/super.c | 1 + fs/ocfs2/quota_global.c | 1 + fs/quota/dquot.c | 26 ++++++++++++++++++-------- fs/reiserfs/super.c | 1 + include/linux/quota.h | 1 + include/linux/quotaops.h | 1 + 7 files changed, 24 insertions(+), 8 deletions(-)
fs/ext3/super.c +1 -0
@@ -757,6 +757,7 @@ static const struct dquot_operations ext3_quota_operations = { .free_space = dquot_free_space, .free_inode = dquot_free_inode, .transfer = dquot_transfer, + .get_id = dquot_get_id, .write_dquot = ext3_write_dquot, .acquire_dquot = ext3_acquire_dquot, .release_dquot = ext3_release_dquot,
fs/ext4/super.c +1 -0
@@ -1025,6 +1025,7 @@ static const struct dquot_operations ext4_quota_operations = { .free_space = dquot_free_space, .free_inode = dquot_free_inode, .transfer = dquot_transfer, + .get_id = dquot_get_id, .write_dquot = ext4_write_dquot, .acquire_dquot = ext4_acquire_dquot, .release_dquot = ext4_release_dquot,
fs/ocfs2/quota_global.c +1 -0
@@ -858,6 +858,7 @@ const struct dquot_operations ocfs2_quota_operations = { .free_space = dquot_free_space, .free_inode = dquot_free_inode, .transfer = dquot_transfer, + .get_id = dquot_get_id, .write_dquot = ocfs2_write_dquot, .acquire_dquot = ocfs2_acquire_dquot, .release_dquot = ocfs2_release_dquot,
fs/quota/dquot.c +18 -8
@@ -1246,6 +1246,20 @@ static int info_bdq_free(struct dquot *dquot, qsize_t space)return QUOTA_NL_BHARDBELOW ;return QUOTA_NL_NOWARN ; } + +qid_t dquot_get_id (struct inode *inode,int type) +{ +switch (type) { +case USRQUOTA : +return inode->i_uid; +case GRPQUOTA : +return inode->i_gid; +default : +BUG (); + } +} +EXPORT_SYMBOL (dquot_get_id); +/* * Initialize quota pointers in inode * We do things in a bit complicated way but by that we avoid calling
@@ -1267,14 +1281,9 @@ int dquot_initialize(struct inode *inode, int type)for (cnt =0 ; cnt <MAXQUOTAS ; cnt++) {if (type !=-1 && cnt != type)continue ; -switch (cnt) { -case USRQUOTA : - id = inode->i_uid; -break ; -case GRPQUOTA : - id = inode->i_gid; -break ; - } +if (!sb_has_quota_active (sb, cnt)) +continue ; + id = inode->i_sb->dq_op->get_id (inode, cnt); got[cnt] =dqget (sb, id, cnt); }
@@ -1788,6 +1797,7 @@ const struct dquot_operations dquot_operations = { .free_space = dquot_free_space, .free_inode = dquot_free_inode, .transfer = dquot_transfer, + .get_id = dquot_get_id, .write_dquot = dquot_commit, .acquire_dquot = dquot_acquire, .release_dquot = dquot_release,
fs/reiserfs/super.c +1 -0
@@ -623,6 +623,7 @@ static const struct dquot_operations reiserfs_quota_operations = { .free_space = dquot_free_space, .free_inode = dquot_free_inode, .transfer = dquot_transfer, + .get_id = dquot_get_id, .write_dquot = reiserfs_write_dquot, .acquire_dquot = reiserfs_acquire_dquot, .release_dquot = reiserfs_release_dquot,
include/linux/quota.h +1 -0
@@ -303,6 +303,7 @@ struct dquot_operations {int (*free_inode) (const struct inode *,qsize_t );int (*transfer) (struct inode *,qid_t *,unsigned long );int (*write_dquot) (struct dquot *);/* Ordinary dquot write */ +qid_t (*get_id)(struct inode *,int );/* Quota id for given type */ struct dquot *(*alloc_dquot)(struct super_block *,int );/* Allocate memory for new dquot */ void (*destroy_dquot)(struct dquot *);/* Free memory for dquot */ int (*acquire_dquot) (struct dquot *);/* Quota is going to be created on disk */
include/linux/quotaops.h +1 -0
@@ -26,6 +26,7 @@ static inline void writeout_quota_sb(struct super_block *sb, int type) sb->s_qcop->quota_sync (sb, type); } +qid_t dquot_get_id (struct inode *inode,int type);int dquot_initialize (struct inode *inode,int type);int dquot_drop (struct inode *inode);struct dquot *dqget (struct super_block *sb,unsigned int id,int type);
Signature · 1 line
1.6.3.3
PATCH 3/3 quota: add generic treeid quota support
Just introduce new and update macros.
It will be used later.
--- fs/quota/dquot.c | 5 +++++ fs/quota/quotaio_v2.h | 4 +++- include/linux/quota.h | 6 ++++-- 3 files changed, 12 insertions(+), 3 deletions(-)
fs/quota/dquot.c +5 -0
@@ -1045,6 +1045,11 @@ static int need_print_warning(struct dquot *dquot)return current_fsuid () == dquot->dq_id;case GRPQUOTA :return in_group_p (dquot->dq_id); +case TRQUOTA : +/* XXX: Currently there is no way to understand +which tree this task belonges to, So print +a warn message unconditionally. -dmon */ +return 1 ; }return 0 ; }
fs/quota/quotaio_v2.h +3 -1
@@ -13,12 +13,14 @@*/ #define V2_INITQMAGICS {\ 0xd9c01f11,/* USRQUOTA */ \ - 0xd9c01927 /* GRPQUOTA */\ +0xd9c01927 ,/* GRPQUOTA */ \ + 0xd9c03f14 /* TRQUOTA */\ } #define V2_INITQVERSIONS {\ 1, /* USRQUOTA */\ 1 /* GRPQUOTA */\ + 1 /* TRPQUOTA */\ } /* First generic header */
include/linux/quota.h +4 -2
@@ -36,11 +36,12 @@#include <linux/errno.h> #include <linux/types.h> -#define __DQUOT_VERSION__ "dquot_6.5.2" +#define __DQUOT_VERSION__ "dquot_7.0.0" -#define MAXQUOTAS 2 +#define MAXQUOTAS 3#define USRQUOTA 0/* element used for user quotas */ #define GRPQUOTA 1/* element used for group quotas */ +#define TRQUOTA 2/* element used for directory tree quotas */ /* * Definitions for the default names of the quotas files.
@@ -48,6 +49,7 @@#define INITQFNAMES { \ "user",/* USRQUOTA */ \"group" ,/* GRPQUOTA */ \ +"tree" ,/* TRQUOTA */ \ "undefined", \ };
Signature · 1 line
1.6.3.3
Jan Kara
reviewerRe: [PATCH 3/3] quota: add generic treeid quota support
Quoted 2 lines · Dmitry Monakhov
Just introduce new and update macros.
It will be used later.
...
fs/quota/quotaio_v2.h line 24
Quoted 5 lines
#define
V2_INITQVERSIONS{\fs/quota/quotaio_v2.h +1
-01, /* USRQUOTA */\ 1 /* GRPQUOTA */\ + 1 /* TRPQUOTA */\ }
This won't compile...
include/linux/quota.h line 39
Quoted 11 lines
/* First generic header */
include/linux/quota.h +1
-1@@ -36,11 +36,12 @@#include <linux/errno.h> #include <linux/types.h> -#define __DQUOT_VERSION__ "dquot_6.5.2" +#define __DQUOT_VERSION__ "dquot_7.0.0"
;-) Hmm, not that this version would matter but 6.6.0 would look
more logical to me. But I'll leave that up to you.
Otherwise I'm fine with the patch.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerRe: [PATCH 2/3] quota: introduce get_id callback
In reply to Dmitry MonakhovQuoted 4 lines · Dmitry Monakhov
During some quota oparations we have to determine
quota_idfor given inode according toquota_type. But only USRQUOTA/GRPQUOTA id are intermediately accessible from generic vfs-inode. This patch introduce newper_sbquota operation for this purpose.
Hmm, but you do not intend to ever change what is returned for USRQUOTA
and GRPQUOTA, do you? So we could just have something like
static qid_t generic_get_id(struct inode *inode, int qtype)
{
switch (qtype) {
case USRQUOTA:
return inode->i_uid;
case GRPQUOTA:
return inode->i_gid;
default:
return inode->i_sb->dq_op->get_id(inode, qtype);
}
}It's not as elegant as your solution but doing an indirect call to read a value directly accessible (which will be a common case) just seems lame...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 2/3] quota: introduce get_id callback
Quoted 7 lines · Jan Kara
Quoted 4 lines · Dmitry Monakhov
During some quota oparations we have to determine
quota_idfor given inode according toquota_type. But only USRQUOTA/GRPQUOTA id are intermediately accessible from generic vfs-inode. This patch introduce newper_sbquota operation for this purpose.Hmm, but you do not intend to ever change what is returned for USRQUOTA
and GRPQUOTA, do you? So we could just have something like
Hmm... In fact i've considered this option. For example:
In case of containers(trees), each container administrator want user/group quota to work inside it's container. I've considered following approach:
1) enlarge qid_t to u64
2) encode quota_uid and group_uid like follows:
quid = treeid << 32 + uid
qgid = treeid << 32 + gid
3) Introduce new 64-bit quota format file to support wide qid_t.
Currently i dont know better way to support user/group quota inside tree. It does not affect old fs-internal code, just replace all hard-coded (int => u64) in fs/quota-XXX. Old 32-bit quota users not affected because qid_t will be shrink ed on quota-save for old(most of) users.
Jan Kara
reviewerRe: [PATCH 2/3] quota: introduce get_id callback
Quoted 19 lines · Dmitry Monakhov
Quoted 7 lines · Jan Kara
Quoted 4 lines · Dmitry Monakhov
During some quota oparations we have to determine
quota_idfor given inode according toquota_type. But only USRQUOTA/GRPQUOTA id are intermediately accessible from generic vfs-inode. This patch introduce newper_sbquota operation for this purpose.Hmm, but you do not intend to ever change what is returned for USRQUOTA
and GRPQUOTA, do you? So we could just have something likeHmm... In fact i've considered this option. For example:
In case of containers(trees), each container administrator want user/group quota to work inside it's container. I've considered following approach:
1) enlargeqid_tto u64
2) encodequota_uidandgroup_uidlike follows:
quid = treeid << 32 + uid
qgid = treeid << 32 + gid
3) Introduce new 64-bit quota format file to support wideqid_t.
Quoted 5 lines
Currently i dont know better way to support user/group quota inside tree. It does not affect old fs-internal code, just replace all hard-coded (int => u64) in
fs/quota-XXX. Old 32-bit quota users not affected becauseqid_twill be shrink ed on quota-save for old(most of) users.
I see. But from what you write it seems to me that actually you'd like
a separate filesystem for each container - you'll get a separate quota files for each container (so no need for id mapping) and a natural total limitation of how much the container can use (the filesystem size).
Now I understand that having really a separate filesystem for each
container is impractical when you want to change sizes of each container and also the overhead of separate filesystem might be too big. But I'd like to understand your needs... Because it might be feasible to introduce a support for lightweight "subfilesystems" of a filesystem if that would solve your case...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 2/3] quota: introduce get_id callback
Quoted 25 lines · Jan Kara
Quoted 19 lines · Dmitry Monakhov
Quoted 7 lines · Jan Kara
Quoted 4 lines · Dmitry Monakhov
During some quota oparations we have to determine
quota_idfor given inode according toquota_type. But only USRQUOTA/GRPQUOTA id are intermediately accessible from generic vfs-inode. This patch introduce newper_sbquota operation for this purpose.Hmm, but you do not intend to ever change what is returned for USRQUOTA and GRPQUOTA, do you? So we could just have something like
Hmm... In fact i've considered this option. For example:
In case of containers(trees), each container administrator want user/group quota to work inside it's container. I've considered following approach:
1) enlargeqid_tto u64
2) encodequota_uidandgroup_uidlike follows:
quid = treeid << 32 + uid
qgid = treeid << 32 + gid
3) Introduce new 64-bit quota format file to support wideqid_t.Quoted 5 lines
Currently i dont know better way to support user/group quota inside tree. It does not affect old fs-internal code, just replace all hard-coded (int => u64) in
fs/quota-XXX. Old 32-bit quota users not affected becauseqid_twill be shrink ed on quota-save for old(most of) users.
Quoted 10 lines
I see. But from what you write it seems to me that actually you'd like a separate filesystem for each container - you'll get a separate quota files for each container (so no need for id mapping) and a natural total limitation of how much the container can use (the filesystem size). Now I understand that having really a separate filesystem for each container is impractical when you want to change sizes of each container and also the overhead of separate filesystem might be too big. But I'd like to understand your needs... Because it might be feasible to introduce a support for lightweight "subfilesystems" of a filesystem if that would solve your case...
Sorry for a long response.
Some weeks ago i've prepared a paper about quota-tree feature with patch-queue http://2ka.mipt.ru/~mov/quota.html
Currently that patch-queue is mostly obsoleted and may be interested only in history reasons.
*Container*
Container is a set of resources.
Each container isolated from another as much as possible. Container has its own root tree. Containers tree is exported inside CT by numerous possible ways (bind-mount, virtual-stack-fs, chroot) Container's root are independent tree(subtree of bare-metal host filesystem's tree)
usually they organized like follows /ct_roots/CT_${ID}/TREE_CONTENT
In terms of simplicity you may think of container as a secure CHROOT:
Bare-metal host file hierarchy: find /ct-roots
/ct-roots/
/ct-1/bin, etc, .....
/ct-2/bin, etc, ....
/ct-400/bin,etc .....enter to the container:
chroot /ct-roots/ct-1 /bin/bash
There are many reasons to keep this trees separate one from another(no hardlinks)
- inode attr:
If inode has links in A n B trees. And A-user call chown() for this inode, then B's owner will be surprised.
The only way to overcome this is to virtualize inode atributes (for each tree) which is madness IMHO.
- checkpoint/restore/online-backup:
This is like suspend resume for VM, but in this case only container's process are stopped(freezed) for some time. After CT's process are stopped we may create backup CT's tree without freezing FS as a whole.
The only way to implement journalled quota for containers is to implement it on native fs level.
"Containers directory tree-id" assumptions:
(1) Tree id is embedded inside inode ( inside xattr )
(2) Tree id is inherent from parent dir
(3) Inode can not belongs to different directory trees
In your terms:
"subfilesystem" of a filesystem is:
1) is subtree
2) all content starting from subtree root includes in to this subtree
3) Thre is no intersection between two different subfilesystems
About quota files:
It is totally impractical to use separate quota files for each
container because
each container requires 2 quota files, Recent servers allow to run about 1000 of containers, so it is madness to has 2*1000 quota files , just think about orphan-list cleanup after unclean umount :).
What's why i whant to encode tree_uid as (treeid << 32 + uid). This allow us to use just 3 quota files.(wide_user, wide_group, treeid)
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Jan Kara
reviewerRe: [PATCH 1/3] quota: generalize quota transfer interface
In reply to Dmitry MonakhovQuoted 4 lines · Dmitry Monakhov
Current quota transfer interface support only uid/gid. This patch extend interface in order to support various quotas types The goal is accomplished without changes in most frequently used
vfs_dq_transfer()func.
This patch is fine with me...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR