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