* [PATCH] quota: sb_quota state flags cleanup
@ 2010-02-02 14:07 Dmitry Monakhov
2010-02-02 15:40 ` Jan Kara
0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Monakhov @ 2010-02-02 14:07 UTC (permalink / raw)
To: linux-fsdevel; +Cc: jack, Dmitry Monakhov
- remove hardcoded USRQUOTA/GRPQUOTA flags
- convert int to bool for appropriate functions
Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
include/linux/quota.h | 15 +++++++--------
include/linux/quotaops.h | 31 +++++++++++++++++--------------
2 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/include/linux/quota.h b/include/linux/quota.h
index a6861f1..1f1a3a1 100644
--- a/include/linux/quota.h
+++ b/include/linux/quota.h
@@ -357,26 +357,25 @@ enum {
#define DQUOT_STATE_FLAGS (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED | \
DQUOT_SUSPENDED)
/* Other quota flags */
-#define DQUOT_QUOTA_SYS_FILE (1 << 6) /* Quota file is a special
+#define DQUOT_STATE_LAST (_DQUOT_STATE_FLAGS * MAXQUOTAS)
+#define DQUOT_QUOTA_SYS_FILE (1 << DQUOT_STATE_LAST)
+ /* Quota file is a special
* system file and user cannot
* touch it. Filesystem is
* responsible for setting
* S_NOQUOTA, S_NOATIME flags
*/
-#define DQUOT_NEGATIVE_USAGE (1 << 7) /* Allow negative quota usage */
+#define DQUOT_NEGATIVE_USAGE (1 << (DQUOT_STATE_LAST + 1))
+ /* Allow negative quota usage */
static inline unsigned int dquot_state_flag(unsigned int flags, int type)
{
- if (type == USRQUOTA)
- return flags;
- return flags << _DQUOT_STATE_FLAGS;
+ return flags << _DQUOT_STATE_FLAGS * type;
}
static inline unsigned int dquot_generic_flag(unsigned int flags, int type)
{
- if (type == USRQUOTA)
- return flags;
- return flags >> _DQUOT_STATE_FLAGS;
+ return (flags >> _DQUOT_STATE_FLAGS * type) & DQUOT_STATE_FLAGS;
}
#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h
index 3ebb231..c0ee7c0 100644
--- a/include/linux/quotaops.h
+++ b/include/linux/quotaops.h
@@ -83,53 +83,56 @@ static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
* Functions for checking status of quota
*/
-static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
+static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
{
return sb_dqopt(sb)->flags &
dquot_state_flag(DQUOT_USAGE_ENABLED, type);
}
-static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
+static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
{
return sb_dqopt(sb)->flags &
dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
}
-static inline int sb_has_quota_suspended(struct super_block *sb, int type)
+static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
{
return sb_dqopt(sb)->flags &
dquot_state_flag(DQUOT_SUSPENDED, type);
}
-static inline int sb_any_quota_suspended(struct super_block *sb)
+static inline unsigned sb_any_quota_suspended(struct super_block *sb)
{
- return sb_has_quota_suspended(sb, USRQUOTA) ||
- sb_has_quota_suspended(sb, GRPQUOTA);
+ unsigned type, tmsk = 0;
+ for (type = 0; type < MAXQUOTAS; type++)
+ tmsk |= sb_has_quota_suspended(sb, type) << type;
+ return tmsk;
}
/* Does kernel know about any quota information for given sb + type? */
-static inline int sb_has_quota_loaded(struct super_block *sb, int type)
+static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
{
/* Currently if anything is on, then quota usage is on as well */
return sb_has_quota_usage_enabled(sb, type);
}
-static inline int sb_any_quota_loaded(struct super_block *sb)
+static inline unsigned sb_any_quota_loaded(struct super_block *sb)
{
- return sb_has_quota_loaded(sb, USRQUOTA) ||
- sb_has_quota_loaded(sb, GRPQUOTA);
+ unsigned type, tmsk = 0;
+ for (type = 0; type < MAXQUOTAS; type++)
+ tmsk |= sb_has_quota_loaded(sb, type) << type;
+ return tmsk;
}
-static inline int sb_has_quota_active(struct super_block *sb, int type)
+static inline bool sb_has_quota_active(struct super_block *sb, int type)
{
return sb_has_quota_loaded(sb, type) &&
!sb_has_quota_suspended(sb, type);
}
-static inline int sb_any_quota_active(struct super_block *sb)
+static inline unsigned sb_any_quota_active(struct super_block *sb)
{
- return sb_has_quota_active(sb, USRQUOTA) ||
- sb_has_quota_active(sb, GRPQUOTA);
+ return sb_any_quota_loaded(sb);
}
/*
--
1.6.3.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] quota: sb_quota state flags cleanup
2010-02-02 14:07 [PATCH] quota: sb_quota state flags cleanup Dmitry Monakhov
@ 2010-02-02 15:40 ` Jan Kara
2010-02-02 16:07 ` Dmitry Monakhov
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kara @ 2010-02-02 15:40 UTC (permalink / raw)
To: Dmitry Monakhov; +Cc: linux-fsdevel, jack
On Tue 02-02-10 17:07:49, Dmitry Monakhov wrote:
> - remove hardcoded USRQUOTA/GRPQUOTA flags
> - convert int to bool for appropriate functions
>
> Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
> ---
...
> -static inline int sb_any_quota_suspended(struct super_block *sb)
> +static inline unsigned sb_any_quota_suspended(struct super_block *sb)
> {
> - return sb_has_quota_suspended(sb, USRQUOTA) ||
> - sb_has_quota_suspended(sb, GRPQUOTA);
> + unsigned type, tmsk = 0;
> + for (type = 0; type < MAXQUOTAS; type++)
> + tmsk |= sb_has_quota_suspended(sb, type) << type;
> + return tmsk;
> }
Any particular reason for returning the mask instead of a simple bool?
Are you going to use the mask in future?
> -static inline int sb_any_quota_loaded(struct super_block *sb)
> +static inline unsigned sb_any_quota_loaded(struct super_block *sb)
> {
> - return sb_has_quota_loaded(sb, USRQUOTA) ||
> - sb_has_quota_loaded(sb, GRPQUOTA);
> + unsigned type, tmsk = 0;
> + for (type = 0; type < MAXQUOTAS; type++)
> + tmsk |= sb_has_quota_loaded(sb, type) << type;
> + return tmsk;
> }
And here as well...
> -static inline int sb_any_quota_active(struct super_block *sb)
> +static inline unsigned sb_any_quota_active(struct super_block *sb)
> {
> - return sb_has_quota_active(sb, USRQUOTA) ||
> - sb_has_quota_active(sb, GRPQUOTA);
> + return sb_any_quota_loaded(sb);
> }
This is wrong - quota is active if it is loaded and is not suspended...
Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] quota: sb_quota state flags cleanup
2010-02-02 15:40 ` Jan Kara
@ 2010-02-02 16:07 ` Dmitry Monakhov
2010-02-02 16:15 ` Jan Kara
0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Monakhov @ 2010-02-02 16:07 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-fsdevel
Jan Kara <jack@suse.cz> writes:
> On Tue 02-02-10 17:07:49, Dmitry Monakhov wrote:
>> - remove hardcoded USRQUOTA/GRPQUOTA flags
>> - convert int to bool for appropriate functions
>>
>> Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
>> ---
> ...
>> -static inline int sb_any_quota_suspended(struct super_block *sb)
>> +static inline unsigned sb_any_quota_suspended(struct super_block *sb)
>> {
>> - return sb_has_quota_suspended(sb, USRQUOTA) ||
>> - sb_has_quota_suspended(sb, GRPQUOTA);
>> + unsigned type, tmsk = 0;
>> + for (type = 0; type < MAXQUOTAS; type++)
>> + tmsk |= sb_has_quota_suspended(sb, type) << type;
>> + return tmsk;
>> }
> Any particular reason for returning the mask instead of a simple bool?
> Are you going to use the mask in future?
>
Actually i've not use this yet, but it is reasonable to
pass this mask in some places for example:
vfs_dq_init() {
mask = sb_any_quota_active(inode->sb)
dq_op->initialize(inode, mask)
}
in order to avoid checks for the same value inside ->initialize()
>> -static inline int sb_any_quota_loaded(struct super_block *sb)
>> +static inline unsigned sb_any_quota_loaded(struct super_block *sb)
>> {
>> - return sb_has_quota_loaded(sb, USRQUOTA) ||
>> - sb_has_quota_loaded(sb, GRPQUOTA);
>> + unsigned type, tmsk = 0;
>> + for (type = 0; type < MAXQUOTAS; type++)
>> + tmsk |= sb_has_quota_loaded(sb, type) << type;
>> + return tmsk;
>> }
> And here as well...
>
>> -static inline int sb_any_quota_active(struct super_block *sb)
>> +static inline unsigned sb_any_quota_active(struct super_block *sb)
>> {
>> - return sb_has_quota_active(sb, USRQUOTA) ||
>> - sb_has_quota_active(sb, GRPQUOTA);
>> + return sb_any_quota_loaded(sb);
>> }
Opps, will redo.
> This is wrong - quota is active if it is loaded and is not suspended...
>
> Honza
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] quota: sb_quota state flags cleanup
2010-02-02 16:07 ` Dmitry Monakhov
@ 2010-02-02 16:15 ` Jan Kara
0 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2010-02-02 16:15 UTC (permalink / raw)
To: Dmitry Monakhov; +Cc: Jan Kara, linux-fsdevel
On Tue 02-02-10 19:07:55, Dmitry Monakhov wrote:
> Jan Kara <jack@suse.cz> writes:
>
> > On Tue 02-02-10 17:07:49, Dmitry Monakhov wrote:
> >> - remove hardcoded USRQUOTA/GRPQUOTA flags
> >> - convert int to bool for appropriate functions
> >>
> >> Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
> >> ---
> > ...
> >> -static inline int sb_any_quota_suspended(struct super_block *sb)
> >> +static inline unsigned sb_any_quota_suspended(struct super_block *sb)
> >> {
> >> - return sb_has_quota_suspended(sb, USRQUOTA) ||
> >> - sb_has_quota_suspended(sb, GRPQUOTA);
> >> + unsigned type, tmsk = 0;
> >> + for (type = 0; type < MAXQUOTAS; type++)
> >> + tmsk |= sb_has_quota_suspended(sb, type) << type;
> >> + return tmsk;
> >> }
> > Any particular reason for returning the mask instead of a simple bool?
> > Are you going to use the mask in future?
> >
> Actually i've not use this yet, but it is reasonable to
> pass this mask in some places for example:
> vfs_dq_init() {
> mask = sb_any_quota_active(inode->sb)
> dq_op->initialize(inode, mask)
> }
> in order to avoid checks for the same value inside ->initialize()
OK, but we usually have to recheck with dqptr_sem held anyway
to make the check reliable... The sb_any_quota_* checks are there usually
to optimize the common case where no quota is enabled on the filesystem.
But it's not a big deal either way... I was just curious...
Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-02-02 16:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-02 14:07 [PATCH] quota: sb_quota state flags cleanup Dmitry Monakhov
2010-02-02 15:40 ` Jan Kara
2010-02-02 16:07 ` Dmitry Monakhov
2010-02-02 16:15 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).