GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / fs / ceph / osd_client.c
blob7d85487f126d426f20f59292caa685b7de9ffe4d
1 #include "ceph_debug.h"
3 #include <linux/err.h>
4 #include <linux/highmem.h>
5 #include <linux/mm.h>
6 #include <linux/pagemap.h>
7 #include <linux/slab.h>
8 #include <linux/uaccess.h>
10 #include "super.h"
11 #include "osd_client.h"
12 #include "messenger.h"
13 #include "decode.h"
14 #include "auth.h"
16 #define OSD_OP_FRONT_LEN 4096
17 #define OSD_OPREPLY_FRONT_LEN 512
19 static const struct ceph_connection_operations osd_con_ops;
20 static int __kick_requests(struct ceph_osd_client *osdc,
21 struct ceph_osd *kickosd);
23 static void kick_requests(struct ceph_osd_client *osdc, struct ceph_osd *osd);
26 * Implement client access to distributed object storage cluster.
28 * All data objects are stored within a cluster/cloud of OSDs, or
29 * "object storage devices." (Note that Ceph OSDs have _nothing_ to
30 * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply
31 * remote daemons serving up and coordinating consistent and safe
32 * access to storage.
34 * Cluster membership and the mapping of data objects onto storage devices
35 * are described by the osd map.
37 * We keep track of pending OSD requests (read, write), resubmit
38 * requests to different OSDs when the cluster topology/data layout
39 * change, or retry the affected requests when the communications
40 * channel with an OSD is reset.
44 * calculate the mapping of a file extent onto an object, and fill out the
45 * request accordingly. shorten extent as necessary if it crosses an
46 * object boundary.
48 * fill osd op in request message.
50 static void calc_layout(struct ceph_osd_client *osdc,
51 struct ceph_vino vino, struct ceph_file_layout *layout,
52 u64 off, u64 *plen,
53 struct ceph_osd_request *req)
55 struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base;
56 struct ceph_osd_op *op = (void *)(reqhead + 1);
57 u64 orig_len = *plen;
58 u64 objoff, objlen; /* extent in object */
59 u64 bno;
61 reqhead->snapid = cpu_to_le64(vino.snap);
63 /* object extent? */
64 ceph_calc_file_object_mapping(layout, off, plen, &bno,
65 &objoff, &objlen);
66 if (*plen < orig_len)
67 dout(" skipping last %llu, final file extent %llu~%llu\n",
68 orig_len - *plen, off, *plen);
70 sprintf(req->r_oid, "%llx.%08llx", vino.ino, bno);
71 req->r_oid_len = strlen(req->r_oid);
73 op->extent.offset = cpu_to_le64(objoff);
74 op->extent.length = cpu_to_le64(objlen);
75 req->r_num_pages = calc_pages_for(off, *plen);
77 dout("calc_layout %s (%d) %llu~%llu (%d pages)\n",
78 req->r_oid, req->r_oid_len, objoff, objlen, req->r_num_pages);
82 * requests
84 void ceph_osdc_release_request(struct kref *kref)
86 struct ceph_osd_request *req = container_of(kref,
87 struct ceph_osd_request,
88 r_kref);
90 if (req->r_request)
91 ceph_msg_put(req->r_request);
92 if (req->r_reply)
93 ceph_msg_put(req->r_reply);
94 if (req->r_con_filling_msg) {
95 dout("release_request revoking pages %p from con %p\n",
96 req->r_pages, req->r_con_filling_msg);
97 ceph_con_revoke_message(req->r_con_filling_msg,
98 req->r_reply);
99 ceph_con_put(req->r_con_filling_msg);
101 if (req->r_own_pages)
102 ceph_release_page_vector(req->r_pages,
103 req->r_num_pages);
104 ceph_put_snap_context(req->r_snapc);
105 if (req->r_mempool)
106 mempool_free(req, req->r_osdc->req_mempool);
107 else
108 kfree(req);
112 * build new request AND message, calculate layout, and adjust file
113 * extent as needed.
115 * if the file was recently truncated, we include information about its
116 * old and new size so that the object can be updated appropriately. (we
117 * avoid synchronously deleting truncated objects because it's slow.)
119 * if @do_sync, include a 'startsync' command so that the osd will flush
120 * data quickly.
122 struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
123 struct ceph_file_layout *layout,
124 struct ceph_vino vino,
125 u64 off, u64 *plen,
126 int opcode, int flags,
127 struct ceph_snap_context *snapc,
128 int do_sync,
129 u32 truncate_seq,
130 u64 truncate_size,
131 struct timespec *mtime,
132 bool use_mempool, int num_reply)
134 struct ceph_osd_request *req;
135 struct ceph_msg *msg;
136 struct ceph_osd_request_head *head;
137 struct ceph_osd_op *op;
138 void *p;
139 int num_op = 1 + do_sync;
140 size_t msg_size = sizeof(*head) + num_op*sizeof(*op);
141 int i;
143 if (use_mempool) {
144 req = mempool_alloc(osdc->req_mempool, GFP_NOFS);
145 memset(req, 0, sizeof(*req));
146 } else {
147 req = kzalloc(sizeof(*req), GFP_NOFS);
149 if (req == NULL)
150 return NULL;
152 req->r_osdc = osdc;
153 req->r_mempool = use_mempool;
154 kref_init(&req->r_kref);
155 init_completion(&req->r_completion);
156 init_completion(&req->r_safe_completion);
157 INIT_LIST_HEAD(&req->r_unsafe_item);
158 req->r_flags = flags;
160 WARN_ON((flags & (CEPH_OSD_FLAG_READ|CEPH_OSD_FLAG_WRITE)) == 0);
162 /* create reply message */
163 if (use_mempool)
164 msg = ceph_msgpool_get(&osdc->msgpool_op_reply, 0);
165 else
166 msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY,
167 OSD_OPREPLY_FRONT_LEN, GFP_NOFS);
168 if (!msg) {
169 ceph_osdc_put_request(req);
170 return NULL;
172 req->r_reply = msg;
174 /* create request message; allow space for oid */
175 msg_size += 40;
176 if (snapc)
177 msg_size += sizeof(u64) * snapc->num_snaps;
178 if (use_mempool)
179 msg = ceph_msgpool_get(&osdc->msgpool_op, 0);
180 else
181 msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, GFP_NOFS);
182 if (!msg) {
183 ceph_osdc_put_request(req);
184 return NULL;
186 msg->hdr.type = cpu_to_le16(CEPH_MSG_OSD_OP);
187 memset(msg->front.iov_base, 0, msg->front.iov_len);
188 head = msg->front.iov_base;
189 op = (void *)(head + 1);
190 p = (void *)(op + num_op);
192 req->r_request = msg;
193 req->r_snapc = ceph_get_snap_context(snapc);
195 head->client_inc = cpu_to_le32(1); /* always, for now. */
196 head->flags = cpu_to_le32(flags);
197 if (flags & CEPH_OSD_FLAG_WRITE)
198 ceph_encode_timespec(&head->mtime, mtime);
199 head->num_ops = cpu_to_le16(num_op);
200 op->op = cpu_to_le16(opcode);
202 /* calculate max write size */
203 calc_layout(osdc, vino, layout, off, plen, req);
204 req->r_file_layout = *layout; /* keep a copy */
206 if (flags & CEPH_OSD_FLAG_WRITE) {
207 req->r_request->hdr.data_off = cpu_to_le16(off);
208 req->r_request->hdr.data_len = cpu_to_le32(*plen);
209 op->payload_len = cpu_to_le32(*plen);
211 op->extent.truncate_size = cpu_to_le64(truncate_size);
212 op->extent.truncate_seq = cpu_to_le32(truncate_seq);
214 /* fill in oid */
215 head->object_len = cpu_to_le32(req->r_oid_len);
216 memcpy(p, req->r_oid, req->r_oid_len);
217 p += req->r_oid_len;
219 if (do_sync) {
220 op++;
221 op->op = cpu_to_le16(CEPH_OSD_OP_STARTSYNC);
223 if (snapc) {
224 head->snap_seq = cpu_to_le64(snapc->seq);
225 head->num_snaps = cpu_to_le32(snapc->num_snaps);
226 for (i = 0; i < snapc->num_snaps; i++) {
227 put_unaligned_le64(snapc->snaps[i], p);
228 p += sizeof(u64);
232 BUG_ON(p > msg->front.iov_base + msg->front.iov_len);
233 msg_size = p - msg->front.iov_base;
234 msg->front.iov_len = msg_size;
235 msg->hdr.front_len = cpu_to_le32(msg_size);
236 return req;
240 * We keep osd requests in an rbtree, sorted by ->r_tid.
242 static void __insert_request(struct ceph_osd_client *osdc,
243 struct ceph_osd_request *new)
245 struct rb_node **p = &osdc->requests.rb_node;
246 struct rb_node *parent = NULL;
247 struct ceph_osd_request *req = NULL;
249 while (*p) {
250 parent = *p;
251 req = rb_entry(parent, struct ceph_osd_request, r_node);
252 if (new->r_tid < req->r_tid)
253 p = &(*p)->rb_left;
254 else if (new->r_tid > req->r_tid)
255 p = &(*p)->rb_right;
256 else
257 BUG();
260 rb_link_node(&new->r_node, parent, p);
261 rb_insert_color(&new->r_node, &osdc->requests);
264 static struct ceph_osd_request *__lookup_request(struct ceph_osd_client *osdc,
265 u64 tid)
267 struct ceph_osd_request *req;
268 struct rb_node *n = osdc->requests.rb_node;
270 while (n) {
271 req = rb_entry(n, struct ceph_osd_request, r_node);
272 if (tid < req->r_tid)
273 n = n->rb_left;
274 else if (tid > req->r_tid)
275 n = n->rb_right;
276 else
277 return req;
279 return NULL;
282 static struct ceph_osd_request *
283 __lookup_request_ge(struct ceph_osd_client *osdc,
284 u64 tid)
286 struct ceph_osd_request *req;
287 struct rb_node *n = osdc->requests.rb_node;
289 while (n) {
290 req = rb_entry(n, struct ceph_osd_request, r_node);
291 if (tid < req->r_tid) {
292 if (!n->rb_left)
293 return req;
294 n = n->rb_left;
295 } else if (tid > req->r_tid) {
296 n = n->rb_right;
297 } else {
298 return req;
301 return NULL;
306 * If the osd connection drops, we need to resubmit all requests.
308 static void osd_reset(struct ceph_connection *con)
310 struct ceph_osd *osd = con->private;
311 struct ceph_osd_client *osdc;
313 if (!osd)
314 return;
315 dout("osd_reset osd%d\n", osd->o_osd);
316 osdc = osd->o_osdc;
317 down_read(&osdc->map_sem);
318 kick_requests(osdc, osd);
319 up_read(&osdc->map_sem);
323 * Track open sessions with osds.
325 static struct ceph_osd *create_osd(struct ceph_osd_client *osdc)
327 struct ceph_osd *osd;
329 osd = kzalloc(sizeof(*osd), GFP_NOFS);
330 if (!osd)
331 return NULL;
333 atomic_set(&osd->o_ref, 1);
334 osd->o_osdc = osdc;
335 INIT_LIST_HEAD(&osd->o_requests);
336 INIT_LIST_HEAD(&osd->o_osd_lru);
337 osd->o_incarnation = 1;
339 ceph_con_init(osdc->client->msgr, &osd->o_con);
340 osd->o_con.private = osd;
341 osd->o_con.ops = &osd_con_ops;
342 osd->o_con.peer_name.type = CEPH_ENTITY_TYPE_OSD;
344 INIT_LIST_HEAD(&osd->o_keepalive_item);
345 return osd;
348 static struct ceph_osd *get_osd(struct ceph_osd *osd)
350 if (atomic_inc_not_zero(&osd->o_ref)) {
351 dout("get_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref)-1,
352 atomic_read(&osd->o_ref));
353 return osd;
354 } else {
355 dout("get_osd %p FAIL\n", osd);
356 return NULL;
360 static void put_osd(struct ceph_osd *osd)
362 dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref),
363 atomic_read(&osd->o_ref) - 1);
364 if (atomic_dec_and_test(&osd->o_ref)) {
365 struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth;
367 if (osd->o_authorizer)
368 ac->ops->destroy_authorizer(ac, osd->o_authorizer);
369 kfree(osd);
374 * remove an osd from our map
376 static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
378 dout("__remove_osd %p\n", osd);
379 BUG_ON(!list_empty(&osd->o_requests));
380 rb_erase(&osd->o_node, &osdc->osds);
381 list_del_init(&osd->o_osd_lru);
382 ceph_con_close(&osd->o_con);
383 put_osd(osd);
386 static void __move_osd_to_lru(struct ceph_osd_client *osdc,
387 struct ceph_osd *osd)
389 dout("__move_osd_to_lru %p\n", osd);
390 BUG_ON(!list_empty(&osd->o_osd_lru));
391 list_add_tail(&osd->o_osd_lru, &osdc->osd_lru);
392 osd->lru_ttl = jiffies + osdc->client->mount_args->osd_idle_ttl * HZ;
395 static void __remove_osd_from_lru(struct ceph_osd *osd)
397 dout("__remove_osd_from_lru %p\n", osd);
398 if (!list_empty(&osd->o_osd_lru))
399 list_del_init(&osd->o_osd_lru);
402 static void remove_old_osds(struct ceph_osd_client *osdc, int remove_all)
404 struct ceph_osd *osd, *nosd;
406 dout("__remove_old_osds %p\n", osdc);
407 mutex_lock(&osdc->request_mutex);
408 list_for_each_entry_safe(osd, nosd, &osdc->osd_lru, o_osd_lru) {
409 if (!remove_all && time_before(jiffies, osd->lru_ttl))
410 break;
411 __remove_osd(osdc, osd);
413 mutex_unlock(&osdc->request_mutex);
417 * reset osd connect
419 static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
421 struct ceph_osd_request *req;
422 int ret = 0;
424 dout("__reset_osd %p osd%d\n", osd, osd->o_osd);
425 if (list_empty(&osd->o_requests)) {
426 __remove_osd(osdc, osd);
427 } else if (memcmp(&osdc->osdmap->osd_addr[osd->o_osd],
428 &osd->o_con.peer_addr,
429 sizeof(osd->o_con.peer_addr)) == 0 &&
430 !ceph_con_opened(&osd->o_con)) {
431 dout(" osd addr hasn't changed and connection never opened,"
432 " letting msgr retry");
433 /* touch each r_stamp for handle_timeout()'s benfit */
434 list_for_each_entry(req, &osd->o_requests, r_osd_item)
435 req->r_stamp = jiffies;
436 ret = -EAGAIN;
437 } else {
438 ceph_con_close(&osd->o_con);
439 ceph_con_open(&osd->o_con, &osdc->osdmap->osd_addr[osd->o_osd]);
440 osd->o_incarnation++;
442 return ret;
445 static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new)
447 struct rb_node **p = &osdc->osds.rb_node;
448 struct rb_node *parent = NULL;
449 struct ceph_osd *osd = NULL;
451 while (*p) {
452 parent = *p;
453 osd = rb_entry(parent, struct ceph_osd, o_node);
454 if (new->o_osd < osd->o_osd)
455 p = &(*p)->rb_left;
456 else if (new->o_osd > osd->o_osd)
457 p = &(*p)->rb_right;
458 else
459 BUG();
462 rb_link_node(&new->o_node, parent, p);
463 rb_insert_color(&new->o_node, &osdc->osds);
466 static struct ceph_osd *__lookup_osd(struct ceph_osd_client *osdc, int o)
468 struct ceph_osd *osd;
469 struct rb_node *n = osdc->osds.rb_node;
471 while (n) {
472 osd = rb_entry(n, struct ceph_osd, o_node);
473 if (o < osd->o_osd)
474 n = n->rb_left;
475 else if (o > osd->o_osd)
476 n = n->rb_right;
477 else
478 return osd;
480 return NULL;
483 static void __schedule_osd_timeout(struct ceph_osd_client *osdc)
485 schedule_delayed_work(&osdc->timeout_work,
486 osdc->client->mount_args->osd_keepalive_timeout * HZ);
489 static void __cancel_osd_timeout(struct ceph_osd_client *osdc)
491 cancel_delayed_work(&osdc->timeout_work);
495 * Register request, assign tid. If this is the first request, set up
496 * the timeout event.
498 static void register_request(struct ceph_osd_client *osdc,
499 struct ceph_osd_request *req)
501 mutex_lock(&osdc->request_mutex);
502 req->r_tid = ++osdc->last_tid;
503 req->r_request->hdr.tid = cpu_to_le64(req->r_tid);
504 INIT_LIST_HEAD(&req->r_req_lru_item);
506 dout("register_request %p tid %lld\n", req, req->r_tid);
507 __insert_request(osdc, req);
508 ceph_osdc_get_request(req);
509 osdc->num_requests++;
511 if (osdc->num_requests == 1) {
512 dout(" first request, scheduling timeout\n");
513 __schedule_osd_timeout(osdc);
515 mutex_unlock(&osdc->request_mutex);
519 * called under osdc->request_mutex
521 static void __unregister_request(struct ceph_osd_client *osdc,
522 struct ceph_osd_request *req)
524 dout("__unregister_request %p tid %lld\n", req, req->r_tid);
525 rb_erase(&req->r_node, &osdc->requests);
526 osdc->num_requests--;
528 if (req->r_osd) {
529 /* make sure the original request isn't in flight. */
530 ceph_con_revoke(&req->r_osd->o_con, req->r_request);
532 list_del_init(&req->r_osd_item);
533 if (list_empty(&req->r_osd->o_requests))
534 __move_osd_to_lru(osdc, req->r_osd);
535 req->r_osd = NULL;
538 ceph_osdc_put_request(req);
540 list_del_init(&req->r_req_lru_item);
541 if (osdc->num_requests == 0) {
542 dout(" no requests, canceling timeout\n");
543 __cancel_osd_timeout(osdc);
548 * Cancel a previously queued request message
550 static void __cancel_request(struct ceph_osd_request *req)
552 if (req->r_sent && req->r_osd) {
553 ceph_con_revoke(&req->r_osd->o_con, req->r_request);
554 req->r_sent = 0;
556 list_del_init(&req->r_req_lru_item);
560 * Pick an osd (the first 'up' osd in the pg), allocate the osd struct
561 * (as needed), and set the request r_osd appropriately. If there is
562 * no up osd, set r_osd to NULL.
564 * Return 0 if unchanged, 1 if changed, or negative on error.
566 * Caller should hold map_sem for read and request_mutex.
568 static int __map_osds(struct ceph_osd_client *osdc,
569 struct ceph_osd_request *req)
571 struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base;
572 struct ceph_pg pgid;
573 int acting[CEPH_PG_MAX_SIZE];
574 int o = -1, num = 0;
575 int err;
577 dout("map_osds %p tid %lld\n", req, req->r_tid);
578 err = ceph_calc_object_layout(&reqhead->layout, req->r_oid,
579 &req->r_file_layout, osdc->osdmap);
580 if (err)
581 return err;
582 pgid = reqhead->layout.ol_pgid;
583 req->r_pgid = pgid;
585 err = ceph_calc_pg_acting(osdc->osdmap, pgid, acting);
586 if (err > 0) {
587 o = acting[0];
588 num = err;
591 if ((req->r_osd && req->r_osd->o_osd == o &&
592 req->r_sent >= req->r_osd->o_incarnation &&
593 req->r_num_pg_osds == num &&
594 memcmp(req->r_pg_osds, acting, sizeof(acting[0])*num) == 0) ||
595 (req->r_osd == NULL && o == -1))
596 return 0; /* no change */
598 dout("map_osds tid %llu pgid %d.%x osd%d (was osd%d)\n",
599 req->r_tid, le32_to_cpu(pgid.pool), le16_to_cpu(pgid.ps), o,
600 req->r_osd ? req->r_osd->o_osd : -1);
602 /* record full pg acting set */
603 memcpy(req->r_pg_osds, acting, sizeof(acting[0]) * num);
604 req->r_num_pg_osds = num;
606 if (req->r_osd) {
607 __cancel_request(req);
608 list_del_init(&req->r_osd_item);
609 req->r_osd = NULL;
612 req->r_osd = __lookup_osd(osdc, o);
613 if (!req->r_osd && o >= 0) {
614 err = -ENOMEM;
615 req->r_osd = create_osd(osdc);
616 if (!req->r_osd)
617 goto out;
619 dout("map_osds osd %p is osd%d\n", req->r_osd, o);
620 req->r_osd->o_osd = o;
621 req->r_osd->o_con.peer_name.num = cpu_to_le64(o);
622 __insert_osd(osdc, req->r_osd);
624 ceph_con_open(&req->r_osd->o_con, &osdc->osdmap->osd_addr[o]);
627 if (req->r_osd) {
628 __remove_osd_from_lru(req->r_osd);
629 list_add(&req->r_osd_item, &req->r_osd->o_requests);
631 err = 1; /* osd or pg changed */
633 out:
634 return err;
638 * caller should hold map_sem (for read) and request_mutex
640 static int __send_request(struct ceph_osd_client *osdc,
641 struct ceph_osd_request *req)
643 struct ceph_osd_request_head *reqhead;
644 int err;
646 err = __map_osds(osdc, req);
647 if (err < 0)
648 return err;
649 if (req->r_osd == NULL) {
650 dout("send_request %p no up osds in pg\n", req);
651 ceph_monc_request_next_osdmap(&osdc->client->monc);
652 return 0;
655 dout("send_request %p tid %llu to osd%d flags %d\n",
656 req, req->r_tid, req->r_osd->o_osd, req->r_flags);
658 reqhead = req->r_request->front.iov_base;
659 reqhead->osdmap_epoch = cpu_to_le32(osdc->osdmap->epoch);
660 reqhead->flags |= cpu_to_le32(req->r_flags); /* e.g., RETRY */
661 reqhead->reassert_version = req->r_reassert_version;
663 req->r_stamp = jiffies;
664 list_move_tail(&req->r_req_lru_item, &osdc->req_lru);
666 ceph_msg_get(req->r_request); /* send consumes a ref */
667 ceph_con_send(&req->r_osd->o_con, req->r_request);
668 req->r_sent = req->r_osd->o_incarnation;
669 return 0;
673 * Timeout callback, called every N seconds when 1 or more osd
674 * requests has been active for more than N seconds. When this
675 * happens, we ping all OSDs with requests who have timed out to
676 * ensure any communications channel reset is detected. Reset the
677 * request timeouts another N seconds in the future as we go.
678 * Reschedule the timeout event another N seconds in future (unless
679 * there are no open requests).
681 static void handle_timeout(struct work_struct *work)
683 struct ceph_osd_client *osdc =
684 container_of(work, struct ceph_osd_client, timeout_work.work);
685 struct ceph_osd_request *req, *last_req = NULL;
686 struct ceph_osd *osd;
687 unsigned long timeout = osdc->client->mount_args->osd_timeout * HZ;
688 unsigned long keepalive =
689 osdc->client->mount_args->osd_keepalive_timeout * HZ;
690 unsigned long last_stamp = 0;
691 struct rb_node *p;
692 struct list_head slow_osds;
694 dout("timeout\n");
695 down_read(&osdc->map_sem);
697 ceph_monc_request_next_osdmap(&osdc->client->monc);
699 mutex_lock(&osdc->request_mutex);
700 for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
701 req = rb_entry(p, struct ceph_osd_request, r_node);
703 if (req->r_resend) {
704 int err;
706 dout("osdc resending prev failed %lld\n", req->r_tid);
707 err = __send_request(osdc, req);
708 if (err)
709 dout("osdc failed again on %lld\n", req->r_tid);
710 else
711 req->r_resend = false;
712 continue;
717 * reset osds that appear to be _really_ unresponsive. this
718 * is a failsafe measure.. we really shouldn't be getting to
719 * this point if the system is working properly. the monitors
720 * should mark the osd as failed and we should find out about
721 * it from an updated osd map.
723 while (timeout && !list_empty(&osdc->req_lru)) {
724 req = list_entry(osdc->req_lru.next, struct ceph_osd_request,
725 r_req_lru_item);
727 if (time_before(jiffies, req->r_stamp + timeout))
728 break;
730 BUG_ON(req == last_req && req->r_stamp == last_stamp);
731 last_req = req;
732 last_stamp = req->r_stamp;
734 osd = req->r_osd;
735 BUG_ON(!osd);
736 pr_warning(" tid %llu timed out on osd%d, will reset osd\n",
737 req->r_tid, osd->o_osd);
738 __kick_requests(osdc, osd);
742 * ping osds that are a bit slow. this ensures that if there
743 * is a break in the TCP connection we will notice, and reopen
744 * a connection with that osd (from the fault callback).
746 INIT_LIST_HEAD(&slow_osds);
747 list_for_each_entry(req, &osdc->req_lru, r_req_lru_item) {
748 if (time_before(jiffies, req->r_stamp + keepalive))
749 break;
751 osd = req->r_osd;
752 BUG_ON(!osd);
753 dout(" tid %llu is slow, will send keepalive on osd%d\n",
754 req->r_tid, osd->o_osd);
755 list_move_tail(&osd->o_keepalive_item, &slow_osds);
757 while (!list_empty(&slow_osds)) {
758 osd = list_entry(slow_osds.next, struct ceph_osd,
759 o_keepalive_item);
760 list_del_init(&osd->o_keepalive_item);
761 ceph_con_keepalive(&osd->o_con);
764 __schedule_osd_timeout(osdc);
765 mutex_unlock(&osdc->request_mutex);
767 up_read(&osdc->map_sem);
770 static void handle_osds_timeout(struct work_struct *work)
772 struct ceph_osd_client *osdc =
773 container_of(work, struct ceph_osd_client,
774 osds_timeout_work.work);
775 unsigned long delay =
776 osdc->client->mount_args->osd_idle_ttl * HZ >> 2;
778 dout("osds timeout\n");
779 down_read(&osdc->map_sem);
780 remove_old_osds(osdc, 0);
781 up_read(&osdc->map_sem);
783 schedule_delayed_work(&osdc->osds_timeout_work,
784 round_jiffies_relative(delay));
788 * handle osd op reply. either call the callback if it is specified,
789 * or do the completion to wake up the waiting thread.
791 static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
792 struct ceph_connection *con)
794 struct ceph_osd_reply_head *rhead = msg->front.iov_base;
795 struct ceph_osd_request *req;
796 u64 tid;
797 int numops, object_len, flags;
798 s32 result;
800 tid = le64_to_cpu(msg->hdr.tid);
801 if (msg->front.iov_len < sizeof(*rhead))
802 goto bad;
803 numops = le32_to_cpu(rhead->num_ops);
804 object_len = le32_to_cpu(rhead->object_len);
805 result = le32_to_cpu(rhead->result);
806 if (msg->front.iov_len != sizeof(*rhead) + object_len +
807 numops * sizeof(struct ceph_osd_op))
808 goto bad;
809 dout("handle_reply %p tid %llu result %d\n", msg, tid, (int)result);
811 /* lookup */
812 mutex_lock(&osdc->request_mutex);
813 req = __lookup_request(osdc, tid);
814 if (req == NULL) {
815 dout("handle_reply tid %llu dne\n", tid);
816 mutex_unlock(&osdc->request_mutex);
817 return;
819 ceph_osdc_get_request(req);
820 flags = le32_to_cpu(rhead->flags);
823 * if this connection filled our message, drop our reference now, to
824 * avoid a (safe but slower) revoke later.
826 if (req->r_con_filling_msg == con && req->r_reply == msg) {
827 dout(" dropping con_filling_msg ref %p\n", con);
828 req->r_con_filling_msg = NULL;
829 ceph_con_put(con);
832 if (!req->r_got_reply) {
833 unsigned bytes;
835 req->r_result = le32_to_cpu(rhead->result);
836 bytes = le32_to_cpu(msg->hdr.data_len);
837 dout("handle_reply result %d bytes %d\n", req->r_result,
838 bytes);
839 if (req->r_result == 0)
840 req->r_result = bytes;
842 /* in case this is a write and we need to replay, */
843 req->r_reassert_version = rhead->reassert_version;
845 req->r_got_reply = 1;
846 } else if ((flags & CEPH_OSD_FLAG_ONDISK) == 0) {
847 dout("handle_reply tid %llu dup ack\n", tid);
848 mutex_unlock(&osdc->request_mutex);
849 goto done;
852 dout("handle_reply tid %llu flags %d\n", tid, flags);
854 /* either this is a read, or we got the safe response */
855 if (result < 0 ||
856 (flags & CEPH_OSD_FLAG_ONDISK) ||
857 ((flags & CEPH_OSD_FLAG_WRITE) == 0))
858 __unregister_request(osdc, req);
860 mutex_unlock(&osdc->request_mutex);
862 if (req->r_callback)
863 req->r_callback(req, msg);
864 else
865 complete_all(&req->r_completion);
867 if (flags & CEPH_OSD_FLAG_ONDISK) {
868 if (req->r_safe_callback)
869 req->r_safe_callback(req, msg);
870 complete_all(&req->r_safe_completion); /* fsync waiter */
873 done:
874 ceph_osdc_put_request(req);
875 return;
877 bad:
878 pr_err("corrupt osd_op_reply got %d %d expected %d\n",
879 (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len),
880 (int)sizeof(*rhead));
881 ceph_msg_dump(msg);
885 static int __kick_requests(struct ceph_osd_client *osdc,
886 struct ceph_osd *kickosd)
888 struct ceph_osd_request *req;
889 struct rb_node *p, *n;
890 int needmap = 0;
891 int err;
893 dout("kick_requests osd%d\n", kickosd ? kickosd->o_osd : -1);
894 if (kickosd) {
895 err = __reset_osd(osdc, kickosd);
896 if (err == -EAGAIN)
897 return 1;
898 } else {
899 for (p = rb_first(&osdc->osds); p; p = n) {
900 struct ceph_osd *osd =
901 rb_entry(p, struct ceph_osd, o_node);
903 n = rb_next(p);
904 if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) ||
905 memcmp(&osd->o_con.peer_addr,
906 ceph_osd_addr(osdc->osdmap,
907 osd->o_osd),
908 sizeof(struct ceph_entity_addr)) != 0)
909 __reset_osd(osdc, osd);
913 for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
914 req = rb_entry(p, struct ceph_osd_request, r_node);
916 if (req->r_resend) {
917 dout(" r_resend set on tid %llu\n", req->r_tid);
918 __cancel_request(req);
919 goto kick;
921 if (req->r_osd && kickosd == req->r_osd) {
922 __cancel_request(req);
923 goto kick;
926 err = __map_osds(osdc, req);
927 if (err == 0)
928 continue; /* no change */
929 if (err < 0) {
930 dout(" setting r_resend on %llu\n", req->r_tid);
931 req->r_resend = true;
932 continue;
934 if (req->r_osd == NULL) {
935 dout("tid %llu maps to no valid osd\n", req->r_tid);
936 needmap++; /* request a newer map */
937 continue;
940 kick:
941 dout("kicking %p tid %llu osd%d\n", req, req->r_tid,
942 req->r_osd ? req->r_osd->o_osd : -1);
943 req->r_flags |= CEPH_OSD_FLAG_RETRY;
944 err = __send_request(osdc, req);
945 if (err) {
946 dout(" setting r_resend on %llu\n", req->r_tid);
947 req->r_resend = true;
951 return needmap;
955 * Resubmit osd requests whose osd or osd address has changed. Request
956 * a new osd map if osds are down, or we are otherwise unable to determine
957 * how to direct a request.
959 * Close connections to down osds.
961 * If @who is specified, resubmit requests for that specific osd.
963 * Caller should hold map_sem for read and request_mutex.
965 static void kick_requests(struct ceph_osd_client *osdc,
966 struct ceph_osd *kickosd)
968 int needmap;
970 mutex_lock(&osdc->request_mutex);
971 needmap = __kick_requests(osdc, kickosd);
972 mutex_unlock(&osdc->request_mutex);
974 if (needmap) {
975 dout("%d requests for down osds, need new map\n", needmap);
976 ceph_monc_request_next_osdmap(&osdc->client->monc);
981 * Process updated osd map.
983 * The message contains any number of incremental and full maps, normally
984 * indicating some sort of topology change in the cluster. Kick requests
985 * off to different OSDs as needed.
987 void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
989 void *p, *end, *next;
990 u32 nr_maps, maplen;
991 u32 epoch;
992 struct ceph_osdmap *newmap = NULL, *oldmap;
993 int err;
994 struct ceph_fsid fsid;
996 dout("handle_map have %u\n", osdc->osdmap ? osdc->osdmap->epoch : 0);
997 p = msg->front.iov_base;
998 end = p + msg->front.iov_len;
1000 /* verify fsid */
1001 ceph_decode_need(&p, end, sizeof(fsid), bad);
1002 ceph_decode_copy(&p, &fsid, sizeof(fsid));
1003 if (ceph_check_fsid(osdc->client, &fsid) < 0)
1004 return;
1006 down_write(&osdc->map_sem);
1008 /* incremental maps */
1009 ceph_decode_32_safe(&p, end, nr_maps, bad);
1010 dout(" %d inc maps\n", nr_maps);
1011 while (nr_maps > 0) {
1012 ceph_decode_need(&p, end, 2*sizeof(u32), bad);
1013 epoch = ceph_decode_32(&p);
1014 maplen = ceph_decode_32(&p);
1015 ceph_decode_need(&p, end, maplen, bad);
1016 next = p + maplen;
1017 if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) {
1018 dout("applying incremental map %u len %d\n",
1019 epoch, maplen);
1020 newmap = osdmap_apply_incremental(&p, next,
1021 osdc->osdmap,
1022 osdc->client->msgr);
1023 if (IS_ERR(newmap)) {
1024 err = PTR_ERR(newmap);
1025 goto bad;
1027 BUG_ON(!newmap);
1028 if (newmap != osdc->osdmap) {
1029 ceph_osdmap_destroy(osdc->osdmap);
1030 osdc->osdmap = newmap;
1032 } else {
1033 dout("ignoring incremental map %u len %d\n",
1034 epoch, maplen);
1036 p = next;
1037 nr_maps--;
1039 if (newmap)
1040 goto done;
1042 /* full maps */
1043 ceph_decode_32_safe(&p, end, nr_maps, bad);
1044 dout(" %d full maps\n", nr_maps);
1045 while (nr_maps) {
1046 ceph_decode_need(&p, end, 2*sizeof(u32), bad);
1047 epoch = ceph_decode_32(&p);
1048 maplen = ceph_decode_32(&p);
1049 ceph_decode_need(&p, end, maplen, bad);
1050 if (nr_maps > 1) {
1051 dout("skipping non-latest full map %u len %d\n",
1052 epoch, maplen);
1053 } else if (osdc->osdmap && osdc->osdmap->epoch >= epoch) {
1054 dout("skipping full map %u len %d, "
1055 "older than our %u\n", epoch, maplen,
1056 osdc->osdmap->epoch);
1057 } else {
1058 dout("taking full map %u len %d\n", epoch, maplen);
1059 newmap = osdmap_decode(&p, p+maplen);
1060 if (IS_ERR(newmap)) {
1061 err = PTR_ERR(newmap);
1062 goto bad;
1064 BUG_ON(!newmap);
1065 oldmap = osdc->osdmap;
1066 osdc->osdmap = newmap;
1067 if (oldmap)
1068 ceph_osdmap_destroy(oldmap);
1070 p += maplen;
1071 nr_maps--;
1074 done:
1075 downgrade_write(&osdc->map_sem);
1076 ceph_monc_got_osdmap(&osdc->client->monc, osdc->osdmap->epoch);
1077 if (newmap)
1078 kick_requests(osdc, NULL);
1079 up_read(&osdc->map_sem);
1080 wake_up_all(&osdc->client->auth_wq);
1081 return;
1083 bad:
1084 pr_err("osdc handle_map corrupt msg\n");
1085 ceph_msg_dump(msg);
1086 up_write(&osdc->map_sem);
1087 return;
1091 * Register request, send initial attempt.
1093 int ceph_osdc_start_request(struct ceph_osd_client *osdc,
1094 struct ceph_osd_request *req,
1095 bool nofail)
1097 int rc = 0;
1099 req->r_request->pages = req->r_pages;
1100 req->r_request->nr_pages = req->r_num_pages;
1102 register_request(osdc, req);
1104 down_read(&osdc->map_sem);
1105 mutex_lock(&osdc->request_mutex);
1107 * a racing kick_requests() may have sent the message for us
1108 * while we dropped request_mutex above, so only send now if
1109 * the request still han't been touched yet.
1111 if (req->r_sent == 0) {
1112 rc = __send_request(osdc, req);
1113 if (rc) {
1114 if (nofail) {
1115 dout("osdc_start_request failed send, "
1116 " marking %lld\n", req->r_tid);
1117 req->r_resend = true;
1118 rc = 0;
1119 } else {
1120 __unregister_request(osdc, req);
1124 mutex_unlock(&osdc->request_mutex);
1125 up_read(&osdc->map_sem);
1126 return rc;
1130 * wait for a request to complete
1132 int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
1133 struct ceph_osd_request *req)
1135 int rc;
1137 rc = wait_for_completion_interruptible(&req->r_completion);
1138 if (rc < 0) {
1139 mutex_lock(&osdc->request_mutex);
1140 __cancel_request(req);
1141 __unregister_request(osdc, req);
1142 mutex_unlock(&osdc->request_mutex);
1143 dout("wait_request tid %llu canceled/timed out\n", req->r_tid);
1144 return rc;
1147 dout("wait_request tid %llu result %d\n", req->r_tid, req->r_result);
1148 return req->r_result;
1152 * sync - wait for all in-flight requests to flush. avoid starvation.
1154 void ceph_osdc_sync(struct ceph_osd_client *osdc)
1156 struct ceph_osd_request *req;
1157 u64 last_tid, next_tid = 0;
1159 mutex_lock(&osdc->request_mutex);
1160 last_tid = osdc->last_tid;
1161 while (1) {
1162 req = __lookup_request_ge(osdc, next_tid);
1163 if (!req)
1164 break;
1165 if (req->r_tid > last_tid)
1166 break;
1168 next_tid = req->r_tid + 1;
1169 if ((req->r_flags & CEPH_OSD_FLAG_WRITE) == 0)
1170 continue;
1172 ceph_osdc_get_request(req);
1173 mutex_unlock(&osdc->request_mutex);
1174 dout("sync waiting on tid %llu (last is %llu)\n",
1175 req->r_tid, last_tid);
1176 wait_for_completion(&req->r_safe_completion);
1177 mutex_lock(&osdc->request_mutex);
1178 ceph_osdc_put_request(req);
1180 mutex_unlock(&osdc->request_mutex);
1181 dout("sync done (thru tid %llu)\n", last_tid);
1185 * init, shutdown
1187 int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client)
1189 int err;
1191 dout("init\n");
1192 osdc->client = client;
1193 osdc->osdmap = NULL;
1194 init_rwsem(&osdc->map_sem);
1195 init_completion(&osdc->map_waiters);
1196 osdc->last_requested_map = 0;
1197 mutex_init(&osdc->request_mutex);
1198 osdc->last_tid = 0;
1199 osdc->osds = RB_ROOT;
1200 INIT_LIST_HEAD(&osdc->osd_lru);
1201 osdc->requests = RB_ROOT;
1202 INIT_LIST_HEAD(&osdc->req_lru);
1203 osdc->num_requests = 0;
1204 INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout);
1205 INIT_DELAYED_WORK(&osdc->osds_timeout_work, handle_osds_timeout);
1207 schedule_delayed_work(&osdc->osds_timeout_work,
1208 round_jiffies_relative(osdc->client->mount_args->osd_idle_ttl * HZ));
1210 err = -ENOMEM;
1211 osdc->req_mempool = mempool_create_kmalloc_pool(10,
1212 sizeof(struct ceph_osd_request));
1213 if (!osdc->req_mempool)
1214 goto out;
1216 err = ceph_msgpool_init(&osdc->msgpool_op, OSD_OP_FRONT_LEN, 10, true,
1217 "osd_op");
1218 if (err < 0)
1219 goto out_mempool;
1220 err = ceph_msgpool_init(&osdc->msgpool_op_reply,
1221 OSD_OPREPLY_FRONT_LEN, 10, true,
1222 "osd_op_reply");
1223 if (err < 0)
1224 goto out_msgpool;
1225 return 0;
1227 out_msgpool:
1228 ceph_msgpool_destroy(&osdc->msgpool_op);
1229 out_mempool:
1230 mempool_destroy(osdc->req_mempool);
1231 out:
1232 return err;
1235 void ceph_osdc_stop(struct ceph_osd_client *osdc)
1237 cancel_delayed_work_sync(&osdc->timeout_work);
1238 cancel_delayed_work_sync(&osdc->osds_timeout_work);
1239 if (osdc->osdmap) {
1240 ceph_osdmap_destroy(osdc->osdmap);
1241 osdc->osdmap = NULL;
1243 remove_old_osds(osdc, 1);
1244 mempool_destroy(osdc->req_mempool);
1245 ceph_msgpool_destroy(&osdc->msgpool_op);
1246 ceph_msgpool_destroy(&osdc->msgpool_op_reply);
1250 * Read some contiguous pages. If we cross a stripe boundary, shorten
1251 * *plen. Return number of bytes read, or error.
1253 int ceph_osdc_readpages(struct ceph_osd_client *osdc,
1254 struct ceph_vino vino, struct ceph_file_layout *layout,
1255 u64 off, u64 *plen,
1256 u32 truncate_seq, u64 truncate_size,
1257 struct page **pages, int num_pages)
1259 struct ceph_osd_request *req;
1260 int rc = 0;
1262 dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino,
1263 vino.snap, off, *plen);
1264 req = ceph_osdc_new_request(osdc, layout, vino, off, plen,
1265 CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
1266 NULL, 0, truncate_seq, truncate_size, NULL,
1267 false, 1);
1268 if (!req)
1269 return -ENOMEM;
1271 /* it may be a short read due to an object boundary */
1272 req->r_pages = pages;
1274 dout("readpages final extent is %llu~%llu (%d pages)\n",
1275 off, *plen, req->r_num_pages);
1277 rc = ceph_osdc_start_request(osdc, req, false);
1278 if (!rc)
1279 rc = ceph_osdc_wait_request(osdc, req);
1281 ceph_osdc_put_request(req);
1282 dout("readpages result %d\n", rc);
1283 return rc;
1287 * do a synchronous write on N pages
1289 int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
1290 struct ceph_file_layout *layout,
1291 struct ceph_snap_context *snapc,
1292 u64 off, u64 len,
1293 u32 truncate_seq, u64 truncate_size,
1294 struct timespec *mtime,
1295 struct page **pages, int num_pages,
1296 int flags, int do_sync, bool nofail)
1298 struct ceph_osd_request *req;
1299 int rc = 0;
1301 BUG_ON(vino.snap != CEPH_NOSNAP);
1302 req = ceph_osdc_new_request(osdc, layout, vino, off, &len,
1303 CEPH_OSD_OP_WRITE,
1304 flags | CEPH_OSD_FLAG_ONDISK |
1305 CEPH_OSD_FLAG_WRITE,
1306 snapc, do_sync,
1307 truncate_seq, truncate_size, mtime,
1308 nofail, 1);
1309 if (!req)
1310 return -ENOMEM;
1312 /* it may be a short write due to an object boundary */
1313 req->r_pages = pages;
1314 dout("writepages %llu~%llu (%d pages)\n", off, len,
1315 req->r_num_pages);
1317 rc = ceph_osdc_start_request(osdc, req, nofail);
1318 if (!rc)
1319 rc = ceph_osdc_wait_request(osdc, req);
1321 ceph_osdc_put_request(req);
1322 if (rc == 0)
1323 rc = len;
1324 dout("writepages result %d\n", rc);
1325 return rc;
1329 * handle incoming message
1331 static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
1333 struct ceph_osd *osd = con->private;
1334 struct ceph_osd_client *osdc;
1335 int type = le16_to_cpu(msg->hdr.type);
1337 if (!osd)
1338 goto out;
1339 osdc = osd->o_osdc;
1341 switch (type) {
1342 case CEPH_MSG_OSD_MAP:
1343 ceph_osdc_handle_map(osdc, msg);
1344 break;
1345 case CEPH_MSG_OSD_OPREPLY:
1346 handle_reply(osdc, msg, con);
1347 break;
1349 default:
1350 pr_err("received unknown message type %d %s\n", type,
1351 ceph_msg_type_name(type));
1353 out:
1354 ceph_msg_put(msg);
1358 * lookup and return message for incoming reply. set up reply message
1359 * pages.
1361 static struct ceph_msg *get_reply(struct ceph_connection *con,
1362 struct ceph_msg_header *hdr,
1363 int *skip)
1365 struct ceph_osd *osd = con->private;
1366 struct ceph_osd_client *osdc = osd->o_osdc;
1367 struct ceph_msg *m;
1368 struct ceph_osd_request *req;
1369 int front = le32_to_cpu(hdr->front_len);
1370 int data_len = le32_to_cpu(hdr->data_len);
1371 u64 tid;
1373 tid = le64_to_cpu(hdr->tid);
1374 mutex_lock(&osdc->request_mutex);
1375 req = __lookup_request(osdc, tid);
1376 if (!req) {
1377 *skip = 1;
1378 m = NULL;
1379 pr_info("get_reply unknown tid %llu from osd%d\n", tid,
1380 osd->o_osd);
1381 goto out;
1384 if (req->r_con_filling_msg) {
1385 dout("get_reply revoking msg %p from old con %p\n",
1386 req->r_reply, req->r_con_filling_msg);
1387 ceph_con_revoke_message(req->r_con_filling_msg, req->r_reply);
1388 ceph_con_put(req->r_con_filling_msg);
1389 req->r_con_filling_msg = NULL;
1392 if (front > req->r_reply->front.iov_len) {
1393 pr_warning("get_reply front %d > preallocated %d\n",
1394 front, (int)req->r_reply->front.iov_len);
1395 m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front, GFP_NOFS);
1396 if (!m)
1397 goto out;
1398 ceph_msg_put(req->r_reply);
1399 req->r_reply = m;
1401 m = ceph_msg_get(req->r_reply);
1403 if (data_len > 0) {
1404 unsigned data_off = le16_to_cpu(hdr->data_off);
1405 int want = calc_pages_for(data_off & ~PAGE_MASK, data_len);
1407 if (unlikely(req->r_num_pages < want)) {
1408 pr_warning("tid %lld reply %d > expected %d pages\n",
1409 tid, want, m->nr_pages);
1410 *skip = 1;
1411 ceph_msg_put(m);
1412 m = NULL;
1413 goto out;
1415 m->pages = req->r_pages;
1416 m->nr_pages = req->r_num_pages;
1418 *skip = 0;
1419 req->r_con_filling_msg = ceph_con_get(con);
1420 dout("get_reply tid %lld %p\n", tid, m);
1422 out:
1423 mutex_unlock(&osdc->request_mutex);
1424 return m;
1428 static struct ceph_msg *alloc_msg(struct ceph_connection *con,
1429 struct ceph_msg_header *hdr,
1430 int *skip)
1432 struct ceph_osd *osd = con->private;
1433 int type = le16_to_cpu(hdr->type);
1434 int front = le32_to_cpu(hdr->front_len);
1436 switch (type) {
1437 case CEPH_MSG_OSD_MAP:
1438 return ceph_msg_new(type, front, GFP_NOFS);
1439 case CEPH_MSG_OSD_OPREPLY:
1440 return get_reply(con, hdr, skip);
1441 default:
1442 pr_info("alloc_msg unexpected msg type %d from osd%d\n", type,
1443 osd->o_osd);
1444 *skip = 1;
1445 return NULL;
1450 * Wrappers to refcount containing ceph_osd struct
1452 static struct ceph_connection *get_osd_con(struct ceph_connection *con)
1454 struct ceph_osd *osd = con->private;
1455 if (get_osd(osd))
1456 return con;
1457 return NULL;
1460 static void put_osd_con(struct ceph_connection *con)
1462 struct ceph_osd *osd = con->private;
1463 put_osd(osd);
1467 * authentication
1469 static int get_authorizer(struct ceph_connection *con,
1470 void **buf, int *len, int *proto,
1471 void **reply_buf, int *reply_len, int force_new)
1473 struct ceph_osd *o = con->private;
1474 struct ceph_osd_client *osdc = o->o_osdc;
1475 struct ceph_auth_client *ac = osdc->client->monc.auth;
1476 int ret = 0;
1478 if (force_new && o->o_authorizer) {
1479 ac->ops->destroy_authorizer(ac, o->o_authorizer);
1480 o->o_authorizer = NULL;
1482 if (o->o_authorizer == NULL) {
1483 ret = ac->ops->create_authorizer(
1484 ac, CEPH_ENTITY_TYPE_OSD,
1485 &o->o_authorizer,
1486 &o->o_authorizer_buf,
1487 &o->o_authorizer_buf_len,
1488 &o->o_authorizer_reply_buf,
1489 &o->o_authorizer_reply_buf_len);
1490 if (ret)
1491 return ret;
1494 *proto = ac->protocol;
1495 *buf = o->o_authorizer_buf;
1496 *len = o->o_authorizer_buf_len;
1497 *reply_buf = o->o_authorizer_reply_buf;
1498 *reply_len = o->o_authorizer_reply_buf_len;
1499 return 0;
1503 static int verify_authorizer_reply(struct ceph_connection *con, int len)
1505 struct ceph_osd *o = con->private;
1506 struct ceph_osd_client *osdc = o->o_osdc;
1507 struct ceph_auth_client *ac = osdc->client->monc.auth;
1509 return ac->ops->verify_authorizer_reply(ac, o->o_authorizer, len);
1512 static int invalidate_authorizer(struct ceph_connection *con)
1514 struct ceph_osd *o = con->private;
1515 struct ceph_osd_client *osdc = o->o_osdc;
1516 struct ceph_auth_client *ac = osdc->client->monc.auth;
1518 if (ac->ops->invalidate_authorizer)
1519 ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD);
1521 return ceph_monc_validate_auth(&osdc->client->monc);
1524 static const struct ceph_connection_operations osd_con_ops = {
1525 .get = get_osd_con,
1526 .put = put_osd_con,
1527 .dispatch = dispatch,
1528 .get_authorizer = get_authorizer,
1529 .verify_authorizer_reply = verify_authorizer_reply,
1530 .invalidate_authorizer = invalidate_authorizer,
1531 .alloc_msg = alloc_msg,
1532 .fault = osd_reset,