xref: /openbmc/linux/fs/gfs2/util.h (revision b3b94faa)
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
4  *
5  * This copyrighted material is made available to anyone wishing to use,
6  * modify, copy, or redistribute it subject to the terms and conditions
7  * of the GNU General Public License v.2.
8  */
9 
10 #ifndef __UTIL_DOT_H__
11 #define __UTIL_DOT_H__
12 
13 uint32_t gfs2_disk_hash(const char *data, int len);
14 
15 
16 #define fs_printk(level, fs, fmt, arg...) \
17 	printk(level "GFS2: fsid=%s: " fmt , (fs)->sd_fsname , ## arg)
18 
19 #define fs_info(fs, fmt, arg...) \
20 	fs_printk(KERN_INFO , fs , fmt , ## arg)
21 
22 #define fs_warn(fs, fmt, arg...) \
23 	fs_printk(KERN_WARNING , fs , fmt , ## arg)
24 
25 #define fs_err(fs, fmt, arg...) \
26 	fs_printk(KERN_ERR, fs , fmt , ## arg)
27 
28 
29 void gfs2_assert_i(struct gfs2_sbd *sdp);
30 
31 #define gfs2_assert(sdp, assertion) \
32 do { \
33 	if (unlikely(!(assertion))) { \
34 		gfs2_assert_i(sdp); \
35 		BUG(); \
36         } \
37 } while (0)
38 
39 
40 int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
41 			   const char *function, char *file, unsigned int line);
42 
43 #define gfs2_assert_withdraw(sdp, assertion) \
44 ((likely(assertion)) ? 0 : gfs2_assert_withdraw_i((sdp), #assertion, \
45 					__FUNCTION__, __FILE__, __LINE__))
46 
47 
48 int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
49 		       const char *function, char *file, unsigned int line);
50 
51 #define gfs2_assert_warn(sdp, assertion) \
52 ((likely(assertion)) ? 0 : gfs2_assert_warn_i((sdp), #assertion, \
53 					__FUNCTION__, __FILE__, __LINE__))
54 
55 
56 int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide,
57 		   const char *function, char *file, unsigned int line);
58 
59 #define gfs2_consist(sdp) \
60 gfs2_consist_i((sdp), 0, __FUNCTION__, __FILE__, __LINE__)
61 
62 
63 int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
64 			 const char *function, char *file, unsigned int line);
65 
66 #define gfs2_consist_inode(ip) \
67 gfs2_consist_inode_i((ip), 0, __FUNCTION__, __FILE__, __LINE__)
68 
69 
70 int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
71 			 const char *function, char *file, unsigned int line);
72 
73 #define gfs2_consist_rgrpd(rgd) \
74 gfs2_consist_rgrpd_i((rgd), 0, __FUNCTION__, __FILE__, __LINE__)
75 
76 
77 int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
78 		       const char *type, const char *function,
79 		       char *file, unsigned int line);
80 
81 static inline int gfs2_meta_check_i(struct gfs2_sbd *sdp,
82 				    struct buffer_head *bh,
83 				    const char *function,
84 				    char *file, unsigned int line)
85 {
86 	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
87 	uint32_t magic = mh->mh_magic;
88 	magic = be32_to_cpu(magic);
89 	if (unlikely(magic != GFS2_MAGIC))
90 		return gfs2_meta_check_ii(sdp, bh, "magic number", function,
91 					  file, line);
92 	return 0;
93 }
94 
95 #define gfs2_meta_check(sdp, bh) \
96 gfs2_meta_check_i((sdp), (bh), __FUNCTION__, __FILE__, __LINE__)
97 
98 
99 int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
100 			   uint16_t type, uint16_t t,
101 			   const char *function,
102 			   char *file, unsigned int line);
103 
104 static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp,
105 					struct buffer_head *bh,
106 					uint16_t type,
107 					const char *function,
108 					char *file, unsigned int line)
109 {
110 	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
111 	uint32_t magic = mh->mh_magic;
112 	uint16_t t = mh->mh_type;
113 	magic = be32_to_cpu(magic);
114 	if (unlikely(magic != GFS2_MAGIC))
115 		return gfs2_meta_check_ii(sdp, bh, "magic number", function,
116 					  file, line);
117 	t = be16_to_cpu(t);
118         if (unlikely(t != type))
119 		return gfs2_metatype_check_ii(sdp, bh, type, t, function,
120 					      file, line);
121 	return 0;
122 }
123 
124 #define gfs2_metatype_check(sdp, bh, type) \
125 gfs2_metatype_check_i((sdp), (bh), (type), __FUNCTION__, __FILE__, __LINE__)
126 
127 static inline void gfs2_metatype_set(struct buffer_head *bh, uint16_t type,
128 				     uint16_t format)
129 {
130 	struct gfs2_meta_header *mh;
131 	mh = (struct gfs2_meta_header *)bh->b_data;
132 	mh->mh_type = cpu_to_be16(type);
133 	mh->mh_format = cpu_to_be16(format);
134 }
135 
136 
137 int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,
138 		    char *file, unsigned int line);
139 
140 #define gfs2_io_error(sdp) \
141 gfs2_io_error_i((sdp), __FUNCTION__, __FILE__, __LINE__);
142 
143 
144 int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
145 		       const char *function, char *file, unsigned int line);
146 
147 #define gfs2_io_error_bh(sdp, bh) \
148 gfs2_io_error_bh_i((sdp), (bh), __FUNCTION__, __FILE__, __LINE__);
149 
150 
151 extern kmem_cache_t *gfs2_glock_cachep;
152 extern kmem_cache_t *gfs2_inode_cachep;
153 extern kmem_cache_t *gfs2_bufdata_cachep;
154 
155 struct gfs2_user_buffer {
156 	char __user *ub_data;
157 	unsigned int ub_size;
158 	unsigned int ub_count;
159 };
160 
161 int gfs2_add_bh_to_ub(struct gfs2_user_buffer *ub, struct buffer_head *bh);
162 
163 static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
164 					   unsigned int *p)
165 {
166 	unsigned int x;
167 	spin_lock(&gt->gt_spin);
168 	x = *p;
169 	spin_unlock(&gt->gt_spin);
170 	return x;
171 }
172 
173 #define gfs2_tune_get(sdp, field) \
174 gfs2_tune_get_i(&(sdp)->sd_tune, &(sdp)->sd_tune.field)
175 
176 void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
177 		      unsigned int bit, int new_value);
178 
179 #endif /* __UTIL_DOT_H__ */
180 
181