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 | |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 15 | #include <linux/ceph/ceph_features.h> |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 16 | #include <linux/ceph/libceph.h> |
| 17 | #include <linux/ceph/osd_client.h> |
| 18 | #include <linux/ceph/messenger.h> |
| 19 | #include <linux/ceph/decode.h> |
| 20 | #include <linux/ceph/auth.h> |
| 21 | #include <linux/ceph/pagelist.h> |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 22 | |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 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 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 29 | /* |
| 30 | * Implement client access to distributed object storage cluster. |
| 31 | * |
| 32 | * All data objects are stored within a cluster/cloud of OSDs, or |
| 33 | * "object storage devices." (Note that Ceph OSDs have _nothing_ to |
| 34 | * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply |
| 35 | * remote daemons serving up and coordinating consistent and safe |
| 36 | * access to storage. |
| 37 | * |
| 38 | * Cluster membership and the mapping of data objects onto storage devices |
| 39 | * are described by the osd map. |
| 40 | * |
| 41 | * We keep track of pending OSD requests (read, write), resubmit |
| 42 | * requests to different OSDs when the cluster topology/data layout |
| 43 | * change, or retry the affected requests when the communications |
| 44 | * channel with an OSD is reset. |
| 45 | */ |
| 46 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 47 | static void link_request(struct ceph_osd *osd, struct ceph_osd_request *req); |
| 48 | static void unlink_request(struct ceph_osd *osd, struct ceph_osd_request *req); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 49 | static void link_linger(struct ceph_osd *osd, |
| 50 | struct ceph_osd_linger_request *lreq); |
| 51 | static void unlink_linger(struct ceph_osd *osd, |
| 52 | struct ceph_osd_linger_request *lreq); |
Ilya Dryomov | a02a946 | 2017-06-19 12:18:05 +0200 | [diff] [blame] | 53 | static void clear_backoffs(struct ceph_osd *osd); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 54 | |
| 55 | #if 1 |
| 56 | static inline bool rwsem_is_wrlocked(struct rw_semaphore *sem) |
| 57 | { |
| 58 | bool wrlocked = true; |
| 59 | |
| 60 | if (unlikely(down_read_trylock(sem))) { |
| 61 | wrlocked = false; |
| 62 | up_read(sem); |
| 63 | } |
| 64 | |
| 65 | return wrlocked; |
| 66 | } |
| 67 | static inline void verify_osdc_locked(struct ceph_osd_client *osdc) |
| 68 | { |
| 69 | WARN_ON(!rwsem_is_locked(&osdc->lock)); |
| 70 | } |
| 71 | static inline void verify_osdc_wrlocked(struct ceph_osd_client *osdc) |
| 72 | { |
| 73 | WARN_ON(!rwsem_is_wrlocked(&osdc->lock)); |
| 74 | } |
| 75 | static inline void verify_osd_locked(struct ceph_osd *osd) |
| 76 | { |
| 77 | struct ceph_osd_client *osdc = osd->o_osdc; |
| 78 | |
| 79 | WARN_ON(!(mutex_is_locked(&osd->lock) && |
| 80 | rwsem_is_locked(&osdc->lock)) && |
| 81 | !rwsem_is_wrlocked(&osdc->lock)); |
| 82 | } |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 83 | static inline void verify_lreq_locked(struct ceph_osd_linger_request *lreq) |
| 84 | { |
| 85 | WARN_ON(!mutex_is_locked(&lreq->lock)); |
| 86 | } |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 87 | #else |
| 88 | static inline void verify_osdc_locked(struct ceph_osd_client *osdc) { } |
| 89 | static inline void verify_osdc_wrlocked(struct ceph_osd_client *osdc) { } |
| 90 | static inline void verify_osd_locked(struct ceph_osd *osd) { } |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 91 | static inline void verify_lreq_locked(struct ceph_osd_linger_request *lreq) { } |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 92 | #endif |
| 93 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 94 | /* |
| 95 | * calculate the mapping of a file extent onto an object, and fill out the |
| 96 | * request accordingly. shorten extent as necessary if it crosses an |
| 97 | * object boundary. |
| 98 | * |
| 99 | * fill osd op in request message. |
| 100 | */ |
Alex Elder | dbe0fc4 | 2013-02-15 22:10:17 -0600 | [diff] [blame] | 101 | 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] | 102 | u64 *objnum, u64 *objoff, u64 *objlen) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 103 | { |
Alex Elder | 60e56f1 | 2013-02-15 11:42:29 -0600 | [diff] [blame] | 104 | u64 orig_len = *plen; |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame] | 105 | int r; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 106 | |
Alex Elder | 60e56f1 | 2013-02-15 11:42:29 -0600 | [diff] [blame] | 107 | /* object extent? */ |
Alex Elder | 75d1c94 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 108 | r = ceph_calc_file_object_mapping(layout, off, orig_len, objnum, |
| 109 | objoff, objlen); |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame] | 110 | if (r < 0) |
| 111 | return r; |
Alex Elder | 75d1c94 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 112 | if (*objlen < orig_len) { |
| 113 | *plen = *objlen; |
Alex Elder | 60e56f1 | 2013-02-15 11:42:29 -0600 | [diff] [blame] | 114 | dout(" skipping last %llu, final file extent %llu~%llu\n", |
| 115 | orig_len - *plen, off, *plen); |
| 116 | } |
| 117 | |
Alex Elder | 75d1c94 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 118 | dout("calc_layout objnum=%llx %llu~%llu\n", *objnum, *objoff, *objlen); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 119 | |
Alex Elder | 3ff5f38 | 2013-02-15 22:10:17 -0600 | [diff] [blame] | 120 | return 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Alex Elder | c54d47b | 2013-04-03 01:28:57 -0500 | [diff] [blame] | 123 | static void ceph_osd_data_init(struct ceph_osd_data *osd_data) |
| 124 | { |
| 125 | memset(osd_data, 0, sizeof (*osd_data)); |
| 126 | osd_data->type = CEPH_OSD_DATA_TYPE_NONE; |
| 127 | } |
| 128 | |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 129 | 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] | 130 | struct page **pages, u64 length, u32 alignment, |
| 131 | bool pages_from_pool, bool own_pages) |
| 132 | { |
| 133 | osd_data->type = CEPH_OSD_DATA_TYPE_PAGES; |
| 134 | osd_data->pages = pages; |
| 135 | osd_data->length = length; |
| 136 | osd_data->alignment = alignment; |
| 137 | osd_data->pages_from_pool = pages_from_pool; |
| 138 | osd_data->own_pages = own_pages; |
| 139 | } |
Alex Elder | 43bfe5d | 2013-04-03 01:28:57 -0500 | [diff] [blame] | 140 | |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 141 | 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] | 142 | struct ceph_pagelist *pagelist) |
| 143 | { |
| 144 | osd_data->type = CEPH_OSD_DATA_TYPE_PAGELIST; |
| 145 | osd_data->pagelist = pagelist; |
| 146 | } |
Alex Elder | 43bfe5d | 2013-04-03 01:28:57 -0500 | [diff] [blame] | 147 | |
| 148 | #ifdef CONFIG_BLOCK |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 149 | 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] | 150 | struct bio *bio, size_t bio_length) |
| 151 | { |
| 152 | osd_data->type = CEPH_OSD_DATA_TYPE_BIO; |
| 153 | osd_data->bio = bio; |
| 154 | osd_data->bio_length = bio_length; |
| 155 | } |
Alex Elder | 43bfe5d | 2013-04-03 01:28:57 -0500 | [diff] [blame] | 156 | #endif /* CONFIG_BLOCK */ |
| 157 | |
Ioana Ciornei | 8a703a3 | 2015-10-22 18:06:07 +0300 | [diff] [blame] | 158 | #define osd_req_op_data(oreq, whch, typ, fld) \ |
| 159 | ({ \ |
| 160 | struct ceph_osd_request *__oreq = (oreq); \ |
| 161 | unsigned int __whch = (whch); \ |
| 162 | BUG_ON(__whch >= __oreq->r_num_ops); \ |
| 163 | &__oreq->r_ops[__whch].typ.fld; \ |
| 164 | }) |
Alex Elder | 863c7eb | 2013-04-15 14:50:36 -0500 | [diff] [blame] | 165 | |
Alex Elder | 4971977 | 2013-02-11 12:33:24 -0600 | [diff] [blame] | 166 | static struct ceph_osd_data * |
| 167 | osd_req_op_raw_data_in(struct ceph_osd_request *osd_req, unsigned int which) |
| 168 | { |
| 169 | BUG_ON(which >= osd_req->r_num_ops); |
| 170 | |
| 171 | return &osd_req->r_ops[which].raw_data_in; |
| 172 | } |
| 173 | |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 174 | struct ceph_osd_data * |
| 175 | osd_req_op_extent_osd_data(struct ceph_osd_request *osd_req, |
Alex Elder | 406e2c9 | 2013-04-15 14:50:36 -0500 | [diff] [blame] | 176 | unsigned int which) |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 177 | { |
Alex Elder | 863c7eb | 2013-04-15 14:50:36 -0500 | [diff] [blame] | 178 | return osd_req_op_data(osd_req, which, extent, osd_data); |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 179 | } |
| 180 | EXPORT_SYMBOL(osd_req_op_extent_osd_data); |
| 181 | |
Alex Elder | 4971977 | 2013-02-11 12:33:24 -0600 | [diff] [blame] | 182 | void osd_req_op_raw_data_in_pages(struct ceph_osd_request *osd_req, |
| 183 | unsigned int which, struct page **pages, |
| 184 | u64 length, u32 alignment, |
| 185 | bool pages_from_pool, bool own_pages) |
| 186 | { |
| 187 | struct ceph_osd_data *osd_data; |
| 188 | |
| 189 | osd_data = osd_req_op_raw_data_in(osd_req, which); |
| 190 | ceph_osd_data_pages_init(osd_data, pages, length, alignment, |
| 191 | pages_from_pool, own_pages); |
| 192 | } |
| 193 | EXPORT_SYMBOL(osd_req_op_raw_data_in_pages); |
| 194 | |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 195 | 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] | 196 | unsigned int which, struct page **pages, |
| 197 | u64 length, u32 alignment, |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 198 | bool pages_from_pool, bool own_pages) |
| 199 | { |
| 200 | struct ceph_osd_data *osd_data; |
| 201 | |
Alex Elder | 863c7eb | 2013-04-15 14:50:36 -0500 | [diff] [blame] | 202 | osd_data = osd_req_op_data(osd_req, which, extent, osd_data); |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 203 | ceph_osd_data_pages_init(osd_data, pages, length, alignment, |
| 204 | pages_from_pool, own_pages); |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 205 | } |
| 206 | EXPORT_SYMBOL(osd_req_op_extent_osd_data_pages); |
| 207 | |
| 208 | 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] | 209 | unsigned int which, struct ceph_pagelist *pagelist) |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 210 | { |
| 211 | struct ceph_osd_data *osd_data; |
| 212 | |
Alex Elder | 863c7eb | 2013-04-15 14:50:36 -0500 | [diff] [blame] | 213 | osd_data = osd_req_op_data(osd_req, which, extent, osd_data); |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 214 | ceph_osd_data_pagelist_init(osd_data, pagelist); |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 215 | } |
| 216 | EXPORT_SYMBOL(osd_req_op_extent_osd_data_pagelist); |
| 217 | |
| 218 | #ifdef CONFIG_BLOCK |
| 219 | 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] | 220 | unsigned int which, struct bio *bio, size_t bio_length) |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 221 | { |
| 222 | struct ceph_osd_data *osd_data; |
Alex Elder | 863c7eb | 2013-04-15 14:50:36 -0500 | [diff] [blame] | 223 | |
| 224 | osd_data = osd_req_op_data(osd_req, which, extent, osd_data); |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 225 | ceph_osd_data_bio_init(osd_data, bio, bio_length); |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 226 | } |
| 227 | EXPORT_SYMBOL(osd_req_op_extent_osd_data_bio); |
| 228 | #endif /* CONFIG_BLOCK */ |
| 229 | |
| 230 | static void osd_req_op_cls_request_info_pagelist( |
| 231 | struct ceph_osd_request *osd_req, |
| 232 | unsigned int which, struct ceph_pagelist *pagelist) |
| 233 | { |
| 234 | struct ceph_osd_data *osd_data; |
| 235 | |
Alex Elder | 863c7eb | 2013-04-15 14:50:36 -0500 | [diff] [blame] | 236 | osd_data = osd_req_op_data(osd_req, which, cls, request_info); |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 237 | ceph_osd_data_pagelist_init(osd_data, pagelist); |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 238 | } |
| 239 | |
Alex Elder | 04017e2 | 2013-04-05 14:46:02 -0500 | [diff] [blame] | 240 | void osd_req_op_cls_request_data_pagelist( |
| 241 | struct ceph_osd_request *osd_req, |
| 242 | unsigned int which, struct ceph_pagelist *pagelist) |
| 243 | { |
| 244 | struct ceph_osd_data *osd_data; |
| 245 | |
Alex Elder | 863c7eb | 2013-04-15 14:50:36 -0500 | [diff] [blame] | 246 | osd_data = osd_req_op_data(osd_req, which, cls, request_data); |
Alex Elder | 04017e2 | 2013-04-05 14:46:02 -0500 | [diff] [blame] | 247 | ceph_osd_data_pagelist_init(osd_data, pagelist); |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 248 | osd_req->r_ops[which].cls.indata_len += pagelist->length; |
| 249 | osd_req->r_ops[which].indata_len += pagelist->length; |
Alex Elder | 04017e2 | 2013-04-05 14:46:02 -0500 | [diff] [blame] | 250 | } |
| 251 | EXPORT_SYMBOL(osd_req_op_cls_request_data_pagelist); |
| 252 | |
Alex Elder | 6c57b55 | 2013-04-19 15:34:49 -0500 | [diff] [blame] | 253 | void osd_req_op_cls_request_data_pages(struct ceph_osd_request *osd_req, |
| 254 | unsigned int which, struct page **pages, u64 length, |
| 255 | u32 alignment, bool pages_from_pool, bool own_pages) |
| 256 | { |
| 257 | struct ceph_osd_data *osd_data; |
| 258 | |
| 259 | osd_data = osd_req_op_data(osd_req, which, cls, request_data); |
| 260 | ceph_osd_data_pages_init(osd_data, pages, length, alignment, |
| 261 | pages_from_pool, own_pages); |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 262 | osd_req->r_ops[which].cls.indata_len += length; |
| 263 | osd_req->r_ops[which].indata_len += length; |
Alex Elder | 6c57b55 | 2013-04-19 15:34:49 -0500 | [diff] [blame] | 264 | } |
| 265 | EXPORT_SYMBOL(osd_req_op_cls_request_data_pages); |
| 266 | |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 267 | void osd_req_op_cls_response_data_pages(struct ceph_osd_request *osd_req, |
| 268 | unsigned int which, struct page **pages, u64 length, |
| 269 | u32 alignment, bool pages_from_pool, bool own_pages) |
| 270 | { |
| 271 | struct ceph_osd_data *osd_data; |
| 272 | |
Alex Elder | 863c7eb | 2013-04-15 14:50:36 -0500 | [diff] [blame] | 273 | osd_data = osd_req_op_data(osd_req, which, cls, response_data); |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 274 | ceph_osd_data_pages_init(osd_data, pages, length, alignment, |
| 275 | pages_from_pool, own_pages); |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 276 | } |
| 277 | EXPORT_SYMBOL(osd_req_op_cls_response_data_pages); |
| 278 | |
Alex Elder | 23c08a9cb | 2013-04-03 01:28:58 -0500 | [diff] [blame] | 279 | static u64 ceph_osd_data_length(struct ceph_osd_data *osd_data) |
| 280 | { |
| 281 | switch (osd_data->type) { |
| 282 | case CEPH_OSD_DATA_TYPE_NONE: |
| 283 | return 0; |
| 284 | case CEPH_OSD_DATA_TYPE_PAGES: |
| 285 | return osd_data->length; |
| 286 | case CEPH_OSD_DATA_TYPE_PAGELIST: |
| 287 | return (u64)osd_data->pagelist->length; |
| 288 | #ifdef CONFIG_BLOCK |
| 289 | case CEPH_OSD_DATA_TYPE_BIO: |
| 290 | return (u64)osd_data->bio_length; |
| 291 | #endif /* CONFIG_BLOCK */ |
| 292 | default: |
| 293 | WARN(true, "unrecognized data type %d\n", (int)osd_data->type); |
| 294 | return 0; |
| 295 | } |
| 296 | } |
| 297 | |
Alex Elder | c54d47b | 2013-04-03 01:28:57 -0500 | [diff] [blame] | 298 | static void ceph_osd_data_release(struct ceph_osd_data *osd_data) |
| 299 | { |
Alex Elder | 5476492 | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 300 | 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] | 301 | int num_pages; |
| 302 | |
| 303 | num_pages = calc_pages_for((u64)osd_data->alignment, |
| 304 | (u64)osd_data->length); |
| 305 | ceph_release_page_vector(osd_data->pages, num_pages); |
| 306 | } |
Alex Elder | 5476492 | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 307 | ceph_osd_data_init(osd_data); |
| 308 | } |
| 309 | |
| 310 | static void osd_req_op_data_release(struct ceph_osd_request *osd_req, |
| 311 | unsigned int which) |
| 312 | { |
| 313 | struct ceph_osd_req_op *op; |
| 314 | |
| 315 | BUG_ON(which >= osd_req->r_num_ops); |
| 316 | op = &osd_req->r_ops[which]; |
| 317 | |
| 318 | switch (op->op) { |
| 319 | case CEPH_OSD_OP_READ: |
| 320 | case CEPH_OSD_OP_WRITE: |
Ilya Dryomov | e30b757 | 2015-10-07 17:27:17 +0200 | [diff] [blame] | 321 | case CEPH_OSD_OP_WRITEFULL: |
Alex Elder | 5476492 | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 322 | ceph_osd_data_release(&op->extent.osd_data); |
| 323 | break; |
| 324 | case CEPH_OSD_OP_CALL: |
| 325 | ceph_osd_data_release(&op->cls.request_info); |
Alex Elder | 04017e2 | 2013-04-05 14:46:02 -0500 | [diff] [blame] | 326 | ceph_osd_data_release(&op->cls.request_data); |
Alex Elder | 5476492 | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 327 | ceph_osd_data_release(&op->cls.response_data); |
| 328 | break; |
Yan, Zheng | d74b50b | 2014-11-12 14:00:43 +0800 | [diff] [blame] | 329 | case CEPH_OSD_OP_SETXATTR: |
| 330 | case CEPH_OSD_OP_CMPXATTR: |
| 331 | ceph_osd_data_release(&op->xattr.osd_data); |
| 332 | break; |
Yan, Zheng | 66ba609 | 2015-04-27 11:02:35 +0800 | [diff] [blame] | 333 | case CEPH_OSD_OP_STAT: |
| 334 | ceph_osd_data_release(&op->raw_data_in); |
| 335 | break; |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 336 | case CEPH_OSD_OP_NOTIFY_ACK: |
| 337 | ceph_osd_data_release(&op->notify_ack.request_data); |
| 338 | break; |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 339 | case CEPH_OSD_OP_NOTIFY: |
| 340 | ceph_osd_data_release(&op->notify.request_data); |
| 341 | ceph_osd_data_release(&op->notify.response_data); |
| 342 | break; |
Douglas Fuller | a4ed38d | 2015-07-17 13:18:07 -0700 | [diff] [blame] | 343 | case CEPH_OSD_OP_LIST_WATCHERS: |
| 344 | ceph_osd_data_release(&op->list_watchers.response_data); |
| 345 | break; |
Alex Elder | 5476492 | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 346 | default: |
| 347 | break; |
| 348 | } |
Alex Elder | c54d47b | 2013-04-03 01:28:57 -0500 | [diff] [blame] | 349 | } |
| 350 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 351 | /* |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 352 | * Assumes @t is zero-initialized. |
| 353 | */ |
| 354 | static void target_init(struct ceph_osd_request_target *t) |
| 355 | { |
| 356 | ceph_oid_init(&t->base_oid); |
| 357 | ceph_oloc_init(&t->base_oloc); |
| 358 | ceph_oid_init(&t->target_oid); |
| 359 | ceph_oloc_init(&t->target_oloc); |
| 360 | |
| 361 | ceph_osds_init(&t->acting); |
| 362 | ceph_osds_init(&t->up); |
| 363 | t->size = -1; |
| 364 | t->min_size = -1; |
| 365 | |
| 366 | t->osd = CEPH_HOMELESS_OSD; |
| 367 | } |
| 368 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 369 | static void target_copy(struct ceph_osd_request_target *dest, |
| 370 | const struct ceph_osd_request_target *src) |
| 371 | { |
| 372 | ceph_oid_copy(&dest->base_oid, &src->base_oid); |
| 373 | ceph_oloc_copy(&dest->base_oloc, &src->base_oloc); |
| 374 | ceph_oid_copy(&dest->target_oid, &src->target_oid); |
| 375 | ceph_oloc_copy(&dest->target_oloc, &src->target_oloc); |
| 376 | |
| 377 | dest->pgid = src->pgid; /* struct */ |
Ilya Dryomov | dc98ff7 | 2017-06-15 16:30:53 +0200 | [diff] [blame] | 378 | dest->spgid = src->spgid; /* struct */ |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 379 | dest->pg_num = src->pg_num; |
| 380 | dest->pg_num_mask = src->pg_num_mask; |
| 381 | ceph_osds_copy(&dest->acting, &src->acting); |
| 382 | ceph_osds_copy(&dest->up, &src->up); |
| 383 | dest->size = src->size; |
| 384 | dest->min_size = src->min_size; |
| 385 | dest->sort_bitwise = src->sort_bitwise; |
| 386 | |
| 387 | dest->flags = src->flags; |
| 388 | dest->paused = src->paused; |
| 389 | |
Ilya Dryomov | 04c7d78 | 2017-06-15 16:30:55 +0200 | [diff] [blame] | 390 | dest->epoch = src->epoch; |
Ilya Dryomov | dc93e0e | 2017-06-05 14:45:00 +0200 | [diff] [blame] | 391 | dest->last_force_resend = src->last_force_resend; |
| 392 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 393 | dest->osd = src->osd; |
| 394 | } |
| 395 | |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 396 | static void target_destroy(struct ceph_osd_request_target *t) |
| 397 | { |
| 398 | ceph_oid_destroy(&t->base_oid); |
Yan, Zheng | 30c156d | 2016-02-14 11:24:31 +0800 | [diff] [blame] | 399 | ceph_oloc_destroy(&t->base_oloc); |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 400 | ceph_oid_destroy(&t->target_oid); |
Yan, Zheng | 30c156d | 2016-02-14 11:24:31 +0800 | [diff] [blame] | 401 | ceph_oloc_destroy(&t->target_oloc); |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /* |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 405 | * requests |
| 406 | */ |
Ilya Dryomov | 3540bfd | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 407 | static void request_release_checks(struct ceph_osd_request *req) |
| 408 | { |
| 409 | WARN_ON(!RB_EMPTY_NODE(&req->r_node)); |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 410 | WARN_ON(!RB_EMPTY_NODE(&req->r_mc_node)); |
Ilya Dryomov | 3540bfd | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 411 | WARN_ON(!list_empty(&req->r_unsafe_item)); |
| 412 | WARN_ON(req->r_osd); |
| 413 | } |
| 414 | |
Ilya Dryomov | 9e94af2 | 2014-06-20 14:14:42 +0400 | [diff] [blame] | 415 | static void ceph_osdc_release_request(struct kref *kref) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 416 | { |
Ilya Dryomov | 9e94af2 | 2014-06-20 14:14:42 +0400 | [diff] [blame] | 417 | struct ceph_osd_request *req = container_of(kref, |
| 418 | struct ceph_osd_request, r_kref); |
Alex Elder | 5476492 | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 419 | unsigned int which; |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 420 | |
Ilya Dryomov | 9e94af2 | 2014-06-20 14:14:42 +0400 | [diff] [blame] | 421 | dout("%s %p (r_request %p r_reply %p)\n", __func__, req, |
| 422 | req->r_request, req->r_reply); |
Ilya Dryomov | 3540bfd | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 423 | request_release_checks(req); |
Ilya Dryomov | 9e94af2 | 2014-06-20 14:14:42 +0400 | [diff] [blame] | 424 | |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 425 | if (req->r_request) |
| 426 | ceph_msg_put(req->r_request); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 427 | if (req->r_reply) |
Alex Elder | ab8cb34 | 2012-06-04 14:43:32 -0500 | [diff] [blame] | 428 | ceph_msg_put(req->r_reply); |
Alex Elder | 0fff87e | 2013-02-14 12:16:43 -0600 | [diff] [blame] | 429 | |
Alex Elder | 5476492 | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 430 | for (which = 0; which < req->r_num_ops; which++) |
| 431 | osd_req_op_data_release(req, which); |
Alex Elder | 0fff87e | 2013-02-14 12:16:43 -0600 | [diff] [blame] | 432 | |
Ilya Dryomov | a66dd38 | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 433 | target_destroy(&req->r_t); |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 434 | ceph_put_snap_context(req->r_snapc); |
Ilya Dryomov | d30291b | 2016-04-29 19:54:20 +0200 | [diff] [blame] | 435 | |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 436 | if (req->r_mempool) |
| 437 | mempool_free(req, req->r_osdc->req_mempool); |
Ilya Dryomov | 3f1af42 | 2016-02-09 17:50:15 +0100 | [diff] [blame] | 438 | else if (req->r_num_ops <= CEPH_OSD_SLAB_OPS) |
Alex Elder | 5522ae0 | 2013-05-01 12:43:04 -0500 | [diff] [blame] | 439 | kmem_cache_free(ceph_osd_request_cache, req); |
Ilya Dryomov | 3f1af42 | 2016-02-09 17:50:15 +0100 | [diff] [blame] | 440 | else |
| 441 | kfree(req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 442 | } |
Ilya Dryomov | 9e94af2 | 2014-06-20 14:14:42 +0400 | [diff] [blame] | 443 | |
| 444 | void ceph_osdc_get_request(struct ceph_osd_request *req) |
| 445 | { |
| 446 | dout("%s %p (was %d)\n", __func__, req, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 447 | kref_read(&req->r_kref)); |
Ilya Dryomov | 9e94af2 | 2014-06-20 14:14:42 +0400 | [diff] [blame] | 448 | kref_get(&req->r_kref); |
| 449 | } |
| 450 | EXPORT_SYMBOL(ceph_osdc_get_request); |
| 451 | |
| 452 | void ceph_osdc_put_request(struct ceph_osd_request *req) |
| 453 | { |
Ilya Dryomov | 3ed97d6 | 2016-04-26 15:05:29 +0200 | [diff] [blame] | 454 | if (req) { |
| 455 | dout("%s %p (was %d)\n", __func__, req, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 456 | kref_read(&req->r_kref)); |
Ilya Dryomov | 3ed97d6 | 2016-04-26 15:05:29 +0200 | [diff] [blame] | 457 | kref_put(&req->r_kref, ceph_osdc_release_request); |
| 458 | } |
Ilya Dryomov | 9e94af2 | 2014-06-20 14:14:42 +0400 | [diff] [blame] | 459 | } |
| 460 | EXPORT_SYMBOL(ceph_osdc_put_request); |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 461 | |
Ilya Dryomov | 3540bfd | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 462 | static void request_init(struct ceph_osd_request *req) |
| 463 | { |
| 464 | /* req only, each op is zeroed in _osd_req_op_init() */ |
| 465 | memset(req, 0, sizeof(*req)); |
| 466 | |
| 467 | kref_init(&req->r_kref); |
| 468 | init_completion(&req->r_completion); |
Ilya Dryomov | 3540bfd | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 469 | RB_CLEAR_NODE(&req->r_node); |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 470 | RB_CLEAR_NODE(&req->r_mc_node); |
Ilya Dryomov | 3540bfd | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 471 | INIT_LIST_HEAD(&req->r_unsafe_item); |
| 472 | |
| 473 | target_init(&req->r_t); |
| 474 | } |
| 475 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 476 | /* |
| 477 | * This is ugly, but it allows us to reuse linger registration and ping |
| 478 | * requests, keeping the structure of the code around send_linger{_ping}() |
| 479 | * reasonable. Setting up a min_nr=2 mempool for each linger request |
| 480 | * and dealing with copying ops (this blasts req only, watch op remains |
| 481 | * intact) isn't any better. |
| 482 | */ |
| 483 | static void request_reinit(struct ceph_osd_request *req) |
| 484 | { |
| 485 | struct ceph_osd_client *osdc = req->r_osdc; |
| 486 | bool mempool = req->r_mempool; |
| 487 | unsigned int num_ops = req->r_num_ops; |
| 488 | u64 snapid = req->r_snapid; |
| 489 | struct ceph_snap_context *snapc = req->r_snapc; |
| 490 | bool linger = req->r_linger; |
| 491 | struct ceph_msg *request_msg = req->r_request; |
| 492 | struct ceph_msg *reply_msg = req->r_reply; |
| 493 | |
| 494 | dout("%s req %p\n", __func__, req); |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 495 | WARN_ON(kref_read(&req->r_kref) != 1); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 496 | request_release_checks(req); |
| 497 | |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 498 | WARN_ON(kref_read(&request_msg->kref) != 1); |
| 499 | WARN_ON(kref_read(&reply_msg->kref) != 1); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 500 | target_destroy(&req->r_t); |
| 501 | |
| 502 | request_init(req); |
| 503 | req->r_osdc = osdc; |
| 504 | req->r_mempool = mempool; |
| 505 | req->r_num_ops = num_ops; |
| 506 | req->r_snapid = snapid; |
| 507 | req->r_snapc = snapc; |
| 508 | req->r_linger = linger; |
| 509 | req->r_request = request_msg; |
| 510 | req->r_reply = reply_msg; |
| 511 | } |
| 512 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 513 | 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] | 514 | struct ceph_snap_context *snapc, |
Sage Weil | 1b83bef | 2013-02-25 16:11:12 -0800 | [diff] [blame] | 515 | unsigned int num_ops, |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 516 | bool use_mempool, |
Alex Elder | 54a5400 | 2012-11-13 21:11:15 -0600 | [diff] [blame] | 517 | gfp_t gfp_flags) |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 518 | { |
| 519 | struct ceph_osd_request *req; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 520 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 521 | if (use_mempool) { |
Ilya Dryomov | 3f1af42 | 2016-02-09 17:50:15 +0100 | [diff] [blame] | 522 | BUG_ON(num_ops > CEPH_OSD_SLAB_OPS); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 523 | req = mempool_alloc(osdc->req_mempool, gfp_flags); |
Ilya Dryomov | 3f1af42 | 2016-02-09 17:50:15 +0100 | [diff] [blame] | 524 | } else if (num_ops <= CEPH_OSD_SLAB_OPS) { |
| 525 | req = kmem_cache_alloc(ceph_osd_request_cache, gfp_flags); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 526 | } else { |
Ilya Dryomov | 3f1af42 | 2016-02-09 17:50:15 +0100 | [diff] [blame] | 527 | BUG_ON(num_ops > CEPH_OSD_MAX_OPS); |
| 528 | req = kmalloc(sizeof(*req) + num_ops * sizeof(req->r_ops[0]), |
| 529 | gfp_flags); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 530 | } |
Ilya Dryomov | 3f1af42 | 2016-02-09 17:50:15 +0100 | [diff] [blame] | 531 | if (unlikely(!req)) |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 532 | return NULL; |
| 533 | |
Ilya Dryomov | 3540bfd | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 534 | request_init(req); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 535 | req->r_osdc = osdc; |
| 536 | req->r_mempool = use_mempool; |
Alex Elder | 7952873 | 2013-04-03 21:32:51 -0500 | [diff] [blame] | 537 | req->r_num_ops = num_ops; |
Ilya Dryomov | 8412728 | 2016-04-26 15:39:47 +0200 | [diff] [blame] | 538 | req->r_snapid = CEPH_NOSNAP; |
| 539 | req->r_snapc = ceph_get_snap_context(snapc); |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 540 | |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 541 | dout("%s req %p\n", __func__, req); |
| 542 | return req; |
| 543 | } |
| 544 | EXPORT_SYMBOL(ceph_osdc_alloc_request); |
Ilya Dryomov | 3f1af42 | 2016-02-09 17:50:15 +0100 | [diff] [blame] | 545 | |
Ilya Dryomov | 2e59ffd | 2017-06-15 16:30:53 +0200 | [diff] [blame] | 546 | static int ceph_oloc_encoding_size(const struct ceph_object_locator *oloc) |
Yan, Zheng | 30c156d | 2016-02-14 11:24:31 +0800 | [diff] [blame] | 547 | { |
| 548 | return 8 + 4 + 4 + 4 + (oloc->pool_ns ? oloc->pool_ns->len : 0); |
| 549 | } |
| 550 | |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 551 | int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp) |
| 552 | { |
| 553 | struct ceph_osd_client *osdc = req->r_osdc; |
| 554 | struct ceph_msg *msg; |
| 555 | int msg_size; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 556 | |
Ilya Dryomov | d30291b | 2016-04-29 19:54:20 +0200 | [diff] [blame] | 557 | WARN_ON(ceph_oid_empty(&req->r_base_oid)); |
Yan, Zheng | 30c156d | 2016-02-14 11:24:31 +0800 | [diff] [blame] | 558 | WARN_ON(ceph_oloc_empty(&req->r_base_oloc)); |
Ilya Dryomov | d30291b | 2016-04-29 19:54:20 +0200 | [diff] [blame] | 559 | |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 560 | /* create request message */ |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 561 | msg_size = CEPH_ENCODING_START_BLK_LEN + |
| 562 | CEPH_PGID_ENCODING_LEN + 1; /* spgid */ |
| 563 | msg_size += 4 + 4 + 4; /* hash, osdmap_epoch, flags */ |
| 564 | msg_size += CEPH_ENCODING_START_BLK_LEN + |
| 565 | sizeof(struct ceph_osd_reqid); /* reqid */ |
| 566 | msg_size += sizeof(struct ceph_blkin_trace_info); /* trace */ |
| 567 | msg_size += 4 + sizeof(struct ceph_timespec); /* client_inc, mtime */ |
Yan, Zheng | 30c156d | 2016-02-14 11:24:31 +0800 | [diff] [blame] | 568 | msg_size += CEPH_ENCODING_START_BLK_LEN + |
| 569 | ceph_oloc_encoding_size(&req->r_base_oloc); /* oloc */ |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 570 | msg_size += 4 + req->r_base_oid.name_len; /* oid */ |
| 571 | msg_size += 2 + req->r_num_ops * sizeof(struct ceph_osd_op); |
Ilya Dryomov | ae458f5 | 2016-02-11 13:09:15 +0100 | [diff] [blame] | 572 | msg_size += 8; /* snapid */ |
| 573 | msg_size += 8; /* snap_seq */ |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 574 | msg_size += 4 + 8 * (req->r_snapc ? req->r_snapc->num_snaps : 0); |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 575 | msg_size += 4 + 8; /* retry_attempt, features */ |
Ilya Dryomov | ae458f5 | 2016-02-11 13:09:15 +0100 | [diff] [blame] | 576 | |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 577 | if (req->r_mempool) |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 578 | msg = ceph_msgpool_get(&osdc->msgpool_op, 0); |
| 579 | else |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 580 | msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp, true); |
| 581 | if (!msg) |
| 582 | return -ENOMEM; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 583 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 584 | memset(msg->front.iov_base, 0, msg->front.iov_len); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 585 | req->r_request = msg; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 586 | |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 587 | /* create reply message */ |
| 588 | msg_size = OSD_OPREPLY_FRONT_LEN; |
Ilya Dryomov | 711da55 | 2016-04-27 18:32:56 +0200 | [diff] [blame] | 589 | msg_size += req->r_base_oid.name_len; |
| 590 | msg_size += req->r_num_ops * sizeof(struct ceph_osd_op); |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 591 | |
| 592 | if (req->r_mempool) |
| 593 | msg = ceph_msgpool_get(&osdc->msgpool_op_reply, 0); |
| 594 | else |
| 595 | msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, msg_size, gfp, true); |
| 596 | if (!msg) |
| 597 | return -ENOMEM; |
| 598 | |
| 599 | req->r_reply = msg; |
| 600 | |
| 601 | return 0; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 602 | } |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 603 | EXPORT_SYMBOL(ceph_osdc_alloc_messages); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 604 | |
Alex Elder | a8dd0a3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 605 | static bool osd_req_opcode_valid(u16 opcode) |
| 606 | { |
| 607 | switch (opcode) { |
Ilya Dryomov | 70b5bfa | 2014-10-02 17:22:29 +0400 | [diff] [blame] | 608 | #define GENERATE_CASE(op, opcode, str) case CEPH_OSD_OP_##op: return true; |
| 609 | __CEPH_FORALL_OSD_OPS(GENERATE_CASE) |
| 610 | #undef GENERATE_CASE |
Alex Elder | a8dd0a3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 611 | default: |
| 612 | return false; |
| 613 | } |
| 614 | } |
| 615 | |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 616 | /* |
| 617 | * This is an osd op init function for opcodes that have no data or |
| 618 | * other information associated with them. It also serves as a |
| 619 | * common init routine for all the other init functions, below. |
| 620 | */ |
Alex Elder | c99d2d4 | 2013-04-05 01:27:11 -0500 | [diff] [blame] | 621 | static struct ceph_osd_req_op * |
Alex Elder | 4971977 | 2013-02-11 12:33:24 -0600 | [diff] [blame] | 622 | _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] | 623 | u16 opcode, u32 flags) |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 624 | { |
Alex Elder | c99d2d4 | 2013-04-05 01:27:11 -0500 | [diff] [blame] | 625 | struct ceph_osd_req_op *op; |
| 626 | |
| 627 | BUG_ON(which >= osd_req->r_num_ops); |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 628 | BUG_ON(!osd_req_opcode_valid(opcode)); |
| 629 | |
Alex Elder | c99d2d4 | 2013-04-05 01:27:11 -0500 | [diff] [blame] | 630 | op = &osd_req->r_ops[which]; |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 631 | memset(op, 0, sizeof (*op)); |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 632 | op->op = opcode; |
Yan, Zheng | 144cba1 | 2015-04-27 11:09:54 +0800 | [diff] [blame] | 633 | op->flags = flags; |
Alex Elder | c99d2d4 | 2013-04-05 01:27:11 -0500 | [diff] [blame] | 634 | |
| 635 | return op; |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 636 | } |
| 637 | |
Alex Elder | 4971977 | 2013-02-11 12:33:24 -0600 | [diff] [blame] | 638 | void osd_req_op_init(struct ceph_osd_request *osd_req, |
Yan, Zheng | 144cba1 | 2015-04-27 11:09:54 +0800 | [diff] [blame] | 639 | unsigned int which, u16 opcode, u32 flags) |
Alex Elder | 4971977 | 2013-02-11 12:33:24 -0600 | [diff] [blame] | 640 | { |
Yan, Zheng | 144cba1 | 2015-04-27 11:09:54 +0800 | [diff] [blame] | 641 | (void)_osd_req_op_init(osd_req, which, opcode, flags); |
Alex Elder | 4971977 | 2013-02-11 12:33:24 -0600 | [diff] [blame] | 642 | } |
| 643 | EXPORT_SYMBOL(osd_req_op_init); |
| 644 | |
Alex Elder | c99d2d4 | 2013-04-05 01:27:11 -0500 | [diff] [blame] | 645 | void osd_req_op_extent_init(struct ceph_osd_request *osd_req, |
| 646 | unsigned int which, u16 opcode, |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 647 | u64 offset, u64 length, |
| 648 | u64 truncate_size, u32 truncate_seq) |
| 649 | { |
Yan, Zheng | 144cba1 | 2015-04-27 11:09:54 +0800 | [diff] [blame] | 650 | struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, |
| 651 | opcode, 0); |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 652 | size_t payload_len = 0; |
| 653 | |
Li Wang | ad7a60d | 2013-08-15 11:51:44 +0800 | [diff] [blame] | 654 | BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE && |
Ilya Dryomov | e30b757 | 2015-10-07 17:27:17 +0200 | [diff] [blame] | 655 | opcode != CEPH_OSD_OP_WRITEFULL && opcode != CEPH_OSD_OP_ZERO && |
| 656 | opcode != CEPH_OSD_OP_TRUNCATE); |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 657 | |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 658 | op->extent.offset = offset; |
| 659 | op->extent.length = length; |
| 660 | op->extent.truncate_size = truncate_size; |
| 661 | op->extent.truncate_seq = truncate_seq; |
Ilya Dryomov | e30b757 | 2015-10-07 17:27:17 +0200 | [diff] [blame] | 662 | if (opcode == CEPH_OSD_OP_WRITE || opcode == CEPH_OSD_OP_WRITEFULL) |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 663 | payload_len += length; |
| 664 | |
Ilya Dryomov | de2aa10 | 2016-02-08 13:39:46 +0100 | [diff] [blame] | 665 | op->indata_len = payload_len; |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 666 | } |
| 667 | EXPORT_SYMBOL(osd_req_op_extent_init); |
| 668 | |
Alex Elder | c99d2d4 | 2013-04-05 01:27:11 -0500 | [diff] [blame] | 669 | void osd_req_op_extent_update(struct ceph_osd_request *osd_req, |
| 670 | unsigned int which, u64 length) |
Alex Elder | e5975c7 | 2013-03-14 14:09:05 -0500 | [diff] [blame] | 671 | { |
Alex Elder | c99d2d4 | 2013-04-05 01:27:11 -0500 | [diff] [blame] | 672 | struct ceph_osd_req_op *op; |
| 673 | u64 previous; |
| 674 | |
| 675 | BUG_ON(which >= osd_req->r_num_ops); |
| 676 | op = &osd_req->r_ops[which]; |
| 677 | previous = op->extent.length; |
Alex Elder | e5975c7 | 2013-03-14 14:09:05 -0500 | [diff] [blame] | 678 | |
| 679 | if (length == previous) |
| 680 | return; /* Nothing to do */ |
| 681 | BUG_ON(length > previous); |
| 682 | |
| 683 | op->extent.length = length; |
Yan, Zheng | d641df8 | 2017-01-19 11:21:29 +0800 | [diff] [blame] | 684 | if (op->op == CEPH_OSD_OP_WRITE || op->op == CEPH_OSD_OP_WRITEFULL) |
| 685 | op->indata_len -= previous - length; |
Alex Elder | e5975c7 | 2013-03-14 14:09:05 -0500 | [diff] [blame] | 686 | } |
| 687 | EXPORT_SYMBOL(osd_req_op_extent_update); |
| 688 | |
Yan, Zheng | 2c63f49 | 2016-01-07 17:32:54 +0800 | [diff] [blame] | 689 | void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req, |
| 690 | unsigned int which, u64 offset_inc) |
| 691 | { |
| 692 | struct ceph_osd_req_op *op, *prev_op; |
| 693 | |
| 694 | BUG_ON(which + 1 >= osd_req->r_num_ops); |
| 695 | |
| 696 | prev_op = &osd_req->r_ops[which]; |
| 697 | op = _osd_req_op_init(osd_req, which + 1, prev_op->op, prev_op->flags); |
| 698 | /* dup previous one */ |
| 699 | op->indata_len = prev_op->indata_len; |
| 700 | op->outdata_len = prev_op->outdata_len; |
| 701 | op->extent = prev_op->extent; |
| 702 | /* adjust offset */ |
| 703 | op->extent.offset += offset_inc; |
| 704 | op->extent.length -= offset_inc; |
| 705 | |
| 706 | if (op->op == CEPH_OSD_OP_WRITE || op->op == CEPH_OSD_OP_WRITEFULL) |
| 707 | op->indata_len -= offset_inc; |
| 708 | } |
| 709 | EXPORT_SYMBOL(osd_req_op_extent_dup_last); |
| 710 | |
Alex Elder | c99d2d4 | 2013-04-05 01:27:11 -0500 | [diff] [blame] | 711 | 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] | 712 | u16 opcode, const char *class, const char *method) |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 713 | { |
Yan, Zheng | 144cba1 | 2015-04-27 11:09:54 +0800 | [diff] [blame] | 714 | struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, |
| 715 | opcode, 0); |
Alex Elder | 5f562df | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 716 | struct ceph_pagelist *pagelist; |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 717 | size_t payload_len = 0; |
| 718 | size_t size; |
| 719 | |
| 720 | BUG_ON(opcode != CEPH_OSD_OP_CALL); |
| 721 | |
Alex Elder | 5f562df | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 722 | pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS); |
| 723 | BUG_ON(!pagelist); |
| 724 | ceph_pagelist_init(pagelist); |
| 725 | |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 726 | op->cls.class_name = class; |
| 727 | size = strlen(class); |
| 728 | BUG_ON(size > (size_t) U8_MAX); |
| 729 | op->cls.class_len = size; |
Alex Elder | 5f562df | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 730 | ceph_pagelist_append(pagelist, class, size); |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 731 | payload_len += size; |
| 732 | |
| 733 | op->cls.method_name = method; |
| 734 | size = strlen(method); |
| 735 | BUG_ON(size > (size_t) U8_MAX); |
| 736 | op->cls.method_len = size; |
Alex Elder | 5f562df | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 737 | ceph_pagelist_append(pagelist, method, size); |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 738 | payload_len += size; |
| 739 | |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 740 | osd_req_op_cls_request_info_pagelist(osd_req, which, pagelist); |
Alex Elder | 5f562df | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 741 | |
Ilya Dryomov | de2aa10 | 2016-02-08 13:39:46 +0100 | [diff] [blame] | 742 | op->indata_len = payload_len; |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 743 | } |
| 744 | EXPORT_SYMBOL(osd_req_op_cls_init); |
Alex Elder | 8c042b0 | 2013-04-03 01:28:58 -0500 | [diff] [blame] | 745 | |
Yan, Zheng | d74b50b | 2014-11-12 14:00:43 +0800 | [diff] [blame] | 746 | int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which, |
| 747 | u16 opcode, const char *name, const void *value, |
| 748 | size_t size, u8 cmp_op, u8 cmp_mode) |
| 749 | { |
Yan, Zheng | 144cba1 | 2015-04-27 11:09:54 +0800 | [diff] [blame] | 750 | struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, |
| 751 | opcode, 0); |
Yan, Zheng | d74b50b | 2014-11-12 14:00:43 +0800 | [diff] [blame] | 752 | struct ceph_pagelist *pagelist; |
| 753 | size_t payload_len; |
| 754 | |
| 755 | BUG_ON(opcode != CEPH_OSD_OP_SETXATTR && opcode != CEPH_OSD_OP_CMPXATTR); |
| 756 | |
| 757 | pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS); |
| 758 | if (!pagelist) |
| 759 | return -ENOMEM; |
| 760 | |
| 761 | ceph_pagelist_init(pagelist); |
| 762 | |
| 763 | payload_len = strlen(name); |
| 764 | op->xattr.name_len = payload_len; |
| 765 | ceph_pagelist_append(pagelist, name, payload_len); |
| 766 | |
| 767 | op->xattr.value_len = size; |
| 768 | ceph_pagelist_append(pagelist, value, size); |
| 769 | payload_len += size; |
| 770 | |
| 771 | op->xattr.cmp_op = cmp_op; |
| 772 | op->xattr.cmp_mode = cmp_mode; |
| 773 | |
| 774 | ceph_osd_data_pagelist_init(&op->xattr.osd_data, pagelist); |
Ilya Dryomov | de2aa10 | 2016-02-08 13:39:46 +0100 | [diff] [blame] | 775 | op->indata_len = payload_len; |
Yan, Zheng | d74b50b | 2014-11-12 14:00:43 +0800 | [diff] [blame] | 776 | return 0; |
| 777 | } |
| 778 | EXPORT_SYMBOL(osd_req_op_xattr_init); |
| 779 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 780 | /* |
| 781 | * @watch_opcode: CEPH_OSD_WATCH_OP_* |
| 782 | */ |
| 783 | static void osd_req_op_watch_init(struct ceph_osd_request *req, int which, |
| 784 | u64 cookie, u8 watch_opcode) |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 785 | { |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 786 | struct ceph_osd_req_op *op; |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 787 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 788 | op = _osd_req_op_init(req, which, CEPH_OSD_OP_WATCH, 0); |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 789 | op->watch.cookie = cookie; |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 790 | op->watch.op = watch_opcode; |
| 791 | op->watch.gen = 0; |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 792 | } |
Alex Elder | 33803f3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 793 | |
Ilya Dryomov | c647b8a | 2014-02-25 16:22:27 +0200 | [diff] [blame] | 794 | void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req, |
| 795 | unsigned int which, |
| 796 | u64 expected_object_size, |
| 797 | u64 expected_write_size) |
| 798 | { |
| 799 | 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] | 800 | CEPH_OSD_OP_SETALLOCHINT, |
| 801 | 0); |
Ilya Dryomov | c647b8a | 2014-02-25 16:22:27 +0200 | [diff] [blame] | 802 | |
| 803 | op->alloc_hint.expected_object_size = expected_object_size; |
| 804 | op->alloc_hint.expected_write_size = expected_write_size; |
| 805 | |
| 806 | /* |
| 807 | * CEPH_OSD_OP_SETALLOCHINT op is advisory and therefore deemed |
| 808 | * not worth a feature bit. Set FAILOK per-op flag to make |
| 809 | * sure older osds don't trip over an unsupported opcode. |
| 810 | */ |
| 811 | op->flags |= CEPH_OSD_OP_FLAG_FAILOK; |
| 812 | } |
| 813 | EXPORT_SYMBOL(osd_req_op_alloc_hint_init); |
| 814 | |
Alex Elder | 90af360 | 2013-04-05 14:46:01 -0500 | [diff] [blame] | 815 | static void ceph_osdc_msg_data_add(struct ceph_msg *msg, |
Alex Elder | ec9123c | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 816 | struct ceph_osd_data *osd_data) |
| 817 | { |
| 818 | u64 length = ceph_osd_data_length(osd_data); |
| 819 | |
| 820 | if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) { |
| 821 | BUG_ON(length > (u64) SIZE_MAX); |
| 822 | if (length) |
Alex Elder | 90af360 | 2013-04-05 14:46:01 -0500 | [diff] [blame] | 823 | ceph_msg_data_add_pages(msg, osd_data->pages, |
Alex Elder | ec9123c | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 824 | length, osd_data->alignment); |
| 825 | } else if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGELIST) { |
| 826 | BUG_ON(!length); |
Alex Elder | 90af360 | 2013-04-05 14:46:01 -0500 | [diff] [blame] | 827 | ceph_msg_data_add_pagelist(msg, osd_data->pagelist); |
Alex Elder | ec9123c | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 828 | #ifdef CONFIG_BLOCK |
| 829 | } else if (osd_data->type == CEPH_OSD_DATA_TYPE_BIO) { |
Alex Elder | 90af360 | 2013-04-05 14:46:01 -0500 | [diff] [blame] | 830 | ceph_msg_data_add_bio(msg, osd_data->bio, length); |
Alex Elder | ec9123c | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 831 | #endif |
| 832 | } else { |
| 833 | BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_NONE); |
| 834 | } |
| 835 | } |
| 836 | |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 837 | static u32 osd_req_encode_op(struct ceph_osd_op *dst, |
| 838 | const struct ceph_osd_req_op *src) |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 839 | { |
Alex Elder | a8dd0a3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 840 | if (WARN_ON(!osd_req_opcode_valid(src->op))) { |
| 841 | pr_err("unrecognized osd opcode %d\n", src->op); |
| 842 | |
| 843 | return 0; |
| 844 | } |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 845 | |
Alex Elder | 065a68f | 2012-04-20 15:49:43 -0500 | [diff] [blame] | 846 | switch (src->op) { |
Alex Elder | fbfab53 | 2013-02-08 09:55:48 -0600 | [diff] [blame] | 847 | case CEPH_OSD_OP_STAT: |
| 848 | break; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 849 | case CEPH_OSD_OP_READ: |
| 850 | case CEPH_OSD_OP_WRITE: |
Ilya Dryomov | e30b757 | 2015-10-07 17:27:17 +0200 | [diff] [blame] | 851 | case CEPH_OSD_OP_WRITEFULL: |
Li Wang | ad7a60d | 2013-08-15 11:51:44 +0800 | [diff] [blame] | 852 | case CEPH_OSD_OP_ZERO: |
Li Wang | ad7a60d | 2013-08-15 11:51:44 +0800 | [diff] [blame] | 853 | case CEPH_OSD_OP_TRUNCATE: |
Alex Elder | 175face | 2013-03-08 13:35:36 -0600 | [diff] [blame] | 854 | dst->extent.offset = cpu_to_le64(src->extent.offset); |
| 855 | dst->extent.length = cpu_to_le64(src->extent.length); |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 856 | dst->extent.truncate_size = |
| 857 | cpu_to_le64(src->extent.truncate_size); |
| 858 | dst->extent.truncate_seq = |
| 859 | cpu_to_le32(src->extent.truncate_seq); |
| 860 | break; |
Yehuda Sadeh | ae1533b | 2010-05-18 16:38:08 -0700 | [diff] [blame] | 861 | case CEPH_OSD_OP_CALL: |
Yehuda Sadeh | ae1533b | 2010-05-18 16:38:08 -0700 | [diff] [blame] | 862 | dst->cls.class_len = src->cls.class_len; |
| 863 | dst->cls.method_len = src->cls.method_len; |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 864 | dst->cls.indata_len = cpu_to_le32(src->cls.indata_len); |
Yehuda Sadeh | ae1533b | 2010-05-18 16:38:08 -0700 | [diff] [blame] | 865 | break; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 866 | case CEPH_OSD_OP_STARTSYNC: |
| 867 | break; |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 868 | case CEPH_OSD_OP_WATCH: |
| 869 | dst->watch.cookie = cpu_to_le64(src->watch.cookie); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 870 | dst->watch.ver = cpu_to_le64(0); |
| 871 | dst->watch.op = src->watch.op; |
| 872 | dst->watch.gen = cpu_to_le32(src->watch.gen); |
| 873 | break; |
| 874 | case CEPH_OSD_OP_NOTIFY_ACK: |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 875 | break; |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 876 | case CEPH_OSD_OP_NOTIFY: |
| 877 | dst->notify.cookie = cpu_to_le64(src->notify.cookie); |
| 878 | break; |
Douglas Fuller | a4ed38d | 2015-07-17 13:18:07 -0700 | [diff] [blame] | 879 | case CEPH_OSD_OP_LIST_WATCHERS: |
| 880 | break; |
Ilya Dryomov | c647b8a | 2014-02-25 16:22:27 +0200 | [diff] [blame] | 881 | case CEPH_OSD_OP_SETALLOCHINT: |
| 882 | dst->alloc_hint.expected_object_size = |
| 883 | cpu_to_le64(src->alloc_hint.expected_object_size); |
| 884 | dst->alloc_hint.expected_write_size = |
| 885 | cpu_to_le64(src->alloc_hint.expected_write_size); |
| 886 | break; |
Yan, Zheng | d74b50b | 2014-11-12 14:00:43 +0800 | [diff] [blame] | 887 | case CEPH_OSD_OP_SETXATTR: |
| 888 | case CEPH_OSD_OP_CMPXATTR: |
| 889 | dst->xattr.name_len = cpu_to_le32(src->xattr.name_len); |
| 890 | dst->xattr.value_len = cpu_to_le32(src->xattr.value_len); |
| 891 | dst->xattr.cmp_op = src->xattr.cmp_op; |
| 892 | dst->xattr.cmp_mode = src->xattr.cmp_mode; |
Yan, Zheng | d74b50b | 2014-11-12 14:00:43 +0800 | [diff] [blame] | 893 | break; |
Yan, Zheng | 864e919 | 2014-11-13 10:47:25 +0800 | [diff] [blame] | 894 | case CEPH_OSD_OP_CREATE: |
| 895 | case CEPH_OSD_OP_DELETE: |
| 896 | break; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 897 | default: |
Alex Elder | 4c46459 | 2013-02-15 11:42:30 -0600 | [diff] [blame] | 898 | pr_err("unsupported osd opcode %s\n", |
Alex Elder | 8f63ca2 | 2013-03-04 11:08:29 -0600 | [diff] [blame] | 899 | ceph_osd_op_name(src->op)); |
Alex Elder | 4c46459 | 2013-02-15 11:42:30 -0600 | [diff] [blame] | 900 | WARN_ON(1); |
Alex Elder | a8dd0a3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 901 | |
| 902 | return 0; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 903 | } |
Ilya Dryomov | 7b25bf5 | 2014-02-25 16:22:26 +0200 | [diff] [blame] | 904 | |
Alex Elder | a8dd0a3 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 905 | dst->op = cpu_to_le16(src->op); |
Ilya Dryomov | 7b25bf5 | 2014-02-25 16:22:26 +0200 | [diff] [blame] | 906 | dst->flags = cpu_to_le32(src->flags); |
Ilya Dryomov | de2aa10 | 2016-02-08 13:39:46 +0100 | [diff] [blame] | 907 | dst->payload_len = cpu_to_le32(src->indata_len); |
Alex Elder | 175face | 2013-03-08 13:35:36 -0600 | [diff] [blame] | 908 | |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 909 | return src->indata_len; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 912 | /* |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 913 | * build new request AND message, calculate layout, and adjust file |
| 914 | * extent as needed. |
| 915 | * |
| 916 | * if the file was recently truncated, we include information about its |
| 917 | * old and new size so that the object can be updated appropriately. (we |
| 918 | * avoid synchronously deleting truncated objects because it's slow.) |
| 919 | * |
| 920 | * if @do_sync, include a 'startsync' command so that the osd will flush |
| 921 | * data quickly. |
| 922 | */ |
| 923 | struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, |
| 924 | struct ceph_file_layout *layout, |
| 925 | struct ceph_vino vino, |
Yan, Zheng | 715e4cd | 2014-11-13 14:40:37 +0800 | [diff] [blame] | 926 | u64 off, u64 *plen, |
| 927 | unsigned int which, int num_ops, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 928 | int opcode, int flags, |
| 929 | struct ceph_snap_context *snapc, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 930 | u32 truncate_seq, |
| 931 | u64 truncate_size, |
Alex Elder | 153e516 | 2013-03-01 18:00:15 -0600 | [diff] [blame] | 932 | bool use_mempool) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 933 | { |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 934 | struct ceph_osd_request *req; |
Alex Elder | 75d1c94 | 2013-03-13 20:50:00 -0500 | [diff] [blame] | 935 | u64 objnum = 0; |
| 936 | u64 objoff = 0; |
| 937 | u64 objlen = 0; |
Sage Weil | 6816282 | 2012-09-24 21:01:02 -0700 | [diff] [blame] | 938 | int r; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 939 | |
Li Wang | ad7a60d | 2013-08-15 11:51:44 +0800 | [diff] [blame] | 940 | BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE && |
Yan, Zheng | 864e919 | 2014-11-13 10:47:25 +0800 | [diff] [blame] | 941 | opcode != CEPH_OSD_OP_ZERO && opcode != CEPH_OSD_OP_TRUNCATE && |
| 942 | opcode != CEPH_OSD_OP_CREATE && opcode != CEPH_OSD_OP_DELETE); |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 943 | |
Alex Elder | acead00 | 2013-03-14 14:09:05 -0500 | [diff] [blame] | 944 | req = ceph_osdc_alloc_request(osdc, snapc, num_ops, use_mempool, |
Alex Elder | ae7ca4a3 | 2012-11-13 21:11:15 -0600 | [diff] [blame] | 945 | GFP_NOFS); |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 946 | if (!req) { |
| 947 | r = -ENOMEM; |
| 948 | goto fail; |
| 949 | } |
Alex Elder | 7952873 | 2013-04-03 21:32:51 -0500 | [diff] [blame] | 950 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 951 | /* calculate max write size */ |
Alex Elder | a19dadf | 2013-03-13 20:50:01 -0500 | [diff] [blame] | 952 | r = calc_layout(layout, off, plen, &objnum, &objoff, &objlen); |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 953 | if (r) |
| 954 | goto fail; |
Alex Elder | a19dadf | 2013-03-13 20:50:01 -0500 | [diff] [blame] | 955 | |
Yan, Zheng | 864e919 | 2014-11-13 10:47:25 +0800 | [diff] [blame] | 956 | if (opcode == CEPH_OSD_OP_CREATE || opcode == CEPH_OSD_OP_DELETE) { |
Yan, Zheng | 144cba1 | 2015-04-27 11:09:54 +0800 | [diff] [blame] | 957 | osd_req_op_init(req, which, opcode, 0); |
Yan, Zheng | 864e919 | 2014-11-13 10:47:25 +0800 | [diff] [blame] | 958 | } else { |
Yan, Zheng | 7627151 | 2016-02-03 21:24:49 +0800 | [diff] [blame] | 959 | u32 object_size = layout->object_size; |
Yan, Zheng | 864e919 | 2014-11-13 10:47:25 +0800 | [diff] [blame] | 960 | u32 object_base = off - objoff; |
| 961 | if (!(truncate_seq == 1 && truncate_size == -1ULL)) { |
| 962 | if (truncate_size <= object_base) { |
| 963 | truncate_size = 0; |
| 964 | } else { |
| 965 | truncate_size -= object_base; |
| 966 | if (truncate_size > object_size) |
| 967 | truncate_size = object_size; |
| 968 | } |
Yan, Zheng | ccca4e3 | 2013-06-02 18:40:23 +0800 | [diff] [blame] | 969 | } |
Yan, Zheng | 715e4cd | 2014-11-13 14:40:37 +0800 | [diff] [blame] | 970 | osd_req_op_extent_init(req, which, opcode, objoff, objlen, |
Yan, Zheng | 864e919 | 2014-11-13 10:47:25 +0800 | [diff] [blame] | 971 | truncate_size, truncate_seq); |
Alex Elder | a19dadf | 2013-03-13 20:50:01 -0500 | [diff] [blame] | 972 | } |
Alex Elder | d18d1e2 | 2013-03-13 20:50:01 -0500 | [diff] [blame] | 973 | |
Jeff Layton | a1f4020 | 2017-04-04 08:39:37 -0400 | [diff] [blame] | 974 | req->r_abort_on_full = true; |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 975 | req->r_flags = flags; |
Yan, Zheng | 7627151 | 2016-02-03 21:24:49 +0800 | [diff] [blame] | 976 | req->r_base_oloc.pool = layout->pool_id; |
Yan, Zheng | 30c156d | 2016-02-14 11:24:31 +0800 | [diff] [blame] | 977 | req->r_base_oloc.pool_ns = ceph_try_get_string(layout->pool_ns); |
Ilya Dryomov | d30291b | 2016-04-29 19:54:20 +0200 | [diff] [blame] | 978 | ceph_oid_printf(&req->r_base_oid, "%llx.%08llx", vino.ino, objnum); |
Alex Elder | dbe0fc4 | 2013-02-15 22:10:17 -0600 | [diff] [blame] | 979 | |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 980 | req->r_snapid = vino.snap; |
| 981 | if (flags & CEPH_OSD_FLAG_WRITE) |
| 982 | req->r_data_offset = off; |
| 983 | |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 984 | r = ceph_osdc_alloc_messages(req, GFP_NOFS); |
| 985 | if (r) |
| 986 | goto fail; |
| 987 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 988 | return req; |
Ilya Dryomov | 13d1ad1 | 2016-04-27 14:15:51 +0200 | [diff] [blame] | 989 | |
| 990 | fail: |
| 991 | ceph_osdc_put_request(req); |
| 992 | return ERR_PTR(r); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 993 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 994 | EXPORT_SYMBOL(ceph_osdc_new_request); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 995 | |
| 996 | /* |
| 997 | * We keep osd requests in an rbtree, sorted by ->r_tid. |
| 998 | */ |
Ilya Dryomov | fcd00b6 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 999 | DEFINE_RB_FUNCS(request, struct ceph_osd_request, r_tid, r_node) |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 1000 | DEFINE_RB_FUNCS(request_mc, struct ceph_osd_request, r_tid, r_mc_node) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1001 | |
Ilya Dryomov | 0247a0c | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1002 | static bool osd_homeless(struct ceph_osd *osd) |
| 1003 | { |
| 1004 | return osd->o_osd == CEPH_HOMELESS_OSD; |
| 1005 | } |
| 1006 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1007 | static bool osd_registered(struct ceph_osd *osd) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1008 | { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1009 | verify_osdc_locked(osd->o_osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1010 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1011 | return !RB_EMPTY_NODE(&osd->o_node); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /* |
Ilya Dryomov | 0247a0c | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1015 | * Assumes @osd is zero-initialized. |
| 1016 | */ |
| 1017 | static void osd_init(struct ceph_osd *osd) |
| 1018 | { |
Elena Reshetova | 02113a0 | 2017-03-17 14:10:28 +0200 | [diff] [blame] | 1019 | refcount_set(&osd->o_ref, 1); |
Ilya Dryomov | 0247a0c | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1020 | RB_CLEAR_NODE(&osd->o_node); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1021 | osd->o_requests = RB_ROOT; |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 1022 | osd->o_linger_requests = RB_ROOT; |
Ilya Dryomov | a02a946 | 2017-06-19 12:18:05 +0200 | [diff] [blame] | 1023 | osd->o_backoff_mappings = RB_ROOT; |
| 1024 | osd->o_backoffs_by_id = RB_ROOT; |
Ilya Dryomov | 0247a0c | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1025 | INIT_LIST_HEAD(&osd->o_osd_lru); |
| 1026 | INIT_LIST_HEAD(&osd->o_keepalive_item); |
| 1027 | osd->o_incarnation = 1; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1028 | mutex_init(&osd->lock); |
Ilya Dryomov | 0247a0c | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | static void osd_cleanup(struct ceph_osd *osd) |
| 1032 | { |
| 1033 | WARN_ON(!RB_EMPTY_NODE(&osd->o_node)); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1034 | WARN_ON(!RB_EMPTY_ROOT(&osd->o_requests)); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 1035 | WARN_ON(!RB_EMPTY_ROOT(&osd->o_linger_requests)); |
Ilya Dryomov | a02a946 | 2017-06-19 12:18:05 +0200 | [diff] [blame] | 1036 | WARN_ON(!RB_EMPTY_ROOT(&osd->o_backoff_mappings)); |
| 1037 | WARN_ON(!RB_EMPTY_ROOT(&osd->o_backoffs_by_id)); |
Ilya Dryomov | 0247a0c | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1038 | WARN_ON(!list_empty(&osd->o_osd_lru)); |
| 1039 | WARN_ON(!list_empty(&osd->o_keepalive_item)); |
| 1040 | |
| 1041 | if (osd->o_auth.authorizer) { |
| 1042 | WARN_ON(osd_homeless(osd)); |
| 1043 | ceph_auth_destroy_authorizer(osd->o_auth.authorizer); |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | /* |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1048 | * Track open sessions with osds. |
| 1049 | */ |
Alex Elder | e10006f | 2012-05-26 23:26:43 -0500 | [diff] [blame] | 1050 | static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1051 | { |
| 1052 | struct ceph_osd *osd; |
| 1053 | |
Ilya Dryomov | 0247a0c | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1054 | WARN_ON(onum == CEPH_HOMELESS_OSD); |
| 1055 | |
Ilya Dryomov | 7a28f59 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1056 | osd = kzalloc(sizeof(*osd), GFP_NOIO | __GFP_NOFAIL); |
Ilya Dryomov | 0247a0c | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1057 | osd_init(osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1058 | osd->o_osdc = osdc; |
Alex Elder | e10006f | 2012-05-26 23:26:43 -0500 | [diff] [blame] | 1059 | osd->o_osd = onum; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1060 | |
Sage Weil | b7a9e5d | 2012-06-27 12:24:08 -0700 | [diff] [blame] | 1061 | 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] | 1062 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1063 | return osd; |
| 1064 | } |
| 1065 | |
| 1066 | static struct ceph_osd *get_osd(struct ceph_osd *osd) |
| 1067 | { |
Elena Reshetova | 02113a0 | 2017-03-17 14:10:28 +0200 | [diff] [blame] | 1068 | if (refcount_inc_not_zero(&osd->o_ref)) { |
| 1069 | dout("get_osd %p %d -> %d\n", osd, refcount_read(&osd->o_ref)-1, |
| 1070 | refcount_read(&osd->o_ref)); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1071 | return osd; |
| 1072 | } else { |
| 1073 | dout("get_osd %p FAIL\n", osd); |
| 1074 | return NULL; |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | static void put_osd(struct ceph_osd *osd) |
| 1079 | { |
Elena Reshetova | 02113a0 | 2017-03-17 14:10:28 +0200 | [diff] [blame] | 1080 | dout("put_osd %p %d -> %d\n", osd, refcount_read(&osd->o_ref), |
| 1081 | refcount_read(&osd->o_ref) - 1); |
| 1082 | if (refcount_dec_and_test(&osd->o_ref)) { |
Ilya Dryomov | 0247a0c | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1083 | osd_cleanup(osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1084 | kfree(osd); |
Sage Weil | 79494d1 | 2010-05-27 14:15:49 -0700 | [diff] [blame] | 1085 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
Ilya Dryomov | fcd00b6 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 1088 | DEFINE_RB_FUNCS(osd, struct ceph_osd, o_osd, o_node) |
| 1089 | |
Ilya Dryomov | 9dd2845 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1090 | static void __move_osd_to_lru(struct ceph_osd *osd) |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1091 | { |
Ilya Dryomov | 9dd2845 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1092 | struct ceph_osd_client *osdc = osd->o_osdc; |
| 1093 | |
| 1094 | dout("%s osd %p osd%d\n", __func__, osd, osd->o_osd); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1095 | BUG_ON(!list_empty(&osd->o_osd_lru)); |
Ilya Dryomov | bbf37ec | 2014-06-20 14:14:41 +0400 | [diff] [blame] | 1096 | |
Ilya Dryomov | 9dd2845 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1097 | spin_lock(&osdc->osd_lru_lock); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1098 | list_add_tail(&osd->o_osd_lru, &osdc->osd_lru); |
Ilya Dryomov | 9dd2845 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1099 | spin_unlock(&osdc->osd_lru_lock); |
| 1100 | |
Ilya Dryomov | a319bf5 | 2015-05-15 12:02:17 +0300 | [diff] [blame] | 1101 | osd->lru_ttl = jiffies + osdc->client->options->osd_idle_ttl; |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
Ilya Dryomov | 9dd2845 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1104 | static void maybe_move_osd_to_lru(struct ceph_osd *osd) |
Ilya Dryomov | bbf37ec | 2014-06-20 14:14:41 +0400 | [diff] [blame] | 1105 | { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1106 | if (RB_EMPTY_ROOT(&osd->o_requests) && |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 1107 | RB_EMPTY_ROOT(&osd->o_linger_requests)) |
Ilya Dryomov | 9dd2845 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1108 | __move_osd_to_lru(osd); |
Ilya Dryomov | bbf37ec | 2014-06-20 14:14:41 +0400 | [diff] [blame] | 1109 | } |
| 1110 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1111 | static void __remove_osd_from_lru(struct ceph_osd *osd) |
| 1112 | { |
Ilya Dryomov | 9dd2845 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1113 | struct ceph_osd_client *osdc = osd->o_osdc; |
| 1114 | |
| 1115 | dout("%s osd %p osd%d\n", __func__, osd, osd->o_osd); |
| 1116 | |
| 1117 | spin_lock(&osdc->osd_lru_lock); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1118 | if (!list_empty(&osd->o_osd_lru)) |
| 1119 | list_del_init(&osd->o_osd_lru); |
Ilya Dryomov | 9dd2845 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1120 | spin_unlock(&osdc->osd_lru_lock); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1121 | } |
| 1122 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1123 | /* |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1124 | * Close the connection and assign any leftover requests to the |
| 1125 | * homeless session. |
| 1126 | */ |
| 1127 | static void close_osd(struct ceph_osd *osd) |
| 1128 | { |
| 1129 | struct ceph_osd_client *osdc = osd->o_osdc; |
| 1130 | struct rb_node *n; |
| 1131 | |
| 1132 | verify_osdc_wrlocked(osdc); |
| 1133 | dout("%s osd %p osd%d\n", __func__, osd, osd->o_osd); |
| 1134 | |
| 1135 | ceph_con_close(&osd->o_con); |
| 1136 | |
| 1137 | for (n = rb_first(&osd->o_requests); n; ) { |
| 1138 | struct ceph_osd_request *req = |
| 1139 | rb_entry(n, struct ceph_osd_request, r_node); |
| 1140 | |
| 1141 | n = rb_next(n); /* unlink_request() */ |
| 1142 | |
| 1143 | dout(" reassigning req %p tid %llu\n", req, req->r_tid); |
| 1144 | unlink_request(osd, req); |
| 1145 | link_request(&osdc->homeless_osd, req); |
| 1146 | } |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 1147 | for (n = rb_first(&osd->o_linger_requests); n; ) { |
| 1148 | struct ceph_osd_linger_request *lreq = |
| 1149 | rb_entry(n, struct ceph_osd_linger_request, node); |
| 1150 | |
| 1151 | n = rb_next(n); /* unlink_linger() */ |
| 1152 | |
| 1153 | dout(" reassigning lreq %p linger_id %llu\n", lreq, |
| 1154 | lreq->linger_id); |
| 1155 | unlink_linger(osd, lreq); |
| 1156 | link_linger(&osdc->homeless_osd, lreq); |
| 1157 | } |
Ilya Dryomov | a02a946 | 2017-06-19 12:18:05 +0200 | [diff] [blame] | 1158 | clear_backoffs(osd); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1159 | |
| 1160 | __remove_osd_from_lru(osd); |
| 1161 | erase_osd(&osdc->osds, osd); |
| 1162 | put_osd(osd); |
| 1163 | } |
| 1164 | |
| 1165 | /* |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1166 | * reset osd connect |
| 1167 | */ |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1168 | static int reopen_osd(struct ceph_osd *osd) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1169 | { |
Alex Elder | c3acb18 | 2012-12-07 09:57:58 -0600 | [diff] [blame] | 1170 | struct ceph_entity_addr *peer_addr; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1171 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1172 | dout("%s osd %p osd%d\n", __func__, osd, osd->o_osd); |
| 1173 | |
| 1174 | if (RB_EMPTY_ROOT(&osd->o_requests) && |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 1175 | RB_EMPTY_ROOT(&osd->o_linger_requests)) { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1176 | close_osd(osd); |
Alex Elder | c3acb18 | 2012-12-07 09:57:58 -0600 | [diff] [blame] | 1177 | return -ENODEV; |
| 1178 | } |
| 1179 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1180 | peer_addr = &osd->o_osdc->osdmap->osd_addr[osd->o_osd]; |
Alex Elder | c3acb18 | 2012-12-07 09:57:58 -0600 | [diff] [blame] | 1181 | if (!memcmp(peer_addr, &osd->o_con.peer_addr, sizeof (*peer_addr)) && |
| 1182 | !ceph_con_opened(&osd->o_con)) { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1183 | struct rb_node *n; |
Alex Elder | c3acb18 | 2012-12-07 09:57:58 -0600 | [diff] [blame] | 1184 | |
Ilya Dryomov | 0b4af2e | 2014-01-16 19:18:27 +0200 | [diff] [blame] | 1185 | dout("osd addr hasn't changed and connection never opened, " |
| 1186 | "letting msgr retry\n"); |
Sage Weil | 87b315a | 2010-03-22 14:51:18 -0700 | [diff] [blame] | 1187 | /* touch each r_stamp for handle_timeout()'s benfit */ |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1188 | for (n = rb_first(&osd->o_requests); n; n = rb_next(n)) { |
| 1189 | struct ceph_osd_request *req = |
| 1190 | rb_entry(n, struct ceph_osd_request, r_node); |
Sage Weil | 87b315a | 2010-03-22 14:51:18 -0700 | [diff] [blame] | 1191 | req->r_stamp = jiffies; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1192 | } |
Alex Elder | c3acb18 | 2012-12-07 09:57:58 -0600 | [diff] [blame] | 1193 | |
| 1194 | return -EAGAIN; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1195 | } |
Alex Elder | c3acb18 | 2012-12-07 09:57:58 -0600 | [diff] [blame] | 1196 | |
| 1197 | ceph_con_close(&osd->o_con); |
| 1198 | ceph_con_open(&osd->o_con, CEPH_ENTITY_TYPE_OSD, osd->o_osd, peer_addr); |
| 1199 | osd->o_incarnation++; |
| 1200 | |
| 1201 | return 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1204 | static struct ceph_osd *lookup_create_osd(struct ceph_osd_client *osdc, int o, |
| 1205 | bool wrlocked) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1206 | { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1207 | struct ceph_osd *osd; |
| 1208 | |
| 1209 | if (wrlocked) |
| 1210 | verify_osdc_wrlocked(osdc); |
| 1211 | else |
| 1212 | verify_osdc_locked(osdc); |
| 1213 | |
| 1214 | if (o != CEPH_HOMELESS_OSD) |
| 1215 | osd = lookup_osd(&osdc->osds, o); |
| 1216 | else |
| 1217 | osd = &osdc->homeless_osd; |
| 1218 | if (!osd) { |
| 1219 | if (!wrlocked) |
| 1220 | return ERR_PTR(-EAGAIN); |
| 1221 | |
| 1222 | osd = create_osd(osdc, o); |
| 1223 | insert_osd(&osdc->osds, osd); |
| 1224 | ceph_con_open(&osd->o_con, CEPH_ENTITY_TYPE_OSD, osd->o_osd, |
| 1225 | &osdc->osdmap->osd_addr[osd->o_osd]); |
| 1226 | } |
| 1227 | |
| 1228 | dout("%s osdc %p osd%d -> osd %p\n", __func__, osdc, o, osd); |
| 1229 | return osd; |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1232 | /* |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1233 | * Create request <-> OSD session relation. |
| 1234 | * |
| 1235 | * @req has to be assigned a tid, @osd may be homeless. |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1236 | */ |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1237 | static void link_request(struct ceph_osd *osd, struct ceph_osd_request *req) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1238 | { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1239 | verify_osd_locked(osd); |
| 1240 | WARN_ON(!req->r_tid || req->r_osd); |
| 1241 | dout("%s osd %p osd%d req %p tid %llu\n", __func__, osd, osd->o_osd, |
| 1242 | req, req->r_tid); |
Sage Weil | 35f9f8a | 2012-05-16 15:16:38 -0500 | [diff] [blame] | 1243 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1244 | if (!osd_homeless(osd)) |
| 1245 | __remove_osd_from_lru(osd); |
| 1246 | else |
| 1247 | atomic_inc(&osd->o_osdc->num_homeless); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1248 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1249 | get_osd(osd); |
| 1250 | insert_request(&osd->o_requests, req); |
| 1251 | req->r_osd = osd; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1252 | } |
| 1253 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1254 | static void unlink_request(struct ceph_osd *osd, struct ceph_osd_request *req) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1255 | { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1256 | verify_osd_locked(osd); |
| 1257 | WARN_ON(req->r_osd != osd); |
| 1258 | dout("%s osd %p osd%d req %p tid %llu\n", __func__, osd, osd->o_osd, |
| 1259 | req, req->r_tid); |
| 1260 | |
| 1261 | req->r_osd = NULL; |
| 1262 | erase_request(&osd->o_requests, req); |
| 1263 | put_osd(osd); |
| 1264 | |
| 1265 | if (!osd_homeless(osd)) |
| 1266 | maybe_move_osd_to_lru(osd); |
| 1267 | else |
| 1268 | atomic_dec(&osd->o_osdc->num_homeless); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1271 | static bool __pool_full(struct ceph_pg_pool_info *pi) |
| 1272 | { |
| 1273 | return pi->flags & CEPH_POOL_FLAG_FULL; |
| 1274 | } |
| 1275 | |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1276 | static bool have_pool_full(struct ceph_osd_client *osdc) |
| 1277 | { |
| 1278 | struct rb_node *n; |
| 1279 | |
| 1280 | for (n = rb_first(&osdc->osdmap->pg_pools); n; n = rb_next(n)) { |
| 1281 | struct ceph_pg_pool_info *pi = |
| 1282 | rb_entry(n, struct ceph_pg_pool_info, node); |
| 1283 | |
| 1284 | if (__pool_full(pi)) |
| 1285 | return true; |
| 1286 | } |
| 1287 | |
| 1288 | return false; |
| 1289 | } |
| 1290 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 1291 | static bool pool_full(struct ceph_osd_client *osdc, s64 pool_id) |
| 1292 | { |
| 1293 | struct ceph_pg_pool_info *pi; |
| 1294 | |
| 1295 | pi = ceph_pg_pool_by_id(osdc->osdmap, pool_id); |
| 1296 | if (!pi) |
| 1297 | return false; |
| 1298 | |
| 1299 | return __pool_full(pi); |
| 1300 | } |
| 1301 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1302 | /* |
Josh Durgin | d29adb3 | 2013-12-02 19:11:48 -0800 | [diff] [blame] | 1303 | * Returns whether a request should be blocked from being sent |
| 1304 | * based on the current osdmap and osd_client settings. |
Josh Durgin | d29adb3 | 2013-12-02 19:11:48 -0800 | [diff] [blame] | 1305 | */ |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1306 | static bool target_should_be_paused(struct ceph_osd_client *osdc, |
| 1307 | const struct ceph_osd_request_target *t, |
| 1308 | struct ceph_pg_pool_info *pi) |
| 1309 | { |
Ilya Dryomov | b7ec35b | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1310 | bool pauserd = ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSERD); |
| 1311 | bool pausewr = ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR) || |
| 1312 | ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) || |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1313 | __pool_full(pi); |
| 1314 | |
Ilya Dryomov | 6d637a5 | 2017-06-15 16:30:55 +0200 | [diff] [blame] | 1315 | WARN_ON(pi->id != t->target_oloc.pool); |
Jeff Layton | 58eb793 | 2017-04-18 09:21:16 -0400 | [diff] [blame] | 1316 | return ((t->flags & CEPH_OSD_FLAG_READ) && pauserd) || |
| 1317 | ((t->flags & CEPH_OSD_FLAG_WRITE) && pausewr) || |
| 1318 | (osdc->osdmap->epoch < osdc->epoch_barrier); |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1319 | } |
| 1320 | |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1321 | enum calc_target_result { |
| 1322 | CALC_TARGET_NO_ACTION = 0, |
| 1323 | CALC_TARGET_NEED_RESEND, |
| 1324 | CALC_TARGET_POOL_DNE, |
| 1325 | }; |
| 1326 | |
| 1327 | static enum calc_target_result calc_target(struct ceph_osd_client *osdc, |
| 1328 | struct ceph_osd_request_target *t, |
Ilya Dryomov | 7de030d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1329 | struct ceph_connection *con, |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1330 | bool any_change) |
| 1331 | { |
| 1332 | struct ceph_pg_pool_info *pi; |
| 1333 | struct ceph_pg pgid, last_pgid; |
| 1334 | struct ceph_osds up, acting; |
| 1335 | bool force_resend = false; |
Ilya Dryomov | 84ed45d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1336 | bool unpaused = false; |
| 1337 | bool legacy_change; |
Ilya Dryomov | 7de030d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1338 | bool split = false; |
Ilya Dryomov | b7ec35b | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 1339 | bool sort_bitwise = ceph_osdmap_flag(osdc, CEPH_OSDMAP_SORTBITWISE); |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1340 | enum calc_target_result ct_res; |
| 1341 | int ret; |
| 1342 | |
Ilya Dryomov | 04c7d78 | 2017-06-15 16:30:55 +0200 | [diff] [blame] | 1343 | t->epoch = osdc->osdmap->epoch; |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1344 | pi = ceph_pg_pool_by_id(osdc->osdmap, t->base_oloc.pool); |
| 1345 | if (!pi) { |
| 1346 | t->osd = CEPH_HOMELESS_OSD; |
| 1347 | ct_res = CALC_TARGET_POOL_DNE; |
| 1348 | goto out; |
| 1349 | } |
| 1350 | |
| 1351 | if (osdc->osdmap->epoch == pi->last_force_request_resend) { |
Ilya Dryomov | dc93e0e | 2017-06-05 14:45:00 +0200 | [diff] [blame] | 1352 | if (t->last_force_resend < pi->last_force_request_resend) { |
| 1353 | t->last_force_resend = pi->last_force_request_resend; |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1354 | force_resend = true; |
Ilya Dryomov | dc93e0e | 2017-06-05 14:45:00 +0200 | [diff] [blame] | 1355 | } else if (t->last_force_resend == 0) { |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1356 | force_resend = true; |
| 1357 | } |
| 1358 | } |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1359 | |
Ilya Dryomov | db098ec | 2017-06-15 16:30:55 +0200 | [diff] [blame] | 1360 | /* apply tiering */ |
| 1361 | ceph_oid_copy(&t->target_oid, &t->base_oid); |
| 1362 | ceph_oloc_copy(&t->target_oloc, &t->base_oloc); |
| 1363 | if ((t->flags & CEPH_OSD_FLAG_IGNORE_OVERLAY) == 0) { |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1364 | if (t->flags & CEPH_OSD_FLAG_READ && pi->read_tier >= 0) |
| 1365 | t->target_oloc.pool = pi->read_tier; |
| 1366 | if (t->flags & CEPH_OSD_FLAG_WRITE && pi->write_tier >= 0) |
| 1367 | t->target_oloc.pool = pi->write_tier; |
Ilya Dryomov | 6d637a5 | 2017-06-15 16:30:55 +0200 | [diff] [blame] | 1368 | |
| 1369 | pi = ceph_pg_pool_by_id(osdc->osdmap, t->target_oloc.pool); |
| 1370 | if (!pi) { |
| 1371 | t->osd = CEPH_HOMELESS_OSD; |
| 1372 | ct_res = CALC_TARGET_POOL_DNE; |
| 1373 | goto out; |
| 1374 | } |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1375 | } |
| 1376 | |
Ilya Dryomov | df28152 | 2017-06-15 16:30:56 +0200 | [diff] [blame] | 1377 | ret = __ceph_object_locator_to_pg(pi, &t->target_oid, &t->target_oloc, |
| 1378 | &pgid); |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1379 | if (ret) { |
| 1380 | WARN_ON(ret != -ENOENT); |
| 1381 | t->osd = CEPH_HOMELESS_OSD; |
| 1382 | ct_res = CALC_TARGET_POOL_DNE; |
| 1383 | goto out; |
| 1384 | } |
| 1385 | last_pgid.pool = pgid.pool; |
| 1386 | last_pgid.seed = ceph_stable_mod(pgid.seed, t->pg_num, t->pg_num_mask); |
| 1387 | |
Ilya Dryomov | df28152 | 2017-06-15 16:30:56 +0200 | [diff] [blame] | 1388 | ceph_pg_to_up_acting_osds(osdc->osdmap, pi, &pgid, &up, &acting); |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1389 | if (any_change && |
| 1390 | ceph_is_new_interval(&t->acting, |
| 1391 | &acting, |
| 1392 | &t->up, |
| 1393 | &up, |
| 1394 | t->size, |
| 1395 | pi->size, |
| 1396 | t->min_size, |
| 1397 | pi->min_size, |
| 1398 | t->pg_num, |
| 1399 | pi->pg_num, |
| 1400 | t->sort_bitwise, |
| 1401 | sort_bitwise, |
| 1402 | &last_pgid)) |
| 1403 | force_resend = true; |
| 1404 | |
| 1405 | if (t->paused && !target_should_be_paused(osdc, t, pi)) { |
| 1406 | t->paused = false; |
Ilya Dryomov | 84ed45d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1407 | unpaused = true; |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1408 | } |
Ilya Dryomov | 84ed45d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1409 | legacy_change = ceph_pg_compare(&t->pgid, &pgid) || |
| 1410 | ceph_osds_changed(&t->acting, &acting, any_change); |
Ilya Dryomov | 7de030d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1411 | if (t->pg_num) |
| 1412 | split = ceph_pg_is_split(&last_pgid, t->pg_num, pi->pg_num); |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1413 | |
Ilya Dryomov | 7de030d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1414 | if (legacy_change || force_resend || split) { |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1415 | t->pgid = pgid; /* struct */ |
Ilya Dryomov | df28152 | 2017-06-15 16:30:56 +0200 | [diff] [blame] | 1416 | ceph_pg_to_primary_shard(osdc->osdmap, pi, &pgid, &t->spgid); |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1417 | ceph_osds_copy(&t->acting, &acting); |
| 1418 | ceph_osds_copy(&t->up, &up); |
| 1419 | t->size = pi->size; |
| 1420 | t->min_size = pi->min_size; |
| 1421 | t->pg_num = pi->pg_num; |
| 1422 | t->pg_num_mask = pi->pg_num_mask; |
| 1423 | t->sort_bitwise = sort_bitwise; |
| 1424 | |
| 1425 | t->osd = acting.primary; |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1426 | } |
| 1427 | |
Ilya Dryomov | 7de030d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1428 | if (unpaused || legacy_change || force_resend || |
| 1429 | (split && con && CEPH_HAVE_FEATURE(con->peer_features, |
| 1430 | RESEND_ON_SPLIT))) |
Ilya Dryomov | 84ed45d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1431 | ct_res = CALC_TARGET_NEED_RESEND; |
| 1432 | else |
| 1433 | ct_res = CALC_TARGET_NO_ACTION; |
| 1434 | |
Ilya Dryomov | 63244fa | 2016-04-28 16:07:23 +0200 | [diff] [blame] | 1435 | out: |
| 1436 | dout("%s t %p -> ct_res %d osd %d\n", __func__, t, ct_res, t->osd); |
| 1437 | return ct_res; |
| 1438 | } |
| 1439 | |
Ilya Dryomov | a02a946 | 2017-06-19 12:18:05 +0200 | [diff] [blame] | 1440 | static struct ceph_spg_mapping *alloc_spg_mapping(void) |
| 1441 | { |
| 1442 | struct ceph_spg_mapping *spg; |
| 1443 | |
| 1444 | spg = kmalloc(sizeof(*spg), GFP_NOIO); |
| 1445 | if (!spg) |
| 1446 | return NULL; |
| 1447 | |
| 1448 | RB_CLEAR_NODE(&spg->node); |
| 1449 | spg->backoffs = RB_ROOT; |
| 1450 | return spg; |
| 1451 | } |
| 1452 | |
| 1453 | static void free_spg_mapping(struct ceph_spg_mapping *spg) |
| 1454 | { |
| 1455 | WARN_ON(!RB_EMPTY_NODE(&spg->node)); |
| 1456 | WARN_ON(!RB_EMPTY_ROOT(&spg->backoffs)); |
| 1457 | |
| 1458 | kfree(spg); |
| 1459 | } |
| 1460 | |
| 1461 | /* |
| 1462 | * rbtree of ceph_spg_mapping for handling map<spg_t, ...>, similar to |
| 1463 | * ceph_pg_mapping. Used to track OSD backoffs -- a backoff [range] is |
| 1464 | * defined only within a specific spgid; it does not pass anything to |
| 1465 | * children on split, or to another primary. |
| 1466 | */ |
| 1467 | DEFINE_RB_FUNCS2(spg_mapping, struct ceph_spg_mapping, spgid, ceph_spg_compare, |
| 1468 | RB_BYPTR, const struct ceph_spg *, node) |
| 1469 | |
| 1470 | static u64 hoid_get_bitwise_key(const struct ceph_hobject_id *hoid) |
| 1471 | { |
| 1472 | return hoid->is_max ? 0x100000000ull : hoid->hash_reverse_bits; |
| 1473 | } |
| 1474 | |
| 1475 | static void hoid_get_effective_key(const struct ceph_hobject_id *hoid, |
| 1476 | void **pkey, size_t *pkey_len) |
| 1477 | { |
| 1478 | if (hoid->key_len) { |
| 1479 | *pkey = hoid->key; |
| 1480 | *pkey_len = hoid->key_len; |
| 1481 | } else { |
| 1482 | *pkey = hoid->oid; |
| 1483 | *pkey_len = hoid->oid_len; |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | static int compare_names(const void *name1, size_t name1_len, |
| 1488 | const void *name2, size_t name2_len) |
| 1489 | { |
| 1490 | int ret; |
| 1491 | |
| 1492 | ret = memcmp(name1, name2, min(name1_len, name2_len)); |
| 1493 | if (!ret) { |
| 1494 | if (name1_len < name2_len) |
| 1495 | ret = -1; |
| 1496 | else if (name1_len > name2_len) |
| 1497 | ret = 1; |
| 1498 | } |
| 1499 | return ret; |
| 1500 | } |
| 1501 | |
| 1502 | static int hoid_compare(const struct ceph_hobject_id *lhs, |
| 1503 | const struct ceph_hobject_id *rhs) |
| 1504 | { |
| 1505 | void *effective_key1, *effective_key2; |
| 1506 | size_t effective_key1_len, effective_key2_len; |
| 1507 | int ret; |
| 1508 | |
| 1509 | if (lhs->is_max < rhs->is_max) |
| 1510 | return -1; |
| 1511 | if (lhs->is_max > rhs->is_max) |
| 1512 | return 1; |
| 1513 | |
| 1514 | if (lhs->pool < rhs->pool) |
| 1515 | return -1; |
| 1516 | if (lhs->pool > rhs->pool) |
| 1517 | return 1; |
| 1518 | |
| 1519 | if (hoid_get_bitwise_key(lhs) < hoid_get_bitwise_key(rhs)) |
| 1520 | return -1; |
| 1521 | if (hoid_get_bitwise_key(lhs) > hoid_get_bitwise_key(rhs)) |
| 1522 | return 1; |
| 1523 | |
| 1524 | ret = compare_names(lhs->nspace, lhs->nspace_len, |
| 1525 | rhs->nspace, rhs->nspace_len); |
| 1526 | if (ret) |
| 1527 | return ret; |
| 1528 | |
| 1529 | hoid_get_effective_key(lhs, &effective_key1, &effective_key1_len); |
| 1530 | hoid_get_effective_key(rhs, &effective_key2, &effective_key2_len); |
| 1531 | ret = compare_names(effective_key1, effective_key1_len, |
| 1532 | effective_key2, effective_key2_len); |
| 1533 | if (ret) |
| 1534 | return ret; |
| 1535 | |
| 1536 | ret = compare_names(lhs->oid, lhs->oid_len, rhs->oid, rhs->oid_len); |
| 1537 | if (ret) |
| 1538 | return ret; |
| 1539 | |
| 1540 | if (lhs->snapid < rhs->snapid) |
| 1541 | return -1; |
| 1542 | if (lhs->snapid > rhs->snapid) |
| 1543 | return 1; |
| 1544 | |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | /* |
| 1549 | * For decoding ->begin and ->end of MOSDBackoff only -- no MIN/MAX |
| 1550 | * compat stuff here. |
| 1551 | * |
| 1552 | * Assumes @hoid is zero-initialized. |
| 1553 | */ |
| 1554 | static int decode_hoid(void **p, void *end, struct ceph_hobject_id *hoid) |
| 1555 | { |
| 1556 | u8 struct_v; |
| 1557 | u32 struct_len; |
| 1558 | int ret; |
| 1559 | |
| 1560 | ret = ceph_start_decoding(p, end, 4, "hobject_t", &struct_v, |
| 1561 | &struct_len); |
| 1562 | if (ret) |
| 1563 | return ret; |
| 1564 | |
| 1565 | if (struct_v < 4) { |
| 1566 | pr_err("got struct_v %d < 4 of hobject_t\n", struct_v); |
| 1567 | goto e_inval; |
| 1568 | } |
| 1569 | |
| 1570 | hoid->key = ceph_extract_encoded_string(p, end, &hoid->key_len, |
| 1571 | GFP_NOIO); |
| 1572 | if (IS_ERR(hoid->key)) { |
| 1573 | ret = PTR_ERR(hoid->key); |
| 1574 | hoid->key = NULL; |
| 1575 | return ret; |
| 1576 | } |
| 1577 | |
| 1578 | hoid->oid = ceph_extract_encoded_string(p, end, &hoid->oid_len, |
| 1579 | GFP_NOIO); |
| 1580 | if (IS_ERR(hoid->oid)) { |
| 1581 | ret = PTR_ERR(hoid->oid); |
| 1582 | hoid->oid = NULL; |
| 1583 | return ret; |
| 1584 | } |
| 1585 | |
| 1586 | ceph_decode_64_safe(p, end, hoid->snapid, e_inval); |
| 1587 | ceph_decode_32_safe(p, end, hoid->hash, e_inval); |
| 1588 | ceph_decode_8_safe(p, end, hoid->is_max, e_inval); |
| 1589 | |
| 1590 | hoid->nspace = ceph_extract_encoded_string(p, end, &hoid->nspace_len, |
| 1591 | GFP_NOIO); |
| 1592 | if (IS_ERR(hoid->nspace)) { |
| 1593 | ret = PTR_ERR(hoid->nspace); |
| 1594 | hoid->nspace = NULL; |
| 1595 | return ret; |
| 1596 | } |
| 1597 | |
| 1598 | ceph_decode_64_safe(p, end, hoid->pool, e_inval); |
| 1599 | |
| 1600 | ceph_hoid_build_hash_cache(hoid); |
| 1601 | return 0; |
| 1602 | |
| 1603 | e_inval: |
| 1604 | return -EINVAL; |
| 1605 | } |
| 1606 | |
| 1607 | static int hoid_encoding_size(const struct ceph_hobject_id *hoid) |
| 1608 | { |
| 1609 | return 8 + 4 + 1 + 8 + /* snapid, hash, is_max, pool */ |
| 1610 | 4 + hoid->key_len + 4 + hoid->oid_len + 4 + hoid->nspace_len; |
| 1611 | } |
| 1612 | |
| 1613 | static void encode_hoid(void **p, void *end, const struct ceph_hobject_id *hoid) |
| 1614 | { |
| 1615 | ceph_start_encoding(p, 4, 3, hoid_encoding_size(hoid)); |
| 1616 | ceph_encode_string(p, end, hoid->key, hoid->key_len); |
| 1617 | ceph_encode_string(p, end, hoid->oid, hoid->oid_len); |
| 1618 | ceph_encode_64(p, hoid->snapid); |
| 1619 | ceph_encode_32(p, hoid->hash); |
| 1620 | ceph_encode_8(p, hoid->is_max); |
| 1621 | ceph_encode_string(p, end, hoid->nspace, hoid->nspace_len); |
| 1622 | ceph_encode_64(p, hoid->pool); |
| 1623 | } |
| 1624 | |
| 1625 | static void free_hoid(struct ceph_hobject_id *hoid) |
| 1626 | { |
| 1627 | if (hoid) { |
| 1628 | kfree(hoid->key); |
| 1629 | kfree(hoid->oid); |
| 1630 | kfree(hoid->nspace); |
| 1631 | kfree(hoid); |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | static struct ceph_osd_backoff *alloc_backoff(void) |
| 1636 | { |
| 1637 | struct ceph_osd_backoff *backoff; |
| 1638 | |
| 1639 | backoff = kzalloc(sizeof(*backoff), GFP_NOIO); |
| 1640 | if (!backoff) |
| 1641 | return NULL; |
| 1642 | |
| 1643 | RB_CLEAR_NODE(&backoff->spg_node); |
| 1644 | RB_CLEAR_NODE(&backoff->id_node); |
| 1645 | return backoff; |
| 1646 | } |
| 1647 | |
| 1648 | static void free_backoff(struct ceph_osd_backoff *backoff) |
| 1649 | { |
| 1650 | WARN_ON(!RB_EMPTY_NODE(&backoff->spg_node)); |
| 1651 | WARN_ON(!RB_EMPTY_NODE(&backoff->id_node)); |
| 1652 | |
| 1653 | free_hoid(backoff->begin); |
| 1654 | free_hoid(backoff->end); |
| 1655 | kfree(backoff); |
| 1656 | } |
| 1657 | |
| 1658 | /* |
| 1659 | * Within a specific spgid, backoffs are managed by ->begin hoid. |
| 1660 | */ |
| 1661 | DEFINE_RB_INSDEL_FUNCS2(backoff, struct ceph_osd_backoff, begin, hoid_compare, |
| 1662 | RB_BYVAL, spg_node); |
| 1663 | |
| 1664 | static struct ceph_osd_backoff *lookup_containing_backoff(struct rb_root *root, |
| 1665 | const struct ceph_hobject_id *hoid) |
| 1666 | { |
| 1667 | struct rb_node *n = root->rb_node; |
| 1668 | |
| 1669 | while (n) { |
| 1670 | struct ceph_osd_backoff *cur = |
| 1671 | rb_entry(n, struct ceph_osd_backoff, spg_node); |
| 1672 | int cmp; |
| 1673 | |
| 1674 | cmp = hoid_compare(hoid, cur->begin); |
| 1675 | if (cmp < 0) { |
| 1676 | n = n->rb_left; |
| 1677 | } else if (cmp > 0) { |
| 1678 | if (hoid_compare(hoid, cur->end) < 0) |
| 1679 | return cur; |
| 1680 | |
| 1681 | n = n->rb_right; |
| 1682 | } else { |
| 1683 | return cur; |
| 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | return NULL; |
| 1688 | } |
| 1689 | |
| 1690 | /* |
| 1691 | * Each backoff has a unique id within its OSD session. |
| 1692 | */ |
| 1693 | DEFINE_RB_FUNCS(backoff_by_id, struct ceph_osd_backoff, id, id_node) |
| 1694 | |
| 1695 | static void clear_backoffs(struct ceph_osd *osd) |
| 1696 | { |
| 1697 | while (!RB_EMPTY_ROOT(&osd->o_backoff_mappings)) { |
| 1698 | struct ceph_spg_mapping *spg = |
| 1699 | rb_entry(rb_first(&osd->o_backoff_mappings), |
| 1700 | struct ceph_spg_mapping, node); |
| 1701 | |
| 1702 | while (!RB_EMPTY_ROOT(&spg->backoffs)) { |
| 1703 | struct ceph_osd_backoff *backoff = |
| 1704 | rb_entry(rb_first(&spg->backoffs), |
| 1705 | struct ceph_osd_backoff, spg_node); |
| 1706 | |
| 1707 | erase_backoff(&spg->backoffs, backoff); |
| 1708 | erase_backoff_by_id(&osd->o_backoffs_by_id, backoff); |
| 1709 | free_backoff(backoff); |
| 1710 | } |
| 1711 | erase_spg_mapping(&osd->o_backoff_mappings, spg); |
| 1712 | free_spg_mapping(spg); |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | /* |
| 1717 | * Set up a temporary, non-owning view into @t. |
| 1718 | */ |
| 1719 | static void hoid_fill_from_target(struct ceph_hobject_id *hoid, |
| 1720 | const struct ceph_osd_request_target *t) |
| 1721 | { |
| 1722 | hoid->key = NULL; |
| 1723 | hoid->key_len = 0; |
| 1724 | hoid->oid = t->target_oid.name; |
| 1725 | hoid->oid_len = t->target_oid.name_len; |
| 1726 | hoid->snapid = CEPH_NOSNAP; |
| 1727 | hoid->hash = t->pgid.seed; |
| 1728 | hoid->is_max = false; |
| 1729 | if (t->target_oloc.pool_ns) { |
| 1730 | hoid->nspace = t->target_oloc.pool_ns->str; |
| 1731 | hoid->nspace_len = t->target_oloc.pool_ns->len; |
| 1732 | } else { |
| 1733 | hoid->nspace = NULL; |
| 1734 | hoid->nspace_len = 0; |
| 1735 | } |
| 1736 | hoid->pool = t->target_oloc.pool; |
| 1737 | ceph_hoid_build_hash_cache(hoid); |
| 1738 | } |
| 1739 | |
| 1740 | static bool should_plug_request(struct ceph_osd_request *req) |
| 1741 | { |
| 1742 | struct ceph_osd *osd = req->r_osd; |
| 1743 | struct ceph_spg_mapping *spg; |
| 1744 | struct ceph_osd_backoff *backoff; |
| 1745 | struct ceph_hobject_id hoid; |
| 1746 | |
| 1747 | spg = lookup_spg_mapping(&osd->o_backoff_mappings, &req->r_t.spgid); |
| 1748 | if (!spg) |
| 1749 | return false; |
| 1750 | |
| 1751 | hoid_fill_from_target(&hoid, &req->r_t); |
| 1752 | backoff = lookup_containing_backoff(&spg->backoffs, &hoid); |
| 1753 | if (!backoff) |
| 1754 | return false; |
| 1755 | |
| 1756 | dout("%s req %p tid %llu backoff osd%d spgid %llu.%xs%d id %llu\n", |
| 1757 | __func__, req, req->r_tid, osd->o_osd, backoff->spgid.pgid.pool, |
| 1758 | backoff->spgid.pgid.seed, backoff->spgid.shard, backoff->id); |
| 1759 | return true; |
| 1760 | } |
| 1761 | |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1762 | static void setup_request_data(struct ceph_osd_request *req, |
| 1763 | struct ceph_msg *msg) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1764 | { |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1765 | u32 data_len = 0; |
| 1766 | int i; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1767 | |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1768 | if (!list_empty(&msg->data)) |
| 1769 | return; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1770 | |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1771 | WARN_ON(msg->data_length); |
| 1772 | for (i = 0; i < req->r_num_ops; i++) { |
| 1773 | struct ceph_osd_req_op *op = &req->r_ops[i]; |
| 1774 | |
| 1775 | switch (op->op) { |
| 1776 | /* request */ |
| 1777 | case CEPH_OSD_OP_WRITE: |
| 1778 | case CEPH_OSD_OP_WRITEFULL: |
| 1779 | WARN_ON(op->indata_len != op->extent.length); |
| 1780 | ceph_osdc_msg_data_add(msg, &op->extent.osd_data); |
| 1781 | break; |
| 1782 | case CEPH_OSD_OP_SETXATTR: |
| 1783 | case CEPH_OSD_OP_CMPXATTR: |
| 1784 | WARN_ON(op->indata_len != op->xattr.name_len + |
| 1785 | op->xattr.value_len); |
| 1786 | ceph_osdc_msg_data_add(msg, &op->xattr.osd_data); |
| 1787 | break; |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 1788 | case CEPH_OSD_OP_NOTIFY_ACK: |
| 1789 | ceph_osdc_msg_data_add(msg, |
| 1790 | &op->notify_ack.request_data); |
| 1791 | break; |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1792 | |
| 1793 | /* reply */ |
| 1794 | case CEPH_OSD_OP_STAT: |
| 1795 | ceph_osdc_msg_data_add(req->r_reply, |
| 1796 | &op->raw_data_in); |
| 1797 | break; |
| 1798 | case CEPH_OSD_OP_READ: |
| 1799 | ceph_osdc_msg_data_add(req->r_reply, |
| 1800 | &op->extent.osd_data); |
| 1801 | break; |
Douglas Fuller | a4ed38d | 2015-07-17 13:18:07 -0700 | [diff] [blame] | 1802 | case CEPH_OSD_OP_LIST_WATCHERS: |
| 1803 | ceph_osdc_msg_data_add(req->r_reply, |
| 1804 | &op->list_watchers.response_data); |
| 1805 | break; |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1806 | |
| 1807 | /* both */ |
| 1808 | case CEPH_OSD_OP_CALL: |
| 1809 | WARN_ON(op->indata_len != op->cls.class_len + |
| 1810 | op->cls.method_len + |
| 1811 | op->cls.indata_len); |
| 1812 | ceph_osdc_msg_data_add(msg, &op->cls.request_info); |
| 1813 | /* optional, can be NONE */ |
| 1814 | ceph_osdc_msg_data_add(msg, &op->cls.request_data); |
| 1815 | /* optional, can be NONE */ |
| 1816 | ceph_osdc_msg_data_add(req->r_reply, |
| 1817 | &op->cls.response_data); |
| 1818 | break; |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 1819 | case CEPH_OSD_OP_NOTIFY: |
| 1820 | ceph_osdc_msg_data_add(msg, |
| 1821 | &op->notify.request_data); |
| 1822 | ceph_osdc_msg_data_add(req->r_reply, |
| 1823 | &op->notify.response_data); |
| 1824 | break; |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | data_len += op->indata_len; |
| 1828 | } |
| 1829 | |
| 1830 | WARN_ON(data_len != msg->data_length); |
| 1831 | } |
| 1832 | |
Ilya Dryomov | 2e59ffd | 2017-06-15 16:30:53 +0200 | [diff] [blame] | 1833 | static void encode_pgid(void **p, const struct ceph_pg *pgid) |
| 1834 | { |
| 1835 | ceph_encode_8(p, 1); |
| 1836 | ceph_encode_64(p, pgid->pool); |
| 1837 | ceph_encode_32(p, pgid->seed); |
| 1838 | ceph_encode_32(p, -1); /* preferred */ |
| 1839 | } |
| 1840 | |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1841 | static void encode_spgid(void **p, const struct ceph_spg *spgid) |
| 1842 | { |
| 1843 | ceph_start_encoding(p, 1, 1, CEPH_PGID_ENCODING_LEN + 1); |
| 1844 | encode_pgid(p, &spgid->pgid); |
| 1845 | ceph_encode_8(p, spgid->shard); |
| 1846 | } |
| 1847 | |
Ilya Dryomov | 2e59ffd | 2017-06-15 16:30:53 +0200 | [diff] [blame] | 1848 | static void encode_oloc(void **p, void *end, |
| 1849 | const struct ceph_object_locator *oloc) |
| 1850 | { |
| 1851 | ceph_start_encoding(p, 5, 4, ceph_oloc_encoding_size(oloc)); |
| 1852 | ceph_encode_64(p, oloc->pool); |
| 1853 | ceph_encode_32(p, -1); /* preferred */ |
| 1854 | ceph_encode_32(p, 0); /* key len */ |
| 1855 | if (oloc->pool_ns) |
| 1856 | ceph_encode_string(p, end, oloc->pool_ns->str, |
| 1857 | oloc->pool_ns->len); |
| 1858 | else |
| 1859 | ceph_encode_32(p, 0); |
| 1860 | } |
| 1861 | |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1862 | static void encode_request_partial(struct ceph_osd_request *req, |
| 1863 | struct ceph_msg *msg) |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1864 | { |
| 1865 | void *p = msg->front.iov_base; |
| 1866 | void *const end = p + msg->front_alloc_len; |
| 1867 | u32 data_len = 0; |
| 1868 | int i; |
| 1869 | |
| 1870 | if (req->r_flags & CEPH_OSD_FLAG_WRITE) { |
| 1871 | /* snapshots aren't writeable */ |
| 1872 | WARN_ON(req->r_snapid != CEPH_NOSNAP); |
| 1873 | } else { |
| 1874 | WARN_ON(req->r_mtime.tv_sec || req->r_mtime.tv_nsec || |
| 1875 | req->r_data_offset || req->r_snapc); |
| 1876 | } |
| 1877 | |
| 1878 | setup_request_data(req, msg); |
| 1879 | |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1880 | encode_spgid(&p, &req->r_t.spgid); /* actual spg */ |
| 1881 | ceph_encode_32(&p, req->r_t.pgid.seed); /* raw hash */ |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1882 | ceph_encode_32(&p, req->r_osdc->osdmap->epoch); |
| 1883 | ceph_encode_32(&p, req->r_flags); |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1884 | |
| 1885 | /* reqid */ |
| 1886 | ceph_start_encoding(&p, 2, 2, sizeof(struct ceph_osd_reqid)); |
| 1887 | memset(p, 0, sizeof(struct ceph_osd_reqid)); |
| 1888 | p += sizeof(struct ceph_osd_reqid); |
| 1889 | |
| 1890 | /* trace */ |
| 1891 | memset(p, 0, sizeof(struct ceph_blkin_trace_info)); |
| 1892 | p += sizeof(struct ceph_blkin_trace_info); |
| 1893 | |
| 1894 | ceph_encode_32(&p, 0); /* client_inc, always 0 */ |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1895 | ceph_encode_timespec(p, &req->r_mtime); |
| 1896 | p += sizeof(struct ceph_timespec); |
Jeff Layton | aa26d66 | 2017-04-04 08:39:36 -0400 | [diff] [blame] | 1897 | |
Ilya Dryomov | 2e59ffd | 2017-06-15 16:30:53 +0200 | [diff] [blame] | 1898 | encode_oloc(&p, end, &req->r_t.target_oloc); |
Ilya Dryomov | 2e59ffd | 2017-06-15 16:30:53 +0200 | [diff] [blame] | 1899 | ceph_encode_string(&p, end, req->r_t.target_oid.name, |
| 1900 | req->r_t.target_oid.name_len); |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1901 | |
| 1902 | /* ops, can imply data */ |
| 1903 | ceph_encode_16(&p, req->r_num_ops); |
| 1904 | for (i = 0; i < req->r_num_ops; i++) { |
| 1905 | data_len += osd_req_encode_op(p, &req->r_ops[i]); |
| 1906 | p += sizeof(struct ceph_osd_op); |
| 1907 | } |
| 1908 | |
| 1909 | ceph_encode_64(&p, req->r_snapid); /* snapid */ |
| 1910 | if (req->r_snapc) { |
| 1911 | ceph_encode_64(&p, req->r_snapc->seq); |
| 1912 | ceph_encode_32(&p, req->r_snapc->num_snaps); |
| 1913 | for (i = 0; i < req->r_snapc->num_snaps; i++) |
| 1914 | ceph_encode_64(&p, req->r_snapc->snaps[i]); |
| 1915 | } else { |
| 1916 | ceph_encode_64(&p, 0); /* snap_seq */ |
| 1917 | ceph_encode_32(&p, 0); /* snaps len */ |
| 1918 | } |
| 1919 | |
| 1920 | ceph_encode_32(&p, req->r_attempts); /* retry_attempt */ |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1921 | BUG_ON(p != end - 8); /* space for features */ |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1922 | |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1923 | msg->hdr.version = cpu_to_le16(8); /* MOSDOp v8 */ |
| 1924 | /* front_len is finalized in encode_request_finish() */ |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 1925 | msg->hdr.data_len = cpu_to_le32(data_len); |
| 1926 | /* |
| 1927 | * The header "data_off" is a hint to the receiver allowing it |
| 1928 | * to align received data into its buffers such that there's no |
| 1929 | * need to re-copy it before writing it to disk (direct I/O). |
| 1930 | */ |
| 1931 | msg->hdr.data_off = cpu_to_le16(req->r_data_offset); |
| 1932 | |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 1933 | dout("%s req %p msg %p oid %s oid_len %d\n", __func__, req, msg, |
| 1934 | req->r_t.target_oid.name, req->r_t.target_oid.name_len); |
| 1935 | } |
| 1936 | |
| 1937 | static void encode_request_finish(struct ceph_msg *msg) |
| 1938 | { |
| 1939 | void *p = msg->front.iov_base; |
| 1940 | void *const end = p + msg->front_alloc_len; |
| 1941 | |
| 1942 | if (CEPH_HAVE_FEATURE(msg->con->peer_features, RESEND_ON_SPLIT)) { |
| 1943 | /* luminous OSD -- encode features and be done */ |
| 1944 | p = end - 8; |
| 1945 | ceph_encode_64(&p, msg->con->peer_features); |
| 1946 | } else { |
| 1947 | struct { |
| 1948 | char spgid[CEPH_ENCODING_START_BLK_LEN + |
| 1949 | CEPH_PGID_ENCODING_LEN + 1]; |
| 1950 | __le32 hash; |
| 1951 | __le32 epoch; |
| 1952 | __le32 flags; |
| 1953 | char reqid[CEPH_ENCODING_START_BLK_LEN + |
| 1954 | sizeof(struct ceph_osd_reqid)]; |
| 1955 | char trace[sizeof(struct ceph_blkin_trace_info)]; |
| 1956 | __le32 client_inc; |
| 1957 | struct ceph_timespec mtime; |
| 1958 | } __packed head; |
| 1959 | struct ceph_pg pgid; |
| 1960 | void *oloc, *oid, *tail; |
| 1961 | int oloc_len, oid_len, tail_len; |
| 1962 | int len; |
| 1963 | |
| 1964 | /* |
| 1965 | * Pre-luminous OSD -- reencode v8 into v4 using @head |
| 1966 | * as a temporary buffer. Encode the raw PG; the rest |
| 1967 | * is just a matter of moving oloc, oid and tail blobs |
| 1968 | * around. |
| 1969 | */ |
| 1970 | memcpy(&head, p, sizeof(head)); |
| 1971 | p += sizeof(head); |
| 1972 | |
| 1973 | oloc = p; |
| 1974 | p += CEPH_ENCODING_START_BLK_LEN; |
| 1975 | pgid.pool = ceph_decode_64(&p); |
| 1976 | p += 4 + 4; /* preferred, key len */ |
| 1977 | len = ceph_decode_32(&p); |
| 1978 | p += len; /* nspace */ |
| 1979 | oloc_len = p - oloc; |
| 1980 | |
| 1981 | oid = p; |
| 1982 | len = ceph_decode_32(&p); |
| 1983 | p += len; |
| 1984 | oid_len = p - oid; |
| 1985 | |
| 1986 | tail = p; |
| 1987 | tail_len = (end - p) - 8; |
| 1988 | |
| 1989 | p = msg->front.iov_base; |
| 1990 | ceph_encode_copy(&p, &head.client_inc, sizeof(head.client_inc)); |
| 1991 | ceph_encode_copy(&p, &head.epoch, sizeof(head.epoch)); |
| 1992 | ceph_encode_copy(&p, &head.flags, sizeof(head.flags)); |
| 1993 | ceph_encode_copy(&p, &head.mtime, sizeof(head.mtime)); |
| 1994 | |
| 1995 | /* reassert_version */ |
| 1996 | memset(p, 0, sizeof(struct ceph_eversion)); |
| 1997 | p += sizeof(struct ceph_eversion); |
| 1998 | |
| 1999 | BUG_ON(p >= oloc); |
| 2000 | memmove(p, oloc, oloc_len); |
| 2001 | p += oloc_len; |
| 2002 | |
| 2003 | pgid.seed = le32_to_cpu(head.hash); |
| 2004 | encode_pgid(&p, &pgid); /* raw pg */ |
| 2005 | |
| 2006 | BUG_ON(p >= oid); |
| 2007 | memmove(p, oid, oid_len); |
| 2008 | p += oid_len; |
| 2009 | |
| 2010 | /* tail -- ops, snapid, snapc, retry_attempt */ |
| 2011 | BUG_ON(p >= tail); |
| 2012 | memmove(p, tail, tail_len); |
| 2013 | p += tail_len; |
| 2014 | |
| 2015 | msg->hdr.version = cpu_to_le16(4); /* MOSDOp v4 */ |
| 2016 | } |
| 2017 | |
| 2018 | BUG_ON(p > end); |
| 2019 | msg->front.iov_len = p - msg->front.iov_base; |
| 2020 | msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); |
| 2021 | |
| 2022 | dout("%s msg %p tid %llu %u+%u+%u v%d\n", __func__, msg, |
| 2023 | le64_to_cpu(msg->hdr.tid), le32_to_cpu(msg->hdr.front_len), |
| 2024 | le32_to_cpu(msg->hdr.middle_len), le32_to_cpu(msg->hdr.data_len), |
| 2025 | le16_to_cpu(msg->hdr.version)); |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | /* |
| 2029 | * @req has to be assigned a tid and registered. |
| 2030 | */ |
| 2031 | static void send_request(struct ceph_osd_request *req) |
| 2032 | { |
| 2033 | struct ceph_osd *osd = req->r_osd; |
| 2034 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2035 | verify_osd_locked(osd); |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 2036 | WARN_ON(osd->o_osd != req->r_t.osd); |
| 2037 | |
Ilya Dryomov | a02a946 | 2017-06-19 12:18:05 +0200 | [diff] [blame] | 2038 | /* backoff? */ |
| 2039 | if (should_plug_request(req)) |
| 2040 | return; |
| 2041 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2042 | /* |
| 2043 | * We may have a previously queued request message hanging |
| 2044 | * around. Cancel it to avoid corrupting the msgr. |
| 2045 | */ |
| 2046 | if (req->r_sent) |
| 2047 | ceph_msg_revoke(req->r_request); |
| 2048 | |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 2049 | req->r_flags |= CEPH_OSD_FLAG_KNOWN_REDIR; |
| 2050 | if (req->r_attempts) |
| 2051 | req->r_flags |= CEPH_OSD_FLAG_RETRY; |
| 2052 | else |
| 2053 | WARN_ON(req->r_flags & CEPH_OSD_FLAG_RETRY); |
| 2054 | |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 2055 | encode_request_partial(req, req->r_request); |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 2056 | |
Ilya Dryomov | 04c7d78 | 2017-06-15 16:30:55 +0200 | [diff] [blame] | 2057 | dout("%s req %p tid %llu to pgid %llu.%x spgid %llu.%xs%d osd%d e%u flags 0x%x attempt %d\n", |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 2058 | __func__, req, req->r_tid, req->r_t.pgid.pool, req->r_t.pgid.seed, |
Ilya Dryomov | dc98ff7 | 2017-06-15 16:30:53 +0200 | [diff] [blame] | 2059 | req->r_t.spgid.pgid.pool, req->r_t.spgid.pgid.seed, |
Ilya Dryomov | 04c7d78 | 2017-06-15 16:30:55 +0200 | [diff] [blame] | 2060 | req->r_t.spgid.shard, osd->o_osd, req->r_t.epoch, req->r_flags, |
| 2061 | req->r_attempts); |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 2062 | |
| 2063 | req->r_t.paused = false; |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 2064 | req->r_stamp = jiffies; |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 2065 | req->r_attempts++; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2066 | |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 2067 | req->r_sent = osd->o_incarnation; |
| 2068 | req->r_request->hdr.tid = cpu_to_le64(req->r_tid); |
| 2069 | ceph_con_send(&osd->o_con, ceph_msg_get(req->r_request)); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 2072 | static void maybe_request_map(struct ceph_osd_client *osdc) |
| 2073 | { |
| 2074 | bool continuous = false; |
| 2075 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2076 | verify_osdc_locked(osdc); |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 2077 | WARN_ON(!osdc->osdmap->epoch); |
| 2078 | |
Ilya Dryomov | b7ec35b | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 2079 | if (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) || |
| 2080 | ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSERD) || |
| 2081 | ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) { |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 2082 | dout("%s osdc %p continuous\n", __func__, osdc); |
| 2083 | continuous = true; |
| 2084 | } else { |
| 2085 | dout("%s osdc %p onetime\n", __func__, osdc); |
| 2086 | } |
| 2087 | |
| 2088 | if (ceph_monc_want_map(&osdc->client->monc, CEPH_SUB_OSDMAP, |
| 2089 | osdc->osdmap->epoch + 1, continuous)) |
| 2090 | ceph_monc_renew_subs(&osdc->client->monc); |
| 2091 | } |
| 2092 | |
Jeff Layton | a1f4020 | 2017-04-04 08:39:37 -0400 | [diff] [blame] | 2093 | static void complete_request(struct ceph_osd_request *req, int err); |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2094 | static void send_map_check(struct ceph_osd_request *req); |
| 2095 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2096 | static void __submit_request(struct ceph_osd_request *req, bool wrlocked) |
Ilya Dryomov | 0bbfdfe | 2014-01-31 19:33:39 +0200 | [diff] [blame] | 2097 | { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2098 | struct ceph_osd_client *osdc = req->r_osdc; |
| 2099 | struct ceph_osd *osd; |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2100 | enum calc_target_result ct_res; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2101 | bool need_send = false; |
| 2102 | bool promoted = false; |
Jeff Layton | a1f4020 | 2017-04-04 08:39:37 -0400 | [diff] [blame] | 2103 | bool need_abort = false; |
Ilya Dryomov | 0bbfdfe | 2014-01-31 19:33:39 +0200 | [diff] [blame] | 2104 | |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 2105 | WARN_ON(req->r_tid); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2106 | dout("%s req %p wrlocked %d\n", __func__, req, wrlocked); |
| 2107 | |
| 2108 | again: |
Ilya Dryomov | 7de030d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 2109 | ct_res = calc_target(osdc, &req->r_t, NULL, false); |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2110 | if (ct_res == CALC_TARGET_POOL_DNE && !wrlocked) |
| 2111 | goto promote; |
| 2112 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2113 | osd = lookup_create_osd(osdc, req->r_t.osd, wrlocked); |
| 2114 | if (IS_ERR(osd)) { |
| 2115 | WARN_ON(PTR_ERR(osd) != -EAGAIN || wrlocked); |
| 2116 | goto promote; |
Ilya Dryomov | 0bbfdfe | 2014-01-31 19:33:39 +0200 | [diff] [blame] | 2117 | } |
| 2118 | |
Jeff Layton | 58eb793 | 2017-04-18 09:21:16 -0400 | [diff] [blame] | 2119 | if (osdc->osdmap->epoch < osdc->epoch_barrier) { |
| 2120 | dout("req %p epoch %u barrier %u\n", req, osdc->osdmap->epoch, |
| 2121 | osdc->epoch_barrier); |
| 2122 | req->r_t.paused = true; |
| 2123 | maybe_request_map(osdc); |
| 2124 | } else if ((req->r_flags & CEPH_OSD_FLAG_WRITE) && |
| 2125 | ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2126 | dout("req %p pausewr\n", req); |
| 2127 | req->r_t.paused = true; |
| 2128 | maybe_request_map(osdc); |
| 2129 | } else if ((req->r_flags & CEPH_OSD_FLAG_READ) && |
Ilya Dryomov | b7ec35b | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 2130 | ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSERD)) { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2131 | dout("req %p pauserd\n", req); |
| 2132 | req->r_t.paused = true; |
| 2133 | maybe_request_map(osdc); |
| 2134 | } else if ((req->r_flags & CEPH_OSD_FLAG_WRITE) && |
| 2135 | !(req->r_flags & (CEPH_OSD_FLAG_FULL_TRY | |
| 2136 | CEPH_OSD_FLAG_FULL_FORCE)) && |
Ilya Dryomov | b7ec35b | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 2137 | (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) || |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2138 | pool_full(osdc, req->r_t.base_oloc.pool))) { |
| 2139 | dout("req %p full/pool_full\n", req); |
| 2140 | pr_warn_ratelimited("FULL or reached pool quota\n"); |
| 2141 | req->r_t.paused = true; |
| 2142 | maybe_request_map(osdc); |
Jeff Layton | a1f4020 | 2017-04-04 08:39:37 -0400 | [diff] [blame] | 2143 | if (req->r_abort_on_full) |
| 2144 | need_abort = true; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2145 | } else if (!osd_homeless(osd)) { |
| 2146 | need_send = true; |
Ilya Dryomov | 0bbfdfe | 2014-01-31 19:33:39 +0200 | [diff] [blame] | 2147 | } else { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2148 | maybe_request_map(osdc); |
Ilya Dryomov | 0bbfdfe | 2014-01-31 19:33:39 +0200 | [diff] [blame] | 2149 | } |
| 2150 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2151 | mutex_lock(&osd->lock); |
| 2152 | /* |
| 2153 | * Assign the tid atomically with send_request() to protect |
| 2154 | * multiple writes to the same object from racing with each |
| 2155 | * other, resulting in out of order ops on the OSDs. |
| 2156 | */ |
| 2157 | req->r_tid = atomic64_inc_return(&osdc->last_tid); |
| 2158 | link_request(osd, req); |
| 2159 | if (need_send) |
| 2160 | send_request(req); |
Jeff Layton | a1f4020 | 2017-04-04 08:39:37 -0400 | [diff] [blame] | 2161 | else if (need_abort) |
| 2162 | complete_request(req, -ENOSPC); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2163 | mutex_unlock(&osd->lock); |
| 2164 | |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2165 | if (ct_res == CALC_TARGET_POOL_DNE) |
| 2166 | send_map_check(req); |
| 2167 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2168 | if (promoted) |
| 2169 | downgrade_write(&osdc->lock); |
| 2170 | return; |
| 2171 | |
| 2172 | promote: |
| 2173 | up_read(&osdc->lock); |
| 2174 | down_write(&osdc->lock); |
| 2175 | wrlocked = true; |
| 2176 | promoted = true; |
| 2177 | goto again; |
| 2178 | } |
| 2179 | |
| 2180 | static void account_request(struct ceph_osd_request *req) |
| 2181 | { |
Ilya Dryomov | 54ea004 | 2017-02-11 18:48:41 +0100 | [diff] [blame] | 2182 | WARN_ON(req->r_flags & (CEPH_OSD_FLAG_ACK | CEPH_OSD_FLAG_ONDISK)); |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 2183 | WARN_ON(!(req->r_flags & (CEPH_OSD_FLAG_READ | CEPH_OSD_FLAG_WRITE))); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2184 | |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 2185 | req->r_flags |= CEPH_OSD_FLAG_ONDISK; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2186 | atomic_inc(&req->r_osdc->num_requests); |
Ilya Dryomov | 7cc5e38 | 2017-02-12 17:11:07 +0100 | [diff] [blame] | 2187 | |
| 2188 | req->r_start_stamp = jiffies; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | static void submit_request(struct ceph_osd_request *req, bool wrlocked) |
| 2192 | { |
| 2193 | ceph_osdc_get_request(req); |
| 2194 | account_request(req); |
| 2195 | __submit_request(req, wrlocked); |
| 2196 | } |
| 2197 | |
Ilya Dryomov | 45ee2c1 | 2016-12-02 14:01:55 +0100 | [diff] [blame] | 2198 | static void finish_request(struct ceph_osd_request *req) |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2199 | { |
| 2200 | struct ceph_osd_client *osdc = req->r_osdc; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2201 | |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2202 | WARN_ON(lookup_request_mc(&osdc->map_checks, req->r_tid)); |
Ilya Dryomov | 04c7d78 | 2017-06-15 16:30:55 +0200 | [diff] [blame] | 2203 | dout("%s req %p tid %llu\n", __func__, req, req->r_tid); |
| 2204 | |
| 2205 | if (req->r_osd) |
| 2206 | unlink_request(req->r_osd, req); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2207 | atomic_dec(&osdc->num_requests); |
| 2208 | |
| 2209 | /* |
| 2210 | * If an OSD has failed or returned and a request has been sent |
| 2211 | * twice, it's possible to get a reply and end up here while the |
| 2212 | * request message is queued for delivery. We will ignore the |
| 2213 | * reply, so not a big deal, but better to try and catch it. |
| 2214 | */ |
| 2215 | ceph_msg_revoke(req->r_request); |
| 2216 | ceph_msg_revoke_incoming(req->r_reply); |
| 2217 | } |
| 2218 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 2219 | static void __complete_request(struct ceph_osd_request *req) |
| 2220 | { |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 2221 | if (req->r_callback) { |
| 2222 | dout("%s req %p tid %llu cb %pf result %d\n", __func__, req, |
| 2223 | req->r_tid, req->r_callback, req->r_result); |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 2224 | req->r_callback(req); |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 2225 | } |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 2226 | } |
| 2227 | |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2228 | /* |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 2229 | * This is open-coded in handle_reply(). |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2230 | */ |
| 2231 | static void complete_request(struct ceph_osd_request *req, int err) |
| 2232 | { |
| 2233 | dout("%s req %p tid %llu err %d\n", __func__, req, req->r_tid, err); |
| 2234 | |
| 2235 | req->r_result = err; |
Ilya Dryomov | 45ee2c1 | 2016-12-02 14:01:55 +0100 | [diff] [blame] | 2236 | finish_request(req); |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2237 | __complete_request(req); |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 2238 | complete_all(&req->r_completion); |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2239 | ceph_osdc_put_request(req); |
| 2240 | } |
| 2241 | |
| 2242 | static void cancel_map_check(struct ceph_osd_request *req) |
| 2243 | { |
| 2244 | struct ceph_osd_client *osdc = req->r_osdc; |
| 2245 | struct ceph_osd_request *lookup_req; |
| 2246 | |
| 2247 | verify_osdc_wrlocked(osdc); |
| 2248 | |
| 2249 | lookup_req = lookup_request_mc(&osdc->map_checks, req->r_tid); |
| 2250 | if (!lookup_req) |
| 2251 | return; |
| 2252 | |
| 2253 | WARN_ON(lookup_req != req); |
| 2254 | erase_request_mc(&osdc->map_checks, req); |
| 2255 | ceph_osdc_put_request(req); |
| 2256 | } |
| 2257 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2258 | static void cancel_request(struct ceph_osd_request *req) |
| 2259 | { |
| 2260 | dout("%s req %p tid %llu\n", __func__, req, req->r_tid); |
| 2261 | |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2262 | cancel_map_check(req); |
Ilya Dryomov | 45ee2c1 | 2016-12-02 14:01:55 +0100 | [diff] [blame] | 2263 | finish_request(req); |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 2264 | complete_all(&req->r_completion); |
Ilya Dryomov | c297eb42 | 2016-12-02 14:01:55 +0100 | [diff] [blame] | 2265 | ceph_osdc_put_request(req); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 2266 | } |
| 2267 | |
Ilya Dryomov | 7cc5e38 | 2017-02-12 17:11:07 +0100 | [diff] [blame] | 2268 | static void abort_request(struct ceph_osd_request *req, int err) |
| 2269 | { |
| 2270 | dout("%s req %p tid %llu err %d\n", __func__, req, req->r_tid, err); |
| 2271 | |
| 2272 | cancel_map_check(req); |
| 2273 | complete_request(req, err); |
| 2274 | } |
| 2275 | |
Jeff Layton | 58eb793 | 2017-04-18 09:21:16 -0400 | [diff] [blame] | 2276 | static void update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb) |
| 2277 | { |
| 2278 | if (likely(eb > osdc->epoch_barrier)) { |
| 2279 | dout("updating epoch_barrier from %u to %u\n", |
| 2280 | osdc->epoch_barrier, eb); |
| 2281 | osdc->epoch_barrier = eb; |
| 2282 | /* Request map if we're not to the barrier yet */ |
| 2283 | if (eb > osdc->osdmap->epoch) |
| 2284 | maybe_request_map(osdc); |
| 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb) |
| 2289 | { |
| 2290 | down_read(&osdc->lock); |
| 2291 | if (unlikely(eb > osdc->epoch_barrier)) { |
| 2292 | up_read(&osdc->lock); |
| 2293 | down_write(&osdc->lock); |
| 2294 | update_epoch_barrier(osdc, eb); |
| 2295 | up_write(&osdc->lock); |
| 2296 | } else { |
| 2297 | up_read(&osdc->lock); |
| 2298 | } |
| 2299 | } |
| 2300 | EXPORT_SYMBOL(ceph_osdc_update_epoch_barrier); |
| 2301 | |
Jeff Layton | fc36d0a | 2017-04-04 08:39:39 -0400 | [diff] [blame] | 2302 | /* |
| 2303 | * Drop all pending requests that are stalled waiting on a full condition to |
Jeff Layton | 58eb793 | 2017-04-18 09:21:16 -0400 | [diff] [blame] | 2304 | * clear, and complete them with ENOSPC as the return code. Set the |
| 2305 | * osdc->epoch_barrier to the latest map epoch that we've seen if any were |
| 2306 | * cancelled. |
Jeff Layton | fc36d0a | 2017-04-04 08:39:39 -0400 | [diff] [blame] | 2307 | */ |
| 2308 | static void ceph_osdc_abort_on_full(struct ceph_osd_client *osdc) |
| 2309 | { |
| 2310 | struct rb_node *n; |
Jeff Layton | 58eb793 | 2017-04-18 09:21:16 -0400 | [diff] [blame] | 2311 | bool victims = false; |
Jeff Layton | fc36d0a | 2017-04-04 08:39:39 -0400 | [diff] [blame] | 2312 | |
| 2313 | dout("enter abort_on_full\n"); |
| 2314 | |
| 2315 | if (!ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) && !have_pool_full(osdc)) |
| 2316 | goto out; |
| 2317 | |
Jeff Layton | 58eb793 | 2017-04-18 09:21:16 -0400 | [diff] [blame] | 2318 | /* Scan list and see if there is anything to abort */ |
| 2319 | for (n = rb_first(&osdc->osds); n; n = rb_next(n)) { |
| 2320 | struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node); |
| 2321 | struct rb_node *m; |
| 2322 | |
| 2323 | m = rb_first(&osd->o_requests); |
| 2324 | while (m) { |
| 2325 | struct ceph_osd_request *req = rb_entry(m, |
| 2326 | struct ceph_osd_request, r_node); |
| 2327 | m = rb_next(m); |
| 2328 | |
| 2329 | if (req->r_abort_on_full) { |
| 2330 | victims = true; |
| 2331 | break; |
| 2332 | } |
| 2333 | } |
| 2334 | if (victims) |
| 2335 | break; |
| 2336 | } |
| 2337 | |
| 2338 | if (!victims) |
| 2339 | goto out; |
| 2340 | |
| 2341 | /* |
| 2342 | * Update the barrier to current epoch if it's behind that point, |
| 2343 | * since we know we have some calls to be aborted in the tree. |
| 2344 | */ |
| 2345 | update_epoch_barrier(osdc, osdc->osdmap->epoch); |
| 2346 | |
Jeff Layton | fc36d0a | 2017-04-04 08:39:39 -0400 | [diff] [blame] | 2347 | for (n = rb_first(&osdc->osds); n; n = rb_next(n)) { |
| 2348 | struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node); |
| 2349 | struct rb_node *m; |
| 2350 | |
| 2351 | m = rb_first(&osd->o_requests); |
| 2352 | while (m) { |
| 2353 | struct ceph_osd_request *req = rb_entry(m, |
| 2354 | struct ceph_osd_request, r_node); |
| 2355 | m = rb_next(m); |
| 2356 | |
| 2357 | if (req->r_abort_on_full && |
| 2358 | (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) || |
| 2359 | pool_full(osdc, req->r_t.target_oloc.pool))) |
| 2360 | abort_request(req, -ENOSPC); |
| 2361 | } |
| 2362 | } |
| 2363 | out: |
Jeff Layton | 58eb793 | 2017-04-18 09:21:16 -0400 | [diff] [blame] | 2364 | dout("return abort_on_full barrier=%u\n", osdc->epoch_barrier); |
Jeff Layton | fc36d0a | 2017-04-04 08:39:39 -0400 | [diff] [blame] | 2365 | } |
| 2366 | |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2367 | static void check_pool_dne(struct ceph_osd_request *req) |
| 2368 | { |
| 2369 | struct ceph_osd_client *osdc = req->r_osdc; |
| 2370 | struct ceph_osdmap *map = osdc->osdmap; |
| 2371 | |
| 2372 | verify_osdc_wrlocked(osdc); |
| 2373 | WARN_ON(!map->epoch); |
| 2374 | |
| 2375 | if (req->r_attempts) { |
| 2376 | /* |
| 2377 | * We sent a request earlier, which means that |
| 2378 | * previously the pool existed, and now it does not |
| 2379 | * (i.e., it was deleted). |
| 2380 | */ |
| 2381 | req->r_map_dne_bound = map->epoch; |
| 2382 | dout("%s req %p tid %llu pool disappeared\n", __func__, req, |
| 2383 | req->r_tid); |
| 2384 | } else { |
| 2385 | dout("%s req %p tid %llu map_dne_bound %u have %u\n", __func__, |
| 2386 | req, req->r_tid, req->r_map_dne_bound, map->epoch); |
| 2387 | } |
| 2388 | |
| 2389 | if (req->r_map_dne_bound) { |
| 2390 | if (map->epoch >= req->r_map_dne_bound) { |
| 2391 | /* we had a new enough map */ |
| 2392 | pr_info_ratelimited("tid %llu pool does not exist\n", |
| 2393 | req->r_tid); |
| 2394 | complete_request(req, -ENOENT); |
| 2395 | } |
| 2396 | } else { |
| 2397 | send_map_check(req); |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | static void map_check_cb(struct ceph_mon_generic_request *greq) |
| 2402 | { |
| 2403 | struct ceph_osd_client *osdc = &greq->monc->client->osdc; |
| 2404 | struct ceph_osd_request *req; |
| 2405 | u64 tid = greq->private_data; |
| 2406 | |
| 2407 | WARN_ON(greq->result || !greq->u.newest); |
| 2408 | |
| 2409 | down_write(&osdc->lock); |
| 2410 | req = lookup_request_mc(&osdc->map_checks, tid); |
| 2411 | if (!req) { |
| 2412 | dout("%s tid %llu dne\n", __func__, tid); |
| 2413 | goto out_unlock; |
| 2414 | } |
| 2415 | |
| 2416 | dout("%s req %p tid %llu map_dne_bound %u newest %llu\n", __func__, |
| 2417 | req, req->r_tid, req->r_map_dne_bound, greq->u.newest); |
| 2418 | if (!req->r_map_dne_bound) |
| 2419 | req->r_map_dne_bound = greq->u.newest; |
| 2420 | erase_request_mc(&osdc->map_checks, req); |
| 2421 | check_pool_dne(req); |
| 2422 | |
| 2423 | ceph_osdc_put_request(req); |
| 2424 | out_unlock: |
| 2425 | up_write(&osdc->lock); |
| 2426 | } |
| 2427 | |
| 2428 | static void send_map_check(struct ceph_osd_request *req) |
| 2429 | { |
| 2430 | struct ceph_osd_client *osdc = req->r_osdc; |
| 2431 | struct ceph_osd_request *lookup_req; |
| 2432 | int ret; |
| 2433 | |
| 2434 | verify_osdc_wrlocked(osdc); |
| 2435 | |
| 2436 | lookup_req = lookup_request_mc(&osdc->map_checks, req->r_tid); |
| 2437 | if (lookup_req) { |
| 2438 | WARN_ON(lookup_req != req); |
| 2439 | return; |
| 2440 | } |
| 2441 | |
| 2442 | ceph_osdc_get_request(req); |
| 2443 | insert_request_mc(&osdc->map_checks, req); |
| 2444 | ret = ceph_monc_get_version_async(&osdc->client->monc, "osdmap", |
| 2445 | map_check_cb, req->r_tid); |
| 2446 | WARN_ON(ret); |
| 2447 | } |
| 2448 | |
Ilya Dryomov | 0bbfdfe | 2014-01-31 19:33:39 +0200 | [diff] [blame] | 2449 | /* |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2450 | * lingering requests, watch/notify v2 infrastructure |
| 2451 | */ |
| 2452 | static void linger_release(struct kref *kref) |
| 2453 | { |
| 2454 | struct ceph_osd_linger_request *lreq = |
| 2455 | container_of(kref, struct ceph_osd_linger_request, kref); |
| 2456 | |
| 2457 | dout("%s lreq %p reg_req %p ping_req %p\n", __func__, lreq, |
| 2458 | lreq->reg_req, lreq->ping_req); |
| 2459 | WARN_ON(!RB_EMPTY_NODE(&lreq->node)); |
| 2460 | WARN_ON(!RB_EMPTY_NODE(&lreq->osdc_node)); |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2461 | WARN_ON(!RB_EMPTY_NODE(&lreq->mc_node)); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2462 | WARN_ON(!list_empty(&lreq->scan_item)); |
Ilya Dryomov | b07d3c4 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2463 | WARN_ON(!list_empty(&lreq->pending_lworks)); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2464 | WARN_ON(lreq->osd); |
| 2465 | |
| 2466 | if (lreq->reg_req) |
| 2467 | ceph_osdc_put_request(lreq->reg_req); |
| 2468 | if (lreq->ping_req) |
| 2469 | ceph_osdc_put_request(lreq->ping_req); |
| 2470 | target_destroy(&lreq->t); |
| 2471 | kfree(lreq); |
| 2472 | } |
| 2473 | |
| 2474 | static void linger_put(struct ceph_osd_linger_request *lreq) |
| 2475 | { |
| 2476 | if (lreq) |
| 2477 | kref_put(&lreq->kref, linger_release); |
| 2478 | } |
| 2479 | |
| 2480 | static struct ceph_osd_linger_request * |
| 2481 | linger_get(struct ceph_osd_linger_request *lreq) |
| 2482 | { |
| 2483 | kref_get(&lreq->kref); |
| 2484 | return lreq; |
| 2485 | } |
| 2486 | |
| 2487 | static struct ceph_osd_linger_request * |
| 2488 | linger_alloc(struct ceph_osd_client *osdc) |
| 2489 | { |
| 2490 | struct ceph_osd_linger_request *lreq; |
| 2491 | |
| 2492 | lreq = kzalloc(sizeof(*lreq), GFP_NOIO); |
| 2493 | if (!lreq) |
| 2494 | return NULL; |
| 2495 | |
| 2496 | kref_init(&lreq->kref); |
| 2497 | mutex_init(&lreq->lock); |
| 2498 | RB_CLEAR_NODE(&lreq->node); |
| 2499 | RB_CLEAR_NODE(&lreq->osdc_node); |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2500 | RB_CLEAR_NODE(&lreq->mc_node); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2501 | INIT_LIST_HEAD(&lreq->scan_item); |
Ilya Dryomov | b07d3c4 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2502 | INIT_LIST_HEAD(&lreq->pending_lworks); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2503 | init_completion(&lreq->reg_commit_wait); |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2504 | init_completion(&lreq->notify_finish_wait); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2505 | |
| 2506 | lreq->osdc = osdc; |
| 2507 | target_init(&lreq->t); |
| 2508 | |
| 2509 | dout("%s lreq %p\n", __func__, lreq); |
| 2510 | return lreq; |
| 2511 | } |
| 2512 | |
| 2513 | DEFINE_RB_INSDEL_FUNCS(linger, struct ceph_osd_linger_request, linger_id, node) |
| 2514 | DEFINE_RB_FUNCS(linger_osdc, struct ceph_osd_linger_request, linger_id, osdc_node) |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2515 | DEFINE_RB_FUNCS(linger_mc, struct ceph_osd_linger_request, linger_id, mc_node) |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2516 | |
| 2517 | /* |
| 2518 | * Create linger request <-> OSD session relation. |
| 2519 | * |
| 2520 | * @lreq has to be registered, @osd may be homeless. |
| 2521 | */ |
| 2522 | static void link_linger(struct ceph_osd *osd, |
| 2523 | struct ceph_osd_linger_request *lreq) |
| 2524 | { |
| 2525 | verify_osd_locked(osd); |
| 2526 | WARN_ON(!lreq->linger_id || lreq->osd); |
| 2527 | dout("%s osd %p osd%d lreq %p linger_id %llu\n", __func__, osd, |
| 2528 | osd->o_osd, lreq, lreq->linger_id); |
| 2529 | |
| 2530 | if (!osd_homeless(osd)) |
| 2531 | __remove_osd_from_lru(osd); |
| 2532 | else |
| 2533 | atomic_inc(&osd->o_osdc->num_homeless); |
| 2534 | |
| 2535 | get_osd(osd); |
| 2536 | insert_linger(&osd->o_linger_requests, lreq); |
| 2537 | lreq->osd = osd; |
| 2538 | } |
| 2539 | |
| 2540 | static void unlink_linger(struct ceph_osd *osd, |
| 2541 | struct ceph_osd_linger_request *lreq) |
| 2542 | { |
| 2543 | verify_osd_locked(osd); |
| 2544 | WARN_ON(lreq->osd != osd); |
| 2545 | dout("%s osd %p osd%d lreq %p linger_id %llu\n", __func__, osd, |
| 2546 | osd->o_osd, lreq, lreq->linger_id); |
| 2547 | |
| 2548 | lreq->osd = NULL; |
| 2549 | erase_linger(&osd->o_linger_requests, lreq); |
| 2550 | put_osd(osd); |
| 2551 | |
| 2552 | if (!osd_homeless(osd)) |
| 2553 | maybe_move_osd_to_lru(osd); |
| 2554 | else |
| 2555 | atomic_dec(&osd->o_osdc->num_homeless); |
| 2556 | } |
| 2557 | |
| 2558 | static bool __linger_registered(struct ceph_osd_linger_request *lreq) |
| 2559 | { |
| 2560 | verify_osdc_locked(lreq->osdc); |
| 2561 | |
| 2562 | return !RB_EMPTY_NODE(&lreq->osdc_node); |
| 2563 | } |
| 2564 | |
| 2565 | static bool linger_registered(struct ceph_osd_linger_request *lreq) |
| 2566 | { |
| 2567 | struct ceph_osd_client *osdc = lreq->osdc; |
| 2568 | bool registered; |
| 2569 | |
| 2570 | down_read(&osdc->lock); |
| 2571 | registered = __linger_registered(lreq); |
| 2572 | up_read(&osdc->lock); |
| 2573 | |
| 2574 | return registered; |
| 2575 | } |
| 2576 | |
| 2577 | static void linger_register(struct ceph_osd_linger_request *lreq) |
| 2578 | { |
| 2579 | struct ceph_osd_client *osdc = lreq->osdc; |
| 2580 | |
| 2581 | verify_osdc_wrlocked(osdc); |
| 2582 | WARN_ON(lreq->linger_id); |
| 2583 | |
| 2584 | linger_get(lreq); |
| 2585 | lreq->linger_id = ++osdc->last_linger_id; |
| 2586 | insert_linger_osdc(&osdc->linger_requests, lreq); |
| 2587 | } |
| 2588 | |
| 2589 | static void linger_unregister(struct ceph_osd_linger_request *lreq) |
| 2590 | { |
| 2591 | struct ceph_osd_client *osdc = lreq->osdc; |
| 2592 | |
| 2593 | verify_osdc_wrlocked(osdc); |
| 2594 | |
| 2595 | erase_linger_osdc(&osdc->linger_requests, lreq); |
| 2596 | linger_put(lreq); |
| 2597 | } |
| 2598 | |
| 2599 | static void cancel_linger_request(struct ceph_osd_request *req) |
| 2600 | { |
| 2601 | struct ceph_osd_linger_request *lreq = req->r_priv; |
| 2602 | |
| 2603 | WARN_ON(!req->r_linger); |
| 2604 | cancel_request(req); |
| 2605 | linger_put(lreq); |
| 2606 | } |
| 2607 | |
| 2608 | struct linger_work { |
| 2609 | struct work_struct work; |
| 2610 | struct ceph_osd_linger_request *lreq; |
Ilya Dryomov | b07d3c4 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2611 | struct list_head pending_item; |
| 2612 | unsigned long queued_stamp; |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2613 | |
| 2614 | union { |
| 2615 | struct { |
| 2616 | u64 notify_id; |
| 2617 | u64 notifier_id; |
| 2618 | void *payload; /* points into @msg front */ |
| 2619 | size_t payload_len; |
| 2620 | |
| 2621 | struct ceph_msg *msg; /* for ceph_msg_put() */ |
| 2622 | } notify; |
| 2623 | struct { |
| 2624 | int err; |
| 2625 | } error; |
| 2626 | }; |
| 2627 | }; |
| 2628 | |
| 2629 | static struct linger_work *lwork_alloc(struct ceph_osd_linger_request *lreq, |
| 2630 | work_func_t workfn) |
| 2631 | { |
| 2632 | struct linger_work *lwork; |
| 2633 | |
| 2634 | lwork = kzalloc(sizeof(*lwork), GFP_NOIO); |
| 2635 | if (!lwork) |
| 2636 | return NULL; |
| 2637 | |
| 2638 | INIT_WORK(&lwork->work, workfn); |
Ilya Dryomov | b07d3c4 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2639 | INIT_LIST_HEAD(&lwork->pending_item); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2640 | lwork->lreq = linger_get(lreq); |
| 2641 | |
| 2642 | return lwork; |
| 2643 | } |
| 2644 | |
| 2645 | static void lwork_free(struct linger_work *lwork) |
| 2646 | { |
| 2647 | struct ceph_osd_linger_request *lreq = lwork->lreq; |
| 2648 | |
Ilya Dryomov | b07d3c4 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2649 | mutex_lock(&lreq->lock); |
| 2650 | list_del(&lwork->pending_item); |
| 2651 | mutex_unlock(&lreq->lock); |
| 2652 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2653 | linger_put(lreq); |
| 2654 | kfree(lwork); |
| 2655 | } |
| 2656 | |
| 2657 | static void lwork_queue(struct linger_work *lwork) |
| 2658 | { |
| 2659 | struct ceph_osd_linger_request *lreq = lwork->lreq; |
| 2660 | struct ceph_osd_client *osdc = lreq->osdc; |
| 2661 | |
| 2662 | verify_lreq_locked(lreq); |
Ilya Dryomov | b07d3c4 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2663 | WARN_ON(!list_empty(&lwork->pending_item)); |
| 2664 | |
| 2665 | lwork->queued_stamp = jiffies; |
| 2666 | list_add_tail(&lwork->pending_item, &lreq->pending_lworks); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2667 | queue_work(osdc->notify_wq, &lwork->work); |
| 2668 | } |
| 2669 | |
| 2670 | static void do_watch_notify(struct work_struct *w) |
| 2671 | { |
| 2672 | struct linger_work *lwork = container_of(w, struct linger_work, work); |
| 2673 | struct ceph_osd_linger_request *lreq = lwork->lreq; |
| 2674 | |
| 2675 | if (!linger_registered(lreq)) { |
| 2676 | dout("%s lreq %p not registered\n", __func__, lreq); |
| 2677 | goto out; |
| 2678 | } |
| 2679 | |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2680 | WARN_ON(!lreq->is_watch); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2681 | dout("%s lreq %p notify_id %llu notifier_id %llu payload_len %zu\n", |
| 2682 | __func__, lreq, lwork->notify.notify_id, lwork->notify.notifier_id, |
| 2683 | lwork->notify.payload_len); |
| 2684 | lreq->wcb(lreq->data, lwork->notify.notify_id, lreq->linger_id, |
| 2685 | lwork->notify.notifier_id, lwork->notify.payload, |
| 2686 | lwork->notify.payload_len); |
| 2687 | |
| 2688 | out: |
| 2689 | ceph_msg_put(lwork->notify.msg); |
| 2690 | lwork_free(lwork); |
| 2691 | } |
| 2692 | |
| 2693 | static void do_watch_error(struct work_struct *w) |
| 2694 | { |
| 2695 | struct linger_work *lwork = container_of(w, struct linger_work, work); |
| 2696 | struct ceph_osd_linger_request *lreq = lwork->lreq; |
| 2697 | |
| 2698 | if (!linger_registered(lreq)) { |
| 2699 | dout("%s lreq %p not registered\n", __func__, lreq); |
| 2700 | goto out; |
| 2701 | } |
| 2702 | |
| 2703 | dout("%s lreq %p err %d\n", __func__, lreq, lwork->error.err); |
| 2704 | lreq->errcb(lreq->data, lreq->linger_id, lwork->error.err); |
| 2705 | |
| 2706 | out: |
| 2707 | lwork_free(lwork); |
| 2708 | } |
| 2709 | |
| 2710 | static void queue_watch_error(struct ceph_osd_linger_request *lreq) |
| 2711 | { |
| 2712 | struct linger_work *lwork; |
| 2713 | |
| 2714 | lwork = lwork_alloc(lreq, do_watch_error); |
| 2715 | if (!lwork) { |
| 2716 | pr_err("failed to allocate error-lwork\n"); |
| 2717 | return; |
| 2718 | } |
| 2719 | |
| 2720 | lwork->error.err = lreq->last_error; |
| 2721 | lwork_queue(lwork); |
| 2722 | } |
| 2723 | |
| 2724 | static void linger_reg_commit_complete(struct ceph_osd_linger_request *lreq, |
| 2725 | int result) |
| 2726 | { |
| 2727 | if (!completion_done(&lreq->reg_commit_wait)) { |
| 2728 | lreq->reg_commit_error = (result <= 0 ? result : 0); |
| 2729 | complete_all(&lreq->reg_commit_wait); |
| 2730 | } |
| 2731 | } |
| 2732 | |
| 2733 | static void linger_commit_cb(struct ceph_osd_request *req) |
| 2734 | { |
| 2735 | struct ceph_osd_linger_request *lreq = req->r_priv; |
| 2736 | |
| 2737 | mutex_lock(&lreq->lock); |
| 2738 | dout("%s lreq %p linger_id %llu result %d\n", __func__, lreq, |
| 2739 | lreq->linger_id, req->r_result); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2740 | linger_reg_commit_complete(lreq, req->r_result); |
| 2741 | lreq->committed = true; |
| 2742 | |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2743 | if (!lreq->is_watch) { |
| 2744 | struct ceph_osd_data *osd_data = |
| 2745 | osd_req_op_data(req, 0, notify, response_data); |
| 2746 | void *p = page_address(osd_data->pages[0]); |
| 2747 | |
| 2748 | WARN_ON(req->r_ops[0].op != CEPH_OSD_OP_NOTIFY || |
| 2749 | osd_data->type != CEPH_OSD_DATA_TYPE_PAGES); |
| 2750 | |
| 2751 | /* make note of the notify_id */ |
| 2752 | if (req->r_ops[0].outdata_len >= sizeof(u64)) { |
| 2753 | lreq->notify_id = ceph_decode_64(&p); |
| 2754 | dout("lreq %p notify_id %llu\n", lreq, |
| 2755 | lreq->notify_id); |
| 2756 | } else { |
| 2757 | dout("lreq %p no notify_id\n", lreq); |
| 2758 | } |
| 2759 | } |
| 2760 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2761 | mutex_unlock(&lreq->lock); |
| 2762 | linger_put(lreq); |
| 2763 | } |
| 2764 | |
| 2765 | static int normalize_watch_error(int err) |
| 2766 | { |
| 2767 | /* |
| 2768 | * Translate ENOENT -> ENOTCONN so that a delete->disconnection |
| 2769 | * notification and a failure to reconnect because we raced with |
| 2770 | * the delete appear the same to the user. |
| 2771 | */ |
| 2772 | if (err == -ENOENT) |
| 2773 | err = -ENOTCONN; |
| 2774 | |
| 2775 | return err; |
| 2776 | } |
| 2777 | |
| 2778 | static void linger_reconnect_cb(struct ceph_osd_request *req) |
| 2779 | { |
| 2780 | struct ceph_osd_linger_request *lreq = req->r_priv; |
| 2781 | |
| 2782 | mutex_lock(&lreq->lock); |
| 2783 | dout("%s lreq %p linger_id %llu result %d last_error %d\n", __func__, |
| 2784 | lreq, lreq->linger_id, req->r_result, lreq->last_error); |
| 2785 | if (req->r_result < 0) { |
| 2786 | if (!lreq->last_error) { |
| 2787 | lreq->last_error = normalize_watch_error(req->r_result); |
| 2788 | queue_watch_error(lreq); |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | mutex_unlock(&lreq->lock); |
| 2793 | linger_put(lreq); |
| 2794 | } |
| 2795 | |
| 2796 | static void send_linger(struct ceph_osd_linger_request *lreq) |
| 2797 | { |
| 2798 | struct ceph_osd_request *req = lreq->reg_req; |
| 2799 | struct ceph_osd_req_op *op = &req->r_ops[0]; |
| 2800 | |
| 2801 | verify_osdc_wrlocked(req->r_osdc); |
| 2802 | dout("%s lreq %p linger_id %llu\n", __func__, lreq, lreq->linger_id); |
| 2803 | |
| 2804 | if (req->r_osd) |
| 2805 | cancel_linger_request(req); |
| 2806 | |
| 2807 | request_reinit(req); |
| 2808 | ceph_oid_copy(&req->r_base_oid, &lreq->t.base_oid); |
| 2809 | ceph_oloc_copy(&req->r_base_oloc, &lreq->t.base_oloc); |
| 2810 | req->r_flags = lreq->t.flags; |
| 2811 | req->r_mtime = lreq->mtime; |
| 2812 | |
| 2813 | mutex_lock(&lreq->lock); |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2814 | if (lreq->is_watch && lreq->committed) { |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2815 | WARN_ON(op->op != CEPH_OSD_OP_WATCH || |
| 2816 | op->watch.cookie != lreq->linger_id); |
| 2817 | op->watch.op = CEPH_OSD_WATCH_OP_RECONNECT; |
| 2818 | op->watch.gen = ++lreq->register_gen; |
| 2819 | dout("lreq %p reconnect register_gen %u\n", lreq, |
| 2820 | op->watch.gen); |
| 2821 | req->r_callback = linger_reconnect_cb; |
| 2822 | } else { |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2823 | if (!lreq->is_watch) |
| 2824 | lreq->notify_id = 0; |
| 2825 | else |
| 2826 | WARN_ON(op->watch.op != CEPH_OSD_WATCH_OP_WATCH); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2827 | dout("lreq %p register\n", lreq); |
| 2828 | req->r_callback = linger_commit_cb; |
| 2829 | } |
| 2830 | mutex_unlock(&lreq->lock); |
| 2831 | |
| 2832 | req->r_priv = linger_get(lreq); |
| 2833 | req->r_linger = true; |
| 2834 | |
| 2835 | submit_request(req, true); |
| 2836 | } |
| 2837 | |
| 2838 | static void linger_ping_cb(struct ceph_osd_request *req) |
| 2839 | { |
| 2840 | struct ceph_osd_linger_request *lreq = req->r_priv; |
| 2841 | |
| 2842 | mutex_lock(&lreq->lock); |
| 2843 | dout("%s lreq %p linger_id %llu result %d ping_sent %lu last_error %d\n", |
| 2844 | __func__, lreq, lreq->linger_id, req->r_result, lreq->ping_sent, |
| 2845 | lreq->last_error); |
| 2846 | if (lreq->register_gen == req->r_ops[0].watch.gen) { |
Ilya Dryomov | b07d3c4 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2847 | if (!req->r_result) { |
| 2848 | lreq->watch_valid_thru = lreq->ping_sent; |
| 2849 | } else if (!lreq->last_error) { |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2850 | lreq->last_error = normalize_watch_error(req->r_result); |
| 2851 | queue_watch_error(lreq); |
| 2852 | } |
| 2853 | } else { |
| 2854 | dout("lreq %p register_gen %u ignoring old pong %u\n", lreq, |
| 2855 | lreq->register_gen, req->r_ops[0].watch.gen); |
| 2856 | } |
| 2857 | |
| 2858 | mutex_unlock(&lreq->lock); |
| 2859 | linger_put(lreq); |
| 2860 | } |
| 2861 | |
| 2862 | static void send_linger_ping(struct ceph_osd_linger_request *lreq) |
| 2863 | { |
| 2864 | struct ceph_osd_client *osdc = lreq->osdc; |
| 2865 | struct ceph_osd_request *req = lreq->ping_req; |
| 2866 | struct ceph_osd_req_op *op = &req->r_ops[0]; |
| 2867 | |
Ilya Dryomov | b7ec35b | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 2868 | if (ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSERD)) { |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2869 | dout("%s PAUSERD\n", __func__); |
| 2870 | return; |
| 2871 | } |
| 2872 | |
| 2873 | lreq->ping_sent = jiffies; |
| 2874 | dout("%s lreq %p linger_id %llu ping_sent %lu register_gen %u\n", |
| 2875 | __func__, lreq, lreq->linger_id, lreq->ping_sent, |
| 2876 | lreq->register_gen); |
| 2877 | |
| 2878 | if (req->r_osd) |
| 2879 | cancel_linger_request(req); |
| 2880 | |
| 2881 | request_reinit(req); |
| 2882 | target_copy(&req->r_t, &lreq->t); |
| 2883 | |
| 2884 | WARN_ON(op->op != CEPH_OSD_OP_WATCH || |
| 2885 | op->watch.cookie != lreq->linger_id || |
| 2886 | op->watch.op != CEPH_OSD_WATCH_OP_PING); |
| 2887 | op->watch.gen = lreq->register_gen; |
| 2888 | req->r_callback = linger_ping_cb; |
| 2889 | req->r_priv = linger_get(lreq); |
| 2890 | req->r_linger = true; |
| 2891 | |
| 2892 | ceph_osdc_get_request(req); |
| 2893 | account_request(req); |
| 2894 | req->r_tid = atomic64_inc_return(&osdc->last_tid); |
| 2895 | link_request(lreq->osd, req); |
| 2896 | send_request(req); |
| 2897 | } |
| 2898 | |
| 2899 | static void linger_submit(struct ceph_osd_linger_request *lreq) |
| 2900 | { |
| 2901 | struct ceph_osd_client *osdc = lreq->osdc; |
| 2902 | struct ceph_osd *osd; |
| 2903 | |
Ilya Dryomov | 7de030d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 2904 | calc_target(osdc, &lreq->t, NULL, false); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2905 | osd = lookup_create_osd(osdc, lreq->t.osd, true); |
| 2906 | link_linger(osd, lreq); |
| 2907 | |
| 2908 | send_linger(lreq); |
| 2909 | } |
| 2910 | |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2911 | static void cancel_linger_map_check(struct ceph_osd_linger_request *lreq) |
| 2912 | { |
| 2913 | struct ceph_osd_client *osdc = lreq->osdc; |
| 2914 | struct ceph_osd_linger_request *lookup_lreq; |
| 2915 | |
| 2916 | verify_osdc_wrlocked(osdc); |
| 2917 | |
| 2918 | lookup_lreq = lookup_linger_mc(&osdc->linger_map_checks, |
| 2919 | lreq->linger_id); |
| 2920 | if (!lookup_lreq) |
| 2921 | return; |
| 2922 | |
| 2923 | WARN_ON(lookup_lreq != lreq); |
| 2924 | erase_linger_mc(&osdc->linger_map_checks, lreq); |
| 2925 | linger_put(lreq); |
| 2926 | } |
| 2927 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2928 | /* |
| 2929 | * @lreq has to be both registered and linked. |
| 2930 | */ |
| 2931 | static void __linger_cancel(struct ceph_osd_linger_request *lreq) |
| 2932 | { |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2933 | if (lreq->is_watch && lreq->ping_req->r_osd) |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2934 | cancel_linger_request(lreq->ping_req); |
| 2935 | if (lreq->reg_req->r_osd) |
| 2936 | cancel_linger_request(lreq->reg_req); |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2937 | cancel_linger_map_check(lreq); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 2938 | unlink_linger(lreq->osd, lreq); |
| 2939 | linger_unregister(lreq); |
| 2940 | } |
| 2941 | |
| 2942 | static void linger_cancel(struct ceph_osd_linger_request *lreq) |
| 2943 | { |
| 2944 | struct ceph_osd_client *osdc = lreq->osdc; |
| 2945 | |
| 2946 | down_write(&osdc->lock); |
| 2947 | if (__linger_registered(lreq)) |
| 2948 | __linger_cancel(lreq); |
| 2949 | up_write(&osdc->lock); |
| 2950 | } |
| 2951 | |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 2952 | static void send_linger_map_check(struct ceph_osd_linger_request *lreq); |
| 2953 | |
| 2954 | static void check_linger_pool_dne(struct ceph_osd_linger_request *lreq) |
| 2955 | { |
| 2956 | struct ceph_osd_client *osdc = lreq->osdc; |
| 2957 | struct ceph_osdmap *map = osdc->osdmap; |
| 2958 | |
| 2959 | verify_osdc_wrlocked(osdc); |
| 2960 | WARN_ON(!map->epoch); |
| 2961 | |
| 2962 | if (lreq->register_gen) { |
| 2963 | lreq->map_dne_bound = map->epoch; |
| 2964 | dout("%s lreq %p linger_id %llu pool disappeared\n", __func__, |
| 2965 | lreq, lreq->linger_id); |
| 2966 | } else { |
| 2967 | dout("%s lreq %p linger_id %llu map_dne_bound %u have %u\n", |
| 2968 | __func__, lreq, lreq->linger_id, lreq->map_dne_bound, |
| 2969 | map->epoch); |
| 2970 | } |
| 2971 | |
| 2972 | if (lreq->map_dne_bound) { |
| 2973 | if (map->epoch >= lreq->map_dne_bound) { |
| 2974 | /* we had a new enough map */ |
| 2975 | pr_info("linger_id %llu pool does not exist\n", |
| 2976 | lreq->linger_id); |
| 2977 | linger_reg_commit_complete(lreq, -ENOENT); |
| 2978 | __linger_cancel(lreq); |
| 2979 | } |
| 2980 | } else { |
| 2981 | send_linger_map_check(lreq); |
| 2982 | } |
| 2983 | } |
| 2984 | |
| 2985 | static void linger_map_check_cb(struct ceph_mon_generic_request *greq) |
| 2986 | { |
| 2987 | struct ceph_osd_client *osdc = &greq->monc->client->osdc; |
| 2988 | struct ceph_osd_linger_request *lreq; |
| 2989 | u64 linger_id = greq->private_data; |
| 2990 | |
| 2991 | WARN_ON(greq->result || !greq->u.newest); |
| 2992 | |
| 2993 | down_write(&osdc->lock); |
| 2994 | lreq = lookup_linger_mc(&osdc->linger_map_checks, linger_id); |
| 2995 | if (!lreq) { |
| 2996 | dout("%s linger_id %llu dne\n", __func__, linger_id); |
| 2997 | goto out_unlock; |
| 2998 | } |
| 2999 | |
| 3000 | dout("%s lreq %p linger_id %llu map_dne_bound %u newest %llu\n", |
| 3001 | __func__, lreq, lreq->linger_id, lreq->map_dne_bound, |
| 3002 | greq->u.newest); |
| 3003 | if (!lreq->map_dne_bound) |
| 3004 | lreq->map_dne_bound = greq->u.newest; |
| 3005 | erase_linger_mc(&osdc->linger_map_checks, lreq); |
| 3006 | check_linger_pool_dne(lreq); |
| 3007 | |
| 3008 | linger_put(lreq); |
| 3009 | out_unlock: |
| 3010 | up_write(&osdc->lock); |
| 3011 | } |
| 3012 | |
| 3013 | static void send_linger_map_check(struct ceph_osd_linger_request *lreq) |
| 3014 | { |
| 3015 | struct ceph_osd_client *osdc = lreq->osdc; |
| 3016 | struct ceph_osd_linger_request *lookup_lreq; |
| 3017 | int ret; |
| 3018 | |
| 3019 | verify_osdc_wrlocked(osdc); |
| 3020 | |
| 3021 | lookup_lreq = lookup_linger_mc(&osdc->linger_map_checks, |
| 3022 | lreq->linger_id); |
| 3023 | if (lookup_lreq) { |
| 3024 | WARN_ON(lookup_lreq != lreq); |
| 3025 | return; |
| 3026 | } |
| 3027 | |
| 3028 | linger_get(lreq); |
| 3029 | insert_linger_mc(&osdc->linger_map_checks, lreq); |
| 3030 | ret = ceph_monc_get_version_async(&osdc->client->monc, "osdmap", |
| 3031 | linger_map_check_cb, lreq->linger_id); |
| 3032 | WARN_ON(ret); |
| 3033 | } |
| 3034 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3035 | static int linger_reg_commit_wait(struct ceph_osd_linger_request *lreq) |
| 3036 | { |
| 3037 | int ret; |
| 3038 | |
| 3039 | dout("%s lreq %p linger_id %llu\n", __func__, lreq, lreq->linger_id); |
| 3040 | ret = wait_for_completion_interruptible(&lreq->reg_commit_wait); |
| 3041 | return ret ?: lreq->reg_commit_error; |
| 3042 | } |
| 3043 | |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 3044 | static int linger_notify_finish_wait(struct ceph_osd_linger_request *lreq) |
| 3045 | { |
| 3046 | int ret; |
| 3047 | |
| 3048 | dout("%s lreq %p linger_id %llu\n", __func__, lreq, lreq->linger_id); |
| 3049 | ret = wait_for_completion_interruptible(&lreq->notify_finish_wait); |
| 3050 | return ret ?: lreq->notify_finish_error; |
| 3051 | } |
| 3052 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3053 | /* |
Ilya Dryomov | fbca963 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3054 | * Timeout callback, called every N seconds. When 1 or more OSD |
| 3055 | * requests has been active for more than N seconds, we send a keepalive |
| 3056 | * (tag + timestamp) to its OSD to ensure any communications channel |
| 3057 | * reset is detected. |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3058 | */ |
| 3059 | static void handle_timeout(struct work_struct *work) |
| 3060 | { |
| 3061 | struct ceph_osd_client *osdc = |
| 3062 | container_of(work, struct ceph_osd_client, timeout_work.work); |
Ilya Dryomov | a319bf5 | 2015-05-15 12:02:17 +0300 | [diff] [blame] | 3063 | struct ceph_options *opts = osdc->client->options; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3064 | unsigned long cutoff = jiffies - opts->osd_keepalive_timeout; |
Ilya Dryomov | 7cc5e38 | 2017-02-12 17:11:07 +0100 | [diff] [blame] | 3065 | unsigned long expiry_cutoff = jiffies - opts->osd_request_timeout; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3066 | LIST_HEAD(slow_osds); |
| 3067 | struct rb_node *n, *p; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3068 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3069 | dout("%s osdc %p\n", __func__, osdc); |
| 3070 | down_write(&osdc->lock); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3071 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3072 | /* |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3073 | * ping osds that are a bit slow. this ensures that if there |
| 3074 | * is a break in the TCP connection we will notice, and reopen |
| 3075 | * a connection with that osd (from the fault callback). |
| 3076 | */ |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3077 | for (n = rb_first(&osdc->osds); n; n = rb_next(n)) { |
| 3078 | struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node); |
| 3079 | bool found = false; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3080 | |
Ilya Dryomov | 7cc5e38 | 2017-02-12 17:11:07 +0100 | [diff] [blame] | 3081 | for (p = rb_first(&osd->o_requests); p; ) { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3082 | struct ceph_osd_request *req = |
| 3083 | rb_entry(p, struct ceph_osd_request, r_node); |
| 3084 | |
Ilya Dryomov | 7cc5e38 | 2017-02-12 17:11:07 +0100 | [diff] [blame] | 3085 | p = rb_next(p); /* abort_request() */ |
| 3086 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3087 | if (time_before(req->r_stamp, cutoff)) { |
| 3088 | dout(" req %p tid %llu on osd%d is laggy\n", |
| 3089 | req, req->r_tid, osd->o_osd); |
| 3090 | found = true; |
| 3091 | } |
Ilya Dryomov | 7cc5e38 | 2017-02-12 17:11:07 +0100 | [diff] [blame] | 3092 | if (opts->osd_request_timeout && |
| 3093 | time_before(req->r_start_stamp, expiry_cutoff)) { |
| 3094 | pr_err_ratelimited("tid %llu on osd%d timeout\n", |
| 3095 | req->r_tid, osd->o_osd); |
| 3096 | abort_request(req, -ETIMEDOUT); |
| 3097 | } |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3098 | } |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3099 | for (p = rb_first(&osd->o_linger_requests); p; p = rb_next(p)) { |
| 3100 | struct ceph_osd_linger_request *lreq = |
| 3101 | rb_entry(p, struct ceph_osd_linger_request, node); |
| 3102 | |
| 3103 | dout(" lreq %p linger_id %llu is served by osd%d\n", |
| 3104 | lreq, lreq->linger_id, osd->o_osd); |
| 3105 | found = true; |
| 3106 | |
| 3107 | mutex_lock(&lreq->lock); |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 3108 | if (lreq->is_watch && lreq->committed && !lreq->last_error) |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3109 | send_linger_ping(lreq); |
| 3110 | mutex_unlock(&lreq->lock); |
| 3111 | } |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3112 | |
| 3113 | if (found) |
| 3114 | list_move_tail(&osd->o_keepalive_item, &slow_osds); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3115 | } |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3116 | |
Ilya Dryomov | 7cc5e38 | 2017-02-12 17:11:07 +0100 | [diff] [blame] | 3117 | if (opts->osd_request_timeout) { |
| 3118 | for (p = rb_first(&osdc->homeless_osd.o_requests); p; ) { |
| 3119 | struct ceph_osd_request *req = |
| 3120 | rb_entry(p, struct ceph_osd_request, r_node); |
| 3121 | |
| 3122 | p = rb_next(p); /* abort_request() */ |
| 3123 | |
| 3124 | if (time_before(req->r_start_stamp, expiry_cutoff)) { |
| 3125 | pr_err_ratelimited("tid %llu on osd%d timeout\n", |
| 3126 | req->r_tid, osdc->homeless_osd.o_osd); |
| 3127 | abort_request(req, -ETIMEDOUT); |
| 3128 | } |
| 3129 | } |
| 3130 | } |
| 3131 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3132 | if (atomic_read(&osdc->num_homeless) || !list_empty(&slow_osds)) |
| 3133 | maybe_request_map(osdc); |
| 3134 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3135 | while (!list_empty(&slow_osds)) { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3136 | struct ceph_osd *osd = list_first_entry(&slow_osds, |
| 3137 | struct ceph_osd, |
| 3138 | o_keepalive_item); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3139 | list_del_init(&osd->o_keepalive_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3140 | ceph_con_keepalive(&osd->o_con); |
| 3141 | } |
| 3142 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3143 | up_write(&osdc->lock); |
Ilya Dryomov | fbca963 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3144 | schedule_delayed_work(&osdc->timeout_work, |
| 3145 | osdc->client->options->osd_keepalive_timeout); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3146 | } |
| 3147 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 3148 | static void handle_osds_timeout(struct work_struct *work) |
| 3149 | { |
| 3150 | struct ceph_osd_client *osdc = |
| 3151 | container_of(work, struct ceph_osd_client, |
| 3152 | osds_timeout_work.work); |
Ilya Dryomov | a319bf5 | 2015-05-15 12:02:17 +0300 | [diff] [blame] | 3153 | unsigned long delay = osdc->client->options->osd_idle_ttl / 4; |
Ilya Dryomov | 42a2c09 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 3154 | struct ceph_osd *osd, *nosd; |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 3155 | |
Ilya Dryomov | 42a2c09 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 3156 | dout("%s osdc %p\n", __func__, osdc); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3157 | down_write(&osdc->lock); |
Ilya Dryomov | 42a2c09 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 3158 | list_for_each_entry_safe(osd, nosd, &osdc->osd_lru, o_osd_lru) { |
| 3159 | if (time_before(jiffies, osd->lru_ttl)) |
| 3160 | break; |
| 3161 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3162 | WARN_ON(!RB_EMPTY_ROOT(&osd->o_requests)); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3163 | WARN_ON(!RB_EMPTY_ROOT(&osd->o_linger_requests)); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3164 | close_osd(osd); |
Ilya Dryomov | 42a2c09 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 3165 | } |
| 3166 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3167 | up_write(&osdc->lock); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 3168 | schedule_delayed_work(&osdc->osds_timeout_work, |
| 3169 | round_jiffies_relative(delay)); |
| 3170 | } |
| 3171 | |
Ilya Dryomov | 205ee118 | 2014-01-27 17:40:20 +0200 | [diff] [blame] | 3172 | static int ceph_oloc_decode(void **p, void *end, |
| 3173 | struct ceph_object_locator *oloc) |
| 3174 | { |
| 3175 | u8 struct_v, struct_cv; |
| 3176 | u32 len; |
| 3177 | void *struct_end; |
| 3178 | int ret = 0; |
| 3179 | |
| 3180 | ceph_decode_need(p, end, 1 + 1 + 4, e_inval); |
| 3181 | struct_v = ceph_decode_8(p); |
| 3182 | struct_cv = ceph_decode_8(p); |
| 3183 | if (struct_v < 3) { |
| 3184 | pr_warn("got v %d < 3 cv %d of ceph_object_locator\n", |
| 3185 | struct_v, struct_cv); |
| 3186 | goto e_inval; |
| 3187 | } |
| 3188 | if (struct_cv > 6) { |
| 3189 | pr_warn("got v %d cv %d > 6 of ceph_object_locator\n", |
| 3190 | struct_v, struct_cv); |
| 3191 | goto e_inval; |
| 3192 | } |
| 3193 | len = ceph_decode_32(p); |
| 3194 | ceph_decode_need(p, end, len, e_inval); |
| 3195 | struct_end = *p + len; |
| 3196 | |
| 3197 | oloc->pool = ceph_decode_64(p); |
| 3198 | *p += 4; /* skip preferred */ |
| 3199 | |
| 3200 | len = ceph_decode_32(p); |
| 3201 | if (len > 0) { |
| 3202 | pr_warn("ceph_object_locator::key is set\n"); |
| 3203 | goto e_inval; |
| 3204 | } |
| 3205 | |
| 3206 | if (struct_v >= 5) { |
Yan, Zheng | cd08e0a | 2016-06-13 19:05:13 +0800 | [diff] [blame] | 3207 | bool changed = false; |
| 3208 | |
Ilya Dryomov | 205ee118 | 2014-01-27 17:40:20 +0200 | [diff] [blame] | 3209 | len = ceph_decode_32(p); |
| 3210 | if (len > 0) { |
Yan, Zheng | 30c156d | 2016-02-14 11:24:31 +0800 | [diff] [blame] | 3211 | ceph_decode_need(p, end, len, e_inval); |
Yan, Zheng | cd08e0a | 2016-06-13 19:05:13 +0800 | [diff] [blame] | 3212 | if (!oloc->pool_ns || |
| 3213 | ceph_compare_string(oloc->pool_ns, *p, len)) |
| 3214 | changed = true; |
Yan, Zheng | 30c156d | 2016-02-14 11:24:31 +0800 | [diff] [blame] | 3215 | *p += len; |
Yan, Zheng | cd08e0a | 2016-06-13 19:05:13 +0800 | [diff] [blame] | 3216 | } else { |
| 3217 | if (oloc->pool_ns) |
| 3218 | changed = true; |
| 3219 | } |
| 3220 | if (changed) { |
| 3221 | /* redirect changes namespace */ |
| 3222 | pr_warn("ceph_object_locator::nspace is changed\n"); |
| 3223 | goto e_inval; |
Ilya Dryomov | 205ee118 | 2014-01-27 17:40:20 +0200 | [diff] [blame] | 3224 | } |
| 3225 | } |
| 3226 | |
| 3227 | if (struct_v >= 6) { |
| 3228 | s64 hash = ceph_decode_64(p); |
| 3229 | if (hash != -1) { |
| 3230 | pr_warn("ceph_object_locator::hash is set\n"); |
| 3231 | goto e_inval; |
| 3232 | } |
| 3233 | } |
| 3234 | |
| 3235 | /* skip the rest */ |
| 3236 | *p = struct_end; |
| 3237 | out: |
| 3238 | return ret; |
| 3239 | |
| 3240 | e_inval: |
| 3241 | ret = -EINVAL; |
| 3242 | goto out; |
| 3243 | } |
| 3244 | |
| 3245 | static int ceph_redirect_decode(void **p, void *end, |
| 3246 | struct ceph_request_redirect *redir) |
| 3247 | { |
| 3248 | u8 struct_v, struct_cv; |
| 3249 | u32 len; |
| 3250 | void *struct_end; |
| 3251 | int ret; |
| 3252 | |
| 3253 | ceph_decode_need(p, end, 1 + 1 + 4, e_inval); |
| 3254 | struct_v = ceph_decode_8(p); |
| 3255 | struct_cv = ceph_decode_8(p); |
| 3256 | if (struct_cv > 1) { |
| 3257 | pr_warn("got v %d cv %d > 1 of ceph_request_redirect\n", |
| 3258 | struct_v, struct_cv); |
| 3259 | goto e_inval; |
| 3260 | } |
| 3261 | len = ceph_decode_32(p); |
| 3262 | ceph_decode_need(p, end, len, e_inval); |
| 3263 | struct_end = *p + len; |
| 3264 | |
| 3265 | ret = ceph_oloc_decode(p, end, &redir->oloc); |
| 3266 | if (ret) |
| 3267 | goto out; |
| 3268 | |
| 3269 | len = ceph_decode_32(p); |
| 3270 | if (len > 0) { |
| 3271 | pr_warn("ceph_request_redirect::object_name is set\n"); |
| 3272 | goto e_inval; |
| 3273 | } |
| 3274 | |
| 3275 | len = ceph_decode_32(p); |
| 3276 | *p += len; /* skip osd_instructions */ |
| 3277 | |
| 3278 | /* skip the rest */ |
| 3279 | *p = struct_end; |
| 3280 | out: |
| 3281 | return ret; |
| 3282 | |
| 3283 | e_inval: |
| 3284 | ret = -EINVAL; |
| 3285 | goto out; |
| 3286 | } |
| 3287 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3288 | struct MOSDOpReply { |
| 3289 | struct ceph_pg pgid; |
| 3290 | u64 flags; |
| 3291 | int result; |
| 3292 | u32 epoch; |
| 3293 | int num_ops; |
| 3294 | u32 outdata_len[CEPH_OSD_MAX_OPS]; |
| 3295 | s32 rval[CEPH_OSD_MAX_OPS]; |
| 3296 | int retry_attempt; |
| 3297 | struct ceph_eversion replay_version; |
| 3298 | u64 user_version; |
| 3299 | struct ceph_request_redirect redirect; |
| 3300 | }; |
Sage Weil | 2584547 | 2011-06-03 09:37:09 -0700 | [diff] [blame] | 3301 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3302 | static int decode_MOSDOpReply(const struct ceph_msg *msg, struct MOSDOpReply *m) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3303 | { |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3304 | void *p = msg->front.iov_base; |
| 3305 | void *const end = p + msg->front.iov_len; |
| 3306 | u16 version = le16_to_cpu(msg->hdr.version); |
| 3307 | struct ceph_eversion bad_replay_version; |
Ilya Dryomov | b0b31a8 | 2016-02-03 15:25:48 +0100 | [diff] [blame] | 3308 | u8 decode_redir; |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3309 | u32 len; |
| 3310 | int ret; |
| 3311 | int i; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3312 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3313 | ceph_decode_32_safe(&p, end, len, e_inval); |
| 3314 | ceph_decode_need(&p, end, len, e_inval); |
| 3315 | p += len; /* skip oid */ |
Sage Weil | 1b83bef | 2013-02-25 16:11:12 -0800 | [diff] [blame] | 3316 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3317 | ret = ceph_decode_pgid(&p, end, &m->pgid); |
| 3318 | if (ret) |
| 3319 | return ret; |
Sage Weil | 1b83bef | 2013-02-25 16:11:12 -0800 | [diff] [blame] | 3320 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3321 | ceph_decode_64_safe(&p, end, m->flags, e_inval); |
| 3322 | ceph_decode_32_safe(&p, end, m->result, e_inval); |
| 3323 | ceph_decode_need(&p, end, sizeof(bad_replay_version), e_inval); |
| 3324 | memcpy(&bad_replay_version, p, sizeof(bad_replay_version)); |
| 3325 | p += sizeof(bad_replay_version); |
| 3326 | ceph_decode_32_safe(&p, end, m->epoch, e_inval); |
Sage Weil | 1b83bef | 2013-02-25 16:11:12 -0800 | [diff] [blame] | 3327 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3328 | ceph_decode_32_safe(&p, end, m->num_ops, e_inval); |
| 3329 | if (m->num_ops > ARRAY_SIZE(m->outdata_len)) |
| 3330 | goto e_inval; |
Sage Weil | 1b83bef | 2013-02-25 16:11:12 -0800 | [diff] [blame] | 3331 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3332 | ceph_decode_need(&p, end, m->num_ops * sizeof(struct ceph_osd_op), |
| 3333 | e_inval); |
| 3334 | for (i = 0; i < m->num_ops; i++) { |
Sage Weil | 1b83bef | 2013-02-25 16:11:12 -0800 | [diff] [blame] | 3335 | struct ceph_osd_op *op = p; |
Sage Weil | 1b83bef | 2013-02-25 16:11:12 -0800 | [diff] [blame] | 3336 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3337 | m->outdata_len[i] = le32_to_cpu(op->payload_len); |
Sage Weil | 1b83bef | 2013-02-25 16:11:12 -0800 | [diff] [blame] | 3338 | p += sizeof(*op); |
| 3339 | } |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3340 | |
| 3341 | ceph_decode_32_safe(&p, end, m->retry_attempt, e_inval); |
| 3342 | for (i = 0; i < m->num_ops; i++) |
| 3343 | ceph_decode_32_safe(&p, end, m->rval[i], e_inval); |
| 3344 | |
| 3345 | if (version >= 5) { |
| 3346 | ceph_decode_need(&p, end, sizeof(m->replay_version), e_inval); |
| 3347 | memcpy(&m->replay_version, p, sizeof(m->replay_version)); |
| 3348 | p += sizeof(m->replay_version); |
| 3349 | ceph_decode_64_safe(&p, end, m->user_version, e_inval); |
| 3350 | } else { |
| 3351 | m->replay_version = bad_replay_version; /* struct */ |
| 3352 | m->user_version = le64_to_cpu(m->replay_version.version); |
Sage Weil | 1b83bef | 2013-02-25 16:11:12 -0800 | [diff] [blame] | 3353 | } |
| 3354 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3355 | if (version >= 6) { |
| 3356 | if (version >= 7) |
| 3357 | ceph_decode_8_safe(&p, end, decode_redir, e_inval); |
Ilya Dryomov | b0b31a8 | 2016-02-03 15:25:48 +0100 | [diff] [blame] | 3358 | else |
| 3359 | decode_redir = 1; |
| 3360 | } else { |
| 3361 | decode_redir = 0; |
| 3362 | } |
| 3363 | |
| 3364 | if (decode_redir) { |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3365 | ret = ceph_redirect_decode(&p, end, &m->redirect); |
| 3366 | if (ret) |
| 3367 | return ret; |
Ilya Dryomov | 205ee118 | 2014-01-27 17:40:20 +0200 | [diff] [blame] | 3368 | } else { |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3369 | ceph_oloc_init(&m->redirect.oloc); |
Ilya Dryomov | 205ee118 | 2014-01-27 17:40:20 +0200 | [diff] [blame] | 3370 | } |
| 3371 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3372 | return 0; |
Ilya Dryomov | 205ee118 | 2014-01-27 17:40:20 +0200 | [diff] [blame] | 3373 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3374 | e_inval: |
| 3375 | return -EINVAL; |
| 3376 | } |
| 3377 | |
| 3378 | /* |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 3379 | * Handle MOSDOpReply. Set ->r_result and call the callback if it is |
| 3380 | * specified. |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3381 | */ |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3382 | static void handle_reply(struct ceph_osd *osd, struct ceph_msg *msg) |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3383 | { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3384 | struct ceph_osd_client *osdc = osd->o_osdc; |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3385 | struct ceph_osd_request *req; |
| 3386 | struct MOSDOpReply m; |
| 3387 | u64 tid = le64_to_cpu(msg->hdr.tid); |
| 3388 | u32 data_len = 0; |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3389 | int ret; |
| 3390 | int i; |
| 3391 | |
| 3392 | dout("%s msg %p tid %llu\n", __func__, msg, tid); |
| 3393 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3394 | down_read(&osdc->lock); |
| 3395 | if (!osd_registered(osd)) { |
| 3396 | dout("%s osd%d unknown\n", __func__, osd->o_osd); |
| 3397 | goto out_unlock_osdc; |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3398 | } |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3399 | WARN_ON(osd->o_osd != le64_to_cpu(msg->hdr.src.num)); |
| 3400 | |
| 3401 | mutex_lock(&osd->lock); |
| 3402 | req = lookup_request(&osd->o_requests, tid); |
| 3403 | if (!req) { |
| 3404 | dout("%s osd%d tid %llu unknown\n", __func__, osd->o_osd, tid); |
| 3405 | goto out_unlock_session; |
| 3406 | } |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3407 | |
Yan, Zheng | cd08e0a | 2016-06-13 19:05:13 +0800 | [diff] [blame] | 3408 | m.redirect.oloc.pool_ns = req->r_t.target_oloc.pool_ns; |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3409 | ret = decode_MOSDOpReply(msg, &m); |
Yan, Zheng | cd08e0a | 2016-06-13 19:05:13 +0800 | [diff] [blame] | 3410 | m.redirect.oloc.pool_ns = NULL; |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3411 | if (ret) { |
| 3412 | pr_err("failed to decode MOSDOpReply for tid %llu: %d\n", |
| 3413 | req->r_tid, ret); |
| 3414 | ceph_msg_dump(msg); |
| 3415 | goto fail_request; |
| 3416 | } |
| 3417 | dout("%s req %p tid %llu flags 0x%llx pgid %llu.%x epoch %u attempt %d v %u'%llu uv %llu\n", |
| 3418 | __func__, req, req->r_tid, m.flags, m.pgid.pool, m.pgid.seed, |
| 3419 | m.epoch, m.retry_attempt, le32_to_cpu(m.replay_version.epoch), |
| 3420 | le64_to_cpu(m.replay_version.version), m.user_version); |
| 3421 | |
| 3422 | if (m.retry_attempt >= 0) { |
| 3423 | if (m.retry_attempt != req->r_attempts - 1) { |
| 3424 | dout("req %p tid %llu retry_attempt %d != %d, ignoring\n", |
| 3425 | req, req->r_tid, m.retry_attempt, |
| 3426 | req->r_attempts - 1); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3427 | goto out_unlock_session; |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3428 | } |
| 3429 | } else { |
| 3430 | WARN_ON(1); /* MOSDOpReply v4 is assumed */ |
| 3431 | } |
| 3432 | |
| 3433 | if (!ceph_oloc_empty(&m.redirect.oloc)) { |
| 3434 | dout("req %p tid %llu redirect pool %lld\n", req, req->r_tid, |
| 3435 | m.redirect.oloc.pool); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3436 | unlink_request(osd, req); |
| 3437 | mutex_unlock(&osd->lock); |
Ilya Dryomov | 205ee118 | 2014-01-27 17:40:20 +0200 | [diff] [blame] | 3438 | |
Yan, Zheng | 30c156d | 2016-02-14 11:24:31 +0800 | [diff] [blame] | 3439 | /* |
| 3440 | * Not ceph_oloc_copy() - changing pool_ns is not |
| 3441 | * supported. |
| 3442 | */ |
| 3443 | req->r_t.target_oloc.pool = m.redirect.oloc.pool; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3444 | req->r_flags |= CEPH_OSD_FLAG_REDIRECTED; |
| 3445 | req->r_tid = 0; |
| 3446 | __submit_request(req, false); |
| 3447 | goto out_unlock_osdc; |
Ilya Dryomov | 205ee118 | 2014-01-27 17:40:20 +0200 | [diff] [blame] | 3448 | } |
| 3449 | |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3450 | if (m.num_ops != req->r_num_ops) { |
| 3451 | pr_err("num_ops %d != %d for tid %llu\n", m.num_ops, |
| 3452 | req->r_num_ops, req->r_tid); |
| 3453 | goto fail_request; |
| 3454 | } |
| 3455 | for (i = 0; i < req->r_num_ops; i++) { |
| 3456 | dout(" req %p tid %llu op %d rval %d len %u\n", req, |
| 3457 | req->r_tid, i, m.rval[i], m.outdata_len[i]); |
| 3458 | req->r_ops[i].rval = m.rval[i]; |
| 3459 | req->r_ops[i].outdata_len = m.outdata_len[i]; |
| 3460 | data_len += m.outdata_len[i]; |
| 3461 | } |
| 3462 | if (data_len != le32_to_cpu(msg->hdr.data_len)) { |
| 3463 | pr_err("sum of lens %u != %u for tid %llu\n", data_len, |
| 3464 | le32_to_cpu(msg->hdr.data_len), req->r_tid); |
| 3465 | goto fail_request; |
| 3466 | } |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 3467 | dout("%s req %p tid %llu result %d data_len %u\n", __func__, |
| 3468 | req, req->r_tid, m.result, data_len); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3469 | |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 3470 | /* |
| 3471 | * Since we only ever request ONDISK, we should only ever get |
| 3472 | * one (type of) reply back. |
| 3473 | */ |
| 3474 | WARN_ON(!(m.flags & CEPH_OSD_FLAG_ONDISK)); |
| 3475 | req->r_result = m.result ?: data_len; |
| 3476 | finish_request(req); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3477 | mutex_unlock(&osd->lock); |
| 3478 | up_read(&osdc->lock); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3479 | |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 3480 | __complete_request(req); |
| 3481 | complete_all(&req->r_completion); |
| 3482 | ceph_osdc_put_request(req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3483 | return; |
Ilya Dryomov | fe5da05 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 3484 | |
| 3485 | fail_request: |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 3486 | complete_request(req, -EIO); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3487 | out_unlock_session: |
| 3488 | mutex_unlock(&osd->lock); |
| 3489 | out_unlock_osdc: |
| 3490 | up_read(&osdc->lock); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3493 | static void set_pool_was_full(struct ceph_osd_client *osdc) |
| 3494 | { |
| 3495 | struct rb_node *n; |
| 3496 | |
| 3497 | for (n = rb_first(&osdc->osdmap->pg_pools); n; n = rb_next(n)) { |
| 3498 | struct ceph_pg_pool_info *pi = |
| 3499 | rb_entry(n, struct ceph_pg_pool_info, node); |
| 3500 | |
| 3501 | pi->was_full = __pool_full(pi); |
| 3502 | } |
| 3503 | } |
| 3504 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3505 | static bool pool_cleared_full(struct ceph_osd_client *osdc, s64 pool_id) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3506 | { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3507 | struct ceph_pg_pool_info *pi; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3508 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3509 | pi = ceph_pg_pool_by_id(osdc->osdmap, pool_id); |
| 3510 | if (!pi) |
| 3511 | return false; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3512 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3513 | return pi->was_full && !__pool_full(pi); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3514 | } |
| 3515 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3516 | static enum calc_target_result |
| 3517 | recalc_linger_target(struct ceph_osd_linger_request *lreq) |
| 3518 | { |
| 3519 | struct ceph_osd_client *osdc = lreq->osdc; |
| 3520 | enum calc_target_result ct_res; |
| 3521 | |
Ilya Dryomov | 7de030d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 3522 | ct_res = calc_target(osdc, &lreq->t, NULL, true); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3523 | if (ct_res == CALC_TARGET_NEED_RESEND) { |
| 3524 | struct ceph_osd *osd; |
| 3525 | |
| 3526 | osd = lookup_create_osd(osdc, lreq->t.osd, true); |
| 3527 | if (osd != lreq->osd) { |
| 3528 | unlink_linger(lreq->osd, lreq); |
| 3529 | link_linger(osd, lreq); |
| 3530 | } |
| 3531 | } |
| 3532 | |
| 3533 | return ct_res; |
| 3534 | } |
| 3535 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3536 | /* |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3537 | * Requeue requests whose mapping to an OSD has changed. |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3538 | */ |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3539 | static void scan_requests(struct ceph_osd *osd, |
| 3540 | bool force_resend, |
| 3541 | bool cleared_full, |
| 3542 | bool check_pool_cleared_full, |
| 3543 | struct rb_root *need_resend, |
| 3544 | struct list_head *need_resend_linger) |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3545 | { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3546 | struct ceph_osd_client *osdc = osd->o_osdc; |
| 3547 | struct rb_node *n; |
| 3548 | bool force_resend_writes; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3549 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3550 | for (n = rb_first(&osd->o_linger_requests); n; ) { |
| 3551 | struct ceph_osd_linger_request *lreq = |
| 3552 | rb_entry(n, struct ceph_osd_linger_request, node); |
| 3553 | enum calc_target_result ct_res; |
| 3554 | |
| 3555 | n = rb_next(n); /* recalc_linger_target() */ |
| 3556 | |
| 3557 | dout("%s lreq %p linger_id %llu\n", __func__, lreq, |
| 3558 | lreq->linger_id); |
| 3559 | ct_res = recalc_linger_target(lreq); |
| 3560 | switch (ct_res) { |
| 3561 | case CALC_TARGET_NO_ACTION: |
| 3562 | force_resend_writes = cleared_full || |
| 3563 | (check_pool_cleared_full && |
| 3564 | pool_cleared_full(osdc, lreq->t.base_oloc.pool)); |
| 3565 | if (!force_resend && !force_resend_writes) |
| 3566 | break; |
| 3567 | |
| 3568 | /* fall through */ |
| 3569 | case CALC_TARGET_NEED_RESEND: |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 3570 | cancel_linger_map_check(lreq); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3571 | /* |
| 3572 | * scan_requests() for the previous epoch(s) |
| 3573 | * may have already added it to the list, since |
| 3574 | * it's not unlinked here. |
| 3575 | */ |
| 3576 | if (list_empty(&lreq->scan_item)) |
| 3577 | list_add_tail(&lreq->scan_item, need_resend_linger); |
| 3578 | break; |
| 3579 | case CALC_TARGET_POOL_DNE: |
Ilya Dryomov | a10bcb1 | 2017-06-15 16:30:55 +0200 | [diff] [blame] | 3580 | list_del_init(&lreq->scan_item); |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 3581 | check_linger_pool_dne(lreq); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3582 | break; |
| 3583 | } |
| 3584 | } |
| 3585 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3586 | for (n = rb_first(&osd->o_requests); n; ) { |
| 3587 | struct ceph_osd_request *req = |
| 3588 | rb_entry(n, struct ceph_osd_request, r_node); |
| 3589 | enum calc_target_result ct_res; |
Alex Elder | ab60b16 | 2012-12-19 15:52:36 -0600 | [diff] [blame] | 3590 | |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 3591 | n = rb_next(n); /* unlink_request(), check_pool_dne() */ |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3592 | |
| 3593 | dout("%s req %p tid %llu\n", __func__, req, req->r_tid); |
Ilya Dryomov | 7de030d | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 3594 | ct_res = calc_target(osdc, &req->r_t, &req->r_osd->o_con, |
| 3595 | false); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3596 | switch (ct_res) { |
| 3597 | case CALC_TARGET_NO_ACTION: |
| 3598 | force_resend_writes = cleared_full || |
| 3599 | (check_pool_cleared_full && |
| 3600 | pool_cleared_full(osdc, req->r_t.base_oloc.pool)); |
| 3601 | if (!force_resend && |
| 3602 | (!(req->r_flags & CEPH_OSD_FLAG_WRITE) || |
| 3603 | !force_resend_writes)) |
| 3604 | break; |
| 3605 | |
| 3606 | /* fall through */ |
| 3607 | case CALC_TARGET_NEED_RESEND: |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 3608 | cancel_map_check(req); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3609 | unlink_request(osd, req); |
| 3610 | insert_request(need_resend, req); |
| 3611 | break; |
| 3612 | case CALC_TARGET_POOL_DNE: |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 3613 | check_pool_dne(req); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3614 | break; |
Alex Elder | ab60b16 | 2012-12-19 15:52:36 -0600 | [diff] [blame] | 3615 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3616 | } |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 3617 | } |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 3618 | |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3619 | static int handle_one_map(struct ceph_osd_client *osdc, |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3620 | void *p, void *end, bool incremental, |
| 3621 | struct rb_root *need_resend, |
| 3622 | struct list_head *need_resend_linger) |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3623 | { |
| 3624 | struct ceph_osdmap *newmap; |
| 3625 | struct rb_node *n; |
| 3626 | bool skipped_map = false; |
| 3627 | bool was_full; |
| 3628 | |
Ilya Dryomov | b7ec35b | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3629 | was_full = ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL); |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3630 | set_pool_was_full(osdc); |
| 3631 | |
| 3632 | if (incremental) |
| 3633 | newmap = osdmap_apply_incremental(&p, end, osdc->osdmap); |
| 3634 | else |
| 3635 | newmap = ceph_osdmap_decode(&p, end); |
| 3636 | if (IS_ERR(newmap)) |
| 3637 | return PTR_ERR(newmap); |
| 3638 | |
| 3639 | if (newmap != osdc->osdmap) { |
| 3640 | /* |
| 3641 | * Preserve ->was_full before destroying the old map. |
| 3642 | * For pools that weren't in the old map, ->was_full |
| 3643 | * should be false. |
| 3644 | */ |
| 3645 | for (n = rb_first(&newmap->pg_pools); n; n = rb_next(n)) { |
| 3646 | struct ceph_pg_pool_info *pi = |
| 3647 | rb_entry(n, struct ceph_pg_pool_info, node); |
| 3648 | struct ceph_pg_pool_info *old_pi; |
| 3649 | |
| 3650 | old_pi = ceph_pg_pool_by_id(osdc->osdmap, pi->id); |
| 3651 | if (old_pi) |
| 3652 | pi->was_full = old_pi->was_full; |
| 3653 | else |
| 3654 | WARN_ON(pi->was_full); |
| 3655 | } |
| 3656 | |
| 3657 | if (osdc->osdmap->epoch && |
| 3658 | osdc->osdmap->epoch + 1 < newmap->epoch) { |
| 3659 | WARN_ON(incremental); |
| 3660 | skipped_map = true; |
| 3661 | } |
| 3662 | |
| 3663 | ceph_osdmap_destroy(osdc->osdmap); |
| 3664 | osdc->osdmap = newmap; |
| 3665 | } |
| 3666 | |
Ilya Dryomov | b7ec35b | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3667 | was_full &= !ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3668 | scan_requests(&osdc->homeless_osd, skipped_map, was_full, true, |
| 3669 | need_resend, need_resend_linger); |
| 3670 | |
| 3671 | for (n = rb_first(&osdc->osds); n; ) { |
| 3672 | struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node); |
| 3673 | |
| 3674 | n = rb_next(n); /* close_osd() */ |
| 3675 | |
| 3676 | scan_requests(osd, skipped_map, was_full, true, need_resend, |
| 3677 | need_resend_linger); |
| 3678 | if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) || |
| 3679 | memcmp(&osd->o_con.peer_addr, |
| 3680 | ceph_osd_addr(osdc->osdmap, osd->o_osd), |
| 3681 | sizeof(struct ceph_entity_addr))) |
| 3682 | close_osd(osd); |
| 3683 | } |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3684 | |
| 3685 | return 0; |
| 3686 | } |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 3687 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3688 | static void kick_requests(struct ceph_osd_client *osdc, |
| 3689 | struct rb_root *need_resend, |
| 3690 | struct list_head *need_resend_linger) |
| 3691 | { |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3692 | struct ceph_osd_linger_request *lreq, *nlreq; |
Ilya Dryomov | 04c7d78 | 2017-06-15 16:30:55 +0200 | [diff] [blame] | 3693 | enum calc_target_result ct_res; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3694 | struct rb_node *n; |
| 3695 | |
Ilya Dryomov | 04c7d78 | 2017-06-15 16:30:55 +0200 | [diff] [blame] | 3696 | /* make sure need_resend targets reflect latest map */ |
| 3697 | for (n = rb_first(need_resend); n; ) { |
| 3698 | struct ceph_osd_request *req = |
| 3699 | rb_entry(n, struct ceph_osd_request, r_node); |
| 3700 | |
| 3701 | n = rb_next(n); |
| 3702 | |
| 3703 | if (req->r_t.epoch < osdc->osdmap->epoch) { |
| 3704 | ct_res = calc_target(osdc, &req->r_t, NULL, false); |
| 3705 | if (ct_res == CALC_TARGET_POOL_DNE) { |
| 3706 | erase_request(need_resend, req); |
| 3707 | check_pool_dne(req); |
| 3708 | } |
| 3709 | } |
| 3710 | } |
| 3711 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3712 | for (n = rb_first(need_resend); n; ) { |
| 3713 | struct ceph_osd_request *req = |
| 3714 | rb_entry(n, struct ceph_osd_request, r_node); |
| 3715 | struct ceph_osd *osd; |
| 3716 | |
| 3717 | n = rb_next(n); |
| 3718 | erase_request(need_resend, req); /* before link_request() */ |
| 3719 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3720 | osd = lookup_create_osd(osdc, req->r_t.osd, true); |
| 3721 | link_request(osd, req); |
| 3722 | if (!req->r_linger) { |
| 3723 | if (!osd_homeless(osd) && !req->r_t.paused) |
| 3724 | send_request(req); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3725 | } else { |
| 3726 | cancel_linger_request(req); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3727 | } |
| 3728 | } |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3729 | |
| 3730 | list_for_each_entry_safe(lreq, nlreq, need_resend_linger, scan_item) { |
| 3731 | if (!osd_homeless(lreq->osd)) |
| 3732 | send_linger(lreq); |
| 3733 | |
| 3734 | list_del_init(&lreq->scan_item); |
| 3735 | } |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3736 | } |
| 3737 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3738 | /* |
| 3739 | * Process updated osd map. |
| 3740 | * |
| 3741 | * The message contains any number of incremental and full maps, normally |
| 3742 | * indicating some sort of topology change in the cluster. Kick requests |
| 3743 | * off to different OSDs as needed. |
| 3744 | */ |
| 3745 | void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg) |
| 3746 | { |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3747 | void *p = msg->front.iov_base; |
| 3748 | void *const end = p + msg->front.iov_len; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3749 | u32 nr_maps, maplen; |
| 3750 | u32 epoch; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3751 | struct ceph_fsid fsid; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3752 | struct rb_root need_resend = RB_ROOT; |
| 3753 | LIST_HEAD(need_resend_linger); |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3754 | bool handled_incremental = false; |
| 3755 | bool was_pauserd, was_pausewr; |
| 3756 | bool pauserd, pausewr; |
| 3757 | int err; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3758 | |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3759 | dout("%s have %u\n", __func__, osdc->osdmap->epoch); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3760 | down_write(&osdc->lock); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3761 | |
| 3762 | /* verify fsid */ |
| 3763 | ceph_decode_need(&p, end, sizeof(fsid), bad); |
| 3764 | ceph_decode_copy(&p, &fsid, sizeof(fsid)); |
Sage Weil | 0743304 | 2009-11-18 16:50:41 -0800 | [diff] [blame] | 3765 | if (ceph_check_fsid(osdc->client, &fsid) < 0) |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3766 | goto bad; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3767 | |
Ilya Dryomov | b7ec35b | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3768 | was_pauserd = ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSERD); |
| 3769 | was_pausewr = ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR) || |
| 3770 | ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) || |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3771 | have_pool_full(osdc); |
Josh Durgin | 9a1ea2d | 2013-12-10 09:35:13 -0800 | [diff] [blame] | 3772 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3773 | /* incremental maps */ |
| 3774 | ceph_decode_32_safe(&p, end, nr_maps, bad); |
| 3775 | dout(" %d inc maps\n", nr_maps); |
| 3776 | while (nr_maps > 0) { |
| 3777 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 3778 | epoch = ceph_decode_32(&p); |
| 3779 | maplen = ceph_decode_32(&p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3780 | ceph_decode_need(&p, end, maplen, bad); |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3781 | if (osdc->osdmap->epoch && |
| 3782 | osdc->osdmap->epoch + 1 == epoch) { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3783 | dout("applying incremental map %u len %d\n", |
| 3784 | epoch, maplen); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3785 | err = handle_one_map(osdc, p, p + maplen, true, |
| 3786 | &need_resend, &need_resend_linger); |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3787 | if (err) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3788 | goto bad; |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3789 | handled_incremental = true; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3790 | } else { |
| 3791 | dout("ignoring incremental map %u len %d\n", |
| 3792 | epoch, maplen); |
| 3793 | } |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3794 | p += maplen; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3795 | nr_maps--; |
| 3796 | } |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3797 | if (handled_incremental) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3798 | goto done; |
| 3799 | |
| 3800 | /* full maps */ |
| 3801 | ceph_decode_32_safe(&p, end, nr_maps, bad); |
| 3802 | dout(" %d full maps\n", nr_maps); |
| 3803 | while (nr_maps) { |
| 3804 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 3805 | epoch = ceph_decode_32(&p); |
| 3806 | maplen = ceph_decode_32(&p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3807 | ceph_decode_need(&p, end, maplen, bad); |
| 3808 | if (nr_maps > 1) { |
| 3809 | dout("skipping non-latest full map %u len %d\n", |
| 3810 | epoch, maplen); |
Ilya Dryomov | e5253a7 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3811 | } else if (osdc->osdmap->epoch >= epoch) { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3812 | dout("skipping full map %u len %d, " |
| 3813 | "older than our %u\n", epoch, maplen, |
| 3814 | osdc->osdmap->epoch); |
| 3815 | } else { |
| 3816 | dout("taking full map %u len %d\n", epoch, maplen); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3817 | err = handle_one_map(osdc, p, p + maplen, false, |
| 3818 | &need_resend, &need_resend_linger); |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3819 | if (err) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3820 | goto bad; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3821 | } |
| 3822 | p += maplen; |
| 3823 | nr_maps--; |
| 3824 | } |
| 3825 | |
| 3826 | done: |
Sage Weil | cd634fb | 2011-05-12 09:29:18 -0700 | [diff] [blame] | 3827 | /* |
| 3828 | * subscribe to subsequent osdmap updates if full to ensure |
| 3829 | * we find out when we are no longer full and stop returning |
| 3830 | * ENOSPC. |
| 3831 | */ |
Ilya Dryomov | b7ec35b | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3832 | pauserd = ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSERD); |
| 3833 | pausewr = ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR) || |
| 3834 | ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) || |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3835 | have_pool_full(osdc); |
Jeff Layton | 58eb793 | 2017-04-18 09:21:16 -0400 | [diff] [blame] | 3836 | if (was_pauserd || was_pausewr || pauserd || pausewr || |
| 3837 | osdc->osdmap->epoch < osdc->epoch_barrier) |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3838 | maybe_request_map(osdc); |
Sage Weil | cd634fb | 2011-05-12 09:29:18 -0700 | [diff] [blame] | 3839 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3840 | kick_requests(osdc, &need_resend, &need_resend_linger); |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3841 | |
Jeff Layton | fc36d0a | 2017-04-04 08:39:39 -0400 | [diff] [blame] | 3842 | ceph_osdc_abort_on_full(osdc); |
Ilya Dryomov | 42c1b12 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 3843 | ceph_monc_got_map(&osdc->client->monc, CEPH_SUB_OSDMAP, |
| 3844 | osdc->osdmap->epoch); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3845 | up_write(&osdc->lock); |
Yehuda Sadeh | 03066f2 | 2010-07-27 13:11:08 -0700 | [diff] [blame] | 3846 | wake_up_all(&osdc->client->auth_wq); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3847 | return; |
| 3848 | |
| 3849 | bad: |
| 3850 | pr_err("osdc handle_map corrupt msg\n"); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 3851 | ceph_msg_dump(msg); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3852 | up_write(&osdc->lock); |
| 3853 | } |
| 3854 | |
| 3855 | /* |
| 3856 | * Resubmit requests pending on the given osd. |
| 3857 | */ |
| 3858 | static void kick_osd_requests(struct ceph_osd *osd) |
| 3859 | { |
| 3860 | struct rb_node *n; |
| 3861 | |
Ilya Dryomov | a02a946 | 2017-06-19 12:18:05 +0200 | [diff] [blame] | 3862 | clear_backoffs(osd); |
| 3863 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3864 | for (n = rb_first(&osd->o_requests); n; ) { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3865 | struct ceph_osd_request *req = |
| 3866 | rb_entry(n, struct ceph_osd_request, r_node); |
| 3867 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3868 | n = rb_next(n); /* cancel_linger_request() */ |
| 3869 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3870 | if (!req->r_linger) { |
| 3871 | if (!req->r_t.paused) |
| 3872 | send_request(req); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3873 | } else { |
| 3874 | cancel_linger_request(req); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3875 | } |
| 3876 | } |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 3877 | for (n = rb_first(&osd->o_linger_requests); n; n = rb_next(n)) { |
| 3878 | struct ceph_osd_linger_request *lreq = |
| 3879 | rb_entry(n, struct ceph_osd_linger_request, node); |
| 3880 | |
| 3881 | send_linger(lreq); |
| 3882 | } |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | /* |
| 3886 | * If the osd connection drops, we need to resubmit all requests. |
| 3887 | */ |
| 3888 | static void osd_fault(struct ceph_connection *con) |
| 3889 | { |
| 3890 | struct ceph_osd *osd = con->private; |
| 3891 | struct ceph_osd_client *osdc = osd->o_osdc; |
| 3892 | |
| 3893 | dout("%s osd %p osd%d\n", __func__, osd, osd->o_osd); |
| 3894 | |
| 3895 | down_write(&osdc->lock); |
| 3896 | if (!osd_registered(osd)) { |
| 3897 | dout("%s osd%d unknown\n", __func__, osd->o_osd); |
| 3898 | goto out_unlock; |
| 3899 | } |
| 3900 | |
| 3901 | if (!reopen_osd(osd)) |
| 3902 | kick_osd_requests(osd); |
| 3903 | maybe_request_map(osdc); |
| 3904 | |
| 3905 | out_unlock: |
| 3906 | up_write(&osdc->lock); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Ilya Dryomov | a02a946 | 2017-06-19 12:18:05 +0200 | [diff] [blame] | 3909 | struct MOSDBackoff { |
| 3910 | struct ceph_spg spgid; |
| 3911 | u32 map_epoch; |
| 3912 | u8 op; |
| 3913 | u64 id; |
| 3914 | struct ceph_hobject_id *begin; |
| 3915 | struct ceph_hobject_id *end; |
| 3916 | }; |
| 3917 | |
| 3918 | static int decode_MOSDBackoff(const struct ceph_msg *msg, struct MOSDBackoff *m) |
| 3919 | { |
| 3920 | void *p = msg->front.iov_base; |
| 3921 | void *const end = p + msg->front.iov_len; |
| 3922 | u8 struct_v; |
| 3923 | u32 struct_len; |
| 3924 | int ret; |
| 3925 | |
| 3926 | ret = ceph_start_decoding(&p, end, 1, "spg_t", &struct_v, &struct_len); |
| 3927 | if (ret) |
| 3928 | return ret; |
| 3929 | |
| 3930 | ret = ceph_decode_pgid(&p, end, &m->spgid.pgid); |
| 3931 | if (ret) |
| 3932 | return ret; |
| 3933 | |
| 3934 | ceph_decode_8_safe(&p, end, m->spgid.shard, e_inval); |
| 3935 | ceph_decode_32_safe(&p, end, m->map_epoch, e_inval); |
| 3936 | ceph_decode_8_safe(&p, end, m->op, e_inval); |
| 3937 | ceph_decode_64_safe(&p, end, m->id, e_inval); |
| 3938 | |
| 3939 | m->begin = kzalloc(sizeof(*m->begin), GFP_NOIO); |
| 3940 | if (!m->begin) |
| 3941 | return -ENOMEM; |
| 3942 | |
| 3943 | ret = decode_hoid(&p, end, m->begin); |
| 3944 | if (ret) { |
| 3945 | free_hoid(m->begin); |
| 3946 | return ret; |
| 3947 | } |
| 3948 | |
| 3949 | m->end = kzalloc(sizeof(*m->end), GFP_NOIO); |
| 3950 | if (!m->end) { |
| 3951 | free_hoid(m->begin); |
| 3952 | return -ENOMEM; |
| 3953 | } |
| 3954 | |
| 3955 | ret = decode_hoid(&p, end, m->end); |
| 3956 | if (ret) { |
| 3957 | free_hoid(m->begin); |
| 3958 | free_hoid(m->end); |
| 3959 | return ret; |
| 3960 | } |
| 3961 | |
| 3962 | return 0; |
| 3963 | |
| 3964 | e_inval: |
| 3965 | return -EINVAL; |
| 3966 | } |
| 3967 | |
| 3968 | static struct ceph_msg *create_backoff_message( |
| 3969 | const struct ceph_osd_backoff *backoff, |
| 3970 | u32 map_epoch) |
| 3971 | { |
| 3972 | struct ceph_msg *msg; |
| 3973 | void *p, *end; |
| 3974 | int msg_size; |
| 3975 | |
| 3976 | msg_size = CEPH_ENCODING_START_BLK_LEN + |
| 3977 | CEPH_PGID_ENCODING_LEN + 1; /* spgid */ |
| 3978 | msg_size += 4 + 1 + 8; /* map_epoch, op, id */ |
| 3979 | msg_size += CEPH_ENCODING_START_BLK_LEN + |
| 3980 | hoid_encoding_size(backoff->begin); |
| 3981 | msg_size += CEPH_ENCODING_START_BLK_LEN + |
| 3982 | hoid_encoding_size(backoff->end); |
| 3983 | |
| 3984 | msg = ceph_msg_new(CEPH_MSG_OSD_BACKOFF, msg_size, GFP_NOIO, true); |
| 3985 | if (!msg) |
| 3986 | return NULL; |
| 3987 | |
| 3988 | p = msg->front.iov_base; |
| 3989 | end = p + msg->front_alloc_len; |
| 3990 | |
| 3991 | encode_spgid(&p, &backoff->spgid); |
| 3992 | ceph_encode_32(&p, map_epoch); |
| 3993 | ceph_encode_8(&p, CEPH_OSD_BACKOFF_OP_ACK_BLOCK); |
| 3994 | ceph_encode_64(&p, backoff->id); |
| 3995 | encode_hoid(&p, end, backoff->begin); |
| 3996 | encode_hoid(&p, end, backoff->end); |
| 3997 | BUG_ON(p != end); |
| 3998 | |
| 3999 | msg->front.iov_len = p - msg->front.iov_base; |
| 4000 | msg->hdr.version = cpu_to_le16(1); /* MOSDBackoff v1 */ |
| 4001 | msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); |
| 4002 | |
| 4003 | return msg; |
| 4004 | } |
| 4005 | |
| 4006 | static void handle_backoff_block(struct ceph_osd *osd, struct MOSDBackoff *m) |
| 4007 | { |
| 4008 | struct ceph_spg_mapping *spg; |
| 4009 | struct ceph_osd_backoff *backoff; |
| 4010 | struct ceph_msg *msg; |
| 4011 | |
| 4012 | dout("%s osd%d spgid %llu.%xs%d id %llu\n", __func__, osd->o_osd, |
| 4013 | m->spgid.pgid.pool, m->spgid.pgid.seed, m->spgid.shard, m->id); |
| 4014 | |
| 4015 | spg = lookup_spg_mapping(&osd->o_backoff_mappings, &m->spgid); |
| 4016 | if (!spg) { |
| 4017 | spg = alloc_spg_mapping(); |
| 4018 | if (!spg) { |
| 4019 | pr_err("%s failed to allocate spg\n", __func__); |
| 4020 | return; |
| 4021 | } |
| 4022 | spg->spgid = m->spgid; /* struct */ |
| 4023 | insert_spg_mapping(&osd->o_backoff_mappings, spg); |
| 4024 | } |
| 4025 | |
| 4026 | backoff = alloc_backoff(); |
| 4027 | if (!backoff) { |
| 4028 | pr_err("%s failed to allocate backoff\n", __func__); |
| 4029 | return; |
| 4030 | } |
| 4031 | backoff->spgid = m->spgid; /* struct */ |
| 4032 | backoff->id = m->id; |
| 4033 | backoff->begin = m->begin; |
| 4034 | m->begin = NULL; /* backoff now owns this */ |
| 4035 | backoff->end = m->end; |
| 4036 | m->end = NULL; /* ditto */ |
| 4037 | |
| 4038 | insert_backoff(&spg->backoffs, backoff); |
| 4039 | insert_backoff_by_id(&osd->o_backoffs_by_id, backoff); |
| 4040 | |
| 4041 | /* |
| 4042 | * Ack with original backoff's epoch so that the OSD can |
| 4043 | * discard this if there was a PG split. |
| 4044 | */ |
| 4045 | msg = create_backoff_message(backoff, m->map_epoch); |
| 4046 | if (!msg) { |
| 4047 | pr_err("%s failed to allocate msg\n", __func__); |
| 4048 | return; |
| 4049 | } |
| 4050 | ceph_con_send(&osd->o_con, msg); |
| 4051 | } |
| 4052 | |
| 4053 | static bool target_contained_by(const struct ceph_osd_request_target *t, |
| 4054 | const struct ceph_hobject_id *begin, |
| 4055 | const struct ceph_hobject_id *end) |
| 4056 | { |
| 4057 | struct ceph_hobject_id hoid; |
| 4058 | int cmp; |
| 4059 | |
| 4060 | hoid_fill_from_target(&hoid, t); |
| 4061 | cmp = hoid_compare(&hoid, begin); |
| 4062 | return !cmp || (cmp > 0 && hoid_compare(&hoid, end) < 0); |
| 4063 | } |
| 4064 | |
| 4065 | static void handle_backoff_unblock(struct ceph_osd *osd, |
| 4066 | const struct MOSDBackoff *m) |
| 4067 | { |
| 4068 | struct ceph_spg_mapping *spg; |
| 4069 | struct ceph_osd_backoff *backoff; |
| 4070 | struct rb_node *n; |
| 4071 | |
| 4072 | dout("%s osd%d spgid %llu.%xs%d id %llu\n", __func__, osd->o_osd, |
| 4073 | m->spgid.pgid.pool, m->spgid.pgid.seed, m->spgid.shard, m->id); |
| 4074 | |
| 4075 | backoff = lookup_backoff_by_id(&osd->o_backoffs_by_id, m->id); |
| 4076 | if (!backoff) { |
| 4077 | pr_err("%s osd%d spgid %llu.%xs%d id %llu backoff dne\n", |
| 4078 | __func__, osd->o_osd, m->spgid.pgid.pool, |
| 4079 | m->spgid.pgid.seed, m->spgid.shard, m->id); |
| 4080 | return; |
| 4081 | } |
| 4082 | |
| 4083 | if (hoid_compare(backoff->begin, m->begin) && |
| 4084 | hoid_compare(backoff->end, m->end)) { |
| 4085 | pr_err("%s osd%d spgid %llu.%xs%d id %llu bad range?\n", |
| 4086 | __func__, osd->o_osd, m->spgid.pgid.pool, |
| 4087 | m->spgid.pgid.seed, m->spgid.shard, m->id); |
| 4088 | /* unblock it anyway... */ |
| 4089 | } |
| 4090 | |
| 4091 | spg = lookup_spg_mapping(&osd->o_backoff_mappings, &backoff->spgid); |
| 4092 | BUG_ON(!spg); |
| 4093 | |
| 4094 | erase_backoff(&spg->backoffs, backoff); |
| 4095 | erase_backoff_by_id(&osd->o_backoffs_by_id, backoff); |
| 4096 | free_backoff(backoff); |
| 4097 | |
| 4098 | if (RB_EMPTY_ROOT(&spg->backoffs)) { |
| 4099 | erase_spg_mapping(&osd->o_backoff_mappings, spg); |
| 4100 | free_spg_mapping(spg); |
| 4101 | } |
| 4102 | |
| 4103 | for (n = rb_first(&osd->o_requests); n; n = rb_next(n)) { |
| 4104 | struct ceph_osd_request *req = |
| 4105 | rb_entry(n, struct ceph_osd_request, r_node); |
| 4106 | |
| 4107 | if (!ceph_spg_compare(&req->r_t.spgid, &m->spgid)) { |
| 4108 | /* |
| 4109 | * Match against @m, not @backoff -- the PG may |
| 4110 | * have split on the OSD. |
| 4111 | */ |
| 4112 | if (target_contained_by(&req->r_t, m->begin, m->end)) { |
| 4113 | /* |
| 4114 | * If no other installed backoff applies, |
| 4115 | * resend. |
| 4116 | */ |
| 4117 | send_request(req); |
| 4118 | } |
| 4119 | } |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | static void handle_backoff(struct ceph_osd *osd, struct ceph_msg *msg) |
| 4124 | { |
| 4125 | struct ceph_osd_client *osdc = osd->o_osdc; |
| 4126 | struct MOSDBackoff m; |
| 4127 | int ret; |
| 4128 | |
| 4129 | down_read(&osdc->lock); |
| 4130 | if (!osd_registered(osd)) { |
| 4131 | dout("%s osd%d unknown\n", __func__, osd->o_osd); |
| 4132 | up_read(&osdc->lock); |
| 4133 | return; |
| 4134 | } |
| 4135 | WARN_ON(osd->o_osd != le64_to_cpu(msg->hdr.src.num)); |
| 4136 | |
| 4137 | mutex_lock(&osd->lock); |
| 4138 | ret = decode_MOSDBackoff(msg, &m); |
| 4139 | if (ret) { |
| 4140 | pr_err("failed to decode MOSDBackoff: %d\n", ret); |
| 4141 | ceph_msg_dump(msg); |
| 4142 | goto out_unlock; |
| 4143 | } |
| 4144 | |
| 4145 | switch (m.op) { |
| 4146 | case CEPH_OSD_BACKOFF_OP_BLOCK: |
| 4147 | handle_backoff_block(osd, &m); |
| 4148 | break; |
| 4149 | case CEPH_OSD_BACKOFF_OP_UNBLOCK: |
| 4150 | handle_backoff_unblock(osd, &m); |
| 4151 | break; |
| 4152 | default: |
| 4153 | pr_err("%s osd%d unknown op %d\n", __func__, osd->o_osd, m.op); |
| 4154 | } |
| 4155 | |
| 4156 | free_hoid(m.begin); |
| 4157 | free_hoid(m.end); |
| 4158 | |
| 4159 | out_unlock: |
| 4160 | mutex_unlock(&osd->lock); |
| 4161 | up_read(&osdc->lock); |
| 4162 | } |
| 4163 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4164 | /* |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4165 | * Process osd watch notifications |
| 4166 | */ |
Alex Elder | 3c663bb | 2013-02-15 11:42:30 -0600 | [diff] [blame] | 4167 | static void handle_watch_notify(struct ceph_osd_client *osdc, |
| 4168 | struct ceph_msg *msg) |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4169 | { |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4170 | void *p = msg->front.iov_base; |
| 4171 | void *const end = p + msg->front.iov_len; |
| 4172 | struct ceph_osd_linger_request *lreq; |
| 4173 | struct linger_work *lwork; |
| 4174 | u8 proto_ver, opcode; |
| 4175 | u64 cookie, notify_id; |
| 4176 | u64 notifier_id = 0; |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 4177 | s32 return_code = 0; |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4178 | void *payload = NULL; |
| 4179 | u32 payload_len = 0; |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4180 | |
| 4181 | ceph_decode_8_safe(&p, end, proto_ver, bad); |
| 4182 | ceph_decode_8_safe(&p, end, opcode, bad); |
| 4183 | ceph_decode_64_safe(&p, end, cookie, bad); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4184 | p += 8; /* skip ver */ |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4185 | ceph_decode_64_safe(&p, end, notify_id, bad); |
| 4186 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4187 | if (proto_ver >= 1) { |
| 4188 | ceph_decode_32_safe(&p, end, payload_len, bad); |
| 4189 | ceph_decode_need(&p, end, payload_len, bad); |
| 4190 | payload = p; |
| 4191 | p += payload_len; |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4192 | } |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4193 | |
| 4194 | if (le16_to_cpu(msg->hdr.version) >= 2) |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 4195 | ceph_decode_32_safe(&p, end, return_code, bad); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4196 | |
| 4197 | if (le16_to_cpu(msg->hdr.version) >= 3) |
| 4198 | ceph_decode_64_safe(&p, end, notifier_id, bad); |
| 4199 | |
| 4200 | down_read(&osdc->lock); |
| 4201 | lreq = lookup_linger_osdc(&osdc->linger_requests, cookie); |
| 4202 | if (!lreq) { |
| 4203 | dout("%s opcode %d cookie %llu dne\n", __func__, opcode, |
| 4204 | cookie); |
| 4205 | goto out_unlock_osdc; |
| 4206 | } |
| 4207 | |
| 4208 | mutex_lock(&lreq->lock); |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 4209 | dout("%s opcode %d cookie %llu lreq %p is_watch %d\n", __func__, |
| 4210 | opcode, cookie, lreq, lreq->is_watch); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4211 | if (opcode == CEPH_WATCH_EVENT_DISCONNECT) { |
| 4212 | if (!lreq->last_error) { |
| 4213 | lreq->last_error = -ENOTCONN; |
| 4214 | queue_watch_error(lreq); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4215 | } |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 4216 | } else if (!lreq->is_watch) { |
| 4217 | /* CEPH_WATCH_EVENT_NOTIFY_COMPLETE */ |
| 4218 | if (lreq->notify_id && lreq->notify_id != notify_id) { |
| 4219 | dout("lreq %p notify_id %llu != %llu, ignoring\n", lreq, |
| 4220 | lreq->notify_id, notify_id); |
| 4221 | } else if (!completion_done(&lreq->notify_finish_wait)) { |
| 4222 | struct ceph_msg_data *data = |
| 4223 | list_first_entry_or_null(&msg->data, |
| 4224 | struct ceph_msg_data, |
| 4225 | links); |
| 4226 | |
| 4227 | if (data) { |
| 4228 | if (lreq->preply_pages) { |
| 4229 | WARN_ON(data->type != |
| 4230 | CEPH_MSG_DATA_PAGES); |
| 4231 | *lreq->preply_pages = data->pages; |
| 4232 | *lreq->preply_len = data->length; |
| 4233 | } else { |
| 4234 | ceph_release_page_vector(data->pages, |
| 4235 | calc_pages_for(0, data->length)); |
| 4236 | } |
| 4237 | } |
| 4238 | lreq->notify_finish_error = return_code; |
| 4239 | complete_all(&lreq->notify_finish_wait); |
| 4240 | } |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4241 | } else { |
| 4242 | /* CEPH_WATCH_EVENT_NOTIFY */ |
| 4243 | lwork = lwork_alloc(lreq, do_watch_notify); |
| 4244 | if (!lwork) { |
| 4245 | pr_err("failed to allocate notify-lwork\n"); |
| 4246 | goto out_unlock_lreq; |
| 4247 | } |
Ilya Dryomov | 91883cd | 2014-09-11 12:18:53 +0400 | [diff] [blame] | 4248 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4249 | lwork->notify.notify_id = notify_id; |
| 4250 | lwork->notify.notifier_id = notifier_id; |
| 4251 | lwork->notify.payload = payload; |
| 4252 | lwork->notify.payload_len = payload_len; |
| 4253 | lwork->notify.msg = ceph_msg_get(msg); |
| 4254 | lwork_queue(lwork); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4255 | } |
| 4256 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4257 | out_unlock_lreq: |
| 4258 | mutex_unlock(&lreq->lock); |
| 4259 | out_unlock_osdc: |
| 4260 | up_read(&osdc->lock); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4261 | return; |
| 4262 | |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4263 | bad: |
| 4264 | pr_err("osdc handle_watch_notify corrupt msg\n"); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4265 | } |
| 4266 | |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4267 | /* |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4268 | * Register request, send initial attempt. |
| 4269 | */ |
| 4270 | int ceph_osdc_start_request(struct ceph_osd_client *osdc, |
| 4271 | struct ceph_osd_request *req, |
| 4272 | bool nofail) |
| 4273 | { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4274 | down_read(&osdc->lock); |
| 4275 | submit_request(req, false); |
| 4276 | up_read(&osdc->lock); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4277 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4278 | return 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4279 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4280 | EXPORT_SYMBOL(ceph_osdc_start_request); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4281 | |
| 4282 | /* |
Ilya Dryomov | c297eb42 | 2016-12-02 14:01:55 +0100 | [diff] [blame] | 4283 | * Unregister a registered request. The request is not completed: |
| 4284 | * ->r_result isn't set and __complete_request() isn't called. |
Ilya Dryomov | c9f9b93 | 2014-06-19 11:38:13 +0400 | [diff] [blame] | 4285 | */ |
| 4286 | void ceph_osdc_cancel_request(struct ceph_osd_request *req) |
| 4287 | { |
| 4288 | struct ceph_osd_client *osdc = req->r_osdc; |
| 4289 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4290 | down_write(&osdc->lock); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4291 | if (req->r_osd) |
| 4292 | cancel_request(req); |
| 4293 | up_write(&osdc->lock); |
Ilya Dryomov | c9f9b93 | 2014-06-19 11:38:13 +0400 | [diff] [blame] | 4294 | } |
| 4295 | EXPORT_SYMBOL(ceph_osdc_cancel_request); |
| 4296 | |
| 4297 | /* |
Ilya Dryomov | 42b0696 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4298 | * @timeout: in jiffies, 0 means "wait forever" |
| 4299 | */ |
| 4300 | static int wait_request_timeout(struct ceph_osd_request *req, |
| 4301 | unsigned long timeout) |
| 4302 | { |
| 4303 | long left; |
| 4304 | |
| 4305 | dout("%s req %p tid %llu\n", __func__, req, req->r_tid); |
Yan, Zheng | 0e76abf | 2016-05-13 11:04:33 +0800 | [diff] [blame] | 4306 | left = wait_for_completion_killable_timeout(&req->r_completion, |
Ilya Dryomov | 42b0696 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4307 | ceph_timeout_jiffies(timeout)); |
| 4308 | if (left <= 0) { |
| 4309 | left = left ?: -ETIMEDOUT; |
| 4310 | ceph_osdc_cancel_request(req); |
Ilya Dryomov | 42b0696 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4311 | } else { |
| 4312 | left = req->r_result; /* completed */ |
| 4313 | } |
| 4314 | |
| 4315 | return left; |
| 4316 | } |
| 4317 | |
| 4318 | /* |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4319 | * wait for a request to complete |
| 4320 | */ |
| 4321 | int ceph_osdc_wait_request(struct ceph_osd_client *osdc, |
| 4322 | struct ceph_osd_request *req) |
| 4323 | { |
Ilya Dryomov | 42b0696 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4324 | return wait_request_timeout(req, 0); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4325 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4326 | EXPORT_SYMBOL(ceph_osdc_wait_request); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4327 | |
| 4328 | /* |
| 4329 | * sync - wait for all in-flight requests to flush. avoid starvation. |
| 4330 | */ |
| 4331 | void ceph_osdc_sync(struct ceph_osd_client *osdc) |
| 4332 | { |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4333 | struct rb_node *n, *p; |
| 4334 | u64 last_tid = atomic64_read(&osdc->last_tid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4335 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4336 | again: |
| 4337 | down_read(&osdc->lock); |
| 4338 | for (n = rb_first(&osdc->osds); n; n = rb_next(n)) { |
| 4339 | struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4340 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4341 | mutex_lock(&osd->lock); |
| 4342 | for (p = rb_first(&osd->o_requests); p; p = rb_next(p)) { |
| 4343 | struct ceph_osd_request *req = |
| 4344 | rb_entry(p, struct ceph_osd_request, r_node); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4345 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4346 | if (req->r_tid > last_tid) |
| 4347 | break; |
| 4348 | |
| 4349 | if (!(req->r_flags & CEPH_OSD_FLAG_WRITE)) |
| 4350 | continue; |
| 4351 | |
| 4352 | ceph_osdc_get_request(req); |
| 4353 | mutex_unlock(&osd->lock); |
| 4354 | up_read(&osdc->lock); |
| 4355 | dout("%s waiting on req %p tid %llu last_tid %llu\n", |
| 4356 | __func__, req, req->r_tid, last_tid); |
Ilya Dryomov | b18b955 | 2017-02-11 18:46:08 +0100 | [diff] [blame] | 4357 | wait_for_completion(&req->r_completion); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4358 | ceph_osdc_put_request(req); |
| 4359 | goto again; |
| 4360 | } |
| 4361 | |
| 4362 | mutex_unlock(&osd->lock); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4363 | } |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4364 | |
| 4365 | up_read(&osdc->lock); |
| 4366 | dout("%s done last_tid %llu\n", __func__, last_tid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4367 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4368 | EXPORT_SYMBOL(ceph_osdc_sync); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4369 | |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4370 | static struct ceph_osd_request * |
| 4371 | alloc_linger_request(struct ceph_osd_linger_request *lreq) |
| 4372 | { |
| 4373 | struct ceph_osd_request *req; |
| 4374 | |
| 4375 | req = ceph_osdc_alloc_request(lreq->osdc, NULL, 1, false, GFP_NOIO); |
| 4376 | if (!req) |
| 4377 | return NULL; |
| 4378 | |
| 4379 | ceph_oid_copy(&req->r_base_oid, &lreq->t.base_oid); |
| 4380 | ceph_oloc_copy(&req->r_base_oloc, &lreq->t.base_oloc); |
| 4381 | |
| 4382 | if (ceph_osdc_alloc_messages(req, GFP_NOIO)) { |
| 4383 | ceph_osdc_put_request(req); |
| 4384 | return NULL; |
| 4385 | } |
| 4386 | |
| 4387 | return req; |
| 4388 | } |
| 4389 | |
| 4390 | /* |
| 4391 | * Returns a handle, caller owns a ref. |
| 4392 | */ |
| 4393 | struct ceph_osd_linger_request * |
| 4394 | ceph_osdc_watch(struct ceph_osd_client *osdc, |
| 4395 | struct ceph_object_id *oid, |
| 4396 | struct ceph_object_locator *oloc, |
| 4397 | rados_watchcb2_t wcb, |
| 4398 | rados_watcherrcb_t errcb, |
| 4399 | void *data) |
| 4400 | { |
| 4401 | struct ceph_osd_linger_request *lreq; |
| 4402 | int ret; |
| 4403 | |
| 4404 | lreq = linger_alloc(osdc); |
| 4405 | if (!lreq) |
| 4406 | return ERR_PTR(-ENOMEM); |
| 4407 | |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 4408 | lreq->is_watch = true; |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4409 | lreq->wcb = wcb; |
| 4410 | lreq->errcb = errcb; |
| 4411 | lreq->data = data; |
Ilya Dryomov | b07d3c4 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 4412 | lreq->watch_valid_thru = jiffies; |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4413 | |
| 4414 | ceph_oid_copy(&lreq->t.base_oid, oid); |
| 4415 | ceph_oloc_copy(&lreq->t.base_oloc, oloc); |
Ilya Dryomov | 54ea004 | 2017-02-11 18:48:41 +0100 | [diff] [blame] | 4416 | lreq->t.flags = CEPH_OSD_FLAG_WRITE; |
Deepa Dinamani | 1134e09 | 2017-05-08 15:59:19 -0700 | [diff] [blame] | 4417 | ktime_get_real_ts(&lreq->mtime); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4418 | |
| 4419 | lreq->reg_req = alloc_linger_request(lreq); |
| 4420 | if (!lreq->reg_req) { |
| 4421 | ret = -ENOMEM; |
| 4422 | goto err_put_lreq; |
| 4423 | } |
| 4424 | |
| 4425 | lreq->ping_req = alloc_linger_request(lreq); |
| 4426 | if (!lreq->ping_req) { |
| 4427 | ret = -ENOMEM; |
| 4428 | goto err_put_lreq; |
| 4429 | } |
| 4430 | |
| 4431 | down_write(&osdc->lock); |
| 4432 | linger_register(lreq); /* before osd_req_op_* */ |
| 4433 | osd_req_op_watch_init(lreq->reg_req, 0, lreq->linger_id, |
| 4434 | CEPH_OSD_WATCH_OP_WATCH); |
| 4435 | osd_req_op_watch_init(lreq->ping_req, 0, lreq->linger_id, |
| 4436 | CEPH_OSD_WATCH_OP_PING); |
| 4437 | linger_submit(lreq); |
| 4438 | up_write(&osdc->lock); |
| 4439 | |
| 4440 | ret = linger_reg_commit_wait(lreq); |
| 4441 | if (ret) { |
| 4442 | linger_cancel(lreq); |
| 4443 | goto err_put_lreq; |
| 4444 | } |
| 4445 | |
| 4446 | return lreq; |
| 4447 | |
| 4448 | err_put_lreq: |
| 4449 | linger_put(lreq); |
| 4450 | return ERR_PTR(ret); |
| 4451 | } |
| 4452 | EXPORT_SYMBOL(ceph_osdc_watch); |
| 4453 | |
| 4454 | /* |
| 4455 | * Releases a ref. |
| 4456 | * |
| 4457 | * Times out after mount_timeout to preserve rbd unmap behaviour |
| 4458 | * introduced in 2894e1d76974 ("rbd: timeout watch teardown on unmap |
| 4459 | * with mount_timeout"). |
| 4460 | */ |
| 4461 | int ceph_osdc_unwatch(struct ceph_osd_client *osdc, |
| 4462 | struct ceph_osd_linger_request *lreq) |
| 4463 | { |
| 4464 | struct ceph_options *opts = osdc->client->options; |
| 4465 | struct ceph_osd_request *req; |
| 4466 | int ret; |
| 4467 | |
| 4468 | req = ceph_osdc_alloc_request(osdc, NULL, 1, false, GFP_NOIO); |
| 4469 | if (!req) |
| 4470 | return -ENOMEM; |
| 4471 | |
| 4472 | ceph_oid_copy(&req->r_base_oid, &lreq->t.base_oid); |
| 4473 | ceph_oloc_copy(&req->r_base_oloc, &lreq->t.base_oloc); |
Ilya Dryomov | 54ea004 | 2017-02-11 18:48:41 +0100 | [diff] [blame] | 4474 | req->r_flags = CEPH_OSD_FLAG_WRITE; |
Deepa Dinamani | 1134e09 | 2017-05-08 15:59:19 -0700 | [diff] [blame] | 4475 | ktime_get_real_ts(&req->r_mtime); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4476 | osd_req_op_watch_init(req, 0, lreq->linger_id, |
| 4477 | CEPH_OSD_WATCH_OP_UNWATCH); |
| 4478 | |
| 4479 | ret = ceph_osdc_alloc_messages(req, GFP_NOIO); |
| 4480 | if (ret) |
| 4481 | goto out_put_req; |
| 4482 | |
| 4483 | ceph_osdc_start_request(osdc, req, false); |
| 4484 | linger_cancel(lreq); |
| 4485 | linger_put(lreq); |
| 4486 | ret = wait_request_timeout(req, opts->mount_timeout); |
| 4487 | |
| 4488 | out_put_req: |
| 4489 | ceph_osdc_put_request(req); |
| 4490 | return ret; |
| 4491 | } |
| 4492 | EXPORT_SYMBOL(ceph_osdc_unwatch); |
| 4493 | |
| 4494 | static int osd_req_op_notify_ack_init(struct ceph_osd_request *req, int which, |
| 4495 | u64 notify_id, u64 cookie, void *payload, |
| 4496 | size_t payload_len) |
| 4497 | { |
| 4498 | struct ceph_osd_req_op *op; |
| 4499 | struct ceph_pagelist *pl; |
| 4500 | int ret; |
| 4501 | |
| 4502 | op = _osd_req_op_init(req, which, CEPH_OSD_OP_NOTIFY_ACK, 0); |
| 4503 | |
| 4504 | pl = kmalloc(sizeof(*pl), GFP_NOIO); |
| 4505 | if (!pl) |
| 4506 | return -ENOMEM; |
| 4507 | |
| 4508 | ceph_pagelist_init(pl); |
| 4509 | ret = ceph_pagelist_encode_64(pl, notify_id); |
| 4510 | ret |= ceph_pagelist_encode_64(pl, cookie); |
| 4511 | if (payload) { |
| 4512 | ret |= ceph_pagelist_encode_32(pl, payload_len); |
| 4513 | ret |= ceph_pagelist_append(pl, payload, payload_len); |
| 4514 | } else { |
| 4515 | ret |= ceph_pagelist_encode_32(pl, 0); |
| 4516 | } |
| 4517 | if (ret) { |
| 4518 | ceph_pagelist_release(pl); |
| 4519 | return -ENOMEM; |
| 4520 | } |
| 4521 | |
| 4522 | ceph_osd_data_pagelist_init(&op->notify_ack.request_data, pl); |
| 4523 | op->indata_len = pl->length; |
| 4524 | return 0; |
| 4525 | } |
| 4526 | |
| 4527 | int ceph_osdc_notify_ack(struct ceph_osd_client *osdc, |
| 4528 | struct ceph_object_id *oid, |
| 4529 | struct ceph_object_locator *oloc, |
| 4530 | u64 notify_id, |
| 4531 | u64 cookie, |
| 4532 | void *payload, |
| 4533 | size_t payload_len) |
| 4534 | { |
| 4535 | struct ceph_osd_request *req; |
| 4536 | int ret; |
| 4537 | |
| 4538 | req = ceph_osdc_alloc_request(osdc, NULL, 1, false, GFP_NOIO); |
| 4539 | if (!req) |
| 4540 | return -ENOMEM; |
| 4541 | |
| 4542 | ceph_oid_copy(&req->r_base_oid, oid); |
| 4543 | ceph_oloc_copy(&req->r_base_oloc, oloc); |
| 4544 | req->r_flags = CEPH_OSD_FLAG_READ; |
| 4545 | |
| 4546 | ret = ceph_osdc_alloc_messages(req, GFP_NOIO); |
| 4547 | if (ret) |
| 4548 | goto out_put_req; |
| 4549 | |
| 4550 | ret = osd_req_op_notify_ack_init(req, 0, notify_id, cookie, payload, |
| 4551 | payload_len); |
| 4552 | if (ret) |
| 4553 | goto out_put_req; |
| 4554 | |
| 4555 | ceph_osdc_start_request(osdc, req, false); |
| 4556 | ret = ceph_osdc_wait_request(osdc, req); |
| 4557 | |
| 4558 | out_put_req: |
| 4559 | ceph_osdc_put_request(req); |
| 4560 | return ret; |
| 4561 | } |
| 4562 | EXPORT_SYMBOL(ceph_osdc_notify_ack); |
| 4563 | |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 4564 | static int osd_req_op_notify_init(struct ceph_osd_request *req, int which, |
| 4565 | u64 cookie, u32 prot_ver, u32 timeout, |
| 4566 | void *payload, size_t payload_len) |
| 4567 | { |
| 4568 | struct ceph_osd_req_op *op; |
| 4569 | struct ceph_pagelist *pl; |
| 4570 | int ret; |
| 4571 | |
| 4572 | op = _osd_req_op_init(req, which, CEPH_OSD_OP_NOTIFY, 0); |
| 4573 | op->notify.cookie = cookie; |
| 4574 | |
| 4575 | pl = kmalloc(sizeof(*pl), GFP_NOIO); |
| 4576 | if (!pl) |
| 4577 | return -ENOMEM; |
| 4578 | |
| 4579 | ceph_pagelist_init(pl); |
| 4580 | ret = ceph_pagelist_encode_32(pl, 1); /* prot_ver */ |
| 4581 | ret |= ceph_pagelist_encode_32(pl, timeout); |
| 4582 | ret |= ceph_pagelist_encode_32(pl, payload_len); |
| 4583 | ret |= ceph_pagelist_append(pl, payload, payload_len); |
| 4584 | if (ret) { |
| 4585 | ceph_pagelist_release(pl); |
| 4586 | return -ENOMEM; |
| 4587 | } |
| 4588 | |
| 4589 | ceph_osd_data_pagelist_init(&op->notify.request_data, pl); |
| 4590 | op->indata_len = pl->length; |
| 4591 | return 0; |
| 4592 | } |
| 4593 | |
| 4594 | /* |
| 4595 | * @timeout: in seconds |
| 4596 | * |
| 4597 | * @preply_{pages,len} are initialized both on success and error. |
| 4598 | * The caller is responsible for: |
| 4599 | * |
| 4600 | * ceph_release_page_vector(reply_pages, calc_pages_for(0, reply_len)) |
| 4601 | */ |
| 4602 | int ceph_osdc_notify(struct ceph_osd_client *osdc, |
| 4603 | struct ceph_object_id *oid, |
| 4604 | struct ceph_object_locator *oloc, |
| 4605 | void *payload, |
| 4606 | size_t payload_len, |
| 4607 | u32 timeout, |
| 4608 | struct page ***preply_pages, |
| 4609 | size_t *preply_len) |
| 4610 | { |
| 4611 | struct ceph_osd_linger_request *lreq; |
| 4612 | struct page **pages; |
| 4613 | int ret; |
| 4614 | |
| 4615 | WARN_ON(!timeout); |
| 4616 | if (preply_pages) { |
| 4617 | *preply_pages = NULL; |
| 4618 | *preply_len = 0; |
| 4619 | } |
| 4620 | |
| 4621 | lreq = linger_alloc(osdc); |
| 4622 | if (!lreq) |
| 4623 | return -ENOMEM; |
| 4624 | |
| 4625 | lreq->preply_pages = preply_pages; |
| 4626 | lreq->preply_len = preply_len; |
| 4627 | |
| 4628 | ceph_oid_copy(&lreq->t.base_oid, oid); |
| 4629 | ceph_oloc_copy(&lreq->t.base_oloc, oloc); |
| 4630 | lreq->t.flags = CEPH_OSD_FLAG_READ; |
| 4631 | |
| 4632 | lreq->reg_req = alloc_linger_request(lreq); |
| 4633 | if (!lreq->reg_req) { |
| 4634 | ret = -ENOMEM; |
| 4635 | goto out_put_lreq; |
| 4636 | } |
| 4637 | |
| 4638 | /* for notify_id */ |
| 4639 | pages = ceph_alloc_page_vector(1, GFP_NOIO); |
| 4640 | if (IS_ERR(pages)) { |
| 4641 | ret = PTR_ERR(pages); |
| 4642 | goto out_put_lreq; |
| 4643 | } |
| 4644 | |
| 4645 | down_write(&osdc->lock); |
| 4646 | linger_register(lreq); /* before osd_req_op_* */ |
| 4647 | ret = osd_req_op_notify_init(lreq->reg_req, 0, lreq->linger_id, 1, |
| 4648 | timeout, payload, payload_len); |
| 4649 | if (ret) { |
| 4650 | linger_unregister(lreq); |
| 4651 | up_write(&osdc->lock); |
| 4652 | ceph_release_page_vector(pages, 1); |
| 4653 | goto out_put_lreq; |
| 4654 | } |
| 4655 | ceph_osd_data_pages_init(osd_req_op_data(lreq->reg_req, 0, notify, |
| 4656 | response_data), |
| 4657 | pages, PAGE_SIZE, 0, false, true); |
| 4658 | linger_submit(lreq); |
| 4659 | up_write(&osdc->lock); |
| 4660 | |
| 4661 | ret = linger_reg_commit_wait(lreq); |
| 4662 | if (!ret) |
| 4663 | ret = linger_notify_finish_wait(lreq); |
| 4664 | else |
| 4665 | dout("lreq %p failed to initiate notify %d\n", lreq, ret); |
| 4666 | |
| 4667 | linger_cancel(lreq); |
| 4668 | out_put_lreq: |
| 4669 | linger_put(lreq); |
| 4670 | return ret; |
| 4671 | } |
| 4672 | EXPORT_SYMBOL(ceph_osdc_notify); |
| 4673 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4674 | /* |
Ilya Dryomov | b07d3c4 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 4675 | * Return the number of milliseconds since the watch was last |
| 4676 | * confirmed, or an error. If there is an error, the watch is no |
| 4677 | * longer valid, and should be destroyed with ceph_osdc_unwatch(). |
| 4678 | */ |
| 4679 | int ceph_osdc_watch_check(struct ceph_osd_client *osdc, |
| 4680 | struct ceph_osd_linger_request *lreq) |
| 4681 | { |
| 4682 | unsigned long stamp, age; |
| 4683 | int ret; |
| 4684 | |
| 4685 | down_read(&osdc->lock); |
| 4686 | mutex_lock(&lreq->lock); |
| 4687 | stamp = lreq->watch_valid_thru; |
| 4688 | if (!list_empty(&lreq->pending_lworks)) { |
| 4689 | struct linger_work *lwork = |
| 4690 | list_first_entry(&lreq->pending_lworks, |
| 4691 | struct linger_work, |
| 4692 | pending_item); |
| 4693 | |
| 4694 | if (time_before(lwork->queued_stamp, stamp)) |
| 4695 | stamp = lwork->queued_stamp; |
| 4696 | } |
| 4697 | age = jiffies - stamp; |
| 4698 | dout("%s lreq %p linger_id %llu age %lu last_error %d\n", __func__, |
| 4699 | lreq, lreq->linger_id, age, lreq->last_error); |
| 4700 | /* we are truncating to msecs, so return a safe upper bound */ |
| 4701 | ret = lreq->last_error ?: 1 + jiffies_to_msecs(age); |
| 4702 | |
| 4703 | mutex_unlock(&lreq->lock); |
| 4704 | up_read(&osdc->lock); |
| 4705 | return ret; |
| 4706 | } |
| 4707 | |
Douglas Fuller | a4ed38d | 2015-07-17 13:18:07 -0700 | [diff] [blame] | 4708 | static int decode_watcher(void **p, void *end, struct ceph_watch_item *item) |
| 4709 | { |
| 4710 | u8 struct_v; |
| 4711 | u32 struct_len; |
| 4712 | int ret; |
| 4713 | |
| 4714 | ret = ceph_start_decoding(p, end, 2, "watch_item_t", |
| 4715 | &struct_v, &struct_len); |
| 4716 | if (ret) |
| 4717 | return ret; |
| 4718 | |
| 4719 | ceph_decode_copy(p, &item->name, sizeof(item->name)); |
| 4720 | item->cookie = ceph_decode_64(p); |
| 4721 | *p += 4; /* skip timeout_seconds */ |
| 4722 | if (struct_v >= 2) { |
| 4723 | ceph_decode_copy(p, &item->addr, sizeof(item->addr)); |
| 4724 | ceph_decode_addr(&item->addr); |
| 4725 | } |
| 4726 | |
| 4727 | dout("%s %s%llu cookie %llu addr %s\n", __func__, |
| 4728 | ENTITY_NAME(item->name), item->cookie, |
| 4729 | ceph_pr_addr(&item->addr.in_addr)); |
| 4730 | return 0; |
| 4731 | } |
| 4732 | |
| 4733 | static int decode_watchers(void **p, void *end, |
| 4734 | struct ceph_watch_item **watchers, |
| 4735 | u32 *num_watchers) |
| 4736 | { |
| 4737 | u8 struct_v; |
| 4738 | u32 struct_len; |
| 4739 | int i; |
| 4740 | int ret; |
| 4741 | |
| 4742 | ret = ceph_start_decoding(p, end, 1, "obj_list_watch_response_t", |
| 4743 | &struct_v, &struct_len); |
| 4744 | if (ret) |
| 4745 | return ret; |
| 4746 | |
| 4747 | *num_watchers = ceph_decode_32(p); |
| 4748 | *watchers = kcalloc(*num_watchers, sizeof(**watchers), GFP_NOIO); |
| 4749 | if (!*watchers) |
| 4750 | return -ENOMEM; |
| 4751 | |
| 4752 | for (i = 0; i < *num_watchers; i++) { |
| 4753 | ret = decode_watcher(p, end, *watchers + i); |
| 4754 | if (ret) { |
| 4755 | kfree(*watchers); |
| 4756 | return ret; |
| 4757 | } |
| 4758 | } |
| 4759 | |
| 4760 | return 0; |
| 4761 | } |
| 4762 | |
| 4763 | /* |
| 4764 | * On success, the caller is responsible for: |
| 4765 | * |
| 4766 | * kfree(watchers); |
| 4767 | */ |
| 4768 | int ceph_osdc_list_watchers(struct ceph_osd_client *osdc, |
| 4769 | struct ceph_object_id *oid, |
| 4770 | struct ceph_object_locator *oloc, |
| 4771 | struct ceph_watch_item **watchers, |
| 4772 | u32 *num_watchers) |
| 4773 | { |
| 4774 | struct ceph_osd_request *req; |
| 4775 | struct page **pages; |
| 4776 | int ret; |
| 4777 | |
| 4778 | req = ceph_osdc_alloc_request(osdc, NULL, 1, false, GFP_NOIO); |
| 4779 | if (!req) |
| 4780 | return -ENOMEM; |
| 4781 | |
| 4782 | ceph_oid_copy(&req->r_base_oid, oid); |
| 4783 | ceph_oloc_copy(&req->r_base_oloc, oloc); |
| 4784 | req->r_flags = CEPH_OSD_FLAG_READ; |
| 4785 | |
| 4786 | ret = ceph_osdc_alloc_messages(req, GFP_NOIO); |
| 4787 | if (ret) |
| 4788 | goto out_put_req; |
| 4789 | |
| 4790 | pages = ceph_alloc_page_vector(1, GFP_NOIO); |
| 4791 | if (IS_ERR(pages)) { |
| 4792 | ret = PTR_ERR(pages); |
| 4793 | goto out_put_req; |
| 4794 | } |
| 4795 | |
| 4796 | osd_req_op_init(req, 0, CEPH_OSD_OP_LIST_WATCHERS, 0); |
| 4797 | ceph_osd_data_pages_init(osd_req_op_data(req, 0, list_watchers, |
| 4798 | response_data), |
| 4799 | pages, PAGE_SIZE, 0, false, true); |
| 4800 | |
| 4801 | ceph_osdc_start_request(osdc, req, false); |
| 4802 | ret = ceph_osdc_wait_request(osdc, req); |
| 4803 | if (ret >= 0) { |
| 4804 | void *p = page_address(pages[0]); |
| 4805 | void *const end = p + req->r_ops[0].outdata_len; |
| 4806 | |
| 4807 | ret = decode_watchers(&p, end, watchers, num_watchers); |
| 4808 | } |
| 4809 | |
| 4810 | out_put_req: |
| 4811 | ceph_osdc_put_request(req); |
| 4812 | return ret; |
| 4813 | } |
| 4814 | EXPORT_SYMBOL(ceph_osdc_list_watchers); |
| 4815 | |
Ilya Dryomov | b07d3c4 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 4816 | /* |
Josh Durgin | dd935f4 | 2013-08-28 21:43:09 -0700 | [diff] [blame] | 4817 | * Call all pending notify callbacks - for use after a watch is |
| 4818 | * unregistered, to make sure no more callbacks for it will be invoked |
| 4819 | */ |
stephen hemminger | f6479449 | 2014-06-10 20:30:13 -0700 | [diff] [blame] | 4820 | void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc) |
Josh Durgin | dd935f4 | 2013-08-28 21:43:09 -0700 | [diff] [blame] | 4821 | { |
Ilya Dryomov | 99d1694 | 2016-08-12 16:11:41 +0200 | [diff] [blame] | 4822 | dout("%s osdc %p\n", __func__, osdc); |
Josh Durgin | dd935f4 | 2013-08-28 21:43:09 -0700 | [diff] [blame] | 4823 | flush_workqueue(osdc->notify_wq); |
| 4824 | } |
| 4825 | EXPORT_SYMBOL(ceph_osdc_flush_notifies); |
| 4826 | |
Ilya Dryomov | 7cca78c | 2016-04-28 16:07:28 +0200 | [diff] [blame] | 4827 | void ceph_osdc_maybe_request_map(struct ceph_osd_client *osdc) |
| 4828 | { |
| 4829 | down_read(&osdc->lock); |
| 4830 | maybe_request_map(osdc); |
| 4831 | up_read(&osdc->lock); |
| 4832 | } |
| 4833 | EXPORT_SYMBOL(ceph_osdc_maybe_request_map); |
Josh Durgin | dd935f4 | 2013-08-28 21:43:09 -0700 | [diff] [blame] | 4834 | |
| 4835 | /* |
Douglas Fuller | 428a715 | 2015-06-17 14:49:45 -0400 | [diff] [blame] | 4836 | * Execute an OSD class method on an object. |
| 4837 | * |
| 4838 | * @flags: CEPH_OSD_FLAG_* |
Ilya Dryomov | 2544a02 | 2017-01-25 18:16:21 +0100 | [diff] [blame] | 4839 | * @resp_len: in/out param for reply length |
Douglas Fuller | 428a715 | 2015-06-17 14:49:45 -0400 | [diff] [blame] | 4840 | */ |
| 4841 | int ceph_osdc_call(struct ceph_osd_client *osdc, |
| 4842 | struct ceph_object_id *oid, |
| 4843 | struct ceph_object_locator *oloc, |
| 4844 | const char *class, const char *method, |
| 4845 | unsigned int flags, |
| 4846 | struct page *req_page, size_t req_len, |
| 4847 | struct page *resp_page, size_t *resp_len) |
| 4848 | { |
| 4849 | struct ceph_osd_request *req; |
| 4850 | int ret; |
| 4851 | |
Ilya Dryomov | 2544a02 | 2017-01-25 18:16:21 +0100 | [diff] [blame] | 4852 | if (req_len > PAGE_SIZE || (resp_page && *resp_len > PAGE_SIZE)) |
| 4853 | return -E2BIG; |
| 4854 | |
Douglas Fuller | 428a715 | 2015-06-17 14:49:45 -0400 | [diff] [blame] | 4855 | req = ceph_osdc_alloc_request(osdc, NULL, 1, false, GFP_NOIO); |
| 4856 | if (!req) |
| 4857 | return -ENOMEM; |
| 4858 | |
| 4859 | ceph_oid_copy(&req->r_base_oid, oid); |
| 4860 | ceph_oloc_copy(&req->r_base_oloc, oloc); |
| 4861 | req->r_flags = flags; |
| 4862 | |
| 4863 | ret = ceph_osdc_alloc_messages(req, GFP_NOIO); |
| 4864 | if (ret) |
| 4865 | goto out_put_req; |
| 4866 | |
| 4867 | osd_req_op_cls_init(req, 0, CEPH_OSD_OP_CALL, class, method); |
| 4868 | if (req_page) |
| 4869 | osd_req_op_cls_request_data_pages(req, 0, &req_page, req_len, |
| 4870 | 0, false, false); |
| 4871 | if (resp_page) |
| 4872 | osd_req_op_cls_response_data_pages(req, 0, &resp_page, |
Ilya Dryomov | 2544a02 | 2017-01-25 18:16:21 +0100 | [diff] [blame] | 4873 | *resp_len, 0, false, false); |
Douglas Fuller | 428a715 | 2015-06-17 14:49:45 -0400 | [diff] [blame] | 4874 | |
| 4875 | ceph_osdc_start_request(osdc, req, false); |
| 4876 | ret = ceph_osdc_wait_request(osdc, req); |
| 4877 | if (ret >= 0) { |
| 4878 | ret = req->r_ops[0].rval; |
| 4879 | if (resp_page) |
| 4880 | *resp_len = req->r_ops[0].outdata_len; |
| 4881 | } |
| 4882 | |
| 4883 | out_put_req: |
| 4884 | ceph_osdc_put_request(req); |
| 4885 | return ret; |
| 4886 | } |
| 4887 | EXPORT_SYMBOL(ceph_osdc_call); |
| 4888 | |
| 4889 | /* |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4890 | * init, shutdown |
| 4891 | */ |
| 4892 | int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client) |
| 4893 | { |
| 4894 | int err; |
| 4895 | |
| 4896 | dout("init\n"); |
| 4897 | osdc->client = client; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4898 | init_rwsem(&osdc->lock); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4899 | osdc->osds = RB_ROOT; |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 4900 | INIT_LIST_HEAD(&osdc->osd_lru); |
Ilya Dryomov | 9dd2845 | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4901 | spin_lock_init(&osdc->osd_lru_lock); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4902 | osd_init(&osdc->homeless_osd); |
| 4903 | osdc->homeless_osd.o_osdc = osdc; |
| 4904 | osdc->homeless_osd.o_osd = CEPH_HOMELESS_OSD; |
Ilya Dryomov | 264048a | 2016-11-08 15:15:24 +0100 | [diff] [blame] | 4905 | osdc->last_linger_id = CEPH_LINGER_ID_START; |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4906 | osdc->linger_requests = RB_ROOT; |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 4907 | osdc->map_checks = RB_ROOT; |
| 4908 | osdc->linger_map_checks = RB_ROOT; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4909 | INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 4910 | INIT_DELAYED_WORK(&osdc->osds_timeout_work, handle_osds_timeout); |
| 4911 | |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 4912 | err = -ENOMEM; |
Ilya Dryomov | e5253a7 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 4913 | osdc->osdmap = ceph_osdmap_alloc(); |
| 4914 | if (!osdc->osdmap) |
| 4915 | goto out; |
| 4916 | |
Ilya Dryomov | 9e767ad | 2016-02-09 17:25:31 +0100 | [diff] [blame] | 4917 | osdc->req_mempool = mempool_create_slab_pool(10, |
| 4918 | ceph_osd_request_cache); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4919 | if (!osdc->req_mempool) |
Ilya Dryomov | e5253a7 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 4920 | goto out_map; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4921 | |
Sage Weil | d50b409 | 2012-07-09 14:22:34 -0700 | [diff] [blame] | 4922 | err = ceph_msgpool_init(&osdc->msgpool_op, CEPH_MSG_OSD_OP, |
Ilya Dryomov | 711da55 | 2016-04-27 18:32:56 +0200 | [diff] [blame] | 4923 | PAGE_SIZE, 10, true, "osd_op"); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4924 | if (err < 0) |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 4925 | goto out_mempool; |
Sage Weil | d50b409 | 2012-07-09 14:22:34 -0700 | [diff] [blame] | 4926 | err = ceph_msgpool_init(&osdc->msgpool_op_reply, CEPH_MSG_OSD_OPREPLY, |
Ilya Dryomov | 711da55 | 2016-04-27 18:32:56 +0200 | [diff] [blame] | 4927 | PAGE_SIZE, 10, true, "osd_op_reply"); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 4928 | if (err < 0) |
| 4929 | goto out_msgpool; |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4930 | |
Dan Carpenter | dbcae08 | 2013-08-15 08:58:59 +0300 | [diff] [blame] | 4931 | err = -ENOMEM; |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4932 | osdc->notify_wq = create_singlethread_workqueue("ceph-watch-notify"); |
Dan Carpenter | dbcae08 | 2013-08-15 08:58:59 +0300 | [diff] [blame] | 4933 | if (!osdc->notify_wq) |
Ilya Dryomov | c172ec5 | 2014-01-31 17:49:22 +0200 | [diff] [blame] | 4934 | goto out_msgpool_reply; |
| 4935 | |
Ilya Dryomov | fbca963 | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 4936 | schedule_delayed_work(&osdc->timeout_work, |
| 4937 | osdc->client->options->osd_keepalive_timeout); |
Ilya Dryomov | b37ee1b | 2016-04-28 16:07:24 +0200 | [diff] [blame] | 4938 | schedule_delayed_work(&osdc->osds_timeout_work, |
| 4939 | round_jiffies_relative(osdc->client->options->osd_idle_ttl)); |
| 4940 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4941 | return 0; |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 4942 | |
Ilya Dryomov | c172ec5 | 2014-01-31 17:49:22 +0200 | [diff] [blame] | 4943 | out_msgpool_reply: |
| 4944 | ceph_msgpool_destroy(&osdc->msgpool_op_reply); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 4945 | out_msgpool: |
| 4946 | ceph_msgpool_destroy(&osdc->msgpool_op); |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 4947 | out_mempool: |
| 4948 | mempool_destroy(osdc->req_mempool); |
Ilya Dryomov | e5253a7 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 4949 | out_map: |
| 4950 | ceph_osdmap_destroy(osdc->osdmap); |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 4951 | out: |
| 4952 | return err; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4953 | } |
| 4954 | |
| 4955 | void ceph_osdc_stop(struct ceph_osd_client *osdc) |
| 4956 | { |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 4957 | flush_workqueue(osdc->notify_wq); |
| 4958 | destroy_workqueue(osdc->notify_wq); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4959 | cancel_delayed_work_sync(&osdc->timeout_work); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 4960 | cancel_delayed_work_sync(&osdc->osds_timeout_work); |
Ilya Dryomov | 42a2c09 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 4961 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4962 | down_write(&osdc->lock); |
Ilya Dryomov | 42a2c09 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 4963 | while (!RB_EMPTY_ROOT(&osdc->osds)) { |
| 4964 | struct ceph_osd *osd = rb_entry(rb_first(&osdc->osds), |
| 4965 | struct ceph_osd, o_node); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4966 | close_osd(osd); |
Ilya Dryomov | 42a2c09 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 4967 | } |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4968 | up_write(&osdc->lock); |
Elena Reshetova | 02113a0 | 2017-03-17 14:10:28 +0200 | [diff] [blame] | 4969 | WARN_ON(refcount_read(&osdc->homeless_osd.o_ref) != 1); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4970 | osd_cleanup(&osdc->homeless_osd); |
| 4971 | |
| 4972 | WARN_ON(!list_empty(&osdc->osd_lru)); |
Ilya Dryomov | 922dab6 | 2016-05-26 01:15:02 +0200 | [diff] [blame] | 4973 | WARN_ON(!RB_EMPTY_ROOT(&osdc->linger_requests)); |
Ilya Dryomov | 4609245 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 4974 | WARN_ON(!RB_EMPTY_ROOT(&osdc->map_checks)); |
| 4975 | WARN_ON(!RB_EMPTY_ROOT(&osdc->linger_map_checks)); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 4976 | WARN_ON(atomic_read(&osdc->num_requests)); |
| 4977 | WARN_ON(atomic_read(&osdc->num_homeless)); |
Ilya Dryomov | 42a2c09 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 4978 | |
Ilya Dryomov | e5253a7 | 2016-04-28 16:07:25 +0200 | [diff] [blame] | 4979 | ceph_osdmap_destroy(osdc->osdmap); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4980 | mempool_destroy(osdc->req_mempool); |
| 4981 | ceph_msgpool_destroy(&osdc->msgpool_op); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 4982 | ceph_msgpool_destroy(&osdc->msgpool_op_reply); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4983 | } |
| 4984 | |
| 4985 | /* |
| 4986 | * Read some contiguous pages. If we cross a stripe boundary, shorten |
| 4987 | * *plen. Return number of bytes read, or error. |
| 4988 | */ |
| 4989 | int ceph_osdc_readpages(struct ceph_osd_client *osdc, |
| 4990 | struct ceph_vino vino, struct ceph_file_layout *layout, |
| 4991 | u64 off, u64 *plen, |
| 4992 | u32 truncate_seq, u64 truncate_size, |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 4993 | struct page **pages, int num_pages, int page_align) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4994 | { |
| 4995 | struct ceph_osd_request *req; |
| 4996 | int rc = 0; |
| 4997 | |
| 4998 | dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino, |
| 4999 | vino.snap, off, *plen); |
Yan, Zheng | 715e4cd | 2014-11-13 14:40:37 +0800 | [diff] [blame] | 5000 | req = ceph_osdc_new_request(osdc, layout, vino, off, plen, 0, 1, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5001 | CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ, |
Alex Elder | acead00 | 2013-03-14 14:09:05 -0500 | [diff] [blame] | 5002 | NULL, truncate_seq, truncate_size, |
Alex Elder | 153e516 | 2013-03-01 18:00:15 -0600 | [diff] [blame] | 5003 | false); |
Sage Weil | 6816282 | 2012-09-24 21:01:02 -0700 | [diff] [blame] | 5004 | if (IS_ERR(req)) |
| 5005 | return PTR_ERR(req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5006 | |
| 5007 | /* it may be a short read due to an object boundary */ |
Alex Elder | 406e2c9 | 2013-04-15 14:50:36 -0500 | [diff] [blame] | 5008 | osd_req_op_extent_osd_data_pages(req, 0, |
Alex Elder | a4ce40a | 2013-04-05 01:27:12 -0500 | [diff] [blame] | 5009 | pages, *plen, page_align, false, false); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5010 | |
Alex Elder | e0c5948 | 2013-03-07 15:38:25 -0600 | [diff] [blame] | 5011 | dout("readpages final extent is %llu~%llu (%llu bytes align %d)\n", |
Alex Elder | 43bfe5d | 2013-04-03 01:28:57 -0500 | [diff] [blame] | 5012 | off, *plen, *plen, page_align); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5013 | |
| 5014 | rc = ceph_osdc_start_request(osdc, req, false); |
| 5015 | if (!rc) |
| 5016 | rc = ceph_osdc_wait_request(osdc, req); |
| 5017 | |
| 5018 | ceph_osdc_put_request(req); |
| 5019 | dout("readpages result %d\n", rc); |
| 5020 | return rc; |
| 5021 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 5022 | EXPORT_SYMBOL(ceph_osdc_readpages); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5023 | |
| 5024 | /* |
| 5025 | * do a synchronous write on N pages |
| 5026 | */ |
| 5027 | int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino, |
| 5028 | struct ceph_file_layout *layout, |
| 5029 | struct ceph_snap_context *snapc, |
| 5030 | u64 off, u64 len, |
| 5031 | u32 truncate_seq, u64 truncate_size, |
| 5032 | struct timespec *mtime, |
Alex Elder | 2480882 | 2013-02-15 11:42:29 -0600 | [diff] [blame] | 5033 | struct page **pages, int num_pages) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5034 | { |
| 5035 | struct ceph_osd_request *req; |
| 5036 | int rc = 0; |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 5037 | int page_align = off & ~PAGE_MASK; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5038 | |
Yan, Zheng | 715e4cd | 2014-11-13 14:40:37 +0800 | [diff] [blame] | 5039 | req = ceph_osdc_new_request(osdc, layout, vino, off, &len, 0, 1, |
Ilya Dryomov | 54ea004 | 2017-02-11 18:48:41 +0100 | [diff] [blame] | 5040 | CEPH_OSD_OP_WRITE, CEPH_OSD_FLAG_WRITE, |
Alex Elder | acead00 | 2013-03-14 14:09:05 -0500 | [diff] [blame] | 5041 | snapc, truncate_seq, truncate_size, |
Alex Elder | 153e516 | 2013-03-01 18:00:15 -0600 | [diff] [blame] | 5042 | true); |
Sage Weil | 6816282 | 2012-09-24 21:01:02 -0700 | [diff] [blame] | 5043 | if (IS_ERR(req)) |
| 5044 | return PTR_ERR(req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5045 | |
| 5046 | /* it may be a short write due to an object boundary */ |
Alex Elder | 406e2c9 | 2013-04-15 14:50:36 -0500 | [diff] [blame] | 5047 | 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] | 5048 | false, false); |
| 5049 | dout("writepages %llu~%llu (%llu bytes)\n", off, len, len); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5050 | |
Ilya Dryomov | bb873b539 | 2016-05-26 00:29:52 +0200 | [diff] [blame] | 5051 | req->r_mtime = *mtime; |
Alex Elder | 87f979d | 2013-02-15 11:42:29 -0600 | [diff] [blame] | 5052 | rc = ceph_osdc_start_request(osdc, req, true); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5053 | if (!rc) |
| 5054 | rc = ceph_osdc_wait_request(osdc, req); |
| 5055 | |
| 5056 | ceph_osdc_put_request(req); |
| 5057 | if (rc == 0) |
| 5058 | rc = len; |
| 5059 | dout("writepages result %d\n", rc); |
| 5060 | return rc; |
| 5061 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 5062 | EXPORT_SYMBOL(ceph_osdc_writepages); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5063 | |
Alex Elder | 5522ae0 | 2013-05-01 12:43:04 -0500 | [diff] [blame] | 5064 | int ceph_osdc_setup(void) |
| 5065 | { |
Ilya Dryomov | 3f1af42 | 2016-02-09 17:50:15 +0100 | [diff] [blame] | 5066 | size_t size = sizeof(struct ceph_osd_request) + |
| 5067 | CEPH_OSD_SLAB_OPS * sizeof(struct ceph_osd_req_op); |
| 5068 | |
Alex Elder | 5522ae0 | 2013-05-01 12:43:04 -0500 | [diff] [blame] | 5069 | BUG_ON(ceph_osd_request_cache); |
Ilya Dryomov | 3f1af42 | 2016-02-09 17:50:15 +0100 | [diff] [blame] | 5070 | ceph_osd_request_cache = kmem_cache_create("ceph_osd_request", size, |
| 5071 | 0, 0, NULL); |
Alex Elder | 5522ae0 | 2013-05-01 12:43:04 -0500 | [diff] [blame] | 5072 | |
| 5073 | return ceph_osd_request_cache ? 0 : -ENOMEM; |
| 5074 | } |
| 5075 | EXPORT_SYMBOL(ceph_osdc_setup); |
| 5076 | |
| 5077 | void ceph_osdc_cleanup(void) |
| 5078 | { |
| 5079 | BUG_ON(!ceph_osd_request_cache); |
| 5080 | kmem_cache_destroy(ceph_osd_request_cache); |
| 5081 | ceph_osd_request_cache = NULL; |
| 5082 | } |
| 5083 | EXPORT_SYMBOL(ceph_osdc_cleanup); |
| 5084 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5085 | /* |
| 5086 | * handle incoming message |
| 5087 | */ |
| 5088 | static void dispatch(struct ceph_connection *con, struct ceph_msg *msg) |
| 5089 | { |
| 5090 | struct ceph_osd *osd = con->private; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5091 | struct ceph_osd_client *osdc = osd->o_osdc; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5092 | int type = le16_to_cpu(msg->hdr.type); |
| 5093 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5094 | switch (type) { |
| 5095 | case CEPH_MSG_OSD_MAP: |
| 5096 | ceph_osdc_handle_map(osdc, msg); |
| 5097 | break; |
| 5098 | case CEPH_MSG_OSD_OPREPLY: |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5099 | handle_reply(osd, msg); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5100 | break; |
Ilya Dryomov | a02a946 | 2017-06-19 12:18:05 +0200 | [diff] [blame] | 5101 | case CEPH_MSG_OSD_BACKOFF: |
| 5102 | handle_backoff(osd, msg); |
| 5103 | break; |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 5104 | case CEPH_MSG_WATCH_NOTIFY: |
| 5105 | handle_watch_notify(osdc, msg); |
| 5106 | break; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5107 | |
| 5108 | default: |
| 5109 | pr_err("received unknown message type %d %s\n", type, |
| 5110 | ceph_msg_type_name(type)); |
| 5111 | } |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5112 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5113 | ceph_msg_put(msg); |
| 5114 | } |
| 5115 | |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 5116 | /* |
Ilya Dryomov | d15f9d6 | 2015-09-02 11:37:09 +0300 | [diff] [blame] | 5117 | * Lookup and return message for incoming reply. Don't try to do |
| 5118 | * anything about a larger than preallocated data portion of the |
| 5119 | * message at the moment - for now, just skip the message. |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 5120 | */ |
| 5121 | static struct ceph_msg *get_reply(struct ceph_connection *con, |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 5122 | struct ceph_msg_header *hdr, |
| 5123 | int *skip) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5124 | { |
| 5125 | struct ceph_osd *osd = con->private; |
| 5126 | struct ceph_osd_client *osdc = osd->o_osdc; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5127 | struct ceph_msg *m = NULL; |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 5128 | struct ceph_osd_request *req; |
Ilya Dryomov | 3f0a4ac | 2014-01-09 20:08:21 +0200 | [diff] [blame] | 5129 | int front_len = le32_to_cpu(hdr->front_len); |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 5130 | int data_len = le32_to_cpu(hdr->data_len); |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5131 | u64 tid = le64_to_cpu(hdr->tid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5132 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5133 | down_read(&osdc->lock); |
| 5134 | if (!osd_registered(osd)) { |
| 5135 | dout("%s osd%d unknown, skipping\n", __func__, osd->o_osd); |
| 5136 | *skip = 1; |
| 5137 | goto out_unlock_osdc; |
| 5138 | } |
| 5139 | WARN_ON(osd->o_osd != le64_to_cpu(hdr->src.num)); |
| 5140 | |
| 5141 | mutex_lock(&osd->lock); |
| 5142 | req = lookup_request(&osd->o_requests, tid); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 5143 | if (!req) { |
Ilya Dryomov | cd8140c | 2016-02-19 11:38:57 +0100 | [diff] [blame] | 5144 | dout("%s osd%d tid %llu unknown, skipping\n", __func__, |
| 5145 | osd->o_osd, tid); |
Ilya Dryomov | d15f9d6 | 2015-09-02 11:37:09 +0300 | [diff] [blame] | 5146 | *skip = 1; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5147 | goto out_unlock_session; |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 5148 | } |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 5149 | |
Alex Elder | ace6d3a | 2013-04-01 16:12:14 -0500 | [diff] [blame] | 5150 | ceph_msg_revoke_incoming(req->r_reply); |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 5151 | |
Ilya Dryomov | f2be82b | 2014-01-09 20:08:21 +0200 | [diff] [blame] | 5152 | if (front_len > req->r_reply->front_alloc_len) { |
Ilya Dryomov | d15f9d6 | 2015-09-02 11:37:09 +0300 | [diff] [blame] | 5153 | pr_warn("%s osd%d tid %llu front %d > preallocated %d\n", |
| 5154 | __func__, osd->o_osd, req->r_tid, front_len, |
| 5155 | req->r_reply->front_alloc_len); |
Ilya Dryomov | 3f0a4ac | 2014-01-09 20:08:21 +0200 | [diff] [blame] | 5156 | m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front_len, GFP_NOFS, |
| 5157 | false); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 5158 | if (!m) |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5159 | goto out_unlock_session; |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 5160 | ceph_msg_put(req->r_reply); |
| 5161 | req->r_reply = m; |
| 5162 | } |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 5163 | |
Ilya Dryomov | d15f9d6 | 2015-09-02 11:37:09 +0300 | [diff] [blame] | 5164 | if (data_len > req->r_reply->data_length) { |
| 5165 | pr_warn("%s osd%d tid %llu data %d > preallocated %zu, skipping\n", |
| 5166 | __func__, osd->o_osd, req->r_tid, data_len, |
| 5167 | req->r_reply->data_length); |
| 5168 | m = NULL; |
| 5169 | *skip = 1; |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5170 | goto out_unlock_session; |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 5171 | } |
Ilya Dryomov | d15f9d6 | 2015-09-02 11:37:09 +0300 | [diff] [blame] | 5172 | |
| 5173 | m = ceph_msg_get(req->r_reply); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 5174 | dout("get_reply tid %lld %p\n", tid, m); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 5175 | |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5176 | out_unlock_session: |
| 5177 | mutex_unlock(&osd->lock); |
| 5178 | out_unlock_osdc: |
| 5179 | up_read(&osdc->lock); |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 5180 | return m; |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 5181 | } |
| 5182 | |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 5183 | /* |
| 5184 | * TODO: switch to a msg-owned pagelist |
| 5185 | */ |
| 5186 | static struct ceph_msg *alloc_msg_with_page_vector(struct ceph_msg_header *hdr) |
| 5187 | { |
| 5188 | struct ceph_msg *m; |
| 5189 | int type = le16_to_cpu(hdr->type); |
| 5190 | u32 front_len = le32_to_cpu(hdr->front_len); |
| 5191 | u32 data_len = le32_to_cpu(hdr->data_len); |
| 5192 | |
| 5193 | m = ceph_msg_new(type, front_len, GFP_NOIO, false); |
| 5194 | if (!m) |
| 5195 | return NULL; |
| 5196 | |
| 5197 | if (data_len) { |
| 5198 | struct page **pages; |
| 5199 | struct ceph_osd_data osd_data; |
| 5200 | |
| 5201 | pages = ceph_alloc_page_vector(calc_pages_for(0, data_len), |
| 5202 | GFP_NOIO); |
Wei Yongjun | c22e853 | 2016-07-30 00:37:57 +0000 | [diff] [blame] | 5203 | if (IS_ERR(pages)) { |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 5204 | ceph_msg_put(m); |
| 5205 | return NULL; |
| 5206 | } |
| 5207 | |
| 5208 | ceph_osd_data_pages_init(&osd_data, pages, data_len, 0, false, |
| 5209 | false); |
| 5210 | ceph_osdc_msg_data_add(m, &osd_data); |
| 5211 | } |
| 5212 | |
| 5213 | return m; |
| 5214 | } |
| 5215 | |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 5216 | static struct ceph_msg *alloc_msg(struct ceph_connection *con, |
| 5217 | struct ceph_msg_header *hdr, |
| 5218 | int *skip) |
| 5219 | { |
| 5220 | struct ceph_osd *osd = con->private; |
| 5221 | int type = le16_to_cpu(hdr->type); |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 5222 | |
Alex Elder | 1c20f2d | 2012-06-04 14:43:32 -0500 | [diff] [blame] | 5223 | *skip = 0; |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 5224 | switch (type) { |
| 5225 | case CEPH_MSG_OSD_MAP: |
Ilya Dryomov | a02a946 | 2017-06-19 12:18:05 +0200 | [diff] [blame] | 5226 | case CEPH_MSG_OSD_BACKOFF: |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 5227 | case CEPH_MSG_WATCH_NOTIFY: |
Ilya Dryomov | 1907920 | 2016-04-28 16:07:27 +0200 | [diff] [blame] | 5228 | return alloc_msg_with_page_vector(hdr); |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 5229 | case CEPH_MSG_OSD_OPREPLY: |
| 5230 | return get_reply(con, hdr, skip); |
| 5231 | default: |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5232 | pr_warn("%s osd%d unknown msg type %d, skipping\n", __func__, |
| 5233 | osd->o_osd, type); |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 5234 | *skip = 1; |
| 5235 | return NULL; |
| 5236 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5237 | } |
| 5238 | |
| 5239 | /* |
| 5240 | * Wrappers to refcount containing ceph_osd struct |
| 5241 | */ |
| 5242 | static struct ceph_connection *get_osd_con(struct ceph_connection *con) |
| 5243 | { |
| 5244 | struct ceph_osd *osd = con->private; |
| 5245 | if (get_osd(osd)) |
| 5246 | return con; |
| 5247 | return NULL; |
| 5248 | } |
| 5249 | |
| 5250 | static void put_osd_con(struct ceph_connection *con) |
| 5251 | { |
| 5252 | struct ceph_osd *osd = con->private; |
| 5253 | put_osd(osd); |
| 5254 | } |
| 5255 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5256 | /* |
| 5257 | * authentication |
| 5258 | */ |
Alex Elder | a3530df | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 5259 | /* |
| 5260 | * Note: returned pointer is the address of a structure that's |
| 5261 | * managed separately. Caller must *not* attempt to free it. |
| 5262 | */ |
| 5263 | static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con, |
Alex Elder | 8f43fb5 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 5264 | int *proto, int force_new) |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5265 | { |
| 5266 | struct ceph_osd *o = con->private; |
| 5267 | struct ceph_osd_client *osdc = o->o_osdc; |
| 5268 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 5269 | struct ceph_auth_handshake *auth = &o->o_auth; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5270 | |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 5271 | if (force_new && auth->authorizer) { |
Ilya Dryomov | 6c1ea26 | 2016-04-11 19:34:49 +0200 | [diff] [blame] | 5272 | ceph_auth_destroy_authorizer(auth->authorizer); |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 5273 | auth->authorizer = NULL; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5274 | } |
Sage Weil | 27859f9 | 2013-03-25 10:26:14 -0700 | [diff] [blame] | 5275 | if (!auth->authorizer) { |
| 5276 | int ret = ceph_auth_create_authorizer(ac, CEPH_ENTITY_TYPE_OSD, |
| 5277 | auth); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5278 | if (ret) |
Alex Elder | a3530df | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 5279 | return ERR_PTR(ret); |
Sage Weil | 27859f9 | 2013-03-25 10:26:14 -0700 | [diff] [blame] | 5280 | } else { |
| 5281 | int ret = ceph_auth_update_authorizer(ac, CEPH_ENTITY_TYPE_OSD, |
Sage Weil | 0bed9b5 | 2013-03-25 10:26:01 -0700 | [diff] [blame] | 5282 | auth); |
| 5283 | if (ret) |
| 5284 | return ERR_PTR(ret); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5285 | } |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5286 | *proto = ac->protocol; |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 5287 | |
Alex Elder | a3530df | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 5288 | return auth; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | |
Ilya Dryomov | 0dde584 | 2016-12-02 16:35:09 +0100 | [diff] [blame] | 5292 | static int verify_authorizer_reply(struct ceph_connection *con) |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5293 | { |
| 5294 | struct ceph_osd *o = con->private; |
| 5295 | struct ceph_osd_client *osdc = o->o_osdc; |
| 5296 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
| 5297 | |
Ilya Dryomov | 0dde584 | 2016-12-02 16:35:09 +0100 | [diff] [blame] | 5298 | return ceph_auth_verify_authorizer_reply(ac, o->o_auth.authorizer); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5299 | } |
| 5300 | |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 5301 | static int invalidate_authorizer(struct ceph_connection *con) |
| 5302 | { |
| 5303 | struct ceph_osd *o = con->private; |
| 5304 | struct ceph_osd_client *osdc = o->o_osdc; |
| 5305 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
| 5306 | |
Sage Weil | 27859f9 | 2013-03-25 10:26:14 -0700 | [diff] [blame] | 5307 | ceph_auth_invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 5308 | return ceph_monc_validate_auth(&osdc->client->monc); |
| 5309 | } |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5310 | |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 5311 | static void osd_reencode_message(struct ceph_msg *msg) |
| 5312 | { |
| 5313 | encode_request_finish(msg); |
| 5314 | } |
| 5315 | |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5316 | static int osd_sign_message(struct ceph_msg *msg) |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5317 | { |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5318 | struct ceph_osd *o = msg->con->private; |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5319 | struct ceph_auth_handshake *auth = &o->o_auth; |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5320 | |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5321 | return ceph_auth_sign_message(auth, msg); |
| 5322 | } |
| 5323 | |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5324 | static int osd_check_message_signature(struct ceph_msg *msg) |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5325 | { |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5326 | struct ceph_osd *o = msg->con->private; |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5327 | struct ceph_auth_handshake *auth = &o->o_auth; |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5328 | |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5329 | return ceph_auth_check_message_signature(auth, msg); |
| 5330 | } |
| 5331 | |
Tobias Klauser | 9e32789 | 2010-05-20 10:40:19 +0200 | [diff] [blame] | 5332 | static const struct ceph_connection_operations osd_con_ops = { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5333 | .get = get_osd_con, |
| 5334 | .put = put_osd_con, |
| 5335 | .dispatch = dispatch, |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5336 | .get_authorizer = get_authorizer, |
| 5337 | .verify_authorizer_reply = verify_authorizer_reply, |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 5338 | .invalidate_authorizer = invalidate_authorizer, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5339 | .alloc_msg = alloc_msg, |
Ilya Dryomov | 8cb441c | 2017-06-15 16:30:54 +0200 | [diff] [blame] | 5340 | .reencode_message = osd_reencode_message, |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5341 | .sign_message = osd_sign_message, |
| 5342 | .check_message_signature = osd_check_message_signature, |
Ilya Dryomov | 5aea3dc | 2016-04-28 16:07:26 +0200 | [diff] [blame] | 5343 | .fault = osd_fault, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 5344 | }; |