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