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