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