1206552Sluigi/* SPDX-License-Identifier: GPL-2.0 */
2206552Sluigi/*
3206497Sluigi * quota.h for OCFS2
4206497Sluigi *
5206497Sluigi * On disk quota structures for local and global quota file, in-memory
6206497Sluigi * structures.
7206497Sluigi *
8206497Sluigi */
9206497Sluigi
10206497Sluigi#ifndef _OCFS2_QUOTA_H
11206497Sluigi#define _OCFS2_QUOTA_H
12206497Sluigi
13206497Sluigi#include <linux/types.h>
14206497Sluigi#include <linux/slab.h>
15206497Sluigi#include <linux/quota.h>
16206497Sluigi#include <linux/list.h>
17206497Sluigi#include <linux/dqblk_qtree.h>
18206497Sluigi
19206497Sluigi#include "ocfs2.h"
20206497Sluigi
21206497Sluigi/* Number of quota types we support */
22206497Sluigi#define OCFS2_MAXQUOTAS 2
23206497Sluigi
24206497Sluigi/*
25206497Sluigi * In-memory structures
26206552Sluigi */
27206552Sluigistruct ocfs2_dquot {
28239834Sissyl0	struct dquot dq_dquot;	/* Generic VFS dquot */
29206497Sluigi	loff_t dq_local_off;	/* Offset in the local quota file */
30206497Sluigi	u64 dq_local_phys_blk;	/* Physical block carrying quota structure */
31206497Sluigi	struct ocfs2_quota_chunk *dq_chunk;	/* Chunk dquot is in */
32206497Sluigi	unsigned int dq_use_count;	/* Number of nodes having reference to this entry in global quota file */
33206497Sluigi	s64 dq_origspace;	/* Last globally synced space usage */
34206497Sluigi	s64 dq_originodes;	/* Last globally synced inode usage */
35206497Sluigi	struct llist_node list;	/* Member of list of dquots to drop */
36206497Sluigi};
37206497Sluigi
38206497Sluigi/* Description of one chunk to recover in memory */
39206497Sluigistruct ocfs2_recovery_chunk {
40206497Sluigi	struct list_head rc_list;	/* List of chunks */
41206497Sluigi	int rc_chunk;			/* Chunk number */
42206497Sluigi	unsigned long *rc_bitmap;	/* Bitmap of entries to recover */
43206497Sluigi};
44206497Sluigi
45206497Sluigistruct ocfs2_quota_recovery {
46206497Sluigi	struct list_head r_list[OCFS2_MAXQUOTAS];	/* List of chunks to recover */
47206497Sluigi};
48206497Sluigi
49206497Sluigi/* In-memory structure with quota header information */
50206497Sluigistruct ocfs2_mem_dqinfo {
51206497Sluigi	unsigned int dqi_type;		/* Quota type this structure describes */
52206497Sluigi	unsigned int dqi_flags;		/* Flags OLQF_* */
53206497Sluigi	unsigned int dqi_chunks;	/* Number of chunks in local quota file */
54206497Sluigi	unsigned int dqi_blocks;	/* Number of blocks allocated for local quota file */
55206497Sluigi	unsigned int dqi_syncms;	/* How often should we sync with other nodes */
56206497Sluigi	struct list_head dqi_chunk;	/* List of chunks */
57206497Sluigi	struct inode *dqi_gqinode;	/* Global quota file inode */
58206497Sluigi	struct ocfs2_lock_res dqi_gqlock;	/* Lock protecting quota information structure */
59206497Sluigi	struct buffer_head *dqi_gqi_bh;	/* Buffer head with global quota file inode - set only if inode lock is obtained */
60206497Sluigi	int dqi_gqi_count;		/* Number of holders of dqi_gqi_bh */
61206497Sluigi	u64 dqi_giblk;			/* Number of block with global information header */
62206497Sluigi	struct buffer_head *dqi_lqi_bh;	/* Buffer head with local quota file inode */
63206497Sluigi	struct buffer_head *dqi_libh;	/* Buffer with local information header */
64206497Sluigi	struct qtree_mem_dqinfo dqi_gi;	/* Info about global file */
65206497Sluigi	struct delayed_work dqi_sync_work;	/* Work for syncing dquots */
66206497Sluigi	struct ocfs2_quota_recovery *dqi_rec;	/* Pointer to recovery
67206497Sluigi						 * information, in case we
68206497Sluigi						 * enable quotas on file
69206497Sluigi						 * needing it */
70206497Sluigi};
71206497Sluigi
72206497Sluigistatic inline struct ocfs2_dquot *OCFS2_DQUOT(struct dquot *dquot)
73206497Sluigi{
74206497Sluigi	return container_of(dquot, struct ocfs2_dquot, dq_dquot);
75206497Sluigi}
76206497Sluigi
77206497Sluigistruct ocfs2_quota_chunk {
78206497Sluigi	struct list_head qc_chunk;	/* List of quotafile chunks */
79206497Sluigi	int qc_num;			/* Number of quota chunk */
80206497Sluigi	struct buffer_head *qc_headerbh;	/* Buffer head with chunk header */
81206497Sluigi};
82206497Sluigi
83206497Sluigiextern struct kmem_cache *ocfs2_dquot_cachep;
84206497Sluigiextern struct kmem_cache *ocfs2_qf_chunk_cachep;
85206497Sluigi
86206497Sluigiextern const struct qtree_fmt_operations ocfs2_global_ops;
87206497Sluigi
88206497Sluigistruct ocfs2_quota_recovery *ocfs2_begin_quota_recovery(
89206497Sluigi				struct ocfs2_super *osb, int slot_num);
90206497Sluigiint ocfs2_finish_quota_recovery(struct ocfs2_super *osb,
91206497Sluigi				struct ocfs2_quota_recovery *rec,
92206497Sluigi				int slot_num);
93206497Sluigivoid ocfs2_free_quota_recovery(struct ocfs2_quota_recovery *rec);
94206497Sluigissize_t ocfs2_quota_read(struct super_block *sb, int type, char *data,
95211962Suqs			 size_t len, loff_t off);
96206497Sluigissize_t ocfs2_quota_write(struct super_block *sb, int type,
97206497Sluigi			  const char *data, size_t len, loff_t off);
98206497Sluigiint ocfs2_global_read_info(struct super_block *sb, int type);
99209350Suqsint ocfs2_global_write_info(struct super_block *sb, int type);
100206497Sluigiint ocfs2_global_read_dquot(struct dquot *dquot);
101206497Sluigiint __ocfs2_sync_dquot(struct dquot *dquot, int freeing);
102206497Sluigistatic inline int ocfs2_sync_dquot(struct dquot *dquot)
103206497Sluigi{
104206497Sluigi	return __ocfs2_sync_dquot(dquot, 0);
105206497Sluigi}
106206497Sluigistatic inline int ocfs2_global_release_dquot(struct dquot *dquot)
107206497Sluigi{
108206497Sluigi	return __ocfs2_sync_dquot(dquot, 1);
109206497Sluigi}
110206497Sluigi
111206497Sluigiint ocfs2_lock_global_qf(struct ocfs2_mem_dqinfo *oinfo, int ex);
112206497Sluigivoid ocfs2_unlock_global_qf(struct ocfs2_mem_dqinfo *oinfo, int ex);
113206497Sluigiint ocfs2_validate_quota_block(struct super_block *sb, struct buffer_head *bh);
114206497Sluigiint ocfs2_read_quota_phys_block(struct inode *inode, u64 p_block,
115206497Sluigi				struct buffer_head **bh);
116206497Sluigiint ocfs2_create_local_dquot(struct dquot *dquot);
117206497Sluigiint ocfs2_local_release_dquot(handle_t *handle, struct dquot *dquot);
118206497Sluigiint ocfs2_local_write_dquot(struct dquot *dquot);
119206497Sluigivoid ocfs2_drop_dquot_refs(struct work_struct *work);
120206497Sluigi
121206497Sluigiextern const struct dquot_operations ocfs2_quota_operations;
122206497Sluigiextern struct quota_format_type ocfs2_quota_format;
123206497Sluigi
124206497Sluigi#endif /* _OCFS2_QUOTA_H */
125206497Sluigi