xref: /openbmc/linux/fs/ocfs2/quota.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
29e33d69fSJan Kara /*
39e33d69fSJan Kara  * quota.h for OCFS2
49e33d69fSJan Kara  *
59e33d69fSJan Kara  * On disk quota structures for local and global quota file, in-memory
69e33d69fSJan Kara  * structures.
79e33d69fSJan Kara  *
89e33d69fSJan Kara  */
99e33d69fSJan Kara 
109e33d69fSJan Kara #ifndef _OCFS2_QUOTA_H
119e33d69fSJan Kara #define _OCFS2_QUOTA_H
129e33d69fSJan Kara 
139e33d69fSJan Kara #include <linux/types.h>
149e33d69fSJan Kara #include <linux/slab.h>
159e33d69fSJan Kara #include <linux/quota.h>
169e33d69fSJan Kara #include <linux/list.h>
179e33d69fSJan Kara #include <linux/dqblk_qtree.h>
189e33d69fSJan Kara 
199e33d69fSJan Kara #include "ocfs2.h"
209e33d69fSJan Kara 
2152362810SJan Kara /* Number of quota types we support */
2252362810SJan Kara #define OCFS2_MAXQUOTAS 2
2352362810SJan Kara 
249e33d69fSJan Kara /*
259e33d69fSJan Kara  * In-memory structures
269e33d69fSJan Kara  */
279e33d69fSJan Kara struct ocfs2_dquot {
289e33d69fSJan Kara 	struct dquot dq_dquot;	/* Generic VFS dquot */
299e33d69fSJan Kara 	loff_t dq_local_off;	/* Offset in the local quota file */
30f64dd44eSJan Kara 	u64 dq_local_phys_blk;	/* Physical block carrying quota structure */
319e33d69fSJan Kara 	struct ocfs2_quota_chunk *dq_chunk;	/* Chunk dquot is in */
329e33d69fSJan Kara 	unsigned int dq_use_count;	/* Number of nodes having reference to this entry in global quota file */
339e33d69fSJan Kara 	s64 dq_origspace;	/* Last globally synced space usage */
349e33d69fSJan Kara 	s64 dq_originodes;	/* Last globally synced inode usage */
35e3a767b6SJan Kara 	struct llist_node list;	/* Member of list of dquots to drop */
369e33d69fSJan Kara };
379e33d69fSJan Kara 
382205363dSJan Kara /* Description of one chunk to recover in memory */
392205363dSJan Kara struct ocfs2_recovery_chunk {
402205363dSJan Kara 	struct list_head rc_list;	/* List of chunks */
412205363dSJan Kara 	int rc_chunk;			/* Chunk number */
422205363dSJan Kara 	unsigned long *rc_bitmap;	/* Bitmap of entries to recover */
432205363dSJan Kara };
442205363dSJan Kara 
452205363dSJan Kara struct ocfs2_quota_recovery {
4652362810SJan Kara 	struct list_head r_list[OCFS2_MAXQUOTAS];	/* List of chunks to recover */
472205363dSJan Kara };
482205363dSJan Kara 
499e33d69fSJan Kara /* In-memory structure with quota header information */
509e33d69fSJan Kara struct ocfs2_mem_dqinfo {
519e33d69fSJan Kara 	unsigned int dqi_type;		/* Quota type this structure describes */
5296827adcSJan Kara 	unsigned int dqi_flags;		/* Flags OLQF_* */
539e33d69fSJan Kara 	unsigned int dqi_chunks;	/* Number of chunks in local quota file */
549e33d69fSJan Kara 	unsigned int dqi_blocks;	/* Number of blocks allocated for local quota file */
559e33d69fSJan Kara 	unsigned int dqi_syncms;	/* How often should we sync with other nodes */
569e33d69fSJan Kara 	struct list_head dqi_chunk;	/* List of chunks */
579e33d69fSJan Kara 	struct inode *dqi_gqinode;	/* Global quota file inode */
589e33d69fSJan Kara 	struct ocfs2_lock_res dqi_gqlock;	/* Lock protecting quota information structure */
599e33d69fSJan Kara 	struct buffer_head *dqi_gqi_bh;	/* Buffer head with global quota file inode - set only if inode lock is obtained */
609e33d69fSJan Kara 	int dqi_gqi_count;		/* Number of holders of dqi_gqi_bh */
61ae4f6ef1SJan Kara 	u64 dqi_giblk;			/* Number of block with global information header */
629e33d69fSJan Kara 	struct buffer_head *dqi_lqi_bh;	/* Buffer head with local quota file inode */
63ae4f6ef1SJan Kara 	struct buffer_head *dqi_libh;	/* Buffer with local information header */
649e33d69fSJan Kara 	struct qtree_mem_dqinfo dqi_gi;	/* Info about global file */
65171bf93cSMark Fasheh 	struct delayed_work dqi_sync_work;	/* Work for syncing dquots */
662205363dSJan Kara 	struct ocfs2_quota_recovery *dqi_rec;	/* Pointer to recovery
672205363dSJan Kara 						 * information, in case we
682205363dSJan Kara 						 * enable quotas on file
692205363dSJan Kara 						 * needing it */
709e33d69fSJan Kara };
719e33d69fSJan Kara 
OCFS2_DQUOT(struct dquot * dquot)729e33d69fSJan Kara static inline struct ocfs2_dquot *OCFS2_DQUOT(struct dquot *dquot)
739e33d69fSJan Kara {
749e33d69fSJan Kara 	return container_of(dquot, struct ocfs2_dquot, dq_dquot);
759e33d69fSJan Kara }
769e33d69fSJan Kara 
779e33d69fSJan Kara struct ocfs2_quota_chunk {
789e33d69fSJan Kara 	struct list_head qc_chunk;	/* List of quotafile chunks */
799e33d69fSJan Kara 	int qc_num;			/* Number of quota chunk */
809e33d69fSJan Kara 	struct buffer_head *qc_headerbh;	/* Buffer head with chunk header */
819e33d69fSJan Kara };
829e33d69fSJan Kara 
839e33d69fSJan Kara extern struct kmem_cache *ocfs2_dquot_cachep;
849e33d69fSJan Kara extern struct kmem_cache *ocfs2_qf_chunk_cachep;
859e33d69fSJan Kara 
86d1b98c23SJulia Lawall extern const struct qtree_fmt_operations ocfs2_global_ops;
879e33d69fSJan Kara 
882205363dSJan Kara struct ocfs2_quota_recovery *ocfs2_begin_quota_recovery(
892205363dSJan Kara 				struct ocfs2_super *osb, int slot_num);
902205363dSJan Kara int ocfs2_finish_quota_recovery(struct ocfs2_super *osb,
912205363dSJan Kara 				struct ocfs2_quota_recovery *rec,
922205363dSJan Kara 				int slot_num);
932205363dSJan Kara void ocfs2_free_quota_recovery(struct ocfs2_quota_recovery *rec);
949e33d69fSJan Kara ssize_t ocfs2_quota_read(struct super_block *sb, int type, char *data,
959e33d69fSJan Kara 			 size_t len, loff_t off);
969e33d69fSJan Kara ssize_t ocfs2_quota_write(struct super_block *sb, int type,
979e33d69fSJan Kara 			  const char *data, size_t len, loff_t off);
989e33d69fSJan Kara int ocfs2_global_read_info(struct super_block *sb, int type);
999e33d69fSJan Kara int ocfs2_global_write_info(struct super_block *sb, int type);
1009e33d69fSJan Kara int ocfs2_global_read_dquot(struct dquot *dquot);
1019e33d69fSJan Kara int __ocfs2_sync_dquot(struct dquot *dquot, int freeing);
ocfs2_sync_dquot(struct dquot * dquot)1029e33d69fSJan Kara static inline int ocfs2_sync_dquot(struct dquot *dquot)
1039e33d69fSJan Kara {
1049e33d69fSJan Kara 	return __ocfs2_sync_dquot(dquot, 0);
1059e33d69fSJan Kara }
ocfs2_global_release_dquot(struct dquot * dquot)1069e33d69fSJan Kara static inline int ocfs2_global_release_dquot(struct dquot *dquot)
1079e33d69fSJan Kara {
1089e33d69fSJan Kara 	return __ocfs2_sync_dquot(dquot, 1);
1099e33d69fSJan Kara }
1109e33d69fSJan Kara 
1119e33d69fSJan Kara int ocfs2_lock_global_qf(struct ocfs2_mem_dqinfo *oinfo, int ex);
1129e33d69fSJan Kara void ocfs2_unlock_global_qf(struct ocfs2_mem_dqinfo *oinfo, int ex);
113fb8dd8d7SJan Kara int ocfs2_validate_quota_block(struct super_block *sb, struct buffer_head *bh);
114f64dd44eSJan Kara int ocfs2_read_quota_phys_block(struct inode *inode, u64 p_block,
115f64dd44eSJan Kara 				struct buffer_head **bh);
116fb8dd8d7SJan Kara int ocfs2_create_local_dquot(struct dquot *dquot);
117fb8dd8d7SJan Kara int ocfs2_local_release_dquot(handle_t *handle, struct dquot *dquot);
118741e1289SJan Kara int ocfs2_local_write_dquot(struct dquot *dquot);
119e3a767b6SJan Kara void ocfs2_drop_dquot_refs(struct work_struct *work);
1209e33d69fSJan Kara 
12161e225dcSAlexey Dobriyan extern const struct dquot_operations ocfs2_quota_operations;
1229e33d69fSJan Kara extern struct quota_format_type ocfs2_quota_format;
1239e33d69fSJan Kara 
1249e33d69fSJan Kara #endif /* _OCFS2_QUOTA_H */
125