xref: /linux/fs/gfs2/quota.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
4  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
5  */
6 
7 #ifndef __QUOTA_DOT_H__
8 #define __QUOTA_DOT_H__
9 
10 #include <linux/list_lru.h>
11 
12 struct gfs2_inode;
13 struct gfs2_sbd;
14 
15 #define NO_UID_QUOTA_CHANGE INVALID_UID
16 #define NO_GID_QUOTA_CHANGE INVALID_GID
17 
18 extern int gfs2_qa_get(struct gfs2_inode *ip);
19 extern void gfs2_qa_put(struct gfs2_inode *ip);
20 extern int gfs2_quota_hold(struct gfs2_inode *ip, kuid_t uid, kgid_t gid);
21 extern void gfs2_quota_unhold(struct gfs2_inode *ip);
22 
23 extern int gfs2_quota_lock(struct gfs2_inode *ip, kuid_t uid, kgid_t gid);
24 extern void gfs2_quota_unlock(struct gfs2_inode *ip);
25 
26 extern int gfs2_quota_check(struct gfs2_inode *ip, kuid_t uid, kgid_t gid,
27 			    struct gfs2_alloc_parms *ap);
28 extern void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
29 			      kuid_t uid, kgid_t gid);
30 
31 extern int gfs2_quota_sync(struct super_block *sb, int type);
32 extern int gfs2_quota_refresh(struct gfs2_sbd *sdp, struct kqid qid);
33 
34 extern int gfs2_quota_init(struct gfs2_sbd *sdp);
35 extern void gfs2_quota_cleanup(struct gfs2_sbd *sdp);
36 extern int gfs2_quotad(void *data);
37 
38 extern void gfs2_wake_up_statfs(struct gfs2_sbd *sdp);
39 
40 static inline int gfs2_quota_lock_check(struct gfs2_inode *ip,
41 					struct gfs2_alloc_parms *ap)
42 {
43 	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
44 	int ret;
45 
46 	ap->allowed = UINT_MAX; /* Assume we are permitted a whole lot */
47 	if (capable(CAP_SYS_RESOURCE) ||
48 	    sdp->sd_args.ar_quota == GFS2_QUOTA_OFF)
49 		return 0;
50 	ret = gfs2_quota_lock(ip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE);
51 	if (ret)
52 		return ret;
53 	if (sdp->sd_args.ar_quota != GFS2_QUOTA_ON)
54 		return 0;
55 	ret = gfs2_quota_check(ip, ip->i_inode.i_uid, ip->i_inode.i_gid, ap);
56 	if (ret)
57 		gfs2_quota_unlock(ip);
58 	return ret;
59 }
60 
61 extern const struct quotactl_ops gfs2_quotactl_ops;
62 extern struct shrinker gfs2_qd_shrinker;
63 extern struct list_lru gfs2_qd_lru;
64 extern void __init gfs2_quota_hash_init(void);
65 
66 #endif /* __QUOTA_DOT_H__ */
67