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