Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1 | #include "ceph_debug.h" |
| 2 | |
| 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> |
| 9 | |
| 10 | #include "super.h" |
| 11 | #include "osd_client.h" |
| 12 | #include "messenger.h" |
| 13 | #include "decode.h" |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 14 | #include "auth.h" |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 15 | |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 16 | #define OSD_OP_FRONT_LEN 4096 |
| 17 | #define OSD_OPREPLY_FRONT_LEN 512 |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 18 | |
Tobias Klauser | 9e32789 | 2010-05-20 10:40:19 +0200 | [diff] [blame] | 19 | static const struct ceph_connection_operations osd_con_ops; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 20 | static int __kick_requests(struct ceph_osd_client *osdc, |
| 21 | struct ceph_osd *kickosd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 22 | |
| 23 | static void kick_requests(struct ceph_osd_client *osdc, struct ceph_osd *osd); |
| 24 | |
| 25 | /* |
| 26 | * Implement client access to distributed object storage cluster. |
| 27 | * |
| 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. |
| 33 | * |
| 34 | * Cluster membership and the mapping of data objects onto storage devices |
| 35 | * are described by the osd map. |
| 36 | * |
| 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. |
| 41 | */ |
| 42 | |
| 43 | /* |
| 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. |
| 47 | * |
| 48 | * fill osd op in request message. |
| 49 | */ |
| 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) |
| 54 | { |
| 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; |
| 60 | |
| 61 | reqhead->snapid = cpu_to_le64(vino.snap); |
| 62 | |
| 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); |
| 69 | |
| 70 | sprintf(req->r_oid, "%llx.%08llx", vino.ino, bno); |
| 71 | req->r_oid_len = strlen(req->r_oid); |
| 72 | |
| 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); |
| 76 | |
| 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); |
| 79 | } |
| 80 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 81 | /* |
| 82 | * requests |
| 83 | */ |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 84 | void ceph_osdc_release_request(struct kref *kref) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 85 | { |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 86 | struct ceph_osd_request *req = container_of(kref, |
| 87 | struct ceph_osd_request, |
| 88 | r_kref); |
| 89 | |
| 90 | if (req->r_request) |
| 91 | ceph_msg_put(req->r_request); |
| 92 | if (req->r_reply) |
| 93 | ceph_msg_put(req->r_reply); |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 94 | if (req->r_con_filling_msg) { |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 95 | dout("release_request revoking pages %p from con %p\n", |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 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); |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 100 | } |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 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); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* |
| 112 | * build new request AND message, calculate layout, and adjust file |
| 113 | * extent as needed. |
| 114 | * |
| 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.) |
| 118 | * |
| 119 | * if @do_sync, include a 'startsync' command so that the osd will flush |
| 120 | * data quickly. |
| 121 | */ |
| 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) |
| 133 | { |
| 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; |
Yehuda Sadeh | 0c94899 | 2010-02-01 16:10:45 -0800 | [diff] [blame] | 139 | int num_op = 1 + do_sync; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 140 | size_t msg_size = sizeof(*head) + num_op*sizeof(*op); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 141 | int i; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 142 | |
| 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); |
| 148 | } |
| 149 | if (req == NULL) |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 150 | return NULL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 151 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 152 | req->r_osdc = osdc; |
| 153 | req->r_mempool = use_mempool; |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 154 | kref_init(&req->r_kref); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 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; |
| 159 | |
| 160 | WARN_ON((flags & (CEPH_OSD_FLAG_READ|CEPH_OSD_FLAG_WRITE)) == 0); |
| 161 | |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 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, |
Yehuda Sadeh | 34d2376 | 2010-04-06 14:33:58 -0700 | [diff] [blame] | 167 | OSD_OPREPLY_FRONT_LEN, GFP_NOFS); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 168 | if (!msg) { |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 169 | ceph_osdc_put_request(req); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 170 | return NULL; |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 171 | } |
| 172 | req->r_reply = msg; |
| 173 | |
| 174 | /* create request message; allow space for oid */ |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 175 | msg_size += 40; |
| 176 | if (snapc) |
| 177 | msg_size += sizeof(u64) * snapc->num_snaps; |
| 178 | if (use_mempool) |
Sage Weil | 8f3bc05 | 2009-10-14 17:36:07 -0700 | [diff] [blame] | 179 | msg = ceph_msgpool_get(&osdc->msgpool_op, 0); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 180 | else |
Yehuda Sadeh | 34d2376 | 2010-04-06 14:33:58 -0700 | [diff] [blame] | 181 | msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, GFP_NOFS); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 182 | if (!msg) { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 183 | ceph_osdc_put_request(req); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 184 | return NULL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 185 | } |
| 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); |
| 191 | |
| 192 | req->r_request = msg; |
| 193 | req->r_snapc = ceph_get_snap_context(snapc); |
| 194 | |
| 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); |
| 201 | |
| 202 | /* calculate max write size */ |
| 203 | calc_layout(osdc, vino, layout, off, plen, req); |
| 204 | req->r_file_layout = *layout; /* keep a copy */ |
| 205 | |
| 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); |
| 210 | } |
Yehuda Sadeh | 0c94899 | 2010-02-01 16:10:45 -0800 | [diff] [blame] | 211 | op->extent.truncate_size = cpu_to_le64(truncate_size); |
| 212 | op->extent.truncate_seq = cpu_to_le32(truncate_seq); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 213 | |
| 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; |
| 218 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 219 | if (do_sync) { |
| 220 | op++; |
| 221 | op->op = cpu_to_le16(CEPH_OSD_OP_STARTSYNC); |
| 222 | } |
| 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); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | BUG_ON(p > msg->front.iov_base + msg->front.iov_len); |
Sage Weil | 6f863e7 | 2010-03-01 15:26:41 -0800 | [diff] [blame] | 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); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 236 | return req; |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | * We keep osd requests in an rbtree, sorted by ->r_tid. |
| 241 | */ |
| 242 | static void __insert_request(struct ceph_osd_client *osdc, |
| 243 | struct ceph_osd_request *new) |
| 244 | { |
| 245 | struct rb_node **p = &osdc->requests.rb_node; |
| 246 | struct rb_node *parent = NULL; |
| 247 | struct ceph_osd_request *req = NULL; |
| 248 | |
| 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(); |
| 258 | } |
| 259 | |
| 260 | rb_link_node(&new->r_node, parent, p); |
| 261 | rb_insert_color(&new->r_node, &osdc->requests); |
| 262 | } |
| 263 | |
| 264 | static struct ceph_osd_request *__lookup_request(struct ceph_osd_client *osdc, |
| 265 | u64 tid) |
| 266 | { |
| 267 | struct ceph_osd_request *req; |
| 268 | struct rb_node *n = osdc->requests.rb_node; |
| 269 | |
| 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; |
| 278 | } |
| 279 | return NULL; |
| 280 | } |
| 281 | |
| 282 | static struct ceph_osd_request * |
| 283 | __lookup_request_ge(struct ceph_osd_client *osdc, |
| 284 | u64 tid) |
| 285 | { |
| 286 | struct ceph_osd_request *req; |
| 287 | struct rb_node *n = osdc->requests.rb_node; |
| 288 | |
| 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; |
| 299 | } |
| 300 | } |
| 301 | return NULL; |
| 302 | } |
| 303 | |
| 304 | |
| 305 | /* |
Sage Weil | 81b024e | 2009-10-09 10:29:18 -0700 | [diff] [blame] | 306 | * If the osd connection drops, we need to resubmit all requests. |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 307 | */ |
| 308 | static void osd_reset(struct ceph_connection *con) |
| 309 | { |
| 310 | struct ceph_osd *osd = con->private; |
| 311 | struct ceph_osd_client *osdc; |
| 312 | |
| 313 | if (!osd) |
| 314 | return; |
| 315 | dout("osd_reset osd%d\n", osd->o_osd); |
| 316 | osdc = osd->o_osdc; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 317 | down_read(&osdc->map_sem); |
| 318 | kick_requests(osdc, osd); |
| 319 | up_read(&osdc->map_sem); |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * Track open sessions with osds. |
| 324 | */ |
| 325 | static struct ceph_osd *create_osd(struct ceph_osd_client *osdc) |
| 326 | { |
| 327 | struct ceph_osd *osd; |
| 328 | |
| 329 | osd = kzalloc(sizeof(*osd), GFP_NOFS); |
| 330 | if (!osd) |
| 331 | return NULL; |
| 332 | |
| 333 | atomic_set(&osd->o_ref, 1); |
| 334 | osd->o_osdc = osdc; |
| 335 | INIT_LIST_HEAD(&osd->o_requests); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 336 | INIT_LIST_HEAD(&osd->o_osd_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 337 | osd->o_incarnation = 1; |
| 338 | |
| 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; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 343 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 344 | INIT_LIST_HEAD(&osd->o_keepalive_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 345 | return osd; |
| 346 | } |
| 347 | |
| 348 | static struct ceph_osd *get_osd(struct ceph_osd *osd) |
| 349 | { |
| 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; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | static void put_osd(struct ceph_osd *osd) |
| 361 | { |
| 362 | dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref), |
| 363 | atomic_read(&osd->o_ref) - 1); |
Sage Weil | 79494d1 | 2010-05-27 14:15:49 -0700 | [diff] [blame] | 364 | if (atomic_dec_and_test(&osd->o_ref)) { |
| 365 | struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth; |
| 366 | |
| 367 | if (osd->o_authorizer) |
| 368 | ac->ops->destroy_authorizer(ac, osd->o_authorizer); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 369 | kfree(osd); |
Sage Weil | 79494d1 | 2010-05-27 14:15:49 -0700 | [diff] [blame] | 370 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /* |
| 374 | * remove an osd from our map |
| 375 | */ |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 376 | static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 377 | { |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 378 | dout("__remove_osd %p\n", osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 379 | BUG_ON(!list_empty(&osd->o_requests)); |
| 380 | rb_erase(&osd->o_node, &osdc->osds); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 381 | list_del_init(&osd->o_osd_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 382 | ceph_con_close(&osd->o_con); |
| 383 | put_osd(osd); |
| 384 | } |
| 385 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 386 | static void __move_osd_to_lru(struct ceph_osd_client *osdc, |
| 387 | struct ceph_osd *osd) |
| 388 | { |
| 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; |
| 393 | } |
| 394 | |
| 395 | static void __remove_osd_from_lru(struct ceph_osd *osd) |
| 396 | { |
| 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); |
| 400 | } |
| 401 | |
| 402 | static void remove_old_osds(struct ceph_osd_client *osdc, int remove_all) |
| 403 | { |
| 404 | struct ceph_osd *osd, *nosd; |
| 405 | |
| 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); |
| 412 | } |
| 413 | mutex_unlock(&osdc->request_mutex); |
| 414 | } |
| 415 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 416 | /* |
| 417 | * reset osd connect |
| 418 | */ |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 419 | static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 420 | { |
Sage Weil | 87b315a | 2010-03-22 14:51:18 -0700 | [diff] [blame] | 421 | struct ceph_osd_request *req; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 422 | int ret = 0; |
| 423 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 424 | dout("__reset_osd %p osd%d\n", osd, osd->o_osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 425 | if (list_empty(&osd->o_requests)) { |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 426 | __remove_osd(osdc, osd); |
Sage Weil | 87b315a | 2010-03-22 14:51:18 -0700 | [diff] [blame] | 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; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 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++; |
| 441 | } |
| 442 | return ret; |
| 443 | } |
| 444 | |
| 445 | static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new) |
| 446 | { |
| 447 | struct rb_node **p = &osdc->osds.rb_node; |
| 448 | struct rb_node *parent = NULL; |
| 449 | struct ceph_osd *osd = NULL; |
| 450 | |
| 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(); |
| 460 | } |
| 461 | |
| 462 | rb_link_node(&new->o_node, parent, p); |
| 463 | rb_insert_color(&new->o_node, &osdc->osds); |
| 464 | } |
| 465 | |
| 466 | static struct ceph_osd *__lookup_osd(struct ceph_osd_client *osdc, int o) |
| 467 | { |
| 468 | struct ceph_osd *osd; |
| 469 | struct rb_node *n = osdc->osds.rb_node; |
| 470 | |
| 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; |
| 479 | } |
| 480 | return NULL; |
| 481 | } |
| 482 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 483 | static void __schedule_osd_timeout(struct ceph_osd_client *osdc) |
| 484 | { |
| 485 | schedule_delayed_work(&osdc->timeout_work, |
| 486 | osdc->client->mount_args->osd_keepalive_timeout * HZ); |
| 487 | } |
| 488 | |
| 489 | static void __cancel_osd_timeout(struct ceph_osd_client *osdc) |
| 490 | { |
| 491 | cancel_delayed_work(&osdc->timeout_work); |
| 492 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 493 | |
| 494 | /* |
| 495 | * Register request, assign tid. If this is the first request, set up |
| 496 | * the timeout event. |
| 497 | */ |
| 498 | static void register_request(struct ceph_osd_client *osdc, |
| 499 | struct ceph_osd_request *req) |
| 500 | { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 501 | mutex_lock(&osdc->request_mutex); |
| 502 | req->r_tid = ++osdc->last_tid; |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame] | 503 | req->r_request->hdr.tid = cpu_to_le64(req->r_tid); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 504 | INIT_LIST_HEAD(&req->r_req_lru_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 505 | |
| 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++; |
| 510 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 511 | if (osdc->num_requests == 1) { |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 512 | dout(" first request, scheduling timeout\n"); |
| 513 | __schedule_osd_timeout(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 514 | } |
| 515 | mutex_unlock(&osdc->request_mutex); |
| 516 | } |
| 517 | |
| 518 | /* |
| 519 | * called under osdc->request_mutex |
| 520 | */ |
| 521 | static void __unregister_request(struct ceph_osd_client *osdc, |
| 522 | struct ceph_osd_request *req) |
| 523 | { |
| 524 | dout("__unregister_request %p tid %lld\n", req, req->r_tid); |
| 525 | rb_erase(&req->r_node, &osdc->requests); |
| 526 | osdc->num_requests--; |
| 527 | |
Sage Weil | 0ba6478 | 2009-10-08 16:57:16 -0700 | [diff] [blame] | 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); |
| 531 | |
| 532 | list_del_init(&req->r_osd_item); |
| 533 | if (list_empty(&req->r_osd->o_requests)) |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 534 | __move_osd_to_lru(osdc, req->r_osd); |
Sage Weil | 0ba6478 | 2009-10-08 16:57:16 -0700 | [diff] [blame] | 535 | req->r_osd = NULL; |
| 536 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 537 | |
| 538 | ceph_osdc_put_request(req); |
| 539 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 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); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * Cancel a previously queued request message |
| 549 | */ |
| 550 | static void __cancel_request(struct ceph_osd_request *req) |
| 551 | { |
| 552 | if (req->r_sent) { |
| 553 | ceph_con_revoke(&req->r_osd->o_con, req->r_request); |
| 554 | req->r_sent = 0; |
| 555 | } |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 556 | list_del_init(&req->r_req_lru_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* |
| 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. |
| 563 | * |
| 564 | * Return 0 if unchanged, 1 if changed, or negative on error. |
| 565 | * |
| 566 | * Caller should hold map_sem for read and request_mutex. |
| 567 | */ |
| 568 | static int __map_osds(struct ceph_osd_client *osdc, |
| 569 | struct ceph_osd_request *req) |
| 570 | { |
| 571 | struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base; |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 572 | struct ceph_pg pgid; |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 573 | int acting[CEPH_PG_MAX_SIZE]; |
| 574 | int o = -1, num = 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 575 | int err; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 576 | |
| 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; |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 582 | pgid = reqhead->layout.ol_pgid; |
Sage Weil | 7740a42 | 2010-01-08 15:58:25 -0800 | [diff] [blame] | 583 | req->r_pgid = pgid; |
| 584 | |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 585 | err = ceph_calc_pg_acting(osdc->osdmap, pgid, acting); |
| 586 | if (err > 0) { |
| 587 | o = acting[0]; |
| 588 | num = err; |
| 589 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 590 | |
| 591 | if ((req->r_osd && req->r_osd->o_osd == o && |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 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) || |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 595 | (req->r_osd == NULL && o == -1)) |
| 596 | return 0; /* no change */ |
| 597 | |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 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, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 600 | req->r_osd ? req->r_osd->o_osd : -1); |
| 601 | |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 602 | /* record full pg acting set */ |
| 603 | memcpy(req->r_pg_osds, acting, sizeof(acting[0]) * num); |
| 604 | req->r_num_pg_osds = num; |
| 605 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 606 | if (req->r_osd) { |
| 607 | __cancel_request(req); |
| 608 | list_del_init(&req->r_osd_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 609 | req->r_osd = NULL; |
| 610 | } |
| 611 | |
| 612 | req->r_osd = __lookup_osd(osdc, o); |
| 613 | if (!req->r_osd && o >= 0) { |
Sage Weil | c99eb1c | 2010-02-26 09:37:33 -0800 | [diff] [blame] | 614 | err = -ENOMEM; |
| 615 | req->r_osd = create_osd(osdc); |
| 616 | if (!req->r_osd) |
| 617 | goto out; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 618 | |
| 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); |
| 623 | |
| 624 | ceph_con_open(&req->r_osd->o_con, &osdc->osdmap->osd_addr[o]); |
| 625 | } |
| 626 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 627 | if (req->r_osd) { |
| 628 | __remove_osd_from_lru(req->r_osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 629 | list_add(&req->r_osd_item, &req->r_osd->o_requests); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 630 | } |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 631 | err = 1; /* osd or pg changed */ |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 632 | |
| 633 | out: |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 634 | return err; |
| 635 | } |
| 636 | |
| 637 | /* |
| 638 | * caller should hold map_sem (for read) and request_mutex |
| 639 | */ |
| 640 | static int __send_request(struct ceph_osd_client *osdc, |
| 641 | struct ceph_osd_request *req) |
| 642 | { |
| 643 | struct ceph_osd_request_head *reqhead; |
| 644 | int err; |
| 645 | |
| 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; |
| 653 | } |
| 654 | |
| 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); |
| 657 | |
| 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; |
| 662 | |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 663 | req->r_stamp = jiffies; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 664 | list_move_tail(&osdc->req_lru, &req->r_req_lru_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 665 | |
| 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; |
| 670 | } |
| 671 | |
| 672 | /* |
| 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). |
| 680 | */ |
| 681 | static void handle_timeout(struct work_struct *work) |
| 682 | { |
| 683 | struct ceph_osd_client *osdc = |
| 684 | container_of(work, struct ceph_osd_client, timeout_work.work); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 685 | struct ceph_osd_request *req, *last_req = NULL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 686 | struct ceph_osd *osd; |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 687 | unsigned long timeout = osdc->client->mount_args->osd_timeout * HZ; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 688 | unsigned long keepalive = |
| 689 | osdc->client->mount_args->osd_keepalive_timeout * HZ; |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 690 | unsigned long last_stamp = 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 691 | struct rb_node *p; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 692 | struct list_head slow_osds; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 693 | |
| 694 | dout("timeout\n"); |
| 695 | down_read(&osdc->map_sem); |
| 696 | |
| 697 | ceph_monc_request_next_osdmap(&osdc->client->monc); |
| 698 | |
| 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); |
| 702 | |
| 703 | if (req->r_resend) { |
| 704 | int err; |
| 705 | |
| 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; |
| 713 | } |
| 714 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 715 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 716 | /* |
| 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. |
| 722 | */ |
Sage Weil | f26e681 | 2010-04-21 11:09:38 -0700 | [diff] [blame] | 723 | while (timeout && !list_empty(&osdc->req_lru)) { |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 724 | req = list_entry(osdc->req_lru.next, struct ceph_osd_request, |
| 725 | r_req_lru_item); |
| 726 | |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 727 | if (time_before(jiffies, req->r_stamp + timeout)) |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 728 | break; |
| 729 | |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 730 | BUG_ON(req == last_req && req->r_stamp == last_stamp); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 731 | last_req = req; |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 732 | last_stamp = req->r_stamp; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 733 | |
| 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); |
| 739 | } |
| 740 | |
| 741 | /* |
| 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). |
| 745 | */ |
| 746 | INIT_LIST_HEAD(&slow_osds); |
| 747 | list_for_each_entry(req, &osdc->req_lru, r_req_lru_item) { |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 748 | if (time_before(jiffies, req->r_stamp + keepalive)) |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 749 | break; |
| 750 | |
| 751 | osd = req->r_osd; |
| 752 | BUG_ON(!osd); |
| 753 | dout(" tid %llu is slow, will send keepalive on osd%d\n", |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 754 | req->r_tid, osd->o_osd); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 755 | list_move_tail(&osd->o_keepalive_item, &slow_osds); |
| 756 | } |
| 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); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 761 | ceph_con_keepalive(&osd->o_con); |
| 762 | } |
| 763 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 764 | __schedule_osd_timeout(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 765 | mutex_unlock(&osdc->request_mutex); |
| 766 | |
| 767 | up_read(&osdc->map_sem); |
| 768 | } |
| 769 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 770 | static void handle_osds_timeout(struct work_struct *work) |
| 771 | { |
| 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; |
| 777 | |
| 778 | dout("osds timeout\n"); |
| 779 | down_read(&osdc->map_sem); |
| 780 | remove_old_osds(osdc, 0); |
| 781 | up_read(&osdc->map_sem); |
| 782 | |
| 783 | schedule_delayed_work(&osdc->osds_timeout_work, |
| 784 | round_jiffies_relative(delay)); |
| 785 | } |
| 786 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 787 | /* |
| 788 | * handle osd op reply. either call the callback if it is specified, |
| 789 | * or do the completion to wake up the waiting thread. |
| 790 | */ |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 791 | static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, |
| 792 | struct ceph_connection *con) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 793 | { |
| 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; |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 798 | s32 result; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 799 | |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame] | 800 | tid = le64_to_cpu(msg->hdr.tid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 801 | if (msg->front.iov_len < sizeof(*rhead)) |
| 802 | goto bad; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 803 | numops = le32_to_cpu(rhead->num_ops); |
| 804 | object_len = le32_to_cpu(rhead->object_len); |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 805 | result = le32_to_cpu(rhead->result); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 806 | if (msg->front.iov_len != sizeof(*rhead) + object_len + |
| 807 | numops * sizeof(struct ceph_osd_op)) |
| 808 | goto bad; |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 809 | dout("handle_reply %p tid %llu result %d\n", msg, tid, (int)result); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 810 | |
| 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; |
| 818 | } |
| 819 | ceph_osdc_get_request(req); |
| 820 | flags = le32_to_cpu(rhead->flags); |
| 821 | |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 822 | /* |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 823 | * if this connection filled our message, drop our reference now, to |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 824 | * avoid a (safe but slower) revoke later. |
| 825 | */ |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 826 | if (req->r_con_filling_msg == con && req->r_reply == msg) { |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 827 | dout(" dropping con_filling_msg ref %p\n", con); |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 828 | req->r_con_filling_msg = NULL; |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 829 | ceph_con_put(con); |
| 830 | } |
| 831 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 832 | if (!req->r_got_reply) { |
| 833 | unsigned bytes; |
| 834 | |
| 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; |
| 841 | |
| 842 | /* in case this is a write and we need to replay, */ |
| 843 | req->r_reassert_version = rhead->reassert_version; |
| 844 | |
| 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); |
Sage Weil | 34b43a5 | 2009-12-01 12:23:54 -0800 | [diff] [blame] | 848 | mutex_unlock(&osdc->request_mutex); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 849 | goto done; |
| 850 | } |
| 851 | |
| 852 | dout("handle_reply tid %llu flags %d\n", tid, flags); |
| 853 | |
| 854 | /* either this is a read, or we got the safe response */ |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 855 | if (result < 0 || |
| 856 | (flags & CEPH_OSD_FLAG_ONDISK) || |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 857 | ((flags & CEPH_OSD_FLAG_WRITE) == 0)) |
| 858 | __unregister_request(osdc, req); |
| 859 | |
| 860 | mutex_unlock(&osdc->request_mutex); |
| 861 | |
| 862 | if (req->r_callback) |
| 863 | req->r_callback(req, msg); |
| 864 | else |
Yehuda Sadeh | 03066f2 | 2010-07-27 13:11:08 -0700 | [diff] [blame] | 865 | complete_all(&req->r_completion); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 866 | |
| 867 | if (flags & CEPH_OSD_FLAG_ONDISK) { |
| 868 | if (req->r_safe_callback) |
| 869 | req->r_safe_callback(req, msg); |
Yehuda Sadeh | 03066f2 | 2010-07-27 13:11:08 -0700 | [diff] [blame] | 870 | complete_all(&req->r_safe_completion); /* fsync waiter */ |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | done: |
| 874 | ceph_osdc_put_request(req); |
| 875 | return; |
| 876 | |
| 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)); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 881 | ceph_msg_dump(msg); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 885 | static int __kick_requests(struct ceph_osd_client *osdc, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 886 | struct ceph_osd *kickosd) |
| 887 | { |
| 888 | struct ceph_osd_request *req; |
| 889 | struct rb_node *p, *n; |
| 890 | int needmap = 0; |
| 891 | int err; |
| 892 | |
| 893 | dout("kick_requests osd%d\n", kickosd ? kickosd->o_osd : -1); |
Sage Weil | 153a008 | 2010-02-15 12:11:51 -0800 | [diff] [blame] | 894 | if (kickosd) { |
Sage Weil | 87b315a | 2010-03-22 14:51:18 -0700 | [diff] [blame] | 895 | err = __reset_osd(osdc, kickosd); |
| 896 | if (err == -EAGAIN) |
| 897 | return 1; |
Sage Weil | 153a008 | 2010-02-15 12:11:51 -0800 | [diff] [blame] | 898 | } else { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 899 | for (p = rb_first(&osdc->osds); p; p = n) { |
| 900 | struct ceph_osd *osd = |
| 901 | rb_entry(p, struct ceph_osd, o_node); |
| 902 | |
| 903 | n = rb_next(p); |
| 904 | if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) || |
Sage Weil | 103e2d3 | 2010-01-07 16:12:36 -0800 | [diff] [blame] | 905 | memcmp(&osd->o_con.peer_addr, |
| 906 | ceph_osd_addr(osdc->osdmap, |
| 907 | osd->o_osd), |
| 908 | sizeof(struct ceph_entity_addr)) != 0) |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 909 | __reset_osd(osdc, osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
| 913 | for (p = rb_first(&osdc->requests); p; p = rb_next(p)) { |
| 914 | req = rb_entry(p, struct ceph_osd_request, r_node); |
| 915 | |
| 916 | if (req->r_resend) { |
| 917 | dout(" r_resend set on tid %llu\n", req->r_tid); |
Sage Weil | 266673d | 2009-10-09 10:31:32 -0700 | [diff] [blame] | 918 | __cancel_request(req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 919 | goto kick; |
| 920 | } |
Sage Weil | 266673d | 2009-10-09 10:31:32 -0700 | [diff] [blame] | 921 | if (req->r_osd && kickosd == req->r_osd) { |
| 922 | __cancel_request(req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 923 | goto kick; |
Sage Weil | 266673d | 2009-10-09 10:31:32 -0700 | [diff] [blame] | 924 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 925 | |
| 926 | err = __map_osds(osdc, req); |
| 927 | if (err == 0) |
| 928 | continue; /* no change */ |
| 929 | if (err < 0) { |
| 930 | /* |
| 931 | * FIXME: really, we should set the request |
| 932 | * error and fail if this isn't a 'nofail' |
| 933 | * request, but that's a fair bit more |
| 934 | * complicated to do. So retry! |
| 935 | */ |
| 936 | dout(" setting r_resend on %llu\n", req->r_tid); |
| 937 | req->r_resend = true; |
| 938 | continue; |
| 939 | } |
| 940 | if (req->r_osd == NULL) { |
| 941 | dout("tid %llu maps to no valid osd\n", req->r_tid); |
| 942 | needmap++; /* request a newer map */ |
| 943 | continue; |
| 944 | } |
| 945 | |
| 946 | kick: |
Sage Weil | c1ea882 | 2009-10-08 16:55:47 -0700 | [diff] [blame] | 947 | dout("kicking %p tid %llu osd%d\n", req, req->r_tid, |
Sage Weil | 12eadc1 | 2010-03-15 22:20:39 -0700 | [diff] [blame] | 948 | req->r_osd ? req->r_osd->o_osd : -1); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 949 | req->r_flags |= CEPH_OSD_FLAG_RETRY; |
| 950 | err = __send_request(osdc, req); |
| 951 | if (err) { |
| 952 | dout(" setting r_resend on %llu\n", req->r_tid); |
| 953 | req->r_resend = true; |
| 954 | } |
| 955 | } |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 956 | |
| 957 | return needmap; |
| 958 | } |
| 959 | |
| 960 | /* |
| 961 | * Resubmit osd requests whose osd or osd address has changed. Request |
| 962 | * a new osd map if osds are down, or we are otherwise unable to determine |
| 963 | * how to direct a request. |
| 964 | * |
| 965 | * Close connections to down osds. |
| 966 | * |
| 967 | * If @who is specified, resubmit requests for that specific osd. |
| 968 | * |
| 969 | * Caller should hold map_sem for read and request_mutex. |
| 970 | */ |
| 971 | static void kick_requests(struct ceph_osd_client *osdc, |
| 972 | struct ceph_osd *kickosd) |
| 973 | { |
| 974 | int needmap; |
| 975 | |
| 976 | mutex_lock(&osdc->request_mutex); |
| 977 | needmap = __kick_requests(osdc, kickosd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 978 | mutex_unlock(&osdc->request_mutex); |
| 979 | |
| 980 | if (needmap) { |
| 981 | dout("%d requests for down osds, need new map\n", needmap); |
| 982 | ceph_monc_request_next_osdmap(&osdc->client->monc); |
| 983 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 984 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 985 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 986 | /* |
| 987 | * Process updated osd map. |
| 988 | * |
| 989 | * The message contains any number of incremental and full maps, normally |
| 990 | * indicating some sort of topology change in the cluster. Kick requests |
| 991 | * off to different OSDs as needed. |
| 992 | */ |
| 993 | void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg) |
| 994 | { |
| 995 | void *p, *end, *next; |
| 996 | u32 nr_maps, maplen; |
| 997 | u32 epoch; |
| 998 | struct ceph_osdmap *newmap = NULL, *oldmap; |
| 999 | int err; |
| 1000 | struct ceph_fsid fsid; |
| 1001 | |
| 1002 | dout("handle_map have %u\n", osdc->osdmap ? osdc->osdmap->epoch : 0); |
| 1003 | p = msg->front.iov_base; |
| 1004 | end = p + msg->front.iov_len; |
| 1005 | |
| 1006 | /* verify fsid */ |
| 1007 | ceph_decode_need(&p, end, sizeof(fsid), bad); |
| 1008 | ceph_decode_copy(&p, &fsid, sizeof(fsid)); |
Sage Weil | 0743304 | 2009-11-18 16:50:41 -0800 | [diff] [blame] | 1009 | if (ceph_check_fsid(osdc->client, &fsid) < 0) |
| 1010 | return; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1011 | |
| 1012 | down_write(&osdc->map_sem); |
| 1013 | |
| 1014 | /* incremental maps */ |
| 1015 | ceph_decode_32_safe(&p, end, nr_maps, bad); |
| 1016 | dout(" %d inc maps\n", nr_maps); |
| 1017 | while (nr_maps > 0) { |
| 1018 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 1019 | epoch = ceph_decode_32(&p); |
| 1020 | maplen = ceph_decode_32(&p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1021 | ceph_decode_need(&p, end, maplen, bad); |
| 1022 | next = p + maplen; |
| 1023 | if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) { |
| 1024 | dout("applying incremental map %u len %d\n", |
| 1025 | epoch, maplen); |
| 1026 | newmap = osdmap_apply_incremental(&p, next, |
| 1027 | osdc->osdmap, |
| 1028 | osdc->client->msgr); |
| 1029 | if (IS_ERR(newmap)) { |
| 1030 | err = PTR_ERR(newmap); |
| 1031 | goto bad; |
| 1032 | } |
Sage Weil | 30dc638 | 2009-12-21 14:49:37 -0800 | [diff] [blame] | 1033 | BUG_ON(!newmap); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1034 | if (newmap != osdc->osdmap) { |
| 1035 | ceph_osdmap_destroy(osdc->osdmap); |
| 1036 | osdc->osdmap = newmap; |
| 1037 | } |
| 1038 | } else { |
| 1039 | dout("ignoring incremental map %u len %d\n", |
| 1040 | epoch, maplen); |
| 1041 | } |
| 1042 | p = next; |
| 1043 | nr_maps--; |
| 1044 | } |
| 1045 | if (newmap) |
| 1046 | goto done; |
| 1047 | |
| 1048 | /* full maps */ |
| 1049 | ceph_decode_32_safe(&p, end, nr_maps, bad); |
| 1050 | dout(" %d full maps\n", nr_maps); |
| 1051 | while (nr_maps) { |
| 1052 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 1053 | epoch = ceph_decode_32(&p); |
| 1054 | maplen = ceph_decode_32(&p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1055 | ceph_decode_need(&p, end, maplen, bad); |
| 1056 | if (nr_maps > 1) { |
| 1057 | dout("skipping non-latest full map %u len %d\n", |
| 1058 | epoch, maplen); |
| 1059 | } else if (osdc->osdmap && osdc->osdmap->epoch >= epoch) { |
| 1060 | dout("skipping full map %u len %d, " |
| 1061 | "older than our %u\n", epoch, maplen, |
| 1062 | osdc->osdmap->epoch); |
| 1063 | } else { |
| 1064 | dout("taking full map %u len %d\n", epoch, maplen); |
| 1065 | newmap = osdmap_decode(&p, p+maplen); |
| 1066 | if (IS_ERR(newmap)) { |
| 1067 | err = PTR_ERR(newmap); |
| 1068 | goto bad; |
| 1069 | } |
Sage Weil | 30dc638 | 2009-12-21 14:49:37 -0800 | [diff] [blame] | 1070 | BUG_ON(!newmap); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1071 | oldmap = osdc->osdmap; |
| 1072 | osdc->osdmap = newmap; |
| 1073 | if (oldmap) |
| 1074 | ceph_osdmap_destroy(oldmap); |
| 1075 | } |
| 1076 | p += maplen; |
| 1077 | nr_maps--; |
| 1078 | } |
| 1079 | |
| 1080 | done: |
| 1081 | downgrade_write(&osdc->map_sem); |
| 1082 | ceph_monc_got_osdmap(&osdc->client->monc, osdc->osdmap->epoch); |
| 1083 | if (newmap) |
| 1084 | kick_requests(osdc, NULL); |
| 1085 | up_read(&osdc->map_sem); |
Yehuda Sadeh | 03066f2 | 2010-07-27 13:11:08 -0700 | [diff] [blame] | 1086 | wake_up_all(&osdc->client->auth_wq); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1087 | return; |
| 1088 | |
| 1089 | bad: |
| 1090 | pr_err("osdc handle_map corrupt msg\n"); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 1091 | ceph_msg_dump(msg); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1092 | up_write(&osdc->map_sem); |
| 1093 | return; |
| 1094 | } |
| 1095 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1096 | /* |
| 1097 | * Register request, send initial attempt. |
| 1098 | */ |
| 1099 | int ceph_osdc_start_request(struct ceph_osd_client *osdc, |
| 1100 | struct ceph_osd_request *req, |
| 1101 | bool nofail) |
| 1102 | { |
Sage Weil | c1ea882 | 2009-10-08 16:55:47 -0700 | [diff] [blame] | 1103 | int rc = 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1104 | |
| 1105 | req->r_request->pages = req->r_pages; |
| 1106 | req->r_request->nr_pages = req->r_num_pages; |
| 1107 | |
| 1108 | register_request(osdc, req); |
| 1109 | |
| 1110 | down_read(&osdc->map_sem); |
| 1111 | mutex_lock(&osdc->request_mutex); |
Sage Weil | c1ea882 | 2009-10-08 16:55:47 -0700 | [diff] [blame] | 1112 | /* |
| 1113 | * a racing kick_requests() may have sent the message for us |
| 1114 | * while we dropped request_mutex above, so only send now if |
| 1115 | * the request still han't been touched yet. |
| 1116 | */ |
| 1117 | if (req->r_sent == 0) { |
| 1118 | rc = __send_request(osdc, req); |
| 1119 | if (rc) { |
| 1120 | if (nofail) { |
| 1121 | dout("osdc_start_request failed send, " |
| 1122 | " marking %lld\n", req->r_tid); |
| 1123 | req->r_resend = true; |
| 1124 | rc = 0; |
| 1125 | } else { |
| 1126 | __unregister_request(osdc, req); |
| 1127 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | mutex_unlock(&osdc->request_mutex); |
| 1131 | up_read(&osdc->map_sem); |
| 1132 | return rc; |
| 1133 | } |
| 1134 | |
| 1135 | /* |
| 1136 | * wait for a request to complete |
| 1137 | */ |
| 1138 | int ceph_osdc_wait_request(struct ceph_osd_client *osdc, |
| 1139 | struct ceph_osd_request *req) |
| 1140 | { |
| 1141 | int rc; |
| 1142 | |
| 1143 | rc = wait_for_completion_interruptible(&req->r_completion); |
| 1144 | if (rc < 0) { |
| 1145 | mutex_lock(&osdc->request_mutex); |
| 1146 | __cancel_request(req); |
Sage Weil | 529cfcc | 2009-12-22 10:29:39 -0800 | [diff] [blame] | 1147 | __unregister_request(osdc, req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1148 | mutex_unlock(&osdc->request_mutex); |
Sage Weil | 529cfcc | 2009-12-22 10:29:39 -0800 | [diff] [blame] | 1149 | dout("wait_request tid %llu canceled/timed out\n", req->r_tid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1150 | return rc; |
| 1151 | } |
| 1152 | |
| 1153 | dout("wait_request tid %llu result %d\n", req->r_tid, req->r_result); |
| 1154 | return req->r_result; |
| 1155 | } |
| 1156 | |
| 1157 | /* |
| 1158 | * sync - wait for all in-flight requests to flush. avoid starvation. |
| 1159 | */ |
| 1160 | void ceph_osdc_sync(struct ceph_osd_client *osdc) |
| 1161 | { |
| 1162 | struct ceph_osd_request *req; |
| 1163 | u64 last_tid, next_tid = 0; |
| 1164 | |
| 1165 | mutex_lock(&osdc->request_mutex); |
| 1166 | last_tid = osdc->last_tid; |
| 1167 | while (1) { |
| 1168 | req = __lookup_request_ge(osdc, next_tid); |
| 1169 | if (!req) |
| 1170 | break; |
| 1171 | if (req->r_tid > last_tid) |
| 1172 | break; |
| 1173 | |
| 1174 | next_tid = req->r_tid + 1; |
| 1175 | if ((req->r_flags & CEPH_OSD_FLAG_WRITE) == 0) |
| 1176 | continue; |
| 1177 | |
| 1178 | ceph_osdc_get_request(req); |
| 1179 | mutex_unlock(&osdc->request_mutex); |
| 1180 | dout("sync waiting on tid %llu (last is %llu)\n", |
| 1181 | req->r_tid, last_tid); |
| 1182 | wait_for_completion(&req->r_safe_completion); |
| 1183 | mutex_lock(&osdc->request_mutex); |
| 1184 | ceph_osdc_put_request(req); |
| 1185 | } |
| 1186 | mutex_unlock(&osdc->request_mutex); |
| 1187 | dout("sync done (thru tid %llu)\n", last_tid); |
| 1188 | } |
| 1189 | |
| 1190 | /* |
| 1191 | * init, shutdown |
| 1192 | */ |
| 1193 | int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client) |
| 1194 | { |
| 1195 | int err; |
| 1196 | |
| 1197 | dout("init\n"); |
| 1198 | osdc->client = client; |
| 1199 | osdc->osdmap = NULL; |
| 1200 | init_rwsem(&osdc->map_sem); |
| 1201 | init_completion(&osdc->map_waiters); |
| 1202 | osdc->last_requested_map = 0; |
| 1203 | mutex_init(&osdc->request_mutex); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1204 | osdc->last_tid = 0; |
| 1205 | osdc->osds = RB_ROOT; |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1206 | INIT_LIST_HEAD(&osdc->osd_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1207 | osdc->requests = RB_ROOT; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1208 | INIT_LIST_HEAD(&osdc->req_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1209 | osdc->num_requests = 0; |
| 1210 | INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1211 | INIT_DELAYED_WORK(&osdc->osds_timeout_work, handle_osds_timeout); |
| 1212 | |
| 1213 | schedule_delayed_work(&osdc->osds_timeout_work, |
| 1214 | round_jiffies_relative(osdc->client->mount_args->osd_idle_ttl * HZ)); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1215 | |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1216 | err = -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1217 | osdc->req_mempool = mempool_create_kmalloc_pool(10, |
| 1218 | sizeof(struct ceph_osd_request)); |
| 1219 | if (!osdc->req_mempool) |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1220 | goto out; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1221 | |
Sage Weil | 4f48280 | 2010-04-24 09:56:35 -0700 | [diff] [blame] | 1222 | err = ceph_msgpool_init(&osdc->msgpool_op, OSD_OP_FRONT_LEN, 10, true, |
| 1223 | "osd_op"); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1224 | if (err < 0) |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1225 | goto out_mempool; |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1226 | err = ceph_msgpool_init(&osdc->msgpool_op_reply, |
Sage Weil | 4f48280 | 2010-04-24 09:56:35 -0700 | [diff] [blame] | 1227 | OSD_OPREPLY_FRONT_LEN, 10, true, |
| 1228 | "osd_op_reply"); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1229 | if (err < 0) |
| 1230 | goto out_msgpool; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1231 | return 0; |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1232 | |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1233 | out_msgpool: |
| 1234 | ceph_msgpool_destroy(&osdc->msgpool_op); |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1235 | out_mempool: |
| 1236 | mempool_destroy(osdc->req_mempool); |
| 1237 | out: |
| 1238 | return err; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | void ceph_osdc_stop(struct ceph_osd_client *osdc) |
| 1242 | { |
| 1243 | cancel_delayed_work_sync(&osdc->timeout_work); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1244 | cancel_delayed_work_sync(&osdc->osds_timeout_work); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1245 | if (osdc->osdmap) { |
| 1246 | ceph_osdmap_destroy(osdc->osdmap); |
| 1247 | osdc->osdmap = NULL; |
| 1248 | } |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1249 | remove_old_osds(osdc, 1); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1250 | mempool_destroy(osdc->req_mempool); |
| 1251 | ceph_msgpool_destroy(&osdc->msgpool_op); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1252 | ceph_msgpool_destroy(&osdc->msgpool_op_reply); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | /* |
| 1256 | * Read some contiguous pages. If we cross a stripe boundary, shorten |
| 1257 | * *plen. Return number of bytes read, or error. |
| 1258 | */ |
| 1259 | int ceph_osdc_readpages(struct ceph_osd_client *osdc, |
| 1260 | struct ceph_vino vino, struct ceph_file_layout *layout, |
| 1261 | u64 off, u64 *plen, |
| 1262 | u32 truncate_seq, u64 truncate_size, |
| 1263 | struct page **pages, int num_pages) |
| 1264 | { |
| 1265 | struct ceph_osd_request *req; |
| 1266 | int rc = 0; |
| 1267 | |
| 1268 | dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino, |
| 1269 | vino.snap, off, *plen); |
| 1270 | req = ceph_osdc_new_request(osdc, layout, vino, off, plen, |
| 1271 | CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ, |
| 1272 | NULL, 0, truncate_seq, truncate_size, NULL, |
| 1273 | false, 1); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1274 | if (!req) |
| 1275 | return -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1276 | |
| 1277 | /* it may be a short read due to an object boundary */ |
| 1278 | req->r_pages = pages; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1279 | |
| 1280 | dout("readpages final extent is %llu~%llu (%d pages)\n", |
| 1281 | off, *plen, req->r_num_pages); |
| 1282 | |
| 1283 | rc = ceph_osdc_start_request(osdc, req, false); |
| 1284 | if (!rc) |
| 1285 | rc = ceph_osdc_wait_request(osdc, req); |
| 1286 | |
| 1287 | ceph_osdc_put_request(req); |
| 1288 | dout("readpages result %d\n", rc); |
| 1289 | return rc; |
| 1290 | } |
| 1291 | |
| 1292 | /* |
| 1293 | * do a synchronous write on N pages |
| 1294 | */ |
| 1295 | int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino, |
| 1296 | struct ceph_file_layout *layout, |
| 1297 | struct ceph_snap_context *snapc, |
| 1298 | u64 off, u64 len, |
| 1299 | u32 truncate_seq, u64 truncate_size, |
| 1300 | struct timespec *mtime, |
| 1301 | struct page **pages, int num_pages, |
| 1302 | int flags, int do_sync, bool nofail) |
| 1303 | { |
| 1304 | struct ceph_osd_request *req; |
| 1305 | int rc = 0; |
| 1306 | |
| 1307 | BUG_ON(vino.snap != CEPH_NOSNAP); |
| 1308 | req = ceph_osdc_new_request(osdc, layout, vino, off, &len, |
| 1309 | CEPH_OSD_OP_WRITE, |
| 1310 | flags | CEPH_OSD_FLAG_ONDISK | |
| 1311 | CEPH_OSD_FLAG_WRITE, |
| 1312 | snapc, do_sync, |
| 1313 | truncate_seq, truncate_size, mtime, |
| 1314 | nofail, 1); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1315 | if (!req) |
| 1316 | return -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1317 | |
| 1318 | /* it may be a short write due to an object boundary */ |
| 1319 | req->r_pages = pages; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1320 | dout("writepages %llu~%llu (%d pages)\n", off, len, |
| 1321 | req->r_num_pages); |
| 1322 | |
| 1323 | rc = ceph_osdc_start_request(osdc, req, nofail); |
| 1324 | if (!rc) |
| 1325 | rc = ceph_osdc_wait_request(osdc, req); |
| 1326 | |
| 1327 | ceph_osdc_put_request(req); |
| 1328 | if (rc == 0) |
| 1329 | rc = len; |
| 1330 | dout("writepages result %d\n", rc); |
| 1331 | return rc; |
| 1332 | } |
| 1333 | |
| 1334 | /* |
| 1335 | * handle incoming message |
| 1336 | */ |
| 1337 | static void dispatch(struct ceph_connection *con, struct ceph_msg *msg) |
| 1338 | { |
| 1339 | struct ceph_osd *osd = con->private; |
Julia Lawall | 32c895e | 2009-11-21 16:53:16 +0100 | [diff] [blame] | 1340 | struct ceph_osd_client *osdc; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1341 | int type = le16_to_cpu(msg->hdr.type); |
| 1342 | |
| 1343 | if (!osd) |
Sage Weil | 4a32f93 | 2010-06-13 10:27:53 -0700 | [diff] [blame] | 1344 | goto out; |
Julia Lawall | 32c895e | 2009-11-21 16:53:16 +0100 | [diff] [blame] | 1345 | osdc = osd->o_osdc; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1346 | |
| 1347 | switch (type) { |
| 1348 | case CEPH_MSG_OSD_MAP: |
| 1349 | ceph_osdc_handle_map(osdc, msg); |
| 1350 | break; |
| 1351 | case CEPH_MSG_OSD_OPREPLY: |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 1352 | handle_reply(osdc, msg, con); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1353 | break; |
| 1354 | |
| 1355 | default: |
| 1356 | pr_err("received unknown message type %d %s\n", type, |
| 1357 | ceph_msg_type_name(type)); |
| 1358 | } |
Sage Weil | 4a32f93 | 2010-06-13 10:27:53 -0700 | [diff] [blame] | 1359 | out: |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1360 | ceph_msg_put(msg); |
| 1361 | } |
| 1362 | |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1363 | /* |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 1364 | * lookup and return message for incoming reply. set up reply message |
| 1365 | * pages. |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1366 | */ |
| 1367 | static struct ceph_msg *get_reply(struct ceph_connection *con, |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 1368 | struct ceph_msg_header *hdr, |
| 1369 | int *skip) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1370 | { |
| 1371 | struct ceph_osd *osd = con->private; |
| 1372 | struct ceph_osd_client *osdc = osd->o_osdc; |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 1373 | struct ceph_msg *m; |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1374 | struct ceph_osd_request *req; |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1375 | int front = le32_to_cpu(hdr->front_len); |
| 1376 | int data_len = le32_to_cpu(hdr->data_len); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1377 | u64 tid; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1378 | |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1379 | tid = le64_to_cpu(hdr->tid); |
| 1380 | mutex_lock(&osdc->request_mutex); |
| 1381 | req = __lookup_request(osdc, tid); |
| 1382 | if (!req) { |
| 1383 | *skip = 1; |
| 1384 | m = NULL; |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1385 | pr_info("get_reply unknown tid %llu from osd%d\n", tid, |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1386 | osd->o_osd); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1387 | goto out; |
| 1388 | } |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1389 | |
| 1390 | if (req->r_con_filling_msg) { |
| 1391 | dout("get_reply revoking msg %p from old con %p\n", |
| 1392 | req->r_reply, req->r_con_filling_msg); |
| 1393 | ceph_con_revoke_message(req->r_con_filling_msg, req->r_reply); |
| 1394 | ceph_con_put(req->r_con_filling_msg); |
Sage Weil | 6f46cb2 | 2010-03-24 21:30:19 -0700 | [diff] [blame] | 1395 | req->r_con_filling_msg = NULL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1396 | } |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 1397 | |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1398 | if (front > req->r_reply->front.iov_len) { |
| 1399 | pr_warning("get_reply front %d > preallocated %d\n", |
| 1400 | front, (int)req->r_reply->front.iov_len); |
Yehuda Sadeh | 34d2376 | 2010-04-06 14:33:58 -0700 | [diff] [blame] | 1401 | m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front, GFP_NOFS); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1402 | if (!m) |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1403 | goto out; |
| 1404 | ceph_msg_put(req->r_reply); |
| 1405 | req->r_reply = m; |
| 1406 | } |
| 1407 | m = ceph_msg_get(req->r_reply); |
| 1408 | |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1409 | if (data_len > 0) { |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 1410 | unsigned data_off = le16_to_cpu(hdr->data_off); |
| 1411 | int want = calc_pages_for(data_off & ~PAGE_MASK, data_len); |
| 1412 | |
| 1413 | if (unlikely(req->r_num_pages < want)) { |
| 1414 | pr_warning("tid %lld reply %d > expected %d pages\n", |
| 1415 | tid, want, m->nr_pages); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1416 | *skip = 1; |
| 1417 | ceph_msg_put(m); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1418 | m = NULL; |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 1419 | goto out; |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1420 | } |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 1421 | m->pages = req->r_pages; |
| 1422 | m->nr_pages = req->r_num_pages; |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1423 | } |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1424 | *skip = 0; |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1425 | req->r_con_filling_msg = ceph_con_get(con); |
| 1426 | dout("get_reply tid %lld %p\n", tid, m); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1427 | |
| 1428 | out: |
| 1429 | mutex_unlock(&osdc->request_mutex); |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 1430 | return m; |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1431 | |
| 1432 | } |
| 1433 | |
| 1434 | static struct ceph_msg *alloc_msg(struct ceph_connection *con, |
| 1435 | struct ceph_msg_header *hdr, |
| 1436 | int *skip) |
| 1437 | { |
| 1438 | struct ceph_osd *osd = con->private; |
| 1439 | int type = le16_to_cpu(hdr->type); |
| 1440 | int front = le32_to_cpu(hdr->front_len); |
| 1441 | |
| 1442 | switch (type) { |
| 1443 | case CEPH_MSG_OSD_MAP: |
Yehuda Sadeh | 34d2376 | 2010-04-06 14:33:58 -0700 | [diff] [blame] | 1444 | return ceph_msg_new(type, front, GFP_NOFS); |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1445 | case CEPH_MSG_OSD_OPREPLY: |
| 1446 | return get_reply(con, hdr, skip); |
| 1447 | default: |
| 1448 | pr_info("alloc_msg unexpected msg type %d from osd%d\n", type, |
| 1449 | osd->o_osd); |
| 1450 | *skip = 1; |
| 1451 | return NULL; |
| 1452 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | /* |
| 1456 | * Wrappers to refcount containing ceph_osd struct |
| 1457 | */ |
| 1458 | static struct ceph_connection *get_osd_con(struct ceph_connection *con) |
| 1459 | { |
| 1460 | struct ceph_osd *osd = con->private; |
| 1461 | if (get_osd(osd)) |
| 1462 | return con; |
| 1463 | return NULL; |
| 1464 | } |
| 1465 | |
| 1466 | static void put_osd_con(struct ceph_connection *con) |
| 1467 | { |
| 1468 | struct ceph_osd *osd = con->private; |
| 1469 | put_osd(osd); |
| 1470 | } |
| 1471 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 1472 | /* |
| 1473 | * authentication |
| 1474 | */ |
| 1475 | static int get_authorizer(struct ceph_connection *con, |
Sage Weil | 213c99e | 2010-08-03 10:25:11 -0700 | [diff] [blame] | 1476 | void **buf, int *len, int *proto, |
| 1477 | void **reply_buf, int *reply_len, int force_new) |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 1478 | { |
| 1479 | struct ceph_osd *o = con->private; |
| 1480 | struct ceph_osd_client *osdc = o->o_osdc; |
| 1481 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
| 1482 | int ret = 0; |
| 1483 | |
| 1484 | if (force_new && o->o_authorizer) { |
| 1485 | ac->ops->destroy_authorizer(ac, o->o_authorizer); |
| 1486 | o->o_authorizer = NULL; |
| 1487 | } |
| 1488 | if (o->o_authorizer == NULL) { |
| 1489 | ret = ac->ops->create_authorizer( |
| 1490 | ac, CEPH_ENTITY_TYPE_OSD, |
| 1491 | &o->o_authorizer, |
| 1492 | &o->o_authorizer_buf, |
| 1493 | &o->o_authorizer_buf_len, |
| 1494 | &o->o_authorizer_reply_buf, |
| 1495 | &o->o_authorizer_reply_buf_len); |
| 1496 | if (ret) |
Sage Weil | 213c99e | 2010-08-03 10:25:11 -0700 | [diff] [blame] | 1497 | return ret; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | *proto = ac->protocol; |
| 1501 | *buf = o->o_authorizer_buf; |
| 1502 | *len = o->o_authorizer_buf_len; |
| 1503 | *reply_buf = o->o_authorizer_reply_buf; |
| 1504 | *reply_len = o->o_authorizer_reply_buf_len; |
| 1505 | return 0; |
| 1506 | } |
| 1507 | |
| 1508 | |
| 1509 | static int verify_authorizer_reply(struct ceph_connection *con, int len) |
| 1510 | { |
| 1511 | struct ceph_osd *o = con->private; |
| 1512 | struct ceph_osd_client *osdc = o->o_osdc; |
| 1513 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
| 1514 | |
| 1515 | return ac->ops->verify_authorizer_reply(ac, o->o_authorizer, len); |
| 1516 | } |
| 1517 | |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 1518 | static int invalidate_authorizer(struct ceph_connection *con) |
| 1519 | { |
| 1520 | struct ceph_osd *o = con->private; |
| 1521 | struct ceph_osd_client *osdc = o->o_osdc; |
| 1522 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
| 1523 | |
| 1524 | if (ac->ops->invalidate_authorizer) |
| 1525 | ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD); |
| 1526 | |
| 1527 | return ceph_monc_validate_auth(&osdc->client->monc); |
| 1528 | } |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 1529 | |
Tobias Klauser | 9e32789 | 2010-05-20 10:40:19 +0200 | [diff] [blame] | 1530 | static const struct ceph_connection_operations osd_con_ops = { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1531 | .get = get_osd_con, |
| 1532 | .put = put_osd_con, |
| 1533 | .dispatch = dispatch, |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 1534 | .get_authorizer = get_authorizer, |
| 1535 | .verify_authorizer_reply = verify_authorizer_reply, |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 1536 | .invalidate_authorizer = invalidate_authorizer, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1537 | .alloc_msg = alloc_msg, |
Sage Weil | 81b024e | 2009-10-09 10:29:18 -0700 | [diff] [blame] | 1538 | .fault = osd_reset, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1539 | }; |