Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1 | #include <linux/ceph/ceph_debug.h> |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2 | |
| 3 | #include <linux/bug.h> |
| 4 | #include <linux/err.h> |
| 5 | #include <linux/random.h> |
| 6 | #include <linux/slab.h> |
| 7 | #include <linux/types.h> |
| 8 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 9 | #include <linux/ceph/mdsmap.h> |
| 10 | #include <linux/ceph/messenger.h> |
| 11 | #include <linux/ceph/decode.h> |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 12 | |
| 13 | #include "super.h" |
| 14 | |
| 15 | |
| 16 | /* |
| 17 | * choose a random mds that is "up" (i.e. has a state > 0), or -1. |
| 18 | */ |
| 19 | int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m) |
| 20 | { |
| 21 | int n = 0; |
| 22 | int i; |
Sam Lang | a84cd29 | 2013-04-09 16:49:11 -0500 | [diff] [blame] | 23 | |
| 24 | /* special case for one mds */ |
Yan, Zheng | 76201b6 | 2017-03-28 17:04:13 +0800 | [diff] [blame] | 25 | if (1 == m->m_num_mds && m->m_info[0].state > 0) |
Sam Lang | a84cd29 | 2013-04-09 16:49:11 -0500 | [diff] [blame] | 26 | return 0; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 27 | |
| 28 | /* count */ |
Yan, Zheng | 76201b6 | 2017-03-28 17:04:13 +0800 | [diff] [blame] | 29 | for (i = 0; i < m->m_num_mds; i++) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 30 | if (m->m_info[i].state > 0) |
| 31 | n++; |
| 32 | if (n == 0) |
| 33 | return -1; |
| 34 | |
| 35 | /* pick */ |
Sam Lang | a84cd29 | 2013-04-09 16:49:11 -0500 | [diff] [blame] | 36 | n = prandom_u32() % n; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 37 | i = 0; |
| 38 | for (i = 0; n > 0; i++, n--) |
| 39 | while (m->m_info[i].state <= 0) |
| 40 | i++; |
| 41 | |
| 42 | return i; |
| 43 | } |
| 44 | |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 45 | #define __decode_and_drop_type(p, end, type, bad) \ |
| 46 | do { \ |
| 47 | if (*p + sizeof(type) > end) \ |
| 48 | goto bad; \ |
| 49 | *p += sizeof(type); \ |
| 50 | } while (0) |
| 51 | |
| 52 | #define __decode_and_drop_set(p, end, type, bad) \ |
| 53 | do { \ |
| 54 | u32 n; \ |
| 55 | size_t need; \ |
| 56 | ceph_decode_32_safe(p, end, n, bad); \ |
| 57 | need = sizeof(type) * n; \ |
| 58 | ceph_decode_need(p, end, need, bad); \ |
| 59 | *p += need; \ |
| 60 | } while (0) |
| 61 | |
| 62 | #define __decode_and_drop_map(p, end, ktype, vtype, bad) \ |
| 63 | do { \ |
| 64 | u32 n; \ |
| 65 | size_t need; \ |
| 66 | ceph_decode_32_safe(p, end, n, bad); \ |
| 67 | need = (sizeof(ktype) + sizeof(vtype)) * n; \ |
| 68 | ceph_decode_need(p, end, need, bad); \ |
| 69 | *p += need; \ |
| 70 | } while (0) |
| 71 | |
| 72 | |
| 73 | static int __decode_and_drop_compat_set(void **p, void* end) |
| 74 | { |
| 75 | int i; |
| 76 | /* compat, ro_compat, incompat*/ |
| 77 | for (i = 0; i < 3; i++) { |
| 78 | u32 n; |
| 79 | ceph_decode_need(p, end, sizeof(u64) + sizeof(u32), bad); |
| 80 | /* mask */ |
| 81 | *p += sizeof(u64); |
| 82 | /* names (map<u64, string>) */ |
| 83 | n = ceph_decode_32(p); |
| 84 | while (n-- > 0) { |
| 85 | u32 len; |
| 86 | ceph_decode_need(p, end, sizeof(u64) + sizeof(u32), |
| 87 | bad); |
| 88 | *p += sizeof(u64); |
| 89 | len = ceph_decode_32(p); |
| 90 | ceph_decode_need(p, end, len, bad); |
| 91 | *p += len; |
| 92 | } |
| 93 | } |
| 94 | return 0; |
| 95 | bad: |
| 96 | return -1; |
| 97 | } |
| 98 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 99 | /* |
| 100 | * Decode an MDS map |
| 101 | * |
| 102 | * Ignore any fields we don't care about (there are quite a few of |
| 103 | * them). |
| 104 | */ |
| 105 | struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end) |
| 106 | { |
| 107 | struct ceph_mdsmap *m; |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 108 | const void *start = *p; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 109 | int i, j, n; |
| 110 | int err = -EINVAL; |
Yan, Zheng | d463a43 | 2016-03-31 15:53:01 +0800 | [diff] [blame] | 111 | u8 mdsmap_v, mdsmap_cv; |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 112 | u16 mdsmap_ev; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 113 | |
| 114 | m = kzalloc(sizeof(*m), GFP_NOFS); |
| 115 | if (m == NULL) |
| 116 | return ERR_PTR(-ENOMEM); |
| 117 | |
Yan, Zheng | d463a43 | 2016-03-31 15:53:01 +0800 | [diff] [blame] | 118 | ceph_decode_need(p, end, 1 + 1, bad); |
| 119 | mdsmap_v = ceph_decode_8(p); |
| 120 | mdsmap_cv = ceph_decode_8(p); |
| 121 | if (mdsmap_v >= 4) { |
| 122 | u32 mdsmap_len; |
| 123 | ceph_decode_32_safe(p, end, mdsmap_len, bad); |
| 124 | if (end < *p + mdsmap_len) |
| 125 | goto bad; |
| 126 | end = *p + mdsmap_len; |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 127 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 128 | |
| 129 | ceph_decode_need(p, end, 8*sizeof(u32) + sizeof(u64), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 130 | m->m_epoch = ceph_decode_32(p); |
| 131 | m->m_client_epoch = ceph_decode_32(p); |
| 132 | m->m_last_failure = ceph_decode_32(p); |
| 133 | m->m_root = ceph_decode_32(p); |
| 134 | m->m_session_timeout = ceph_decode_32(p); |
| 135 | m->m_session_autoclose = ceph_decode_32(p); |
| 136 | m->m_max_file_size = ceph_decode_64(p); |
| 137 | m->m_max_mds = ceph_decode_32(p); |
Yan, Zheng | 76201b6 | 2017-03-28 17:04:13 +0800 | [diff] [blame] | 138 | m->m_num_mds = m->m_max_mds; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 139 | |
Yan, Zheng | 76201b6 | 2017-03-28 17:04:13 +0800 | [diff] [blame] | 140 | m->m_info = kcalloc(m->m_num_mds, sizeof(*m->m_info), GFP_NOFS); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 141 | if (m->m_info == NULL) |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 142 | goto nomem; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 143 | |
| 144 | /* pick out active nodes from mds_info (state > 0) */ |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 145 | n = ceph_decode_32(p); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 146 | for (i = 0; i < n; i++) { |
Sage Weil | 94045e1 | 2009-11-19 15:31:50 -0800 | [diff] [blame] | 147 | u64 global_id; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 148 | u32 namelen; |
| 149 | s32 mds, inc, state; |
| 150 | u64 state_seq; |
Yan, Zheng | d463a43 | 2016-03-31 15:53:01 +0800 | [diff] [blame] | 151 | u8 info_v; |
| 152 | void *info_end = NULL; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 153 | struct ceph_entity_addr addr; |
| 154 | u32 num_export_targets; |
| 155 | void *pexport_targets = NULL; |
Sage Weil | 0deb01c | 2010-06-17 14:19:01 -0700 | [diff] [blame] | 156 | struct ceph_timespec laggy_since; |
Dan Carpenter | 6af8652 | 2013-05-29 06:46:56 -0500 | [diff] [blame] | 157 | struct ceph_mds_info *info; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 158 | |
Yan, Zheng | d463a43 | 2016-03-31 15:53:01 +0800 | [diff] [blame] | 159 | ceph_decode_need(p, end, sizeof(u64) + 1, bad); |
Sage Weil | 94045e1 | 2009-11-19 15:31:50 -0800 | [diff] [blame] | 160 | global_id = ceph_decode_64(p); |
Yan, Zheng | d463a43 | 2016-03-31 15:53:01 +0800 | [diff] [blame] | 161 | info_v= ceph_decode_8(p); |
| 162 | if (info_v >= 4) { |
| 163 | u32 info_len; |
| 164 | u8 info_cv; |
| 165 | ceph_decode_need(p, end, 1 + sizeof(u32), bad); |
| 166 | info_cv = ceph_decode_8(p); |
| 167 | info_len = ceph_decode_32(p); |
| 168 | info_end = *p + info_len; |
| 169 | if (info_end > end) |
| 170 | goto bad; |
| 171 | } |
| 172 | |
| 173 | ceph_decode_need(p, end, sizeof(u64) + sizeof(u32), bad); |
Sage Weil | 94045e1 | 2009-11-19 15:31:50 -0800 | [diff] [blame] | 174 | *p += sizeof(u64); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 175 | namelen = ceph_decode_32(p); /* skip mds name */ |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 176 | *p += namelen; |
| 177 | |
| 178 | ceph_decode_need(p, end, |
Sage Weil | e251e28 | 2009-10-07 16:38:19 -0700 | [diff] [blame] | 179 | 4*sizeof(u32) + sizeof(u64) + |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 180 | sizeof(addr) + sizeof(struct ceph_timespec), |
| 181 | bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 182 | mds = ceph_decode_32(p); |
| 183 | inc = ceph_decode_32(p); |
| 184 | state = ceph_decode_32(p); |
| 185 | state_seq = ceph_decode_64(p); |
Sage Weil | 94045e1 | 2009-11-19 15:31:50 -0800 | [diff] [blame] | 186 | ceph_decode_copy(p, &addr, sizeof(addr)); |
| 187 | ceph_decode_addr(&addr); |
Sage Weil | 0deb01c | 2010-06-17 14:19:01 -0700 | [diff] [blame] | 188 | ceph_decode_copy(p, &laggy_since, sizeof(laggy_since)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 189 | *p += sizeof(u32); |
| 190 | ceph_decode_32_safe(p, end, namelen, bad); |
Sage Weil | e251e28 | 2009-10-07 16:38:19 -0700 | [diff] [blame] | 191 | *p += namelen; |
Yan, Zheng | d463a43 | 2016-03-31 15:53:01 +0800 | [diff] [blame] | 192 | if (info_v >= 2) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 193 | ceph_decode_32_safe(p, end, num_export_targets, bad); |
| 194 | pexport_targets = *p; |
Sage Weil | e251e28 | 2009-10-07 16:38:19 -0700 | [diff] [blame] | 195 | *p += num_export_targets * sizeof(u32); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 196 | } else { |
| 197 | num_export_targets = 0; |
| 198 | } |
| 199 | |
Yan, Zheng | d463a43 | 2016-03-31 15:53:01 +0800 | [diff] [blame] | 200 | if (info_end && *p != info_end) { |
| 201 | if (*p > info_end) |
| 202 | goto bad; |
| 203 | *p = info_end; |
| 204 | } |
| 205 | |
Sage Weil | 94045e1 | 2009-11-19 15:31:50 -0800 | [diff] [blame] | 206 | dout("mdsmap_decode %d/%d %lld mds%d.%d %s %s\n", |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 207 | i+1, n, global_id, mds, inc, |
| 208 | ceph_pr_addr(&addr.in_addr), |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 209 | ceph_mds_state_name(state)); |
Dan Carpenter | 6af8652 | 2013-05-29 06:46:56 -0500 | [diff] [blame] | 210 | |
Yan, Zheng | 76201b6 | 2017-03-28 17:04:13 +0800 | [diff] [blame] | 211 | if (mds < 0 || state <= 0) |
Dan Carpenter | 6af8652 | 2013-05-29 06:46:56 -0500 | [diff] [blame] | 212 | continue; |
| 213 | |
Yan, Zheng | 76201b6 | 2017-03-28 17:04:13 +0800 | [diff] [blame] | 214 | if (mds >= m->m_num_mds) { |
| 215 | int new_num = max(mds + 1, m->m_num_mds * 2); |
| 216 | void *new_m_info = krealloc(m->m_info, |
| 217 | new_num * sizeof(*m->m_info), |
| 218 | GFP_NOFS | __GFP_ZERO); |
| 219 | if (!new_m_info) |
| 220 | goto nomem; |
| 221 | m->m_info = new_m_info; |
| 222 | m->m_num_mds = new_num; |
| 223 | } |
| 224 | |
Dan Carpenter | 6af8652 | 2013-05-29 06:46:56 -0500 | [diff] [blame] | 225 | info = &m->m_info[mds]; |
| 226 | info->global_id = global_id; |
| 227 | info->state = state; |
| 228 | info->addr = addr; |
| 229 | info->laggy = (laggy_since.tv_sec != 0 || |
| 230 | laggy_since.tv_nsec != 0); |
| 231 | info->num_export_targets = num_export_targets; |
| 232 | if (num_export_targets) { |
| 233 | info->export_targets = kcalloc(num_export_targets, |
| 234 | sizeof(u32), GFP_NOFS); |
| 235 | if (info->export_targets == NULL) |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 236 | goto nomem; |
Dan Carpenter | 6af8652 | 2013-05-29 06:46:56 -0500 | [diff] [blame] | 237 | for (j = 0; j < num_export_targets; j++) |
| 238 | info->export_targets[j] = |
| 239 | ceph_decode_32(&pexport_targets); |
| 240 | } else { |
| 241 | info->export_targets = NULL; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
Yan, Zheng | 76201b6 | 2017-03-28 17:04:13 +0800 | [diff] [blame] | 244 | if (m->m_num_mds > m->m_max_mds) { |
| 245 | /* find max up mds */ |
| 246 | for (i = m->m_num_mds; i >= m->m_max_mds; i--) { |
| 247 | if (i == 0 || m->m_info[i-1].state > 0) |
| 248 | break; |
| 249 | } |
| 250 | m->m_num_mds = i; |
| 251 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 252 | |
| 253 | /* pg_pools */ |
| 254 | ceph_decode_32_safe(p, end, n, bad); |
| 255 | m->m_num_data_pg_pools = n; |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 256 | m->m_data_pg_pools = kcalloc(n, sizeof(u64), GFP_NOFS); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 257 | if (!m->m_data_pg_pools) |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 258 | goto nomem; |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 259 | ceph_decode_need(p, end, sizeof(u64)*(n+1), bad); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 260 | for (i = 0; i < n; i++) |
Sage Weil | 4f6a7e5 | 2013-02-23 10:41:09 -0800 | [diff] [blame] | 261 | m->m_data_pg_pools[i] = ceph_decode_64(p); |
| 262 | m->m_cas_pg_pool = ceph_decode_64(p); |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 263 | m->m_enabled = m->m_epoch > 1; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 264 | |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 265 | mdsmap_ev = 1; |
| 266 | if (mdsmap_v >= 2) { |
| 267 | ceph_decode_16_safe(p, end, mdsmap_ev, bad_ext); |
| 268 | } |
| 269 | if (mdsmap_ev >= 3) { |
| 270 | if (__decode_and_drop_compat_set(p, end) < 0) |
| 271 | goto bad_ext; |
| 272 | } |
| 273 | /* metadata_pool */ |
| 274 | if (mdsmap_ev < 5) { |
| 275 | __decode_and_drop_type(p, end, u32, bad_ext); |
| 276 | } else { |
| 277 | __decode_and_drop_type(p, end, u64, bad_ext); |
| 278 | } |
| 279 | |
| 280 | /* created + modified + tableserver */ |
| 281 | __decode_and_drop_type(p, end, struct ceph_timespec, bad_ext); |
| 282 | __decode_and_drop_type(p, end, struct ceph_timespec, bad_ext); |
| 283 | __decode_and_drop_type(p, end, u32, bad_ext); |
| 284 | |
| 285 | /* in */ |
| 286 | { |
| 287 | int num_laggy = 0; |
| 288 | ceph_decode_32_safe(p, end, n, bad_ext); |
| 289 | ceph_decode_need(p, end, sizeof(u32) * n, bad_ext); |
| 290 | |
| 291 | for (i = 0; i < n; i++) { |
| 292 | s32 mds = ceph_decode_32(p); |
Yan, Zheng | 76201b6 | 2017-03-28 17:04:13 +0800 | [diff] [blame] | 293 | if (mds >= 0 && mds < m->m_num_mds) { |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 294 | if (m->m_info[mds].laggy) |
| 295 | num_laggy++; |
| 296 | } |
| 297 | } |
| 298 | m->m_num_laggy = num_laggy; |
Yan, Zheng | 76201b6 | 2017-03-28 17:04:13 +0800 | [diff] [blame] | 299 | |
| 300 | if (n > m->m_num_mds) { |
| 301 | void *new_m_info = krealloc(m->m_info, |
| 302 | n * sizeof(*m->m_info), |
| 303 | GFP_NOFS | __GFP_ZERO); |
| 304 | if (!new_m_info) |
| 305 | goto nomem; |
| 306 | m->m_info = new_m_info; |
| 307 | } |
| 308 | m->m_num_mds = n; |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | /* inc */ |
| 312 | __decode_and_drop_map(p, end, u32, u32, bad_ext); |
| 313 | /* up */ |
| 314 | __decode_and_drop_map(p, end, u32, u64, bad_ext); |
| 315 | /* failed */ |
| 316 | __decode_and_drop_set(p, end, u32, bad_ext); |
| 317 | /* stopped */ |
| 318 | __decode_and_drop_set(p, end, u32, bad_ext); |
| 319 | |
| 320 | if (mdsmap_ev >= 4) { |
| 321 | /* last_failure_osd_epoch */ |
| 322 | __decode_and_drop_type(p, end, u32, bad_ext); |
| 323 | } |
| 324 | if (mdsmap_ev >= 6) { |
| 325 | /* ever_allowed_snaps */ |
| 326 | __decode_and_drop_type(p, end, u8, bad_ext); |
| 327 | /* explicitly_allowed_snaps */ |
| 328 | __decode_and_drop_type(p, end, u8, bad_ext); |
| 329 | } |
| 330 | if (mdsmap_ev >= 7) { |
| 331 | /* inline_data_enabled */ |
| 332 | __decode_and_drop_type(p, end, u8, bad_ext); |
| 333 | } |
| 334 | if (mdsmap_ev >= 8) { |
| 335 | u32 name_len; |
| 336 | /* enabled */ |
| 337 | ceph_decode_8_safe(p, end, m->m_enabled, bad_ext); |
| 338 | ceph_decode_32_safe(p, end, name_len, bad_ext); |
| 339 | ceph_decode_need(p, end, name_len, bad_ext); |
| 340 | *p += name_len; |
| 341 | } |
| 342 | /* damaged */ |
| 343 | if (mdsmap_ev >= 9) { |
| 344 | size_t need; |
| 345 | ceph_decode_32_safe(p, end, n, bad_ext); |
| 346 | need = sizeof(u32) * n; |
| 347 | ceph_decode_need(p, end, need, bad_ext); |
| 348 | *p += need; |
| 349 | m->m_damaged = n > 0; |
| 350 | } else { |
| 351 | m->m_damaged = false; |
| 352 | } |
| 353 | bad_ext: |
Yan, Zheng | d463a43 | 2016-03-31 15:53:01 +0800 | [diff] [blame] | 354 | *p = end; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 355 | dout("mdsmap_decode success epoch %u\n", m->m_epoch); |
| 356 | return m; |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 357 | nomem: |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 358 | err = -ENOMEM; |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 359 | goto out_err; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 360 | bad: |
| 361 | pr_err("corrupt mdsmap\n"); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 362 | print_hex_dump(KERN_DEBUG, "mdsmap: ", |
| 363 | DUMP_PREFIX_OFFSET, 16, 1, |
| 364 | start, end - start, true); |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 365 | out_err: |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 366 | ceph_mdsmap_destroy(m); |
Emil Goode | c213b50 | 2013-05-28 16:59:00 +0200 | [diff] [blame] | 367 | return ERR_PTR(err); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | void ceph_mdsmap_destroy(struct ceph_mdsmap *m) |
| 371 | { |
| 372 | int i; |
| 373 | |
Yan, Zheng | 76201b6 | 2017-03-28 17:04:13 +0800 | [diff] [blame] | 374 | for (i = 0; i < m->m_num_mds; i++) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 375 | kfree(m->m_info[i].export_targets); |
| 376 | kfree(m->m_info); |
| 377 | kfree(m->m_data_pg_pools); |
| 378 | kfree(m); |
| 379 | } |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 380 | |
| 381 | bool ceph_mdsmap_is_cluster_available(struct ceph_mdsmap *m) |
| 382 | { |
| 383 | int i, nr_active = 0; |
| 384 | if (!m->m_enabled) |
| 385 | return false; |
| 386 | if (m->m_damaged) |
| 387 | return false; |
| 388 | if (m->m_num_laggy > 0) |
| 389 | return false; |
Yan, Zheng | 76201b6 | 2017-03-28 17:04:13 +0800 | [diff] [blame] | 390 | for (i = 0; i < m->m_num_mds; i++) { |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 391 | if (m->m_info[i].state == CEPH_MDS_STATE_ACTIVE) |
| 392 | nr_active++; |
| 393 | } |
| 394 | return nr_active > 0; |
| 395 | } |