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