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