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