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