xref: /OK3568_Linux_fs/kernel/fs/ocfs2/quota.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * quota.h for OCFS2
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * On disk quota structures for local and global quota file, in-memory
6*4882a593Smuzhiyun  * structures.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #ifndef _OCFS2_QUOTA_H
11*4882a593Smuzhiyun #define _OCFS2_QUOTA_H
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <linux/types.h>
14*4882a593Smuzhiyun #include <linux/slab.h>
15*4882a593Smuzhiyun #include <linux/quota.h>
16*4882a593Smuzhiyun #include <linux/list.h>
17*4882a593Smuzhiyun #include <linux/dqblk_qtree.h>
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #include "ocfs2.h"
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /* Number of quota types we support */
22*4882a593Smuzhiyun #define OCFS2_MAXQUOTAS 2
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun /*
25*4882a593Smuzhiyun  * In-memory structures
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun struct ocfs2_dquot {
28*4882a593Smuzhiyun 	struct dquot dq_dquot;	/* Generic VFS dquot */
29*4882a593Smuzhiyun 	loff_t dq_local_off;	/* Offset in the local quota file */
30*4882a593Smuzhiyun 	u64 dq_local_phys_blk;	/* Physical block carrying quota structure */
31*4882a593Smuzhiyun 	struct ocfs2_quota_chunk *dq_chunk;	/* Chunk dquot is in */
32*4882a593Smuzhiyun 	unsigned int dq_use_count;	/* Number of nodes having reference to this entry in global quota file */
33*4882a593Smuzhiyun 	s64 dq_origspace;	/* Last globally synced space usage */
34*4882a593Smuzhiyun 	s64 dq_originodes;	/* Last globally synced inode usage */
35*4882a593Smuzhiyun 	struct llist_node list;	/* Member of list of dquots to drop */
36*4882a593Smuzhiyun };
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /* Description of one chunk to recover in memory */
39*4882a593Smuzhiyun struct ocfs2_recovery_chunk {
40*4882a593Smuzhiyun 	struct list_head rc_list;	/* List of chunks */
41*4882a593Smuzhiyun 	int rc_chunk;			/* Chunk number */
42*4882a593Smuzhiyun 	unsigned long *rc_bitmap;	/* Bitmap of entries to recover */
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun struct ocfs2_quota_recovery {
46*4882a593Smuzhiyun 	struct list_head r_list[OCFS2_MAXQUOTAS];	/* List of chunks to recover */
47*4882a593Smuzhiyun };
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /* In-memory structure with quota header information */
50*4882a593Smuzhiyun struct ocfs2_mem_dqinfo {
51*4882a593Smuzhiyun 	unsigned int dqi_type;		/* Quota type this structure describes */
52*4882a593Smuzhiyun 	unsigned int dqi_flags;		/* Flags OLQF_* */
53*4882a593Smuzhiyun 	unsigned int dqi_chunks;	/* Number of chunks in local quota file */
54*4882a593Smuzhiyun 	unsigned int dqi_blocks;	/* Number of blocks allocated for local quota file */
55*4882a593Smuzhiyun 	unsigned int dqi_syncms;	/* How often should we sync with other nodes */
56*4882a593Smuzhiyun 	struct list_head dqi_chunk;	/* List of chunks */
57*4882a593Smuzhiyun 	struct inode *dqi_gqinode;	/* Global quota file inode */
58*4882a593Smuzhiyun 	struct ocfs2_lock_res dqi_gqlock;	/* Lock protecting quota information structure */
59*4882a593Smuzhiyun 	struct buffer_head *dqi_gqi_bh;	/* Buffer head with global quota file inode - set only if inode lock is obtained */
60*4882a593Smuzhiyun 	int dqi_gqi_count;		/* Number of holders of dqi_gqi_bh */
61*4882a593Smuzhiyun 	u64 dqi_giblk;			/* Number of block with global information header */
62*4882a593Smuzhiyun 	struct buffer_head *dqi_lqi_bh;	/* Buffer head with local quota file inode */
63*4882a593Smuzhiyun 	struct buffer_head *dqi_libh;	/* Buffer with local information header */
64*4882a593Smuzhiyun 	struct qtree_mem_dqinfo dqi_gi;	/* Info about global file */
65*4882a593Smuzhiyun 	struct delayed_work dqi_sync_work;	/* Work for syncing dquots */
66*4882a593Smuzhiyun 	struct ocfs2_quota_recovery *dqi_rec;	/* Pointer to recovery
67*4882a593Smuzhiyun 						 * information, in case we
68*4882a593Smuzhiyun 						 * enable quotas on file
69*4882a593Smuzhiyun 						 * needing it */
70*4882a593Smuzhiyun };
71*4882a593Smuzhiyun 
OCFS2_DQUOT(struct dquot * dquot)72*4882a593Smuzhiyun static inline struct ocfs2_dquot *OCFS2_DQUOT(struct dquot *dquot)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun 	return container_of(dquot, struct ocfs2_dquot, dq_dquot);
75*4882a593Smuzhiyun }
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun struct ocfs2_quota_chunk {
78*4882a593Smuzhiyun 	struct list_head qc_chunk;	/* List of quotafile chunks */
79*4882a593Smuzhiyun 	int qc_num;			/* Number of quota chunk */
80*4882a593Smuzhiyun 	struct buffer_head *qc_headerbh;	/* Buffer head with chunk header */
81*4882a593Smuzhiyun };
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun extern struct kmem_cache *ocfs2_dquot_cachep;
84*4882a593Smuzhiyun extern struct kmem_cache *ocfs2_qf_chunk_cachep;
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun extern const struct qtree_fmt_operations ocfs2_global_ops;
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun struct ocfs2_quota_recovery *ocfs2_begin_quota_recovery(
89*4882a593Smuzhiyun 				struct ocfs2_super *osb, int slot_num);
90*4882a593Smuzhiyun int ocfs2_finish_quota_recovery(struct ocfs2_super *osb,
91*4882a593Smuzhiyun 				struct ocfs2_quota_recovery *rec,
92*4882a593Smuzhiyun 				int slot_num);
93*4882a593Smuzhiyun void ocfs2_free_quota_recovery(struct ocfs2_quota_recovery *rec);
94*4882a593Smuzhiyun ssize_t ocfs2_quota_read(struct super_block *sb, int type, char *data,
95*4882a593Smuzhiyun 			 size_t len, loff_t off);
96*4882a593Smuzhiyun ssize_t ocfs2_quota_write(struct super_block *sb, int type,
97*4882a593Smuzhiyun 			  const char *data, size_t len, loff_t off);
98*4882a593Smuzhiyun int ocfs2_global_read_info(struct super_block *sb, int type);
99*4882a593Smuzhiyun int ocfs2_global_write_info(struct super_block *sb, int type);
100*4882a593Smuzhiyun int ocfs2_global_read_dquot(struct dquot *dquot);
101*4882a593Smuzhiyun int __ocfs2_sync_dquot(struct dquot *dquot, int freeing);
ocfs2_sync_dquot(struct dquot * dquot)102*4882a593Smuzhiyun static inline int ocfs2_sync_dquot(struct dquot *dquot)
103*4882a593Smuzhiyun {
104*4882a593Smuzhiyun 	return __ocfs2_sync_dquot(dquot, 0);
105*4882a593Smuzhiyun }
ocfs2_global_release_dquot(struct dquot * dquot)106*4882a593Smuzhiyun static inline int ocfs2_global_release_dquot(struct dquot *dquot)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun 	return __ocfs2_sync_dquot(dquot, 1);
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun int ocfs2_lock_global_qf(struct ocfs2_mem_dqinfo *oinfo, int ex);
112*4882a593Smuzhiyun void ocfs2_unlock_global_qf(struct ocfs2_mem_dqinfo *oinfo, int ex);
113*4882a593Smuzhiyun int ocfs2_validate_quota_block(struct super_block *sb, struct buffer_head *bh);
114*4882a593Smuzhiyun int ocfs2_read_quota_phys_block(struct inode *inode, u64 p_block,
115*4882a593Smuzhiyun 				struct buffer_head **bh);
116*4882a593Smuzhiyun int ocfs2_create_local_dquot(struct dquot *dquot);
117*4882a593Smuzhiyun int ocfs2_local_release_dquot(handle_t *handle, struct dquot *dquot);
118*4882a593Smuzhiyun int ocfs2_local_write_dquot(struct dquot *dquot);
119*4882a593Smuzhiyun void ocfs2_drop_dquot_refs(struct work_struct *work);
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun extern const struct dquot_operations ocfs2_quota_operations;
122*4882a593Smuzhiyun extern struct quota_format_type ocfs2_quota_format;
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun #endif /* _OCFS2_QUOTA_H */
125