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