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