Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1 | #include <linux/ceph/ceph_debug.h> |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 3 | #include <linux/module.h> |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4 | #include <linux/err.h> |
| 5 | #include <linux/highmem.h> |
| 6 | #include <linux/mm.h> |
| 7 | #include <linux/pagemap.h> |
| 8 | #include <linux/slab.h> |
| 9 | #include <linux/uaccess.h> |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 10 | #ifdef CONFIG_BLOCK |
| 11 | #include <linux/bio.h> |
| 12 | #endif |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 13 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 14 | #include <linux/ceph/libceph.h> |
| 15 | #include <linux/ceph/osd_client.h> |
| 16 | #include <linux/ceph/messenger.h> |
| 17 | #include <linux/ceph/decode.h> |
| 18 | #include <linux/ceph/auth.h> |
| 19 | #include <linux/ceph/pagelist.h> |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 20 | |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 21 | #define OSD_OP_FRONT_LEN 4096 |
| 22 | #define OSD_OPREPLY_FRONT_LEN 512 |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 23 | |
Tobias Klauser | 9e32789 | 2010-05-20 10:40:19 +0200 | [diff] [blame] | 24 | static const struct ceph_connection_operations osd_con_ops; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 25 | static int __kick_requests(struct ceph_osd_client *osdc, |
| 26 | struct ceph_osd *kickosd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 27 | |
| 28 | static void kick_requests(struct ceph_osd_client *osdc, struct ceph_osd *osd); |
| 29 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 30 | static int op_needs_trail(int op) |
| 31 | { |
| 32 | switch (op) { |
| 33 | case CEPH_OSD_OP_GETXATTR: |
| 34 | case CEPH_OSD_OP_SETXATTR: |
| 35 | case CEPH_OSD_OP_CMPXATTR: |
| 36 | case CEPH_OSD_OP_CALL: |
| 37 | return 1; |
| 38 | default: |
| 39 | return 0; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | static int op_has_extent(int op) |
| 44 | { |
| 45 | return (op == CEPH_OSD_OP_READ || |
| 46 | op == CEPH_OSD_OP_WRITE); |
| 47 | } |
| 48 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 49 | void ceph_calc_raw_layout(struct ceph_osd_client *osdc, |
| 50 | struct ceph_file_layout *layout, |
| 51 | u64 snapid, |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 52 | u64 off, u64 *plen, u64 *bno, |
| 53 | struct ceph_osd_request *req, |
| 54 | struct ceph_osd_req_op *op) |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 55 | { |
| 56 | struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 57 | u64 orig_len = *plen; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 58 | u64 objoff, objlen; /* extent in object */ |
| 59 | |
| 60 | reqhead->snapid = cpu_to_le64(snapid); |
| 61 | |
| 62 | /* object extent? */ |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 63 | ceph_calc_file_object_mapping(layout, off, plen, bno, |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 64 | &objoff, &objlen); |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 65 | if (*plen < orig_len) |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 66 | dout(" skipping last %llu, final file extent %llu~%llu\n", |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 67 | orig_len - *plen, off, *plen); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 68 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 69 | if (op_has_extent(op->op)) { |
| 70 | op->extent.offset = objoff; |
| 71 | op->extent.length = objlen; |
| 72 | } |
| 73 | req->r_num_pages = calc_pages_for(off, *plen); |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 74 | req->r_page_alignment = off & ~PAGE_MASK; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 75 | if (op->op == CEPH_OSD_OP_WRITE) |
| 76 | op->payload_len = *plen; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 77 | |
| 78 | dout("calc_layout bno=%llx %llu~%llu (%d pages)\n", |
| 79 | *bno, objoff, objlen, req->r_num_pages); |
| 80 | |
| 81 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 82 | EXPORT_SYMBOL(ceph_calc_raw_layout); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 83 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 84 | /* |
| 85 | * Implement client access to distributed object storage cluster. |
| 86 | * |
| 87 | * All data objects are stored within a cluster/cloud of OSDs, or |
| 88 | * "object storage devices." (Note that Ceph OSDs have _nothing_ to |
| 89 | * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply |
| 90 | * remote daemons serving up and coordinating consistent and safe |
| 91 | * access to storage. |
| 92 | * |
| 93 | * Cluster membership and the mapping of data objects onto storage devices |
| 94 | * are described by the osd map. |
| 95 | * |
| 96 | * We keep track of pending OSD requests (read, write), resubmit |
| 97 | * requests to different OSDs when the cluster topology/data layout |
| 98 | * change, or retry the affected requests when the communications |
| 99 | * channel with an OSD is reset. |
| 100 | */ |
| 101 | |
| 102 | /* |
| 103 | * calculate the mapping of a file extent onto an object, and fill out the |
| 104 | * request accordingly. shorten extent as necessary if it crosses an |
| 105 | * object boundary. |
| 106 | * |
| 107 | * fill osd op in request message. |
| 108 | */ |
| 109 | static void calc_layout(struct ceph_osd_client *osdc, |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 110 | struct ceph_vino vino, |
| 111 | struct ceph_file_layout *layout, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 112 | u64 off, u64 *plen, |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 113 | struct ceph_osd_request *req, |
| 114 | struct ceph_osd_req_op *op) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 115 | { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 116 | u64 bno; |
| 117 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 118 | ceph_calc_raw_layout(osdc, layout, vino.snap, off, |
| 119 | plen, &bno, req, op); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 120 | |
| 121 | sprintf(req->r_oid, "%llx.%08llx", vino.ino, bno); |
| 122 | req->r_oid_len = strlen(req->r_oid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 125 | /* |
| 126 | * requests |
| 127 | */ |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 128 | void ceph_osdc_release_request(struct kref *kref) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 129 | { |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 130 | struct ceph_osd_request *req = container_of(kref, |
| 131 | struct ceph_osd_request, |
| 132 | r_kref); |
| 133 | |
| 134 | if (req->r_request) |
| 135 | ceph_msg_put(req->r_request); |
| 136 | if (req->r_reply) |
| 137 | ceph_msg_put(req->r_reply); |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 138 | if (req->r_con_filling_msg) { |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 139 | dout("release_request revoking pages %p from con %p\n", |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 140 | req->r_pages, req->r_con_filling_msg); |
| 141 | ceph_con_revoke_message(req->r_con_filling_msg, |
| 142 | req->r_reply); |
| 143 | ceph_con_put(req->r_con_filling_msg); |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 144 | } |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 145 | if (req->r_own_pages) |
| 146 | ceph_release_page_vector(req->r_pages, |
| 147 | req->r_num_pages); |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 148 | #ifdef CONFIG_BLOCK |
| 149 | if (req->r_bio) |
| 150 | bio_put(req->r_bio); |
| 151 | #endif |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 152 | ceph_put_snap_context(req->r_snapc); |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 153 | if (req->r_trail) { |
| 154 | ceph_pagelist_release(req->r_trail); |
| 155 | kfree(req->r_trail); |
| 156 | } |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 157 | if (req->r_mempool) |
| 158 | mempool_free(req, req->r_osdc->req_mempool); |
| 159 | else |
| 160 | kfree(req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 161 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 162 | EXPORT_SYMBOL(ceph_osdc_release_request); |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 163 | |
| 164 | static int get_num_ops(struct ceph_osd_req_op *ops, int *needs_trail) |
| 165 | { |
| 166 | int i = 0; |
| 167 | |
| 168 | if (needs_trail) |
| 169 | *needs_trail = 0; |
| 170 | while (ops[i].op) { |
| 171 | if (needs_trail && op_needs_trail(ops[i].op)) |
| 172 | *needs_trail = 1; |
| 173 | i++; |
| 174 | } |
| 175 | |
| 176 | return i; |
| 177 | } |
| 178 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 179 | struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, |
| 180 | int flags, |
| 181 | struct ceph_snap_context *snapc, |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 182 | struct ceph_osd_req_op *ops, |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 183 | bool use_mempool, |
| 184 | gfp_t gfp_flags, |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 185 | struct page **pages, |
| 186 | struct bio *bio) |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 187 | { |
| 188 | struct ceph_osd_request *req; |
| 189 | struct ceph_msg *msg; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 190 | int needs_trail; |
| 191 | int num_op = get_num_ops(ops, &needs_trail); |
| 192 | size_t msg_size = sizeof(struct ceph_osd_request_head); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 193 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 194 | msg_size += num_op*sizeof(struct ceph_osd_op); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 195 | |
| 196 | if (use_mempool) { |
| 197 | req = mempool_alloc(osdc->req_mempool, gfp_flags); |
| 198 | memset(req, 0, sizeof(*req)); |
| 199 | } else { |
| 200 | req = kzalloc(sizeof(*req), gfp_flags); |
| 201 | } |
| 202 | if (req == NULL) |
| 203 | return NULL; |
| 204 | |
| 205 | req->r_osdc = osdc; |
| 206 | req->r_mempool = use_mempool; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 207 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 208 | kref_init(&req->r_kref); |
| 209 | init_completion(&req->r_completion); |
| 210 | init_completion(&req->r_safe_completion); |
| 211 | INIT_LIST_HEAD(&req->r_unsafe_item); |
| 212 | req->r_flags = flags; |
| 213 | |
| 214 | WARN_ON((flags & (CEPH_OSD_FLAG_READ|CEPH_OSD_FLAG_WRITE)) == 0); |
| 215 | |
| 216 | /* create reply message */ |
| 217 | if (use_mempool) |
| 218 | msg = ceph_msgpool_get(&osdc->msgpool_op_reply, 0); |
| 219 | else |
| 220 | msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, |
| 221 | OSD_OPREPLY_FRONT_LEN, gfp_flags); |
| 222 | if (!msg) { |
| 223 | ceph_osdc_put_request(req); |
| 224 | return NULL; |
| 225 | } |
| 226 | req->r_reply = msg; |
| 227 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 228 | /* allocate space for the trailing data */ |
| 229 | if (needs_trail) { |
| 230 | req->r_trail = kmalloc(sizeof(struct ceph_pagelist), gfp_flags); |
| 231 | if (!req->r_trail) { |
| 232 | ceph_osdc_put_request(req); |
| 233 | return NULL; |
| 234 | } |
| 235 | ceph_pagelist_init(req->r_trail); |
| 236 | } |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 237 | /* create request message; allow space for oid */ |
| 238 | msg_size += 40; |
| 239 | if (snapc) |
| 240 | msg_size += sizeof(u64) * snapc->num_snaps; |
| 241 | if (use_mempool) |
| 242 | msg = ceph_msgpool_get(&osdc->msgpool_op, 0); |
| 243 | else |
| 244 | msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp_flags); |
| 245 | if (!msg) { |
| 246 | ceph_osdc_put_request(req); |
| 247 | return NULL; |
| 248 | } |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 249 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 250 | msg->hdr.type = cpu_to_le16(CEPH_MSG_OSD_OP); |
| 251 | memset(msg->front.iov_base, 0, msg->front.iov_len); |
| 252 | |
| 253 | req->r_request = msg; |
| 254 | req->r_pages = pages; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 255 | #ifdef CONFIG_BLOCK |
| 256 | if (bio) { |
| 257 | req->r_bio = bio; |
| 258 | bio_get(req->r_bio); |
| 259 | } |
| 260 | #endif |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 261 | |
| 262 | return req; |
| 263 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 264 | EXPORT_SYMBOL(ceph_osdc_alloc_request); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 265 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 266 | static void osd_req_encode_op(struct ceph_osd_request *req, |
| 267 | struct ceph_osd_op *dst, |
| 268 | struct ceph_osd_req_op *src) |
| 269 | { |
| 270 | dst->op = cpu_to_le16(src->op); |
| 271 | |
| 272 | switch (dst->op) { |
| 273 | case CEPH_OSD_OP_READ: |
| 274 | case CEPH_OSD_OP_WRITE: |
| 275 | dst->extent.offset = |
| 276 | cpu_to_le64(src->extent.offset); |
| 277 | dst->extent.length = |
| 278 | cpu_to_le64(src->extent.length); |
| 279 | dst->extent.truncate_size = |
| 280 | cpu_to_le64(src->extent.truncate_size); |
| 281 | dst->extent.truncate_seq = |
| 282 | cpu_to_le32(src->extent.truncate_seq); |
| 283 | break; |
| 284 | |
| 285 | case CEPH_OSD_OP_GETXATTR: |
| 286 | case CEPH_OSD_OP_SETXATTR: |
| 287 | case CEPH_OSD_OP_CMPXATTR: |
| 288 | BUG_ON(!req->r_trail); |
| 289 | |
| 290 | dst->xattr.name_len = cpu_to_le32(src->xattr.name_len); |
| 291 | dst->xattr.value_len = cpu_to_le32(src->xattr.value_len); |
| 292 | dst->xattr.cmp_op = src->xattr.cmp_op; |
| 293 | dst->xattr.cmp_mode = src->xattr.cmp_mode; |
| 294 | ceph_pagelist_append(req->r_trail, src->xattr.name, |
| 295 | src->xattr.name_len); |
| 296 | ceph_pagelist_append(req->r_trail, src->xattr.val, |
| 297 | src->xattr.value_len); |
| 298 | break; |
Yehuda Sadeh | ae1533b | 2010-05-18 16:38:08 -0700 | [diff] [blame] | 299 | case CEPH_OSD_OP_CALL: |
| 300 | BUG_ON(!req->r_trail); |
| 301 | |
| 302 | dst->cls.class_len = src->cls.class_len; |
| 303 | dst->cls.method_len = src->cls.method_len; |
| 304 | dst->cls.indata_len = cpu_to_le32(src->cls.indata_len); |
| 305 | |
| 306 | ceph_pagelist_append(req->r_trail, src->cls.class_name, |
| 307 | src->cls.class_len); |
| 308 | ceph_pagelist_append(req->r_trail, src->cls.method_name, |
| 309 | src->cls.method_len); |
| 310 | ceph_pagelist_append(req->r_trail, src->cls.indata, |
| 311 | src->cls.indata_len); |
| 312 | break; |
| 313 | case CEPH_OSD_OP_ROLLBACK: |
| 314 | dst->snap.snapid = cpu_to_le64(src->snap.snapid); |
| 315 | break; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 316 | case CEPH_OSD_OP_STARTSYNC: |
| 317 | break; |
| 318 | default: |
| 319 | pr_err("unrecognized osd opcode %d\n", dst->op); |
| 320 | WARN_ON(1); |
| 321 | break; |
| 322 | } |
| 323 | dst->payload_len = cpu_to_le32(src->payload_len); |
| 324 | } |
| 325 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 326 | /* |
| 327 | * build new request AND message |
| 328 | * |
| 329 | */ |
| 330 | void ceph_osdc_build_request(struct ceph_osd_request *req, |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 331 | u64 off, u64 *plen, |
| 332 | struct ceph_osd_req_op *src_ops, |
| 333 | struct ceph_snap_context *snapc, |
| 334 | struct timespec *mtime, |
| 335 | const char *oid, |
| 336 | int oid_len) |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 337 | { |
| 338 | struct ceph_msg *msg = req->r_request; |
| 339 | struct ceph_osd_request_head *head; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 340 | struct ceph_osd_req_op *src_op; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 341 | struct ceph_osd_op *op; |
| 342 | void *p; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 343 | int num_op = get_num_ops(src_ops, NULL); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 344 | size_t msg_size = sizeof(*head) + num_op*sizeof(*op); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 345 | int flags = req->r_flags; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 346 | u64 data_len = 0; |
| 347 | int i; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 348 | |
| 349 | head = msg->front.iov_base; |
| 350 | op = (void *)(head + 1); |
| 351 | p = (void *)(op + num_op); |
| 352 | |
| 353 | req->r_snapc = ceph_get_snap_context(snapc); |
| 354 | |
| 355 | head->client_inc = cpu_to_le32(1); /* always, for now. */ |
| 356 | head->flags = cpu_to_le32(flags); |
| 357 | if (flags & CEPH_OSD_FLAG_WRITE) |
| 358 | ceph_encode_timespec(&head->mtime, mtime); |
| 359 | head->num_ops = cpu_to_le16(num_op); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 360 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 361 | |
| 362 | /* fill in oid */ |
| 363 | head->object_len = cpu_to_le32(oid_len); |
| 364 | memcpy(p, oid, oid_len); |
| 365 | p += oid_len; |
| 366 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 367 | src_op = src_ops; |
| 368 | while (src_op->op) { |
| 369 | osd_req_encode_op(req, op, src_op); |
| 370 | src_op++; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 371 | op++; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 372 | } |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 373 | |
| 374 | if (req->r_trail) |
| 375 | data_len += req->r_trail->length; |
| 376 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 377 | if (snapc) { |
| 378 | head->snap_seq = cpu_to_le64(snapc->seq); |
| 379 | head->num_snaps = cpu_to_le32(snapc->num_snaps); |
| 380 | for (i = 0; i < snapc->num_snaps; i++) { |
| 381 | put_unaligned_le64(snapc->snaps[i], p); |
| 382 | p += sizeof(u64); |
| 383 | } |
| 384 | } |
| 385 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 386 | if (flags & CEPH_OSD_FLAG_WRITE) { |
| 387 | req->r_request->hdr.data_off = cpu_to_le16(off); |
| 388 | req->r_request->hdr.data_len = cpu_to_le32(*plen + data_len); |
| 389 | } else if (data_len) { |
| 390 | req->r_request->hdr.data_off = 0; |
| 391 | req->r_request->hdr.data_len = cpu_to_le32(data_len); |
| 392 | } |
| 393 | |
Sage Weil | c5c6b19 | 2010-11-09 12:40:00 -0800 | [diff] [blame] | 394 | req->r_request->page_alignment = req->r_page_alignment; |
| 395 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 396 | BUG_ON(p > msg->front.iov_base + msg->front.iov_len); |
| 397 | msg_size = p - msg->front.iov_base; |
| 398 | msg->front.iov_len = msg_size; |
| 399 | msg->hdr.front_len = cpu_to_le32(msg_size); |
| 400 | return; |
| 401 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 402 | EXPORT_SYMBOL(ceph_osdc_build_request); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 403 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 404 | /* |
| 405 | * build new request AND message, calculate layout, and adjust file |
| 406 | * extent as needed. |
| 407 | * |
| 408 | * if the file was recently truncated, we include information about its |
| 409 | * old and new size so that the object can be updated appropriately. (we |
| 410 | * avoid synchronously deleting truncated objects because it's slow.) |
| 411 | * |
| 412 | * if @do_sync, include a 'startsync' command so that the osd will flush |
| 413 | * data quickly. |
| 414 | */ |
| 415 | struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, |
| 416 | struct ceph_file_layout *layout, |
| 417 | struct ceph_vino vino, |
| 418 | u64 off, u64 *plen, |
| 419 | int opcode, int flags, |
| 420 | struct ceph_snap_context *snapc, |
| 421 | int do_sync, |
| 422 | u32 truncate_seq, |
| 423 | u64 truncate_size, |
| 424 | struct timespec *mtime, |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 425 | bool use_mempool, int num_reply, |
| 426 | int page_align) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 427 | { |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 428 | struct ceph_osd_req_op ops[3]; |
| 429 | struct ceph_osd_request *req; |
| 430 | |
| 431 | ops[0].op = opcode; |
| 432 | ops[0].extent.truncate_seq = truncate_seq; |
| 433 | ops[0].extent.truncate_size = truncate_size; |
| 434 | ops[0].payload_len = 0; |
| 435 | |
| 436 | if (do_sync) { |
| 437 | ops[1].op = CEPH_OSD_OP_STARTSYNC; |
| 438 | ops[1].payload_len = 0; |
| 439 | ops[2].op = 0; |
| 440 | } else |
| 441 | ops[1].op = 0; |
| 442 | |
| 443 | req = ceph_osdc_alloc_request(osdc, flags, |
| 444 | snapc, ops, |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 445 | use_mempool, |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 446 | GFP_NOFS, NULL, NULL); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 447 | if (IS_ERR(req)) |
| 448 | return req; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 449 | |
| 450 | /* calculate max write size */ |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 451 | calc_layout(osdc, vino, layout, off, plen, req, ops); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 452 | req->r_file_layout = *layout; /* keep a copy */ |
| 453 | |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 454 | /* in case it differs from natural alignment that calc_layout |
| 455 | filled in for us */ |
| 456 | req->r_page_alignment = page_align; |
| 457 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 458 | ceph_osdc_build_request(req, off, plen, ops, |
| 459 | snapc, |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 460 | mtime, |
| 461 | req->r_oid, req->r_oid_len); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 462 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 463 | return req; |
| 464 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 465 | EXPORT_SYMBOL(ceph_osdc_new_request); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 466 | |
| 467 | /* |
| 468 | * We keep osd requests in an rbtree, sorted by ->r_tid. |
| 469 | */ |
| 470 | static void __insert_request(struct ceph_osd_client *osdc, |
| 471 | struct ceph_osd_request *new) |
| 472 | { |
| 473 | struct rb_node **p = &osdc->requests.rb_node; |
| 474 | struct rb_node *parent = NULL; |
| 475 | struct ceph_osd_request *req = NULL; |
| 476 | |
| 477 | while (*p) { |
| 478 | parent = *p; |
| 479 | req = rb_entry(parent, struct ceph_osd_request, r_node); |
| 480 | if (new->r_tid < req->r_tid) |
| 481 | p = &(*p)->rb_left; |
| 482 | else if (new->r_tid > req->r_tid) |
| 483 | p = &(*p)->rb_right; |
| 484 | else |
| 485 | BUG(); |
| 486 | } |
| 487 | |
| 488 | rb_link_node(&new->r_node, parent, p); |
| 489 | rb_insert_color(&new->r_node, &osdc->requests); |
| 490 | } |
| 491 | |
| 492 | static struct ceph_osd_request *__lookup_request(struct ceph_osd_client *osdc, |
| 493 | u64 tid) |
| 494 | { |
| 495 | struct ceph_osd_request *req; |
| 496 | struct rb_node *n = osdc->requests.rb_node; |
| 497 | |
| 498 | while (n) { |
| 499 | req = rb_entry(n, struct ceph_osd_request, r_node); |
| 500 | if (tid < req->r_tid) |
| 501 | n = n->rb_left; |
| 502 | else if (tid > req->r_tid) |
| 503 | n = n->rb_right; |
| 504 | else |
| 505 | return req; |
| 506 | } |
| 507 | return NULL; |
| 508 | } |
| 509 | |
| 510 | static struct ceph_osd_request * |
| 511 | __lookup_request_ge(struct ceph_osd_client *osdc, |
| 512 | u64 tid) |
| 513 | { |
| 514 | struct ceph_osd_request *req; |
| 515 | struct rb_node *n = osdc->requests.rb_node; |
| 516 | |
| 517 | while (n) { |
| 518 | req = rb_entry(n, struct ceph_osd_request, r_node); |
| 519 | if (tid < req->r_tid) { |
| 520 | if (!n->rb_left) |
| 521 | return req; |
| 522 | n = n->rb_left; |
| 523 | } else if (tid > req->r_tid) { |
| 524 | n = n->rb_right; |
| 525 | } else { |
| 526 | return req; |
| 527 | } |
| 528 | } |
| 529 | return NULL; |
| 530 | } |
| 531 | |
| 532 | |
| 533 | /* |
Sage Weil | 81b024e | 2009-10-09 10:29:18 -0700 | [diff] [blame] | 534 | * If the osd connection drops, we need to resubmit all requests. |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 535 | */ |
| 536 | static void osd_reset(struct ceph_connection *con) |
| 537 | { |
| 538 | struct ceph_osd *osd = con->private; |
| 539 | struct ceph_osd_client *osdc; |
| 540 | |
| 541 | if (!osd) |
| 542 | return; |
| 543 | dout("osd_reset osd%d\n", osd->o_osd); |
| 544 | osdc = osd->o_osdc; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 545 | down_read(&osdc->map_sem); |
| 546 | kick_requests(osdc, osd); |
| 547 | up_read(&osdc->map_sem); |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | * Track open sessions with osds. |
| 552 | */ |
| 553 | static struct ceph_osd *create_osd(struct ceph_osd_client *osdc) |
| 554 | { |
| 555 | struct ceph_osd *osd; |
| 556 | |
| 557 | osd = kzalloc(sizeof(*osd), GFP_NOFS); |
| 558 | if (!osd) |
| 559 | return NULL; |
| 560 | |
| 561 | atomic_set(&osd->o_ref, 1); |
| 562 | osd->o_osdc = osdc; |
| 563 | INIT_LIST_HEAD(&osd->o_requests); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 564 | INIT_LIST_HEAD(&osd->o_osd_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 565 | osd->o_incarnation = 1; |
| 566 | |
| 567 | ceph_con_init(osdc->client->msgr, &osd->o_con); |
| 568 | osd->o_con.private = osd; |
| 569 | osd->o_con.ops = &osd_con_ops; |
| 570 | osd->o_con.peer_name.type = CEPH_ENTITY_TYPE_OSD; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 571 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 572 | INIT_LIST_HEAD(&osd->o_keepalive_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 573 | return osd; |
| 574 | } |
| 575 | |
| 576 | static struct ceph_osd *get_osd(struct ceph_osd *osd) |
| 577 | { |
| 578 | if (atomic_inc_not_zero(&osd->o_ref)) { |
| 579 | dout("get_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref)-1, |
| 580 | atomic_read(&osd->o_ref)); |
| 581 | return osd; |
| 582 | } else { |
| 583 | dout("get_osd %p FAIL\n", osd); |
| 584 | return NULL; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | static void put_osd(struct ceph_osd *osd) |
| 589 | { |
| 590 | dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref), |
| 591 | atomic_read(&osd->o_ref) - 1); |
Sage Weil | 79494d1 | 2010-05-27 14:15:49 -0700 | [diff] [blame] | 592 | if (atomic_dec_and_test(&osd->o_ref)) { |
| 593 | struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth; |
| 594 | |
| 595 | if (osd->o_authorizer) |
| 596 | ac->ops->destroy_authorizer(ac, osd->o_authorizer); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 597 | kfree(osd); |
Sage Weil | 79494d1 | 2010-05-27 14:15:49 -0700 | [diff] [blame] | 598 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /* |
| 602 | * remove an osd from our map |
| 603 | */ |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 604 | 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] | 605 | { |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 606 | dout("__remove_osd %p\n", osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 607 | BUG_ON(!list_empty(&osd->o_requests)); |
| 608 | rb_erase(&osd->o_node, &osdc->osds); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 609 | list_del_init(&osd->o_osd_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 610 | ceph_con_close(&osd->o_con); |
| 611 | put_osd(osd); |
| 612 | } |
| 613 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 614 | static void __move_osd_to_lru(struct ceph_osd_client *osdc, |
| 615 | struct ceph_osd *osd) |
| 616 | { |
| 617 | dout("__move_osd_to_lru %p\n", osd); |
| 618 | BUG_ON(!list_empty(&osd->o_osd_lru)); |
| 619 | list_add_tail(&osd->o_osd_lru, &osdc->osd_lru); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 620 | osd->lru_ttl = jiffies + osdc->client->options->osd_idle_ttl * HZ; |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static void __remove_osd_from_lru(struct ceph_osd *osd) |
| 624 | { |
| 625 | dout("__remove_osd_from_lru %p\n", osd); |
| 626 | if (!list_empty(&osd->o_osd_lru)) |
| 627 | list_del_init(&osd->o_osd_lru); |
| 628 | } |
| 629 | |
| 630 | static void remove_old_osds(struct ceph_osd_client *osdc, int remove_all) |
| 631 | { |
| 632 | struct ceph_osd *osd, *nosd; |
| 633 | |
| 634 | dout("__remove_old_osds %p\n", osdc); |
| 635 | mutex_lock(&osdc->request_mutex); |
| 636 | list_for_each_entry_safe(osd, nosd, &osdc->osd_lru, o_osd_lru) { |
| 637 | if (!remove_all && time_before(jiffies, osd->lru_ttl)) |
| 638 | break; |
| 639 | __remove_osd(osdc, osd); |
| 640 | } |
| 641 | mutex_unlock(&osdc->request_mutex); |
| 642 | } |
| 643 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 644 | /* |
| 645 | * reset osd connect |
| 646 | */ |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 647 | 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] | 648 | { |
Sage Weil | 87b315a | 2010-03-22 14:51:18 -0700 | [diff] [blame] | 649 | struct ceph_osd_request *req; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 650 | int ret = 0; |
| 651 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 652 | dout("__reset_osd %p osd%d\n", osd, osd->o_osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 653 | if (list_empty(&osd->o_requests)) { |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 654 | __remove_osd(osdc, osd); |
Sage Weil | 87b315a | 2010-03-22 14:51:18 -0700 | [diff] [blame] | 655 | } else if (memcmp(&osdc->osdmap->osd_addr[osd->o_osd], |
| 656 | &osd->o_con.peer_addr, |
| 657 | sizeof(osd->o_con.peer_addr)) == 0 && |
| 658 | !ceph_con_opened(&osd->o_con)) { |
| 659 | dout(" osd addr hasn't changed and connection never opened," |
| 660 | " letting msgr retry"); |
| 661 | /* touch each r_stamp for handle_timeout()'s benfit */ |
| 662 | list_for_each_entry(req, &osd->o_requests, r_osd_item) |
| 663 | req->r_stamp = jiffies; |
| 664 | ret = -EAGAIN; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 665 | } else { |
| 666 | ceph_con_close(&osd->o_con); |
| 667 | ceph_con_open(&osd->o_con, &osdc->osdmap->osd_addr[osd->o_osd]); |
| 668 | osd->o_incarnation++; |
| 669 | } |
| 670 | return ret; |
| 671 | } |
| 672 | |
| 673 | static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new) |
| 674 | { |
| 675 | struct rb_node **p = &osdc->osds.rb_node; |
| 676 | struct rb_node *parent = NULL; |
| 677 | struct ceph_osd *osd = NULL; |
| 678 | |
| 679 | while (*p) { |
| 680 | parent = *p; |
| 681 | osd = rb_entry(parent, struct ceph_osd, o_node); |
| 682 | if (new->o_osd < osd->o_osd) |
| 683 | p = &(*p)->rb_left; |
| 684 | else if (new->o_osd > osd->o_osd) |
| 685 | p = &(*p)->rb_right; |
| 686 | else |
| 687 | BUG(); |
| 688 | } |
| 689 | |
| 690 | rb_link_node(&new->o_node, parent, p); |
| 691 | rb_insert_color(&new->o_node, &osdc->osds); |
| 692 | } |
| 693 | |
| 694 | static struct ceph_osd *__lookup_osd(struct ceph_osd_client *osdc, int o) |
| 695 | { |
| 696 | struct ceph_osd *osd; |
| 697 | struct rb_node *n = osdc->osds.rb_node; |
| 698 | |
| 699 | while (n) { |
| 700 | osd = rb_entry(n, struct ceph_osd, o_node); |
| 701 | if (o < osd->o_osd) |
| 702 | n = n->rb_left; |
| 703 | else if (o > osd->o_osd) |
| 704 | n = n->rb_right; |
| 705 | else |
| 706 | return osd; |
| 707 | } |
| 708 | return NULL; |
| 709 | } |
| 710 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 711 | static void __schedule_osd_timeout(struct ceph_osd_client *osdc) |
| 712 | { |
| 713 | schedule_delayed_work(&osdc->timeout_work, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 714 | osdc->client->options->osd_keepalive_timeout * HZ); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static void __cancel_osd_timeout(struct ceph_osd_client *osdc) |
| 718 | { |
| 719 | cancel_delayed_work(&osdc->timeout_work); |
| 720 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 721 | |
| 722 | /* |
| 723 | * Register request, assign tid. If this is the first request, set up |
| 724 | * the timeout event. |
| 725 | */ |
| 726 | static void register_request(struct ceph_osd_client *osdc, |
| 727 | struct ceph_osd_request *req) |
| 728 | { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 729 | mutex_lock(&osdc->request_mutex); |
| 730 | req->r_tid = ++osdc->last_tid; |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame] | 731 | req->r_request->hdr.tid = cpu_to_le64(req->r_tid); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 732 | INIT_LIST_HEAD(&req->r_req_lru_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 733 | |
| 734 | dout("register_request %p tid %lld\n", req, req->r_tid); |
| 735 | __insert_request(osdc, req); |
| 736 | ceph_osdc_get_request(req); |
| 737 | osdc->num_requests++; |
| 738 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 739 | if (osdc->num_requests == 1) { |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 740 | dout(" first request, scheduling timeout\n"); |
| 741 | __schedule_osd_timeout(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 742 | } |
| 743 | mutex_unlock(&osdc->request_mutex); |
| 744 | } |
| 745 | |
| 746 | /* |
| 747 | * called under osdc->request_mutex |
| 748 | */ |
| 749 | static void __unregister_request(struct ceph_osd_client *osdc, |
| 750 | struct ceph_osd_request *req) |
| 751 | { |
| 752 | dout("__unregister_request %p tid %lld\n", req, req->r_tid); |
| 753 | rb_erase(&req->r_node, &osdc->requests); |
| 754 | osdc->num_requests--; |
| 755 | |
Sage Weil | 0ba6478 | 2009-10-08 16:57:16 -0700 | [diff] [blame] | 756 | if (req->r_osd) { |
| 757 | /* make sure the original request isn't in flight. */ |
| 758 | ceph_con_revoke(&req->r_osd->o_con, req->r_request); |
| 759 | |
| 760 | list_del_init(&req->r_osd_item); |
| 761 | if (list_empty(&req->r_osd->o_requests)) |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 762 | __move_osd_to_lru(osdc, req->r_osd); |
Sage Weil | 0ba6478 | 2009-10-08 16:57:16 -0700 | [diff] [blame] | 763 | req->r_osd = NULL; |
| 764 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 765 | |
| 766 | ceph_osdc_put_request(req); |
| 767 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 768 | list_del_init(&req->r_req_lru_item); |
| 769 | if (osdc->num_requests == 0) { |
| 770 | dout(" no requests, canceling timeout\n"); |
| 771 | __cancel_osd_timeout(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | |
| 775 | /* |
| 776 | * Cancel a previously queued request message |
| 777 | */ |
| 778 | static void __cancel_request(struct ceph_osd_request *req) |
| 779 | { |
Sage Weil | 6bc1887 | 2010-09-27 10:18:52 -0700 | [diff] [blame] | 780 | if (req->r_sent && req->r_osd) { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 781 | ceph_con_revoke(&req->r_osd->o_con, req->r_request); |
| 782 | req->r_sent = 0; |
| 783 | } |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 784 | list_del_init(&req->r_req_lru_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | /* |
| 788 | * Pick an osd (the first 'up' osd in the pg), allocate the osd struct |
| 789 | * (as needed), and set the request r_osd appropriately. If there is |
| 790 | * no up osd, set r_osd to NULL. |
| 791 | * |
| 792 | * Return 0 if unchanged, 1 if changed, or negative on error. |
| 793 | * |
| 794 | * Caller should hold map_sem for read and request_mutex. |
| 795 | */ |
| 796 | static int __map_osds(struct ceph_osd_client *osdc, |
| 797 | struct ceph_osd_request *req) |
| 798 | { |
| 799 | struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base; |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 800 | struct ceph_pg pgid; |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 801 | int acting[CEPH_PG_MAX_SIZE]; |
| 802 | int o = -1, num = 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 803 | int err; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 804 | |
| 805 | dout("map_osds %p tid %lld\n", req, req->r_tid); |
| 806 | err = ceph_calc_object_layout(&reqhead->layout, req->r_oid, |
| 807 | &req->r_file_layout, osdc->osdmap); |
| 808 | if (err) |
| 809 | return err; |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 810 | pgid = reqhead->layout.ol_pgid; |
Sage Weil | 7740a42 | 2010-01-08 15:58:25 -0800 | [diff] [blame] | 811 | req->r_pgid = pgid; |
| 812 | |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 813 | err = ceph_calc_pg_acting(osdc->osdmap, pgid, acting); |
| 814 | if (err > 0) { |
| 815 | o = acting[0]; |
| 816 | num = err; |
| 817 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 818 | |
| 819 | if ((req->r_osd && req->r_osd->o_osd == o && |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 820 | req->r_sent >= req->r_osd->o_incarnation && |
| 821 | req->r_num_pg_osds == num && |
| 822 | memcmp(req->r_pg_osds, acting, sizeof(acting[0])*num) == 0) || |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 823 | (req->r_osd == NULL && o == -1)) |
| 824 | return 0; /* no change */ |
| 825 | |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 826 | dout("map_osds tid %llu pgid %d.%x osd%d (was osd%d)\n", |
| 827 | 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] | 828 | req->r_osd ? req->r_osd->o_osd : -1); |
| 829 | |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 830 | /* record full pg acting set */ |
| 831 | memcpy(req->r_pg_osds, acting, sizeof(acting[0]) * num); |
| 832 | req->r_num_pg_osds = num; |
| 833 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 834 | if (req->r_osd) { |
| 835 | __cancel_request(req); |
| 836 | list_del_init(&req->r_osd_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 837 | req->r_osd = NULL; |
| 838 | } |
| 839 | |
| 840 | req->r_osd = __lookup_osd(osdc, o); |
| 841 | if (!req->r_osd && o >= 0) { |
Sage Weil | c99eb1c | 2010-02-26 09:37:33 -0800 | [diff] [blame] | 842 | err = -ENOMEM; |
| 843 | req->r_osd = create_osd(osdc); |
| 844 | if (!req->r_osd) |
| 845 | goto out; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 846 | |
| 847 | dout("map_osds osd %p is osd%d\n", req->r_osd, o); |
| 848 | req->r_osd->o_osd = o; |
| 849 | req->r_osd->o_con.peer_name.num = cpu_to_le64(o); |
| 850 | __insert_osd(osdc, req->r_osd); |
| 851 | |
| 852 | ceph_con_open(&req->r_osd->o_con, &osdc->osdmap->osd_addr[o]); |
| 853 | } |
| 854 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 855 | if (req->r_osd) { |
| 856 | __remove_osd_from_lru(req->r_osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 857 | list_add(&req->r_osd_item, &req->r_osd->o_requests); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 858 | } |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 859 | err = 1; /* osd or pg changed */ |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 860 | |
| 861 | out: |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 862 | return err; |
| 863 | } |
| 864 | |
| 865 | /* |
| 866 | * caller should hold map_sem (for read) and request_mutex |
| 867 | */ |
| 868 | static int __send_request(struct ceph_osd_client *osdc, |
| 869 | struct ceph_osd_request *req) |
| 870 | { |
| 871 | struct ceph_osd_request_head *reqhead; |
| 872 | int err; |
| 873 | |
| 874 | err = __map_osds(osdc, req); |
| 875 | if (err < 0) |
| 876 | return err; |
| 877 | if (req->r_osd == NULL) { |
| 878 | dout("send_request %p no up osds in pg\n", req); |
| 879 | ceph_monc_request_next_osdmap(&osdc->client->monc); |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | dout("send_request %p tid %llu to osd%d flags %d\n", |
| 884 | req, req->r_tid, req->r_osd->o_osd, req->r_flags); |
| 885 | |
| 886 | reqhead = req->r_request->front.iov_base; |
| 887 | reqhead->osdmap_epoch = cpu_to_le32(osdc->osdmap->epoch); |
| 888 | reqhead->flags |= cpu_to_le32(req->r_flags); /* e.g., RETRY */ |
| 889 | reqhead->reassert_version = req->r_reassert_version; |
| 890 | |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 891 | req->r_stamp = jiffies; |
Henry C Chang | 07a27e2 | 2010-08-22 21:34:27 -0700 | [diff] [blame] | 892 | list_move_tail(&req->r_req_lru_item, &osdc->req_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 893 | |
| 894 | ceph_msg_get(req->r_request); /* send consumes a ref */ |
| 895 | ceph_con_send(&req->r_osd->o_con, req->r_request); |
| 896 | req->r_sent = req->r_osd->o_incarnation; |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | /* |
| 901 | * Timeout callback, called every N seconds when 1 or more osd |
| 902 | * requests has been active for more than N seconds. When this |
| 903 | * happens, we ping all OSDs with requests who have timed out to |
| 904 | * ensure any communications channel reset is detected. Reset the |
| 905 | * request timeouts another N seconds in the future as we go. |
| 906 | * Reschedule the timeout event another N seconds in future (unless |
| 907 | * there are no open requests). |
| 908 | */ |
| 909 | static void handle_timeout(struct work_struct *work) |
| 910 | { |
| 911 | struct ceph_osd_client *osdc = |
| 912 | container_of(work, struct ceph_osd_client, timeout_work.work); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 913 | struct ceph_osd_request *req, *last_req = NULL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 914 | struct ceph_osd *osd; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 915 | unsigned long timeout = osdc->client->options->osd_timeout * HZ; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 916 | unsigned long keepalive = |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 917 | osdc->client->options->osd_keepalive_timeout * HZ; |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 918 | unsigned long last_stamp = 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 919 | struct rb_node *p; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 920 | struct list_head slow_osds; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 921 | |
| 922 | dout("timeout\n"); |
| 923 | down_read(&osdc->map_sem); |
| 924 | |
| 925 | ceph_monc_request_next_osdmap(&osdc->client->monc); |
| 926 | |
| 927 | mutex_lock(&osdc->request_mutex); |
| 928 | for (p = rb_first(&osdc->requests); p; p = rb_next(p)) { |
| 929 | req = rb_entry(p, struct ceph_osd_request, r_node); |
| 930 | |
| 931 | if (req->r_resend) { |
| 932 | int err; |
| 933 | |
| 934 | dout("osdc resending prev failed %lld\n", req->r_tid); |
| 935 | err = __send_request(osdc, req); |
| 936 | if (err) |
| 937 | dout("osdc failed again on %lld\n", req->r_tid); |
| 938 | else |
| 939 | req->r_resend = false; |
| 940 | continue; |
| 941 | } |
| 942 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 943 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 944 | /* |
| 945 | * reset osds that appear to be _really_ unresponsive. this |
| 946 | * is a failsafe measure.. we really shouldn't be getting to |
| 947 | * this point if the system is working properly. the monitors |
| 948 | * should mark the osd as failed and we should find out about |
| 949 | * it from an updated osd map. |
| 950 | */ |
Sage Weil | f26e681 | 2010-04-21 11:09:38 -0700 | [diff] [blame] | 951 | while (timeout && !list_empty(&osdc->req_lru)) { |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 952 | req = list_entry(osdc->req_lru.next, struct ceph_osd_request, |
| 953 | r_req_lru_item); |
| 954 | |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 955 | if (time_before(jiffies, req->r_stamp + timeout)) |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 956 | break; |
| 957 | |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 958 | BUG_ON(req == last_req && req->r_stamp == last_stamp); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 959 | last_req = req; |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 960 | last_stamp = req->r_stamp; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 961 | |
| 962 | osd = req->r_osd; |
| 963 | BUG_ON(!osd); |
| 964 | pr_warning(" tid %llu timed out on osd%d, will reset osd\n", |
| 965 | req->r_tid, osd->o_osd); |
| 966 | __kick_requests(osdc, osd); |
| 967 | } |
| 968 | |
| 969 | /* |
| 970 | * ping osds that are a bit slow. this ensures that if there |
| 971 | * is a break in the TCP connection we will notice, and reopen |
| 972 | * a connection with that osd (from the fault callback). |
| 973 | */ |
| 974 | INIT_LIST_HEAD(&slow_osds); |
| 975 | list_for_each_entry(req, &osdc->req_lru, r_req_lru_item) { |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 976 | if (time_before(jiffies, req->r_stamp + keepalive)) |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 977 | break; |
| 978 | |
| 979 | osd = req->r_osd; |
| 980 | BUG_ON(!osd); |
| 981 | dout(" tid %llu is slow, will send keepalive on osd%d\n", |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 982 | req->r_tid, osd->o_osd); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 983 | list_move_tail(&osd->o_keepalive_item, &slow_osds); |
| 984 | } |
| 985 | while (!list_empty(&slow_osds)) { |
| 986 | osd = list_entry(slow_osds.next, struct ceph_osd, |
| 987 | o_keepalive_item); |
| 988 | list_del_init(&osd->o_keepalive_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 989 | ceph_con_keepalive(&osd->o_con); |
| 990 | } |
| 991 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 992 | __schedule_osd_timeout(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 993 | mutex_unlock(&osdc->request_mutex); |
| 994 | |
| 995 | up_read(&osdc->map_sem); |
| 996 | } |
| 997 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 998 | static void handle_osds_timeout(struct work_struct *work) |
| 999 | { |
| 1000 | struct ceph_osd_client *osdc = |
| 1001 | container_of(work, struct ceph_osd_client, |
| 1002 | osds_timeout_work.work); |
| 1003 | unsigned long delay = |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1004 | osdc->client->options->osd_idle_ttl * HZ >> 2; |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1005 | |
| 1006 | dout("osds timeout\n"); |
| 1007 | down_read(&osdc->map_sem); |
| 1008 | remove_old_osds(osdc, 0); |
| 1009 | up_read(&osdc->map_sem); |
| 1010 | |
| 1011 | schedule_delayed_work(&osdc->osds_timeout_work, |
| 1012 | round_jiffies_relative(delay)); |
| 1013 | } |
| 1014 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1015 | /* |
| 1016 | * handle osd op reply. either call the callback if it is specified, |
| 1017 | * or do the completion to wake up the waiting thread. |
| 1018 | */ |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 1019 | static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, |
| 1020 | struct ceph_connection *con) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1021 | { |
| 1022 | struct ceph_osd_reply_head *rhead = msg->front.iov_base; |
| 1023 | struct ceph_osd_request *req; |
| 1024 | u64 tid; |
| 1025 | int numops, object_len, flags; |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 1026 | s32 result; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1027 | |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame] | 1028 | tid = le64_to_cpu(msg->hdr.tid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1029 | if (msg->front.iov_len < sizeof(*rhead)) |
| 1030 | goto bad; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1031 | numops = le32_to_cpu(rhead->num_ops); |
| 1032 | object_len = le32_to_cpu(rhead->object_len); |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 1033 | result = le32_to_cpu(rhead->result); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1034 | if (msg->front.iov_len != sizeof(*rhead) + object_len + |
| 1035 | numops * sizeof(struct ceph_osd_op)) |
| 1036 | goto bad; |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 1037 | 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] | 1038 | |
| 1039 | /* lookup */ |
| 1040 | mutex_lock(&osdc->request_mutex); |
| 1041 | req = __lookup_request(osdc, tid); |
| 1042 | if (req == NULL) { |
| 1043 | dout("handle_reply tid %llu dne\n", tid); |
| 1044 | mutex_unlock(&osdc->request_mutex); |
| 1045 | return; |
| 1046 | } |
| 1047 | ceph_osdc_get_request(req); |
| 1048 | flags = le32_to_cpu(rhead->flags); |
| 1049 | |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 1050 | /* |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 1051 | * if this connection filled our message, drop our reference now, to |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 1052 | * avoid a (safe but slower) revoke later. |
| 1053 | */ |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 1054 | if (req->r_con_filling_msg == con && req->r_reply == msg) { |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1055 | dout(" dropping con_filling_msg ref %p\n", con); |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 1056 | req->r_con_filling_msg = NULL; |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 1057 | ceph_con_put(con); |
| 1058 | } |
| 1059 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1060 | if (!req->r_got_reply) { |
| 1061 | unsigned bytes; |
| 1062 | |
| 1063 | req->r_result = le32_to_cpu(rhead->result); |
| 1064 | bytes = le32_to_cpu(msg->hdr.data_len); |
| 1065 | dout("handle_reply result %d bytes %d\n", req->r_result, |
| 1066 | bytes); |
| 1067 | if (req->r_result == 0) |
| 1068 | req->r_result = bytes; |
| 1069 | |
| 1070 | /* in case this is a write and we need to replay, */ |
| 1071 | req->r_reassert_version = rhead->reassert_version; |
| 1072 | |
| 1073 | req->r_got_reply = 1; |
| 1074 | } else if ((flags & CEPH_OSD_FLAG_ONDISK) == 0) { |
| 1075 | dout("handle_reply tid %llu dup ack\n", tid); |
Sage Weil | 34b43a5 | 2009-12-01 12:23:54 -0800 | [diff] [blame] | 1076 | mutex_unlock(&osdc->request_mutex); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1077 | goto done; |
| 1078 | } |
| 1079 | |
| 1080 | dout("handle_reply tid %llu flags %d\n", tid, flags); |
| 1081 | |
| 1082 | /* either this is a read, or we got the safe response */ |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 1083 | if (result < 0 || |
| 1084 | (flags & CEPH_OSD_FLAG_ONDISK) || |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1085 | ((flags & CEPH_OSD_FLAG_WRITE) == 0)) |
| 1086 | __unregister_request(osdc, req); |
| 1087 | |
| 1088 | mutex_unlock(&osdc->request_mutex); |
| 1089 | |
| 1090 | if (req->r_callback) |
| 1091 | req->r_callback(req, msg); |
| 1092 | else |
Yehuda Sadeh | 03066f2 | 2010-07-27 13:11:08 -0700 | [diff] [blame] | 1093 | complete_all(&req->r_completion); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1094 | |
| 1095 | if (flags & CEPH_OSD_FLAG_ONDISK) { |
| 1096 | if (req->r_safe_callback) |
| 1097 | req->r_safe_callback(req, msg); |
Yehuda Sadeh | 03066f2 | 2010-07-27 13:11:08 -0700 | [diff] [blame] | 1098 | complete_all(&req->r_safe_completion); /* fsync waiter */ |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | done: |
| 1102 | ceph_osdc_put_request(req); |
| 1103 | return; |
| 1104 | |
| 1105 | bad: |
| 1106 | pr_err("corrupt osd_op_reply got %d %d expected %d\n", |
| 1107 | (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len), |
| 1108 | (int)sizeof(*rhead)); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 1109 | ceph_msg_dump(msg); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1113 | static int __kick_requests(struct ceph_osd_client *osdc, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1114 | struct ceph_osd *kickosd) |
| 1115 | { |
| 1116 | struct ceph_osd_request *req; |
| 1117 | struct rb_node *p, *n; |
| 1118 | int needmap = 0; |
| 1119 | int err; |
| 1120 | |
| 1121 | dout("kick_requests osd%d\n", kickosd ? kickosd->o_osd : -1); |
Sage Weil | 153a008 | 2010-02-15 12:11:51 -0800 | [diff] [blame] | 1122 | if (kickosd) { |
Sage Weil | 87b315a | 2010-03-22 14:51:18 -0700 | [diff] [blame] | 1123 | err = __reset_osd(osdc, kickosd); |
| 1124 | if (err == -EAGAIN) |
| 1125 | return 1; |
Sage Weil | 153a008 | 2010-02-15 12:11:51 -0800 | [diff] [blame] | 1126 | } else { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1127 | for (p = rb_first(&osdc->osds); p; p = n) { |
| 1128 | struct ceph_osd *osd = |
| 1129 | rb_entry(p, struct ceph_osd, o_node); |
| 1130 | |
| 1131 | n = rb_next(p); |
| 1132 | if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) || |
Sage Weil | 103e2d3 | 2010-01-07 16:12:36 -0800 | [diff] [blame] | 1133 | memcmp(&osd->o_con.peer_addr, |
| 1134 | ceph_osd_addr(osdc->osdmap, |
| 1135 | osd->o_osd), |
| 1136 | sizeof(struct ceph_entity_addr)) != 0) |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1137 | __reset_osd(osdc, osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | for (p = rb_first(&osdc->requests); p; p = rb_next(p)) { |
| 1142 | req = rb_entry(p, struct ceph_osd_request, r_node); |
| 1143 | |
| 1144 | if (req->r_resend) { |
| 1145 | dout(" r_resend set on tid %llu\n", req->r_tid); |
Sage Weil | 266673d | 2009-10-09 10:31:32 -0700 | [diff] [blame] | 1146 | __cancel_request(req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1147 | goto kick; |
| 1148 | } |
Sage Weil | 266673d | 2009-10-09 10:31:32 -0700 | [diff] [blame] | 1149 | if (req->r_osd && kickosd == req->r_osd) { |
| 1150 | __cancel_request(req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1151 | goto kick; |
Sage Weil | 266673d | 2009-10-09 10:31:32 -0700 | [diff] [blame] | 1152 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1153 | |
| 1154 | err = __map_osds(osdc, req); |
| 1155 | if (err == 0) |
| 1156 | continue; /* no change */ |
| 1157 | if (err < 0) { |
| 1158 | /* |
| 1159 | * FIXME: really, we should set the request |
| 1160 | * error and fail if this isn't a 'nofail' |
| 1161 | * request, but that's a fair bit more |
| 1162 | * complicated to do. So retry! |
| 1163 | */ |
| 1164 | dout(" setting r_resend on %llu\n", req->r_tid); |
| 1165 | req->r_resend = true; |
| 1166 | continue; |
| 1167 | } |
| 1168 | if (req->r_osd == NULL) { |
| 1169 | dout("tid %llu maps to no valid osd\n", req->r_tid); |
| 1170 | needmap++; /* request a newer map */ |
| 1171 | continue; |
| 1172 | } |
| 1173 | |
| 1174 | kick: |
Sage Weil | c1ea882 | 2009-10-08 16:55:47 -0700 | [diff] [blame] | 1175 | dout("kicking %p tid %llu osd%d\n", req, req->r_tid, |
Sage Weil | 12eadc1 | 2010-03-15 22:20:39 -0700 | [diff] [blame] | 1176 | req->r_osd ? req->r_osd->o_osd : -1); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1177 | req->r_flags |= CEPH_OSD_FLAG_RETRY; |
| 1178 | err = __send_request(osdc, req); |
| 1179 | if (err) { |
| 1180 | dout(" setting r_resend on %llu\n", req->r_tid); |
| 1181 | req->r_resend = true; |
| 1182 | } |
| 1183 | } |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1184 | |
| 1185 | return needmap; |
| 1186 | } |
| 1187 | |
| 1188 | /* |
| 1189 | * Resubmit osd requests whose osd or osd address has changed. Request |
| 1190 | * a new osd map if osds are down, or we are otherwise unable to determine |
| 1191 | * how to direct a request. |
| 1192 | * |
| 1193 | * Close connections to down osds. |
| 1194 | * |
| 1195 | * If @who is specified, resubmit requests for that specific osd. |
| 1196 | * |
| 1197 | * Caller should hold map_sem for read and request_mutex. |
| 1198 | */ |
| 1199 | static void kick_requests(struct ceph_osd_client *osdc, |
| 1200 | struct ceph_osd *kickosd) |
| 1201 | { |
| 1202 | int needmap; |
| 1203 | |
| 1204 | mutex_lock(&osdc->request_mutex); |
| 1205 | needmap = __kick_requests(osdc, kickosd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1206 | mutex_unlock(&osdc->request_mutex); |
| 1207 | |
| 1208 | if (needmap) { |
| 1209 | dout("%d requests for down osds, need new map\n", needmap); |
| 1210 | ceph_monc_request_next_osdmap(&osdc->client->monc); |
| 1211 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1212 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1213 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1214 | /* |
| 1215 | * Process updated osd map. |
| 1216 | * |
| 1217 | * The message contains any number of incremental and full maps, normally |
| 1218 | * indicating some sort of topology change in the cluster. Kick requests |
| 1219 | * off to different OSDs as needed. |
| 1220 | */ |
| 1221 | void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg) |
| 1222 | { |
| 1223 | void *p, *end, *next; |
| 1224 | u32 nr_maps, maplen; |
| 1225 | u32 epoch; |
| 1226 | struct ceph_osdmap *newmap = NULL, *oldmap; |
| 1227 | int err; |
| 1228 | struct ceph_fsid fsid; |
| 1229 | |
| 1230 | dout("handle_map have %u\n", osdc->osdmap ? osdc->osdmap->epoch : 0); |
| 1231 | p = msg->front.iov_base; |
| 1232 | end = p + msg->front.iov_len; |
| 1233 | |
| 1234 | /* verify fsid */ |
| 1235 | ceph_decode_need(&p, end, sizeof(fsid), bad); |
| 1236 | ceph_decode_copy(&p, &fsid, sizeof(fsid)); |
Sage Weil | 0743304 | 2009-11-18 16:50:41 -0800 | [diff] [blame] | 1237 | if (ceph_check_fsid(osdc->client, &fsid) < 0) |
| 1238 | return; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1239 | |
| 1240 | down_write(&osdc->map_sem); |
| 1241 | |
| 1242 | /* incremental maps */ |
| 1243 | ceph_decode_32_safe(&p, end, nr_maps, bad); |
| 1244 | dout(" %d inc maps\n", nr_maps); |
| 1245 | while (nr_maps > 0) { |
| 1246 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 1247 | epoch = ceph_decode_32(&p); |
| 1248 | maplen = ceph_decode_32(&p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1249 | ceph_decode_need(&p, end, maplen, bad); |
| 1250 | next = p + maplen; |
| 1251 | if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) { |
| 1252 | dout("applying incremental map %u len %d\n", |
| 1253 | epoch, maplen); |
| 1254 | newmap = osdmap_apply_incremental(&p, next, |
| 1255 | osdc->osdmap, |
| 1256 | osdc->client->msgr); |
| 1257 | if (IS_ERR(newmap)) { |
| 1258 | err = PTR_ERR(newmap); |
| 1259 | goto bad; |
| 1260 | } |
Sage Weil | 30dc638 | 2009-12-21 14:49:37 -0800 | [diff] [blame] | 1261 | BUG_ON(!newmap); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1262 | if (newmap != osdc->osdmap) { |
| 1263 | ceph_osdmap_destroy(osdc->osdmap); |
| 1264 | osdc->osdmap = newmap; |
| 1265 | } |
| 1266 | } else { |
| 1267 | dout("ignoring incremental map %u len %d\n", |
| 1268 | epoch, maplen); |
| 1269 | } |
| 1270 | p = next; |
| 1271 | nr_maps--; |
| 1272 | } |
| 1273 | if (newmap) |
| 1274 | goto done; |
| 1275 | |
| 1276 | /* full maps */ |
| 1277 | ceph_decode_32_safe(&p, end, nr_maps, bad); |
| 1278 | dout(" %d full maps\n", nr_maps); |
| 1279 | while (nr_maps) { |
| 1280 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 1281 | epoch = ceph_decode_32(&p); |
| 1282 | maplen = ceph_decode_32(&p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1283 | ceph_decode_need(&p, end, maplen, bad); |
| 1284 | if (nr_maps > 1) { |
| 1285 | dout("skipping non-latest full map %u len %d\n", |
| 1286 | epoch, maplen); |
| 1287 | } else if (osdc->osdmap && osdc->osdmap->epoch >= epoch) { |
| 1288 | dout("skipping full map %u len %d, " |
| 1289 | "older than our %u\n", epoch, maplen, |
| 1290 | osdc->osdmap->epoch); |
| 1291 | } else { |
| 1292 | dout("taking full map %u len %d\n", epoch, maplen); |
| 1293 | newmap = osdmap_decode(&p, p+maplen); |
| 1294 | if (IS_ERR(newmap)) { |
| 1295 | err = PTR_ERR(newmap); |
| 1296 | goto bad; |
| 1297 | } |
Sage Weil | 30dc638 | 2009-12-21 14:49:37 -0800 | [diff] [blame] | 1298 | BUG_ON(!newmap); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1299 | oldmap = osdc->osdmap; |
| 1300 | osdc->osdmap = newmap; |
| 1301 | if (oldmap) |
| 1302 | ceph_osdmap_destroy(oldmap); |
| 1303 | } |
| 1304 | p += maplen; |
| 1305 | nr_maps--; |
| 1306 | } |
| 1307 | |
| 1308 | done: |
| 1309 | downgrade_write(&osdc->map_sem); |
| 1310 | ceph_monc_got_osdmap(&osdc->client->monc, osdc->osdmap->epoch); |
| 1311 | if (newmap) |
| 1312 | kick_requests(osdc, NULL); |
| 1313 | up_read(&osdc->map_sem); |
Yehuda Sadeh | 03066f2 | 2010-07-27 13:11:08 -0700 | [diff] [blame] | 1314 | wake_up_all(&osdc->client->auth_wq); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1315 | return; |
| 1316 | |
| 1317 | bad: |
| 1318 | pr_err("osdc handle_map corrupt msg\n"); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 1319 | ceph_msg_dump(msg); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1320 | up_write(&osdc->map_sem); |
| 1321 | return; |
| 1322 | } |
| 1323 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1324 | /* |
| 1325 | * Register request, send initial attempt. |
| 1326 | */ |
| 1327 | int ceph_osdc_start_request(struct ceph_osd_client *osdc, |
| 1328 | struct ceph_osd_request *req, |
| 1329 | bool nofail) |
| 1330 | { |
Sage Weil | c1ea882 | 2009-10-08 16:55:47 -0700 | [diff] [blame] | 1331 | int rc = 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1332 | |
| 1333 | req->r_request->pages = req->r_pages; |
| 1334 | req->r_request->nr_pages = req->r_num_pages; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 1335 | #ifdef CONFIG_BLOCK |
| 1336 | req->r_request->bio = req->r_bio; |
| 1337 | #endif |
| 1338 | req->r_request->trail = req->r_trail; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1339 | |
| 1340 | register_request(osdc, req); |
| 1341 | |
| 1342 | down_read(&osdc->map_sem); |
| 1343 | mutex_lock(&osdc->request_mutex); |
Sage Weil | c1ea882 | 2009-10-08 16:55:47 -0700 | [diff] [blame] | 1344 | /* |
| 1345 | * a racing kick_requests() may have sent the message for us |
| 1346 | * while we dropped request_mutex above, so only send now if |
| 1347 | * the request still han't been touched yet. |
| 1348 | */ |
| 1349 | if (req->r_sent == 0) { |
| 1350 | rc = __send_request(osdc, req); |
| 1351 | if (rc) { |
| 1352 | if (nofail) { |
| 1353 | dout("osdc_start_request failed send, " |
| 1354 | " marking %lld\n", req->r_tid); |
| 1355 | req->r_resend = true; |
| 1356 | rc = 0; |
| 1357 | } else { |
| 1358 | __unregister_request(osdc, req); |
| 1359 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | mutex_unlock(&osdc->request_mutex); |
| 1363 | up_read(&osdc->map_sem); |
| 1364 | return rc; |
| 1365 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1366 | EXPORT_SYMBOL(ceph_osdc_start_request); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1367 | |
| 1368 | /* |
| 1369 | * wait for a request to complete |
| 1370 | */ |
| 1371 | int ceph_osdc_wait_request(struct ceph_osd_client *osdc, |
| 1372 | struct ceph_osd_request *req) |
| 1373 | { |
| 1374 | int rc; |
| 1375 | |
| 1376 | rc = wait_for_completion_interruptible(&req->r_completion); |
| 1377 | if (rc < 0) { |
| 1378 | mutex_lock(&osdc->request_mutex); |
| 1379 | __cancel_request(req); |
Sage Weil | 529cfcc | 2009-12-22 10:29:39 -0800 | [diff] [blame] | 1380 | __unregister_request(osdc, req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1381 | mutex_unlock(&osdc->request_mutex); |
Sage Weil | 529cfcc | 2009-12-22 10:29:39 -0800 | [diff] [blame] | 1382 | dout("wait_request tid %llu canceled/timed out\n", req->r_tid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1383 | return rc; |
| 1384 | } |
| 1385 | |
| 1386 | dout("wait_request tid %llu result %d\n", req->r_tid, req->r_result); |
| 1387 | return req->r_result; |
| 1388 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1389 | EXPORT_SYMBOL(ceph_osdc_wait_request); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1390 | |
| 1391 | /* |
| 1392 | * sync - wait for all in-flight requests to flush. avoid starvation. |
| 1393 | */ |
| 1394 | void ceph_osdc_sync(struct ceph_osd_client *osdc) |
| 1395 | { |
| 1396 | struct ceph_osd_request *req; |
| 1397 | u64 last_tid, next_tid = 0; |
| 1398 | |
| 1399 | mutex_lock(&osdc->request_mutex); |
| 1400 | last_tid = osdc->last_tid; |
| 1401 | while (1) { |
| 1402 | req = __lookup_request_ge(osdc, next_tid); |
| 1403 | if (!req) |
| 1404 | break; |
| 1405 | if (req->r_tid > last_tid) |
| 1406 | break; |
| 1407 | |
| 1408 | next_tid = req->r_tid + 1; |
| 1409 | if ((req->r_flags & CEPH_OSD_FLAG_WRITE) == 0) |
| 1410 | continue; |
| 1411 | |
| 1412 | ceph_osdc_get_request(req); |
| 1413 | mutex_unlock(&osdc->request_mutex); |
| 1414 | dout("sync waiting on tid %llu (last is %llu)\n", |
| 1415 | req->r_tid, last_tid); |
| 1416 | wait_for_completion(&req->r_safe_completion); |
| 1417 | mutex_lock(&osdc->request_mutex); |
| 1418 | ceph_osdc_put_request(req); |
| 1419 | } |
| 1420 | mutex_unlock(&osdc->request_mutex); |
| 1421 | dout("sync done (thru tid %llu)\n", last_tid); |
| 1422 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1423 | EXPORT_SYMBOL(ceph_osdc_sync); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1424 | |
| 1425 | /* |
| 1426 | * init, shutdown |
| 1427 | */ |
| 1428 | int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client) |
| 1429 | { |
| 1430 | int err; |
| 1431 | |
| 1432 | dout("init\n"); |
| 1433 | osdc->client = client; |
| 1434 | osdc->osdmap = NULL; |
| 1435 | init_rwsem(&osdc->map_sem); |
| 1436 | init_completion(&osdc->map_waiters); |
| 1437 | osdc->last_requested_map = 0; |
| 1438 | mutex_init(&osdc->request_mutex); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1439 | osdc->last_tid = 0; |
| 1440 | osdc->osds = RB_ROOT; |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1441 | INIT_LIST_HEAD(&osdc->osd_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1442 | osdc->requests = RB_ROOT; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1443 | INIT_LIST_HEAD(&osdc->req_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1444 | osdc->num_requests = 0; |
| 1445 | INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1446 | INIT_DELAYED_WORK(&osdc->osds_timeout_work, handle_osds_timeout); |
| 1447 | |
| 1448 | schedule_delayed_work(&osdc->osds_timeout_work, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1449 | round_jiffies_relative(osdc->client->options->osd_idle_ttl * HZ)); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1450 | |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1451 | err = -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1452 | osdc->req_mempool = mempool_create_kmalloc_pool(10, |
| 1453 | sizeof(struct ceph_osd_request)); |
| 1454 | if (!osdc->req_mempool) |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1455 | goto out; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1456 | |
Sage Weil | 4f48280 | 2010-04-24 09:56:35 -0700 | [diff] [blame] | 1457 | err = ceph_msgpool_init(&osdc->msgpool_op, OSD_OP_FRONT_LEN, 10, true, |
| 1458 | "osd_op"); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1459 | if (err < 0) |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1460 | goto out_mempool; |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1461 | err = ceph_msgpool_init(&osdc->msgpool_op_reply, |
Sage Weil | 4f48280 | 2010-04-24 09:56:35 -0700 | [diff] [blame] | 1462 | OSD_OPREPLY_FRONT_LEN, 10, true, |
| 1463 | "osd_op_reply"); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1464 | if (err < 0) |
| 1465 | goto out_msgpool; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1466 | return 0; |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1467 | |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1468 | out_msgpool: |
| 1469 | ceph_msgpool_destroy(&osdc->msgpool_op); |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1470 | out_mempool: |
| 1471 | mempool_destroy(osdc->req_mempool); |
| 1472 | out: |
| 1473 | return err; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1474 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1475 | EXPORT_SYMBOL(ceph_osdc_init); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1476 | |
| 1477 | void ceph_osdc_stop(struct ceph_osd_client *osdc) |
| 1478 | { |
| 1479 | cancel_delayed_work_sync(&osdc->timeout_work); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1480 | cancel_delayed_work_sync(&osdc->osds_timeout_work); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1481 | if (osdc->osdmap) { |
| 1482 | ceph_osdmap_destroy(osdc->osdmap); |
| 1483 | osdc->osdmap = NULL; |
| 1484 | } |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1485 | remove_old_osds(osdc, 1); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1486 | mempool_destroy(osdc->req_mempool); |
| 1487 | ceph_msgpool_destroy(&osdc->msgpool_op); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1488 | ceph_msgpool_destroy(&osdc->msgpool_op_reply); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1489 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1490 | EXPORT_SYMBOL(ceph_osdc_stop); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1491 | |
| 1492 | /* |
| 1493 | * Read some contiguous pages. If we cross a stripe boundary, shorten |
| 1494 | * *plen. Return number of bytes read, or error. |
| 1495 | */ |
| 1496 | int ceph_osdc_readpages(struct ceph_osd_client *osdc, |
| 1497 | struct ceph_vino vino, struct ceph_file_layout *layout, |
| 1498 | u64 off, u64 *plen, |
| 1499 | u32 truncate_seq, u64 truncate_size, |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 1500 | struct page **pages, int num_pages, int page_align) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1501 | { |
| 1502 | struct ceph_osd_request *req; |
| 1503 | int rc = 0; |
| 1504 | |
| 1505 | dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino, |
| 1506 | vino.snap, off, *plen); |
| 1507 | req = ceph_osdc_new_request(osdc, layout, vino, off, plen, |
| 1508 | CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ, |
| 1509 | NULL, 0, truncate_seq, truncate_size, NULL, |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 1510 | false, 1, page_align); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1511 | if (!req) |
| 1512 | return -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1513 | |
| 1514 | /* it may be a short read due to an object boundary */ |
| 1515 | req->r_pages = pages; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1516 | |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 1517 | dout("readpages final extent is %llu~%llu (%d pages align %d)\n", |
| 1518 | off, *plen, req->r_num_pages, page_align); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1519 | |
| 1520 | rc = ceph_osdc_start_request(osdc, req, false); |
| 1521 | if (!rc) |
| 1522 | rc = ceph_osdc_wait_request(osdc, req); |
| 1523 | |
| 1524 | ceph_osdc_put_request(req); |
| 1525 | dout("readpages result %d\n", rc); |
| 1526 | return rc; |
| 1527 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1528 | EXPORT_SYMBOL(ceph_osdc_readpages); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1529 | |
| 1530 | /* |
| 1531 | * do a synchronous write on N pages |
| 1532 | */ |
| 1533 | int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino, |
| 1534 | struct ceph_file_layout *layout, |
| 1535 | struct ceph_snap_context *snapc, |
| 1536 | u64 off, u64 len, |
| 1537 | u32 truncate_seq, u64 truncate_size, |
| 1538 | struct timespec *mtime, |
| 1539 | struct page **pages, int num_pages, |
| 1540 | int flags, int do_sync, bool nofail) |
| 1541 | { |
| 1542 | struct ceph_osd_request *req; |
| 1543 | int rc = 0; |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 1544 | int page_align = off & ~PAGE_MASK; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1545 | |
| 1546 | BUG_ON(vino.snap != CEPH_NOSNAP); |
| 1547 | req = ceph_osdc_new_request(osdc, layout, vino, off, &len, |
| 1548 | CEPH_OSD_OP_WRITE, |
| 1549 | flags | CEPH_OSD_FLAG_ONDISK | |
| 1550 | CEPH_OSD_FLAG_WRITE, |
| 1551 | snapc, do_sync, |
| 1552 | truncate_seq, truncate_size, mtime, |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 1553 | nofail, 1, page_align); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1554 | if (!req) |
| 1555 | return -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1556 | |
| 1557 | /* it may be a short write due to an object boundary */ |
| 1558 | req->r_pages = pages; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1559 | dout("writepages %llu~%llu (%d pages)\n", off, len, |
| 1560 | req->r_num_pages); |
| 1561 | |
| 1562 | rc = ceph_osdc_start_request(osdc, req, nofail); |
| 1563 | if (!rc) |
| 1564 | rc = ceph_osdc_wait_request(osdc, req); |
| 1565 | |
| 1566 | ceph_osdc_put_request(req); |
| 1567 | if (rc == 0) |
| 1568 | rc = len; |
| 1569 | dout("writepages result %d\n", rc); |
| 1570 | return rc; |
| 1571 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1572 | EXPORT_SYMBOL(ceph_osdc_writepages); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1573 | |
| 1574 | /* |
| 1575 | * handle incoming message |
| 1576 | */ |
| 1577 | static void dispatch(struct ceph_connection *con, struct ceph_msg *msg) |
| 1578 | { |
| 1579 | struct ceph_osd *osd = con->private; |
Julia Lawall | 32c895e | 2009-11-21 16:53:16 +0100 | [diff] [blame] | 1580 | struct ceph_osd_client *osdc; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1581 | int type = le16_to_cpu(msg->hdr.type); |
| 1582 | |
| 1583 | if (!osd) |
Sage Weil | 4a32f93 | 2010-06-13 10:27:53 -0700 | [diff] [blame] | 1584 | goto out; |
Julia Lawall | 32c895e | 2009-11-21 16:53:16 +0100 | [diff] [blame] | 1585 | osdc = osd->o_osdc; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1586 | |
| 1587 | switch (type) { |
| 1588 | case CEPH_MSG_OSD_MAP: |
| 1589 | ceph_osdc_handle_map(osdc, msg); |
| 1590 | break; |
| 1591 | case CEPH_MSG_OSD_OPREPLY: |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 1592 | handle_reply(osdc, msg, con); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1593 | break; |
| 1594 | |
| 1595 | default: |
| 1596 | pr_err("received unknown message type %d %s\n", type, |
| 1597 | ceph_msg_type_name(type)); |
| 1598 | } |
Sage Weil | 4a32f93 | 2010-06-13 10:27:53 -0700 | [diff] [blame] | 1599 | out: |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1600 | ceph_msg_put(msg); |
| 1601 | } |
| 1602 | |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1603 | /* |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 1604 | * lookup and return message for incoming reply. set up reply message |
| 1605 | * pages. |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1606 | */ |
| 1607 | static struct ceph_msg *get_reply(struct ceph_connection *con, |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 1608 | struct ceph_msg_header *hdr, |
| 1609 | int *skip) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1610 | { |
| 1611 | struct ceph_osd *osd = con->private; |
| 1612 | struct ceph_osd_client *osdc = osd->o_osdc; |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 1613 | struct ceph_msg *m; |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1614 | struct ceph_osd_request *req; |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1615 | int front = le32_to_cpu(hdr->front_len); |
| 1616 | int data_len = le32_to_cpu(hdr->data_len); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1617 | u64 tid; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1618 | |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1619 | tid = le64_to_cpu(hdr->tid); |
| 1620 | mutex_lock(&osdc->request_mutex); |
| 1621 | req = __lookup_request(osdc, tid); |
| 1622 | if (!req) { |
| 1623 | *skip = 1; |
| 1624 | m = NULL; |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1625 | pr_info("get_reply unknown tid %llu from osd%d\n", tid, |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1626 | osd->o_osd); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1627 | goto out; |
| 1628 | } |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1629 | |
| 1630 | if (req->r_con_filling_msg) { |
| 1631 | dout("get_reply revoking msg %p from old con %p\n", |
| 1632 | req->r_reply, req->r_con_filling_msg); |
| 1633 | ceph_con_revoke_message(req->r_con_filling_msg, req->r_reply); |
| 1634 | ceph_con_put(req->r_con_filling_msg); |
Sage Weil | 6f46cb2 | 2010-03-24 21:30:19 -0700 | [diff] [blame] | 1635 | req->r_con_filling_msg = NULL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1636 | } |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 1637 | |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1638 | if (front > req->r_reply->front.iov_len) { |
| 1639 | pr_warning("get_reply front %d > preallocated %d\n", |
| 1640 | front, (int)req->r_reply->front.iov_len); |
Yehuda Sadeh | 34d2376 | 2010-04-06 14:33:58 -0700 | [diff] [blame] | 1641 | m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front, GFP_NOFS); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1642 | if (!m) |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1643 | goto out; |
| 1644 | ceph_msg_put(req->r_reply); |
| 1645 | req->r_reply = m; |
| 1646 | } |
| 1647 | m = ceph_msg_get(req->r_reply); |
| 1648 | |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1649 | if (data_len > 0) { |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 1650 | int want = calc_pages_for(req->r_page_alignment, data_len); |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 1651 | |
| 1652 | if (unlikely(req->r_num_pages < want)) { |
| 1653 | pr_warning("tid %lld reply %d > expected %d pages\n", |
| 1654 | tid, want, m->nr_pages); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1655 | *skip = 1; |
| 1656 | ceph_msg_put(m); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1657 | m = NULL; |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 1658 | goto out; |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1659 | } |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 1660 | m->pages = req->r_pages; |
| 1661 | m->nr_pages = req->r_num_pages; |
Sage Weil | c5c6b19 | 2010-11-09 12:40:00 -0800 | [diff] [blame] | 1662 | m->page_alignment = req->r_page_alignment; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 1663 | #ifdef CONFIG_BLOCK |
| 1664 | m->bio = req->r_bio; |
| 1665 | #endif |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1666 | } |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1667 | *skip = 0; |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1668 | req->r_con_filling_msg = ceph_con_get(con); |
| 1669 | dout("get_reply tid %lld %p\n", tid, m); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 1670 | |
| 1671 | out: |
| 1672 | mutex_unlock(&osdc->request_mutex); |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 1673 | return m; |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1674 | |
| 1675 | } |
| 1676 | |
| 1677 | static struct ceph_msg *alloc_msg(struct ceph_connection *con, |
| 1678 | struct ceph_msg_header *hdr, |
| 1679 | int *skip) |
| 1680 | { |
| 1681 | struct ceph_osd *osd = con->private; |
| 1682 | int type = le16_to_cpu(hdr->type); |
| 1683 | int front = le32_to_cpu(hdr->front_len); |
| 1684 | |
| 1685 | switch (type) { |
| 1686 | case CEPH_MSG_OSD_MAP: |
Yehuda Sadeh | 34d2376 | 2010-04-06 14:33:58 -0700 | [diff] [blame] | 1687 | return ceph_msg_new(type, front, GFP_NOFS); |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 1688 | case CEPH_MSG_OSD_OPREPLY: |
| 1689 | return get_reply(con, hdr, skip); |
| 1690 | default: |
| 1691 | pr_info("alloc_msg unexpected msg type %d from osd%d\n", type, |
| 1692 | osd->o_osd); |
| 1693 | *skip = 1; |
| 1694 | return NULL; |
| 1695 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | /* |
| 1699 | * Wrappers to refcount containing ceph_osd struct |
| 1700 | */ |
| 1701 | static struct ceph_connection *get_osd_con(struct ceph_connection *con) |
| 1702 | { |
| 1703 | struct ceph_osd *osd = con->private; |
| 1704 | if (get_osd(osd)) |
| 1705 | return con; |
| 1706 | return NULL; |
| 1707 | } |
| 1708 | |
| 1709 | static void put_osd_con(struct ceph_connection *con) |
| 1710 | { |
| 1711 | struct ceph_osd *osd = con->private; |
| 1712 | put_osd(osd); |
| 1713 | } |
| 1714 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 1715 | /* |
| 1716 | * authentication |
| 1717 | */ |
| 1718 | static int get_authorizer(struct ceph_connection *con, |
Sage Weil | 213c99e | 2010-08-03 10:25:11 -0700 | [diff] [blame] | 1719 | void **buf, int *len, int *proto, |
| 1720 | void **reply_buf, int *reply_len, int force_new) |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 1721 | { |
| 1722 | struct ceph_osd *o = con->private; |
| 1723 | struct ceph_osd_client *osdc = o->o_osdc; |
| 1724 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
| 1725 | int ret = 0; |
| 1726 | |
| 1727 | if (force_new && o->o_authorizer) { |
| 1728 | ac->ops->destroy_authorizer(ac, o->o_authorizer); |
| 1729 | o->o_authorizer = NULL; |
| 1730 | } |
| 1731 | if (o->o_authorizer == NULL) { |
| 1732 | ret = ac->ops->create_authorizer( |
| 1733 | ac, CEPH_ENTITY_TYPE_OSD, |
| 1734 | &o->o_authorizer, |
| 1735 | &o->o_authorizer_buf, |
| 1736 | &o->o_authorizer_buf_len, |
| 1737 | &o->o_authorizer_reply_buf, |
| 1738 | &o->o_authorizer_reply_buf_len); |
| 1739 | if (ret) |
Sage Weil | 213c99e | 2010-08-03 10:25:11 -0700 | [diff] [blame] | 1740 | return ret; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | *proto = ac->protocol; |
| 1744 | *buf = o->o_authorizer_buf; |
| 1745 | *len = o->o_authorizer_buf_len; |
| 1746 | *reply_buf = o->o_authorizer_reply_buf; |
| 1747 | *reply_len = o->o_authorizer_reply_buf_len; |
| 1748 | return 0; |
| 1749 | } |
| 1750 | |
| 1751 | |
| 1752 | static int verify_authorizer_reply(struct ceph_connection *con, int len) |
| 1753 | { |
| 1754 | struct ceph_osd *o = con->private; |
| 1755 | struct ceph_osd_client *osdc = o->o_osdc; |
| 1756 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
| 1757 | |
| 1758 | return ac->ops->verify_authorizer_reply(ac, o->o_authorizer, len); |
| 1759 | } |
| 1760 | |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 1761 | static int invalidate_authorizer(struct ceph_connection *con) |
| 1762 | { |
| 1763 | struct ceph_osd *o = con->private; |
| 1764 | struct ceph_osd_client *osdc = o->o_osdc; |
| 1765 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
| 1766 | |
| 1767 | if (ac->ops->invalidate_authorizer) |
| 1768 | ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD); |
| 1769 | |
| 1770 | return ceph_monc_validate_auth(&osdc->client->monc); |
| 1771 | } |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 1772 | |
Tobias Klauser | 9e32789 | 2010-05-20 10:40:19 +0200 | [diff] [blame] | 1773 | static const struct ceph_connection_operations osd_con_ops = { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1774 | .get = get_osd_con, |
| 1775 | .put = put_osd_con, |
| 1776 | .dispatch = dispatch, |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 1777 | .get_authorizer = get_authorizer, |
| 1778 | .verify_authorizer_reply = verify_authorizer_reply, |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 1779 | .invalidate_authorizer = invalidate_authorizer, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1780 | .alloc_msg = alloc_msg, |
Sage Weil | 81b024e | 2009-10-09 10:29:18 -0700 | [diff] [blame] | 1781 | .fault = osd_reset, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1782 | }; |