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