David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 13 | |
| 14 | #define fs_printk(level, fs, fmt, arg...) \ |
| 15 | printk(level "GFS2: fsid=%s: " fmt , (fs)->sd_fsname , ## arg) |
| 16 | |
| 17 | #define fs_info(fs, fmt, arg...) \ |
| 18 | fs_printk(KERN_INFO , fs , fmt , ## arg) |
| 19 | |
| 20 | #define fs_warn(fs, fmt, arg...) \ |
| 21 | fs_printk(KERN_WARNING , fs , fmt , ## arg) |
| 22 | |
| 23 | #define fs_err(fs, fmt, arg...) \ |
| 24 | fs_printk(KERN_ERR, fs , fmt , ## arg) |
| 25 | |
| 26 | |
| 27 | void gfs2_assert_i(struct gfs2_sbd *sdp); |
| 28 | |
| 29 | #define gfs2_assert(sdp, assertion) \ |
| 30 | do { \ |
| 31 | if (unlikely(!(assertion))) { \ |
| 32 | gfs2_assert_i(sdp); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 33 | } \ |
| 34 | } while (0) |
| 35 | |
| 36 | |
| 37 | int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion, |
| 38 | const char *function, char *file, unsigned int line); |
| 39 | |
| 40 | #define gfs2_assert_withdraw(sdp, assertion) \ |
| 41 | ((likely(assertion)) ? 0 : gfs2_assert_withdraw_i((sdp), #assertion, \ |
| 42 | __FUNCTION__, __FILE__, __LINE__)) |
| 43 | |
| 44 | |
| 45 | int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, |
| 46 | const char *function, char *file, unsigned int line); |
| 47 | |
| 48 | #define gfs2_assert_warn(sdp, assertion) \ |
| 49 | ((likely(assertion)) ? 0 : gfs2_assert_warn_i((sdp), #assertion, \ |
| 50 | __FUNCTION__, __FILE__, __LINE__)) |
| 51 | |
| 52 | |
| 53 | int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, |
| 54 | const char *function, char *file, unsigned int line); |
| 55 | |
| 56 | #define gfs2_consist(sdp) \ |
| 57 | gfs2_consist_i((sdp), 0, __FUNCTION__, __FILE__, __LINE__) |
| 58 | |
| 59 | |
| 60 | int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, |
| 61 | const char *function, char *file, unsigned int line); |
| 62 | |
| 63 | #define gfs2_consist_inode(ip) \ |
| 64 | gfs2_consist_inode_i((ip), 0, __FUNCTION__, __FILE__, __LINE__) |
| 65 | |
| 66 | |
| 67 | int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide, |
| 68 | const char *function, char *file, unsigned int line); |
| 69 | |
| 70 | #define gfs2_consist_rgrpd(rgd) \ |
| 71 | gfs2_consist_rgrpd_i((rgd), 0, __FUNCTION__, __FILE__, __LINE__) |
| 72 | |
| 73 | |
| 74 | int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, |
| 75 | const char *type, const char *function, |
| 76 | char *file, unsigned int line); |
| 77 | |
| 78 | static inline int gfs2_meta_check_i(struct gfs2_sbd *sdp, |
| 79 | struct buffer_head *bh, |
| 80 | const char *function, |
| 81 | char *file, unsigned int line) |
| 82 | { |
| 83 | struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; |
| 84 | uint32_t magic = mh->mh_magic; |
| 85 | magic = be32_to_cpu(magic); |
| 86 | if (unlikely(magic != GFS2_MAGIC)) |
| 87 | return gfs2_meta_check_ii(sdp, bh, "magic number", function, |
| 88 | file, line); |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | #define gfs2_meta_check(sdp, bh) \ |
| 93 | gfs2_meta_check_i((sdp), (bh), __FUNCTION__, __FILE__, __LINE__) |
| 94 | |
| 95 | |
| 96 | int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, |
| 97 | uint16_t type, uint16_t t, |
| 98 | const char *function, |
| 99 | char *file, unsigned int line); |
| 100 | |
| 101 | static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp, |
| 102 | struct buffer_head *bh, |
| 103 | uint16_t type, |
| 104 | const char *function, |
| 105 | char *file, unsigned int line) |
| 106 | { |
| 107 | struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; |
| 108 | uint32_t magic = mh->mh_magic; |
Steven Whitehouse | e3167de | 2006-03-30 15:46:23 -0500 | [diff] [blame] | 109 | uint16_t t = be32_to_cpu(mh->mh_type); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 110 | magic = be32_to_cpu(magic); |
| 111 | if (unlikely(magic != GFS2_MAGIC)) |
| 112 | return gfs2_meta_check_ii(sdp, bh, "magic number", function, |
| 113 | file, line); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 114 | if (unlikely(t != type)) |
| 115 | return gfs2_metatype_check_ii(sdp, bh, type, t, function, |
| 116 | file, line); |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | #define gfs2_metatype_check(sdp, bh, type) \ |
| 121 | gfs2_metatype_check_i((sdp), (bh), (type), __FUNCTION__, __FILE__, __LINE__) |
| 122 | |
| 123 | static inline void gfs2_metatype_set(struct buffer_head *bh, uint16_t type, |
| 124 | uint16_t format) |
| 125 | { |
| 126 | struct gfs2_meta_header *mh; |
| 127 | mh = (struct gfs2_meta_header *)bh->b_data; |
Steven Whitehouse | e3167de | 2006-03-30 15:46:23 -0500 | [diff] [blame] | 128 | mh->mh_type = cpu_to_be32(type); |
| 129 | mh->mh_format = cpu_to_be32(format); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
| 133 | int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, |
| 134 | char *file, unsigned int line); |
| 135 | |
| 136 | #define gfs2_io_error(sdp) \ |
| 137 | gfs2_io_error_i((sdp), __FUNCTION__, __FILE__, __LINE__); |
| 138 | |
| 139 | |
| 140 | int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, |
| 141 | const char *function, char *file, unsigned int line); |
| 142 | |
| 143 | #define gfs2_io_error_bh(sdp, bh) \ |
| 144 | gfs2_io_error_bh_i((sdp), (bh), __FUNCTION__, __FILE__, __LINE__); |
| 145 | |
| 146 | |
| 147 | extern kmem_cache_t *gfs2_glock_cachep; |
| 148 | extern kmem_cache_t *gfs2_inode_cachep; |
| 149 | extern kmem_cache_t *gfs2_bufdata_cachep; |
| 150 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 151 | static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt, |
| 152 | unsigned int *p) |
| 153 | { |
| 154 | unsigned int x; |
| 155 | spin_lock(>->gt_spin); |
| 156 | x = *p; |
| 157 | spin_unlock(>->gt_spin); |
| 158 | return x; |
| 159 | } |
| 160 | |
| 161 | #define gfs2_tune_get(sdp, field) \ |
| 162 | gfs2_tune_get_i(&(sdp)->sd_tune, &(sdp)->sd_tune.field) |
| 163 | |
| 164 | void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap, |
| 165 | unsigned int bit, int new_value); |
| 166 | |
| 167 | #endif /* __UTIL_DOT_H__ */ |
| 168 | |