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