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