2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1982, 1986 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Robert Elz at The University of Melbourne.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
#ifndef _LINUX_QUOTA_
|
|
|
|
#define _LINUX_QUOTA_
|
|
|
|
|
2008-02-26 21:53:20 +07:00
|
|
|
#include <linux/list.h>
|
2006-04-25 20:52:13 +07:00
|
|
|
#include <linux/mutex.h>
|
2008-02-26 21:53:20 +07:00
|
|
|
#include <linux/rwsem.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/wait.h>
|
2010-05-27 04:21:58 +07:00
|
|
|
#include <linux/percpu_counter.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#include <linux/dqblk_xfs.h>
|
|
|
|
#include <linux/dqblk_v1.h>
|
|
|
|
#include <linux/dqblk_v2.h>
|
|
|
|
|
2011-07-27 06:09:06 +07:00
|
|
|
#include <linux/atomic.h>
|
userns: Implement struct kqid
Add the data type struct kqid which holds the kernel internal form of
the owning identifier of a quota. struct kqid is a replacement for
the implicit union of uid, gid and project id stored in an unsigned
int and the quota type field that is was used in the quota data
structures. Making the data type explicit allows the kuid_t and
kgid_t type safety to propogate more thoroughly through the code,
revealing more places where uid/gid conversions need be made.
Along with the data type struct kqid comes the helper functions
qid_eq, qid_lt, from_kqid, from_kqid_munged, qid_valid, make_kqid,
make_kqid_invalid, make_kqid_uid, make_kqid_gid.
Cc: Jan Kara <jack@suse.cz>
Cc: Dave Chinner <david@fromorbit.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
2012-09-16 15:11:45 +07:00
|
|
|
#include <linux/uidgid.h>
|
|
|
|
#include <linux/projid.h>
|
2012-10-13 16:46:48 +07:00
|
|
|
#include <uapi/linux/quota.h>
|
userns: Implement struct kqid
Add the data type struct kqid which holds the kernel internal form of
the owning identifier of a quota. struct kqid is a replacement for
the implicit union of uid, gid and project id stored in an unsigned
int and the quota type field that is was used in the quota data
structures. Making the data type explicit allows the kuid_t and
kgid_t type safety to propogate more thoroughly through the code,
revealing more places where uid/gid conversions need be made.
Along with the data type struct kqid comes the helper functions
qid_eq, qid_lt, from_kqid, from_kqid_munged, qid_valid, make_kqid,
make_kqid_invalid, make_kqid_uid, make_kqid_gid.
Cc: Jan Kara <jack@suse.cz>
Cc: Dave Chinner <david@fromorbit.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
2012-09-16 15:11:45 +07:00
|
|
|
|
|
|
|
#undef USRQUOTA
|
|
|
|
#undef GRPQUOTA
|
2015-03-19 02:04:53 +07:00
|
|
|
#undef PRJQUOTA
|
userns: Implement struct kqid
Add the data type struct kqid which holds the kernel internal form of
the owning identifier of a quota. struct kqid is a replacement for
the implicit union of uid, gid and project id stored in an unsigned
int and the quota type field that is was used in the quota data
structures. Making the data type explicit allows the kuid_t and
kgid_t type safety to propogate more thoroughly through the code,
revealing more places where uid/gid conversions need be made.
Along with the data type struct kqid comes the helper functions
qid_eq, qid_lt, from_kqid, from_kqid_munged, qid_valid, make_kqid,
make_kqid_invalid, make_kqid_uid, make_kqid_gid.
Cc: Jan Kara <jack@suse.cz>
Cc: Dave Chinner <david@fromorbit.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
2012-09-16 15:11:45 +07:00
|
|
|
enum quota_type {
|
|
|
|
USRQUOTA = 0, /* element used for user quotas */
|
|
|
|
GRPQUOTA = 1, /* element used for group quotas */
|
|
|
|
PRJQUOTA = 2, /* element used for project quotas */
|
|
|
|
};
|
2008-02-26 21:53:20 +07:00
|
|
|
|
2014-09-30 15:43:09 +07:00
|
|
|
/* Masks for quota types when used as a bitmask */
|
|
|
|
#define QTYPE_MASK_USR (1 << USRQUOTA)
|
|
|
|
#define QTYPE_MASK_GRP (1 << GRPQUOTA)
|
|
|
|
#define QTYPE_MASK_PRJ (1 << PRJQUOTA)
|
|
|
|
|
2008-07-25 15:46:51 +07:00
|
|
|
typedef __kernel_uid32_t qid_t; /* Type in which we store ids in memory */
|
2008-10-01 23:21:39 +07:00
|
|
|
typedef long long qsize_t; /* Type in which we store sizes */
|
2008-07-25 15:46:51 +07:00
|
|
|
|
userns: Implement struct kqid
Add the data type struct kqid which holds the kernel internal form of
the owning identifier of a quota. struct kqid is a replacement for
the implicit union of uid, gid and project id stored in an unsigned
int and the quota type field that is was used in the quota data
structures. Making the data type explicit allows the kuid_t and
kgid_t type safety to propogate more thoroughly through the code,
revealing more places where uid/gid conversions need be made.
Along with the data type struct kqid comes the helper functions
qid_eq, qid_lt, from_kqid, from_kqid_munged, qid_valid, make_kqid,
make_kqid_invalid, make_kqid_uid, make_kqid_gid.
Cc: Jan Kara <jack@suse.cz>
Cc: Dave Chinner <david@fromorbit.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
2012-09-16 15:11:45 +07:00
|
|
|
struct kqid { /* Type in which we store the quota identifier */
|
|
|
|
union {
|
|
|
|
kuid_t uid;
|
|
|
|
kgid_t gid;
|
|
|
|
kprojid_t projid;
|
|
|
|
};
|
|
|
|
enum quota_type type; /* USRQUOTA (uid) or GRPQUOTA (gid) or PRJQUOTA (projid) */
|
|
|
|
};
|
|
|
|
|
|
|
|
extern bool qid_eq(struct kqid left, struct kqid right);
|
|
|
|
extern bool qid_lt(struct kqid left, struct kqid right);
|
|
|
|
extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
|
|
|
|
extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
|
|
|
|
extern bool qid_valid(struct kqid qid);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* make_kqid - Map a user-namespace, type, qid tuple into a kqid.
|
|
|
|
* @from: User namespace that the qid is in
|
|
|
|
* @type: The type of quota
|
|
|
|
* @qid: Quota identifier
|
|
|
|
*
|
|
|
|
* Maps a user-namespace, type qid tuple into a kernel internal
|
|
|
|
* kqid, and returns that kqid.
|
|
|
|
*
|
|
|
|
* When there is no mapping defined for the user-namespace, type,
|
|
|
|
* qid tuple an invalid kqid is returned. Callers are expected to
|
|
|
|
* test for and handle handle invalid kqids being returned.
|
|
|
|
* Invalid kqids may be tested for using qid_valid().
|
|
|
|
*/
|
|
|
|
static inline struct kqid make_kqid(struct user_namespace *from,
|
|
|
|
enum quota_type type, qid_t qid)
|
|
|
|
{
|
|
|
|
struct kqid kqid;
|
|
|
|
|
|
|
|
kqid.type = type;
|
|
|
|
switch (type) {
|
|
|
|
case USRQUOTA:
|
|
|
|
kqid.uid = make_kuid(from, qid);
|
|
|
|
break;
|
|
|
|
case GRPQUOTA:
|
|
|
|
kqid.gid = make_kgid(from, qid);
|
|
|
|
break;
|
|
|
|
case PRJQUOTA:
|
|
|
|
kqid.projid = make_kprojid(from, qid);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
return kqid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* make_kqid_invalid - Explicitly make an invalid kqid
|
|
|
|
* @type: The type of quota identifier
|
|
|
|
*
|
|
|
|
* Returns an invalid kqid with the specified type.
|
|
|
|
*/
|
|
|
|
static inline struct kqid make_kqid_invalid(enum quota_type type)
|
|
|
|
{
|
|
|
|
struct kqid kqid;
|
|
|
|
|
|
|
|
kqid.type = type;
|
|
|
|
switch (type) {
|
|
|
|
case USRQUOTA:
|
|
|
|
kqid.uid = INVALID_UID;
|
|
|
|
break;
|
|
|
|
case GRPQUOTA:
|
|
|
|
kqid.gid = INVALID_GID;
|
|
|
|
break;
|
|
|
|
case PRJQUOTA:
|
|
|
|
kqid.projid = INVALID_PROJID;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
return kqid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* make_kqid_uid - Make a kqid from a kuid
|
|
|
|
* @uid: The kuid to make the quota identifier from
|
|
|
|
*/
|
|
|
|
static inline struct kqid make_kqid_uid(kuid_t uid)
|
|
|
|
{
|
|
|
|
struct kqid kqid;
|
|
|
|
kqid.type = USRQUOTA;
|
|
|
|
kqid.uid = uid;
|
|
|
|
return kqid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* make_kqid_gid - Make a kqid from a kgid
|
|
|
|
* @gid: The kgid to make the quota identifier from
|
|
|
|
*/
|
|
|
|
static inline struct kqid make_kqid_gid(kgid_t gid)
|
|
|
|
{
|
|
|
|
struct kqid kqid;
|
|
|
|
kqid.type = GRPQUOTA;
|
|
|
|
kqid.gid = gid;
|
|
|
|
return kqid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* make_kqid_projid - Make a kqid from a projid
|
|
|
|
* @projid: The kprojid to make the quota identifier from
|
|
|
|
*/
|
|
|
|
static inline struct kqid make_kqid_projid(kprojid_t projid)
|
|
|
|
{
|
|
|
|
struct kqid kqid;
|
|
|
|
kqid.type = PRJQUOTA;
|
|
|
|
kqid.projid = projid;
|
|
|
|
return kqid;
|
|
|
|
}
|
|
|
|
|
2016-07-01 04:31:01 +07:00
|
|
|
/**
|
|
|
|
* qid_has_mapping - Report if a qid maps into a user namespace.
|
|
|
|
* @ns: The user namespace to see if a value maps into.
|
|
|
|
* @qid: The kernel internal quota identifier to test.
|
|
|
|
*/
|
|
|
|
static inline bool qid_has_mapping(struct user_namespace *ns, struct kqid qid)
|
|
|
|
{
|
|
|
|
return from_kqid(ns, qid) != (qid_t) -1;
|
|
|
|
}
|
|
|
|
|
userns: Implement struct kqid
Add the data type struct kqid which holds the kernel internal form of
the owning identifier of a quota. struct kqid is a replacement for
the implicit union of uid, gid and project id stored in an unsigned
int and the quota type field that is was used in the quota data
structures. Making the data type explicit allows the kuid_t and
kgid_t type safety to propogate more thoroughly through the code,
revealing more places where uid/gid conversions need be made.
Along with the data type struct kqid comes the helper functions
qid_eq, qid_lt, from_kqid, from_kqid_munged, qid_valid, make_kqid,
make_kqid_invalid, make_kqid_uid, make_kqid_gid.
Cc: Jan Kara <jack@suse.cz>
Cc: Dave Chinner <david@fromorbit.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
2012-09-16 15:11:45 +07:00
|
|
|
|
2007-05-08 14:31:51 +07:00
|
|
|
extern spinlock_t dq_data_lock;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Maximal numbers of writes for quota operation (insert/delete/update)
|
2005-06-24 12:01:03 +07:00
|
|
|
* (over VFS all formats) */
|
|
|
|
#define DQUOT_INIT_ALLOC max(V1_INIT_ALLOC, V2_INIT_ALLOC)
|
|
|
|
#define DQUOT_INIT_REWRITE max(V1_INIT_REWRITE, V2_INIT_REWRITE)
|
|
|
|
#define DQUOT_DEL_ALLOC max(V1_DEL_ALLOC, V2_DEL_ALLOC)
|
|
|
|
#define DQUOT_DEL_REWRITE max(V1_DEL_REWRITE, V2_DEL_REWRITE)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Data for one user/group kept in memory
|
|
|
|
*/
|
|
|
|
struct mem_dqblk {
|
2008-08-20 19:45:12 +07:00
|
|
|
qsize_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
|
|
|
|
qsize_t dqb_bsoftlimit; /* preferred limit on disk blks */
|
2005-04-17 05:20:36 +07:00
|
|
|
qsize_t dqb_curspace; /* current used space */
|
2009-01-13 22:43:09 +07:00
|
|
|
qsize_t dqb_rsvspace; /* current reserved space for delalloc*/
|
2008-08-20 19:45:12 +07:00
|
|
|
qsize_t dqb_ihardlimit; /* absolute limit on allocated inodes */
|
|
|
|
qsize_t dqb_isoftlimit; /* preferred inode limit */
|
|
|
|
qsize_t dqb_curinodes; /* current # allocated inodes */
|
2016-06-18 03:03:16 +07:00
|
|
|
time64_t dqb_btime; /* time limit for excessive disk use */
|
|
|
|
time64_t dqb_itime; /* time limit for excessive inode use */
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data for one quotafile kept in memory
|
|
|
|
*/
|
|
|
|
struct quota_format_type;
|
|
|
|
|
|
|
|
struct mem_dqinfo {
|
|
|
|
struct quota_format_type *dqi_format;
|
2008-04-28 16:14:33 +07:00
|
|
|
int dqi_fmt_id; /* Id of the dqi_format - used when turning
|
|
|
|
* quotas on after remount RW */
|
2005-04-17 05:20:36 +07:00
|
|
|
struct list_head dqi_dirty_list; /* List of dirty dquots */
|
|
|
|
unsigned long dqi_flags;
|
|
|
|
unsigned int dqi_bgrace;
|
|
|
|
unsigned int dqi_igrace;
|
2014-10-09 21:54:13 +07:00
|
|
|
qsize_t dqi_max_spc_limit;
|
|
|
|
qsize_t dqi_max_ino_limit;
|
2008-10-02 23:44:14 +07:00
|
|
|
void *dqi_priv;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct super_block;
|
|
|
|
|
2014-11-19 15:21:58 +07:00
|
|
|
/* Mask for flags passed to userspace */
|
|
|
|
#define DQF_GETINFO_MASK (DQF_ROOT_SQUASH | DQF_SYS_FILE)
|
|
|
|
/* Mask for flags modifiable from userspace */
|
|
|
|
#define DQF_SETINFO_MASK DQF_ROOT_SQUASH
|
|
|
|
|
|
|
|
enum {
|
|
|
|
DQF_INFO_DIRTY_B = DQF_PRIVATE,
|
|
|
|
};
|
2005-04-17 05:20:36 +07:00
|
|
|
#define DQF_INFO_DIRTY (1 << DQF_INFO_DIRTY_B) /* Is info dirty? */
|
|
|
|
|
|
|
|
extern void mark_info_dirty(struct super_block *sb, int type);
|
2008-07-25 15:46:52 +07:00
|
|
|
static inline int info_dirty(struct mem_dqinfo *info)
|
|
|
|
{
|
|
|
|
return test_bit(DQF_INFO_DIRTY_B, &info->dqi_flags);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-04-26 23:03:33 +07:00
|
|
|
enum {
|
|
|
|
DQST_LOOKUPS,
|
|
|
|
DQST_DROPS,
|
|
|
|
DQST_READS,
|
|
|
|
DQST_WRITES,
|
|
|
|
DQST_CACHE_HITS,
|
|
|
|
DQST_ALLOC_DQUOTS,
|
|
|
|
DQST_FREE_DQUOTS,
|
|
|
|
DQST_SYNCS,
|
|
|
|
_DQST_DQSTAT_LAST
|
|
|
|
};
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
struct dqstats {
|
2010-04-26 23:03:33 +07:00
|
|
|
int stat[_DQST_DQSTAT_LAST];
|
2010-05-27 04:21:58 +07:00
|
|
|
struct percpu_counter counter[_DQST_DQSTAT_LAST];
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2010-04-26 23:03:33 +07:00
|
|
|
extern struct dqstats *dqstats_pcpu;
|
2005-04-17 05:20:36 +07:00
|
|
|
extern struct dqstats dqstats;
|
|
|
|
|
2010-04-26 23:03:33 +07:00
|
|
|
static inline void dqstats_inc(unsigned int type)
|
|
|
|
{
|
2010-05-27 04:21:58 +07:00
|
|
|
percpu_counter_inc(&dqstats.counter[type]);
|
2010-04-26 23:03:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void dqstats_dec(unsigned int type)
|
|
|
|
{
|
2010-05-27 04:21:58 +07:00
|
|
|
percpu_counter_dec(&dqstats.counter[type]);
|
2010-04-26 23:03:33 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#define DQ_MOD_B 0 /* dquot modified since read */
|
|
|
|
#define DQ_BLKS_B 1 /* uid/gid has been warned about blk limit */
|
|
|
|
#define DQ_INODES_B 2 /* uid/gid has been warned about inode limit */
|
|
|
|
#define DQ_FAKE_B 3 /* no limits only usage */
|
|
|
|
#define DQ_READ_B 4 /* dquot was read into memory */
|
|
|
|
#define DQ_ACTIVE_B 5 /* dquot is active (dquot_release not called) */
|
2008-10-02 21:48:10 +07:00
|
|
|
#define DQ_LASTSET_B 6 /* Following 6 bits (see QIF_) are reserved\
|
|
|
|
* for the mask of entries set via SETQUOTA\
|
|
|
|
* quotactl. They are set under dq_data_lock\
|
|
|
|
* and the quota format handling dquot can\
|
|
|
|
* clear them when it sees fit. */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
struct dquot {
|
|
|
|
struct hlist_node dq_hash; /* Hash list in memory */
|
|
|
|
struct list_head dq_inuse; /* List of all quotas */
|
|
|
|
struct list_head dq_free; /* Free list element */
|
|
|
|
struct list_head dq_dirty; /* List of dirty dquots */
|
2006-03-23 18:00:29 +07:00
|
|
|
struct mutex dq_lock; /* dquot IO lock */
|
2005-04-17 05:20:36 +07:00
|
|
|
atomic_t dq_count; /* Use count */
|
|
|
|
wait_queue_head_t dq_wait_unused; /* Wait queue for dquot to become unused */
|
|
|
|
struct super_block *dq_sb; /* superblock this applies to */
|
2012-09-16 17:56:19 +07:00
|
|
|
struct kqid dq_id; /* ID this applies to (uid, gid, projid) */
|
2005-04-17 05:20:36 +07:00
|
|
|
loff_t dq_off; /* Offset of dquot on disk */
|
|
|
|
unsigned long dq_flags; /* See DQ_* */
|
|
|
|
struct mem_dqblk dq_dqb; /* Diskquota usage */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Operations which must be implemented by each quota format */
|
|
|
|
struct quota_format_ops {
|
|
|
|
int (*check_quota_file)(struct super_block *sb, int type); /* Detect whether file is in our format */
|
|
|
|
int (*read_file_info)(struct super_block *sb, int type); /* Read main info about file - called on quotaon() */
|
|
|
|
int (*write_file_info)(struct super_block *sb, int type); /* Write main info about file */
|
|
|
|
int (*free_file_info)(struct super_block *sb, int type); /* Called on quotaoff() */
|
|
|
|
int (*read_dqblk)(struct dquot *dquot); /* Read structure for one user */
|
|
|
|
int (*commit_dqblk)(struct dquot *dquot); /* Write structure for one user */
|
|
|
|
int (*release_dqblk)(struct dquot *dquot); /* Called when last reference to dquot is being dropped */
|
2016-01-26 01:24:50 +07:00
|
|
|
int (*get_next_id)(struct super_block *sb, struct kqid *qid); /* Get next ID with existing structure in the quota file */
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Operations working with dquots */
|
|
|
|
struct dquot_operations {
|
|
|
|
int (*write_dquot) (struct dquot *); /* Ordinary dquot write */
|
2008-08-19 19:51:22 +07:00
|
|
|
struct dquot *(*alloc_dquot)(struct super_block *, int); /* Allocate memory for new dquot */
|
|
|
|
void (*destroy_dquot)(struct dquot *); /* Free memory for dquot */
|
2005-04-17 05:20:36 +07:00
|
|
|
int (*acquire_dquot) (struct dquot *); /* Quota is going to be created on disk */
|
|
|
|
int (*release_dquot) (struct dquot *); /* Quota is going to be deleted from disk */
|
|
|
|
int (*mark_dirty) (struct dquot *); /* Dquot is marked dirty */
|
|
|
|
int (*write_info) (struct super_block *, int); /* Write of quota "superblock" */
|
2009-12-14 19:21:13 +07:00
|
|
|
/* get reserved quota for delayed alloc, value returned is managed by
|
|
|
|
* quota code only */
|
|
|
|
qsize_t *(*get_reserved_space) (struct inode *);
|
2015-03-19 02:04:53 +07:00
|
|
|
int (*get_projid) (struct inode *, kprojid_t *);/* Get project ID */
|
2017-06-22 22:46:48 +07:00
|
|
|
/* Get number of inodes that were charged for a given inode */
|
|
|
|
int (*get_inode_usage) (struct inode *, qsize_t *);
|
2016-01-26 01:24:50 +07:00
|
|
|
/* Get next ID with active quota structure */
|
|
|
|
int (*get_next_id) (struct super_block *sb, struct kqid *qid);
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2010-09-15 22:38:58 +07:00
|
|
|
struct path;
|
|
|
|
|
2014-10-09 21:03:13 +07:00
|
|
|
/* Structure for communicating via ->get_dqblk() & ->set_dqblk() */
|
|
|
|
struct qc_dqblk {
|
|
|
|
int d_fieldmask; /* mask of fields to change in ->set_dqblk() */
|
|
|
|
u64 d_spc_hardlimit; /* absolute limit on used space */
|
|
|
|
u64 d_spc_softlimit; /* preferred limit on used space */
|
|
|
|
u64 d_ino_hardlimit; /* maximum # allocated inodes */
|
|
|
|
u64 d_ino_softlimit; /* preferred inode limit */
|
|
|
|
u64 d_space; /* Space owned by the user */
|
|
|
|
u64 d_ino_count; /* # inodes owned by the user */
|
|
|
|
s64 d_ino_timer; /* zero if within inode limits */
|
|
|
|
/* if not, we refuse service */
|
|
|
|
s64 d_spc_timer; /* similar to above; for space */
|
|
|
|
int d_ino_warns; /* # warnings issued wrt num inodes */
|
|
|
|
int d_spc_warns; /* # warnings issued wrt used space */
|
|
|
|
u64 d_rt_spc_hardlimit; /* absolute limit on realtime space */
|
|
|
|
u64 d_rt_spc_softlimit; /* preferred limit on RT space */
|
|
|
|
u64 d_rt_space; /* realtime space owned */
|
|
|
|
s64 d_rt_spc_timer; /* similar to above; for RT space */
|
|
|
|
int d_rt_spc_warns; /* # warnings issued wrt RT space */
|
|
|
|
};
|
|
|
|
|
2014-12-16 18:03:51 +07:00
|
|
|
/*
|
|
|
|
* Field specifiers for ->set_dqblk() in struct qc_dqblk and also for
|
|
|
|
* ->set_info() in struct qc_info
|
|
|
|
*/
|
2014-10-09 21:03:13 +07:00
|
|
|
#define QC_INO_SOFT (1<<0)
|
|
|
|
#define QC_INO_HARD (1<<1)
|
|
|
|
#define QC_SPC_SOFT (1<<2)
|
|
|
|
#define QC_SPC_HARD (1<<3)
|
|
|
|
#define QC_RT_SPC_SOFT (1<<4)
|
|
|
|
#define QC_RT_SPC_HARD (1<<5)
|
|
|
|
#define QC_LIMIT_MASK (QC_INO_SOFT | QC_INO_HARD | QC_SPC_SOFT | QC_SPC_HARD | \
|
|
|
|
QC_RT_SPC_SOFT | QC_RT_SPC_HARD)
|
|
|
|
#define QC_SPC_TIMER (1<<6)
|
|
|
|
#define QC_INO_TIMER (1<<7)
|
|
|
|
#define QC_RT_SPC_TIMER (1<<8)
|
|
|
|
#define QC_TIMER_MASK (QC_SPC_TIMER | QC_INO_TIMER | QC_RT_SPC_TIMER)
|
|
|
|
#define QC_SPC_WARNS (1<<9)
|
|
|
|
#define QC_INO_WARNS (1<<10)
|
|
|
|
#define QC_RT_SPC_WARNS (1<<11)
|
|
|
|
#define QC_WARNS_MASK (QC_SPC_WARNS | QC_INO_WARNS | QC_RT_SPC_WARNS)
|
|
|
|
#define QC_SPACE (1<<12)
|
|
|
|
#define QC_INO_COUNT (1<<13)
|
|
|
|
#define QC_RT_SPACE (1<<14)
|
|
|
|
#define QC_ACCT_MASK (QC_SPACE | QC_INO_COUNT | QC_RT_SPACE)
|
2014-12-16 18:03:51 +07:00
|
|
|
#define QC_FLAGS (1<<15)
|
2014-10-09 21:03:13 +07:00
|
|
|
|
2014-11-19 06:42:09 +07:00
|
|
|
#define QCI_SYSFILE (1 << 0) /* Quota file is hidden from userspace */
|
|
|
|
#define QCI_ROOT_SQUASH (1 << 1) /* Root squash turned on */
|
|
|
|
#define QCI_ACCT_ENABLED (1 << 2) /* Quota accounting enabled */
|
|
|
|
#define QCI_LIMITS_ENFORCED (1 << 3) /* Quota limits enforced */
|
|
|
|
|
|
|
|
/* Structures for communicating via ->get_state */
|
|
|
|
struct qc_type_state {
|
|
|
|
unsigned int flags; /* Flags QCI_* */
|
|
|
|
unsigned int spc_timelimit; /* Time after which space softlimit is
|
|
|
|
* enforced */
|
|
|
|
unsigned int ino_timelimit; /* Ditto for inode softlimit */
|
|
|
|
unsigned int rt_spc_timelimit; /* Ditto for real-time space */
|
|
|
|
unsigned int spc_warnlimit; /* Limit for number of space warnings */
|
|
|
|
unsigned int ino_warnlimit; /* Ditto for inodes */
|
|
|
|
unsigned int rt_spc_warnlimit; /* Ditto for real-time space */
|
|
|
|
unsigned long long ino; /* Inode number of quota file */
|
|
|
|
blkcnt_t blocks; /* Number of 512-byte blocks in the file */
|
|
|
|
blkcnt_t nextents; /* Number of extents in the file */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct qc_state {
|
|
|
|
unsigned int s_incoredqs; /* Number of dquots in core */
|
|
|
|
/*
|
|
|
|
* Per quota type information. The array should really have
|
|
|
|
* max(MAXQUOTAS, XQM_MAXQUOTAS) entries. BUILD_BUG_ON in
|
|
|
|
* quota_getinfo() makes sure XQM_MAXQUOTAS is large enough. Once VFS
|
|
|
|
* supports project quotas, this can be changed to MAXQUOTAS
|
|
|
|
*/
|
|
|
|
struct qc_type_state s_state[XQM_MAXQUOTAS];
|
|
|
|
};
|
|
|
|
|
2014-12-16 18:03:51 +07:00
|
|
|
/* Structure for communicating via ->set_info */
|
|
|
|
struct qc_info {
|
|
|
|
int i_fieldmask; /* mask of fields to change in ->set_info() */
|
|
|
|
unsigned int i_flags; /* Flags QCI_* */
|
|
|
|
unsigned int i_spc_timelimit; /* Time after which space softlimit is
|
|
|
|
* enforced */
|
|
|
|
unsigned int i_ino_timelimit; /* Ditto for inode softlimit */
|
|
|
|
unsigned int i_rt_spc_timelimit;/* Ditto for real-time space */
|
|
|
|
unsigned int i_spc_warnlimit; /* Limit for number of space warnings */
|
|
|
|
unsigned int i_ino_warnlimit; /* Limit for number of inode warnings */
|
|
|
|
unsigned int i_rt_spc_warnlimit; /* Ditto for real-time space */
|
|
|
|
};
|
2014-10-09 21:03:13 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Operations handling requests from userspace */
|
|
|
|
struct quotactl_ops {
|
2016-11-21 07:49:34 +07:00
|
|
|
int (*quota_on)(struct super_block *, int, int, const struct path *);
|
2010-05-19 18:16:43 +07:00
|
|
|
int (*quota_off)(struct super_block *, int);
|
2014-10-08 20:56:21 +07:00
|
|
|
int (*quota_enable)(struct super_block *, unsigned int);
|
|
|
|
int (*quota_disable)(struct super_block *, unsigned int);
|
2012-07-03 21:45:28 +07:00
|
|
|
int (*quota_sync)(struct super_block *, int);
|
2014-12-16 18:03:51 +07:00
|
|
|
int (*set_info)(struct super_block *, int, struct qc_info *);
|
2014-10-09 21:03:13 +07:00
|
|
|
int (*get_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
|
quota: add new quotactl Q_XGETNEXTQUOTA
Q_XGETNEXTQUOTA is exactly like Q_XGETQUOTA, except that it
will return quota information for the id equal to or greater
than the id requested. In other words, if the requested id has
no quota, the command will return quota information for the
next higher id which does have a quota set. If no higher id
has an active quota, -ESRCH is returned.
This allows filesystems to do efficient iteration in kernelspace,
much like extN filesystems do in userspace when asked to report
all active quotas.
The patch adds a d_id field to struct qc_dqblk so that we can
pass back the id of the quota which was found, and return it
to userspace.
Today, filesystems such as XFS require getpwent-style iterations,
and for systems which have i.e. LDAP backends, this can be very
slow, or even impossible if iteration is not allowed in the
configuration.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-02-08 07:21:50 +07:00
|
|
|
int (*get_nextdqblk)(struct super_block *, struct kqid *,
|
|
|
|
struct qc_dqblk *);
|
2014-10-09 21:03:13 +07:00
|
|
|
int (*set_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
|
2014-11-19 06:42:09 +07:00
|
|
|
int (*get_state)(struct super_block *, struct qc_state *);
|
xfs: fix Q_XQUOTARM ioctl
The Q_XQUOTARM quotactl was not working properly, because
we weren't passing around proper flags. The xfs_fs_set_xstate()
ioctl handler used the same flags for Q_XQUOTAON/OFF as
well as for Q_XQUOTARM, but Q_XQUOTAON/OFF look for
XFS_UQUOTA_ACCT, XFS_UQUOTA_ENFD, XFS_GQUOTA_ACCT etc,
i.e. quota type + state, while Q_XQUOTARM looks only for
the type of quota, i.e. XFS_DQ_USER, XFS_DQ_GROUP etc.
Unfortunately these flag spaces overlap a bit, so we
got semi-random results for Q_XQUOTARM; i.e. the value
for XFS_DQ_USER == XFS_UQUOTA_ACCT, etc. yeargh.
Add a new quotactl op vector specifically for the QUOTARM
operation, since it operates with a different flag space.
This has been broken more or less forever, AFAICT.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Acked-by: Jan Kara <jack@suse.cz>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2014-05-05 14:25:50 +07:00
|
|
|
int (*rm_xquota)(struct super_block *, unsigned int);
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct quota_format_type {
|
|
|
|
int qf_fmt_id; /* Quota format id */
|
2009-10-16 18:26:03 +07:00
|
|
|
const struct quota_format_ops *qf_ops; /* Operations of format */
|
2005-04-17 05:20:36 +07:00
|
|
|
struct module *qf_owner; /* Module implementing quota format */
|
|
|
|
struct quota_format_type *qf_next;
|
|
|
|
};
|
|
|
|
|
2015-02-12 23:08:16 +07:00
|
|
|
/**
|
|
|
|
* Quota state flags - they actually come in two flavors - for users and groups.
|
|
|
|
*
|
|
|
|
* Actual typed flags layout:
|
|
|
|
* USRQUOTA GRPQUOTA
|
|
|
|
* DQUOT_USAGE_ENABLED 0x0001 0x0002
|
|
|
|
* DQUOT_LIMITS_ENABLED 0x0004 0x0008
|
|
|
|
* DQUOT_SUSPENDED 0x0010 0x0020
|
|
|
|
*
|
|
|
|
* Following bits are used for non-typed flags:
|
|
|
|
* DQUOT_QUOTA_SYS_FILE 0x0040
|
|
|
|
* DQUOT_NEGATIVE_USAGE 0x0080
|
|
|
|
*/
|
2008-08-20 22:50:32 +07:00
|
|
|
enum {
|
|
|
|
_DQUOT_USAGE_ENABLED = 0, /* Track disk usage for users */
|
|
|
|
_DQUOT_LIMITS_ENABLED, /* Enforce quota limits for users */
|
|
|
|
_DQUOT_SUSPENDED, /* User diskquotas are off, but
|
2008-04-28 16:14:33 +07:00
|
|
|
* we have necessary info in
|
|
|
|
* memory to turn them on */
|
2008-08-20 22:50:32 +07:00
|
|
|
_DQUOT_STATE_FLAGS
|
|
|
|
};
|
2015-02-12 23:08:16 +07:00
|
|
|
#define DQUOT_USAGE_ENABLED (1 << _DQUOT_USAGE_ENABLED * MAXQUOTAS)
|
|
|
|
#define DQUOT_LIMITS_ENABLED (1 << _DQUOT_LIMITS_ENABLED * MAXQUOTAS)
|
|
|
|
#define DQUOT_SUSPENDED (1 << _DQUOT_SUSPENDED * MAXQUOTAS)
|
2008-08-20 22:50:32 +07:00
|
|
|
#define DQUOT_STATE_FLAGS (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED | \
|
|
|
|
DQUOT_SUSPENDED)
|
2008-09-30 22:53:37 +07:00
|
|
|
/* Other quota flags */
|
2010-02-16 12:31:49 +07:00
|
|
|
#define DQUOT_STATE_LAST (_DQUOT_STATE_FLAGS * MAXQUOTAS)
|
|
|
|
#define DQUOT_QUOTA_SYS_FILE (1 << DQUOT_STATE_LAST)
|
|
|
|
/* Quota file is a special
|
2008-09-30 22:53:37 +07:00
|
|
|
* system file and user cannot
|
|
|
|
* touch it. Filesystem is
|
|
|
|
* responsible for setting
|
|
|
|
* S_NOQUOTA, S_NOATIME flags
|
|
|
|
*/
|
2010-02-16 12:31:49 +07:00
|
|
|
#define DQUOT_NEGATIVE_USAGE (1 << (DQUOT_STATE_LAST + 1))
|
|
|
|
/* Allow negative quota usage */
|
2008-08-20 22:50:32 +07:00
|
|
|
static inline unsigned int dquot_state_flag(unsigned int flags, int type)
|
|
|
|
{
|
2015-02-12 23:08:16 +07:00
|
|
|
return flags << type;
|
2008-08-20 22:50:32 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int dquot_generic_flag(unsigned int flags, int type)
|
|
|
|
{
|
2015-02-12 23:08:16 +07:00
|
|
|
return (flags >> type) & DQUOT_STATE_FLAGS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bitmap of quota types where flag is set in flags */
|
|
|
|
static __always_inline unsigned dquot_state_types(unsigned flags, unsigned flag)
|
|
|
|
{
|
|
|
|
BUILD_BUG_ON_NOT_POWER_OF_2(flag);
|
|
|
|
return (flags / flag) & ((1 << MAXQUOTAS) - 1);
|
2008-08-20 22:50:32 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-09-28 18:35:17 +07:00
|
|
|
#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
|
2012-09-16 16:32:43 +07:00
|
|
|
extern void quota_send_warning(struct kqid qid, dev_t dev,
|
2009-09-28 18:35:17 +07:00
|
|
|
const char warntype);
|
|
|
|
#else
|
2012-09-16 16:32:43 +07:00
|
|
|
static inline void quota_send_warning(struct kqid qid, dev_t dev,
|
2009-09-28 18:35:17 +07:00
|
|
|
const char warntype)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_QUOTA_NETLINK_INTERFACE */
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
struct quota_info {
|
|
|
|
unsigned int flags; /* Flags for diskquotas on this device */
|
2006-03-23 18:00:29 +07:00
|
|
|
struct mutex dqio_mutex; /* lock device while I/O in progress */
|
2005-04-17 05:20:36 +07:00
|
|
|
struct inode *files[MAXQUOTAS]; /* inodes of quotafiles */
|
|
|
|
struct mem_dqinfo info[MAXQUOTAS]; /* Information for each quota type */
|
2009-10-16 18:26:03 +07:00
|
|
|
const struct quota_format_ops *ops[MAXQUOTAS]; /* Operations for each type */
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
int register_quota_format(struct quota_format_type *fmt);
|
|
|
|
void unregister_quota_format(struct quota_format_type *fmt);
|
|
|
|
|
|
|
|
struct quota_module_name {
|
|
|
|
int qm_fmt_id;
|
|
|
|
char *qm_mod_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define INIT_QUOTA_MODULE_NAMES {\
|
|
|
|
{QFMT_VFS_OLD, "quota_v1"},\
|
|
|
|
{QFMT_VFS_V0, "quota_v2"},\
|
2013-01-25 11:24:56 +07:00
|
|
|
{QFMT_VFS_V1, "quota_v2"},\
|
2005-04-17 05:20:36 +07:00
|
|
|
{0, NULL}}
|
|
|
|
|
|
|
|
#endif /* _QUOTA_ */
|