2005-04-17 06:20:36 +08: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_
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
2008-10-30 16:17:52 +08:00
|
|
|
#define __DQUOT_VERSION__ "dquot_6.5.2"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define MAXQUOTAS 2
|
|
|
|
#define USRQUOTA 0 /* element used for user quotas */
|
|
|
|
#define GRPQUOTA 1 /* element used for group quotas */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Definitions for the default names of the quotas files.
|
|
|
|
*/
|
|
|
|
#define INITQFNAMES { \
|
|
|
|
"user", /* USRQUOTA */ \
|
|
|
|
"group", /* GRPQUOTA */ \
|
|
|
|
"undefined", \
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Command definitions for the 'quotactl' system call.
|
|
|
|
* The commands are broken into a main command defined below
|
|
|
|
* and a subcommand that is used to convey the type of
|
|
|
|
* quota that is being manipulated (see above).
|
|
|
|
*/
|
|
|
|
#define SUBCMDMASK 0x00ff
|
|
|
|
#define SUBCMDSHIFT 8
|
|
|
|
#define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
|
|
|
|
|
|
|
|
#define Q_SYNC 0x800001 /* sync disk copy of a filesystems quotas */
|
|
|
|
#define Q_QUOTAON 0x800002 /* turn quotas on */
|
|
|
|
#define Q_QUOTAOFF 0x800003 /* turn quotas off */
|
|
|
|
#define Q_GETFMT 0x800004 /* get quota format used on given filesystem */
|
|
|
|
#define Q_GETINFO 0x800005 /* get information about quota files */
|
|
|
|
#define Q_SETINFO 0x800006 /* set information about quota files */
|
|
|
|
#define Q_GETQUOTA 0x800007 /* get user quota structure */
|
|
|
|
#define Q_SETQUOTA 0x800008 /* set user quota structure */
|
|
|
|
|
2008-11-25 22:31:31 +08:00
|
|
|
/* Quota format type IDs */
|
|
|
|
#define QFMT_VFS_OLD 1
|
|
|
|
#define QFMT_VFS_V0 2
|
2009-12-01 05:17:41 +08:00
|
|
|
#define QFMT_OCFS2 3
|
2009-11-17 01:09:47 +08:00
|
|
|
#define QFMT_VFS_V1 4
|
2008-11-25 22:31:31 +08:00
|
|
|
|
2008-08-20 20:45:12 +08:00
|
|
|
/* Size of block in which space limits are passed through the quota
|
|
|
|
* interface */
|
|
|
|
#define QIF_DQBLKSIZE_BITS 10
|
|
|
|
#define QIF_DQBLKSIZE (1 << QIF_DQBLKSIZE_BITS)
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Quota structure used for communication with userspace via quotactl
|
|
|
|
* Following flags are used to specify which fields are valid
|
|
|
|
*/
|
2008-10-02 22:48:10 +08:00
|
|
|
enum {
|
|
|
|
QIF_BLIMITS_B = 0,
|
|
|
|
QIF_SPACE_B,
|
|
|
|
QIF_ILIMITS_B,
|
|
|
|
QIF_INODES_B,
|
|
|
|
QIF_BTIME_B,
|
|
|
|
QIF_ITIME_B,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define QIF_BLIMITS (1 << QIF_BLIMITS_B)
|
|
|
|
#define QIF_SPACE (1 << QIF_SPACE_B)
|
|
|
|
#define QIF_ILIMITS (1 << QIF_ILIMITS_B)
|
|
|
|
#define QIF_INODES (1 << QIF_INODES_B)
|
|
|
|
#define QIF_BTIME (1 << QIF_BTIME_B)
|
|
|
|
#define QIF_ITIME (1 << QIF_ITIME_B)
|
2005-04-17 06:20:36 +08:00
|
|
|
#define QIF_LIMITS (QIF_BLIMITS | QIF_ILIMITS)
|
|
|
|
#define QIF_USAGE (QIF_SPACE | QIF_INODES)
|
|
|
|
#define QIF_TIMES (QIF_BTIME | QIF_ITIME)
|
|
|
|
#define QIF_ALL (QIF_LIMITS | QIF_USAGE | QIF_TIMES)
|
|
|
|
|
|
|
|
struct if_dqblk {
|
|
|
|
__u64 dqb_bhardlimit;
|
|
|
|
__u64 dqb_bsoftlimit;
|
|
|
|
__u64 dqb_curspace;
|
|
|
|
__u64 dqb_ihardlimit;
|
|
|
|
__u64 dqb_isoftlimit;
|
|
|
|
__u64 dqb_curinodes;
|
|
|
|
__u64 dqb_btime;
|
|
|
|
__u64 dqb_itime;
|
|
|
|
__u32 dqb_valid;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structure used for setting quota information about file via quotactl
|
|
|
|
* Following flags are used to specify which fields are valid
|
|
|
|
*/
|
|
|
|
#define IIF_BGRACE 1
|
|
|
|
#define IIF_IGRACE 2
|
|
|
|
#define IIF_FLAGS 4
|
|
|
|
#define IIF_ALL (IIF_BGRACE | IIF_IGRACE | IIF_FLAGS)
|
|
|
|
|
|
|
|
struct if_dqinfo {
|
|
|
|
__u64 dqi_bgrace;
|
|
|
|
__u64 dqi_igrace;
|
|
|
|
__u32 dqi_flags;
|
|
|
|
__u32 dqi_valid;
|
|
|
|
};
|
|
|
|
|
2007-10-17 14:29:31 +08:00
|
|
|
/*
|
|
|
|
* Definitions for quota netlink interface
|
|
|
|
*/
|
|
|
|
#define QUOTA_NL_NOWARN 0
|
|
|
|
#define QUOTA_NL_IHARDWARN 1 /* Inode hardlimit reached */
|
|
|
|
#define QUOTA_NL_ISOFTLONGWARN 2 /* Inode grace time expired */
|
|
|
|
#define QUOTA_NL_ISOFTWARN 3 /* Inode softlimit reached */
|
|
|
|
#define QUOTA_NL_BHARDWARN 4 /* Block hardlimit reached */
|
|
|
|
#define QUOTA_NL_BSOFTLONGWARN 5 /* Block grace time expired */
|
|
|
|
#define QUOTA_NL_BSOFTWARN 6 /* Block softlimit reached */
|
2008-07-25 16:46:52 +08:00
|
|
|
#define QUOTA_NL_IHARDBELOW 7 /* Usage got below inode hardlimit */
|
|
|
|
#define QUOTA_NL_ISOFTBELOW 8 /* Usage got below inode softlimit */
|
|
|
|
#define QUOTA_NL_BHARDBELOW 9 /* Usage got below block hardlimit */
|
|
|
|
#define QUOTA_NL_BSOFTBELOW 10 /* Usage got below block softlimit */
|
2007-10-17 14:29:31 +08:00
|
|
|
|
|
|
|
enum {
|
|
|
|
QUOTA_NL_C_UNSPEC,
|
|
|
|
QUOTA_NL_C_WARNING,
|
|
|
|
__QUOTA_NL_C_MAX,
|
|
|
|
};
|
|
|
|
#define QUOTA_NL_C_MAX (__QUOTA_NL_C_MAX - 1)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
QUOTA_NL_A_UNSPEC,
|
|
|
|
QUOTA_NL_A_QTYPE,
|
|
|
|
QUOTA_NL_A_EXCESS_ID,
|
|
|
|
QUOTA_NL_A_WARNING,
|
|
|
|
QUOTA_NL_A_DEV_MAJOR,
|
|
|
|
QUOTA_NL_A_DEV_MINOR,
|
|
|
|
QUOTA_NL_A_CAUSED_ID,
|
|
|
|
__QUOTA_NL_A_MAX,
|
|
|
|
};
|
|
|
|
#define QUOTA_NL_A_MAX (__QUOTA_NL_A_MAX - 1)
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef __KERNEL__
|
2008-02-26 22:53:20 +08:00
|
|
|
#include <linux/list.h>
|
2006-04-25 21:52:13 +08:00
|
|
|
#include <linux/mutex.h>
|
2008-02-26 22:53:20 +08:00
|
|
|
#include <linux/rwsem.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/wait.h>
|
2010-05-27 05:21:58 +08:00
|
|
|
#include <linux/percpu_counter.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <linux/dqblk_xfs.h>
|
|
|
|
#include <linux/dqblk_v1.h>
|
|
|
|
#include <linux/dqblk_v2.h>
|
|
|
|
|
2011-07-27 07:09:06 +08: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 16:11:45 +08:00
|
|
|
#include <linux/uidgid.h>
|
|
|
|
#include <linux/projid.h>
|
|
|
|
|
|
|
|
#undef USRQUOTA
|
|
|
|
#undef GRPQUOTA
|
|
|
|
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 22:53:20 +08:00
|
|
|
|
2008-07-25 16:46:51 +08:00
|
|
|
typedef __kernel_uid32_t qid_t; /* Type in which we store ids in memory */
|
2008-10-02 00:21:39 +08:00
|
|
|
typedef long long qsize_t; /* Type in which we store sizes */
|
2008-07-25 16:46:51 +08: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 16:11:45 +08: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-08 15:31:51 +08:00
|
|
|
extern spinlock_t dq_data_lock;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Maximal numbers of writes for quota operation (insert/delete/update)
|
2005-06-24 13:01:03 +08: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 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Data for one user/group kept in memory
|
|
|
|
*/
|
|
|
|
struct mem_dqblk {
|
2008-08-20 20:45:12 +08:00
|
|
|
qsize_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
|
|
|
|
qsize_t dqb_bsoftlimit; /* preferred limit on disk blks */
|
2005-04-17 06:20:36 +08:00
|
|
|
qsize_t dqb_curspace; /* current used space */
|
2009-01-13 23:43:09 +08:00
|
|
|
qsize_t dqb_rsvspace; /* current reserved space for delalloc*/
|
2008-08-20 20:45:12 +08:00
|
|
|
qsize_t dqb_ihardlimit; /* absolute limit on allocated inodes */
|
|
|
|
qsize_t dqb_isoftlimit; /* preferred inode limit */
|
|
|
|
qsize_t dqb_curinodes; /* current # allocated inodes */
|
2005-04-17 06:20:36 +08:00
|
|
|
time_t dqb_btime; /* time limit for excessive disk use */
|
|
|
|
time_t dqb_itime; /* time limit for excessive inode use */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data for one quotafile kept in memory
|
|
|
|
*/
|
|
|
|
struct quota_format_type;
|
|
|
|
|
|
|
|
struct mem_dqinfo {
|
|
|
|
struct quota_format_type *dqi_format;
|
2008-04-28 17:14:33 +08:00
|
|
|
int dqi_fmt_id; /* Id of the dqi_format - used when turning
|
|
|
|
* quotas on after remount RW */
|
2005-04-17 06:20:36 +08:00
|
|
|
struct list_head dqi_dirty_list; /* List of dirty dquots */
|
|
|
|
unsigned long dqi_flags;
|
|
|
|
unsigned int dqi_bgrace;
|
|
|
|
unsigned int dqi_igrace;
|
2008-04-28 17:14:31 +08:00
|
|
|
qsize_t dqi_maxblimit;
|
|
|
|
qsize_t dqi_maxilimit;
|
2008-10-03 00:44:14 +08:00
|
|
|
void *dqi_priv;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct super_block;
|
|
|
|
|
|
|
|
#define DQF_MASK 0xffff /* Mask for format specific flags */
|
2011-11-16 22:03:59 +08:00
|
|
|
#define DQF_GETINFO_MASK 0x1ffff /* Mask for flags passed to userspace */
|
|
|
|
#define DQF_SETINFO_MASK 0xffff /* Mask for flags modifiable from userspace */
|
|
|
|
#define DQF_SYS_FILE_B 16
|
|
|
|
#define DQF_SYS_FILE (1 << DQF_SYS_FILE_B) /* Quota file stored as system file */
|
|
|
|
#define DQF_INFO_DIRTY_B 31
|
2005-04-17 06:20:36 +08: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 16:46:52 +08:00
|
|
|
static inline int info_dirty(struct mem_dqinfo *info)
|
|
|
|
{
|
|
|
|
return test_bit(DQF_INFO_DIRTY_B, &info->dqi_flags);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-04-27 00:03:33 +08: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 06:20:36 +08:00
|
|
|
struct dqstats {
|
2010-04-27 00:03:33 +08:00
|
|
|
int stat[_DQST_DQSTAT_LAST];
|
2010-05-27 05:21:58 +08:00
|
|
|
struct percpu_counter counter[_DQST_DQSTAT_LAST];
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2010-04-27 00:03:33 +08:00
|
|
|
extern struct dqstats *dqstats_pcpu;
|
2005-04-17 06:20:36 +08:00
|
|
|
extern struct dqstats dqstats;
|
|
|
|
|
2010-04-27 00:03:33 +08:00
|
|
|
static inline void dqstats_inc(unsigned int type)
|
|
|
|
{
|
2010-05-27 05:21:58 +08:00
|
|
|
percpu_counter_inc(&dqstats.counter[type]);
|
2010-04-27 00:03:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void dqstats_dec(unsigned int type)
|
|
|
|
{
|
2010-05-27 05:21:58 +08:00
|
|
|
percpu_counter_dec(&dqstats.counter[type]);
|
2010-04-27 00:03:33 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08: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 22:48:10 +08: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 06:20:36 +08: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 19:00:29 +08:00
|
|
|
struct mutex dq_lock; /* dquot IO lock */
|
2005-04-17 06:20:36 +08: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 */
|
|
|
|
unsigned int dq_id; /* ID this applies to (uid, gid) */
|
|
|
|
loff_t dq_off; /* Offset of dquot on disk */
|
|
|
|
unsigned long dq_flags; /* See DQ_* */
|
|
|
|
short dq_type; /* Type of quota */
|
|
|
|
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 */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Operations working with dquots */
|
|
|
|
struct dquot_operations {
|
|
|
|
int (*write_dquot) (struct dquot *); /* Ordinary dquot write */
|
2008-08-19 20:51:22 +08: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 06:20:36 +08: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 20:21:13 +08:00
|
|
|
/* get reserved quota for delayed alloc, value returned is managed by
|
|
|
|
* quota code only */
|
|
|
|
qsize_t *(*get_reserved_space) (struct inode *);
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2010-09-15 23:38:58 +08:00
|
|
|
struct path;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Operations handling requests from userspace */
|
|
|
|
struct quotactl_ops {
|
2010-09-15 23:38:58 +08:00
|
|
|
int (*quota_on)(struct super_block *, int, int, struct path *);
|
|
|
|
int (*quota_on_meta)(struct super_block *, int, int);
|
2010-05-19 19:16:43 +08:00
|
|
|
int (*quota_off)(struct super_block *, int);
|
2012-07-03 22:45:28 +08:00
|
|
|
int (*quota_sync)(struct super_block *, int);
|
2005-04-17 06:20:36 +08:00
|
|
|
int (*get_info)(struct super_block *, int, struct if_dqinfo *);
|
|
|
|
int (*set_info)(struct super_block *, int, struct if_dqinfo *);
|
2012-09-16 17:07:49 +08:00
|
|
|
int (*get_dqblk)(struct super_block *, struct kqid, struct fs_disk_quota *);
|
|
|
|
int (*set_dqblk)(struct super_block *, struct kqid, struct fs_disk_quota *);
|
2005-04-17 06:20:36 +08:00
|
|
|
int (*get_xstate)(struct super_block *, struct fs_quota_stat *);
|
|
|
|
int (*set_xstate)(struct super_block *, unsigned int, int);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct quota_format_type {
|
|
|
|
int qf_fmt_id; /* Quota format id */
|
2009-10-16 19:26:03 +08:00
|
|
|
const struct quota_format_ops *qf_ops; /* Operations of format */
|
2005-04-17 06:20:36 +08:00
|
|
|
struct module *qf_owner; /* Module implementing quota format */
|
|
|
|
struct quota_format_type *qf_next;
|
|
|
|
};
|
|
|
|
|
2008-08-20 23:50:32 +08:00
|
|
|
/* Quota state flags - they actually come in two flavors - for users and groups */
|
|
|
|
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 17:14:33 +08:00
|
|
|
* we have necessary info in
|
|
|
|
* memory to turn them on */
|
2008-08-20 23:50:32 +08:00
|
|
|
_DQUOT_STATE_FLAGS
|
|
|
|
};
|
|
|
|
#define DQUOT_USAGE_ENABLED (1 << _DQUOT_USAGE_ENABLED)
|
|
|
|
#define DQUOT_LIMITS_ENABLED (1 << _DQUOT_LIMITS_ENABLED)
|
|
|
|
#define DQUOT_SUSPENDED (1 << _DQUOT_SUSPENDED)
|
|
|
|
#define DQUOT_STATE_FLAGS (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED | \
|
|
|
|
DQUOT_SUSPENDED)
|
2008-09-30 23:53:37 +08:00
|
|
|
/* Other quota flags */
|
2010-02-16 13:31:49 +08: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 23:53:37 +08:00
|
|
|
* system file and user cannot
|
|
|
|
* touch it. Filesystem is
|
|
|
|
* responsible for setting
|
|
|
|
* S_NOQUOTA, S_NOATIME flags
|
|
|
|
*/
|
2010-02-16 13:31:49 +08:00
|
|
|
#define DQUOT_NEGATIVE_USAGE (1 << (DQUOT_STATE_LAST + 1))
|
|
|
|
/* Allow negative quota usage */
|
2008-08-20 23:50:32 +08:00
|
|
|
|
|
|
|
static inline unsigned int dquot_state_flag(unsigned int flags, int type)
|
|
|
|
{
|
2010-02-16 13:31:49 +08:00
|
|
|
return flags << _DQUOT_STATE_FLAGS * type;
|
2008-08-20 23:50:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int dquot_generic_flag(unsigned int flags, int type)
|
|
|
|
{
|
2010-02-16 13:31:49 +08:00
|
|
|
return (flags >> _DQUOT_STATE_FLAGS * type) & DQUOT_STATE_FLAGS;
|
2008-08-20 23:50:32 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-09-28 19:35:17 +08:00
|
|
|
#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
|
|
|
|
extern void quota_send_warning(short type, unsigned int id, dev_t dev,
|
|
|
|
const char warntype);
|
|
|
|
#else
|
|
|
|
static inline void quota_send_warning(short type, unsigned int id, dev_t dev,
|
|
|
|
const char warntype)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_QUOTA_NETLINK_INTERFACE */
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct quota_info {
|
|
|
|
unsigned int flags; /* Flags for diskquotas on this device */
|
2006-03-23 19:00:29 +08:00
|
|
|
struct mutex dqio_mutex; /* lock device while I/O in progress */
|
|
|
|
struct mutex dqonoff_mutex; /* Serialize quotaon & quotaoff */
|
2005-04-17 06:20:36 +08:00
|
|
|
struct rw_semaphore dqptr_sem; /* serialize ops using quota_info struct, pointers from inode to dquots */
|
|
|
|
struct inode *files[MAXQUOTAS]; /* inodes of quotafiles */
|
|
|
|
struct mem_dqinfo info[MAXQUOTAS]; /* Information for each quota type */
|
2009-10-16 19:26:03 +08:00
|
|
|
const struct quota_format_ops *ops[MAXQUOTAS]; /* Operations for each type */
|
2005-04-17 06:20:36 +08: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"},\
|
|
|
|
{0, NULL}}
|
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
#endif /* _QUOTA_ */
|