Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * quota.h for OCFS2
0004  *
0005  * On disk quota structures for local and global quota file, in-memory
0006  * structures.
0007  *
0008  */
0009 
0010 #ifndef _OCFS2_QUOTA_H
0011 #define _OCFS2_QUOTA_H
0012 
0013 #include <linux/types.h>
0014 #include <linux/slab.h>
0015 #include <linux/quota.h>
0016 #include <linux/list.h>
0017 #include <linux/dqblk_qtree.h>
0018 
0019 #include "ocfs2.h"
0020 
0021 /* Number of quota types we support */
0022 #define OCFS2_MAXQUOTAS 2
0023 
0024 /*
0025  * In-memory structures
0026  */
0027 struct ocfs2_dquot {
0028     struct dquot dq_dquot;  /* Generic VFS dquot */
0029     loff_t dq_local_off;    /* Offset in the local quota file */
0030     u64 dq_local_phys_blk;  /* Physical block carrying quota structure */
0031     struct ocfs2_quota_chunk *dq_chunk; /* Chunk dquot is in */
0032     unsigned int dq_use_count;  /* Number of nodes having reference to this entry in global quota file */
0033     s64 dq_origspace;   /* Last globally synced space usage */
0034     s64 dq_originodes;  /* Last globally synced inode usage */
0035     struct llist_node list; /* Member of list of dquots to drop */
0036 };
0037 
0038 /* Description of one chunk to recover in memory */
0039 struct ocfs2_recovery_chunk {
0040     struct list_head rc_list;   /* List of chunks */
0041     int rc_chunk;           /* Chunk number */
0042     unsigned long *rc_bitmap;   /* Bitmap of entries to recover */
0043 };
0044 
0045 struct ocfs2_quota_recovery {
0046     struct list_head r_list[OCFS2_MAXQUOTAS];   /* List of chunks to recover */
0047 };
0048 
0049 /* In-memory structure with quota header information */
0050 struct ocfs2_mem_dqinfo {
0051     unsigned int dqi_type;      /* Quota type this structure describes */
0052     unsigned int dqi_flags;     /* Flags OLQF_* */
0053     unsigned int dqi_chunks;    /* Number of chunks in local quota file */
0054     unsigned int dqi_blocks;    /* Number of blocks allocated for local quota file */
0055     unsigned int dqi_syncms;    /* How often should we sync with other nodes */
0056     struct list_head dqi_chunk; /* List of chunks */
0057     struct inode *dqi_gqinode;  /* Global quota file inode */
0058     struct ocfs2_lock_res dqi_gqlock;   /* Lock protecting quota information structure */
0059     struct buffer_head *dqi_gqi_bh; /* Buffer head with global quota file inode - set only if inode lock is obtained */
0060     int dqi_gqi_count;      /* Number of holders of dqi_gqi_bh */
0061     u64 dqi_giblk;          /* Number of block with global information header */
0062     struct buffer_head *dqi_lqi_bh; /* Buffer head with local quota file inode */
0063     struct buffer_head *dqi_libh;   /* Buffer with local information header */
0064     struct qtree_mem_dqinfo dqi_gi; /* Info about global file */
0065     struct delayed_work dqi_sync_work;  /* Work for syncing dquots */
0066     struct ocfs2_quota_recovery *dqi_rec;   /* Pointer to recovery
0067                          * information, in case we
0068                          * enable quotas on file
0069                          * needing it */
0070 };
0071 
0072 static inline struct ocfs2_dquot *OCFS2_DQUOT(struct dquot *dquot)
0073 {
0074     return container_of(dquot, struct ocfs2_dquot, dq_dquot);
0075 }
0076 
0077 struct ocfs2_quota_chunk {
0078     struct list_head qc_chunk;  /* List of quotafile chunks */
0079     int qc_num;         /* Number of quota chunk */
0080     struct buffer_head *qc_headerbh;    /* Buffer head with chunk header */
0081 };
0082 
0083 extern struct kmem_cache *ocfs2_dquot_cachep;
0084 extern struct kmem_cache *ocfs2_qf_chunk_cachep;
0085 
0086 extern const struct qtree_fmt_operations ocfs2_global_ops;
0087 
0088 struct ocfs2_quota_recovery *ocfs2_begin_quota_recovery(
0089                 struct ocfs2_super *osb, int slot_num);
0090 int ocfs2_finish_quota_recovery(struct ocfs2_super *osb,
0091                 struct ocfs2_quota_recovery *rec,
0092                 int slot_num);
0093 void ocfs2_free_quota_recovery(struct ocfs2_quota_recovery *rec);
0094 ssize_t ocfs2_quota_read(struct super_block *sb, int type, char *data,
0095              size_t len, loff_t off);
0096 ssize_t ocfs2_quota_write(struct super_block *sb, int type,
0097               const char *data, size_t len, loff_t off);
0098 int ocfs2_global_read_info(struct super_block *sb, int type);
0099 int ocfs2_global_write_info(struct super_block *sb, int type);
0100 int ocfs2_global_read_dquot(struct dquot *dquot);
0101 int __ocfs2_sync_dquot(struct dquot *dquot, int freeing);
0102 static inline int ocfs2_sync_dquot(struct dquot *dquot)
0103 {
0104     return __ocfs2_sync_dquot(dquot, 0);
0105 }
0106 static inline int ocfs2_global_release_dquot(struct dquot *dquot)
0107 {
0108     return __ocfs2_sync_dquot(dquot, 1);
0109 }
0110 
0111 int ocfs2_lock_global_qf(struct ocfs2_mem_dqinfo *oinfo, int ex);
0112 void ocfs2_unlock_global_qf(struct ocfs2_mem_dqinfo *oinfo, int ex);
0113 int ocfs2_validate_quota_block(struct super_block *sb, struct buffer_head *bh);
0114 int ocfs2_read_quota_phys_block(struct inode *inode, u64 p_block,
0115                 struct buffer_head **bh);
0116 int ocfs2_create_local_dquot(struct dquot *dquot);
0117 int ocfs2_local_release_dquot(handle_t *handle, struct dquot *dquot);
0118 int ocfs2_local_write_dquot(struct dquot *dquot);
0119 void ocfs2_drop_dquot_refs(struct work_struct *work);
0120 
0121 extern const struct dquot_operations ocfs2_quota_operations;
0122 extern struct quota_format_type ocfs2_quota_format;
0123 
0124 #endif /* _OCFS2_QUOTA_H */