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