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