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