xref: /linux/fs/gfs2/util.h (revision afcbce74f358a540761aa893939590a667162dff)
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 __UTIL_DOT_H__
8 #define __UTIL_DOT_H__
9 
10 #ifdef pr_fmt
11 #undef pr_fmt
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #endif
14 
15 #include <linux/mempool.h>
16 
17 #include "incore.h"
18 
19 #define fs_emerg(fs, fmt, ...)						\
20 	pr_emerg("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
21 #define fs_warn(fs, fmt, ...)						\
22 	pr_warn("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
23 #define fs_err(fs, fmt, ...)						\
24 	pr_err("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
25 #define fs_info(fs, fmt, ...)						\
26 	pr_info("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
27 
28 void gfs2_assert_i(struct gfs2_sbd *sdp);
29 
30 #define gfs2_assert(sdp, assertion) \
31 do { \
32 	if (unlikely(!(assertion))) { \
33 		gfs2_assert_i(sdp); \
34 		BUG(); \
35         } \
36 } while (0)
37 
38 
39 void gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
40 			    const char *function, char *file, unsigned int line);
41 
42 #define gfs2_assert_withdraw(sdp, assertion) \
43 	({ \
44 		bool _bool = (assertion); \
45 		if (unlikely(!_bool)) \
46 			gfs2_assert_withdraw_i((sdp), #assertion, \
47 					__func__, __FILE__, __LINE__); \
48 		!_bool; \
49 	})
50 
51 void gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
52 			const char *function, char *file, unsigned int line);
53 
54 #define gfs2_assert_warn(sdp, assertion) \
55 	({ \
56 		bool _bool = (assertion); \
57 		if (unlikely(!_bool)) \
58 			gfs2_assert_warn_i((sdp), #assertion, \
59 					__func__, __FILE__, __LINE__); \
60 		!_bool; \
61 	})
62 
63 void gfs2_consist_i(struct gfs2_sbd *sdp,
64 		    const char *function, char *file, unsigned int line);
65 
66 #define gfs2_consist(sdp) \
67 gfs2_consist_i((sdp), __func__, __FILE__, __LINE__)
68 
69 
70 void gfs2_consist_inode_i(struct gfs2_inode *ip,
71 			  const char *function, char *file, unsigned int line);
72 
73 #define gfs2_consist_inode(ip) \
74 gfs2_consist_inode_i((ip), __func__, __FILE__, __LINE__)
75 
76 
77 void gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd,
78 			  const char *function, char *file, unsigned int line);
79 
80 #define gfs2_consist_rgrpd(rgd) \
81 gfs2_consist_rgrpd_i((rgd), __func__, __FILE__, __LINE__)
82 
83 
84 void gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
85 			const char *function,
86 			char *file, unsigned int line);
87 
88 static inline int gfs2_meta_check(struct gfs2_sbd *sdp,
89 				    struct buffer_head *bh)
90 {
91 	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
92 	u32 magic = be32_to_cpu(mh->mh_magic);
93 	if (unlikely(magic != GFS2_MAGIC)) {
94 		fs_err(sdp, "Magic number missing at %llu\n",
95 		       (unsigned long long)bh->b_blocknr);
96 		return -EIO;
97 	}
98 	return 0;
99 }
100 
101 void gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
102 			    u16 type, u16 t,
103 			    const char *function,
104 			    char *file, unsigned int line);
105 
106 static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp,
107 					struct buffer_head *bh,
108 					u16 type,
109 					const char *function,
110 					char *file, unsigned int line)
111 {
112 	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
113 	u32 magic = be32_to_cpu(mh->mh_magic);
114 	u16 t = be32_to_cpu(mh->mh_type);
115 	if (unlikely(magic != GFS2_MAGIC)) {
116 		gfs2_meta_check_ii(sdp, bh, function,
117 				   file, line);
118 		return -EIO;
119 	}
120         if (unlikely(t != type)) {
121 		gfs2_metatype_check_ii(sdp, bh, type, t, function,
122 				       file, line);
123 		return -EIO;
124 	}
125 	return 0;
126 }
127 
128 #define gfs2_metatype_check(sdp, bh, type) \
129 gfs2_metatype_check_i((sdp), (bh), (type), __func__, __FILE__, __LINE__)
130 
131 static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type,
132 				     u16 format)
133 {
134 	struct gfs2_meta_header *mh;
135 	mh = (struct gfs2_meta_header *)bh->b_data;
136 	mh->mh_type = cpu_to_be32(type);
137 	mh->mh_format = cpu_to_be32(format);
138 }
139 
140 
141 void gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,
142 		     char *file, unsigned int line);
143 
144 int check_journal_clean(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
145 		        bool verbose);
146 int gfs2_freeze_lock_shared(struct gfs2_sbd *sdp);
147 void gfs2_freeze_unlock(struct gfs2_sbd *sdp);
148 
149 #define gfs2_io_error(sdp) \
150 gfs2_io_error_i((sdp), __func__, __FILE__, __LINE__)
151 
152 
153 void gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
154 			const char *function, char *file, unsigned int line);
155 
156 #define gfs2_io_error_bh(sdp, bh) \
157 gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__)
158 
159 
160 extern struct kmem_cache *gfs2_glock_cachep;
161 extern struct kmem_cache *gfs2_glock_aspace_cachep;
162 extern struct kmem_cache *gfs2_inode_cachep;
163 extern struct kmem_cache *gfs2_bufdata_cachep;
164 extern struct kmem_cache *gfs2_rgrpd_cachep;
165 extern struct kmem_cache *gfs2_quotad_cachep;
166 extern struct kmem_cache *gfs2_qadata_cachep;
167 extern struct kmem_cache *gfs2_trans_cachep;
168 extern mempool_t *gfs2_page_pool;
169 extern struct workqueue_struct *gfs2_control_wq;
170 
171 static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
172 					   unsigned int *p)
173 {
174 	unsigned int x;
175 	spin_lock(&gt->gt_spin);
176 	x = *p;
177 	spin_unlock(&gt->gt_spin);
178 	return x;
179 }
180 
181 /**
182  * gfs2_withdrawn - test whether the file system is withdrawn
183  * @sdp: the superblock
184  */
185 static inline bool gfs2_withdrawn(struct gfs2_sbd *sdp)
186 {
187 	return unlikely(test_bit(SDF_WITHDRAWN, &sdp->sd_flags));
188 }
189 
190 #define gfs2_tune_get(sdp, field) \
191 gfs2_tune_get_i(&(sdp)->sd_tune, &(sdp)->sd_tune.field)
192 
193 __printf(2, 3)
194 void gfs2_lm(struct gfs2_sbd *sdp, const char *fmt, ...);
195 
196 void gfs2_withdraw_func(struct work_struct *work);
197 void gfs2_withdraw(struct gfs2_sbd *sdp);
198 
199 #endif /* __UTIL_DOT_H__ */
200