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