Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 1 | #include "ceph_debug.h" |
| 2 | |
| 3 | #include <linux/types.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame^] | 4 | #include <linux/slab.h> |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 5 | #include <linux/random.h> |
| 6 | #include <linux/sched.h> |
| 7 | |
| 8 | #include "mon_client.h" |
| 9 | #include "super.h" |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 10 | #include "auth.h" |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 11 | #include "decode.h" |
| 12 | |
| 13 | /* |
| 14 | * Interact with Ceph monitor cluster. Handle requests for new map |
| 15 | * versions, and periodically resend as needed. Also implement |
| 16 | * statfs() and umount(). |
| 17 | * |
| 18 | * A small cluster of Ceph "monitors" are responsible for managing critical |
| 19 | * cluster configuration and state information. An odd number (e.g., 3, 5) |
| 20 | * of cmon daemons use a modified version of the Paxos part-time parliament |
| 21 | * algorithm to manage the MDS map (mds cluster membership), OSD map, and |
| 22 | * list of clients who have mounted the file system. |
| 23 | * |
| 24 | * We maintain an open, active session with a monitor at all times in order to |
| 25 | * receive timely MDSMap updates. We periodically send a keepalive byte on the |
| 26 | * TCP socket to ensure we detect a failure. If the connection does break, we |
| 27 | * randomly hunt for a new monitor. Once the connection is reestablished, we |
| 28 | * resend any outstanding requests. |
| 29 | */ |
| 30 | |
| 31 | const static struct ceph_connection_operations mon_con_ops; |
| 32 | |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 33 | static int __validate_auth(struct ceph_mon_client *monc); |
| 34 | |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 35 | /* |
| 36 | * Decode a monmap blob (e.g., during mount). |
| 37 | */ |
| 38 | struct ceph_monmap *ceph_monmap_decode(void *p, void *end) |
| 39 | { |
| 40 | struct ceph_monmap *m = NULL; |
| 41 | int i, err = -EINVAL; |
| 42 | struct ceph_fsid fsid; |
| 43 | u32 epoch, num_mon; |
| 44 | u16 version; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 45 | u32 len; |
| 46 | |
| 47 | ceph_decode_32_safe(&p, end, len, bad); |
| 48 | ceph_decode_need(&p, end, len, bad); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 49 | |
| 50 | dout("monmap_decode %p %p len %d\n", p, end, (int)(end-p)); |
| 51 | |
| 52 | ceph_decode_16_safe(&p, end, version, bad); |
| 53 | |
| 54 | ceph_decode_need(&p, end, sizeof(fsid) + 2*sizeof(u32), bad); |
| 55 | ceph_decode_copy(&p, &fsid, sizeof(fsid)); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 56 | epoch = ceph_decode_32(&p); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 57 | |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 58 | num_mon = ceph_decode_32(&p); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 59 | ceph_decode_need(&p, end, num_mon*sizeof(m->mon_inst[0]), bad); |
| 60 | |
| 61 | if (num_mon >= CEPH_MAX_MON) |
| 62 | goto bad; |
| 63 | m = kmalloc(sizeof(*m) + sizeof(m->mon_inst[0])*num_mon, GFP_NOFS); |
| 64 | if (m == NULL) |
| 65 | return ERR_PTR(-ENOMEM); |
| 66 | m->fsid = fsid; |
| 67 | m->epoch = epoch; |
| 68 | m->num_mon = num_mon; |
| 69 | ceph_decode_copy(&p, m->mon_inst, num_mon*sizeof(m->mon_inst[0])); |
Sage Weil | 63f2d21 | 2009-11-03 15:17:56 -0800 | [diff] [blame] | 70 | for (i = 0; i < num_mon; i++) |
| 71 | ceph_decode_addr(&m->mon_inst[i].addr); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 72 | |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 73 | dout("monmap_decode epoch %d, num_mon %d\n", m->epoch, |
| 74 | m->num_mon); |
| 75 | for (i = 0; i < m->num_mon; i++) |
| 76 | dout("monmap_decode mon%d is %s\n", i, |
| 77 | pr_addr(&m->mon_inst[i].addr.in_addr)); |
| 78 | return m; |
| 79 | |
| 80 | bad: |
| 81 | dout("monmap_decode failed with %d\n", err); |
| 82 | kfree(m); |
| 83 | return ERR_PTR(err); |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * return true if *addr is included in the monmap. |
| 88 | */ |
| 89 | int ceph_monmap_contains(struct ceph_monmap *m, struct ceph_entity_addr *addr) |
| 90 | { |
| 91 | int i; |
| 92 | |
| 93 | for (i = 0; i < m->num_mon; i++) |
Sage Weil | 103e2d3 | 2010-01-07 16:12:36 -0800 | [diff] [blame] | 94 | if (memcmp(addr, &m->mon_inst[i].addr, sizeof(*addr)) == 0) |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 95 | return 1; |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | /* |
Sage Weil | 5ce6e9d | 2010-02-15 16:22:28 -0800 | [diff] [blame] | 100 | * Send an auth request. |
| 101 | */ |
| 102 | static void __send_prepared_auth_request(struct ceph_mon_client *monc, int len) |
| 103 | { |
| 104 | monc->pending_auth = 1; |
| 105 | monc->m_auth->front.iov_len = len; |
| 106 | monc->m_auth->hdr.front_len = cpu_to_le32(len); |
| 107 | ceph_msg_get(monc->m_auth); /* keep our ref */ |
| 108 | ceph_con_send(monc->con, monc->m_auth); |
| 109 | } |
| 110 | |
| 111 | /* |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 112 | * Close monitor session, if any. |
| 113 | */ |
| 114 | static void __close_session(struct ceph_mon_client *monc) |
| 115 | { |
| 116 | if (monc->con) { |
| 117 | dout("__close_session closing mon%d\n", monc->cur_mon); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 118 | ceph_con_revoke(monc->con, monc->m_auth); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 119 | ceph_con_close(monc->con); |
| 120 | monc->cur_mon = -1; |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 121 | monc->pending_auth = 0; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 122 | ceph_auth_reset(monc->auth); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Open a session with a (new) monitor. |
| 128 | */ |
| 129 | static int __open_session(struct ceph_mon_client *monc) |
| 130 | { |
| 131 | char r; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 132 | int ret; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 133 | |
| 134 | if (monc->cur_mon < 0) { |
| 135 | get_random_bytes(&r, 1); |
| 136 | monc->cur_mon = r % monc->monmap->num_mon; |
| 137 | dout("open_session num=%d r=%d -> mon%d\n", |
| 138 | monc->monmap->num_mon, r, monc->cur_mon); |
| 139 | monc->sub_sent = 0; |
| 140 | monc->sub_renew_after = jiffies; /* i.e., expired */ |
| 141 | monc->want_next_osdmap = !!monc->want_next_osdmap; |
| 142 | |
| 143 | dout("open_session mon%d opening\n", monc->cur_mon); |
| 144 | monc->con->peer_name.type = CEPH_ENTITY_TYPE_MON; |
| 145 | monc->con->peer_name.num = cpu_to_le64(monc->cur_mon); |
| 146 | ceph_con_open(monc->con, |
| 147 | &monc->monmap->mon_inst[monc->cur_mon].addr); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 148 | |
| 149 | /* initiatiate authentication handshake */ |
| 150 | ret = ceph_auth_build_hello(monc->auth, |
| 151 | monc->m_auth->front.iov_base, |
| 152 | monc->m_auth->front_max); |
Sage Weil | 5ce6e9d | 2010-02-15 16:22:28 -0800 | [diff] [blame] | 153 | __send_prepared_auth_request(monc, ret); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 154 | } else { |
| 155 | dout("open_session mon%d already open\n", monc->cur_mon); |
| 156 | } |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | static bool __sub_expired(struct ceph_mon_client *monc) |
| 161 | { |
| 162 | return time_after_eq(jiffies, monc->sub_renew_after); |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * Reschedule delayed work timer. |
| 167 | */ |
| 168 | static void __schedule_delayed(struct ceph_mon_client *monc) |
| 169 | { |
| 170 | unsigned delay; |
| 171 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 172 | if (monc->cur_mon < 0 || __sub_expired(monc)) |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 173 | delay = 10 * HZ; |
| 174 | else |
| 175 | delay = 20 * HZ; |
| 176 | dout("__schedule_delayed after %u\n", delay); |
| 177 | schedule_delayed_work(&monc->delayed_work, delay); |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Send subscribe request for mdsmap and/or osdmap. |
| 182 | */ |
| 183 | static void __send_subscribe(struct ceph_mon_client *monc) |
| 184 | { |
| 185 | dout("__send_subscribe sub_sent=%u exp=%u want_osd=%d\n", |
| 186 | (unsigned)monc->sub_sent, __sub_expired(monc), |
| 187 | monc->want_next_osdmap); |
| 188 | if ((__sub_expired(monc) && !monc->sub_sent) || |
| 189 | monc->want_next_osdmap == 1) { |
| 190 | struct ceph_msg *msg; |
| 191 | struct ceph_mon_subscribe_item *i; |
| 192 | void *p, *end; |
| 193 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 194 | msg = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96, 0, 0, NULL); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 195 | if (!msg) |
| 196 | return; |
| 197 | |
| 198 | p = msg->front.iov_base; |
| 199 | end = p + msg->front.iov_len; |
| 200 | |
| 201 | dout("__send_subscribe to 'mdsmap' %u+\n", |
| 202 | (unsigned)monc->have_mdsmap); |
| 203 | if (monc->want_next_osdmap) { |
| 204 | dout("__send_subscribe to 'osdmap' %u\n", |
| 205 | (unsigned)monc->have_osdmap); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 206 | ceph_encode_32(&p, 3); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 207 | ceph_encode_string(&p, end, "osdmap", 6); |
| 208 | i = p; |
| 209 | i->have = cpu_to_le64(monc->have_osdmap); |
| 210 | i->onetime = 1; |
| 211 | p += sizeof(*i); |
| 212 | monc->want_next_osdmap = 2; /* requested */ |
| 213 | } else { |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 214 | ceph_encode_32(&p, 2); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 215 | } |
| 216 | ceph_encode_string(&p, end, "mdsmap", 6); |
| 217 | i = p; |
| 218 | i->have = cpu_to_le64(monc->have_mdsmap); |
| 219 | i->onetime = 0; |
| 220 | p += sizeof(*i); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 221 | ceph_encode_string(&p, end, "monmap", 6); |
| 222 | i = p; |
| 223 | i->have = 0; |
| 224 | i->onetime = 0; |
| 225 | p += sizeof(*i); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 226 | |
| 227 | msg->front.iov_len = p - msg->front.iov_base; |
| 228 | msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); |
| 229 | ceph_con_send(monc->con, msg); |
| 230 | |
| 231 | monc->sub_sent = jiffies | 1; /* never 0 */ |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | static void handle_subscribe_ack(struct ceph_mon_client *monc, |
| 236 | struct ceph_msg *msg) |
| 237 | { |
| 238 | unsigned seconds; |
Sage Weil | 07bd10f | 2009-10-14 17:26:40 -0700 | [diff] [blame] | 239 | struct ceph_mon_subscribe_ack *h = msg->front.iov_base; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 240 | |
Sage Weil | 07bd10f | 2009-10-14 17:26:40 -0700 | [diff] [blame] | 241 | if (msg->front.iov_len < sizeof(*h)) |
| 242 | goto bad; |
| 243 | seconds = le32_to_cpu(h->duration); |
| 244 | |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 245 | mutex_lock(&monc->mutex); |
| 246 | if (monc->hunting) { |
| 247 | pr_info("mon%d %s session established\n", |
| 248 | monc->cur_mon, pr_addr(&monc->con->peer_addr.in_addr)); |
| 249 | monc->hunting = false; |
| 250 | } |
| 251 | dout("handle_subscribe_ack after %d seconds\n", seconds); |
Sage Weil | 0656d11 | 2009-10-08 10:25:46 -0700 | [diff] [blame] | 252 | monc->sub_renew_after = monc->sub_sent + (seconds >> 1)*HZ - 1; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 253 | monc->sub_sent = 0; |
| 254 | mutex_unlock(&monc->mutex); |
| 255 | return; |
| 256 | bad: |
| 257 | pr_err("got corrupt subscribe-ack msg\n"); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 258 | ceph_msg_dump(msg); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Keep track of which maps we have |
| 263 | */ |
| 264 | int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, u32 got) |
| 265 | { |
| 266 | mutex_lock(&monc->mutex); |
| 267 | monc->have_mdsmap = got; |
| 268 | mutex_unlock(&monc->mutex); |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | int ceph_monc_got_osdmap(struct ceph_mon_client *monc, u32 got) |
| 273 | { |
| 274 | mutex_lock(&monc->mutex); |
| 275 | monc->have_osdmap = got; |
| 276 | monc->want_next_osdmap = 0; |
| 277 | mutex_unlock(&monc->mutex); |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * Register interest in the next osdmap |
| 283 | */ |
| 284 | void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc) |
| 285 | { |
| 286 | dout("request_next_osdmap have %u\n", monc->have_osdmap); |
| 287 | mutex_lock(&monc->mutex); |
| 288 | if (!monc->want_next_osdmap) |
| 289 | monc->want_next_osdmap = 1; |
| 290 | if (monc->want_next_osdmap < 2) |
| 291 | __send_subscribe(monc); |
| 292 | mutex_unlock(&monc->mutex); |
| 293 | } |
| 294 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 295 | /* |
Sage Weil | 50b885b | 2009-12-01 14:12:07 -0800 | [diff] [blame] | 296 | * |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 297 | */ |
| 298 | int ceph_monc_open_session(struct ceph_mon_client *monc) |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 299 | { |
| 300 | if (!monc->con) { |
| 301 | monc->con = kmalloc(sizeof(*monc->con), GFP_KERNEL); |
| 302 | if (!monc->con) |
| 303 | return -ENOMEM; |
| 304 | ceph_con_init(monc->client->msgr, monc->con); |
| 305 | monc->con->private = monc; |
| 306 | monc->con->ops = &mon_con_ops; |
| 307 | } |
| 308 | |
| 309 | mutex_lock(&monc->mutex); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 310 | __open_session(monc); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 311 | __schedule_delayed(monc); |
| 312 | mutex_unlock(&monc->mutex); |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * The monitor responds with mount ack indicate mount success. The |
| 318 | * included client ticket allows the client to talk to MDSs and OSDs. |
| 319 | */ |
Sage Weil | 0743304 | 2009-11-18 16:50:41 -0800 | [diff] [blame] | 320 | static void ceph_monc_handle_map(struct ceph_mon_client *monc, |
| 321 | struct ceph_msg *msg) |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 322 | { |
| 323 | struct ceph_client *client = monc->client; |
| 324 | struct ceph_monmap *monmap = NULL, *old = monc->monmap; |
| 325 | void *p, *end; |
| 326 | |
| 327 | mutex_lock(&monc->mutex); |
| 328 | |
| 329 | dout("handle_monmap\n"); |
| 330 | p = msg->front.iov_base; |
| 331 | end = p + msg->front.iov_len; |
| 332 | |
| 333 | monmap = ceph_monmap_decode(p, end); |
| 334 | if (IS_ERR(monmap)) { |
| 335 | pr_err("problem decoding monmap, %d\n", |
| 336 | (int)PTR_ERR(monmap)); |
Sage Weil | d4a780c | 2009-12-11 08:55:23 -0800 | [diff] [blame] | 337 | goto out; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 338 | } |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 339 | |
Sage Weil | 0743304 | 2009-11-18 16:50:41 -0800 | [diff] [blame] | 340 | if (ceph_check_fsid(monc->client, &monmap->fsid) < 0) { |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 341 | kfree(monmap); |
Sage Weil | d4a780c | 2009-12-11 08:55:23 -0800 | [diff] [blame] | 342 | goto out; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | client->monc.monmap = monmap; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 346 | kfree(old); |
| 347 | |
Sage Weil | d4a780c | 2009-12-11 08:55:23 -0800 | [diff] [blame] | 348 | out: |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 349 | mutex_unlock(&monc->mutex); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 350 | wake_up(&client->auth_wq); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 351 | } |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 352 | |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 353 | /* |
| 354 | * statfs |
| 355 | */ |
Sage Weil | 85ff03f | 2010-02-15 14:47:28 -0800 | [diff] [blame] | 356 | static struct ceph_mon_statfs_request *__lookup_statfs( |
| 357 | struct ceph_mon_client *monc, u64 tid) |
| 358 | { |
| 359 | struct ceph_mon_statfs_request *req; |
| 360 | struct rb_node *n = monc->statfs_request_tree.rb_node; |
| 361 | |
| 362 | while (n) { |
| 363 | req = rb_entry(n, struct ceph_mon_statfs_request, node); |
| 364 | if (tid < req->tid) |
| 365 | n = n->rb_left; |
| 366 | else if (tid > req->tid) |
| 367 | n = n->rb_right; |
| 368 | else |
| 369 | return req; |
| 370 | } |
| 371 | return NULL; |
| 372 | } |
| 373 | |
| 374 | static void __insert_statfs(struct ceph_mon_client *monc, |
| 375 | struct ceph_mon_statfs_request *new) |
| 376 | { |
| 377 | struct rb_node **p = &monc->statfs_request_tree.rb_node; |
| 378 | struct rb_node *parent = NULL; |
| 379 | struct ceph_mon_statfs_request *req = NULL; |
| 380 | |
| 381 | while (*p) { |
| 382 | parent = *p; |
| 383 | req = rb_entry(parent, struct ceph_mon_statfs_request, node); |
| 384 | if (new->tid < req->tid) |
| 385 | p = &(*p)->rb_left; |
| 386 | else if (new->tid > req->tid) |
| 387 | p = &(*p)->rb_right; |
| 388 | else |
| 389 | BUG(); |
| 390 | } |
| 391 | |
| 392 | rb_link_node(&new->node, parent, p); |
| 393 | rb_insert_color(&new->node, &monc->statfs_request_tree); |
| 394 | } |
| 395 | |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 396 | static void handle_statfs_reply(struct ceph_mon_client *monc, |
| 397 | struct ceph_msg *msg) |
| 398 | { |
| 399 | struct ceph_mon_statfs_request *req; |
| 400 | struct ceph_mon_statfs_reply *reply = msg->front.iov_base; |
| 401 | u64 tid; |
| 402 | |
| 403 | if (msg->front.iov_len != sizeof(*reply)) |
| 404 | goto bad; |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame] | 405 | tid = le64_to_cpu(msg->hdr.tid); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 406 | dout("handle_statfs_reply %p tid %llu\n", msg, tid); |
| 407 | |
| 408 | mutex_lock(&monc->mutex); |
Sage Weil | 85ff03f | 2010-02-15 14:47:28 -0800 | [diff] [blame] | 409 | req = __lookup_statfs(monc, tid); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 410 | if (req) { |
| 411 | *req->buf = reply->st; |
| 412 | req->result = 0; |
| 413 | } |
| 414 | mutex_unlock(&monc->mutex); |
| 415 | if (req) |
| 416 | complete(&req->completion); |
| 417 | return; |
| 418 | |
| 419 | bad: |
| 420 | pr_err("corrupt statfs reply, no tid\n"); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 421 | ceph_msg_dump(msg); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | /* |
| 425 | * (re)send a statfs request |
| 426 | */ |
| 427 | static int send_statfs(struct ceph_mon_client *monc, |
| 428 | struct ceph_mon_statfs_request *req) |
| 429 | { |
| 430 | struct ceph_msg *msg; |
| 431 | struct ceph_mon_statfs *h; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 432 | |
| 433 | dout("send_statfs tid %llu\n", req->tid); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 434 | msg = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h), 0, 0, NULL); |
| 435 | if (IS_ERR(msg)) |
| 436 | return PTR_ERR(msg); |
| 437 | req->request = msg; |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame] | 438 | msg->hdr.tid = cpu_to_le64(req->tid); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 439 | h = msg->front.iov_base; |
Sage Weil | 13e38c8 | 2009-10-09 16:36:34 -0700 | [diff] [blame] | 440 | h->monhdr.have_version = 0; |
| 441 | h->monhdr.session_mon = cpu_to_le16(-1); |
| 442 | h->monhdr.session_mon_tid = 0; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 443 | h->fsid = monc->monmap->fsid; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 444 | ceph_con_send(monc->con, msg); |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | /* |
| 449 | * Do a synchronous statfs(). |
| 450 | */ |
| 451 | int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) |
| 452 | { |
| 453 | struct ceph_mon_statfs_request req; |
| 454 | int err; |
| 455 | |
| 456 | req.buf = buf; |
| 457 | init_completion(&req.completion); |
| 458 | |
| 459 | /* allocate memory for reply */ |
| 460 | err = ceph_msgpool_resv(&monc->msgpool_statfs_reply, 1); |
| 461 | if (err) |
| 462 | return err; |
| 463 | |
| 464 | /* register request */ |
| 465 | mutex_lock(&monc->mutex); |
| 466 | req.tid = ++monc->last_tid; |
| 467 | req.last_attempt = jiffies; |
| 468 | req.delay = BASE_DELAY_INTERVAL; |
Sage Weil | 85ff03f | 2010-02-15 14:47:28 -0800 | [diff] [blame] | 469 | __insert_statfs(monc, &req); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 470 | monc->num_statfs_requests++; |
| 471 | mutex_unlock(&monc->mutex); |
| 472 | |
| 473 | /* send request and wait */ |
| 474 | err = send_statfs(monc, &req); |
| 475 | if (!err) |
| 476 | err = wait_for_completion_interruptible(&req.completion); |
| 477 | |
| 478 | mutex_lock(&monc->mutex); |
Sage Weil | 85ff03f | 2010-02-15 14:47:28 -0800 | [diff] [blame] | 479 | rb_erase(&req.node, &monc->statfs_request_tree); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 480 | monc->num_statfs_requests--; |
| 481 | ceph_msgpool_resv(&monc->msgpool_statfs_reply, -1); |
| 482 | mutex_unlock(&monc->mutex); |
| 483 | |
| 484 | if (!err) |
| 485 | err = req.result; |
| 486 | return err; |
| 487 | } |
| 488 | |
| 489 | /* |
| 490 | * Resend pending statfs requests. |
| 491 | */ |
| 492 | static void __resend_statfs(struct ceph_mon_client *monc) |
| 493 | { |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 494 | struct ceph_mon_statfs_request *req; |
Sage Weil | 85ff03f | 2010-02-15 14:47:28 -0800 | [diff] [blame] | 495 | struct rb_node *p; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 496 | |
Sage Weil | 85ff03f | 2010-02-15 14:47:28 -0800 | [diff] [blame] | 497 | for (p = rb_first(&monc->statfs_request_tree); p; p = rb_next(p)) { |
| 498 | req = rb_entry(p, struct ceph_mon_statfs_request, node); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 499 | send_statfs(monc, req); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | /* |
| 504 | * Delayed work. If we haven't mounted yet, retry. Otherwise, |
| 505 | * renew/retry subscription as needed (in case it is timing out, or we |
| 506 | * got an ENOMEM). And keep the monitor connection alive. |
| 507 | */ |
| 508 | static void delayed_work(struct work_struct *work) |
| 509 | { |
| 510 | struct ceph_mon_client *monc = |
| 511 | container_of(work, struct ceph_mon_client, delayed_work.work); |
| 512 | |
| 513 | dout("monc delayed_work\n"); |
| 514 | mutex_lock(&monc->mutex); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 515 | if (monc->hunting) { |
| 516 | __close_session(monc); |
| 517 | __open_session(monc); /* continue hunting */ |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 518 | } else { |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 519 | ceph_con_keepalive(monc->con); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 520 | |
| 521 | __validate_auth(monc); |
| 522 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 523 | if (monc->auth->ops->is_authenticated(monc->auth)) |
| 524 | __send_subscribe(monc); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 525 | } |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 526 | __schedule_delayed(monc); |
| 527 | mutex_unlock(&monc->mutex); |
| 528 | } |
| 529 | |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 530 | /* |
| 531 | * On startup, we build a temporary monmap populated with the IPs |
| 532 | * provided by mount(2). |
| 533 | */ |
| 534 | static int build_initial_monmap(struct ceph_mon_client *monc) |
| 535 | { |
| 536 | struct ceph_mount_args *args = monc->client->mount_args; |
| 537 | struct ceph_entity_addr *mon_addr = args->mon_addr; |
| 538 | int num_mon = args->num_mon; |
| 539 | int i; |
| 540 | |
| 541 | /* build initial monmap */ |
| 542 | monc->monmap = kzalloc(sizeof(*monc->monmap) + |
| 543 | num_mon*sizeof(monc->monmap->mon_inst[0]), |
| 544 | GFP_KERNEL); |
| 545 | if (!monc->monmap) |
| 546 | return -ENOMEM; |
| 547 | for (i = 0; i < num_mon; i++) { |
| 548 | monc->monmap->mon_inst[i].addr = mon_addr[i]; |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 549 | monc->monmap->mon_inst[i].addr.nonce = 0; |
| 550 | monc->monmap->mon_inst[i].name.type = |
| 551 | CEPH_ENTITY_TYPE_MON; |
| 552 | monc->monmap->mon_inst[i].name.num = cpu_to_le64(i); |
| 553 | } |
| 554 | monc->monmap->num_mon = num_mon; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 555 | monc->have_fsid = false; |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 556 | |
| 557 | /* release addr memory */ |
| 558 | kfree(args->mon_addr); |
| 559 | args->mon_addr = NULL; |
| 560 | args->num_mon = 0; |
| 561 | return 0; |
| 562 | } |
| 563 | |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 564 | int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl) |
| 565 | { |
| 566 | int err = 0; |
| 567 | |
| 568 | dout("init\n"); |
| 569 | memset(monc, 0, sizeof(*monc)); |
| 570 | monc->client = cl; |
| 571 | monc->monmap = NULL; |
| 572 | mutex_init(&monc->mutex); |
| 573 | |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 574 | err = build_initial_monmap(monc); |
| 575 | if (err) |
| 576 | goto out; |
| 577 | |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 578 | monc->con = NULL; |
| 579 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 580 | /* authentication */ |
| 581 | monc->auth = ceph_auth_init(cl->mount_args->name, |
| 582 | cl->mount_args->secret); |
| 583 | if (IS_ERR(monc->auth)) |
| 584 | return PTR_ERR(monc->auth); |
| 585 | monc->auth->want_keys = |
| 586 | CEPH_ENTITY_TYPE_AUTH | CEPH_ENTITY_TYPE_MON | |
| 587 | CEPH_ENTITY_TYPE_OSD | CEPH_ENTITY_TYPE_MDS; |
| 588 | |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 589 | /* msg pools */ |
Sage Weil | 07bd10f | 2009-10-14 17:26:40 -0700 | [diff] [blame] | 590 | err = ceph_msgpool_init(&monc->msgpool_subscribe_ack, |
| 591 | sizeof(struct ceph_mon_subscribe_ack), 1, false); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 592 | if (err < 0) |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 593 | goto out_monmap; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 594 | err = ceph_msgpool_init(&monc->msgpool_statfs_reply, |
| 595 | sizeof(struct ceph_mon_statfs_reply), 0, false); |
| 596 | if (err < 0) |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 597 | goto out_pool1; |
| 598 | err = ceph_msgpool_init(&monc->msgpool_auth_reply, 4096, 1, false); |
| 599 | if (err < 0) |
| 600 | goto out_pool2; |
| 601 | |
| 602 | monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, 0, 0, NULL); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 603 | monc->pending_auth = 0; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 604 | if (IS_ERR(monc->m_auth)) { |
| 605 | err = PTR_ERR(monc->m_auth); |
| 606 | monc->m_auth = NULL; |
| 607 | goto out_pool3; |
| 608 | } |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 609 | |
| 610 | monc->cur_mon = -1; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 611 | monc->hunting = true; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 612 | monc->sub_renew_after = jiffies; |
| 613 | monc->sub_sent = 0; |
| 614 | |
| 615 | INIT_DELAYED_WORK(&monc->delayed_work, delayed_work); |
Sage Weil | 85ff03f | 2010-02-15 14:47:28 -0800 | [diff] [blame] | 616 | monc->statfs_request_tree = RB_ROOT; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 617 | monc->num_statfs_requests = 0; |
| 618 | monc->last_tid = 0; |
| 619 | |
| 620 | monc->have_mdsmap = 0; |
| 621 | monc->have_osdmap = 0; |
| 622 | monc->want_next_osdmap = 1; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 623 | return 0; |
| 624 | |
| 625 | out_pool3: |
| 626 | ceph_msgpool_destroy(&monc->msgpool_auth_reply); |
| 627 | out_pool2: |
| 628 | ceph_msgpool_destroy(&monc->msgpool_subscribe_ack); |
| 629 | out_pool1: |
| 630 | ceph_msgpool_destroy(&monc->msgpool_statfs_reply); |
| 631 | out_monmap: |
| 632 | kfree(monc->monmap); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 633 | out: |
| 634 | return err; |
| 635 | } |
| 636 | |
| 637 | void ceph_monc_stop(struct ceph_mon_client *monc) |
| 638 | { |
| 639 | dout("stop\n"); |
| 640 | cancel_delayed_work_sync(&monc->delayed_work); |
| 641 | |
| 642 | mutex_lock(&monc->mutex); |
| 643 | __close_session(monc); |
| 644 | if (monc->con) { |
| 645 | monc->con->private = NULL; |
| 646 | monc->con->ops->put(monc->con); |
| 647 | monc->con = NULL; |
| 648 | } |
| 649 | mutex_unlock(&monc->mutex); |
| 650 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 651 | ceph_auth_destroy(monc->auth); |
| 652 | |
| 653 | ceph_msg_put(monc->m_auth); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 654 | ceph_msgpool_destroy(&monc->msgpool_subscribe_ack); |
| 655 | ceph_msgpool_destroy(&monc->msgpool_statfs_reply); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 656 | ceph_msgpool_destroy(&monc->msgpool_auth_reply); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 657 | |
| 658 | kfree(monc->monmap); |
| 659 | } |
| 660 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 661 | static void handle_auth_reply(struct ceph_mon_client *monc, |
| 662 | struct ceph_msg *msg) |
| 663 | { |
| 664 | int ret; |
| 665 | |
| 666 | mutex_lock(&monc->mutex); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 667 | monc->pending_auth = 0; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 668 | ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base, |
| 669 | msg->front.iov_len, |
| 670 | monc->m_auth->front.iov_base, |
| 671 | monc->m_auth->front_max); |
| 672 | if (ret < 0) { |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 673 | monc->client->auth_err = ret; |
| 674 | wake_up(&monc->client->auth_wq); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 675 | } else if (ret > 0) { |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 676 | __send_prepared_auth_request(monc, ret); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 677 | } else if (monc->auth->ops->is_authenticated(monc->auth)) { |
| 678 | dout("authenticated, starting session\n"); |
Sage Weil | 0743304 | 2009-11-18 16:50:41 -0800 | [diff] [blame] | 679 | |
| 680 | monc->client->msgr->inst.name.type = CEPH_ENTITY_TYPE_CLIENT; |
| 681 | monc->client->msgr->inst.name.num = monc->auth->global_id; |
| 682 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 683 | __send_subscribe(monc); |
| 684 | __resend_statfs(monc); |
| 685 | } |
| 686 | mutex_unlock(&monc->mutex); |
| 687 | } |
| 688 | |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 689 | static int __validate_auth(struct ceph_mon_client *monc) |
| 690 | { |
| 691 | int ret; |
| 692 | |
| 693 | if (monc->pending_auth) |
| 694 | return 0; |
| 695 | |
| 696 | ret = ceph_build_auth(monc->auth, monc->m_auth->front.iov_base, |
| 697 | monc->m_auth->front_max); |
| 698 | if (ret <= 0) |
| 699 | return ret; /* either an error, or no need to authenticate */ |
| 700 | __send_prepared_auth_request(monc, ret); |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | int ceph_monc_validate_auth(struct ceph_mon_client *monc) |
| 705 | { |
| 706 | int ret; |
| 707 | |
| 708 | mutex_lock(&monc->mutex); |
| 709 | ret = __validate_auth(monc); |
| 710 | mutex_unlock(&monc->mutex); |
| 711 | return ret; |
| 712 | } |
| 713 | |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 714 | /* |
| 715 | * handle incoming message |
| 716 | */ |
| 717 | static void dispatch(struct ceph_connection *con, struct ceph_msg *msg) |
| 718 | { |
| 719 | struct ceph_mon_client *monc = con->private; |
| 720 | int type = le16_to_cpu(msg->hdr.type); |
| 721 | |
| 722 | if (!monc) |
| 723 | return; |
| 724 | |
| 725 | switch (type) { |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 726 | case CEPH_MSG_AUTH_REPLY: |
| 727 | handle_auth_reply(monc, msg); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 728 | break; |
| 729 | |
| 730 | case CEPH_MSG_MON_SUBSCRIBE_ACK: |
| 731 | handle_subscribe_ack(monc, msg); |
| 732 | break; |
| 733 | |
| 734 | case CEPH_MSG_STATFS_REPLY: |
| 735 | handle_statfs_reply(monc, msg); |
| 736 | break; |
| 737 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 738 | case CEPH_MSG_MON_MAP: |
| 739 | ceph_monc_handle_map(monc, msg); |
| 740 | break; |
| 741 | |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 742 | case CEPH_MSG_MDS_MAP: |
| 743 | ceph_mdsc_handle_map(&monc->client->mdsc, msg); |
| 744 | break; |
| 745 | |
| 746 | case CEPH_MSG_OSD_MAP: |
| 747 | ceph_osdc_handle_map(&monc->client->osdc, msg); |
| 748 | break; |
| 749 | |
| 750 | default: |
| 751 | pr_err("received unknown message type %d %s\n", type, |
| 752 | ceph_msg_type_name(type)); |
| 753 | } |
| 754 | ceph_msg_put(msg); |
| 755 | } |
| 756 | |
| 757 | /* |
| 758 | * Allocate memory for incoming message |
| 759 | */ |
| 760 | static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con, |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 761 | struct ceph_msg_header *hdr, |
| 762 | int *skip) |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 763 | { |
| 764 | struct ceph_mon_client *monc = con->private; |
| 765 | int type = le16_to_cpu(hdr->type); |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 766 | int front_len = le32_to_cpu(hdr->front_len); |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 767 | struct ceph_msg *m = NULL; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 768 | |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 769 | *skip = 0; |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 770 | |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 771 | switch (type) { |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 772 | case CEPH_MSG_MON_SUBSCRIBE_ACK: |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 773 | m = ceph_msgpool_get(&monc->msgpool_subscribe_ack, front_len); |
| 774 | break; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 775 | case CEPH_MSG_STATFS_REPLY: |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 776 | m = ceph_msgpool_get(&monc->msgpool_statfs_reply, front_len); |
| 777 | break; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 778 | case CEPH_MSG_AUTH_REPLY: |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 779 | m = ceph_msgpool_get(&monc->msgpool_auth_reply, front_len); |
| 780 | break; |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 781 | case CEPH_MSG_MON_MAP: |
| 782 | case CEPH_MSG_MDS_MAP: |
| 783 | case CEPH_MSG_OSD_MAP: |
| 784 | m = ceph_msg_new(type, front_len, 0, 0, NULL); |
| 785 | break; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 786 | } |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 787 | |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 788 | if (!m) { |
| 789 | pr_info("alloc_msg unknown type %d\n", type); |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 790 | *skip = 1; |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 791 | } |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 792 | return m; |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | /* |
| 796 | * If the monitor connection resets, pick a new monitor and resubmit |
| 797 | * any pending requests. |
| 798 | */ |
| 799 | static void mon_fault(struct ceph_connection *con) |
| 800 | { |
| 801 | struct ceph_mon_client *monc = con->private; |
| 802 | |
| 803 | if (!monc) |
| 804 | return; |
| 805 | |
| 806 | dout("mon_fault\n"); |
| 807 | mutex_lock(&monc->mutex); |
| 808 | if (!con->private) |
| 809 | goto out; |
| 810 | |
| 811 | if (monc->con && !monc->hunting) |
| 812 | pr_info("mon%d %s session lost, " |
| 813 | "hunting for new mon\n", monc->cur_mon, |
| 814 | pr_addr(&monc->con->peer_addr.in_addr)); |
| 815 | |
| 816 | __close_session(monc); |
| 817 | if (!monc->hunting) { |
| 818 | /* start hunting */ |
| 819 | monc->hunting = true; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 820 | __open_session(monc); |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 821 | } else { |
| 822 | /* already hunting, let's wait a bit */ |
| 823 | __schedule_delayed(monc); |
| 824 | } |
| 825 | out: |
| 826 | mutex_unlock(&monc->mutex); |
| 827 | } |
| 828 | |
| 829 | const static struct ceph_connection_operations mon_con_ops = { |
| 830 | .get = ceph_con_get, |
| 831 | .put = ceph_con_put, |
| 832 | .dispatch = dispatch, |
| 833 | .fault = mon_fault, |
| 834 | .alloc_msg = mon_alloc_msg, |
Sage Weil | ba75bb9 | 2009-10-06 11:31:11 -0700 | [diff] [blame] | 835 | }; |